dump nodes

This commit is contained in:
bronku 2025-12-14 00:48:38 +01:00
parent b68282dbc3
commit 2466e27bd0
4 changed files with 39 additions and 2 deletions

View file

@ -4,7 +4,7 @@ use crate::record::Record;
use crate::storage::Storage;
pub struct BPlusTree<S> {
storage: S,
pub storage: S,
header: HeaderNode,
}

View file

@ -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 {

View file

@ -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),

View file

@ -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>,
}