BloomBuilder

Struct BloomBuilder 

Source
pub struct BloomBuilder<T: AsRef<[u8]>> { /* private fields */ }
Expand description

Provides a way to build a bloom filter with optional fields, such as customizing the Hasher used or the number of hash functions used in its representation. Will use a DefaultHasher if no other hasher is specified, and will use the optimal number of hash functions depending on the number of items by default.

§Example

use std::io::Read;
use sha3::{Digest, Sha3_512};
use flowerbloom::{BloomBuilder, BloomFilter, Hasher};

pub struct CustomHasher {}
impl<T: AsRef<[u8]>> Hasher<T> for CustomHasher {
    fn hash(item: &T) -> u64 {
        let mut hasher = Sha3_512::new();
        hasher.update(item);
        let result = hasher.finalize();
        let mut buf = [0; 8];
        let mut handle = result.take(8);
        handle.read_exact(&mut buf).unwrap();
        u64::from_be_bytes(buf)
    }
}
let capacity: u32 = 50;
let fp_rate: f32 = 0.03;
let mut bf: BloomFilter<&str> = BloomBuilder::new(capacity, fp_rate)
    .hasher::<CustomHasher>()
    .build();
bf.insert("hello");
bf.insert("world");
let _ = bf.has("nyan");

Implementations§

Source§

impl<T: AsRef<[u8]>> BloomBuilder<T>

Source

pub fn new(capacity: u32, fp_rate: f32) -> BloomBuilder<T>

Source

pub fn hasher<H: Hasher<T>>(self) -> BloomBuilder<T>

Source

pub fn build(self) -> BloomFilter<T>

Auto Trait Implementations§

§

impl<T> Freeze for BloomBuilder<T>

§

impl<T> RefUnwindSafe for BloomBuilder<T>

§

impl<T> Send for BloomBuilder<T>

§

impl<T> Sync for BloomBuilder<T>

§

impl<T> Unpin for BloomBuilder<T>

§

impl<T> UnwindSafe for BloomBuilder<T>

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

Source§

type Output = T

Should always be Self
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.