pub struct BloomFilter { /* private fields */ }Expand description
Bloom filter for fast probabilistic existence checks.
Uses multiple hash functions to minimize false positives while maintaining constant-time lookups regardless of dataset size.
Implementations§
Source§impl BloomFilter
impl BloomFilter
Sourcepub fn new(expected_items: usize, false_positive_rate: f64) -> Self
pub fn new(expected_items: usize, false_positive_rate: f64) -> Self
Create a new bloom filter with the given expected item count and false positive rate.
§Arguments
expected_items- Expected number of items to be storedfalse_positive_rate- Desired false positive rate (0.0 - 1.0)
Sourcepub fn with_config(config: BloomConfig) -> Self
pub fn with_config(config: BloomConfig) -> Self
Create a bloom filter with custom configuration
Sourcepub fn insert_cid(&self, cid: &Cid)
pub fn insert_cid(&self, cid: &Cid)
Insert a CID into the bloom filter
Sourcepub fn contains_cid(&self, cid: &Cid) -> bool
pub fn contains_cid(&self, cid: &Cid) -> bool
Check if a CID might be in the bloom filter
Returns true if the CID might be present (may be a false positive),
Returns false if the CID is definitely not present.
Sourcepub fn fill_ratio(&self) -> f64
pub fn fill_ratio(&self) -> f64
Get the fill ratio (proportion of bits set)
Sourcepub fn estimated_fpr(&self) -> f64
pub fn estimated_fpr(&self) -> f64
Estimate the actual false positive rate based on current fill
Sourcepub fn memory_bytes(&self) -> usize
pub fn memory_bytes(&self) -> usize
Get memory usage in bytes
Sourcepub fn save_to_file(&self, path: &Path) -> Result<()>
pub fn save_to_file(&self, path: &Path) -> Result<()>
Save the bloom filter to a file
Sourcepub fn load_from_file(path: &Path, config: BloomConfig) -> Result<Self>
pub fn load_from_file(path: &Path, config: BloomConfig) -> Result<Self>
Load the bloom filter from a file
Sourcepub fn stats(&self) -> BloomStats
pub fn stats(&self) -> BloomStats
Get bloom filter statistics
Source§impl BloomFilter
Convenience constructor: create a BloomFilter backed by a fixed bit-count.
impl BloomFilter
Convenience constructor: create a BloomFilter backed by a fixed bit-count.
Rounds bits up to the next multiple of 64 and uses a two-hash (FNV-1a +
multiplicative) scheme with 7 probes — chosen for ~1 % FPR at 100 k elements
in a 1 M-bit filter.
Sourcepub fn new_with_bits(bits: usize) -> Self
pub fn new_with_bits(bits: usize) -> Self
Create a filter with exactly bits capacity (rounded up to 64-bit boundary).
Uses a fixed 7-probe two-hash scheme suitable for general-purpose deduplication.
Sourcepub fn is_bloom_empty(&self) -> bool
pub fn is_bloom_empty(&self) -> bool
Whether no elements have been inserted (semantic alias, kept for test clarity).
Sourcepub fn may_contain(&self, key: &[u8]) -> bool
pub fn may_contain(&self, key: &[u8]) -> bool
Probabilistic check: returns false iff the key is definitely absent.
Sourcepub fn estimated_fill_ratio(&self) -> f64
pub fn estimated_fill_ratio(&self) -> f64
Fraction of bits currently set (0.0 – 1.0).
Auto Trait Implementations§
impl !Freeze for BloomFilter
impl !RefUnwindSafe for BloomFilter
impl Send for BloomFilter
impl Sync for BloomFilter
impl Unpin for BloomFilter
impl UnsafeUnpin for BloomFilter
impl UnwindSafe for BloomFilter
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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>
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>
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