pub struct GrowableBloomBuilder { /* private fields */ }
Expand description
Builder API for GrowableBloom.
use growable_bloom_filter::GrowableBloomBuilder;
let mut gbloom = GrowableBloomBuilder::new()
.estimated_insertions(100)
.desired_error_ratio(0.05)
.build();
Implementations§
source§impl GrowableBloomBuilder
impl GrowableBloomBuilder
sourcepub fn new() -> Self
pub fn new() -> Self
Create a new GrowableBloomBuilder.
Builder API for GrowableBloom.
use growable_bloom_filter::GrowableBloomBuilder;
let mut gbloom = GrowableBloomBuilder::new()
.estimated_insertions(1000)
.desired_error_ratio(0.01)
.growth_factor(2)
.tightening_ratio(0.85)
.build();
gbloom.insert("hello world");
assert!(gbloom.contains(&"hello world"));
sourcepub fn estimated_insertions(self, count: usize) -> Self
pub fn estimated_insertions(self, count: usize) -> Self
Estimated number of insertions. A power of ten accuracy is good enough.
§Panics
This will panic in debug mode if count is zero.
sourcepub fn desired_error_ratio(self, ratio: f64) -> Self
pub fn desired_error_ratio(self, ratio: f64) -> Self
Desired error ratio (i.e. false positive rate).
Smaller error ratios will use more memory and might be a bit slower.
§Panics
This will panic if the error ratio is outside of (0, 1.0).
sourcepub fn growth_factor(self, factor: usize) -> Self
pub fn growth_factor(self, factor: usize) -> Self
Base for the exponential growth factor.
As more items are inserted into a GrowableBloom this growth_factor number is used to exponentially grow the capacity of newly added internal bloom filters. So this number is raised to some exponent proportional to the number of bloom filters held internally.
Basically it’ll control how quickly the bloom filter grows in capacity. By default it’s set to two.
sourcepub fn tightening_ratio(self, ratio: f64) -> Self
pub fn tightening_ratio(self, ratio: f64) -> Self
Control the downwards adjustment on the error ratio when growing.
When GrowableBloom adds a new internal bloom filter it uses the tightening_ratio to adjust the desired_error_ratio on these new, larger internal bloom filters. This is necessary to achieve decent accuracy on the user’s desired error_ratio while using larger and larger bloom filters internally.
By default this library sets it to ~0.85, but for smaller growth factors any number around 0.8 - 0.9 should be fine.
sourcepub fn build(self) -> GrowableBloom
pub fn build(self) -> GrowableBloom
Consume the builder to create a GrowableBloom.
§Panics
This will panic if an invalid value is specified.