This commit is contained in:
bronku 2025-12-14 00:39:29 +01:00
parent ce0d7512d2
commit b68282dbc3
2 changed files with 34 additions and 0 deletions

View file

@ -226,6 +226,35 @@ where
} }
} }
} }
pub fn dump_records(&mut self) {
let mut loc = self.leftmost_leaf();
while let Some(Node::Leaf(leaf)) = self.storage.read_node(loc) {
for record in &leaf.values {
println!("{:?}", record);
}
match leaf.next {
Some(next) => loc = next,
None => break,
}
}
}
fn leftmost_leaf(&mut self) -> usize {
let mut loc = self.header.root;
loop {
match self.storage.read_node(loc) {
Some(Node::Internal(internal)) => {
loc = internal.children[0];
}
Some(Node::Leaf(_)) => return loc,
_ => panic!("Corrupt tree"),
}
}
}
} }
#[cfg(test)] #[cfg(test)]

View file

@ -51,6 +51,11 @@ fn repl(tree: &mut BPlusTree<FileStorage>) {
continue; continue;
} }
if input == "all" {
tree.dump_records();
continue;
}
match handle_command(tree, input) { match handle_command(tree, input) {
Ok(()) => {} Ok(()) => {}
Err(err) => println!("Error: {}", err), Err(err) => println!("Error: {}", err),