RBTree

Struct RBTree 

Source
pub struct RBTree<'a, K, V, const KSIZE: usize, const VSIZE: usize>(/* private fields */)
where
    K: Ord + BorshDeserialize + BorshSerialize,
    V: BorshDeserialize + BorshSerialize;
Expand description

A slice-based Red-Black tree

See module level documentation for more info.

Implementations§

Source§

impl<'a, K, V, const KSIZE: usize, const VSIZE: usize> RBTree<'a, K, V, KSIZE, VSIZE>

Source

pub fn init_slice(slice: &'a mut [u8]) -> Result<Self, Error>

Initializes RBTree in a given slice

Source

pub unsafe fn from_slice(slice: &'a mut [u8]) -> Result<Self, Error>

Returns RBTree, contained in the given slice

§Safety

This function must be called only on slices, previously initialized as RBTree using init_tree or RBTree::init_slice

Source

pub fn len(&self) -> usize

Returns the number of occupied nodes

This function runs in O(n), where n - is the number of nodes

Source

pub fn clear(&mut self)

Clears the tree

This function runs in O(n), where n - is the number of nodes

Source

pub fn free_nodes_left(&self) -> usize

Returns the number of free nodes

This function runs in O(n), where n - is the number of nodes

Source

pub fn contains_key<Q>(&self, k: &Q) -> bool
where K: Borrow<Q> + Ord, Q: Ord + ?Sized,

Returns true if the map contains a value for the specified key

This function runs in O(log(n)), where n - is the number of nodes

Source

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

Returns a key-value pair corresponding to the supplied key

This function runs in O(log(n)), where n - is the number of nodes

Source

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

Returns the value corresponding to the key

This function runs in O(log(n)), where n - is the number of nodes

Source

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

Inserts a new key-value pair and returns the old value if it was present

This function runs in O(log(n)), where n - is the number of nodes

Source

pub fn is_empty(&self) -> bool

Returns true if the tree contains no elements

Source

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

Deletes entry and returns deserialized value

This function runs in O(log(n)), where n - is the number of nodes

Source

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

Deletes entry and returns deserialized key-value pair

This function runs in O(log(n)), where n - is the number of nodes

Source

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

Deletes entry without deserializing the value

Returns true if there was a value with the given key.

Source

pub fn first_entry(&self) -> Option<(K, V)>

Returns the first key-value pair in the map

This function runs in O(log(n)), where n - is the number of nodes

Source

pub fn last_entry(&self) -> Option<(K, V)>

Returns the last key-value pair in the map

This function runs in O(log(n)), where n - is the number of nodes

Source

pub fn pairs<'b>(&'b self) -> PairsIterator<'b, 'a, K, V, KSIZE, VSIZE>

Creates an iterator over key-value pairs, in order by key

Source

pub fn keys<'b>(&'b self) -> KeysIterator<'b, 'a, K, V, KSIZE, VSIZE>

Creates an iterator over keys, from smallest to biggest

Source

pub fn values<'b>(&'b self) -> ValuesIterator<'b, 'a, K, V, KSIZE, VSIZE>

Creates an iterator over values, in order by key

Trait Implementations§

Source§

impl<'a, K, V, const KSIZE: usize, const VSIZE: usize> Debug for RBTree<'a, K, V, KSIZE, VSIZE>

Source§

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

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

impl<'a, K, V, const KSIZE: usize, const VSIZE: usize> Extend<(K, V)> for RBTree<'a, K, V, KSIZE, VSIZE>

Source§

fn extend<T: IntoIterator<Item = (K, V)>>(&mut self, iter: T)

Extends a collection with the contents of an iterator. Read more
Source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
Source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more

Auto Trait Implementations§

§

impl<'a, K, V, const KSIZE: usize, const VSIZE: usize> Freeze for RBTree<'a, K, V, KSIZE, VSIZE>

§

impl<'a, K, V, const KSIZE: usize, const VSIZE: usize> RefUnwindSafe for RBTree<'a, K, V, KSIZE, VSIZE>

§

impl<'a, K, V, const KSIZE: usize, const VSIZE: usize> Send for RBTree<'a, K, V, KSIZE, VSIZE>
where K: Send, V: Send,

§

impl<'a, K, V, const KSIZE: usize, const VSIZE: usize> Sync for RBTree<'a, K, V, KSIZE, VSIZE>
where K: Sync, V: Sync,

§

impl<'a, K, V, const KSIZE: usize, const VSIZE: usize> Unpin for RBTree<'a, K, V, KSIZE, VSIZE>
where K: Unpin, V: Unpin,

§

impl<'a, K, V, const KSIZE: usize, const VSIZE: usize> !UnwindSafe for RBTree<'a, K, V, KSIZE, VSIZE>

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, 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.