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
Auto Trait Implementations§
impl !Freeze for BloomFilter
impl !RefUnwindSafe for BloomFilter
impl Send for BloomFilter
impl Sync for BloomFilter
impl Unpin 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
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