Struct RedBlackTree

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

Source

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.

Source

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.

Source

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.

Source

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.

Source

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

Returns a reference to the smallest (minimum) key-value pair in the tree, if any.

Source

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

Returns a reference to the largest (maximum) key-value pair in the tree, if any.

Source

pub fn remove(&mut self, key: K) -> bool

If the key is not found, nothing happens.

Source

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

Returns an iterator over the key-value pairs of the tree in ascending key order.

Source

pub fn is_valid(&self) -> bool

Checks if the red-black tree invariants are preserved.

Source

pub fn contains_key(&self, key: &K) -> bool

Source

pub fn get_mut(&mut self, key: &K) -> Option<&mut V>

Source

pub fn len(&self) -> usize

Source

pub fn isEmpty(&self) -> bool

Trait Implementations§

Source§

impl<K: Debug + Ord, V: Debug, const N: usize> Debug for RedBlackTree<K, V, N>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<K, V, const N: usize> Freeze for RedBlackTree<K, V, N>
where K: Freeze, V: Freeze,

§

impl<K, V, const N: usize> RefUnwindSafe for RedBlackTree<K, V, N>

§

impl<K, V, const N: usize> Send for RedBlackTree<K, V, N>
where K: Send, V: Send,

§

impl<K, V, const N: usize> Sync for RedBlackTree<K, V, N>
where K: Sync, V: Sync,

§

impl<K, V, const N: usize> Unpin for RedBlackTree<K, V, N>
where K: Unpin, V: Unpin,

§

impl<K, V, const N: usize> UnwindSafe for RedBlackTree<K, V, N>
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> 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.