Live data from Hacker News

Bloom Filters by Example

llimllib.github.io

11–20 of 39 posts

Re: Bloom Filters by Example

#11
Unrelated, but I've always had this question about bloom filters...

If testing for membership in the set is unreliable, but testing for non-membership in the set works every time, then why can't you simply invert the boolean for the non-membership test and call that a membership test?

E.g., if it's not not in the group, then it's in the group...

Re: Bloom Filters by Example

#12
post #5

I disagree with the standard dogma around bloom filters that you need multiple hash functions. Just use a simple incrementing salt value to modify the input so you can hash the resulting salted input as many times as you need to, using a different salt value each time. Say you want to hash the string "abc" 8 times. Instead of having 8 hash functions, just take the hash of, say, "abc-0", "abc-1", ... "abc-7". As long…

I think I actually wrote a section on doing this and then wrote over it at some point :(

PRs welcome, I'm on vacation and unlikely to get to it immediately. http://github.com/llimllib/bloomfilter-tutorial

Re: Bloom Filters by Example

#13

Unrelated, but I've always had this question about bloom filters... If testing for membership in the set is unreliable, but testing for non-membership in the set works every time, then why can't you simply invert the boolean for the non-membership test and call that a membership test? E.g., if it's not not in the group, then it's in the group...

If you want to invert the boolean check, then you need to invert the input space as well, which is not possible.

For example, consider a Bloom filter checking the availability of a username during sign up. If you want an inverse Bloom filter that checks if it is not not in the group, then you need to load it with all possible usernames.

Re: Bloom Filters by Example

#14

Unrelated, but I've always had this question about bloom filters... If testing for membership in the set is unreliable, but testing for non-membership in the set works every time, then why can't you simply invert the boolean for the non-membership test and call that a membership test? E.g., if it's not not in the group, then it's in the group...

If you want to invert the boolean check, then you need to invert the input space as well, which is not possible. For example, consider a Bloom filter checking the availability of a username during sign up. If you want an inverse Bloom filter that checks if it is not not in the group, then you need to load it with all possible usernames.

Makes sense. OP's link is interactive enough that I was beginning to see that, though couldn't articulate it. Thanks!

Re: Bloom Filters by Example

#15
sha1 is very, very fast. This article seems to confuse cryptographically useful hash functions with key stretching, adaptive work hashing, and the like.

Re: Bloom Filters by Example

#16

Earlier quoted context omitted.

If you want to invert the boolean check, then you need to invert the input space as well, which is not possible. For example, consider a Bloom filter checking the availability of a username during sign up. If you want an inverse Bloom filter that checks if it is not not in the group, then you need to load it with all possible usernames.

Makes sense. OP's link is interactive enough that I was beginning to see that, though couldn't articulate it. Thanks!

If I was going to explain a bloom filter like you're 5... a bloom filter is like a savant who never forgets a face -- maybe he's got a job in passport control in Arstotzka -- if you show him someone's face or picture once, he'll never forget it: if any time later you show him the same picture and ask him "have you seen this face before?" he'll say "yes" without fail. If he replies "no way", you can be 100% sure he's never seen it. But his memory isn't photographic: he confuses people's faces after a while, recognizing faces he's never seen, and that becomes worse the more people he's seen. So to be safe he doesn't reply just "yes" but "hmm, I guess so".

In computing terms the interface has 2 methods:

- takeALookAtThisFace(x)

- yaSeenThisFaceBefore?(x) which returns either "no way" or "hmm, I guess so".

"no way" means P(x is a member) = 0. Its negation is not "hell yes" (P(x is a member) = 1), it's "maybe" (P(x is a member) > 0).

Re: Bloom Filters by Example

#17
post #5

I disagree with the standard dogma around bloom filters that you need multiple hash functions. Just use a simple incrementing salt value to modify the input so you can hash the resulting salted input as many times as you need to, using a different salt value each time. Say you want to hash the string "abc" 8 times. Instead of having 8 hash functions, just take the hash of, say, "abc-0", "abc-1", ... "abc-7". As long…

The only problem is this assumes that the hash unpredictably changes on input modification. Which is true for cryptographic hashes but not others.

Re: Bloom Filters by Example

#18
post #16

Earlier quoted context omitted.

Makes sense. OP's link is interactive enough that I was beginning to see that, though couldn't articulate it. Thanks!

If I was going to explain a bloom filter like you're 5... a bloom filter is like a savant who never forgets a face -- maybe he's got a job in passport control in Arstotzka -- if you show him someone's face or picture once, he'll never forget it: if any time later you show him the same picture and ask him "have you seen this face before?" he'll say "yes" without fail. If he replies "no way", you can be 100% sure he's…

Thanks for this explanation it was really helpful!

Re: Bloom Filters by Example

#19
I am confused by:

    > cryptographic hashes such as sha1,
    > though widely used therefore are not
    > very good choices
I thought SHA1 was fast, and that was a reason to not use it in applications where brute-forcing might be an issue.

    > [the more times you hash it the fewer
    > false positives]
That doesn't match my understanding of how any even slightly reasonable hash function should work, doubly so if it's uniformly distributed.

Re: Bloom Filters by Example

#20
For implementations that use cryptographic hash functions, do you actually need more than one hash function invocation per item?

For instance, suppose you were implementing a Bloom filter with 2^20 bits, and you want to use 10 bits per item. Instead of hashing the item 10 times, could you hash once with a 256 bit cryptographic hash, and then take the lower 200 bits, divide that into 10 bit strings of 20 bits each, and use those?

Post reply on HN