Struct HamtMut

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

Mutable HAMT data structure

This is created after a thaw of an immutable HAMT, and right after the creation, all the node are still shared with the immutable HAMT.

Once modification happens, then each nodes from root to leaf will be modified and kept in an efficient mutable format until freezing.

Implementations§

Source§

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

Source

pub fn new() -> Self

Create a new empty mutable HAMT

Source§

impl<H, K, V> HamtMut<K, V, H>

Source

pub fn freeze(self) -> Hamt<K, V, H>

Freeze the mutable HAMT back into an immutable HAMT

This recursively freeze all the mutable nodes

Source§

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

Source

pub fn insert(&mut self, k: K, v: V) -> Result<(), InsertError>

Insert a new key into the HAMT

If the key already exists, then an InsertError is returned.

To simulaneously manipulate a key, either to insert or update, use ‘insert_or_update’

Source§

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

Source

pub fn remove_match(&mut self, k: &K, v: &V) -> Result<(), RemoveError>

Remove a key from the HAMT, if it also matching the value V

If the key doesn’t exist, then RemoveError::KeyNotFound will be returned and otherwise if the key exists but the value doesn’t match, RemoveError::ValueNotMatching will be returned.

Source§

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

Source

pub fn remove(&mut self, k: &K) -> Result<(), RemoveError>

Remove a key from the HAMT

If the key doesn’t exist, then RemoveError::KeyNotFound will be returned

Source§

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

Source

pub fn replace(&mut self, k: &K, v: V) -> Result<V, ReplaceError>

Replace the element at the key by the v and return the new tree and the old value.

Source

pub fn replace_with<F>(&mut self, k: &K, f: F) -> Result<(), ReplaceError>
where F: FnOnce(&V) -> V,

Replace the element at the key by the v and return the new tree and the old value.

Source§

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

Source

pub fn update<F, U>(&mut self, k: &K, f: F) -> Result<(), UpdateError<U>>
where F: FnOnce(&V) -> Result<Option<V>, U>,

Update the element at the key K.

If the closure F in parameter returns None, then the key is deleted.

If the key is not present then UpdateError::KeyNotFound is returned

Source

pub fn insert_or_update<F, E>(&mut self, k: K, v: V, f: F) -> Result<(), E>
where F: FnOnce(&V) -> Result<Option<V>, E>, V: Clone,

Update or insert the element at the key K

If the element is not present, then V is added, otherwise the closure F is apply to the found element. If the closure returns None, then the key is deleted

Source

pub fn insert_or_update_simple<F>(&mut self, k: K, v: V, f: F)
where F: for<'a> FnOnce(&'a V) -> Option<V>, V: Clone,

Update or insert the element at the key K

If the element is not present, then V is added, otherwise the closure F is apply to the found element. If the closure returns None, then the key is deleted.

This is similar to ‘insert_or_update’ except the closure shouldn’t be failing

Trait Implementations§

Source§

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

Source§

fn clone(&self) -> Self

Returns a copy 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<'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 HamtMut<K, V, H>

Source§

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

Creates a value from an iterator. Read more

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

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

§

impl<K, V, H> UnwindSafe for HamtMut<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.