Open Karanstr opened 1 month ago
The original (super outdated) code here: Can be used a reference when I come to implement a full object verion of this compacting.
fn _compact_root_children(&mut self, root:&mut NodeAddress) -> bool {
let child_directions = [1, 0];
let mut new_root_node = Node::new_empty();
let children = self.get_node(&root).child_indexes;
for index in 0 .. child_directions.len() {
let address = NodeAddress::new(root.layer - 1, children[index]);
let node = self.get_node(&address);
let (child_count, last_index) = node.count_kids_and_get_last();
if child_count > 1 || last_index != child_directions[index] {
return false //Cannot compact root
}
new_root_node.child_indexes[index] = node.child_indexes[child_directions[index]];
} //If we don't terminate we are safe to lower the root
let new_root_index = self.add_node(root.layer - 1, new_root_node);
self.transfer_reference(&root, &NodeAddress::new(root.layer - 1, new_root_index));
root.layer -= 1;
root.index = new_root_index;
true //Successfully compacted root
}
Each layer I descend into the tree and test increases the optimality of my compacting script, but will also take longer, as it will have insert time complexity here once I figure it out. At what point do I no longer care about compacting nodes?