Tree-ds
This library provides a tree data structure that can be used to represent hierarchical data in Rust. The library allows you to perform the following operations on a tree:
- Enumerating all nodes in the tree
- Enumerating a section of the tree
- Finding a node in the tree
- Finding a section of the tree
- Adding a node to a certain position in the tree
- Removing a node from the tree
- Pruning a section of the tree
- Grafting a whole section of the tree onto another tree
- Finding the root of any node
- Finding the lowest common ancestor of two nodes
Why use this library?
There are many crates that make tree data structures available in Rust, but this library is unique in that it provides a tree data structure that is feature rich, easy to use and has a simple API. The library is also well-documented and has a comprehensive test suite that ensures that it works as expected. Most importantly, the library is designed to be fast and efficient, making it suitable for use in performance-critical applications.
Usage
Add the following to your Cargo.toml
file:
[]
= "0.1"
A crude example of how to use the library is shown below:
use ;
This will output:
Original Tree
*********************
Risk: 5000
├── Fixed Income: 2000
│ └── Debt: 1000
│ └── Debt Mutual Funds: 500
└── Equity: 3000
├── Mutual Funds: 1000
│ └── Equity Mutual Funds: 500
└── Stocks: 2000
├── Large Cap Stocks: 1000
├── Mid Cap Stocks: 1000
└── Small Cap Stocks: 1000
After Removing The Stocks Node
*******************
Risk: 5000
├── Fixed Income: 2000
│ └── Debt: 1000
│ └── Debt Mutual Funds: 500
└── Equity: 3000
└── Mutual Funds: 1000
└── Equity Mutual Funds: 500
Equity Sub Tree
*********************
Equity: 3000
└── Mutual Funds: 1000
└── Equity Mutual Funds: 500
Roadmap
- Add support for more tree operations.
- Add a macro to create trees from a DSL.
- Add support for weighted nodes.
License
This project is licensed under the MIT License - see the LICENSE file for details.