pub struct BloomPrescreen {
pub bits: Vec<u64>,
pub k_hashes: u32,
pub num_bits: usize,
/* private fields */
}Expand description
Bloom filter optimised for deduplication pre-screening.
§Example
use oximedia_dedup::bloom_prescreen::BloomPrescreen;
let mut bp = BloomPrescreen::new(1000, 0.01);
bp.insert(b"hello");
assert!(bp.might_contain(b"hello"));
assert!(!bp.might_contain(b"world")); // (with high probability)Fields§
§bits: Vec<u64>Underlying bit storage (each u64 holds 64 bits).
k_hashes: u32Number of independent hash functions.
num_bits: usizeTotal number of addressable bits.
Implementations§
Source§impl BloomPrescreen
impl BloomPrescreen
Sourcepub fn new(capacity: usize, false_positive_rate: f64) -> Self
pub fn new(capacity: usize, false_positive_rate: f64) -> Self
Create a new BloomPrescreen sized for capacity expected items at
the given false_positive_rate.
Uses the standard formulas:
m = ceil(-n * ln(p) / (ln 2)^2)(number of bits)k = round((m / n) * ln 2)(number of hash functions)
Both values are clamped to sensible minimums.
Sourcepub fn insert(&mut self, key: &[u8])
pub fn insert(&mut self, key: &[u8])
Insert key into the filter.
After calling this, might_contain will always
return true for the same key (no false negatives).
Sourcepub fn might_contain(&self, key: &[u8]) -> bool
pub fn might_contain(&self, key: &[u8]) -> bool
Returns true if key might be in the set (possible false positive).
Returns false if key is definitely not in the set.
Sourcepub fn false_positive_rate_estimate(&self) -> f64
pub fn false_positive_rate_estimate(&self) -> f64
Estimate the current false-positive rate given the number of inserted items.
Formula: (1 - e^(-k * n / m))^k
Returns 1.0 when the filter is full.
Sourcepub fn items_inserted(&self) -> u64
pub fn items_inserted(&self) -> u64
Number of items inserted so far.
Sourcepub fn set_bit_count(&self) -> u64
pub fn set_bit_count(&self) -> u64
Number of set bits (useful for diagnostics).
Trait Implementations§
Source§impl Clone for BloomPrescreen
impl Clone for BloomPrescreen
Source§fn clone(&self) -> BloomPrescreen
fn clone(&self) -> BloomPrescreen
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for BloomPrescreen
impl RefUnwindSafe for BloomPrescreen
impl Send for BloomPrescreen
impl Sync for BloomPrescreen
impl Unpin for BloomPrescreen
impl UnsafeUnpin for BloomPrescreen
impl UnwindSafe for BloomPrescreen
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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