Struct RotatingBloomFilter

Source
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 out

Implementations§

Source§

impl RotatingBloomFilter

Source

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.

Source

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)

Source

pub fn contains(&self, value: &(impl Hash + ?Sized)) -> bool

Tests whether an item might be present in the current rotation.

May return false positives but never false negatives.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.