Skip to main content

Crate flat_rbtree

Crate flat_rbtree 

Source
Expand description

A fast, index-based Red-Black Tree with no heap allocations.

§Features

  • Flat storage: all nodes are stored in an array, avoiding pointer indirection.
  • No allocations per node: avoids Box, Rc, or Arc.
  • No-std: works in embedded or bare-metal environments without relying on the Rust standard library.
  • Preallocated with MaybeUninit: memory for all nodes is allocated upfront, minimizing runtime overhead and ensuring safe initialization.
  • Fixed capacity: tree size is bounded at compile-time, making resource usage predictable.
  • expanded feature (optional): enables tracking of subtree sizes for each node, allowing support for rank, select, and range_count queries.

§Simple example

use flat_rbtree::RedBlackTree;

let mut tree = RedBlackTree::<i32, &str, 10>::new();

tree.insert(10, "A");
tree.insert(20, "B");
tree.insert(5, "C");

tree.update(10, "Updated A");

if let Some(value) = tree.search(&10) {
    println!("Key 10 has value: {}", value);
}

for (key, value) in tree.iter() {
    println!("Key: {}, Value: {}", key, value);
}

assert_eq!(tree.remove(20), true);

if !tree.contains_key(&20) {
    println!("Key 20 successfully removed");
}

Structs§

RedBlackTree
Index-based Red-Black Tree implementation
RedBlackTreeIter
An iterator over the entries of a RedBlackTree.