Struct hash_trie::HashTrieSet[][src]

pub struct HashTrieSet<B: Bits, V: Value, H: HasherBv<B, V>> { /* 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, String, DefaultHasher> = HashTrieSet::new();
let hello_world: String = "Hello, world!".into();

hash_set = hash_set.insert(Cow::Borrowed(&hello_world)).unwrap();
 
// Inserting an already-inserted value returns a reference to the value in the set.
assert_eq!(*hash_set.insert(Cow::Borrowed(&hello_world)).unwrap_err(), hello_world);

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<B: Bits, V: Value, H: HasherBv<B, V>> HashTrieSet<B, V, H>[src]

pub fn new() -> Self[src]

Get a new, empty HashTrieSet.

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(&self, value: Cow<'_, V>) -> Result<Self, &V>[src]

Search the HashTrieSet for the spot to insert the value and return a mutated set, or a reference to the existing value if found.

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<B: Clone + Bits, V: Clone + Value, H: Clone + HasherBv<B, V>> Clone for HashTrieSet<B, V, H>[src]

fn clone(&self) -> HashTrieSet<B, V, H>[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<B: Debug + Bits, V: Debug + Value, H: Debug + HasherBv<B, V>> Debug for HashTrieSet<B, V, H>[src]

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

Formats the value using the given formatter. Read more

impl<B: Bits, V: Value, H: HasherBv<B, V>> Default for HashTrieSet<B, V, H>[src]

fn default() -> Self[src]

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

Auto Trait Implementations

impl<B, V, H> !Send for HashTrieSet<B, V, H>

impl<B, V, H> !Sync for HashTrieSet<B, V, H>

impl<B, V, H> Unpin for HashTrieSet<B, V, H>

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.