Crates.io | b100m-filter |
lib.rs | b100m-filter |
version | 0.4.0 |
source | src |
created_at | 2023-10-29 23:43:48.663337 |
updated_at | 2024-03-05 02:24:56.308716 |
description | The fastest bloom filter in Rust. No accuracy compromises. Use any hasher. |
homepage | https://github.com/tomtomwombat/b100m-filter/ |
repository | https://github.com/tomtomwombat/b100m-filter/ |
max_upload_size | |
id | 1017859 |
size | 57,909 |
The fastest bloom filter in Rust. No accuracy compromises. Use any hasher.
# Cargo.toml
[dependencies]
b100m-filter = "0.4.0"
use b100m_filter::BloomFilter;
let num_blocks = 4; // by default, each block is 512 bits
let values = vec!["42", "🦀"];
let filter = BloomFilter::builder(num_blocks).items(values.iter());
assert!(filter.contains("42"));
assert!(filter.contains("🦀"));
use b100m_filter::BloomFilter;
use ahash::RandomState;
let num_blocks = 4; // by default, each block is 512 bits
let filter = BloomFilter::builder(num_blocks)
.hasher(RandomState::default())
.items(["42", "🦀"].iter());
Bloom filters are a space efficient approximate membership set data structure. False positives from contains
are possible, but false negatives are not, i.e. contains
for all items in the set is guaranteed to return true, while contains
for all items not in the set probably return false.
Blocked bloom filters are supported by an underlying bit vector, chunked into 512, 256, 128, or 64 bit "blocks", to track item membership. To insert, a number of bits, based on the item's hash, are set in the underlying bit vector. To check membership, a number of bits, based on the item's hash, are checked in the underlying bit vector.
Once constructed, neither the bloom filter's underlying memory usage nor number of bits per item change.
b100m-filter
is blazingly fast because it uses L1 cache friendly blocks and efficiently derives many index bits from only one hash per value. Compared to traditional implementations, b100m-filter
is 2-5 times faster for small sets of items, and hundreds of times faster for larger item sets. In all cases, b100m-filter
maintains competitive false positive rates.
Runtime comparison to other bloom filter crates:
Check Non-Existing (ns) | Check Existing (ns) | |
---|---|---|
b100m-filter | 16.900 | 139.62 |
*fastbloom-rs | 35.358 | 485.81 |
bloom | 66.136 | 749.27 |
bloomfilter | 68.912 | 996.56 |
probabilistic-collections | 83.385 | 974.67 |
*fastbloom-rs uses XXHash, which is faster than SipHash.
b100m-filter
does not compromise accuracy. Below is a comparison false positive rate with other bloom filter crates:
b100m-filter
scales very well.
As the number of bits and set size increase, traditional bloom filters need to perform more hashes per item to optimize false positive rates. However, b100m-filter
's optimal number of hashes is bounded while keeping near zero rates even for many items:
Bloom filter speed is directly proportional to number of hashes.
Licensed under either of
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.