{"id":22611507,"url":"https://github.com/antouhou/easy-tree","last_synced_at":"2025-06-19T23:41:22.946Z","repository":{"id":242507763,"uuid":"809722377","full_name":"antouhou/easy-tree","owner":"antouhou","description":"A simple and efficient tree structure library for Rust with recursive traversal","archived":false,"fork":false,"pushed_at":"2024-11-18T11:41:55.000Z","size":20,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-08T10:52:01.494Z","etag":null,"topics":["algorithms","data-structures","recursive","rust","traversal","tree","tree-structure","trees"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/antouhou.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-06-03T10:22:43.000Z","updated_at":"2025-03-16T01:24:41.000Z","dependencies_parsed_at":"2024-12-08T16:11:36.327Z","dependency_job_id":"7840ae08-de6d-442c-b727-571a743b3818","html_url":"https://github.com/antouhou/easy-tree","commit_stats":null,"previous_names":["antouhou/easy-tree"],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/antouhou%2Feasy-tree","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/antouhou%2Feasy-tree/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/antouhou%2Feasy-tree/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/antouhou%2Feasy-tree/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/antouhou","download_url":"https://codeload.github.com/antouhou/easy-tree/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248360052,"owners_count":21090642,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["algorithms","data-structures","recursive","rust","traversal","tree","tree-structure","trees"],"created_at":"2024-12-08T16:11:25.909Z","updated_at":"2025-04-11T07:56:35.020Z","avatar_url":"https://github.com/antouhou.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# easy-tree\n\n[![Crates.io](https://img.shields.io/crates/v/easy-tree.svg)](https://crates.io/crates/easy-tree)\n[![Documentation](https://docs.rs/easy-tree/badge.svg)](https://docs.rs/easy-tree)\n[![Build and test](https://github.com/antouhou/easy-tree/actions/workflows/test.yml/badge.svg?branch=main)](https://github.com/antouhou/easy-tree/actions)\n\n`easy-tree` is a lightweight Rust library for managing and traversing hierarchical data structures. It provides a simple interface for creating trees and supports **recursive depth-first traversal** with pre- and post-processing callbacks.\n\n## Key Features\n\n- **Depth-first traversal**: Easily process nodes with callbacks before and after their subtrees.\n- **Simple API**: Add, modify, and retrieve nodes effortlessly.\n- **Customizable traversal logic**: Use callbacks to handle specific traversal behaviors.\n- **Optional parallel iteration**: Boost performance with [rayon](https://docs.rs/rayon).\n\n## Why Use easy-tree?\n\n1. **Designed for Hierarchical Data**: Ideal for file systems, DOM structures, organizational charts, and more.\n2. **Traverse with Precision**: Depth-first traversal with pre- and post-order processing in one simple call.\n3. **Memory Efficient**: Minimal overhead with direct references between nodes.\n4. **Extensible**: Integrates easily into larger systems and workflows.\n\n---\n\n## Installation\n\nAdd `easy-tree` to your `Cargo.toml`:\n\n```toml\n[dependencies]\neasy-tree = \"0.1\"\n```\n\nTo enable parallel iteration:\n\n```toml\n[dependencies]\neasy-tree = { version = \"0.1\", features = [\"rayon\"] }\n```\n\n---\n\n## How It Works\n\n### Tree Structure\n\nEach node in the tree has:\n- A **data payload** (your custom type)\n- A single parent (or `None` for the root)\n- A list of child indices\n\n### Traversal Flow\n\nHere’s an illustration of a depth-first traversal order:\n\n```\nRoot\n├── Child 1\n│   └── Grandchild 1\n├── Child 2\n└── Child 3\n```\n\nTraversal output:\n1. `Visiting Child 1`\n2. `Visiting Grandchild 1`\n3. `Leaving Grandchild 1`\n4. `Leaving Child 1`\n5. ...\n\n---\n\n## Examples\n\n### 1. Basic Tree Creation\n\n```rust\nuse easy_tree::Tree;\n\nfn main() {\n    let mut tree = Tree::new();\n    let root = tree.add_node(\"root\");\n    let child = tree.add_child(root, \"child\");\n    let grandchild = tree.add_child(child, \"grandchild\");\n\n    assert_eq!(tree.get(root), Some(\u0026\"root\"));\n    assert_eq!(tree.get(grandchild), Some(\u0026\"grandchild\"));\n}\n```\n\n### 2. Depth-First Traversal\n\n```rust\nuse easy_tree::Tree;\n\nfn main() {\n    let mut tree = Tree::new();\n    let root = tree.add_node(\"root\");\n    let child1 = tree.add_child(root, \"child1\");\n    let grandchild1 = tree.add_child(child1, \"grandchild1\");\n    let child2 = tree.add_child(root, \"child2\");\n\n    let mut log = vec![];\n    tree.traverse(\n        |idx, data, log| log.push(format!(\"Visiting node {}: {}\", idx, data)),\n        |idx, data, log| log.push(format!(\"Finished node {}: {}\", idx, data)),\n        \u0026mut log,\n    );\n\n    println!(\"{:?}\", log);\n}\n```\n\n### 3. Parallel Iteration (Optional)\n\n```rust\nuse easy_tree::Tree;\n\nfn main() {\n    let mut tree = Tree::new();\n    let root = tree.add_node(0);\n    let _child1 = tree.add_child(root, 1);\n    let _child2 = tree.add_child(root, 2);\n\n    #[cfg(feature = \"rayon\")]\n    {\n        tree.par_iter().for_each(|(idx, data)| {\n            println!(\"Processing node {}: {}\", idx, data);\n        });\n    }\n}\n```\n\n---\n\n## Use Cases\n\n### Represent a File System\n\n```rust\nuse easy_tree::Tree;\n\nfn main() {\n    let mut fs = Tree::new();\n    let root = fs.add_node(\"root/\");\n    let home = fs.add_child(root, \"home/\");\n    let user = fs.add_child(home, \"user/\");\n    let file = fs.add_child(user, \"file.txt\");\n\n    println!(\"Tree structure:\");\n    fs.traverse(\n        |_, data, _| println!(\"Entering {}\", data),\n        |_, data, _| println!(\"Leaving {}\", data),\n        \u0026mut (),\n    );\n}\n```\n\n---\n\n## Performance\n\n- **Low Memory Overhead**: Nodes are stored contiguously in a vector.\n- **Efficient Traversal**: Iterative depth-first traversal minimizes recursion overhead.\n- **Parallel Ready**: Enable the `rayon` feature for concurrent processing.\n\n---\n\n## Advanced Features\n\n1. **Custom Traversal Logic**: Use pre- and post-processing callbacks for fine-grained control.\n2. **Flexible Node Access**: Retrieve, update, or delete nodes efficiently.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fantouhou%2Feasy-tree","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fantouhou%2Feasy-tree","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fantouhou%2Feasy-tree/lists"}