Hamt

Struct Hamt 

Source
pub struct Hamt<K, V, H> { /* private fields */ }
Expand description

HAMT with shareable nodes

The structure is immutable from root to leaves, where each node of this structure is also independently shareable, including on different thread.

Implementations§

Source§

impl<H: Hasher + Default, K: PartialEq + Eq + Hash, V> Hamt<K, V, H>

Source

pub fn new() -> Self

Create a new empty HAMT

Source

pub fn is_empty(&self) -> bool

Check if the HAMT is empty

Source

pub fn size(&self) -> usize

Return the number of elements in this HAMT

Source

pub fn thaw(&self) -> HamtMut<K, V, H>

Thaw this HAMT into a HAMT that can be mutated

Source

pub fn mutate_freeze<E, F>(&self, f: F) -> Result<Self, E>
where F: FnOnce(&mut HamtMut<K, V, H>) -> Result<(), E>,

Temporary create a mutable HAMT from an immutable one, and apply the callback f to the mutable reference, then thaw into the resulting HAMT

let empty : Hamt<u32, u32, DefaultHasher> = Hamt::new();
let result = reference.freeze(|x| {
    x.insert(10, 20)?;
    x.insert(20, 30)
}).expect("it works");
Source

pub fn mutate_freeze_ret<E, F, R>(&self, f: F) -> Result<(Self, R), E>
where F: FnOnce(&mut HamtMut<K, V, H>) -> Result<R, E>,

Similar to ‘mutate_freeze’ and also returns the result of f too

Source§

impl<H: Hasher + Default, K: Hash + Eq, V> Hamt<K, V, H>

Source

pub fn lookup(&self, k: &K) -> Option<&V>

Try to get the element related to key K

Source

pub fn contains_key(&self, k: &K) -> bool

Check if the key is contained into the HAMT

Source

pub fn iter(&self) -> HamtIter<'_, K, V>

Create a new iterator for this HAMT

Trait Implementations§

Source§

impl<H, K, V> Clone for Hamt<K, V, H>

Source§

fn clone(&self) -> Self

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: Hasher + Default, K: Eq + Hash, V> Default for Hamt<K, V, H>

Source§

fn default() -> Self

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

impl<'a, H, K, V> From<&'a Hamt<K, V, H>> for HamtMut<K, V, H>

Source§

fn from(t: &'a Hamt<K, V, H>) -> Self

Converts to this type from the input type.
Source§

impl<H: Default + Hasher, K: Eq + Hash + Clone, V: Clone> FromIterator<(K, V)> for Hamt<K, V, H>

Source§

fn from_iter<I: IntoIterator<Item = (K, V)>>(iter: I) -> Self

Creates a value from an iterator. Read more
Source§

impl<H: Default + Hasher, K: Eq + Hash, V: PartialEq> PartialEq for Hamt<K, V, H>

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: Default + Hasher, K: Eq + Hash, V: Eq> Eq for Hamt<K, V, H>

Auto Trait Implementations§

§

impl<K, V, H> Freeze for Hamt<K, V, H>

§

impl<K, V, H> RefUnwindSafe for Hamt<K, V, H>

§

impl<K, V, H> Send for Hamt<K, V, H>
where H: Send, K: Sync + Send, V: Sync + Send,

§

impl<K, V, H> Sync for Hamt<K, V, H>
where H: Sync, K: Sync + Send, V: Sync + Send,

§

impl<K, V, H> Unpin for Hamt<K, V, H>
where H: Unpin,

§

impl<K, V, H> UnwindSafe for Hamt<K, V, H>

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.