Struct HashTrieSet

Source
pub struct HashTrieSet<H: Hashword, F: Flagword<H>, K: Key, M: HasherBv<H, K>>
where <F as TryFrom<<H as BitAnd>::Output>>::Error: Debug,
{ /* private fields */ }
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§

Source§

impl<H: Hashword, F: Flagword<H>, K: Key, M: HasherBv<H, K>> HashTrieSet<H, F, K, M>
where <F as TryFrom<<H as BitAnd>::Output>>::Error: Debug,

Source

pub fn new() -> Self

Get a new, empty HashTrieSet.

Source

pub fn size(&self) -> usize

Get the total number of entries in the set.

Source

pub fn find<'a, L: Key + HashLike<K>>( &'a self, key: &L, ) -> Result<&'a K, HashTrieError>
where K: PartialEq<L>, M: HasherBv<H, L>,

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

Source

pub fn insert<'a, L: Key + HashLike<K> + Into<K>>( &'a self, key: L, replace: bool, ) -> Result<(Self, *const K, Option<&'a K>), &'a K>
where K: HashLike<L> + PartialEq<L>, M: HasherBv<H, L>,

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.

Source

pub fn remove<'a, L: Key + HashLike<K>>( &'a self, key: &L, ) -> Result<(Self, &'a K), HashTrieError>
where K: PartialEq<L>, M: HasherBv<H, L>,

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

Source

pub fn visit<Op>(&self, op: Op)
where Op: Fn(&K) + Clone,

Run an operation on each entry in the set.

Source

pub fn transform<ReduceT, ReduceOp, Op>( &self, reduce_op: ReduceOp, op: Op, ) -> (Self, ReduceT)
where Self: Sized, ReduceT: Default, ReduceOp: Fn(&ReduceT, &ReduceT) -> ReduceT + Clone, Op: Fn(&K) -> SetTransformResult<ReduceT> + Clone,

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.

Source

pub unsafe fn transmute<S: Key + HashLike<S>, ReduceT, ReduceOp, Op>( &self, reduce_op: ReduceOp, op: Op, ) -> (HashTrieSet<H, F, S, M>, ReduceT)
where Self: Sized, ReduceT: Default, ReduceOp: Fn(&ReduceT, &ReduceT) -> ReduceT + Clone, Op: Fn(&K) -> SetTransmuteResult<S, ReduceT> + Clone, K: HashLike<S> + PartialEq<S>, M: HasherBv<H, S>,

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.

Source

pub fn transform_with_transformed<ReduceT, ReduceOp, BothOp, LeftOp, RightOp>( &self, right: &Self, reduce_op: ReduceOp, both_op: BothOp, left_op: LeftOp, right_op: RightOp, ) -> (Self, ReduceT)
where Self: Sized, ReduceT: Default, ReduceOp: Fn(&ReduceT, &ReduceT) -> ReduceT + Clone, BothOp: Fn(&K, &K) -> SetJointTransformResult<ReduceT> + Clone, LeftOp: Fn(&K) -> SetTransformResult<ReduceT> + Clone, RightOp: Fn(&K) -> SetTransformResult<ReduceT> + Clone,

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.

Source

pub unsafe fn transform_with_transmuted<L, ReduceT, ReduceOp, BothOp, LeftOp, RightOp>( &self, right: &HashTrieSet<H, F, L, M>, reduce_op: ReduceOp, both_op: BothOp, left_op: LeftOp, right_op: RightOp, ) -> (Self, ReduceT)
where Self: Sized, ReduceT: Default, ReduceOp: Fn(&ReduceT, &ReduceT) -> ReduceT + Clone, BothOp: Fn(&K, &L) -> SetTransformResult<ReduceT> + Clone, LeftOp: Fn(&K) -> SetTransformResult<ReduceT> + Clone, RightOp: Fn(&L) -> SetTransmuteResult<K, ReduceT> + Clone, K: HashLike<L> + PartialEq<L>, L: HashLike<K> + PartialEq<K> + Key, M: HasherBv<H, L>,

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.

Source

pub unsafe fn transmute_with_transformed<L, ReduceT, ReduceOp, BothOp, LeftOp, RightOp>( &self, right: &HashTrieSet<H, F, L, M>, reduce_op: ReduceOp, both_op: BothOp, left_op: LeftOp, right_op: RightOp, ) -> (HashTrieSet<H, F, L, M>, ReduceT)
where Self: Sized, ReduceT: Default, ReduceOp: Fn(&ReduceT, &ReduceT) -> ReduceT + Clone, BothOp: Fn(&K, &L) -> SetTransformResult<ReduceT> + Clone, LeftOp: Fn(&K) -> SetTransmuteResult<L, ReduceT> + Clone, RightOp: Fn(&L) -> SetTransformResult<ReduceT> + Clone, K: HashLike<L> + PartialEq<L>, L: HashLike<K> + PartialEq<K> + Key, M: HasherBv<H, L>,

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.

Source

pub unsafe fn transmute_with_transmuted<L, S: Key + HashLike<K>, ReduceT, ReduceOp, BothOp, LeftOp, RightOp>( &self, right: &HashTrieSet<H, F, L, M>, reduce_op: ReduceOp, both_op: BothOp, left_op: LeftOp, right_op: RightOp, ) -> (HashTrieSet<H, F, S, M>, ReduceT)
where Self: Sized, ReduceT: Default, ReduceOp: Fn(&ReduceT, &ReduceT) -> ReduceT + Clone, BothOp: Fn(&K, &L) -> SetTransmuteResult<S, ReduceT> + Clone, LeftOp: Fn(&K) -> SetTransmuteResult<S, ReduceT> + Clone, RightOp: Fn(&L) -> SetTransmuteResult<S, ReduceT> + Clone, K: HashLike<L> + PartialEq<L> + HashLike<S> + PartialEq<S>, L: HashLike<K> + PartialEq<K> + HashLike<S> + PartialEq<S> + Key, M: HasherBv<H, L> + HasherBv<H, S>,

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§

Source§

impl<H: Clone + Hashword, F: Clone + Flagword<H>, K: Clone + Key, M: Clone + HasherBv<H, K>> Clone for HashTrieSet<H, F, K, M>
where <F as TryFrom<<H as BitAnd>::Output>>::Error: Debug,

Source§

fn clone(&self) -> HashTrieSet<H, F, K, M>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<H: Debug + Hashword, F: Debug + Flagword<H>, K: Debug + Key, M: Debug + HasherBv<H, K>> Debug for HashTrieSet<H, F, K, M>
where <F as TryFrom<<H as BitAnd>::Output>>::Error: Debug,

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<H: Hashword, F: Flagword<H>, K: Key, M: HasherBv<H, K>> Default for HashTrieSet<H, F, K, M>
where <F as TryFrom<<H as BitAnd>::Output>>::Error: Debug,

Source§

fn default() -> Self

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

impl<H: Hashword, F: Flagword<H>, K: Key, M: HasherBv<H, K>> PartialEq for HashTrieSet<H, F, K, M>
where <F as TryFrom<<H as BitAnd>::Output>>::Error: Debug,

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<H: Hashword, F: Flagword<H>, K: Key, M: HasherBv<H, K>> Eq for HashTrieSet<H, F, K, M>
where <F as TryFrom<<H as BitAnd>::Output>>::Error: Debug,

Auto Trait Implementations§

§

impl<H, F, K, M> Freeze for HashTrieSet<H, F, K, M>

§

impl<H, F, K, M> !RefUnwindSafe for HashTrieSet<H, F, K, M>

§

impl<H, F, K, M> !Send for HashTrieSet<H, F, K, M>

§

impl<H, F, K, M> !Sync for HashTrieSet<H, F, K, M>

§

impl<H, F, K, M> Unpin for HashTrieSet<H, F, K, M>

§

impl<H, F, K, M> !UnwindSafe for HashTrieSet<H, F, K, M>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

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

fn clone_into(&self, target: &mut T)

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

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
Source§

impl<T> HashLike<T> for T