Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: move child resolution to bptree node #316

Merged
merged 2 commits into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions src/btree/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ export class BTreeNode {
private readonly dataFileResolver: RangeResolver;
private readonly fileFormat: FileFormat;
private readonly pageFieldType: FieldType;
private readonly tree: RangeResolver;
private readonly pageFieldWidth: number;

constructor(
keys: ReferencedValue[],
Expand All @@ -28,13 +30,17 @@ export class BTreeNode {
dataFileResolver: RangeResolver,
fileFormat: FileFormat,
pageFieldType: FieldType,
tree: RangeResolver,
pageFieldWidth: number,
) {
this.keys = keys;
this.leafPointers = leafPointers;
this.internalPointers = internalPointers;
this.dataFileResolver = dataFileResolver;
this.fileFormat = fileFormat;
this.pageFieldType = pageFieldType;
this.tree = tree;
this.pageFieldWidth = pageFieldWidth;
}

leaf(): boolean {
Expand All @@ -56,6 +62,25 @@ export class BTreeNode {
return this.internalPointers.length + this.leafPointers.length;
}

async readChildNode(index: number) {
friendlymatthew marked this conversation as resolved.
Show resolved Hide resolved
const childPointer = this.pointer(index);

const { node, bytesRead } = await BTreeNode.fromMemoryPointer(
childPointer,
this.tree,
this.dataFileResolver,
this.fileFormat,
this.pageFieldType,
this.pageFieldWidth,
);

if (!bytesRead) {
throw new Error("bytes read do not line up");
}

return node;
}

async unmarshalBinary(buffer: ArrayBuffer, pageFieldWidth: number) {
let dataView = new DataView(buffer);
let size = dataView.getUint32(0, true);
Expand Down Expand Up @@ -226,6 +251,8 @@ export class BTreeNode {
dataFilePointer,
fileFormat,
pageFieldType,
resolver,
pageFieldWidth,
);

await node.unmarshalBinary(bufferData, pageFieldWidth);
Expand Down
4 changes: 2 additions & 2 deletions src/btree/traversal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ export class TraversalIterator {
return false;
}
// propagate the rollover
this.records[i].node = await this.tree.readNode(
this.records[i + 1].node.pointer(this.records[i + 1].index),
this.records[i].node = await this.records[i + 1].node.readChildNode(
this.records[i + 1].index,
);

if (rolloverLeft) {
Expand Down
Loading