Struct hash_trie::HashTrieSet[][src]

pub struct HashTrieSet<H: Hashword, F: Flagword<H>, K: Key, M: HasherBv<H, K>> 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 fnv::FnvHasher;
use hash_trie::{HashTrieSet, traits::HashLike};
use std::string::String;
 
#[derive(Clone,Debug,Eq,Hash,PartialEq)]
struct Str<'a> {
    s: &'a str
}
 
impl <'a> Str<'a> {
    fn new(s: &'a str) -> Self {
        Self {s}
    }
}
 
impl <'a> Default for Str<'a> {
    fn default() -> Self {
        Self {s: ""}
    }
}
impl <'a> From<Str<'a>> for String {
    fn from(s: Str<'a>) -> String {
        s.s.into()
    }
}
impl <'a> PartialEq<Str<'a>> for String {
    fn eq(&self, other: &Str<'a>) -> bool {
        *self == other.s
    }
}
impl <'a> HashLike<String> for Str<'a> {}
impl <'a> HashLike<Str<'a>> for String {}
unsafe impl <'a> Send for Str<'a> {}
unsafe impl <'a> Sync for Str<'a> {}
 
let mut hash_set: HashTrieSet<u64, u32, String, FnvHasher> = HashTrieSet::new();
let hello_world = "Hello, world!";

hash_set = hash_set.insert(Str::new(hello_world), false).unwrap().0;
 
// Inserting an already-inserted key returns a reference to the key in the set...
assert!(*hash_set.insert(Str::new(hello_world), false).map(|_| ()).unwrap_err() == hello_world);
// ... unless you enable replacement.
assert!(hash_set.insert(Str::new(hello_world), true).is_ok());

assert!(hash_set.find(&Str::new(hello_world)).map(|reference| *reference == hello_world).unwrap());

match hash_set.remove(&Str::new(hello_world)) {
    Ok((mutated, reference)) => {
        // Removing a key returns a reference to the key
        // in the set in addition to the mutated set.
        println!("Value stored in hash_set: {}", reference);
        hash_set = mutated;
    },
    Err(_) => panic!(),
}

Implementations

Get a new, empty HashTrieSet.

Get the total number of entries in the set.

Search the HashTrieSet for the given key and return a reference if found, or HashTrieError::NotFound if not found.

Search the HashTrieSet for the spot to insert the key and return both a mutated set and, if applicable, a reference to the replaced key. If found and replacement is disabled, a reference to the existing key is returned.

Search the HashTrieSet for the given key to remove and return a mutated set, or HashTrieError::NotFound if not found.

Run an operation on each entry in the set.

Run a transform operation on each entry in the set. Returns the transformed set and a reduction of the secondary returns of the transform operations.

Run a transmute operation on each entry in the set. Returns the transmuted set and a reduction of the secondary returns of the transmute operations.

Run a transform operation on each entry or pair of entries in the sets. Returns the transformed set and a reduction of the secondary returns of the transmute operations. Can reuse nodes from either set.

Run a transform/transmute operation on each entry or pair of entries in the sets. Returns the transmuted set and a reduction of the secondary returns of the transmute operations. Can reuse nodes from the transformed set.

Run a transmute/transform operation on each entry or pair of entries in the sets. Returns the transmuted set and a reduction of the secondary returns of the transmute operations. Can reuse nodes from the transformed set.

Run a transmute operation on each entry or pair of entries in the sets. Returns the transmuted set and a reduction of the secondary returns of the transmute operations.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

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

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

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

recently added

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

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.