Struct scuttlebutt::bloomfilter::BloomFilter
source · pub struct BloomFilter { /* private fields */ }
Expand description
Simple implementation of a Bloom Filter. Which is guaranteed to return 1 if an element is in the set, but returns 1 with probability p (settable) if an item is not in the set. Does not reveal what is in the set.
Implementations§
source§impl BloomFilter
impl BloomFilter
sourcepub fn new(size: usize, nhashes: usize) -> Self
pub fn new(size: usize, nhashes: usize) -> Self
Create a new BloomFilter with size
entries, using nhashes
hash functions.
sourcepub fn compute_expansion(p: f64) -> f64
pub fn compute_expansion(p: f64) -> f64
Compute required expansion for false positive probability p
.
That is - if you plan to insert n
items into the BloomFilter, and want a false
positive probability of p
, then you should set the BloomFilter size to
compute_expansion(p) * n
.
sourcepub fn compute_nhashes(p: f64) -> usize
pub fn compute_nhashes(p: f64) -> usize
Compute required number of hash functions for false positive probability p
.
sourcepub fn with_false_positive_prob(p: f64, n: usize) -> Self
pub fn with_false_positive_prob(p: f64, n: usize) -> Self
Create a new BloomFilter with false positive probability p
which can support up
to n
insertions.
sourcepub fn from_bytes(bytes: &[u8], size: usize, nhashes: usize) -> Self
pub fn from_bytes(bytes: &[u8], size: usize, nhashes: usize) -> Self
Create bloom filter from bytes.
Trait Implementations§
source§impl Debug for BloomFilter
impl Debug for BloomFilter
source§impl PartialEq for BloomFilter
impl PartialEq for BloomFilter
source§fn eq(&self, other: &BloomFilter) -> bool
fn eq(&self, other: &BloomFilter) -> bool
This method tests for
self
and other
values to be equal, and is used
by ==
.source§impl PartialOrd for BloomFilter
impl PartialOrd for BloomFilter
source§fn partial_cmp(&self, other: &BloomFilter) -> Option<Ordering>
fn partial_cmp(&self, other: &BloomFilter) -> Option<Ordering>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for
self
and other
) and is used by the <=
operator. Read moreimpl StructuralPartialEq for BloomFilter
Auto Trait Implementations§
impl Freeze for BloomFilter
impl RefUnwindSafe for BloomFilter
impl Send for BloomFilter
impl Sync for BloomFilter
impl Unpin 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