pub struct CuckooFilter<H> { /* private fields */ }
Expand description

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).unwrap() {
        insertions += 1;
    }
}

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

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

assert_eq!(cf.len(), words.len() + 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

Construct a CuckooFilter with default capacity and hasher.

Constructs a Cuckoo Filter with a given max capacity

Checks if data is in the filter.

Adds data to the filter. Returns Ok if the insertion was successful, but could fail with a NotEnoughSpace error, especially when the filter is nearing its capacity. 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.

Note: When this returns NotEnoughSpace, the element given was actually added to the filter, but some random other element was removed. This might improve in the future.

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

Number of items in the filter.

Exports fingerprints in all buckets, along with the filter’s length for storage. The filter can be recovered by passing the ExportedCuckooFilter struct to the from method of CuckooFilter.

Number of bytes the filter occupies in memory

Check if filter is empty

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

Trait Implementations

Returns the “default value” for a type. Read more

Converts a CuckooFilter into a simplified version which can be serialized and stored for later use.

Converts a simplified representation of a filter used for export to a fully functioning version.

Contents
  • values - A serialized version of the CuckooFilter’s memory, where the fingerprints in each bucket are chained one after another, then in turn all buckets are chained together.
  • length - The number of valid fingerprints inside the CuckooFilter. This value is used as a time saving method, otherwise all fingerprints would need to be checked for equivalence against the null pattern.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.