[−][src]Struct growable_bloom_filter::GrowableBloom
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]
fn clone(&self) -> GrowableBloom
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl PartialEq<GrowableBloom> for GrowableBloom
[src]
fn eq(&self, other: &GrowableBloom) -> bool
[src]
fn ne(&self, other: &GrowableBloom) -> bool
[src]
impl Debug for GrowableBloom
[src]
impl Serialize for GrowableBloom
[src]
fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error> where
__S: Serializer,
[src]
__S: Serializer,
impl<'de> Deserialize<'de> for GrowableBloom
[src]
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
[src]
__D: Deserializer<'de>,
Auto Trait Implementations
impl Send for GrowableBloom
impl Sync for GrowableBloom
impl Unpin for GrowableBloom
impl UnwindSafe for GrowableBloom
impl RefUnwindSafe for GrowableBloom
Blanket Implementations
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From<T> for T
[src]
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> DeserializeOwned for T where
T: Deserialize<'de>,
[src]
T: Deserialize<'de>,