dump nodes
This commit is contained in:
parent
b68282dbc3
commit
2466e27bd0
4 changed files with 39 additions and 2 deletions
|
|
@ -4,7 +4,7 @@ use crate::record::Record;
|
|||
use crate::storage::Storage;
|
||||
|
||||
pub struct BPlusTree<S> {
|
||||
storage: S,
|
||||
pub storage: S,
|
||||
header: HeaderNode,
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -27,6 +27,38 @@ impl FileStorage {
|
|||
page_writes: 0,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn dump_pages(&mut self) {
|
||||
let total = self.total_nodes();
|
||||
for loc in 0..total {
|
||||
print!("Page {}: ", loc);
|
||||
|
||||
match self.read_node(loc) {
|
||||
Some(Node::Header(header)) => {
|
||||
println!("Header, root: {:?}", header.root)
|
||||
}
|
||||
Some(Node::Leaf(leaf)) => {
|
||||
println!(
|
||||
"Leaf keys={:?} values={} next={:?}",
|
||||
leaf.keys,
|
||||
leaf.values.len(),
|
||||
leaf.next
|
||||
);
|
||||
}
|
||||
Some(Node::Internal(internal)) => {
|
||||
println!(
|
||||
"Internal keys={:?} children={:?}",
|
||||
internal.keys, internal.children
|
||||
);
|
||||
}
|
||||
None => {
|
||||
println!("<empty or invalid>");
|
||||
}
|
||||
}
|
||||
|
||||
self.page_reads -= 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Storage for FileStorage {
|
||||
|
|
|
|||
|
|
@ -56,6 +56,11 @@ fn repl(tree: &mut BPlusTree<FileStorage>) {
|
|||
continue;
|
||||
}
|
||||
|
||||
if input == "nodes" {
|
||||
tree.storage.dump_pages();
|
||||
continue;
|
||||
}
|
||||
|
||||
match handle_command(tree, input) {
|
||||
Ok(()) => {}
|
||||
Err(err) => println!("Error: {}", err),
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ pub struct HeaderNode {
|
|||
#[derive(Debug, Clone, Encode, Decode, PartialEq, Eq)]
|
||||
pub struct LeafNode {
|
||||
pub keys: Vec<i32>,
|
||||
pub values: Vec<Record>,
|
||||
pub values: Vec<Option<Record>>,
|
||||
pub next: Option<usize>,
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue