Recursively count elements with proper arena access.
(&self, node: &NodeRef<K, V>)
| 18 | |
| 19 | /// Recursively count elements with proper arena access. |
| 20 | fn len_recursive(&self, node: &NodeRef<K, V>) -> usize { |
| 21 | match node { |
| 22 | NodeRef::Leaf(id, _) => self.get_leaf(*id).map(|leaf| leaf.len()).unwrap_or(0), |
| 23 | NodeRef::Branch(id, _) => self |
| 24 | .get_branch(*id) |
| 25 | .map(|branch| { |
| 26 | branch |
| 27 | .children |
| 28 | .iter() |
| 29 | .map(|child| self.len_recursive(child)) |
| 30 | .sum() |
| 31 | }) |
| 32 | .unwrap_or(0), |
| 33 | } |
| 34 | } |
| 35 | |
| 36 | /// Returns true if the tree is empty. |
| 37 | pub fn is_empty(&self) -> bool { |
no test coverage detected