rs-avl
A compact, generic ordered set powered by an AVL tree. It keeps itself height-balanced after every insertion and removal, giving predictable logarithmic lookup while retaining simple, sorted iteration.
Use it for primitive values, strings, domain records, or any type for which
you can define a meaningful Ord
implementation.
Highlights
O(log n)insertion, removal, and searchO(log n + k)bounded ranges returningkvalues- Unique-value set semantics
- No
Clonerequirement on stored values - Borrowed-key lookup with
Borrow - In-order, pre-order, post-order, and level-order traversals
FromIterator,Extend, and iteration by reference
Installation
[]
= "0.1"
Quick start
use AvlTree;
let mut tree: = .into_iter.collect;
assert!;
assert!;
assert_eq!;
assert_eq!;
assert_eq!;
assert!;
Store your own structs
The tree is not limited to numbers. Deriving Ord gives an arbitrary Rust
struct a lexicographic ordering based on its field order. Here, releases sort
by semantic version first, then by channel and title:
use AvlTree;
let mut releases = new;
releases.insert;
releases.insert;
releases.insert;
let versions = releases
.iter
.map
.;
assert_eq!;
assert_eq!;
assert_eq!;
Notice that Release does not implement Clone: the tree takes ownership of
each value and its iterators yield shared references. For domain-specific
ordering—such as comparing releases by version only—you can implement Ord
manually and the AVL tree will follow those rules everywhere.
Traversal and inspection
iter() and in_order() yield ascending values. pre_order(),
post_order(), and level_order() expose the tree's current balanced shape,
which is useful for visualization and teaching. root() provides read-only
node inspection without allowing callers to break ordering or height
invariants.
Full API documentation is available on docs.rs.
License
Dual-licensed under your choice of GPL-3.0-only or Apache-2.0.