News for hackers. Stuff that matters.
Re:Word-Aligned Bloom Filters by lelandfe on Sunday October 03, 2021 @12:43PM (#28738477)
At the risk of finally exposing myself as an impostor, does anyone have a good link for an explanation of bloom filters?

I’ve tried, unsuccessfully, to wrap my head around the concept before, and this article seems really interesting!

Re:Word-Aligned Bloom Filters by rattlesnakedave on Sunday October 03, 2021 @01:11PM (#28738725)
You want to check if an element is probably in a dataset. You want speed, and the possibility of a false positive doesn’t scare you that much.

Say you want to lookup if a username is in a database. That could take a while if you have a really large db of usernames, but you want to tell a user quickly if a name is taken.

So what you can do is make a bloom filter, which is basically just an array of bits of n length. Let’s say 10 for our example.

Then gather some hash functions (h1, h2, and h3).

When someone inputs a username, you run it through the hash functions, and modulo by the number of bits, and get an integer result.

So:

h1(“rattlesnakedave”) % 10 = 3 h2(“rattlesnakedave”) % 10 = 7 h3(“rattlesnakedave”) % 10 = 2

Then you check the bits at position 3,2, and 7 in the array.

If they any of the bits are set to 0, we haven’t seen the username before.

If they’re all set to 1, we have possibly seen the username before.

Let’s say they’re all set to 0, so we probably haven’t seen it. We can present the message that the username is available, and allow registration. During registration, we can do a slower more expensive verification that the username isn’t actually in the dataset.

Now that the username is in the dataset, we can flip the bits on our bloom filter at position 3,2, and 7 to 1. So the next time we lookup that username we can tell quickly that it’s probably taken.

There is no way to delete from the bloom filter. The more values you store relative to its size, the more false positives you get.

Hopefully that makes sense, and is correct.

Re:Word-Aligned Bloom Filters by Taywee on Sunday October 03, 2021 @01:14PM (#28738752)
Not exactly correct. If all of the bits is 1, then the value is possibly in the set (not "probably", but "possibly", with the likelihood being affected by the sizes of the set and the array).

If any of the bits is zero, the value definitely isn't in the set (also not "probably haven't", but definitely not).

Re:Word-Aligned Bloom Filters by rattlesnakedave on Sunday October 03, 2021 @01:20PM (#28738788)
Good catch! Thank you.

Was trying to keep the initial explanation simple by leaving out the false positives scaling relative to the size of the array and set, and then clarifying at the end.

The second part (any 0 bits it hasn’t been seen) is true, a goof up on my part.

Re:Word-Aligned Bloom Filters by DougBTX on Sunday October 03, 2021 @02:39PM (#28739481)
Usernames is a nice example. Just as a demo, we could make things simpler:

Look at all the usernames in the input, keep track of all the letters you’ve seen. When you get a new name, if you’ve seen all the letters before, you might have seen the name before. If there’s a new letter, it must be a new name.

Obviously that isn’t a great hash function, some letters are more common than others, so real Bloom filters use better ones, but it works basically the same way.

Re:Word-Aligned Bloom Filters by a11r on Sunday October 03, 2021 @02:03PM (#28739124)
The original paper by Burton H. Bloom is only 5 pages and very readable. https://dl.acm.org/doi/10.1145/362686.362692
Re:Word-Aligned Bloom Filters by ghostly_s on Sunday October 03, 2021 @03:02PM (#28739640)
Re:Word-Aligned Bloom Filters by taeric on Sunday October 03, 2021 @09:38PM (#28742124)
I always think of them as "bouncer filter."

Think of them as asking a bouncer if they have seen a suspect enter a club. They don't know folks by name, but can answer a series questions about the people that entered.

Then, the "hashes" are effectively your new questions. Did someone with green hair enter? Did someone limping enter? Wearing a hat? Etc

To that end, it is clear that you won't get a definitive yes to entry. You may get a sufficient no, though.

Re:Word-Aligned Bloom Filters by avinassh on Sunday October 03, 2021 @12:48PM (#28738524)
Re:Word-Aligned Bloom Filters by stevenguh on Sunday October 03, 2021 @12:48PM (#28738523)
Try watching this video: https://youtu.be/Bay3X9PAX5k
Re:Word-Aligned Bloom Filters by GVRV on Monday October 04, 2021 @12:02AM (#28742926)
They finally clicked for me after reading about how they're used by the bitcoin network: https://github.com/bitcoinbook/bitcoinbook/blob/develop/ch08...
Re:Word-Aligned Bloom Filters by 6510 on Sunday October 03, 2021 @02:23PM (#28739309)
let me butcher the concept for you :)

say though nummerology you reduce the character values of a name to a number 0-10. Lots of names will reduce to the same number. We take 11 bits and for "jim" we set the first bit. We have only one name in our data set so all other bits are 0. Now if someone types "joe" in the search box and it reduces to 2 we look at the second bit, see it is a zero and know 100% *for sure* that this name is not in the data set. If "jack" reduces to 1 and we look him up we see 1 is set so this name *might be* there.

Re:Word-Aligned Bloom Filters by cma on Sunday October 03, 2021 @02:44PM (#28739513)
Isn't this just similar to hash prefixes and not a true bloom filter?
Re:Word-Aligned Bloom Filters by 6510 on Sunday October 03, 2021 @10:37PM (#28742421)
I did say I'd butcher it. :-) imho one shouldn't be overly attached to an exact implementation but learn to reason about it. You could for example make an array and count how many times each bit was set. A textbook bloomfilter doesn't allow you to remove things but if you count how often a bit was set you obviously can.
Re:Word-Aligned Bloom Filters by dr_kiszonka on Sunday October 03, 2021 @02:34PM (#28739425)
I will take an imposter over a grandiose narcissist any day! (But then I am an imposter too.)
Re:Word-Aligned Bloom Filters by robertlagrant on Sunday October 03, 2021 @03:27PM (#28739825)
> If everyone is am imposter, no one is!

- Syndrome

Re:Word-Aligned Bloom Filters by actually_a_dog on Sunday October 03, 2021 @04:33PM (#28740305)
This article has a pretty good explanation, IMO: https://freecontent.manning.com/all-about-bloom-filters/