broomfilter
A (pretty fast) bloom filter implementation in Rust.
๐ค What is this?
A bloom filter is a probabilistic data structure that can tell you:
- โ "Definitely not in the set" โ 100% accurate
- ๐คท "Probably in the set" โ maybe, who knows
Think of it as that friend who says "I'm pretty sure I locked the door." You can trust them when they say they didn't, but when they say they did... you might want to go check.
๐งน Theory of broom sweeping (simplified)
item โโโ [ hash hash hash ] โโโ flip bits in the array
๐งน๐จ
query โโโ [ hash hash hash ] โโโ check bits
โโโ all set? โ "probably yes" ๐คท
โโโ any unset? โ "definitely no" โ
๐ก Why does this exist?
Because I wanted to learn how a bloom filter actually worked instead of just reciting the definition in tech interviews. Turns out its super fun to optimize!
๐ Usage
use Filter;
// Create a filter with 2^14 bits, optimized for 10,000 items
let mut filter = new.unwrap;
// Insert some things ๐งน
filter.insert;
filter.insert;
// Check for things
assert!; // true โ probably ๐คท
assert!; // false โ definitely โ
๐๏ธ Status
โ ๏ธ Work in progress โ handle with care (or don't, I'm a dev, not a cop)
It works, it has benchmarks, it probably won't break. But then again, the whole point of a bloom filter is that you can never be 100% sure about anything.
| Feature | Status |
|---|---|
| Insert items | โ Swept in |
| Check membership | โ Probably |
| False positives | โ It's a feature |
| False negatives | ๐ซ Impossible (finally, some certainty) |
| Delete items | ๐งน Nope, the broom only sweeps one way |
๐ License
MIT โ do whatever you want with it, just don't blame me when it breaks.