Struct fastbloom::BuilderWithBits
source · pub struct BuilderWithBits<const BLOCK_SIZE_BITS: usize = 512, S = DefaultHasher> { /* private fields */ }Expand description
A bloom filter builder with an immutable number of bits.
This type can be used to construct an instance of BloomFilter via the builder pattern.
§Examples
use fastbloom::BloomFilter;
let builder = BloomFilter::with_num_bits(1024);
let builder = BloomFilter::from_vec(vec![0; 8]);Implementations§
source§impl<const BLOCK_SIZE_BITS: usize> BuilderWithBits<BLOCK_SIZE_BITS>
impl<const BLOCK_SIZE_BITS: usize> BuilderWithBits<BLOCK_SIZE_BITS>
sourcepub fn seed(self, seed: &u128) -> Self
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::with_num_bits(1024).seed(&1).hashes(4);source§impl<const BLOCK_SIZE_BITS: usize, S: BuildHasher> BuilderWithBits<BLOCK_SIZE_BITS, S>
impl<const BLOCK_SIZE_BITS: usize, S: BuildHasher> BuilderWithBits<BLOCK_SIZE_BITS, S>
sourcepub fn hasher<H: BuildHasher>(
self,
hasher: H
) -> BuilderWithBits<BLOCK_SIZE_BITS, H>
pub fn hasher<H: BuildHasher>( self, hasher: H ) -> BuilderWithBits<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::with_num_bits(1024).hasher(RandomState::default()).hashes(4);sourcepub fn hashes(self, num_hashes: u32) -> BloomFilter<BLOCK_SIZE_BITS, S>
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::with_num_bits(1024).hashes(4);sourcepub fn expected_items(
self,
expected_num_items: usize
) -> BloomFilter<BLOCK_SIZE_BITS, S>
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::with_num_bits(1024).expected_items(500);sourcepub fn items<I: IntoIterator<IntoIter = impl ExactSizeIterator<Item = impl Hash>>>(
self,
items: I
) -> BloomFilter<BLOCK_SIZE_BITS, S>
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 BuilderWithBits::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::with_num_bits(1024).items([1, 2, 3]);source§impl<const BLOCK_SIZE_BITS: usize, S: BuildHasher> BuilderWithBits<BLOCK_SIZE_BITS, S>
impl<const BLOCK_SIZE_BITS: usize, S: BuildHasher> BuilderWithBits<BLOCK_SIZE_BITS, S>
sourcepub fn block_size_64(self) -> BuilderWithBits<64, S>
pub fn block_size_64(self) -> BuilderWithBits<64, S>
Set the block size of the bloom filter to 64 bits. The underlying bit vector size will be rounded up to be a multiple of the block size.
§Example
use fastbloom::BloomFilter;
let builder = BloomFilter::with_num_bits(1000).block_size_64();source§impl<const BLOCK_SIZE_BITS: usize, S: BuildHasher> BuilderWithBits<BLOCK_SIZE_BITS, S>
impl<const BLOCK_SIZE_BITS: usize, S: BuildHasher> BuilderWithBits<BLOCK_SIZE_BITS, S>
sourcepub fn block_size_128(self) -> BuilderWithBits<128, S>
pub fn block_size_128(self) -> BuilderWithBits<128, S>
Set the block size of the bloom filter to 128 bits. The underlying bit vector size will be rounded up to be a multiple of the block size.
§Example
use fastbloom::BloomFilter;
let builder = BloomFilter::with_num_bits(1000).block_size_128();source§impl<const BLOCK_SIZE_BITS: usize, S: BuildHasher> BuilderWithBits<BLOCK_SIZE_BITS, S>
impl<const BLOCK_SIZE_BITS: usize, S: BuildHasher> BuilderWithBits<BLOCK_SIZE_BITS, S>
sourcepub fn block_size_256(self) -> BuilderWithBits<256, S>
pub fn block_size_256(self) -> BuilderWithBits<256, S>
Set the block size of the bloom filter to 256 bits. The underlying bit vector size will be rounded up to be a multiple of the block size.
§Example
use fastbloom::BloomFilter;
let builder = BloomFilter::with_num_bits(1000).block_size_256();source§impl<const BLOCK_SIZE_BITS: usize, S: BuildHasher> BuilderWithBits<BLOCK_SIZE_BITS, S>
impl<const BLOCK_SIZE_BITS: usize, S: BuildHasher> BuilderWithBits<BLOCK_SIZE_BITS, S>
sourcepub fn block_size_512(self) -> BuilderWithBits<512, S>
pub fn block_size_512(self) -> BuilderWithBits<512, S>
Set the block size of the bloom filter to 512 bits. The underlying bit vector size will be rounded up to be a multiple of the block size.
§Example
use fastbloom::BloomFilter;
let builder = BloomFilter::with_num_bits(1000).block_size_512();Trait Implementations§
source§impl<const BLOCK_SIZE_BITS: usize, S: Clone> Clone for BuilderWithBits<BLOCK_SIZE_BITS, S>
impl<const BLOCK_SIZE_BITS: usize, S: Clone> Clone for BuilderWithBits<BLOCK_SIZE_BITS, S>
source§fn clone(&self) -> BuilderWithBits<BLOCK_SIZE_BITS, S>
fn clone(&self) -> BuilderWithBits<BLOCK_SIZE_BITS, S>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more