RbTree

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: AsRef<[u8]>, V: AsHashTree> 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<'a>(&'a self, key: &[u8]) -> HashTree<'a>

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<'a>, ) -> HashTree<'a>

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

Source§

fn _ty() -> Type

Source§

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

Source§

fn ty() -> Type

Source§

fn id() -> TypeId

Source§

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

Source§

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

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

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, V> FromIterator<(K, V)> for RbTree<K, V>
where K: AsRef<[u8]>, V: 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<'a, K: AsRef<[u8]>, V: AsHashTree> IntoIterator for &'a RbTree<K, V>

Source§

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

The type of the elements being iterated over.
Source§

type IntoIter = Iter<'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<K, V> Ord for RbTree<K, V>
where K: AsRef<[u8]> + Ord, V: 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: AsRef<[u8]> + PartialEq, V: 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: AsRef<[u8]> + PartialOrd, V: 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> Serialize for RbTree<K, V>
where K: Serialize + AsRef<[u8]>, V: Serialize + AsHashTree,

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
Source§

impl<K, V> Eq for RbTree<K, V>
where K: AsRef<[u8]> + Eq, V: 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, 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> 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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,