Trees in Rust
Trees in Rust
Trees are one of the most basic data structures. So, how are they supported in Rust?
In general, you can checkout https://crates.io/keywords/tree
Below is a table of specially selected crates. The less features, the fastest the implementation. So, if you are going to pick one, choose the one that exactly fits your use case.
feature\crate | tree-flat | ego-tree | description |
---|---|---|---|
stable node id | ✔ | ✔ | Nodes have a unique id that never invalidates |
root | ✔ | ✔ | Get root id |
get node | ✔ | ✔ | Get a node form an id |
mutate values | ✔ | ✔ | Get mutable reference to node values |
children | ✔ | ✔ | Get children of a node |
parent | ✔ | ✔ | Get the parent of a node |
siblings | ✔ | ✔ (separated in next_ and previous_siblings) | Get the siblings of a node |
detach | ❌ | ✔ | Node can not bea accessed anymore/td> </tr> |
remove | ❌ | ❌ | Node is not part of the tree |