in src/tree.rs [560:591]
fn retrieve_path(&mut self, key: &TreeIndex) -> Vec<usize> {
let mut vec: Vec<usize> = Vec::new();
// Start from the index of the root.
let mut node_idx = TreeIndex::zero(0);
let mut node: usize = self.root;
vec.push(node); // Add the root to the path.
for i in 0..self.height {
// Add the left child if not exist.
if self.nodes[node].get_lch().is_none() {
self.add_lch(node);
}
// Add the right child if not exist.
if self.nodes[node].get_rch().is_none() {
self.add_rch(node);
}
// Move on to the next node in the path.
if key.get_bit(i) == 0 {
// Go to the left child.
node = self.nodes[node].get_lch().unwrap();
node_idx = node_idx.get_lch_index();
} else {
// Go to the right child.
node = self.nodes[node].get_rch().unwrap();
node_idx = node_idx.get_rch_index();
}
vec.push(node);
}
vec
}