Skip to content

Commit 465bbf4

Browse files
Craig MacomberCraig Macomber
authored andcommitted
fix isShared bug, making regression test pass
1 parent aca7081 commit 465bbf4

File tree

4 files changed

+23
-7
lines changed

4 files changed

+23
-7
lines changed

b+tree.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@ var __extends = (this && this.__extends) || (function () {
33
var extendStatics = function (d, b) {
44
extendStatics = Object.setPrototypeOf ||
55
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6-
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
6+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
77
return extendStatics(d, b);
88
};
99
return function (d, b) {
10+
if (typeof b !== "function" && b !== null)
11+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
1012
extendStatics(d, b);
1113
function __() { this.constructor = d; }
1214
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
@@ -979,9 +981,16 @@ var BTree = /** @class */ (function () {
979981
return typeof r === "number" ? r : r.break;
980982
}
981983
finally {
982-
while (root.keys.length <= 1 && !root.isLeaf)
984+
var isShared = undefined;
985+
while (root.keys.length <= 1 && !root.isLeaf) {
986+
isShared || (isShared = root.isShared);
983987
this._root = root = root.keys.length === 0 ? EmptyLeaf :
984988
root.children[0];
989+
}
990+
// If any ancestor of the new root was shared, the new root must also be shared
991+
if (isShared) {
992+
root.isShared = true;
993+
}
985994
}
986995
};
987996
/** Same as `editRange` except that the callback is called for all pairs. */

b+tree.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1094,9 +1094,16 @@ export default class BTree<K=any, V=any> implements ISortedMapF<K,V>, ISortedMap
10941094
var r = root.forRange(low, high, includeHigh, true, this, initialCounter || 0, onFound);
10951095
return typeof r === "number" ? r : r.break!;
10961096
} finally {
1097-
while (root.keys.length <= 1 && !root.isLeaf)
1097+
let isShared: undefined | true = undefined;
1098+
while (root.keys.length <= 1 && !root.isLeaf) {
1099+
isShared ||= root.isShared;
10981100
this._root = root = root.keys.length === 0 ? EmptyLeaf :
10991101
(root as any as BNodeInternal<K,V>).children[0];
1102+
}
1103+
// If any ancestor of the new root was shared, the new root must also be shared
1104+
if (isShared) {
1105+
root.isShared = true;
1106+
}
11001107
}
11011108
}
11021109

package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
"testpack-cli": "^1.1.4",
5959
"ts-jest": "^26.4.3",
6060
"ts-node": "^7.0.1",
61-
"typescript": "^3.8.3",
61+
"typescript": "^4.0.8",
6262
"uglify-js": "^3.11.4"
6363
},
6464
"dependencies": {},

0 commit comments

Comments
 (0)