pub struct BloomFilter {
pub size: u16,
pub num_hashes: u8,
pub bits: Vec<u8>,
}Expand description
Per-file bloom filter for fast trigram membership testing.
Uses a 256-byte bitset with 5 independent hashes, yielding a false-positive rate of ~0.7% for up to 200 trigrams.
Fields§
§size: u16Size of the bit array in bytes.
num_hashes: u8Number of hash functions (k).
bits: Vec<u8>The bit array backing the filter.
Implementations§
Source§impl BloomFilter
impl BloomFilter
Sourcepub fn new(size: usize, num_hashes: u8) -> Self
pub fn new(size: usize, num_hashes: u8) -> Self
Create a new bloom filter with the given size and number of hash functions.
Sourcepub fn contains(&self, trigram: Trigram) -> bool
pub fn contains(&self, trigram: Trigram) -> bool
Check if a trigram may be present in the filter.
Returns true if the trigram might be present (could be a false positive).
Returns false only if the trigram is definitely not present.
Trait Implementations§
Source§impl Clone for BloomFilter
impl Clone for BloomFilter
Source§fn clone(&self) -> BloomFilter
fn clone(&self) -> BloomFilter
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto 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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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