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

source

pub fn new(size: usize, nhashes: usize) -> Self

Create a new BloomFilter with size entries, using nhashes hash functions.

source

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.

source

pub fn compute_nhashes(p: f64) -> usize

Compute required number of hash functions for false positive probability p.

source

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.

source

pub fn len(&self) -> usize

Get the number of bins in this BloomFilter.

source

pub fn nhashes(&self) -> usize

Get the number of hash functions in this BloomFilter.

source

pub fn bins(&self) -> &[bool]

Get bloom filter bins.

source

pub fn as_bytes(&self) -> Vec<u8>

Get bloom filter bins packed in bytes.

source

pub fn from_bytes(bytes: &[u8], size: usize, nhashes: usize) -> Self

Create bloom filter from bytes.

source

pub fn bin<V: AsRef<[u8]>>(value: &V, hash_index: usize) -> usize

Compute the bin that this value would go to in a BloomFilter.

Result must be modded by the actual size of the bloom filter to avoid out of bounds errors.

source

pub fn insert<V: AsRef<[u8]>>(&mut self, value: &V)

Insert an item into the BloomFilter.

source

pub fn contains<V: AsRef<[u8]>>(&mut self, value: &V) -> bool

Check whether an item exists in the BloomFilter.

Trait Implementations§

source§

impl Debug for BloomFilter

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl PartialEq for BloomFilter

source§

fn eq(&self, other: &BloomFilter) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialOrd for BloomFilter

source§

fn partial_cmp(&self, other: &BloomFilter) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

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 more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl StructuralPartialEq for BloomFilter

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V