Struct cuckoofilter::CuckooFilter[][src]

pub struct CuckooFilter<H> { /* fields omitted */ }

A cuckoo filter class exposes a Bloomier filter interface, providing methods of add, delete, contains.

Examples

extern crate cuckoofilter;

let words = vec!["foo", "bar", "xylophone", "milagro"];
let mut cf = cuckoofilter::CuckooFilter::new();

let mut insertions = 0;
for s in &words {
    if cf.test_and_add(s) {
        insertions += 1;
    }
}

assert_eq!(insertions, words.len());
assert_eq!(cf.len(), words.len() as u64);

// Re-add the first element.
cf.add(words[0]);

assert_eq!(cf.len(), words.len() as u64 + 1);

for s in &words {
    cf.delete(s);
}

assert_eq!(cf.len(), 1);
assert!(!cf.is_empty());

cf.delete(words[0]);

assert_eq!(cf.len(), 0);
assert!(cf.is_empty());

Implementations

impl CuckooFilter<DefaultHasher>[src]

pub fn new() -> CuckooFilter<DefaultHasher>[src]

Construct a CuckooFilter with default capacity and hasher.

impl<H> CuckooFilter<H> where
    H: Hasher + Default
[src]

pub fn with_capacity(cap: u64) -> CuckooFilter<H>[src]

Constructs a Cuckoo Filter with a given max capacity

pub fn contains<T: ?Sized + Hash>(&self, data: &T) -> bool[src]

Checks if data is in the filter.

pub fn add<T: ?Sized + Hash>(&mut self, data: &T) -> bool[src]

Adds data to the filter. Returns true if the insertion was successful. Note that while you can put any hashable type in the same filter, beware for side effects like that the same number can have diferent hashes depending on the type. So for the filter, 4711i64 isn’t the same as 4711u64.

pub fn test_and_add<T: ?Sized + Hash>(&mut self, data: &T) -> bool[src]

Adds data to the filter if it does not exist in the filter yet. Returns true if data was not yet present in the filter and added successfully.

pub fn len(&self) -> u64[src]

Number of items in the filter.

pub fn memory_usage(&self) -> usize[src]

Number of bytes the filter occupies in memory

pub fn is_empty(&self) -> bool[src]

Check if filter is empty

pub fn delete<T: ?Sized + Hash>(&mut self, data: &T) -> bool[src]

Deletes data from the filter. Returns true if data existed in the filter before.

Trait Implementations

impl Default for CuckooFilter<DefaultHasher>[src]

Auto Trait Implementations

impl<H> RefUnwindSafe for CuckooFilter<H> where
    H: RefUnwindSafe

impl<H> Send for CuckooFilter<H> where
    H: Send

impl<H> Sync for CuckooFilter<H> where
    H: Sync

impl<H> Unpin for CuckooFilter<H> where
    H: Unpin

impl<H> UnwindSafe for CuckooFilter<H> where
    H: UnwindSafe

Blanket Implementations

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

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

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

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

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

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.