pub struct HashProxy<T, H, F>{ /* private fields */ }
Expand description
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 passwords: Vec<String> = (0..SAMPLE_SIZE)
.map(|_| rand::thread_rng().sample_iter(&Alphanumeric).take(30).map(char::from).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§
Auto Trait Implementations§
impl<T, H, F> RefUnwindSafe for HashProxy<T, H, F>
impl<T, H, F> Send for HashProxy<T, H, F>
impl<T, H, F> Sync for HashProxy<T, H, F>
impl<T, H, F> Unpin for HashProxy<T, H, F>
impl<T, H, F> UnwindSafe for HashProxy<T, H, F>
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more