[−][src]Struct xorf::HashProxy
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 HashProxy
s' key type parameter, the existence of a key can only be checked using
types a HashProxy
is constructed with.
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 HashProxy
s 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]
T: Hash,
H: Hasher + Default,
F: Filter<u64>,
fn contains(&self, key: &T) -> bool
[src]
Returns true
if the underlying filter contains the specified key.
fn len(&self) -> usize
[src]
impl<'_, T, H, F> From<&'_ [T]> for HashProxy<T, H, F> where
T: Hash,
H: Hasher + Default,
F: Filter<u64> + From<Vec<u64>>,
[src]
T: Hash,
H: Hasher + Default,
F: Filter<u64> + From<Vec<u64>>,
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]
T: Hash,
H: Hasher + Default,
F: Filter<u64> + From<Vec<u64>>,
Auto Trait Implementations
impl<T, H, F> Send for HashProxy<T, H, F> where
F: Send,
H: Send,
T: Send,
F: Send,
H: Send,
T: Send,
impl<T, H, F> Sync for HashProxy<T, H, F> where
F: Sync,
H: Sync,
T: Sync,
F: Sync,
H: Sync,
T: Sync,
impl<T, H, F> Unpin for HashProxy<T, H, F> where
F: Unpin,
H: Unpin,
T: Unpin,
F: Unpin,
H: Unpin,
T: Unpin,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
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> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
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>,