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]

pub fn new() -> Self[src]

Get a new, empty HashTrieMap.

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]

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]

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]

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]

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]

fn fmt(&self, f: &mut Formatter<'_>) -> Result[src]

Formats the value using the given formatter. Read more

impl<H: Hashword, F: Flagword<H>, K: Value, V: Clone + Debug + Eq + PartialEq + Send + Sync + 'static, M: HasherBv<H, K> + 'static> Default for HashTrieMap<H, F, K, V, M> where
    <F as TryFrom<<H as BitAnd>::Output>>::Error: Debug
[src]

fn default() -> Self[src]

Returns the “default value” for a type. Read more

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> Any for T where
    T: 'static + ?Sized
[src]

pub fn type_id(&self) -> TypeId[src]

Gets the TypeId of self. Read more

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

pub fn borrow(&self) -> &T[src]

Immutably borrows from an owned value. Read more

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

pub fn borrow_mut(&mut self) -> &mut T[src]

Mutably borrows from an owned value. Read more

impl<T> From<T> for T[src]

pub fn from(t: T) -> T[src]

Performs the conversion.

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

pub fn into(self) -> U[src]

Performs the conversion.

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

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]

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]

Performs the conversion.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>[src]

Performs the conversion.

impl<T> HashLike<T> for T[src]