MCPcopy Create free account
hub / github.com/KentBeck/BPlusTree3 / count_nodes_recursive

Method count_nodes_recursive

rust/src/tree_structure.rs:91–113  ·  view source on GitHub ↗

Recursively count nodes in the tree.

(&self, node: &NodeRef<K, V>)

Source from the content-addressed store, hash-verified

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

Callers 1

count_nodes_in_treeMethod · 0.80

Calls 1

get_branchMethod · 0.80

Tested by

no test coverage detected