BloomFilter

Struct BloomFilter 

Source
pub struct BloomFilter<T> { /* private fields */ }
Expand description

BloomFilter

An implementation of a bloom filter

Implementations§

Source§

impl<T: BloomHasher> BloomFilter<T>

Source

pub fn new(hasher: T, k: u32, array_size: u64) -> Self

Create a new BloomFilter given a hasher, the number of hash functions to use, and the size of the underlying bit array.

Typically, this function should not be called directly unless, the optimal number of hash functions and optimal array size are already known.

Source

pub fn optimal(hasher: T, max_elements: u64, error_rate: f64) -> Self

Create a BloomFilter by computing its optimal parameters.

This function computes the optimal array size using

-(n * ln(p)) / ln(2) ^ 2

and computes the optimal number of hash functions using

m / n * ln(2)
Source

pub fn insert(&mut self, bytes: &[u8])

Insert a slice of bytes into the BloomFilter.

Source

pub fn insert_all<B: AsRef<[u8]>>(&mut self, slice: &[B])

Insert a slice of slices of bytes into the BloomFilter.

Source

pub fn contains<B: AsRef<[u8]>>(&self, bytes: B) -> bool

Check whether a slice of bytes exists in the BloomFilter.

This is a probabilistic function that may return a false positive but will never return a false negative.

§Examples
extern crate bloom_filter_rs as bloom_filter;

use std::vec::Vec;
use bloom_filter::{BloomFilter, Murmur3};

let words = vec!["Hello", "I", "am", "some", "words"];

let mut bloom_filter = BloomFilter::optimal(Murmur3, words.len() as u64, 0.01);

bloom_filter.insert_all(&words);

for word in words.iter() {
    assert!(bloom_filter.contains(&word));
}
Source

pub fn false_positive_rate(&self) -> f64

Calculate the expected false positive rate given the current state of the BloomFilter.

Auto Trait Implementations§

§

impl<T> Freeze for BloomFilter<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for BloomFilter<T>
where T: RefUnwindSafe,

§

impl<T> Send for BloomFilter<T>
where T: Send,

§

impl<T> Sync for BloomFilter<T>
where T: Sync,

§

impl<T> Unpin for BloomFilter<T>
where T: Unpin,

§

impl<T> UnwindSafe for BloomFilter<T>
where T: UnwindSafe,

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

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>,

Source§

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.