#tree #tree-traversal #arena #reference-counting #index #trie

no-std indextree

Arena based tree structure by using indices instead of reference counted pointers

26 stable releases (4 major)

4.7.3 Oct 21, 2024
4.7.0 Jul 30, 2024
4.6.0 Mar 9, 2023
4.5.0 Sep 16, 2022
0.1.1 Dec 22, 2016

#38 in Data structures

Download history 7019/week @ 2024-08-19 7035/week @ 2024-08-26 7499/week @ 2024-09-02 5872/week @ 2024-09-09 4867/week @ 2024-09-16 8458/week @ 2024-09-23 5074/week @ 2024-09-30 5928/week @ 2024-10-07 7624/week @ 2024-10-14 6634/week @ 2024-10-21 6551/week @ 2024-10-28 6701/week @ 2024-11-04 6394/week @ 2024-11-11 6673/week @ 2024-11-18 6583/week @ 2024-11-25 6624/week @ 2024-12-02

26,585 downloads per month
Used in 110 crates (40 directly)

MIT license

120KB
1.5K SLoC

indextree

GitHub Actions Coverage Dependency Status Doc indextree License MIT Crates.io doc.rs

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.

Example usage

use indextree::Arena;

// Create a new arena
let arena = &mut Arena::new();

// Add some new nodes to the arena
let a = arena.new_node(1);
let b = arena.new_node(2);

// Append a to b
assert!(a.append(b, arena).is_ok());
assert_eq!(b.ancestors(arena).into_iter().count(), 2);

Benchmarks

https://github.com/mooman219/generational_arena_bench

Dependencies

~0–495KB
~10K SLoC