Struct hash_trie::HashTrieSet [−][src]
pub struct HashTrieSet<H: Hashword, F: Flagword<H>, K: Key, M: HasherBv<H, K>> where
<F as TryFrom<<H as BitAnd>::Output>>::Error: Debug, { /* fields omitted */ }
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
Search the HashTrieSet for the given key and return a reference if found, or HashTrieError::NotFound
if not found.
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.
Search the HashTrieSet for the given key to remove and return a mutated set, or HashTrieError::NotFound
if not found.
Run an operation on each entry in the set.
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.
pub unsafe fn transmute<S: Key + HashLike<S>, ReduceT, ReduceOp, Op>(
&self,
reduce_op: ReduceOp,
op: Op
) -> (HashTrieSet<H, F, S, M>, ReduceT) where
Self: Sized,
ReduceT: Default,
ReduceOp: Fn(&ReduceT, &ReduceT) -> ReduceT + Clone,
Op: Fn(&K) -> SetTransmuteResult<S, ReduceT> + Clone,
K: HashLike<S>,
K: PartialEq<S>,
M: HasherBv<H, S>,
pub unsafe fn transmute<S: Key + HashLike<S>, ReduceT, ReduceOp, Op>(
&self,
reduce_op: ReduceOp,
op: Op
) -> (HashTrieSet<H, F, S, M>, ReduceT) where
Self: Sized,
ReduceT: Default,
ReduceOp: Fn(&ReduceT, &ReduceT) -> ReduceT + Clone,
Op: Fn(&K) -> SetTransmuteResult<S, ReduceT> + Clone,
K: HashLike<S>,
K: PartialEq<S>,
M: HasherBv<H, S>,
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.
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) where
Self: Sized,
ReduceT: Default,
ReduceOp: Fn(&ReduceT, &ReduceT) -> ReduceT + Clone,
BothOp: Fn(&K, &K) -> SetJointTransformResult<ReduceT> + Clone,
LeftOp: Fn(&K) -> SetTransformResult<ReduceT> + Clone,
RightOp: Fn(&K) -> SetTransformResult<ReduceT> + Clone,
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) where
Self: Sized,
ReduceT: Default,
ReduceOp: Fn(&ReduceT, &ReduceT) -> ReduceT + Clone,
BothOp: Fn(&K, &K) -> SetJointTransformResult<ReduceT> + Clone,
LeftOp: Fn(&K) -> SetTransformResult<ReduceT> + Clone,
RightOp: Fn(&K) -> SetTransformResult<ReduceT> + Clone,
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.
pub unsafe fn transform_with_transmuted<L: 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
) -> (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>,
K: PartialEq<L>,
L: HashLike<K>,
L: PartialEq<K>,
M: HasherBv<H, L>,
pub unsafe fn transform_with_transmuted<L: 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
) -> (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>,
K: PartialEq<L>,
L: HashLike<K>,
L: PartialEq<K>,
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.
pub unsafe fn transmute_with_transformed<L: 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, 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>,
K: PartialEq<L>,
L: HashLike<K>,
L: PartialEq<K>,
M: HasherBv<H, L>,
pub unsafe fn transmute_with_transformed<L: 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, 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>,
K: PartialEq<L>,
L: HashLike<K>,
L: PartialEq<K>,
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.
pub unsafe fn transmute_with_transmuted<L: Key + HashLike<K>, 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>,
K: PartialEq<L>,
K: HashLike<S>,
K: PartialEq<S>,
L: HashLike<K>,
L: PartialEq<K>,
L: HashLike<S>,
L: PartialEq<S>,
M: HasherBv<H, L>,
M: HasherBv<H, S>,
pub unsafe fn transmute_with_transmuted<L: Key + HashLike<K>, 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>,
K: PartialEq<L>,
K: HashLike<S>,
K: PartialEq<S>,
L: HashLike<K>,
L: PartialEq<K>,
L: HashLike<S>,
L: PartialEq<S>,
M: HasherBv<H, L>,
M: 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
Auto Trait Implementations
impl<H, F, K, M> !RefUnwindSafe for HashTrieSet<H, F, K, M>
impl<H, F, K, M> !Send for HashTrieSet<H, F, K, M>
impl<H, F, K, M> !Sync for HashTrieSet<H, F, K, M>
impl<H, F, K, M> Unpin for HashTrieSet<H, F, K, M>
impl<H, F, K, M> !UnwindSafe for HashTrieSet<H, F, K, M>
Blanket Implementations
Mutably borrows from an owned value. Read more