dump tree

This commit is contained in:
bronku 2025-12-14 00:35:08 +01:00
parent d54d86d948
commit ce0d7512d2
2 changed files with 26 additions and 1 deletions

View file

@ -202,6 +202,30 @@ where
self.insert_into_parent(new_key, new_internal_loc, path); self.insert_into_parent(new_key, new_internal_loc, path);
} }
} }
pub fn dump_tree(&mut self) {
self.dump_node(self.header.root, 0);
}
fn dump_node(&mut self, loc: usize, depth: usize) {
let indent = " ".repeat(depth);
match self.storage.read_node(loc) {
Some(Node::Leaf(leaf)) => {
println!("{}Leaf [{}] keys={:?}", indent, loc, leaf.keys);
}
Some(Node::Internal(internal)) => {
println!("{}Internal [{}] keys={:?}", indent, loc, internal.keys);
for &child in &internal.children {
self.dump_node(child, depth + 1);
}
}
_ => {
println!("{}<invalid node @{}>", indent, loc);
}
}
}
} }
#[cfg(test)] #[cfg(test)]

View file

@ -46,7 +46,8 @@ fn repl(tree: &mut BPlusTree<FileStorage>) {
break; break;
} }
if input == "help" { if input == "tree" {
tree.dump_tree();
continue; continue;
} }