Skip to main content

ScalableBloomFilter

Struct ScalableBloomFilter 

Source
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

Source

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).
Source

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.

Source

pub fn contains(&self, item: &[u8]) -> bool

Return true if item may be in any layer; false means it definitely was never inserted.

Source

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).

Source

pub fn total_item_count(&self) -> u64

Return the total number of items inserted across all layers.

Source

pub fn layer_count(&self) -> usize

Return the number of layers currently allocated.

Source

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).

Source

pub fn tightening_ratio(&self) -> f64

Return the tightening ratio.

Source

pub fn growth_factor(&self) -> f64

Return the growth factor.

Source

pub fn layer_stats(&self) -> Vec<(u64, usize, f64)>

Return per-layer statistics: (item_count, num_bits, estimated_fpr).

Source

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.

Source

pub fn clear(&mut self)

Clear all layers and reset to a single fresh layer.

Source

pub fn total_bits(&self) -> usize

Return the total number of bits across all layers.

Trait Implementations§

Source§

impl Clone for ScalableBloomFilter

Source§

fn clone(&self) -> ScalableBloomFilter

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ScalableBloomFilter

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.