ic_certification::rb_tree

Struct RbTree

source
pub struct RbTree<K, V> { /* private fields */ }
Expand description

Implements mutable left-leaning red-black trees as defined in https://www.cs.princeton.edu/~rs/talks/LLRB/LLRB.pdf

Implementations§

source§

impl<K, V> RbTree<K, V>

source

pub const fn new() -> Self

Constructs a new empty tree.

source

pub const fn is_empty(&self) -> bool

Returns true if the map is empty.

source§

impl<K: 'static + AsRef<[u8]>, V: AsHashTree + 'static> RbTree<K, V>

source

pub fn get(&self, key: &[u8]) -> Option<&V>

Looks up the key in the map and returns the associated value, if there is one.

source

pub fn modify(&mut self, key: &[u8], f: impl FnOnce(&mut V))

Updates the value corresponding to the specified key.

source

pub fn witness(&self, key: &[u8]) -> HashTree

Constructs a hash tree that acts as a proof that there is a entry with the specified key in this map. The proof also contains the value in question.

If the key is not in the map, returns a proof of absence.

source

pub fn nested_witness<'a>( &'a self, key: &[u8], f: impl FnOnce(&'a V) -> HashTree, ) -> HashTree

Like witness, but gives the caller more control over the construction of the value witness. This method is useful for constructing witnesses for nested certified maps.

source

pub fn 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 key_range(&self, first: &[u8], last: &[u8]) -> HashTree

Returns a witness for the keys in the specified range. The resulting tree doesn’t include values, they are replaced with “Pruned” nodes.

source

pub fn value_range(&self, first: &[u8], last: &[u8]) -> HashTree

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

source

pub fn keys_with_prefix(&self, prefix: &[u8]) -> HashTree

Returns a witness that enumerates all the keys starting with the specified prefix.

source

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

Creates an iterator over the map’s keys and values.

source

pub fn for_each<'a, F>(&'a self, f: F)
where F: 'a + FnMut(&'a [u8], &'a V),

Enumerates all the key-value pairs in the tree.

source

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

Inserts a key-value entry into the map.

source

pub fn delete(&mut self, key: &[u8])

Removes the specified key from the map.

Trait Implementations§

source§

impl<K: 'static + AsRef<[u8]>, V: AsHashTree + 'static> AsHashTree for RbTree<K, V>

source§

fn root_hash(&self) -> Hash

Returns the root hash of the tree without constructing it. Must be equivalent to as_hash_tree().reconstruct().
source§

fn as_hash_tree(&self) -> HashTree

Constructs a hash tree corresponding to the data.
source§

impl<K: Clone, V: Clone> Clone for RbTree<K, V>

source§

fn clone(&self) -> RbTree<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<K, V> Debug for RbTree<K, V>
where K: 'static + AsRef<[u8]> + Debug, V: 'static + AsHashTree + Debug,

source§

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

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

impl<K: Default, V: Default> Default for RbTree<K, V>

source§

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

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

impl<K, V> FromIterator<(K, V)> for RbTree<K, V>
where K: 'static + AsRef<[u8]>, V: 'static + AsHashTree,

source§

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

Creates a value from an iterator. Read more
source§

impl<K, V> Ord for RbTree<K, V>
where K: 'static + AsRef<[u8]> + Ord, V: 'static + AsHashTree + Ord,

source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
source§

impl<K, V> PartialEq for RbTree<K, V>
where K: 'static + AsRef<[u8]> + PartialEq, V: 'static + AsHashTree + PartialEq,

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<K, V> PartialOrd for RbTree<K, V>
where K: 'static + AsRef<[u8]> + PartialOrd, V: 'static + AsHashTree + PartialOrd,

source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

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

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

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

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

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

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl<K, V> Eq for RbTree<K, V>
where K: 'static + AsRef<[u8]> + Eq, V: 'static + AsHashTree + Eq,

Auto Trait Implementations§

§

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

§

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

§

impl<K, V> Send for RbTree<K, V>
where K: Send, V: Send,

§

impl<K, V> Sync for RbTree<K, V>
where K: Sync, V: Sync,

§

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

§

impl<K, V> UnwindSafe for RbTree<K, V>
where K: UnwindSafe, V: UnwindSafe,

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, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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> 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> NestedTreeValueRequirements for T
where T: Debug + Clone + AsHashTree + 'static,