pub struct BloomFilterCascade { /* private fields */ }Expand description
Cascaded bloom filters with decreasing false positive rates
§Design
Organizes multiple bloom filters in a cascade where:
- First filter (L0): Smallest, catches most negatives quickly
- Subsequent filters: Progressively lower FPR for items that pass
§Benefits
- Fast rejection of non-existent keys (first filter catches ~99%)
- Lower overall FPR than single filter for same memory budget
- Amortized O(1) lookup with early termination
§Example Configuration
L0: 1% FPR, 100KB → Catches 99% of negatives
L1: 0.1% FPR, 50KB → Catches 99.9% of remaining
L2: 0.01% FPR, 25KB → Final filter for edge cases
Combined FPR: 0.01 * 0.001 * 0.0001 = 0.000000001 (1 in billion)Implementations§
Source§impl BloomFilterCascade
impl BloomFilterCascade
Sourcepub fn new(expected_items: usize, level_fprs: Vec<f64>) -> Self
pub fn new(expected_items: usize, level_fprs: Vec<f64>) -> Self
Create a new cascade with specified levels
§Arguments
expected_items- Number of items to storelevel_fprs- False positive rate for each level (e.g., [0.01, 0.001, 0.0001])
Sourcepub fn default_cascade(expected_items: usize) -> Self
pub fn default_cascade(expected_items: usize) -> Self
Create default 3-level cascade
- L0: 1% FPR (fast initial check)
- L1: 0.1% FPR (medium precision)
- L2: 0.01% FPR (high precision)
Sourcepub fn contains<T: Hash>(&self, item: &T) -> bool
pub fn contains<T: Hash>(&self, item: &T) -> bool
Check if item might exist (with early termination)
Returns false (definitely not present) as soon as any level returns false. Returns true only if ALL levels return true.
Sourcepub fn contains_with_level<T: Hash>(&self, item: &T) -> (bool, usize)
pub fn contains_with_level<T: Hash>(&self, item: &T) -> (bool, usize)
Check with level tracking (for debugging/stats)
Sourcepub fn combined_fpr(&self) -> f64
pub fn combined_fpr(&self) -> f64
Combined theoretical false positive rate
Sourcepub fn num_levels(&self) -> usize
pub fn num_levels(&self) -> usize
Number of cascade levels
Sourcepub fn memory_usage(&self) -> usize
pub fn memory_usage(&self) -> usize
Memory usage in bytes
Sourcepub fn from_bytes(bytes: &[u8]) -> Result<Self>
pub fn from_bytes(bytes: &[u8]) -> Result<Self>
Deserialize from bytes
Trait Implementations§
Auto Trait Implementations§
impl Freeze for BloomFilterCascade
impl RefUnwindSafe for BloomFilterCascade
impl Send for BloomFilterCascade
impl Sync for BloomFilterCascade
impl Unpin for BloomFilterCascade
impl UnsafeUnpin for BloomFilterCascade
impl UnwindSafe for BloomFilterCascade
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more