[][src]Struct xorf::HashProxy

pub struct HashProxy<T, H, F> where
    T: Hash,
    H: Hasher + Default,
    F: Filter<u64>, 
{ /* fields omitted */ }

Arbitrary key type proxy for Xor filters.

A HashProxy exposes a Filter trait for arbitrary key types, using a Filter<u64> as an underlying keystore. The performance and collision rate of the HashProxy filter depends on the choice of Hasher and underlying Filter. A HashProxy is immutable once constructed.

use std::collections::hash_map::DefaultHasher;
use xorf::{Filter, HashProxy, Xor8};

const SAMPLE_SIZE: usize = 1_000_000;
let rng = rand::thread_rng();
let passwords: Vec<String> = (0..SAMPLE_SIZE)
    .map(|_| rng.sample_iter(&Alphanumeric).take(30).collect())
    .collect();

let pw_filter: HashProxy<String, DefaultHasher, Xor8> = HashProxy::from(&passwords);

for password in passwords {
    assert!(pw_filter.contains(&password));
}

While a HashProxy persists type information about the keys it is constructed with, in most cases the key type parameter can be elided. For example, the pw_filter defined above can also be defined as

let pw_filter: HashProxy<_, DefaultHasher, Xor8> = HashProxy::from(&passwords);

Because of HashProxys' key type parameter, the existence of a key can only be checked using types a HashProxy is constructed with.

This example deliberately fails to compile
use std::collections::hash_map::DefaultHasher;
use std::hash::{Hash, Hasher};
use xorf::{Filter, HashProxy, Xor8};

let fruits = vec!["apple", "banana", "tangerine", "watermelon"];
let fruits: HashProxy<_, DefaultHasher, Xor8> = HashProxy::from(&fruits);

let mut hasher = DefaultHasher::default();
"tangerine".hash(&mut hasher);
let tangerine_hash = hasher.finish();

assert!(fruits.contains(&tangerine_hash)); // doesn't work!

Serializing and deserializing HashProxys can be enabled with the serde feature.

Trait Implementations

impl<T, H, F> Filter<T> for HashProxy<T, H, F> where
    T: Hash,
    H: Hasher + Default,
    F: Filter<u64>, 
[src]

fn contains(&self, key: &T) -> bool[src]

Returns true if the underlying filter contains the specified key.

impl<'_, T, H, F> From<&'_ [T]> for HashProxy<T, H, F> where
    T: Hash,
    H: Hasher + Default,
    F: Filter<u64> + From<Vec<u64>>, 
[src]

impl<'_, T, H, F> From<&'_ Vec<T>> for HashProxy<T, H, F> where
    T: Hash,
    H: Hasher + Default,
    F: Filter<u64> + From<Vec<u64>>, 
[src]

Auto Trait Implementations

impl<T, H, F> Send for HashProxy<T, H, F> where
    F: Send,
    H: Send,
    T: Send

impl<T, H, F> Sync for HashProxy<T, H, F> where
    F: Sync,
    H: Sync,
    T: Sync

impl<T, H, F> Unpin for HashProxy<T, H, F> where
    F: Unpin,
    H: Unpin,
    T: Unpin

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.