indextree
Arena based tree structure with multithreading support
This arena tree structure is using just a single Vec and numerical identifiers
(indices in the vector) instead of reference counted pointers. This means there
is no RefCell and mutability is handled in a way much more idiomatic to Rust
through unique (&mut) access to the arena. The tree can be sent or shared across
threads like a Vec. This enables general multiprocessing support like
parallel tree traversals.
Features
| Feature | Default | Description |
|---|---|---|
std |
yes | Standard library support. Disable for no_std (requires alloc). |
macros |
yes | tree! macro for declarative tree construction. |
deser |
no | Serde serialization and deserialization. |
par_iter |
no | Parallel iteration via rayon. |
Example usage
use Arena;
// Create a new arena
let arena = &mut new;
// Add some new nodes to the arena
let a = arena.new_node;
let b = arena.new_node;
// Append b to a
a.append;
assert_eq!;
Building trees with the tree! macro
The optional macros feature (enabled by default) provides a tree! macro
for declarative tree construction:
use ;
let arena = &mut new;
let root = tree!;
assert_eq!;
assert_eq!;
Building a file system tree
use Arena;
let arena = &mut new;
let root = arena.new_node;
let etc = root.append_value;
let usr = root.append_value;
etc.append_value;
etc.append_value;
let bin = usr.append_value;
bin.append_value;
// Traverse and collect paths
let descendants: = root
.descendants
.map
.collect;
assert_eq!;
Parallel iteration
With the par_iter feature, trees can be traversed in parallel using
rayon:
use Arena;
use *;
let arena = &mut new;
let root = arena.new_node;
for i in 1..=1000
let sum: i64 = arena.par_iter.map.sum;
assert_eq!;