pub struct RotatingBloomFilter { /* private fields */ }Expand description
A probabilistic data structure that rotates out old items to maintain recent membership.
RotatingBloomFilter provides membership testing for recently inserted items, with older items
automatically rotating out. Items are guaranteed to be retained for at least the minimum
retention period, and typically remain for up to twice that duration.
Uses a dual-buffer rotation mechanism where items are added to both buffers, and periodically the older buffer is discarded, causing old items to rotate out.
§Examples
let mut filter = RotatingBloomFilter::new(0.001, 1000, &mut OsRng);
filter.insert("hello");
assert!(filter.contains("hello"));
// After 2000 more insertions, "hello" will rotate outImplementations§
Source§impl RotatingBloomFilter
impl RotatingBloomFilter
Sourcepub fn new(
false_pos: f64,
min_retention: usize,
csprng: &mut impl RngCore,
) -> Self
pub fn new( false_pos: f64, min_retention: usize, csprng: &mut impl RngCore, ) -> Self
Creates a new RotatingBloomFilter with a given false positive rate and minimum retention
period.
Sourcepub fn insert(&mut self, value: &(impl Hash + ?Sized)) -> (bool, bool)
pub fn insert(&mut self, value: &(impl Hash + ?Sized)) -> (bool, bool)
Inserts an item into the rotating filter.
Items are guaranteed to be retained for at least the minimum retention period, typically remaining for up to twice that duration before rotating out.
Returns a tuple: (was_in_current, was_in_next)