pub struct ScalableBloomFilter { /* private fields */ }Expand description
Auto-growing Bloom filter that adds new layers when the estimated false-positive rate of the current layer exceeds a threshold.
Each layer is an independent BloomFilter with geometrically increasing
capacity. A contains query checks all layers; an insert goes into the
active (most recent) layer. When the active layer’s estimated FPR exceeds
max_fpr_per_layer, a new layer is allocated with capacity scaled by
growth_factor.
The overall false-positive rate is bounded by the geometric series
p₀ + p₁ + p₂ + … where each pᵢ = max_fpr_per_layer * tightening_ratioⁱ.
With a tightening ratio < 1 (default 0.8) the series converges.
Implementations§
Source§impl ScalableBloomFilter
impl ScalableBloomFilter
Sourcepub fn new(initial_capacity: usize, target_fpr: f64, growth_factor: f64) -> Self
pub fn new(initial_capacity: usize, target_fpr: f64, growth_factor: f64) -> Self
Create a new ScalableBloomFilter.
§Parameters
initial_capacity— expected items for the first layer (must be > 0).target_fpr— target false-positive rate per layer in(0, 1).growth_factor— how much each successive layer grows (>1.0, e.g. 2.0).
Sourcepub fn insert(&mut self, item: &[u8])
pub fn insert(&mut self, item: &[u8])
Insert item into the active (most recent) layer.
If the active layer’s estimated FPR exceeds max_fpr_per_layer after
insertion, a new layer is allocated.
Sourcepub fn contains(&self, item: &[u8]) -> bool
pub fn contains(&self, item: &[u8]) -> bool
Return true if item may be in any layer; false means it
definitely was never inserted.
Sourcepub fn estimate_false_positive_rate(&self) -> f64
pub fn estimate_false_positive_rate(&self) -> f64
Estimate the aggregate false-positive rate across all layers.
The overall FPR is 1 - Π(1 - fprᵢ) (probability of at least one
layer reporting a false positive).
Sourcepub fn total_item_count(&self) -> u64
pub fn total_item_count(&self) -> u64
Return the total number of items inserted across all layers.
Sourcepub fn layer_count(&self) -> usize
pub fn layer_count(&self) -> usize
Return the number of layers currently allocated.
Sourcepub fn set_tightening_ratio(&mut self, ratio: f64)
pub fn set_tightening_ratio(&mut self, ratio: f64)
Set the tightening ratio (must be in (0, 1)).
Each successive layer uses fpr * tightening_ratio^i to keep the
aggregate FPR bounded. A lower ratio means tighter per-layer FPR
targets (more bits per layer).
Sourcepub fn tightening_ratio(&self) -> f64
pub fn tightening_ratio(&self) -> f64
Return the tightening ratio.
Sourcepub fn growth_factor(&self) -> f64
pub fn growth_factor(&self) -> f64
Return the growth factor.
Sourcepub fn layer_stats(&self) -> Vec<(u64, usize, f64)>
pub fn layer_stats(&self) -> Vec<(u64, usize, f64)>
Return per-layer statistics: (item_count, num_bits, estimated_fpr).
Sourcepub fn estimated_capacity_remaining(&self) -> usize
pub fn estimated_capacity_remaining(&self) -> usize
Return the estimated remaining capacity of the active (most recent) layer before it triggers a new layer allocation.
This is approximate: it counts how many more items can be inserted
before the active layer’s estimated FPR exceeds max_fpr_per_layer.
Returns 0 if the active layer has already exceeded its FPR target.
Sourcepub fn total_bits(&self) -> usize
pub fn total_bits(&self) -> usize
Return the total number of bits across all layers.
Trait Implementations§
Source§impl Clone for ScalableBloomFilter
impl Clone for ScalableBloomFilter
Source§fn clone(&self) -> ScalableBloomFilter
fn clone(&self) -> ScalableBloomFilter
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more