pub struct BloomFilter { /* private fields */ }Expand description
Bloom filter for fast negative lookups False positive rate: ~1% with 3 hash functions
Implementations§
Source§impl BloomFilter
impl BloomFilter
Sourcepub fn new(size: u32, num_hashes: u8) -> BloomFilter
pub fn new(size: u32, num_hashes: u8) -> BloomFilter
Create new bloom filter with given size in bits
Sourcepub fn with_capacity(elements: usize, false_positive_rate: f64) -> BloomFilter
pub fn with_capacity(elements: usize, false_positive_rate: f64) -> BloomFilter
Create bloom filter optimized for expected number of elements Formula: size = -n * ln(p) / (ln(2)^2) Where n = elements, p = false positive rate (0.01 = 1%)
Sourcepub fn contains(&self, key: &[u8]) -> bool
pub fn contains(&self, key: &[u8]) -> bool
Check if key might exist (false positive possible, no false negative)
Sourcepub fn from_bytes(bytes: Vec<u8>, num_hashes: u8) -> BloomFilter
pub fn from_bytes(bytes: Vec<u8>, num_hashes: u8) -> BloomFilter
Load from raw bytes
Sourcepub fn from_bytes_with_size(
bytes: Vec<u8>,
num_hashes: u8,
size: u32,
) -> BloomFilter
pub fn from_bytes_with_size( bytes: Vec<u8>, num_hashes: u8, size: u32, ) -> BloomFilter
Load from raw bytes with an explicit original bit size.
Use this when from_bytes would lose the declared size (when the
original size was not a multiple of 8). The hash functions reduce
positions modulo size, so restoring with a different value would
produce false negatives.
Sourcepub fn estimate_fp_rate(&self, inserted_count: usize) -> f64
pub fn estimate_fp_rate(&self, inserted_count: usize) -> f64
Estimate false positive rate based on current fill
Sourcepub fn count_set_bits(&self) -> u32
pub fn count_set_bits(&self) -> u32
Get number of set bits
Sourcepub fn fill_ratio(&self) -> f64
pub fn fill_ratio(&self) -> f64
Calculate fill ratio (0.0 to 1.0)
Sourcepub fn merge(&self, other: &BloomFilter) -> Option<BloomFilter>
pub fn merge(&self, other: &BloomFilter) -> Option<BloomFilter>
Merge two bloom filters via bitwise OR.
Returns None if the filters have different size or hash count.
Sourcepub fn union_inplace(&mut self, other: &BloomFilter) -> bool
pub fn union_inplace(&mut self, other: &BloomFilter) -> bool
Merge another bloom filter into this one in-place.
Returns false if the filters are incompatible (different size/hashes).
Sourcepub fn num_hashes(&self) -> u8
pub fn num_hashes(&self) -> u8
Get the number of hash functions
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
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 moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request