dump tree
This commit is contained in:
parent
d54d86d948
commit
ce0d7512d2
2 changed files with 26 additions and 1 deletions
24
src/btree.rs
24
src/btree.rs
|
|
@ -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)]
|
||||||
|
|
|
||||||
|
|
@ -46,7 +46,8 @@ fn repl(tree: &mut BPlusTree<FileStorage>) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if input == "help" {
|
if input == "tree" {
|
||||||
|
tree.dump_tree();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue