Struct hash_trie::HashTrieMap [−][src]
#[must_use]pub struct HashTrieMap<H: Hashword, F: Flagword<H>, K: Value, V: Clone + Debug + Eq + PartialEq + Send + Sync + 'static, M: HasherBv<H, K> + 'static> where
<F as TryFrom<<H as BitAnd>::Output>>::Error: Debug, { /* fields omitted */ }
Expand description
HashTrieMap implements a hash map using a hash array mapped trie (HAMT).
Example Usage
use hash_trie::HashTrieMap; use std::{borrow::Cow, collections::hash_map::DefaultHasher}; let mut hash_map: HashTrieMap<u64, u32, String, String, DefaultHasher> = HashTrieMap::new(); let hello: String = "Hello,".into(); let world: String = "world!,".into(); hash_map = hash_map.insert(Cow::Borrowed(&hello), Cow::Borrowed(&world), false).unwrap().0; // Inserting an already-inserted key returns references to the key and value in the map... assert_eq!(hash_map.insert(Cow::Borrowed(&hello), Cow::Owned("?".into()), false) .unwrap_err(), (&hello, &world)); // ... unless you enable replacement. assert!(hash_map.insert(Cow::Borrowed(&hello), Cow::Owned("?".into()), true).is_ok()); assert_eq!(hash_map.find(&hello).unwrap(), (&hello, &world)); match hash_map.remove(&hello) { Ok((mutated, key_reference, value_reference)) => { // 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: {}", value_reference); hash_map = mutated; }, Err(_) => panic!(), }
Implementations
impl<H: Hashword, F: Flagword<H>, K: Value, V: Clone + Debug + Eq + PartialEq + Send + Sync + 'static, M: HasherBv<H, K> + 'static> HashTrieMap<H, F, K, V, M> where
<F as TryFrom<<H as BitAnd>::Output>>::Error: Debug, [src]
impl<H: Hashword, F: Flagword<H>, K: Value, V: Clone + Debug + Eq + PartialEq + Send + Sync + 'static, M: HasherBv<H, K> + 'static> HashTrieMap<H, F, K, V, M> where
<F as TryFrom<<H as BitAnd>::Output>>::Error: Debug, [src]pub fn find(&self, key: &K) -> Result<(&K, &V), HashTrieError>[src]
pub fn find(&self, key: &K) -> Result<(&K, &V), HashTrieError>[src]Search the HashTrieMap for the given key and return references if found, or HashTrieError::NotFound if not found.
pub fn insert<'a>(
&'a self,
key: Cow<'a, K>,
value: Cow<'a, V>,
replace: bool
) -> Result<(Self, Option<(&'a K, &'a V)>), (&'a K, &'a V)>[src]
pub fn insert<'a>(
&'a self,
key: Cow<'a, K>,
value: Cow<'a, V>,
replace: bool
) -> Result<(Self, Option<(&'a K, &'a V)>), (&'a K, &'a V)>[src]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.
pub fn remove(&self, key: &K) -> Result<(Self, &K, &V), HashTrieError>[src]
pub fn remove(&self, key: &K) -> Result<(Self, &K, &V), HashTrieError>[src]Search the HashTrieMap for the given key to remove and return a mutated map, or HashTrieError::NotFound if not found.
Trait Implementations
impl<H: Clone + Hashword, F: Clone + Flagword<H>, K: Clone + Value, V: Clone + Debug + Eq + PartialEq + Send + Sync + 'static, M: Clone + HasherBv<H, K> + 'static> Clone for HashTrieMap<H, F, K, V, M> where
<F as TryFrom<<H as BitAnd>::Output>>::Error: Debug, [src]
impl<H: Clone + Hashword, F: Clone + Flagword<H>, K: Clone + Value, V: Clone + Debug + Eq + PartialEq + Send + Sync + 'static, M: Clone + HasherBv<H, K> + 'static> Clone for HashTrieMap<H, F, K, V, M> where
<F as TryFrom<<H as BitAnd>::Output>>::Error: Debug, [src]fn clone(&self) -> HashTrieMap<H, F, K, V, M>[src]
fn clone(&self) -> HashTrieMap<H, F, K, V, M>[src]Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)1.0.0[src]
fn clone_from(&mut self, source: &Self)1.0.0[src]Performs copy-assignment from source. Read more
impl<H: Debug + Hashword, F: Debug + Flagword<H>, K: Debug + Value, V: Debug + Clone + Eq + PartialEq + Send + Sync + 'static, M: Debug + HasherBv<H, K> + 'static> Debug for HashTrieMap<H, F, K, V, M> where
<F as TryFrom<<H as BitAnd>::Output>>::Error: Debug, [src]
impl<H: Debug + Hashword, F: Debug + Flagword<H>, K: Debug + Value, V: Debug + Clone + Eq + PartialEq + Send + Sync + 'static, M: Debug + HasherBv<H, K> + 'static> Debug for HashTrieMap<H, F, K, V, M> where
<F as TryFrom<<H as BitAnd>::Output>>::Error: Debug, [src]Auto Trait Implementations
impl<H, F, K, V, M> !Send for HashTrieMap<H, F, K, V, M>
impl<H, F, K, V, M> !Sync for HashTrieMap<H, F, K, V, M>
impl<H, F, K, V, M> Unpin for HashTrieMap<H, F, K, V, M>
Blanket Implementations
impl<T> BorrowMut<T> for T where
T: ?Sized, [src]
impl<T> BorrowMut<T> for T where
T: ?Sized, [src]pub fn borrow_mut(&mut self) -> &mut T[src]
pub fn borrow_mut(&mut self) -> &mut T[src]Mutably borrows from an owned value. Read more
impl<T> ToOwned for T where
T: Clone, [src]
impl<T> ToOwned for T where
T: Clone, [src]type Owned = T
type Owned = TThe resulting type after obtaining ownership.
pub fn to_owned(&self) -> T[src]
pub fn to_owned(&self) -> T[src]Creates owned data from borrowed data, usually by cloning. Read more
pub fn clone_into(&self, target: &mut T)[src]
pub fn clone_into(&self, target: &mut T)[src]🔬 This is a nightly-only experimental API. (toowned_clone_into)
recently added
Uses borrowed data to replace owned data, usually by cloning. Read more