pub struct HashTrieMap<H: Hashword, F: Flagword<H>, K: Key, V: Value, M: HasherBv<H, K>>{ /* private fields */ }
Expand description
HashTrieMap
implements a hash map using a hash array mapped trie (HAMT).
§Example Usage
use fnv::FnvHasher;
use hash_trie::{HashTrieMap, 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_map: HashTrieMap<u64, u32, String, String, FnvHasher> = HashTrieMap::new();
let hello = "Hello,";
let world = "world!,";
hash_map = hash_map.insert(Str::new(hello), world, false).unwrap().0;
// Inserting an already-inserted key returns references to the key and value in the map...
assert!(hash_map.insert(Str::new(hello), "?", false).map(|_| ())
.map_err(|key_value| *key_value.0 == hello && *key_value.1 == world).unwrap_err());
// ... unless you enable replacement.
assert!(hash_map.insert(Str::new(hello), "?", true).is_ok());
assert!(hash_map.find(&Str::new(hello)).map(|key_value| *key_value.0 == hello && *key_value.1 == world).unwrap());
match hash_map.remove(&Str::new(hello)) {
Ok((mutated, key, value)) => {
// Removing a key returns references to the key and
// value in the set in addition to the mutated map.
println!("Value stored in hash_map: ({}, {})", key, value);
hash_map = mutated;
},
Err(_) => panic!(),
}
Implementations§
Source§impl<H: Hashword, F: Flagword<H>, K: Key, V: Value, M: HasherBv<H, K>> HashTrieMap<H, F, K, V, M>
impl<H: Hashword, F: Flagword<H>, K: Key, V: Value, M: HasherBv<H, K>> HashTrieMap<H, F, K, V, M>
Sourcepub fn find<'a, L: Key + HashLike<K>>(
&'a self,
key: &L,
) -> Result<(&'a K, &'a V), HashTrieError>
pub fn find<'a, L: Key + HashLike<K>>( &'a self, key: &L, ) -> Result<(&'a K, &'a V), HashTrieError>
Search the HashTrieMap for the given key and return references if found, or HashTrieError::NotFound
if not found.
Sourcepub fn insert<'a, L: Key + HashLike<K> + Into<K>, W: Into<V>>(
&'a self,
key: L,
value: W,
replace: bool,
) -> Result<(Self, *const K, *const V, Option<(&'a K, &'a V)>), (&'a K, &'a V)>
pub fn insert<'a, L: Key + HashLike<K> + Into<K>, W: Into<V>>( &'a self, key: L, value: W, replace: bool, ) -> Result<(Self, *const K, *const V, Option<(&'a K, &'a V)>), (&'a K, &'a V)>
Search the HashTrieMap for the spot to insert the key and return both a mutated map and, if applicable, references to the replaced values. If found and replacement is disabled, references to the existing values are returned.
Sourcepub fn remove<'a, L: Key + HashLike<K>>(
&'a self,
key: &L,
) -> Result<(Self, &'a K, &'a V), HashTrieError>
pub fn remove<'a, L: Key + HashLike<K>>( &'a self, key: &L, ) -> Result<(Self, &'a K, &'a V), HashTrieError>
Search the HashTrieMap for the given key to remove and return a mutated map, 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 map. Returns the transformed map and a reduction of the secondary returns of the transform operations.
Sourcepub unsafe fn transmute<S: Key + HashLike<K>, X: Value, ReduceT, ReduceOp, Op>(
&self,
reduce_op: ReduceOp,
op: Op,
) -> (HashTrieMap<H, F, S, X, M>, ReduceT)
pub unsafe fn transmute<S: Key + HashLike<K>, X: Value, ReduceT, ReduceOp, Op>( &self, reduce_op: ReduceOp, op: Op, ) -> (HashTrieMap<H, F, S, X, M>, ReduceT)
Run a transmute operation on each entry in the map. Returns the transmuted map 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 maps. Returns the transformed map and a reduction of the secondary returns of the transmute operations. Can reuse nodes from either map.
Sourcepub fn transform_with_transfuted<W: Value, ReduceT, ReduceOp, BothOp, LeftOp, RightOp>(
&self,
right: &HashTrieMap<H, F, K, W, M>,
reduce_op: ReduceOp,
both_op: BothOp,
left_op: LeftOp,
right_op: RightOp,
) -> (Self, ReduceT)
pub fn transform_with_transfuted<W: Value, ReduceT, ReduceOp, BothOp, LeftOp, RightOp>( &self, right: &HashTrieMap<H, F, K, W, M>, reduce_op: ReduceOp, both_op: BothOp, left_op: LeftOp, right_op: RightOp, ) -> (Self, ReduceT)
Run a transform/transmute operation on each entry or pair of entries in the maps. Returns the transmuted map and a reduction of the secondary returns of the transmute operations. Can reuse nodes from the transformed map. Like transform_with_transmuted but enforces identity transformations on keys.
Sourcepub unsafe fn transform_with_transmuted<L, W: Value, ReduceT, ReduceOp, BothOp, LeftOp, RightOp>(
&self,
right: &HashTrieMap<H, F, L, W, 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, &V, &L, &W) -> MapTransformResult<V, ReduceT> + Clone,
LeftOp: Fn(&K, &V) -> MapTransformResult<V, ReduceT> + Clone,
RightOp: Fn(&L, &W) -> MapTransmuteResult<K, V, ReduceT> + Clone,
K: HashLike<L> + PartialEq<L>,
L: HashLike<K> + PartialEq<K> + Key,
M: HasherBv<H, L>,
pub unsafe fn transform_with_transmuted<L, W: Value, ReduceT, ReduceOp, BothOp, LeftOp, RightOp>(
&self,
right: &HashTrieMap<H, F, L, W, 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, &V, &L, &W) -> MapTransformResult<V, ReduceT> + Clone,
LeftOp: Fn(&K, &V) -> MapTransformResult<V, ReduceT> + Clone,
RightOp: Fn(&L, &W) -> MapTransmuteResult<K, V, 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 maps. Returns the transmuted map and a reduction of the secondary returns of the transmute operations. Can reuse nodes from the transformed map.
Sourcepub fn transfute_with_transformed<W: Value, ReduceT, ReduceOp, BothOp, LeftOp, RightOp>(
&self,
right: &HashTrieMap<H, F, K, W, M>,
reduce_op: ReduceOp,
both_op: BothOp,
left_op: LeftOp,
right_op: RightOp,
) -> (HashTrieMap<H, F, K, W, M>, ReduceT)
pub fn transfute_with_transformed<W: Value, ReduceT, ReduceOp, BothOp, LeftOp, RightOp>( &self, right: &HashTrieMap<H, F, K, W, M>, reduce_op: ReduceOp, both_op: BothOp, left_op: LeftOp, right_op: RightOp, ) -> (HashTrieMap<H, F, K, W, M>, ReduceT)
Run a transmute/transform operation on each entry or pair of entries in the maps. Returns the transmuted map and a reduction of the secondary returns of the transmute operations. Can reuse nodes from the transformed map. Like transmute_with_transformed but enforces identity transformations on keys.
Sourcepub unsafe fn transmute_with_transformed<L, W: Value, ReduceT, ReduceOp, BothOp, LeftOp, RightOp>(
&self,
right: &HashTrieMap<H, F, L, W, M>,
reduce_op: ReduceOp,
both_op: BothOp,
left_op: LeftOp,
right_op: RightOp,
) -> (HashTrieMap<H, F, L, W, M>, ReduceT)where
Self: Sized,
ReduceT: Default,
ReduceOp: Fn(&ReduceT, &ReduceT) -> ReduceT + Clone,
BothOp: Fn(&K, &V, &L, &W) -> MapTransformResult<W, ReduceT> + Clone,
LeftOp: Fn(&K, &V) -> MapTransmuteResult<L, W, ReduceT> + Clone,
RightOp: Fn(&L, &W) -> MapTransformResult<W, ReduceT> + Clone,
K: HashLike<L> + PartialEq<L>,
L: HashLike<K> + PartialEq<K> + Key,
M: HasherBv<H, L>,
pub unsafe fn transmute_with_transformed<L, W: Value, ReduceT, ReduceOp, BothOp, LeftOp, RightOp>(
&self,
right: &HashTrieMap<H, F, L, W, M>,
reduce_op: ReduceOp,
both_op: BothOp,
left_op: LeftOp,
right_op: RightOp,
) -> (HashTrieMap<H, F, L, W, M>, ReduceT)where
Self: Sized,
ReduceT: Default,
ReduceOp: Fn(&ReduceT, &ReduceT) -> ReduceT + Clone,
BothOp: Fn(&K, &V, &L, &W) -> MapTransformResult<W, ReduceT> + Clone,
LeftOp: Fn(&K, &V) -> MapTransmuteResult<L, W, ReduceT> + Clone,
RightOp: Fn(&L, &W) -> MapTransformResult<W, 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 maps. Returns the transmuted map and a reduction of the secondary returns of the transmute operations. Can reuse nodes from the transformed map.
Sourcepub unsafe fn transmute_with_transmuted<L, W: Value, S: Key + HashLike<K>, X: Value, ReduceT, ReduceOp, BothOp, LeftOp, RightOp>(
&self,
right: &HashTrieMap<H, F, L, W, M>,
reduce_op: ReduceOp,
both_op: BothOp,
left_op: LeftOp,
right_op: RightOp,
) -> (HashTrieMap<H, F, S, X, M>, ReduceT)where
Self: Sized,
ReduceT: Default,
ReduceOp: Fn(&ReduceT, &ReduceT) -> ReduceT + Clone,
BothOp: Fn(&K, &V, &L, &W) -> MapTransmuteResult<S, X, ReduceT> + Clone,
LeftOp: Fn(&K, &V) -> MapTransmuteResult<S, X, ReduceT> + Clone,
RightOp: Fn(&L, &W) -> MapTransmuteResult<S, X, 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, W: Value, S: Key + HashLike<K>, X: Value, ReduceT, ReduceOp, BothOp, LeftOp, RightOp>(
&self,
right: &HashTrieMap<H, F, L, W, M>,
reduce_op: ReduceOp,
both_op: BothOp,
left_op: LeftOp,
right_op: RightOp,
) -> (HashTrieMap<H, F, S, X, M>, ReduceT)where
Self: Sized,
ReduceT: Default,
ReduceOp: Fn(&ReduceT, &ReduceT) -> ReduceT + Clone,
BothOp: Fn(&K, &V, &L, &W) -> MapTransmuteResult<S, X, ReduceT> + Clone,
LeftOp: Fn(&K, &V) -> MapTransmuteResult<S, X, ReduceT> + Clone,
RightOp: Fn(&L, &W) -> MapTransmuteResult<S, X, 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 maps. Returns the transmuted map 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, V: Clone + Value, M: Clone + HasherBv<H, K>> Clone for HashTrieMap<H, F, K, V, M>
impl<H: Clone + Hashword, F: Clone + Flagword<H>, K: Clone + Key, V: Clone + Value, M: Clone + HasherBv<H, K>> Clone for HashTrieMap<H, F, K, V, M>
Source§fn clone(&self) -> HashTrieMap<H, F, K, V, M>
fn clone(&self) -> HashTrieMap<H, F, K, V, M>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more