pub struct HashTrieSet<H: Hashword, F: Flagword<H>, K: Key, M: HasherBv<H, K>>{ /* private fields */ }
Expand description
HashTrieSet
implements a hash set using a hash array mapped trie (HAMT).
§Example Usage
use fnv::FnvHasher;
use hash_trie::{HashTrieSet, traits::HashLike};
use std::string::String;
#[derive(Clone,Debug,Eq,Hash,PartialEq)]
struct Str<'a> {
s: &'a str
}
impl <'a> Str<'a> {
fn new(s: &'a str) -> Self {
Self {s}
}
}
impl <'a> Default for Str<'a> {
fn default() -> Self {
Self {s: ""}
}
}
impl <'a> From<Str<'a>> for String {
fn from(s: Str<'a>) -> String {
s.s.into()
}
}
impl <'a> PartialEq<Str<'a>> for String {
fn eq(&self, other: &Str<'a>) -> bool {
*self == other.s
}
}
impl <'a> HashLike<String> for Str<'a> {}
impl <'a> HashLike<Str<'a>> for String {}
unsafe impl <'a> Send for Str<'a> {}
unsafe impl <'a> Sync for Str<'a> {}
let mut hash_set: HashTrieSet<u64, u32, String, FnvHasher> = HashTrieSet::new();
let hello_world = "Hello, world!";
hash_set = hash_set.insert(Str::new(hello_world), false).unwrap().0;
// Inserting an already-inserted key returns a reference to the key in the set...
assert!(*hash_set.insert(Str::new(hello_world), false).map(|_| ()).unwrap_err() == hello_world);
// ... unless you enable replacement.
assert!(hash_set.insert(Str::new(hello_world), true).is_ok());
assert!(hash_set.find(&Str::new(hello_world)).map(|reference| *reference == hello_world).unwrap());
match hash_set.remove(&Str::new(hello_world)) {
Ok((mutated, reference)) => {
// Removing a key returns a reference to the key
// in the set in addition to the mutated set.
println!("Value stored in hash_set: {}", reference);
hash_set = mutated;
},
Err(_) => panic!(),
}
Implementations§
Source§impl<H: Hashword, F: Flagword<H>, K: Key, M: HasherBv<H, K>> HashTrieSet<H, F, K, M>
impl<H: Hashword, F: Flagword<H>, K: Key, M: HasherBv<H, K>> HashTrieSet<H, F, K, M>
Sourcepub fn find<'a, L: Key + HashLike<K>>(
&'a self,
key: &L,
) -> Result<&'a K, HashTrieError>
pub fn find<'a, L: Key + HashLike<K>>( &'a self, key: &L, ) -> Result<&'a K, HashTrieError>
Search the HashTrieSet for the given key and return a reference if found, or HashTrieError::NotFound
if not found.
Sourcepub fn insert<'a, L: Key + HashLike<K> + Into<K>>(
&'a self,
key: L,
replace: bool,
) -> Result<(Self, *const K, Option<&'a K>), &'a K>
pub fn insert<'a, L: Key + HashLike<K> + Into<K>>( &'a self, key: L, replace: bool, ) -> Result<(Self, *const K, Option<&'a K>), &'a K>
Search the HashTrieSet for the spot to insert the key and return both a mutated set and, if applicable, a reference to the replaced key. If found and replacement is disabled, a reference to the existing key is returned.
Sourcepub fn remove<'a, L: Key + HashLike<K>>(
&'a self,
key: &L,
) -> Result<(Self, &'a K), HashTrieError>
pub fn remove<'a, L: Key + HashLike<K>>( &'a self, key: &L, ) -> Result<(Self, &'a K), HashTrieError>
Search the HashTrieSet for the given key to remove and return a mutated set, or HashTrieError::NotFound
if not found.
Sourcepub fn transform<ReduceT, ReduceOp, Op>(
&self,
reduce_op: ReduceOp,
op: Op,
) -> (Self, ReduceT)
pub fn transform<ReduceT, ReduceOp, Op>( &self, reduce_op: ReduceOp, op: Op, ) -> (Self, ReduceT)
Run a transform operation on each entry in the set. Returns the transformed set and a reduction of the secondary returns of the transform operations.
Sourcepub unsafe fn transmute<S: Key + HashLike<S>, ReduceT, ReduceOp, Op>(
&self,
reduce_op: ReduceOp,
op: Op,
) -> (HashTrieSet<H, F, S, M>, ReduceT)
pub unsafe fn transmute<S: Key + HashLike<S>, ReduceT, ReduceOp, Op>( &self, reduce_op: ReduceOp, op: Op, ) -> (HashTrieSet<H, F, S, M>, ReduceT)
Run a transmute operation on each entry in the set. Returns the transmuted set and a reduction of the secondary returns of the transmute operations.
Sourcepub fn transform_with_transformed<ReduceT, ReduceOp, BothOp, LeftOp, RightOp>(
&self,
right: &Self,
reduce_op: ReduceOp,
both_op: BothOp,
left_op: LeftOp,
right_op: RightOp,
) -> (Self, ReduceT)
pub fn transform_with_transformed<ReduceT, ReduceOp, BothOp, LeftOp, RightOp>( &self, right: &Self, reduce_op: ReduceOp, both_op: BothOp, left_op: LeftOp, right_op: RightOp, ) -> (Self, ReduceT)
Run a transform operation on each entry or pair of entries in the sets. Returns the transformed set and a reduction of the secondary returns of the transmute operations. Can reuse nodes from either set.
Sourcepub unsafe fn transform_with_transmuted<L, ReduceT, ReduceOp, BothOp, LeftOp, RightOp>(
&self,
right: &HashTrieSet<H, F, L, M>,
reduce_op: ReduceOp,
both_op: BothOp,
left_op: LeftOp,
right_op: RightOp,
) -> (Self, ReduceT)where
Self: Sized,
ReduceT: Default,
ReduceOp: Fn(&ReduceT, &ReduceT) -> ReduceT + Clone,
BothOp: Fn(&K, &L) -> SetTransformResult<ReduceT> + Clone,
LeftOp: Fn(&K) -> SetTransformResult<ReduceT> + Clone,
RightOp: Fn(&L) -> SetTransmuteResult<K, ReduceT> + Clone,
K: HashLike<L> + PartialEq<L>,
L: HashLike<K> + PartialEq<K> + Key,
M: HasherBv<H, L>,
pub unsafe fn transform_with_transmuted<L, ReduceT, ReduceOp, BothOp, LeftOp, RightOp>(
&self,
right: &HashTrieSet<H, F, L, M>,
reduce_op: ReduceOp,
both_op: BothOp,
left_op: LeftOp,
right_op: RightOp,
) -> (Self, ReduceT)where
Self: Sized,
ReduceT: Default,
ReduceOp: Fn(&ReduceT, &ReduceT) -> ReduceT + Clone,
BothOp: Fn(&K, &L) -> SetTransformResult<ReduceT> + Clone,
LeftOp: Fn(&K) -> SetTransformResult<ReduceT> + Clone,
RightOp: Fn(&L) -> SetTransmuteResult<K, ReduceT> + Clone,
K: HashLike<L> + PartialEq<L>,
L: HashLike<K> + PartialEq<K> + Key,
M: HasherBv<H, L>,
Run a transform/transmute operation on each entry or pair of entries in the sets. Returns the transmuted set and a reduction of the secondary returns of the transmute operations. Can reuse nodes from the transformed set.
Sourcepub unsafe fn transmute_with_transformed<L, ReduceT, ReduceOp, BothOp, LeftOp, RightOp>(
&self,
right: &HashTrieSet<H, F, L, M>,
reduce_op: ReduceOp,
both_op: BothOp,
left_op: LeftOp,
right_op: RightOp,
) -> (HashTrieSet<H, F, L, M>, ReduceT)where
Self: Sized,
ReduceT: Default,
ReduceOp: Fn(&ReduceT, &ReduceT) -> ReduceT + Clone,
BothOp: Fn(&K, &L) -> SetTransformResult<ReduceT> + Clone,
LeftOp: Fn(&K) -> SetTransmuteResult<L, ReduceT> + Clone,
RightOp: Fn(&L) -> SetTransformResult<ReduceT> + Clone,
K: HashLike<L> + PartialEq<L>,
L: HashLike<K> + PartialEq<K> + Key,
M: HasherBv<H, L>,
pub unsafe fn transmute_with_transformed<L, ReduceT, ReduceOp, BothOp, LeftOp, RightOp>(
&self,
right: &HashTrieSet<H, F, L, M>,
reduce_op: ReduceOp,
both_op: BothOp,
left_op: LeftOp,
right_op: RightOp,
) -> (HashTrieSet<H, F, L, M>, ReduceT)where
Self: Sized,
ReduceT: Default,
ReduceOp: Fn(&ReduceT, &ReduceT) -> ReduceT + Clone,
BothOp: Fn(&K, &L) -> SetTransformResult<ReduceT> + Clone,
LeftOp: Fn(&K) -> SetTransmuteResult<L, ReduceT> + Clone,
RightOp: Fn(&L) -> SetTransformResult<ReduceT> + Clone,
K: HashLike<L> + PartialEq<L>,
L: HashLike<K> + PartialEq<K> + Key,
M: HasherBv<H, L>,
Run a transmute/transform operation on each entry or pair of entries in the sets. Returns the transmuted set and a reduction of the secondary returns of the transmute operations. Can reuse nodes from the transformed set.
Sourcepub unsafe fn transmute_with_transmuted<L, S: Key + HashLike<K>, ReduceT, ReduceOp, BothOp, LeftOp, RightOp>(
&self,
right: &HashTrieSet<H, F, L, M>,
reduce_op: ReduceOp,
both_op: BothOp,
left_op: LeftOp,
right_op: RightOp,
) -> (HashTrieSet<H, F, S, M>, ReduceT)where
Self: Sized,
ReduceT: Default,
ReduceOp: Fn(&ReduceT, &ReduceT) -> ReduceT + Clone,
BothOp: Fn(&K, &L) -> SetTransmuteResult<S, ReduceT> + Clone,
LeftOp: Fn(&K) -> SetTransmuteResult<S, ReduceT> + Clone,
RightOp: Fn(&L) -> SetTransmuteResult<S, ReduceT> + Clone,
K: HashLike<L> + PartialEq<L> + HashLike<S> + PartialEq<S>,
L: HashLike<K> + PartialEq<K> + HashLike<S> + PartialEq<S> + Key,
M: HasherBv<H, L> + HasherBv<H, S>,
pub unsafe fn transmute_with_transmuted<L, S: Key + HashLike<K>, ReduceT, ReduceOp, BothOp, LeftOp, RightOp>(
&self,
right: &HashTrieSet<H, F, L, M>,
reduce_op: ReduceOp,
both_op: BothOp,
left_op: LeftOp,
right_op: RightOp,
) -> (HashTrieSet<H, F, S, M>, ReduceT)where
Self: Sized,
ReduceT: Default,
ReduceOp: Fn(&ReduceT, &ReduceT) -> ReduceT + Clone,
BothOp: Fn(&K, &L) -> SetTransmuteResult<S, ReduceT> + Clone,
LeftOp: Fn(&K) -> SetTransmuteResult<S, ReduceT> + Clone,
RightOp: Fn(&L) -> SetTransmuteResult<S, ReduceT> + Clone,
K: HashLike<L> + PartialEq<L> + HashLike<S> + PartialEq<S>,
L: HashLike<K> + PartialEq<K> + HashLike<S> + PartialEq<S> + Key,
M: HasherBv<H, L> + HasherBv<H, S>,
Run a transmute operation on each entry or pair of entries in the sets. Returns the transmuted set and a reduction of the secondary returns of the transmute operations.
Trait Implementations§
Source§impl<H: Clone + Hashword, F: Clone + Flagword<H>, K: Clone + Key, M: Clone + HasherBv<H, K>> Clone for HashTrieSet<H, F, K, M>
impl<H: Clone + Hashword, F: Clone + Flagword<H>, K: Clone + Key, M: Clone + HasherBv<H, K>> Clone for HashTrieSet<H, F, K, M>
Source§fn clone(&self) -> HashTrieSet<H, F, K, M>
fn clone(&self) -> HashTrieSet<H, F, K, M>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more