Struct hash_trie::HashTrieMap [−][src]
pub struct HashTrieMap<B: Bits, K: Value, V: Clone + Debug + Eq + PartialEq + Send + Sync + 'static, H: HasherBv<B, K>> { /* 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, 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<B: Bits, K: Value, V: Clone + Debug + Eq + PartialEq + Send + Sync + 'static, H: HasherBv<B, K>> HashTrieMap<B, K, V, H>[src]
impl<B: Bits, K: Value, V: Clone + Debug + Eq + PartialEq + Send + Sync + 'static, H: HasherBv<B, K>> HashTrieMap<B, K, V, H>[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<B: Clone + Bits, K: Clone + Value, V: Clone + Debug + Eq + PartialEq + Send + Sync + 'static, H: Clone + HasherBv<B, K>> Clone for HashTrieMap<B, K, V, H>[src]
impl<B: Clone + Bits, K: Clone + Value, V: Clone + Debug + Eq + PartialEq + Send + Sync + 'static, H: Clone + HasherBv<B, K>> Clone for HashTrieMap<B, K, V, H>[src]fn clone(&self) -> HashTrieMap<B, K, V, H>[src]
fn clone(&self) -> HashTrieMap<B, K, V, H>[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
Auto Trait Implementations
impl<B, K, V, H> !Send for HashTrieMap<B, K, V, H>
impl<B, K, V, H> !Sync for HashTrieMap<B, K, V, H>
impl<B, K, V, H> Unpin for HashTrieMap<B, K, V, H>
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