broomfilter 0.1.4

A bloom filter that sweeps away your certainty. Probably.
Documentation

broomfilter

CI crates.io docs.rs Rust License: MIT Downloads

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 broomfilter::Filter;

// Create a filter with 2^14 bits, optimized for 10,000 items
let mut filter = Filter::new(14, 10_000).unwrap();

// Insert some things ๐Ÿงน
filter.insert("hello");
filter.insert("world");

// Check for things
assert!(filter.contains("hello"));    // true  โ€” probably  ๐Ÿคท
assert!(!filter.contains("goodbye")); // 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.