[−][src]Struct tinysearch_cuckoofilter::CuckooFilter
A cuckoo filter class exposes a Bloomier filter interface, providing methods of add, delete, contains.
Examples
extern crate tinysearch_cuckoofilter; use tinysearch_cuckoofilter::CuckooFilter; let words = vec!["foo", "bar", "xylophone", "milagro"]; let mut cf = 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());
Methods
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]
H: Hasher + Default,
pub fn with_capacity(cap: usize) -> 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) -> Result<(), CuckooError>
[src]
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.
pub fn test_and_add<T: ?Sized + Hash>(
&mut self,
data: &T
) -> Result<bool, CuckooError>
[src]
&mut self,
data: &T
) -> Result<bool, CuckooError>
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.
pub fn len(&self) -> usize
[src]
Number of items in the filter.
pub fn export(&self) -> ExportedCuckooFilter
[src]
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
.
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]
impl<H> From<ExportedCuckooFilter> for CuckooFilter<H>
[src]
fn from(exported: ExportedCuckooFilter) -> CuckooFilter<H>
[src]
Converts a simplified representation of a filter used for export to a fully functioning version.
Contents
values
- A serialized version of theCuckooFilter
'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 theCuckooFilter
. This value is used as a time saving method, otherwise all fingerprints would need to be checked for equivalence against the null pattern.
impl<'a, H> From<&'a CuckooFilter<H>> for ExportedCuckooFilter where
H: Hasher + Default,
[src]
H: Hasher + Default,
fn from(cuckoo: &'a CuckooFilter<H>) -> ExportedCuckooFilter
[src]
Converts a CuckooFilter
into a simplified version which can be serialized and stored
for later use.
Auto Trait Implementations
impl<H> Send for CuckooFilter<H> where
H: Send,
H: Send,
impl<H> Sync for CuckooFilter<H> where
H: Sync,
H: Sync,
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, 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> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,