MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / build_tree_hierarchy

Function build_tree_hierarchy

atomic-core/src/output/repo/tree.rs:938–947  ·  view source on GitHub ↗

Build a tree structure from flat paths. Organizes items into a hierarchical structure by parent-child relationships. # Arguments `items` - Flat list of tree items # Returns A map from parent path to child items. # Example ```rust use atomic_core::output::repo::{build_tree_hierarchy, TreeItem}; use atomic_core::types::{Inode, Position}; let items = vec![ TreeItem::file("src/main.rs", Inode:

(items: &[TreeItem])

Source from the content-addressed store, hash-verified

936/// assert!(hierarchy.get("src").is_some());
937/// ```
938pub fn build_tree_hierarchy(items: &[TreeItem]) -> HashMap<String, Vec<&TreeItem>> {
939 let mut hierarchy: HashMap<String, Vec<&TreeItem>> = HashMap::new();
940
941 for item in items {
942 let parent = item.parent_path().to_string();
943 hierarchy.entry(parent).or_default().push(item);
944 }
945
946 hierarchy
947}
948
949// ============================================================================
950// TESTS

Calls 2

parent_pathMethod · 0.80
pushMethod · 0.45