pub struct CountingBloomFilter { /* private fields */ }Expand description
Bloom filter with 4-bit saturating counters that supports deletion.
Each logical bit-position in the standard filter is replaced by a 4-bit counter stored in nibbles (two counters per byte). A counter saturates at 15 to prevent overflow; decrement is a no-op on saturated counters (a conservative choice that avoids spurious false-negatives).
Implementations§
Source§impl CountingBloomFilter
impl CountingBloomFilter
Sourcepub fn new(expected_items: usize, false_positive_rate: f64) -> Self
pub fn new(expected_items: usize, false_positive_rate: f64) -> Self
Construct a new CountingBloomFilter optimised for the given parameters.
Sourcepub fn insert(&mut self, item: &[u8])
pub fn insert(&mut self, item: &[u8])
Insert item into the filter, incrementing all associated counters.
Sourcepub fn remove(&mut self, item: &[u8]) -> bool
pub fn remove(&mut self, item: &[u8]) -> bool
Attempt to remove item from the filter by decrementing all associated
counters.
Returns true if the item was (probably) present and all counters could
be safely decremented. Returns false if any counter was already zero
(item was never inserted, or already removed) or if any counter is
saturated (the decrement is withheld).
Sourcepub fn item_count(&self) -> u64
pub fn item_count(&self) -> u64
Return the number of items currently represented in the filter.
Sourcepub fn estimate_false_positive_rate(&self) -> f64
pub fn estimate_false_positive_rate(&self) -> f64
Estimate false-positive rate (same formula as BloomFilter).
Trait Implementations§
Source§impl Clone for CountingBloomFilter
impl Clone for CountingBloomFilter
Source§fn clone(&self) -> CountingBloomFilter
fn clone(&self) -> CountingBloomFilter
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more