Get the ID of the first (leftmost) leaf in the tree
(&self)
| 118 | |
| 119 | /// Get the ID of the first (leftmost) leaf in the tree |
| 120 | pub fn get_first_leaf_id(&self) -> Option<NodeId> { |
| 121 | let mut current = &self.root; |
| 122 | |
| 123 | loop { |
| 124 | match current { |
| 125 | NodeRef::Leaf(leaf_id, _) => return Some(*leaf_id), |
| 126 | NodeRef::Branch(branch_id, _) => { |
| 127 | if let Some(branch) = self.get_branch(*branch_id) { |
| 128 | if !branch.children.is_empty() { |
| 129 | current = &branch.children[0]; |
| 130 | } else { |
| 131 | return None; |
| 132 | } |
| 133 | } else { |
| 134 | return None; |
| 135 | } |
| 136 | } |
| 137 | } |
| 138 | } |
| 139 | } |
| 140 | |
| 141 | /// Find the leaf node and index where a key should be located. |
| 142 | /// Returns the leaf `NodeId` and the insertion index within that leaf. |
no test coverage detected