Recursively count leaf nodes with proper arena access.
(&self, node: &NodeRef<K, V>)
| 50 | |
| 51 | /// Recursively count leaf nodes with proper arena access. |
| 52 | fn leaf_count_recursive(&self, node: &NodeRef<K, V>) -> usize { |
| 53 | match node { |
| 54 | NodeRef::Leaf(_, _) => 1, // An arena leaf is one leaf node |
| 55 | NodeRef::Branch(id, _) => self |
| 56 | .get_branch(*id) |
| 57 | .map(|branch| { |
| 58 | branch |
| 59 | .children |
| 60 | .iter() |
| 61 | .map(|child| self.leaf_count_recursive(child)) |
| 62 | .sum() |
| 63 | }) |
| 64 | .unwrap_or(0), |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | /// Clear all items from the tree. |
| 69 | pub fn clear(&mut self) { |