Map

Struct Map 

Source
pub struct Map<K: 'static + Label, V: AsHashTree + 'static> { /* private fields */ }

Implementations§

Source§

impl<K: 'static + Label, V: AsHashTree + 'static> Map<K, V>

Source

pub fn new() -> Self

Source

pub fn is_empty(&self) -> bool

Returns true if the map does not contain any values.

Source

pub fn len(&self) -> usize

Returns the number of elements in the map.

Source

pub fn clear(&mut self)

Clear the map.

Source

pub fn insert(&mut self, key: K, value: V) -> Option<V>

Insert a key-value pair into the map. Returns None if the key did not exists in the map, otherwise the previous value associated with the provided key will be returned.

Source

pub fn remove<Q>(&mut self, key: &Q) -> Option<V>
where K: Borrow<Q>, Q: Ord + ?Sized,

Remove the value associated with the given key from the map, returns the previous value associated with the key.

Source

pub fn remove_entry<Q>(&mut self, key: &Q) -> Option<(K, V)>
where K: Borrow<Q>, Q: Ord + ?Sized,

Remove an entry from the map and return the key and value.

Source

pub fn entry(&mut self, key: K) -> Entry<'_, K, V>

Source

pub fn get_mut<Q>(&mut self, key: &Q) -> Option<&mut V>
where K: Borrow<Q>, Q: Ord + ?Sized,

Returns a mutable reference to the value corresponding to the key.

Source

pub fn get<Q>(&self, key: &Q) -> Option<&V>
where K: Borrow<Q>, Q: Ord + ?Sized,

Return the value associated with the given key.

Source

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

Return an iterator over the key-values in the map.

Source

pub fn witness<Q>(&self, key: &Q) -> HashTree<'_>
where K: Borrow<Q>, Q: Ord + ?Sized,

Create a HashTree witness for the value associated with given key.

Source

pub fn witness_keys(&self) -> HashTree<'_>

Returns a witness enumerating all the keys in this map. The resulting tree doesn’t include values, they are replaced with “Pruned” nodes.

Source

pub fn witness_value_range<Q1, Q2>(&self, first: &K, last: &K) -> HashTree<'_>
where K: Borrow<Q1> + Borrow<Q2>, Q1: Ord + ?Sized, Q2: Ord + ?Sized,

Returns a witness for the key-value pairs in the specified range. The resulting tree contains both keys and values.

Source

pub fn witness_key_range<Q1, Q2>(&self, first: &K, last: &K) -> HashTree<'_>
where K: Borrow<Q1> + Borrow<Q2>, Q1: Ord + ?Sized, Q2: Ord + ?Sized,

Returns a witness for the keys in the specified range. The resulting tree only contains the keys, and the values are replaced with “Pruned” nodes.

Source

pub fn witness_keys_with_prefix<P>(&self, prefix: &P) -> HashTree<'_>
where K: Prefix<P>, P: Ord + ?Sized,

Returns a witness for the keys with the given prefix, this replaces the values with “Pruned” nodes.

Source

pub fn as_tree(&self) -> &RbTree<K, V>

Return the underlying RbTree for this map.

Source§

impl<K: 'static + Label, V: AsHashTree> Map<K, Seq<V>>

Source

pub fn append_deep(&mut self, key: K, value: V)

Perform a Seq::append on the seq associated with the give value, if the seq does not exists, creates an empty one and inserts it to the map.

Source

pub fn len_deep<Q>(&mut self, key: &Q) -> usize
where K: Borrow<Q>, Q: Ord + ?Sized,

Trait Implementations§

Source§

impl<K: 'static + Label, V: AsHashTree + 'static> AsHashTree for Map<K, V>

Source§

fn root_hash(&self) -> Hash

This method should return the root hash of this hash tree. Must be equivalent to as_hash_tree().reconstruct(). Read more
Source§

fn as_hash_tree(&self) -> HashTree<'_>

Constructs a hash tree corresponding to the data.
Source§

impl<K: 'static + Label, V: 'static + AsHashTree> AsRef<RbTree<K, V>> for Map<K, V>

Source§

fn as_ref(&self) -> &RbTree<K, V>

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<K, V> CandidType for Map<K, V>
where K: CandidType + 'static + Label, V: CandidType + AsHashTree + 'static,

Source§

fn _ty() -> Type

Source§

fn idl_serialize<S>(&self, serializer: S) -> Result<(), S::Error>
where S: Serializer,

Source§

fn ty() -> Type

Source§

fn id() -> TypeId

Source§

impl<K, V> Debug for Map<K, V>
where K: Debug + 'static + Label, V: Debug + AsHashTree + 'static,

Source§

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

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

impl<K: Default + 'static + Label, V: Default + AsHashTree + 'static> Default for Map<K, V>

Source§

fn default() -> Map<K, V>

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

impl<'de, K, V> Deserialize<'de> for Map<K, V>
where K: Deserialize<'de> + 'static + Label, V: Deserialize<'de> + AsHashTree + 'static,

Source§

fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<K: 'static + Label, V: AsHashTree + 'static> FromIterator<(K, V)> for Map<K, V>

Source§

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

Creates a value from an iterator. Read more
Source§

impl<K, V> Serialize for Map<K, V>
where K: Serialize + 'static + Label, V: Serialize + AsHashTree + 'static,

Source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

§

impl<K, V> Freeze for Map<K, V>

§

impl<K, V> RefUnwindSafe for Map<K, V>

§

impl<K, V> !Send for Map<K, V>

§

impl<K, V> !Sync for Map<K, V>

§

impl<K, V> Unpin for Map<K, V>

§

impl<K, V> UnwindSafe for Map<K, V>

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> 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> Same for T

Source§

type Output = T

Should always be Self
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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> GroupLeaf for T
where T: Any + AsHashTree,