alexandrnikitin / bloom-filter-scala

Bloom filter for Scala, the fastest for JVM
https://alexandrnikitin.github.io/blog/bloom-filter-for-scala/
MIT License
376 stars 57 forks source link

Why the bloomfilter returns false? #18

Closed leesf closed 7 years ago

leesf commented 7 years ago

When i use the example on the main page i add element to the bloomfilter, however, when using mightContain method to check whether an element in a set. it returns false.Why?

val expectedElements = 1000000 val falsePositiveRate = 0.1 val bf = BloomFilter[String](expectedElements, falsePositiveRate)

// Put an element bf.add("lee")

// Check whether an element in a set bf.mightContain("lee") // return false

// Dispose the instance bf.dispose()

alexandrnikitin commented 7 years ago

It returns true for me. I added a commit with your code https://github.com/alexandrnikitin/bloom-filter-scala/commit/1493f2c611e287ab1466efe8fea765fe10aacb38 Try it please. Make sure you use the latest version. It's 0.7.0 at the moment.

leesf commented 7 years ago

@alexandrnikitin Thanks for replying. I have already used 0.7.0 and changed the code, however, it still returns false for me, the computedHash in add operation and mightContain is different when debugging.

leesf commented 7 years ago

@alexandrnikitin However, when i use the following code, it returns true.

val expectedElements = 1000 val falsePositiveRate = 0.1 val bf = BloomFilter[Array[Byte]](expectedElements, falsePositiveRate)

// Put an element bf.add("lee".getBytes)

// Check whether an element in a set bf.mightContain("lee".getBytes) // return true

bf.dispose()

It is so odd. And i do not know how it happens.

alexandrnikitin commented 7 years ago

@leesf Hmm, interesting, could you please push a unit test to this repository that reproduces that behavior in your environment.

leesf commented 7 years ago

@alexandrnikitin , I would push a unit test to the repository with pleasure, but exactly i don't know how to conduct a unit test.

alexandrnikitin commented 7 years ago

@leesf Another option is to change the example application like I did here https://github.com/alexandrnikitin/bloom-filter-scala/commit/1493f2c611e287ab1466efe8fea765fe10aacb38