Struct hash_trie::HashTrieSet [−][src]
#[must_use]pub struct HashTrieSet<H: Hashword, F: Flagword<H>, V: Value, M: HasherBv<H, V> + 'static> 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 hash_trie::HashTrieSet; use std::{borrow::Cow, collections::hash_map::DefaultHasher}; let mut hash_set: HashTrieSet<u64, u32, String, DefaultHasher> = HashTrieSet::new(); let hello_world: String = "Hello, world!".into(); hash_set = hash_set.insert(Cow::Borrowed(&hello_world), false).unwrap().0; // Inserting an already-inserted value returns a reference to the value in the set... assert_eq!(*hash_set.insert(Cow::Borrowed(&hello_world), false).unwrap_err(), hello_world); // ... unless you enable replacement. assert!(hash_set.insert(Cow::Borrowed(&hello_world), true).is_ok()); assert_eq!(*hash_set.find(&hello_world).unwrap(), hello_world); match hash_set.remove(&hello_world) { Ok((mutated, reference)) => { // Removing a value returns a reference to the value // in the set in addition to the mutated set. println!("Value stored in hash_set: {}", reference); hash_set = mutated; }, Err(_) => panic!(), }
Implementations
impl<H: Hashword, F: Flagword<H>, V: Value, M: HasherBv<H, V> + 'static> HashTrieSet<H, F, V, M> where
<F as TryFrom<<H as BitAnd>::Output>>::Error: Debug, [src]
impl<H: Hashword, F: Flagword<H>, V: Value, M: HasherBv<H, V> + 'static> HashTrieSet<H, F, V, M> where
<F as TryFrom<<H as BitAnd>::Output>>::Error: Debug, [src]pub fn find(&self, value: &V) -> Result<&V, HashTrieError>[src]
pub fn find(&self, value: &V) -> Result<&V, HashTrieError>[src]Search the HashTrieSet for the given value and return a reference if found, or HashTrieError::NotFound if not found.
pub fn insert<'a>(
&'a self,
value: Cow<'a, V>,
replace: bool
) -> Result<(Self, Option<&'a V>), &'a V>[src]
pub fn insert<'a>(
&'a self,
value: Cow<'a, V>,
replace: bool
) -> Result<(Self, Option<&'a V>), &'a V>[src]Search the HashTrieSet for the spot to insert the value and return both a mutated set and, if applicable, a reference to the replaced value. If found and replacement is disabled, a reference to the existing value is returned.
pub fn remove(&self, value: &V) -> Result<(Self, &V), HashTrieError>[src]
pub fn remove(&self, value: &V) -> Result<(Self, &V), HashTrieError>[src]Search the HashTrieSet for the given value to remove and return a mutated set, or HashTrieError::NotFound if not found.
Trait Implementations
impl<H: Clone + Hashword, F: Clone + Flagword<H>, V: Clone + Value, M: Clone + HasherBv<H, V> + 'static> Clone for HashTrieSet<H, F, V, M> where
<F as TryFrom<<H as BitAnd>::Output>>::Error: Debug, [src]
impl<H: Clone + Hashword, F: Clone + Flagword<H>, V: Clone + Value, M: Clone + HasherBv<H, V> + 'static> Clone for HashTrieSet<H, F, V, M> where
<F as TryFrom<<H as BitAnd>::Output>>::Error: Debug, [src]fn clone(&self) -> HashTrieSet<H, F, V, M>[src]
fn clone(&self) -> HashTrieSet<H, F, 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
Auto Trait Implementations
impl<H, F, V, M> !Send for HashTrieSet<H, F, V, M>
impl<H, F, V, M> !Sync for HashTrieSet<H, F, V, M>
impl<H, F, V, M> Unpin for HashTrieSet<H, F, 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