Crates.io | growable-bloom-filter |
lib.rs | growable-bloom-filter |
version | 2.1.1 |
source | src |
created_at | 2019-10-07 01:04:41.770727 |
updated_at | 2024-10-06 17:30:10.071037 |
description | Scalable Bloom Filters with serde support |
homepage | https://github.com/dpbriggs/growable-bloom-filters |
repository | https://github.com/dpbriggs/growable-bloom-filters |
max_upload_size | |
id | 170476 |
size | 38,996 |
Implementation of Scalable Bloom Filters which also provides serde serialization and deserialize.
A bloom filter lets you insert
items, and then test association with contains
.
It's space and time efficient, at the cost of false positives.
In particular, if contains
returns true
, it may be in filter.
But if contains
returns false, it's definitely not in the bloom filter.
You can control the failure rate by setting desired_error_prob
and est_insertions
appropriately.
use growable_bloom_filter::GrowableBloom;
// Create and insert into the bloom filter
let mut gbloom = GrowableBloom::new(0.05, 1000);
gbloom.insert(&0);
assert!(gbloom.contains(&0));
// Serialize and Deserialize the bloom filter
use serde_json;
let s = serde_json::to_string(&gbloom).unwrap();
let des_gbloom: GrowableBloom = serde_json::from_str(&s).unwrap();
assert!(des_gbloom.contains(&0));
// Builder API
use growable_bloom_filter::GrowableBloomBuilder;
let mut gbloom = GrowableBloomBuilder::new()
.estimated_insertions(100)
.desired_error_ratio(0.05)
.build();
gbloom.insert(&0);
assert!(gbloom.contains(&0));
Bloom filters are typically used as a pre-cache to avoid expensive operations. For example, if you need to ask ten thousand servers if they have data XYZ, you could use GrowableBloom to figure out which ones do NOT have XYZ.
The (de)serialized bloom filter can be transferred and used across different platforms, independent of endianness, architecture or word size.
Note that stability is only guaranteed within the same major version of the crate.