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
impl FilterBuilder
Sourcepub fn new(expected_elements: u64, false_positive_probability: f64) -> Self
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();
Sourcepub fn from_size_and_hashes(size: u64, hashes: u32) -> Self
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.
Sourcepub fn enable_repeat_insert(&mut self, enable: bool)
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);
Sourcepub fn build_bloom_filter(&mut self) -> BloomFilter
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).
Sourcepub fn build_counting_bloom_filter(&mut self) -> CountingBloomFilter
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
impl Clone for FilterBuilder
Source§fn clone(&self) -> FilterBuilder
fn clone(&self) -> FilterBuilder
1.0.0 · Source§const fn clone_from(&mut self, source: &Self)
const fn clone_from(&mut self, source: &Self)
source
. Read more