pub struct SharedBloomFilter { /* private fields */ }Implementations§
Sourcepub fn suggest_config(n_items: usize, p: f64) -> (usize, u32)
pub fn suggest_config(n_items: usize, p: f64) -> (usize, u32)
Suggest n_bits and n_hashes for a target false-positive rate
p and expected item count n. Both rounded up.
Sourcepub fn create(
base_path: impl AsRef<Path>,
n_bits: usize,
n_hashes: u32,
) -> Result<Self, BloomError>
pub fn create( base_path: impl AsRef<Path>, n_bits: usize, n_hashes: u32, ) -> Result<Self, BloomError>
Obtain the filter at base_path, initializing an empty one if
its files do not yet exist and attaching to them if they do.
Attaching leaves inserted members in place; a region built with
a different n_bits or n_hashes is a LayoutMismatch.
reset reinitializes.
Sourcepub fn reset(
base_path: impl AsRef<Path>,
n_bits: usize,
n_hashes: u32,
) -> Result<Self, BloomError>
pub fn reset( base_path: impl AsRef<Path>, n_bits: usize, n_hashes: u32, ) -> Result<Self, BloomError>
Truncate both of the filter’s files at base_path and
initialize an empty one, discarding every member live peers
share. For a caller that knows it owns the path.
pub fn open( base_path: impl AsRef<Path>, n_bits: usize, n_hashes: u32, ) -> Result<Self, BloomError>
pub fn n_bits(&self) -> u64
pub fn n_hashes(&self) -> u32
pub fn insert(&self, item: &[u8]) -> Result<(), BloomError>
Sourcepub fn contains(&self, item: &[u8]) -> Result<bool, BloomError>
pub fn contains(&self, item: &[u8]) -> Result<bool, BloomError>
True if item MIGHT be in the set; false if definitely not.
False positives are possible; false negatives are NOT.
Sourcepub fn estimated_false_positive_rate(&self) -> f64
pub fn estimated_false_positive_rate(&self) -> f64
Estimate the current false-positive rate from the bit-set density. Returns 0.0 for an empty filter; approaches 1.0 as the filter saturates.
Sourcepub fn estimated_insert_count(&self) -> u64
pub fn estimated_insert_count(&self) -> u64
Estimate the number of distinct inserted items based on bit
density. Formula: -n_bits / n_hashes * ln(1 - fill / n_bits).