pub struct BloomFilter { /* private fields */ }
Expand description

A space efficient approximate membership set data structure. False positives from contains are possible, but false negatives are not, i.e. contains for all items in the set is guaranteed to return true, while contains for all items not in the set probably return false.

BloomFilter is supported by an underlying bit vector, chunked into 512 bit “blocks”, to track item membership. To insert, a number of bits, based on the item’s hash, are set in the underlying bit vector. To check membership, a number of bits, based on the item’s hash, are checked in the underlying bit vector.

Once constructed, a bloom filter’s underlying memory usage or number of bits per item does not change.

Examples

use b100m_filter::BloomFilter;

let num_blocks = 4; // each block is 64 bytes, 512 bits
let values = vec!["42", "bloom"];

let mut filter = BloomFilter::builder(num_blocks).items(values.iter());
filter.insert("qwerty");
assert!(filter.contains("42"));
assert!(filter.contains("bloom"));
assert!(filter.contains("qwerty"));

Implementations§

source§

impl BloomFilter

source

pub fn builder(num_blocks: usize) -> Builder

Creates a new instance of Builder to construct a BloomFilter with num_blocks number of blocks for tracking item membership. Each block is 512 bits of memory.

Examples
use b100m_filter::{BloomFilter, Builder};

let builder: Builder = BloomFilter::builder(16);
let bloom: BloomFilter = builder.hashes(4);
source

pub fn num_hashes(&self) -> u64

Returns the number of bits derived per item for the bloom filter. This number is effectivly the number of hashes per item, but all hashes are not actually performed.

The returned value is always a multiple of 4 due to internal optimizations.

source

pub fn insert(&mut self, val: &(impl Hash + ?Sized))

Adds a value to the bloom filter.

Examples
use b100m_filter::BloomFilter;

let mut bloom = BloomFilter::builder(4).hashes(4);
bloom.insert(&2);
assert!(bloom.contains(&2));
source

pub fn contains(&self, val: &(impl Hash + ?Sized)) -> bool

Returns false if the bloom filter definitely does not contain a value. Returns true if the bloom filter may contain a value, with a degree of certainty.

Examples
use b100m_filter::BloomFilter;

let bloom = BloomFilter::builder(4).items([1, 2, 3].iter());
assert!(bloom.contains(&1));

Trait Implementations§

source§

impl Clone for BloomFilter

source§

fn clone(&self) -> BloomFilter

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for BloomFilter

source§

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

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

impl<T> Extend<T> for BloomFilter
where T: Hash,

source§

fn extend<I: IntoIterator<Item = T>>(&mut self, iter: I)

Extends a collection with the contents of an iterator. Read more
source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
source§

impl PartialEq for BloomFilter

source§

fn eq(&self, other: &Self) -> 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 Eq 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> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.