all
This commit is contained in:
parent
ce0d7512d2
commit
b68282dbc3
2 changed files with 34 additions and 0 deletions
29
src/btree.rs
29
src/btree.rs
|
|
@ -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)]
|
||||
|
|
|
|||
|
|
@ -51,6 +51,11 @@ fn repl(tree: &mut BPlusTree<FileStorage>) {
|
|||
continue;
|
||||
}
|
||||
|
||||
if input == "all" {
|
||||
tree.dump_records();
|
||||
continue;
|
||||
}
|
||||
|
||||
match handle_command(tree, input) {
|
||||
Ok(()) => {}
|
||||
Err(err) => println!("Error: {}", err),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue