Struct imhamt::Hamt

source ·
pub struct Hamt<H: Hasher + Default, K: PartialEq + Eq + Hash, V> {
    root: Node<K, V>,
    hasher: PhantomData<H>,
}

Fields§

§root: Node<K, V>§hasher: PhantomData<H>

Implementations§

source§

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

source

pub fn new() -> Self

source

pub fn is_empty(&self) -> bool

source

pub fn size(&self) -> usize

source§

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

source

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

source§

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

source

pub fn remove_match<Q>(&self, k: &Q, v: &V) -> Result<Self, RemoveError>where K: Borrow<Q>, Q: Hash + Eq,

source§

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

source

pub fn remove<Q>(&self, k: &Q) -> Result<Self, RemoveError>where K: Borrow<Q>, Q: Hash + Eq,

source§

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

source

pub fn replace(&self, k: &K, v: V) -> Result<(Self, 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>(&self, k: &K, f: F) -> Result<Self, 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> Hamt<H, K, V>

source

pub fn update<F, U>(&self, k: &K, f: F) -> Result<Self, UpdateError<U>>where F: FnOnce(&V) -> Result<Option<V>, U>, U: Error + Debug + 'static,

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>(&self, k: K, v: V, f: F) -> Result<Self, E>where F: FnOnce(&V) -> Result<Option<V>, E>, V: Clone, E: Error + Debug + 'static,

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>(&self, k: K, v: V, f: F) -> Selfwhere 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

source§

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

source

pub fn lookup<Q>(&self, k: &Q) -> Option<&V>where K: Borrow<Q>, Q: Hash + Eq,

Try to get the element related to key K

source

pub fn contains_key<Q>(&self, k: &Q) -> boolwhere K: Borrow<Q>, Q: Hash + Eq,

Check if the key is contained into the HAMT

source

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

Trait Implementations§

source§

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

source§

fn clone(&self) -> Hamt<H, K, V>

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

source§

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

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

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

source§

fn default() -> Self

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

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

source§

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

Creates a value from an iterator. Read more
source§

impl<'a, H: Default + Hasher, K: Eq + Hash, V> IntoIterator for &'a Hamt<H, K, V>

§

type Item = (&'a K, &'a V)

The type of the elements being iterated over.
§

type IntoIter = HamtIter<'a, K, V>

Which kind of iterator are we turning this into?
source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
source§

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

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method 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<H, K, V>

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

impl<H, K, V> UnwindSafe for Hamt<H, K, V>where H: UnwindSafe, K: RefUnwindSafe, V: RefUnwindSafe,

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. 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 Twhere 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 Twhere T: Clone,

§

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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.