Struct FilterBuilder

Source
pub struct FilterBuilder {
    pub expected_elements: u64,
    pub false_positive_probability: f64,
    pub size: u64,
    pub hashes: u32,
    pub enable_repeat_insert: bool,
    /* private fields */
}
Expand description

Builder for Bloom Filters.

Fields§

§expected_elements: u64§false_positive_probability: f64§size: u64§hashes: u32§enable_repeat_insert: bool

Usage for CountingBloomFilter.

Implementations§

Source§

impl FilterBuilder

Source

pub fn new(expected_elements: u64, false_positive_probability: f64) -> Self

Constructs a new Bloom Filter Builder by specifying the expected size of the filter and the tolerable false positive probability. The size of the BLoom filter in in bits and the optimal number of hash functions will be inferred from this.

§Examples
use fastbloom_rs::FilterBuilder;
let mut builder = FilterBuilder::new(100_000_000, 0.01);
let bloom = builder.build_bloom_filter();
Source

pub fn from_size_and_hashes(size: u64, hashes: u32) -> Self

Constructs a new Bloom Filter Builder by specifying the size of the bloom filter in bits and the number of hashes. The expected size of the filter and the tolerable false positive probability will be inferred from this.

Source

pub fn enable_repeat_insert(&mut self, enable: bool)

Use for CountingBloomFilter.

§Example:
use fastbloom_rs::{Deletable, FilterBuilder, Membership};

let mut builder = FilterBuilder::new(100_000, 0.01);
// enable_repeat_insert is true
builder.enable_repeat_insert(true);
let mut cbf = builder.build_counting_bloom_filter();
cbf.add(b"hello"); // modify underlying vector counter.
cbf.add(b"hello"); // modify underlying vector counter.
assert_eq!(cbf.contains(b"hello"), true);
cbf.remove(b"hello");
assert_eq!(cbf.contains(b"hello"), true);
cbf.remove(b"hello");
assert_eq!(cbf.contains(b"hello"), false);

// enable_repeat_insert is false
builder.enable_repeat_insert(false);
let mut cbf = builder.build_counting_bloom_filter();
cbf.add(b"hello"); // modify underlying vector counter.
cbf.add(b"hello"); // not modify underlying vector counter because b"hello" has been added.
assert_eq!(cbf.contains(b"hello"), true);
cbf.remove(b"hello");
assert_eq!(cbf.contains(b"hello"), false);
Source

pub fn build_bloom_filter(&mut self) -> BloomFilter

Constructs a Bloom filter using the specified parameters and computing missing parameters if possible (e.g. the optimal Bloom filter bit size).

Source

pub fn build_counting_bloom_filter(&mut self) -> CountingBloomFilter

Constructs a Counting Bloom filter using the specified parameters and computing missing parameters if possible (e.g. the optimal Bloom filter bit size).

Trait Implementations§

Source§

impl Clone for FilterBuilder

Source§

fn clone(&self) -> FilterBuilder

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for FilterBuilder

Source§

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

Formats the value using the given formatter. Read more

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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,

Source§

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

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.