diff --git a/package.json b/package.json index 7c76c05..dfba269 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "serializable-bptree", - "version": "4.0.3", + "version": "4.0.4", "description": "Store the B+tree flexibly, not only in-memory.", "types": "./dist/types/index.d.ts", "main": "./dist/cjs/index.cjs", diff --git a/src/BPTreeAsync.ts b/src/BPTreeAsync.ts index 919e2ea..643cd57 100644 --- a/src/BPTreeAsync.ts +++ b/src/BPTreeAsync.ts @@ -173,8 +173,11 @@ export class BPTreeAsync extends BPTree { (node.keys.length < Math.ceil(this.order/2) && !node.leaf) || (node.values.length < Math.ceil((this.order-1)/2) && node.leaf) ) { + if (node.parent === null) { + return + } let isPredecessor = false - let parentNode = await this.getNode(node.parent!) as BPTreeInternalNode + let parentNode = await this.getNode(node.parent) as BPTreeInternalNode let prevNode: BPTreeInternalNode|null = null let nextNode: BPTreeInternalNode|null = null let prevValue: V|null = null diff --git a/src/BPTreeSync.ts b/src/BPTreeSync.ts index 0345447..b07522b 100644 --- a/src/BPTreeSync.ts +++ b/src/BPTreeSync.ts @@ -173,8 +173,11 @@ export class BPTreeSync extends BPTree { (node.keys.length < Math.ceil(this.order/2) && !node.leaf) || (node.values.length < Math.ceil((this.order-1)/2) && node.leaf) ) { + if (node.parent === null) { + return + } let isPredecessor = false - let parentNode = this.getNode(node.parent!) as BPTreeInternalNode + let parentNode = this.getNode(node.parent) as BPTreeInternalNode let prevNode: BPTreeInternalNode|null = null let nextNode: BPTreeInternalNode|null = null let prevValue: V|null = null