[][src]Struct growable_bloom_filter::GrowableBloom

pub struct GrowableBloom { /* fields omitted */ }

A Growable Bloom Filter

Overview

Implementation of Scalable Bloom Filters which also provides serde serialization and deserialize.

A bloom filter lets you insert items, and then test association with contains. It's space and time efficient, at the cost of false positives. In particular, if contains returns true, it may be in filter. But if contains returns false, it's definitely not in the bloom filter.

You can control the failure rate by setting desired_error_prob and est_insertions appropriately.

Applications

Bloom filters are typically used as a pre-cache to avoid expensive operations. For example, if you need to ask ten thousand servers if they have data XYZ, you could use GrowableBloom to figure out which ones do NOT have XYZ.

Example

use serde_json;
use growable_bloom_filter::GrowableBloom;

let mut gbloom = GrowableBloom::new(0.05, 1000);
gbloom.insert(&0);
assert!(gbloom.contains(&0));

let s = serde_json::to_string(&gbloom).unwrap();
let des_gbloom: GrowableBloom = serde_json::from_str(&s).unwrap();
assert!(des_gbloom.contains(&0));

Methods

impl GrowableBloom[src]

pub fn new(desired_error_prob: f64, est_insertions: usize) -> GrowableBloom[src]

Create a new GrowableBloom filter.

Arguments

  • desired_error_prob - The desired error probability (eg. 0.05, 0.01)
  • est_insertions - The estimated number of insertions (eg. 100, 1000)

NOTE: You really don't need to be accurate with est_insertions. Power of 10 granularity should be fine.

Example

// 5% failure rate, estimated 100 elements to insert
use growable_bloom_filter::GrowableBloom;
let mut gbloom = GrowableBloom::new(0.05, 100);

Panics

Panics if desired_error_prob is less then 0 or greater than 1

pub fn contains<T: Hash>(&self, item: T) -> bool[src]

Test if item in the Bloom filter.

If true is returned, it's may be in the filter. If false is returned, it's NOT in the filter.

Arguments

  • item - The item to test

Example

use growable_bloom_filter::GrowableBloom;
let mut bloom = GrowableBloom::new(0.05, 10);
let item = 0;

bloom.insert(&item);
assert!(bloom.contains(&item));

pub fn insert<T: Hash>(&mut self, item: T)[src]

Insert item into the filter.

This may resize the GrowableBloom.

Arguments

  • item - The item to insert

Example

use growable_bloom_filter::GrowableBloom;
let mut bloom = GrowableBloom::new(0.05, 10);
let item = 0;

bloom.insert(&item);
bloom.insert(&-1);
bloom.insert(&vec![1, 2, 3]);
bloom.insert("hello");

Trait Implementations

impl Clone for GrowableBloom[src]

impl PartialEq<GrowableBloom> for GrowableBloom[src]

impl Debug for GrowableBloom[src]

impl Serialize for GrowableBloom[src]

impl<'de> Deserialize<'de> for GrowableBloom[src]

Auto Trait Implementations

Blanket Implementations

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> From<T> for T[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> DeserializeOwned for T where
    T: Deserialize<'de>, 
[src]