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>
impl<'a, K, V, const KSIZE: usize, const VSIZE: usize> RBTree<'a, K, V, KSIZE, VSIZE>
Sourcepub fn init_slice(slice: &'a mut [u8]) -> Result<Self, Error>
pub fn init_slice(slice: &'a mut [u8]) -> Result<Self, Error>
Initializes RBTree in a given slice
Sourcepub unsafe fn from_slice(slice: &'a mut [u8]) -> Result<Self, Error>
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
Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Returns the number of occupied nodes
This function runs in O(n), where n - is the number of nodes
Sourcepub fn clear(&mut self)
pub fn clear(&mut self)
Clears the tree
This function runs in O(n), where n - is the number of nodes
Sourcepub fn free_nodes_left(&self) -> usize
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
Sourcepub fn contains_key<Q>(&self, k: &Q) -> bool
pub fn contains_key<Q>(&self, k: &Q) -> bool
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
Sourcepub fn get_entry<Q>(&self, k: &Q) -> Option<(K, V)>
pub fn get_entry<Q>(&self, k: &Q) -> Option<(K, V)>
Returns a key-value pair corresponding to the supplied key
This function runs in O(log(n)), where n - is the number of nodes
Sourcepub fn get<Q>(&self, k: &Q) -> Option<V>
pub fn get<Q>(&self, k: &Q) -> Option<V>
Returns the value corresponding to the key
This function runs in O(log(n)), where n - is the number of nodes
Sourcepub fn insert(&mut self, k: K, v: V) -> Result<Option<V>, Error>
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
Sourcepub fn remove<Q>(&mut self, key: &Q) -> Option<V>
pub fn remove<Q>(&mut self, key: &Q) -> Option<V>
Deletes entry and returns deserialized value
This function runs in O(log(n)), where n - is the number of nodes
Sourcepub fn remove_entry<Q>(&mut self, key: &Q) -> Option<(K, V)>
pub fn remove_entry<Q>(&mut self, key: &Q) -> Option<(K, V)>
Deletes entry and returns deserialized key-value pair
This function runs in O(log(n)), where n - is the number of nodes
Sourcepub fn delete<Q>(&mut self, key: &Q) -> bool
pub fn delete<Q>(&mut self, key: &Q) -> bool
Deletes entry without deserializing the value
Returns true if there was a value with the given key.
Sourcepub fn first_entry(&self) -> Option<(K, V)>
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
Sourcepub fn last_entry(&self) -> Option<(K, V)>
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
Sourcepub fn pairs<'b>(&'b self) -> PairsIterator<'b, 'a, K, V, KSIZE, VSIZE> ⓘ
pub fn pairs<'b>(&'b self) -> PairsIterator<'b, 'a, K, V, KSIZE, VSIZE> ⓘ
Creates an iterator over key-value pairs, in order by key
Sourcepub fn keys<'b>(&'b self) -> KeysIterator<'b, 'a, K, V, KSIZE, VSIZE> ⓘ
pub fn keys<'b>(&'b self) -> KeysIterator<'b, 'a, K, V, KSIZE, VSIZE> ⓘ
Creates an iterator over keys, from smallest to biggest
Sourcepub fn values<'b>(&'b self) -> ValuesIterator<'b, 'a, K, V, KSIZE, VSIZE> ⓘ
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>where
K: Ord + BorshDeserialize + BorshSerialize + Debug,
V: BorshDeserialize + BorshSerialize + Debug,
impl<'a, K, V, const KSIZE: usize, const VSIZE: usize> Debug for RBTree<'a, K, V, KSIZE, VSIZE>where
K: Ord + BorshDeserialize + BorshSerialize + Debug,
V: BorshDeserialize + BorshSerialize + Debug,
Source§impl<'a, K, V, const KSIZE: usize, const VSIZE: usize> Extend<(K, V)> for RBTree<'a, K, V, KSIZE, VSIZE>
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)
fn extend<T: IntoIterator<Item = (K, V)>>(&mut self, iter: T)
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one)