[go: up one dir, main page]

Struct fastbloom::Builder

source ·
pub struct Builder<const BLOCK_SIZE_BITS: usize = 512, S = DefaultHasher> { /* private fields */ }
Expand description

A bloom filter builder.

This type can be used to construct an instance of BloomFilter via the builder pattern.

  1. First, the Builder is initialized from some specification of underlying memory, either number of bits or raw vec data:
  1. Some optional modifications can be made, such as setting the seed (only for DefaultHasher) or setting the hasher:
  1. Lastly, the builder is “consumed” and a BloomFilter is built from a direct or indirect specification for number of hashes:

Implementations§

source§

impl<const BLOCK_SIZE_BITS: usize> Builder<BLOCK_SIZE_BITS>

source

pub fn seed(self, seed: &u128) -> Self

Sets the seed for this builder. The later constructed BloomFilter will use this seed when hashing items.

§Examples
use fastbloom::BloomFilter;

let bloom = BloomFilter::builder(1024).seed(&1).hashes(4);
source§

impl<const BLOCK_SIZE_BITS: usize, S: BuildHasher> Builder<BLOCK_SIZE_BITS, S>

source

pub fn hasher<H: BuildHasher>(self, hasher: H) -> Builder<BLOCK_SIZE_BITS, H>

Sets the hasher for this builder. The later constructed BloomFilter will use this hasher when inserting and checking items.

§Examples
use fastbloom::BloomFilter;
use ahash::RandomState;

let bloom = BloomFilter::builder(1024).hasher(RandomState::default()).hashes(4);
source

pub fn hashes(self, num_hashes: u32) -> BloomFilter<BLOCK_SIZE_BITS, S>

“Consumes” this builder, using the provided num_hashes to return an empty BloomFilter.

§Examples
use fastbloom::BloomFilter;

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

pub fn expected_items( self, expected_num_items: usize ) -> BloomFilter<BLOCK_SIZE_BITS, S>

“Consumes” this builder, using the provided expected_num_items to return an empty BloomFilter. The number of hashes is optimized based on expected_num_items to maximize bloom filter accuracy (minimize false positives chance on BloomFilter::contains). More or less than expected_num_items may be inserted into BloomFilter.

§Examples
use fastbloom::BloomFilter;

let bloom = BloomFilter::builder(1024).expected_items(500);
source

pub fn items<I: IntoIterator<IntoIter = impl ExactSizeIterator<Item = impl Hash>>>( self, items: I ) -> BloomFilter<BLOCK_SIZE_BITS, S>

“Consumes” this builder and constructs a BloomFilter containing all values in items. Like Builder::expected_items, the number of hashes per item is optimized based on items.len() to maximize bloom filter accuracy (minimize false positives chance on BloomFilter::contains).

§Examples
use fastbloom::BloomFilter;

let bloom = BloomFilter::builder(1024).items([1, 2, 3]);

Trait Implementations§

source§

impl<const BLOCK_SIZE_BITS: usize, S: Clone> Clone for Builder<BLOCK_SIZE_BITS, S>

source§

fn clone(&self) -> Builder<BLOCK_SIZE_BITS, S>

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<const BLOCK_SIZE_BITS: usize, S: Debug> Debug for Builder<BLOCK_SIZE_BITS, S>

source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<const BLOCK_SIZE_BITS: usize, S> RefUnwindSafe for Builder<BLOCK_SIZE_BITS, S>
where S: RefUnwindSafe,

§

impl<const BLOCK_SIZE_BITS: usize, S> Send for Builder<BLOCK_SIZE_BITS, S>
where S: Send,

§

impl<const BLOCK_SIZE_BITS: usize, S> Sync for Builder<BLOCK_SIZE_BITS, S>
where S: Sync,

§

impl<const BLOCK_SIZE_BITS: usize, S> Unpin for Builder<BLOCK_SIZE_BITS, S>
where S: Unpin,

§

impl<const BLOCK_SIZE_BITS: usize, S> UnwindSafe for Builder<BLOCK_SIZE_BITS, S>
where S: 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> 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.
source§

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

source§

fn vzip(self) -> V