pub struct RedBlackTree<K: Ord, V, const N: usize> { /* private fields */ }Expand description
Index-based Red-Black Tree implementation
Implementations§
Source§impl<K: Ord, V, const N: usize> RedBlackTree<K, V, N>
impl<K: Ord, V, const N: usize> RedBlackTree<K, V, N>
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new empty red-black tree with capacity for up to N elements.
Nodes are preallocated using MaybeUninit, and no heap allocations are performed.
Sourcepub fn search(&self, key: &K) -> Option<&V>
pub fn search(&self, key: &K) -> Option<&V>
Searches for a value associated with the given key.
Returns a reference to the value if the key is found, or None otherwise.
Sourcepub fn insert(&mut self, key: K, value: V) -> Option<&V>
pub fn insert(&mut self, key: K, value: V) -> Option<&V>
Inserts a key-value pair into the tree.
If the key already exists, its value is replaced.
Sourcepub fn update(&mut self, key: K, value: V) -> Option<&V>
pub fn update(&mut self, key: K, value: V) -> Option<&V>
Updates the value for an existing key.
If the key is not found, it is inserted with the provided key and value.
Sourcepub fn min(&self) -> Option<(&K, &V)>
pub fn min(&self) -> Option<(&K, &V)>
Returns a reference to the smallest (minimum) key-value pair in the tree, if any.
Sourcepub fn max(&self) -> Option<(&K, &V)>
pub fn max(&self) -> Option<(&K, &V)>
Returns a reference to the largest (maximum) key-value pair in the tree, if any.
Sourcepub fn iter(&self) -> RedBlackTreeIter<'_, K, V, N> ⓘ
pub fn iter(&self) -> RedBlackTreeIter<'_, K, V, N> ⓘ
Returns an iterator over the key-value pairs of the tree in ascending key order.