Struct growable_bloom_filter::GrowableBloomBuilder

source ·
pub struct GrowableBloomBuilder { /* private fields */ }
Expand description

Builder API for GrowableBloom.

use growable_bloom_filter::GrowableBloomBuilder;
let mut gbloom = GrowableBloomBuilder::new()
    .estimated_insertions(100)
    .desired_error_ratio(0.05)
    .build();

Implementations§

source§

impl GrowableBloomBuilder

source

pub fn new() -> Self

Create a new GrowableBloomBuilder.

Builder API for GrowableBloom.

use growable_bloom_filter::GrowableBloomBuilder;
let mut gbloom = GrowableBloomBuilder::new()
    .estimated_insertions(1000)
    .desired_error_ratio(0.01)
    .growth_factor(2)
    .tightening_ratio(0.85)
    .build();
gbloom.insert("hello world");
assert!(gbloom.contains(&"hello world"));
source

pub fn estimated_insertions(self, count: usize) -> Self

Estimated number of insertions. A power of ten accuracy is good enough.

§Panics

This will panic in debug mode if count is zero.

source

pub fn desired_error_ratio(self, ratio: f64) -> Self

Desired error ratio (i.e. false positive rate).

Smaller error ratios will use more memory and might be a bit slower.

§Panics

This will panic if the error ratio is outside of (0, 1.0).

source

pub fn growth_factor(self, factor: usize) -> Self

Base for the exponential growth factor.

As more items are inserted into a GrowableBloom this growth_factor number is used to exponentially grow the capacity of newly added internal bloom filters. So this number is raised to some exponent proportional to the number of bloom filters held internally.

Basically it’ll control how quickly the bloom filter grows in capacity. By default it’s set to two.

source

pub fn tightening_ratio(self, ratio: f64) -> Self

Control the downwards adjustment on the error ratio when growing.

When GrowableBloom adds a new internal bloom filter it uses the tightening_ratio to adjust the desired_error_ratio on these new, larger internal bloom filters. This is necessary to achieve decent accuracy on the user’s desired error_ratio while using larger and larger bloom filters internally.

By default this library sets it to ~0.85, but for smaller growth factors any number around 0.8 - 0.9 should be fine.

source

pub fn build(self) -> GrowableBloom

Consume the builder to create a GrowableBloom.

§Panics

This will panic if an invalid value is specified.

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