pub struct BloomFilter { /* private fields */ }Expand description
Probabilistic set membership test for string terms.
Optimized for the BM25 file-pruning use case: insert all tokenized terms from a data file at write time; at search time, check whether any query term may be present. False positives keep the file (safe); false negatives are impossible.
Implementations§
Source§impl BloomFilter
impl BloomFilter
Sourcepub fn with_capacity(capacity: usize, fpr: f64) -> Self
pub fn with_capacity(capacity: usize, fpr: f64) -> Self
Construct a Bloom filter sized for capacity items at fpr false-positive rate.
Formula: m = -n * ln(p) / ln(2)², rounded up to the next 64-bit boundary.
A capacity=10_000, fpr=0.01 filter uses ~12 KB of bit storage.
pub fn insert(&mut self, term: &str)
Sourcepub fn may_contain(&self, term: &str) -> bool
pub fn may_contain(&self, term: &str) -> bool
Returns true if term might be in the set (false positives possible).
Returns false only when the term is definitely absent.
Sourcepub fn to_bytes(&self) -> Vec<u8> ⓘ
pub fn to_bytes(&self) -> Vec<u8> ⓘ
Serialize to bytes: u64_le(num_bits) || u64_le(word_0) || ... || u64_le(word_N).
Sourcepub fn from_bytes(bytes: &[u8]) -> Option<Self>
pub fn from_bytes(bytes: &[u8]) -> Option<Self>
Deserialize from bytes produced by to_bytes. Returns None on malformed input.
pub fn num_bits(&self) -> usize
Trait Implementations§
Source§impl Clone for BloomFilter
impl Clone for BloomFilter
Source§fn clone(&self) -> BloomFilter
fn clone(&self) -> BloomFilter
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 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§
impl<T> Allocation for T
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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>
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