Find parent of a node by traversal from root.
(&self, current: usize, target: usize)
| 94 | |
| 95 | /// Find parent of a node by traversal from root. |
| 96 | pub(crate) fn find_parent(&self, current: usize, target: usize) -> Option<usize> { |
| 97 | if let NodeKind::Internal { children } = &self.nodes[current].kind { |
| 98 | for child in children { |
| 99 | if child.node_idx == target { |
| 100 | return Some(current); |
| 101 | } |
| 102 | if let Some(p) = self.find_parent(child.node_idx, target) { |
| 103 | return Some(p); |
| 104 | } |
| 105 | } |
| 106 | } |
| 107 | None |
| 108 | } |
| 109 | |
| 110 | /// Condense root: if root is internal with 1 child, collapse. |
| 111 | pub(crate) fn condense_root(&mut self) { |