Recursively count nodes in the tree.
(&self, node: &NodeRef<K, V>)
| 89 | |
| 90 | /// Recursively count nodes in the tree. |
| 91 | fn count_nodes_recursive(&self, node: &NodeRef<K, V>) -> (usize, usize) { |
| 92 | match node { |
| 93 | NodeRef::Leaf(_, _) => (1, 0), // Found a leaf |
| 94 | NodeRef::Branch(id, _) => { |
| 95 | if let Some(branch) = self.get_branch(*id) { |
| 96 | let mut total_leaves = 0; |
| 97 | let mut total_branches = 1; // Count this branch |
| 98 | |
| 99 | // Recursively count in all children |
| 100 | for child in &branch.children { |
| 101 | let (child_leaves, child_branches) = self.count_nodes_recursive(child); |
| 102 | total_leaves += child_leaves; |
| 103 | total_branches += child_branches; |
| 104 | } |
| 105 | |
| 106 | (total_leaves, total_branches) |
| 107 | } else { |
| 108 | // Invalid branch reference |
| 109 | (0, 0) |
| 110 | } |
| 111 | } |
| 112 | } |
| 113 | } |
| 114 | |
| 115 | // ============================================================================ |
| 116 | // TREE NAVIGATION HELPERS |
no test coverage detected