augmented-rbtree
An augmented red-black tree for Rust with generic, user-defined per-node statistics.
augmented-rbtree automatically maintains augmentation data during inserts, deletes, and rotations.
Build interval trees, order-statistics trees, and other indexed tree structures with O(log n) updates and lookups.
Highlights
- Generic augmentation via the
Augmenttrait for customized subtree statistics. - Red-Black tree fallback without augmentation for standard key-value storage has no augmentation calculation overhead.
- Ordered-map API parity with
BTreeMap, including range queries, iterators, andEntrymechanics. - Core
no_stdcompatibility supporting distinct stack-only and custom allocator profiles. - Tree navigation cursors allows custom traversal strategies.
InOrdertraversal iterator with customizable pruning and filtering of subtrees.- Native topology extraction utilities to generate Graphviz layout files for visual debugging.
- Built-in, conditional compilation flags for an optimized
IntervalTreeandserdesupport. - Extensive test coverage verified through local integration test matrices and example recipes.
- Validated via Miri checks and isolated fuzzing workflows to ensure strict memory safety.
Installation
Default configuration uses alloc:
[]
= "0.3"
Quick start
Implement Augment to define your subtree statistic:
use ;
;
Common use cases: order-statistics trees, interval trees, range-sum trees, and range-max trees.
Feature flags
| Feature | Purpose |
|---|---|
alloc (default) |
Use global allocator-backed storage. |
interval-tree |
Enable IntervalTree type and overlap queries. |
serde |
Enable Serialize/Deserialize support. |
allocator-api |
Enable custom allocators on stable via allocator-api2. |
nightly |
Enable nightly allocator API integration. |
Note:
allocator-apiandnightlyare mutually exclusive.
Interval tree example
[]
= { = "0.3", = ["interval-tree"] }
use ;
Configuration recipes
Use strict no_std mode with no default features:
[]
= { = "0.2", = false }
Use custom allocator support on stable:
[]
= { = "0.2", = false, = ["allocator-api"] }
Use nightly allocator API:
[]
= { = "0.2", = false, = ["nightly"] }
Performance
Core operations remain $O(\log n)$ while maintaining augmentation data during balancing and structural updates.
Run benchmarks:
Visualization (optional)
The crate includes a topology traversal API and a visualization example.
This runs the example at examples/visualization.rs and generates a Graphviz SVG layout.
MSRV
- Rust 1.87+
License
Licensed under either of:
- Apache License, Version 2.0 (LICENSE-APACHE or http://apache.org/licenses/LICENSE-2.0)
- MIT License (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Contributing
See CONTRIBUTING.md.