| Crates.io | bloomz |
| lib.rs | bloomz |
| version | 0.1.0 |
| created_at | 2025-08-10 11:59:53.515245+00 |
| updated_at | 2025-08-10 11:59:53.515245+00 |
| description | A fast, flexible Bloom filter library for Rust with parallel operations support |
| homepage | https://github.com/pixperk/bloomz |
| repository | https://github.com/pixperk/bloomz |
| max_upload_size | |
| id | 1788840 |
| size | 66,996 |
Fast, flexible Bloom filter for Rust with pluggable hashers and parallel operations.
Add to your Cargo.toml:
[dependencies]
bloomz = "0.1"
# Enable optional features
bloomz = { version = "0.1", features = ["serde", "rayon"] }
use bloomz::BloomFilter;
// Create a filter for ~1000 items with 1% false positive rate
let mut filter = BloomFilter::new_for_capacity(1000, 0.01);
// Insert items
filter.insert(&"hello");
filter.insert(&42);
// Check membership
assert!(filter.contains(&"hello"));
assert!(!filter.contains(&"world"));
rayon feature)use bloomz::BloomFilter;
use rayon::prelude::*;
use std::collections::hash_map::RandomState;
let rs = RandomState::new();
let mut filter = BloomFilter::with_hasher(10000, 7, rs);
// Parallel batch insert
let items: Vec<i32> = (0..1000).collect();
filter.insert_batch(items.par_iter().cloned());
// Parallel batch contains
let test_items: Vec<i32> = (500..600).collect();
let results = filter.contains_batch(test_items.par_iter().cloned());
// Check if all items are present
let all_present = filter.contains_all(test_items.par_iter().cloned());
serde feature)use bloomz::BloomFilter;
let mut filter = BloomFilter::new_for_capacity(100, 0.01);
filter.insert(&"data");
// JSON serialization
let json = serde_json::to_string(&filter)?;
let restored: BloomFilter = serde_json::from_str(&json)?;
// Binary serialization
let bytes = filter.to_bytes();
let restored = BloomFilter::from_bytes(&bytes).unwrap();
use bloomz::BloomFilter;
use std::collections::hash_map::RandomState;
// Default SipHash (secure)
let filter1 = BloomFilter::new(1000, 5);
// Custom RandomState
let rs = RandomState::new();
let filter2 = BloomFilter::with_hasher(1000, 5, rs);
// Fast hashers (requires feature flags)
#[cfg(feature = "fast-ahash")]
{
use ahash::AHasher;
let filter3 = BloomFilter::with_hasher(1000, 5,
ahash::RandomState::new());
}
Bloomz uses several optimizations:
u64Run benchmarks to compare hashers and parallel vs sequential operations:
# Compare different hash builders
cargo bench --features "fast-ahash,fast-xxh3" bloom_hashers
# Compare parallel vs sequential operations
cargo bench --features rayon parallel_bloom
BloomFilter<S> - Main bloom filter with hasher type SBitSet - Underlying bit storage with optimized operationsinsert(&item) - Insert a single iteminsert_batch(items) - Parallel batch insert (rayon feature)contains(&item) - Check if item is probably in setcontains_batch(items) - Parallel batch check (rayon feature)contains_all(items) - Check if all items are present (rayon feature)union_inplace(&other) - Merge with another filterintersect_inplace(&other) - Keep only common elementsclear() - Remove all itemsto_bytes() / from_bytes() - Binary formatuse bloomz::math;
// Calculate optimal parameters
let m = math::optimal_m(n_items, false_positive_rate);
let k = math::optimal_k(m, n_items);
let filter = BloomFilter::new(m, k);
| Feature | Description | Dependencies |
|---|---|---|
serde |
JSON/binary serialization | serde, serde_json |
rayon |
Parallel batch operations | rayon |
fast-ahash |
AHash hasher support | ahash |
fast-xxh3 |
xxHash hasher support | xxhash-rust |
See src/main.rs for a complete web crawler URL filter demo:
# Basic demo
cargo run
# With all features
cargo run --features "rayon,serde,fast-ahash"
Contributions welcome! Please check:
cargo test --all-featurescargo bench --all-featuresMIT License - see LICENSE file.
🌸 Bloomz: Where speed meets flexibility in Rust Bloom filters!