pub struct BloomFilter {
pub bits: Vec<u64>,
pub num_hashes: u32,
pub bit_count: u64,
}Expand description
A counting-free Bloom filter backed by a Vec<u64> bit array.
Insert items and test membership with a configurable false-positive rate. Deletions are not supported (standard Bloom filter design).
Fields§
§bits: Vec<u64>Bit storage (each u64 holds 64 bits).
num_hashes: u32Number of independent hash functions.
bit_count: u64Total number of bits (length of the logical bit array).
Implementations§
Source§impl BloomFilter
impl BloomFilter
Sourcepub fn new(capacity: usize, false_positive_rate: f32) -> Self
pub fn new(capacity: usize, false_positive_rate: f32) -> Self
Create a new Bloom filter sized for capacity items at a given false_positive_rate.
Uses the standard formulas:
m = -n * ln(p) / (ln(2))^2(number of bits)k = (m / n) * ln(2)(number of hash functions)
Sourcepub fn contains(&self, item: &[u8]) -> bool
pub fn contains(&self, item: &[u8]) -> bool
Returns true if item may be in the set (possible false positive).
Returns false if item is definitely not in the set.
Sourcepub fn estimated_count(&self) -> usize
pub fn estimated_count(&self) -> usize
Estimate the number of items inserted using the formula:
n̂ = -m / k * ln(1 - X / m)
where X is the number of set bits.
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
Mutably borrows from an owned value. Read more
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