avl-tree-typed 2.5.1 → 2.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.cjs +423 -52
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs-legacy/index.cjs +423 -51
- package/dist/cjs-legacy/index.cjs.map +1 -1
- package/dist/esm/index.mjs +423 -52
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm-legacy/index.mjs +423 -51
- package/dist/esm-legacy/index.mjs.map +1 -1
- package/dist/types/common/error.d.ts +9 -0
- package/dist/types/common/index.d.ts +1 -1
- package/dist/types/data-structures/binary-tree/avl-tree.d.ts +36 -0
- package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +42 -0
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +77 -2
- package/dist/types/data-structures/binary-tree/bst.d.ts +171 -0
- package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +57 -0
- package/dist/types/data-structures/binary-tree/segment-tree.d.ts +18 -0
- package/dist/types/data-structures/binary-tree/tree-map.d.ts +409 -0
- package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +411 -6
- package/dist/types/data-structures/binary-tree/tree-multi-set.d.ts +339 -6
- package/dist/types/data-structures/binary-tree/tree-set.d.ts +391 -0
- package/dist/types/data-structures/graph/directed-graph.d.ts +30 -0
- package/dist/types/data-structures/graph/undirected-graph.d.ts +27 -0
- package/dist/types/data-structures/hash/hash-map.d.ts +33 -0
- package/dist/types/data-structures/heap/heap.d.ts +42 -0
- package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +51 -0
- package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +45 -0
- package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +54 -0
- package/dist/types/data-structures/matrix/matrix.d.ts +24 -0
- package/dist/types/data-structures/queue/deque.d.ts +45 -0
- package/dist/types/data-structures/queue/queue.d.ts +36 -0
- package/dist/types/data-structures/stack/stack.d.ts +30 -0
- package/dist/types/data-structures/trie/trie.d.ts +36 -0
- package/dist/types/types/data-structures/binary-tree/bst.d.ts +1 -0
- package/dist/types/types/data-structures/binary-tree/tree-map.d.ts +5 -0
- package/dist/types/types/data-structures/binary-tree/tree-multi-set.d.ts +4 -0
- package/dist/types/types/data-structures/binary-tree/tree-set.d.ts +4 -0
- package/dist/umd/avl-tree-typed.js +420 -49
- package/dist/umd/avl-tree-typed.js.map +1 -1
- package/dist/umd/avl-tree-typed.min.js +3 -3
- package/dist/umd/avl-tree-typed.min.js.map +1 -1
- package/package.json +2 -2
- package/src/common/error.ts +19 -1
- package/src/common/index.ts +1 -1
- package/src/data-structures/base/iterable-element-base.ts +3 -2
- package/src/data-structures/binary-tree/avl-tree.ts +47 -0
- package/src/data-structures/binary-tree/binary-indexed-tree.ts +46 -4
- package/src/data-structures/binary-tree/binary-tree.ts +79 -4
- package/src/data-structures/binary-tree/bst.ts +441 -6
- package/src/data-structures/binary-tree/red-black-tree.ts +73 -0
- package/src/data-structures/binary-tree/segment-tree.ts +18 -0
- package/src/data-structures/binary-tree/tree-map.ts +434 -9
- package/src/data-structures/binary-tree/tree-multi-map.ts +426 -5
- package/src/data-structures/binary-tree/tree-multi-set.ts +350 -6
- package/src/data-structures/binary-tree/tree-set.ts +410 -8
- package/src/data-structures/graph/abstract-graph.ts +2 -2
- package/src/data-structures/graph/directed-graph.ts +30 -0
- package/src/data-structures/graph/undirected-graph.ts +27 -0
- package/src/data-structures/hash/hash-map.ts +35 -4
- package/src/data-structures/heap/heap.ts +46 -4
- package/src/data-structures/heap/max-heap.ts +2 -2
- package/src/data-structures/linked-list/doubly-linked-list.ts +51 -0
- package/src/data-structures/linked-list/singly-linked-list.ts +45 -0
- package/src/data-structures/linked-list/skip-linked-list.ts +59 -5
- package/src/data-structures/matrix/matrix.ts +33 -9
- package/src/data-structures/priority-queue/max-priority-queue.ts +2 -2
- package/src/data-structures/queue/deque.ts +45 -0
- package/src/data-structures/queue/queue.ts +36 -0
- package/src/data-structures/stack/stack.ts +30 -0
- package/src/data-structures/trie/trie.ts +38 -2
- package/src/types/data-structures/binary-tree/bst.ts +1 -0
- package/src/types/data-structures/binary-tree/tree-map.ts +6 -0
- package/src/types/data-structures/binary-tree/tree-multi-set.ts +5 -0
- package/src/types/data-structures/binary-tree/tree-set.ts +5 -0
package/dist/esm/index.mjs
CHANGED
|
@@ -57,6 +57,56 @@ function makeTrampoline(fn) {
|
|
|
57
57
|
}
|
|
58
58
|
__name(makeTrampoline, "makeTrampoline");
|
|
59
59
|
|
|
60
|
+
// src/common/error.ts
|
|
61
|
+
function raise(ErrorClass, message) {
|
|
62
|
+
throw new ErrorClass(message);
|
|
63
|
+
}
|
|
64
|
+
__name(raise, "raise");
|
|
65
|
+
var ERR = {
|
|
66
|
+
// Range / index
|
|
67
|
+
indexOutOfRange: /* @__PURE__ */ __name((index, min, max, ctx) => `${ctx ? ctx + ": " : ""}Index ${index} is out of range [${min}, ${max}].`, "indexOutOfRange"),
|
|
68
|
+
invalidIndex: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Index must be an integer.`, "invalidIndex"),
|
|
69
|
+
// Type / argument
|
|
70
|
+
invalidArgument: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidArgument"),
|
|
71
|
+
comparatorRequired: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Comparator is required for non-number/non-string/non-Date keys.`, "comparatorRequired"),
|
|
72
|
+
invalidKey: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidKey"),
|
|
73
|
+
notAFunction: /* @__PURE__ */ __name((name, ctx) => `${ctx ? ctx + ": " : ""}${name} must be a function.`, "notAFunction"),
|
|
74
|
+
invalidEntry: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Each entry must be a [key, value] tuple.`, "invalidEntry"),
|
|
75
|
+
invalidNaN: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}NaN is not a valid key.`, "invalidNaN"),
|
|
76
|
+
invalidDate: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Invalid Date key.`, "invalidDate"),
|
|
77
|
+
reduceEmpty: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Reduce of empty structure with no initial value.`, "reduceEmpty"),
|
|
78
|
+
callbackReturnType: /* @__PURE__ */ __name((expected, got, ctx) => `${ctx ? ctx + ": " : ""}Callback must return ${expected}; got ${got}.`, "callbackReturnType"),
|
|
79
|
+
// State / operation
|
|
80
|
+
invalidOperation: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidOperation"),
|
|
81
|
+
// Matrix
|
|
82
|
+
matrixDimensionMismatch: /* @__PURE__ */ __name((op) => `Matrix: Dimensions must be compatible for ${op}.`, "matrixDimensionMismatch"),
|
|
83
|
+
matrixSingular: /* @__PURE__ */ __name(() => "Matrix: Singular matrix, inverse does not exist.", "matrixSingular"),
|
|
84
|
+
matrixNotSquare: /* @__PURE__ */ __name(() => "Matrix: Must be square for inversion.", "matrixNotSquare"),
|
|
85
|
+
matrixNotRectangular: /* @__PURE__ */ __name(() => "Matrix: Must be rectangular for transposition.", "matrixNotRectangular"),
|
|
86
|
+
matrixRowMismatch: /* @__PURE__ */ __name((expected, got) => `Matrix: Expected row length ${expected}, but got ${got}.`, "matrixRowMismatch"),
|
|
87
|
+
// Order statistic
|
|
88
|
+
orderStatisticNotEnabled: /* @__PURE__ */ __name((method, ctx) => `${ctx ? ctx + ": " : ""}${method}() requires enableOrderStatistic: true.`, "orderStatisticNotEnabled")
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
// src/common/index.ts
|
|
92
|
+
var Range = class {
|
|
93
|
+
constructor(low, high, includeLow = true, includeHigh = true) {
|
|
94
|
+
this.low = low;
|
|
95
|
+
this.high = high;
|
|
96
|
+
this.includeLow = includeLow;
|
|
97
|
+
this.includeHigh = includeHigh;
|
|
98
|
+
}
|
|
99
|
+
static {
|
|
100
|
+
__name(this, "Range");
|
|
101
|
+
}
|
|
102
|
+
// Determine whether a key is within the range
|
|
103
|
+
isInRange(key, comparator) {
|
|
104
|
+
const lowCheck = this.includeLow ? comparator(key, this.low) >= 0 : comparator(key, this.low) > 0;
|
|
105
|
+
const highCheck = this.includeHigh ? comparator(key, this.high) <= 0 : comparator(key, this.high) < 0;
|
|
106
|
+
return lowCheck && highCheck;
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
|
|
60
110
|
// src/data-structures/base/iterable-element-base.ts
|
|
61
111
|
var IterableElementBase = class {
|
|
62
112
|
static {
|
|
@@ -75,7 +125,7 @@ var IterableElementBase = class {
|
|
|
75
125
|
if (options) {
|
|
76
126
|
const { toElementFn } = options;
|
|
77
127
|
if (typeof toElementFn === "function") this._toElementFn = toElementFn;
|
|
78
|
-
else if (toElementFn)
|
|
128
|
+
else if (toElementFn) raise(TypeError, "toElementFn must be a function type");
|
|
79
129
|
}
|
|
80
130
|
}
|
|
81
131
|
/**
|
|
@@ -238,7 +288,7 @@ var IterableElementBase = class {
|
|
|
238
288
|
acc = initialValue;
|
|
239
289
|
} else {
|
|
240
290
|
const first = iter.next();
|
|
241
|
-
if (first.done)
|
|
291
|
+
if (first.done) raise(TypeError, "Reduce of empty structure with no initial value");
|
|
242
292
|
acc = first.value;
|
|
243
293
|
index = 1;
|
|
244
294
|
}
|
|
@@ -473,50 +523,6 @@ var LinearBase = class _LinearBase extends IterableElementBase {
|
|
|
473
523
|
}
|
|
474
524
|
};
|
|
475
525
|
|
|
476
|
-
// src/common/error.ts
|
|
477
|
-
var ERR = {
|
|
478
|
-
// Range / index
|
|
479
|
-
indexOutOfRange: /* @__PURE__ */ __name((index, min, max, ctx) => `${ctx ? ctx + ": " : ""}Index ${index} is out of range [${min}, ${max}].`, "indexOutOfRange"),
|
|
480
|
-
invalidIndex: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Index must be an integer.`, "invalidIndex"),
|
|
481
|
-
// Type / argument
|
|
482
|
-
invalidArgument: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidArgument"),
|
|
483
|
-
comparatorRequired: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Comparator is required for non-number/non-string/non-Date keys.`, "comparatorRequired"),
|
|
484
|
-
invalidKey: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidKey"),
|
|
485
|
-
notAFunction: /* @__PURE__ */ __name((name, ctx) => `${ctx ? ctx + ": " : ""}${name} must be a function.`, "notAFunction"),
|
|
486
|
-
invalidEntry: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Each entry must be a [key, value] tuple.`, "invalidEntry"),
|
|
487
|
-
invalidNaN: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}NaN is not a valid key.`, "invalidNaN"),
|
|
488
|
-
invalidDate: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Invalid Date key.`, "invalidDate"),
|
|
489
|
-
reduceEmpty: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Reduce of empty structure with no initial value.`, "reduceEmpty"),
|
|
490
|
-
callbackReturnType: /* @__PURE__ */ __name((expected, got, ctx) => `${ctx ? ctx + ": " : ""}Callback must return ${expected}; got ${got}.`, "callbackReturnType"),
|
|
491
|
-
// State / operation
|
|
492
|
-
invalidOperation: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidOperation"),
|
|
493
|
-
// Matrix
|
|
494
|
-
matrixDimensionMismatch: /* @__PURE__ */ __name((op) => `Matrix: Dimensions must be compatible for ${op}.`, "matrixDimensionMismatch"),
|
|
495
|
-
matrixSingular: /* @__PURE__ */ __name(() => "Matrix: Singular matrix, inverse does not exist.", "matrixSingular"),
|
|
496
|
-
matrixNotSquare: /* @__PURE__ */ __name(() => "Matrix: Must be square for inversion.", "matrixNotSquare"),
|
|
497
|
-
matrixNotRectangular: /* @__PURE__ */ __name(() => "Matrix: Must be rectangular for transposition.", "matrixNotRectangular"),
|
|
498
|
-
matrixRowMismatch: /* @__PURE__ */ __name((expected, got) => `Matrix: Expected row length ${expected}, but got ${got}.`, "matrixRowMismatch")
|
|
499
|
-
};
|
|
500
|
-
|
|
501
|
-
// src/common/index.ts
|
|
502
|
-
var Range = class {
|
|
503
|
-
constructor(low, high, includeLow = true, includeHigh = true) {
|
|
504
|
-
this.low = low;
|
|
505
|
-
this.high = high;
|
|
506
|
-
this.includeLow = includeLow;
|
|
507
|
-
this.includeHigh = includeHigh;
|
|
508
|
-
}
|
|
509
|
-
static {
|
|
510
|
-
__name(this, "Range");
|
|
511
|
-
}
|
|
512
|
-
// Determine whether a key is within the range
|
|
513
|
-
isInRange(key, comparator) {
|
|
514
|
-
const lowCheck = this.includeLow ? comparator(key, this.low) >= 0 : comparator(key, this.low) > 0;
|
|
515
|
-
const highCheck = this.includeHigh ? comparator(key, this.high) <= 0 : comparator(key, this.high) < 0;
|
|
516
|
-
return lowCheck && highCheck;
|
|
517
|
-
}
|
|
518
|
-
};
|
|
519
|
-
|
|
520
526
|
// src/data-structures/base/iterable-entry-base.ts
|
|
521
527
|
var IterableEntryBase = class {
|
|
522
528
|
static {
|
|
@@ -787,6 +793,9 @@ var Queue = class _Queue extends LinearBase {
|
|
|
787
793
|
|
|
788
794
|
|
|
789
795
|
|
|
796
|
+
|
|
797
|
+
|
|
798
|
+
|
|
790
799
|
|
|
791
800
|
|
|
792
801
|
|
|
@@ -834,6 +843,9 @@ var Queue = class _Queue extends LinearBase {
|
|
|
834
843
|
|
|
835
844
|
|
|
836
845
|
|
|
846
|
+
|
|
847
|
+
|
|
848
|
+
|
|
837
849
|
|
|
838
850
|
|
|
839
851
|
|
|
@@ -897,6 +909,9 @@ var Queue = class _Queue extends LinearBase {
|
|
|
897
909
|
|
|
898
910
|
|
|
899
911
|
|
|
912
|
+
|
|
913
|
+
|
|
914
|
+
|
|
900
915
|
|
|
901
916
|
|
|
902
917
|
|
|
@@ -956,6 +971,9 @@ var Queue = class _Queue extends LinearBase {
|
|
|
956
971
|
|
|
957
972
|
|
|
958
973
|
|
|
974
|
+
|
|
975
|
+
|
|
976
|
+
|
|
959
977
|
|
|
960
978
|
|
|
961
979
|
|
|
@@ -1022,6 +1040,9 @@ var Queue = class _Queue extends LinearBase {
|
|
|
1022
1040
|
|
|
1023
1041
|
|
|
1024
1042
|
|
|
1043
|
+
|
|
1044
|
+
|
|
1045
|
+
|
|
1025
1046
|
|
|
1026
1047
|
|
|
1027
1048
|
|
|
@@ -1078,6 +1099,9 @@ var Queue = class _Queue extends LinearBase {
|
|
|
1078
1099
|
|
|
1079
1100
|
|
|
1080
1101
|
|
|
1102
|
+
|
|
1103
|
+
|
|
1104
|
+
|
|
1081
1105
|
|
|
1082
1106
|
|
|
1083
1107
|
|
|
@@ -1127,6 +1151,9 @@ var Queue = class _Queue extends LinearBase {
|
|
|
1127
1151
|
|
|
1128
1152
|
|
|
1129
1153
|
|
|
1154
|
+
|
|
1155
|
+
|
|
1156
|
+
|
|
1130
1157
|
|
|
1131
1158
|
|
|
1132
1159
|
|
|
@@ -1217,6 +1244,9 @@ var Queue = class _Queue extends LinearBase {
|
|
|
1217
1244
|
|
|
1218
1245
|
|
|
1219
1246
|
|
|
1247
|
+
|
|
1248
|
+
|
|
1249
|
+
|
|
1220
1250
|
|
|
1221
1251
|
|
|
1222
1252
|
|
|
@@ -1260,6 +1290,9 @@ var Queue = class _Queue extends LinearBase {
|
|
|
1260
1290
|
|
|
1261
1291
|
|
|
1262
1292
|
|
|
1293
|
+
|
|
1294
|
+
|
|
1295
|
+
|
|
1263
1296
|
|
|
1264
1297
|
|
|
1265
1298
|
|
|
@@ -1326,6 +1359,9 @@ var Queue = class _Queue extends LinearBase {
|
|
|
1326
1359
|
|
|
1327
1360
|
|
|
1328
1361
|
|
|
1362
|
+
|
|
1363
|
+
|
|
1364
|
+
|
|
1329
1365
|
|
|
1330
1366
|
|
|
1331
1367
|
|
|
@@ -1376,6 +1412,9 @@ var Queue = class _Queue extends LinearBase {
|
|
|
1376
1412
|
|
|
1377
1413
|
|
|
1378
1414
|
|
|
1415
|
+
|
|
1416
|
+
|
|
1417
|
+
|
|
1379
1418
|
|
|
1380
1419
|
|
|
1381
1420
|
|
|
@@ -1430,6 +1469,9 @@ var Queue = class _Queue extends LinearBase {
|
|
|
1430
1469
|
|
|
1431
1470
|
|
|
1432
1471
|
|
|
1472
|
+
|
|
1473
|
+
|
|
1474
|
+
|
|
1433
1475
|
|
|
1434
1476
|
|
|
1435
1477
|
|
|
@@ -1684,7 +1726,7 @@ var BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
1684
1726
|
if (isMapMode !== void 0) this._isMapMode = isMapMode;
|
|
1685
1727
|
if (isDuplicate !== void 0) this._isDuplicate = isDuplicate;
|
|
1686
1728
|
if (typeof toEntryFn === "function") this._toEntryFn = toEntryFn;
|
|
1687
|
-
else if (toEntryFn)
|
|
1729
|
+
else if (toEntryFn) raise(TypeError, ERR.notAFunction("toEntryFn", "BinaryTree"));
|
|
1688
1730
|
}
|
|
1689
1731
|
if (keysNodesEntriesOrRaws) this.setMany(keysNodesEntriesOrRaws);
|
|
1690
1732
|
}
|
|
@@ -1927,6 +1969,9 @@ var BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
1927
1969
|
|
|
1928
1970
|
|
|
1929
1971
|
|
|
1972
|
+
|
|
1973
|
+
|
|
1974
|
+
|
|
1930
1975
|
|
|
1931
1976
|
|
|
1932
1977
|
|
|
@@ -1978,6 +2023,9 @@ var BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
1978
2023
|
|
|
1979
2024
|
|
|
1980
2025
|
|
|
2026
|
+
|
|
2027
|
+
|
|
2028
|
+
|
|
1981
2029
|
|
|
1982
2030
|
|
|
1983
2031
|
|
|
@@ -2081,6 +2129,9 @@ var BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
2081
2129
|
|
|
2082
2130
|
|
|
2083
2131
|
|
|
2132
|
+
|
|
2133
|
+
|
|
2134
|
+
|
|
2084
2135
|
|
|
2085
2136
|
|
|
2086
2137
|
|
|
@@ -2120,6 +2171,9 @@ var BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
2120
2171
|
|
|
2121
2172
|
|
|
2122
2173
|
|
|
2174
|
+
|
|
2175
|
+
|
|
2176
|
+
|
|
2123
2177
|
|
|
2124
2178
|
|
|
2125
2179
|
|
|
@@ -2180,6 +2234,9 @@ var BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
2180
2234
|
|
|
2181
2235
|
|
|
2182
2236
|
|
|
2237
|
+
|
|
2238
|
+
|
|
2239
|
+
|
|
2183
2240
|
|
|
2184
2241
|
|
|
2185
2242
|
|
|
@@ -2239,6 +2296,9 @@ var BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
2239
2296
|
|
|
2240
2297
|
|
|
2241
2298
|
|
|
2299
|
+
|
|
2300
|
+
|
|
2301
|
+
|
|
2242
2302
|
|
|
2243
2303
|
|
|
2244
2304
|
|
|
@@ -2376,6 +2436,9 @@ var BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
2376
2436
|
|
|
2377
2437
|
|
|
2378
2438
|
|
|
2439
|
+
|
|
2440
|
+
|
|
2441
|
+
|
|
2379
2442
|
|
|
2380
2443
|
|
|
2381
2444
|
|
|
@@ -2431,6 +2494,9 @@ var BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
2431
2494
|
|
|
2432
2495
|
|
|
2433
2496
|
|
|
2497
|
+
|
|
2498
|
+
|
|
2499
|
+
|
|
2434
2500
|
|
|
2435
2501
|
|
|
2436
2502
|
|
|
@@ -2488,6 +2554,9 @@ var BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
2488
2554
|
|
|
2489
2555
|
|
|
2490
2556
|
|
|
2557
|
+
|
|
2558
|
+
|
|
2559
|
+
|
|
2491
2560
|
|
|
2492
2561
|
|
|
2493
2562
|
|
|
@@ -2533,6 +2602,9 @@ var BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
2533
2602
|
|
|
2534
2603
|
|
|
2535
2604
|
|
|
2605
|
+
|
|
2606
|
+
|
|
2607
|
+
|
|
2536
2608
|
|
|
2537
2609
|
|
|
2538
2610
|
|
|
@@ -2587,6 +2659,9 @@ var BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
2587
2659
|
|
|
2588
2660
|
|
|
2589
2661
|
|
|
2662
|
+
|
|
2663
|
+
|
|
2664
|
+
|
|
2590
2665
|
|
|
2591
2666
|
|
|
2592
2667
|
|
|
@@ -2668,6 +2743,9 @@ var BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
2668
2743
|
|
|
2669
2744
|
|
|
2670
2745
|
|
|
2746
|
+
|
|
2747
|
+
|
|
2748
|
+
|
|
2671
2749
|
|
|
2672
2750
|
|
|
2673
2751
|
|
|
@@ -2726,6 +2804,9 @@ var BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
2726
2804
|
|
|
2727
2805
|
|
|
2728
2806
|
|
|
2807
|
+
|
|
2808
|
+
|
|
2809
|
+
|
|
2729
2810
|
|
|
2730
2811
|
|
|
2731
2812
|
|
|
@@ -3200,6 +3281,9 @@ var BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
3200
3281
|
|
|
3201
3282
|
|
|
3202
3283
|
|
|
3284
|
+
|
|
3285
|
+
|
|
3286
|
+
|
|
3203
3287
|
|
|
3204
3288
|
|
|
3205
3289
|
|
|
@@ -3249,6 +3333,9 @@ var BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
3249
3333
|
|
|
3250
3334
|
|
|
3251
3335
|
|
|
3336
|
+
|
|
3337
|
+
|
|
3338
|
+
|
|
3252
3339
|
|
|
3253
3340
|
|
|
3254
3341
|
|
|
@@ -3302,6 +3389,9 @@ var BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
3302
3389
|
|
|
3303
3390
|
|
|
3304
3391
|
|
|
3392
|
+
|
|
3393
|
+
|
|
3394
|
+
|
|
3305
3395
|
|
|
3306
3396
|
|
|
3307
3397
|
|
|
@@ -3380,6 +3470,9 @@ var BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
3380
3470
|
|
|
3381
3471
|
|
|
3382
3472
|
|
|
3473
|
+
|
|
3474
|
+
|
|
3475
|
+
|
|
3383
3476
|
|
|
3384
3477
|
|
|
3385
3478
|
|
|
@@ -4015,12 +4108,16 @@ var BST = class extends BinaryTree {
|
|
|
4015
4108
|
} else {
|
|
4016
4109
|
this._comparator = this._createDefaultComparator();
|
|
4017
4110
|
}
|
|
4111
|
+
if (options.enableOrderStatistic) {
|
|
4112
|
+
this._enableOrderStatistic = true;
|
|
4113
|
+
}
|
|
4018
4114
|
} else {
|
|
4019
4115
|
this._comparator = this._createDefaultComparator();
|
|
4020
4116
|
}
|
|
4021
4117
|
if (keysNodesEntriesOrRaws) this.setMany(keysNodesEntriesOrRaws);
|
|
4022
4118
|
}
|
|
4023
4119
|
_root = void 0;
|
|
4120
|
+
_enableOrderStatistic = false;
|
|
4024
4121
|
/**
|
|
4025
4122
|
* Gets the root node of the tree.
|
|
4026
4123
|
* @remarks Time O(1)
|
|
@@ -4190,6 +4287,12 @@ var BST = class extends BinaryTree {
|
|
|
4190
4287
|
|
|
4191
4288
|
|
|
4192
4289
|
|
|
4290
|
+
|
|
4291
|
+
|
|
4292
|
+
|
|
4293
|
+
|
|
4294
|
+
|
|
4295
|
+
|
|
4193
4296
|
|
|
4194
4297
|
|
|
4195
4298
|
|
|
@@ -4351,6 +4454,84 @@ var BST = class extends BinaryTree {
|
|
|
4351
4454
|
const searchRange = range instanceof Range ? range : new Range(range[0], range[1]);
|
|
4352
4455
|
return this.search(searchRange, false, callback, startNode, iterationType);
|
|
4353
4456
|
}
|
|
4457
|
+
getByRank(k, callback = this._DEFAULT_NODE_CALLBACK, iterationType = this.iterationType) {
|
|
4458
|
+
if (!this._enableOrderStatistic) {
|
|
4459
|
+
raise(Error, ERR.orderStatisticNotEnabled("getByRank"));
|
|
4460
|
+
}
|
|
4461
|
+
if (k < 0 || k >= this._size) return void 0;
|
|
4462
|
+
let actualCallback = void 0;
|
|
4463
|
+
let actualIterationType = this.iterationType;
|
|
4464
|
+
if (typeof callback === "string") {
|
|
4465
|
+
actualIterationType = callback;
|
|
4466
|
+
} else if (callback) {
|
|
4467
|
+
actualCallback = callback;
|
|
4468
|
+
if (iterationType) {
|
|
4469
|
+
actualIterationType = iterationType;
|
|
4470
|
+
}
|
|
4471
|
+
}
|
|
4472
|
+
const node = actualIterationType === "RECURSIVE" ? this._getByRankRecursive(this._root, k) : this._getByRankIterative(this._root, k);
|
|
4473
|
+
if (!node) return void 0;
|
|
4474
|
+
return actualCallback ? actualCallback(node) : node.key;
|
|
4475
|
+
}
|
|
4476
|
+
getRank(keyNodeEntryOrPredicate, iterationType = this.iterationType) {
|
|
4477
|
+
if (!this._enableOrderStatistic) {
|
|
4478
|
+
raise(Error, ERR.orderStatisticNotEnabled("getRank"));
|
|
4479
|
+
}
|
|
4480
|
+
if (!this._root || this._size === 0) return -1;
|
|
4481
|
+
let actualIterationType = this.iterationType;
|
|
4482
|
+
if (iterationType) actualIterationType = iterationType;
|
|
4483
|
+
let key;
|
|
4484
|
+
if (typeof keyNodeEntryOrPredicate === "function") {
|
|
4485
|
+
const results = this.search(keyNodeEntryOrPredicate, true);
|
|
4486
|
+
if (results.length === 0 || results[0] === void 0) return -1;
|
|
4487
|
+
key = results[0];
|
|
4488
|
+
} else if (keyNodeEntryOrPredicate === null || keyNodeEntryOrPredicate === void 0) {
|
|
4489
|
+
return -1;
|
|
4490
|
+
} else if (this.isNode(keyNodeEntryOrPredicate)) {
|
|
4491
|
+
key = keyNodeEntryOrPredicate.key;
|
|
4492
|
+
} else if (Array.isArray(keyNodeEntryOrPredicate)) {
|
|
4493
|
+
key = keyNodeEntryOrPredicate[0] ?? void 0;
|
|
4494
|
+
if (key === void 0 || key === null) return -1;
|
|
4495
|
+
} else {
|
|
4496
|
+
key = keyNodeEntryOrPredicate;
|
|
4497
|
+
}
|
|
4498
|
+
if (key === void 0) return -1;
|
|
4499
|
+
return actualIterationType === "RECURSIVE" ? this._getRankRecursive(this._root, key) : this._getRankIterative(this._root, key);
|
|
4500
|
+
}
|
|
4501
|
+
rangeByRank(start, end, callback = this._DEFAULT_NODE_CALLBACK, iterationType = this.iterationType) {
|
|
4502
|
+
if (!this._enableOrderStatistic) {
|
|
4503
|
+
raise(Error, ERR.orderStatisticNotEnabled("rangeByRank"));
|
|
4504
|
+
}
|
|
4505
|
+
if (this._size === 0) return [];
|
|
4506
|
+
const lo = Math.max(0, start);
|
|
4507
|
+
const hi = Math.min(this._size - 1, end);
|
|
4508
|
+
if (lo > hi) return [];
|
|
4509
|
+
let actualCallback = void 0;
|
|
4510
|
+
let actualIterationType = this.iterationType;
|
|
4511
|
+
if (typeof callback === "string") {
|
|
4512
|
+
actualIterationType = callback;
|
|
4513
|
+
} else if (callback) {
|
|
4514
|
+
actualCallback = callback;
|
|
4515
|
+
if (iterationType) {
|
|
4516
|
+
actualIterationType = iterationType;
|
|
4517
|
+
}
|
|
4518
|
+
}
|
|
4519
|
+
const results = [];
|
|
4520
|
+
const count = hi - lo + 1;
|
|
4521
|
+
const startNode = actualIterationType === "RECURSIVE" ? this._getByRankRecursive(this._root, lo) : this._getByRankIterative(this._root, lo);
|
|
4522
|
+
if (!startNode) return [];
|
|
4523
|
+
let collected = 0;
|
|
4524
|
+
const cb = actualCallback ?? this._DEFAULT_NODE_CALLBACK;
|
|
4525
|
+
let current = startNode;
|
|
4526
|
+
while (current && collected < count) {
|
|
4527
|
+
results.push(cb(current));
|
|
4528
|
+
collected++;
|
|
4529
|
+
if (collected < count) {
|
|
4530
|
+
current = this._next(current);
|
|
4531
|
+
}
|
|
4532
|
+
}
|
|
4533
|
+
return results;
|
|
4534
|
+
}
|
|
4354
4535
|
/**
|
|
4355
4536
|
* Adds a new node to the BST based on key comparison.
|
|
4356
4537
|
* @remarks Time O(log N), where H is tree height. O(N) worst-case (unbalanced tree), O(log N) average. Space O(1).
|
|
@@ -4436,6 +4617,15 @@ var BST = class extends BinaryTree {
|
|
|
4436
4617
|
|
|
4437
4618
|
|
|
4438
4619
|
|
|
4620
|
+
|
|
4621
|
+
|
|
4622
|
+
|
|
4623
|
+
|
|
4624
|
+
|
|
4625
|
+
|
|
4626
|
+
|
|
4627
|
+
|
|
4628
|
+
|
|
4439
4629
|
|
|
4440
4630
|
|
|
4441
4631
|
|
|
@@ -4460,6 +4650,7 @@ var BST = class extends BinaryTree {
|
|
|
4460
4650
|
this._setRoot(newNode);
|
|
4461
4651
|
if (this._isMapMode && this.isRealNode(newNode)) this._store.set(newNode.key, newNode);
|
|
4462
4652
|
this._size++;
|
|
4653
|
+
this._updateCount(newNode);
|
|
4463
4654
|
return true;
|
|
4464
4655
|
}
|
|
4465
4656
|
let current = this._root;
|
|
@@ -4473,6 +4664,7 @@ var BST = class extends BinaryTree {
|
|
|
4473
4664
|
current.left = newNode;
|
|
4474
4665
|
if (this._isMapMode && this.isRealNode(newNode)) this._store.set(newNode.key, newNode);
|
|
4475
4666
|
this._size++;
|
|
4667
|
+
this._updateCountAlongPath(newNode);
|
|
4476
4668
|
return true;
|
|
4477
4669
|
}
|
|
4478
4670
|
if (current.left !== null) current = current.left;
|
|
@@ -4481,6 +4673,7 @@ var BST = class extends BinaryTree {
|
|
|
4481
4673
|
current.right = newNode;
|
|
4482
4674
|
if (this._isMapMode && this.isRealNode(newNode)) this._store.set(newNode.key, newNode);
|
|
4483
4675
|
this._size++;
|
|
4676
|
+
this._updateCountAlongPath(newNode);
|
|
4484
4677
|
return true;
|
|
4485
4678
|
}
|
|
4486
4679
|
if (current.right !== null) current = current.right;
|
|
@@ -4545,6 +4738,12 @@ var BST = class extends BinaryTree {
|
|
|
4545
4738
|
|
|
4546
4739
|
|
|
4547
4740
|
|
|
4741
|
+
|
|
4742
|
+
|
|
4743
|
+
|
|
4744
|
+
|
|
4745
|
+
|
|
4746
|
+
|
|
4548
4747
|
|
|
4549
4748
|
|
|
4550
4749
|
|
|
@@ -4832,6 +5031,9 @@ var BST = class extends BinaryTree {
|
|
|
4832
5031
|
|
|
4833
5032
|
|
|
4834
5033
|
|
|
5034
|
+
|
|
5035
|
+
|
|
5036
|
+
|
|
4835
5037
|
|
|
4836
5038
|
|
|
4837
5039
|
|
|
@@ -4898,6 +5100,9 @@ var BST = class extends BinaryTree {
|
|
|
4898
5100
|
|
|
4899
5101
|
|
|
4900
5102
|
|
|
5103
|
+
|
|
5104
|
+
|
|
5105
|
+
|
|
4901
5106
|
|
|
4902
5107
|
|
|
4903
5108
|
|
|
@@ -5011,6 +5216,12 @@ var BST = class extends BinaryTree {
|
|
|
5011
5216
|
|
|
5012
5217
|
|
|
5013
5218
|
|
|
5219
|
+
|
|
5220
|
+
|
|
5221
|
+
|
|
5222
|
+
|
|
5223
|
+
|
|
5224
|
+
|
|
5014
5225
|
|
|
5015
5226
|
|
|
5016
5227
|
|
|
@@ -5092,13 +5303,11 @@ var BST = class extends BinaryTree {
|
|
|
5092
5303
|
if (a instanceof Date && b instanceof Date) {
|
|
5093
5304
|
const ta = a.getTime();
|
|
5094
5305
|
const tb = b.getTime();
|
|
5095
|
-
if (Number.isNaN(ta) || Number.isNaN(tb))
|
|
5306
|
+
if (Number.isNaN(ta) || Number.isNaN(tb)) raise(TypeError, ERR.invalidDate("BST"));
|
|
5096
5307
|
return ta > tb ? 1 : ta < tb ? -1 : 0;
|
|
5097
5308
|
}
|
|
5098
5309
|
if (typeof a === "object" || typeof b === "object") {
|
|
5099
|
-
|
|
5100
|
-
ERR.comparatorRequired("BST")
|
|
5101
|
-
);
|
|
5310
|
+
raise(TypeError, ERR.comparatorRequired("BST"));
|
|
5102
5311
|
}
|
|
5103
5312
|
return 0;
|
|
5104
5313
|
};
|
|
@@ -5417,7 +5626,8 @@ var BST = class extends BinaryTree {
|
|
|
5417
5626
|
_snapshotOptions() {
|
|
5418
5627
|
return {
|
|
5419
5628
|
...super._snapshotOptions(),
|
|
5420
|
-
comparator: this._comparator
|
|
5629
|
+
comparator: this._comparator,
|
|
5630
|
+
enableOrderStatistic: this._enableOrderStatistic
|
|
5421
5631
|
};
|
|
5422
5632
|
}
|
|
5423
5633
|
/**
|
|
@@ -5439,6 +5649,113 @@ var BST = class extends BinaryTree {
|
|
|
5439
5649
|
*
|
|
5440
5650
|
* @param v - The node to set as root.
|
|
5441
5651
|
*/
|
|
5652
|
+
/**
|
|
5653
|
+
* (Protected) Recalculates the subtree count for a single node.
|
|
5654
|
+
* @remarks Time O(1). Only active when enableOrderStatistic is true.
|
|
5655
|
+
*/
|
|
5656
|
+
_updateCount(node) {
|
|
5657
|
+
if (!this._enableOrderStatistic) return;
|
|
5658
|
+
node._count = 1 + (this.isRealNode(node.left) ? node.left._count : 0) + (this.isRealNode(node.right) ? node.right._count : 0);
|
|
5659
|
+
}
|
|
5660
|
+
/**
|
|
5661
|
+
* (Protected) Updates subtree counts from a node up to the root.
|
|
5662
|
+
* @remarks Time O(log n). Only active when enableOrderStatistic is true.
|
|
5663
|
+
*/
|
|
5664
|
+
_updateCountAlongPath(node) {
|
|
5665
|
+
if (!this._enableOrderStatistic) return;
|
|
5666
|
+
let current = node;
|
|
5667
|
+
while (current) {
|
|
5668
|
+
this._updateCount(current);
|
|
5669
|
+
current = current.parent;
|
|
5670
|
+
}
|
|
5671
|
+
}
|
|
5672
|
+
/**
|
|
5673
|
+
* (Protected) Finds the node at position k in tree order (iterative).
|
|
5674
|
+
* @remarks Time O(log n), Space O(1)
|
|
5675
|
+
*/
|
|
5676
|
+
_getByRankIterative(node, k) {
|
|
5677
|
+
let current = node;
|
|
5678
|
+
let remaining = k;
|
|
5679
|
+
while (current) {
|
|
5680
|
+
const leftCount = this.isRealNode(current.left) ? current.left._count : 0;
|
|
5681
|
+
if (remaining < leftCount) {
|
|
5682
|
+
current = current.left;
|
|
5683
|
+
} else if (remaining === leftCount) {
|
|
5684
|
+
return current;
|
|
5685
|
+
} else {
|
|
5686
|
+
remaining = remaining - leftCount - 1;
|
|
5687
|
+
current = current.right;
|
|
5688
|
+
}
|
|
5689
|
+
}
|
|
5690
|
+
return void 0;
|
|
5691
|
+
}
|
|
5692
|
+
/**
|
|
5693
|
+
* (Protected) Finds the node at position k in tree order (recursive).
|
|
5694
|
+
* @remarks Time O(log n), Space O(log n) call stack
|
|
5695
|
+
*/
|
|
5696
|
+
_getByRankRecursive(node, k) {
|
|
5697
|
+
if (!node) return void 0;
|
|
5698
|
+
const leftCount = this.isRealNode(node.left) ? node.left._count : 0;
|
|
5699
|
+
if (k < leftCount) return this._getByRankRecursive(node.left, k);
|
|
5700
|
+
if (k === leftCount) return node;
|
|
5701
|
+
return this._getByRankRecursive(node.right, k - leftCount - 1);
|
|
5702
|
+
}
|
|
5703
|
+
/**
|
|
5704
|
+
* (Protected) Computes the rank of a key iteratively.
|
|
5705
|
+
* @remarks Time O(log n), Space O(1)
|
|
5706
|
+
*/
|
|
5707
|
+
_getRankIterative(node, key) {
|
|
5708
|
+
let rank = 0;
|
|
5709
|
+
let current = node;
|
|
5710
|
+
while (this.isRealNode(current)) {
|
|
5711
|
+
const cmp = this._compare(current.key, key);
|
|
5712
|
+
if (cmp > 0) {
|
|
5713
|
+
current = current.left;
|
|
5714
|
+
} else if (cmp < 0) {
|
|
5715
|
+
rank += (this.isRealNode(current.left) ? current.left._count : 0) + 1;
|
|
5716
|
+
current = current.right;
|
|
5717
|
+
} else {
|
|
5718
|
+
rank += this.isRealNode(current.left) ? current.left._count : 0;
|
|
5719
|
+
return rank;
|
|
5720
|
+
}
|
|
5721
|
+
}
|
|
5722
|
+
return rank;
|
|
5723
|
+
}
|
|
5724
|
+
/**
|
|
5725
|
+
* (Protected) Computes the rank of a key recursively.
|
|
5726
|
+
* @remarks Time O(log n), Space O(log n) call stack
|
|
5727
|
+
*/
|
|
5728
|
+
_getRankRecursive(node, key) {
|
|
5729
|
+
if (!node) return 0;
|
|
5730
|
+
const cmp = this._compare(node.key, key);
|
|
5731
|
+
if (cmp > 0) {
|
|
5732
|
+
return this._getRankRecursive(node.left, key);
|
|
5733
|
+
} else if (cmp < 0) {
|
|
5734
|
+
return (this.isRealNode(node.left) ? node.left._count : 0) + 1 + this._getRankRecursive(node.right, key);
|
|
5735
|
+
} else {
|
|
5736
|
+
return this.isRealNode(node.left) ? node.left._count : 0;
|
|
5737
|
+
}
|
|
5738
|
+
}
|
|
5739
|
+
/**
|
|
5740
|
+
* (Protected) Finds the in-order successor of a node.
|
|
5741
|
+
* @remarks Time O(log n), Space O(1)
|
|
5742
|
+
*/
|
|
5743
|
+
_next(node) {
|
|
5744
|
+
if (this.isRealNode(node.right)) {
|
|
5745
|
+
let current2 = node.right;
|
|
5746
|
+
while (this.isRealNode(current2.left)) {
|
|
5747
|
+
current2 = current2.left;
|
|
5748
|
+
}
|
|
5749
|
+
return current2;
|
|
5750
|
+
}
|
|
5751
|
+
let current = node;
|
|
5752
|
+
let parent = current.parent;
|
|
5753
|
+
while (parent && current === parent.right) {
|
|
5754
|
+
current = parent;
|
|
5755
|
+
parent = parent.parent;
|
|
5756
|
+
}
|
|
5757
|
+
return parent;
|
|
5758
|
+
}
|
|
5442
5759
|
_setRoot(v) {
|
|
5443
5760
|
if (v) v.parent = void 0;
|
|
5444
5761
|
this._root = v;
|
|
@@ -5485,21 +5802,28 @@ var BST = class extends BinaryTree {
|
|
|
5485
5802
|
while (x.left !== void 0 && x.left !== null) x = x.left;
|
|
5486
5803
|
return x;
|
|
5487
5804
|
}, "minNode");
|
|
5805
|
+
let countUpdateStart;
|
|
5488
5806
|
if (node.left === void 0) {
|
|
5807
|
+
countUpdateStart = node.parent;
|
|
5489
5808
|
transplant(node, node.right);
|
|
5490
5809
|
} else if (node.right === void 0) {
|
|
5810
|
+
countUpdateStart = node.parent;
|
|
5491
5811
|
transplant(node, node.left);
|
|
5492
5812
|
} else {
|
|
5493
5813
|
const succ = minNode(node.right);
|
|
5494
5814
|
if (succ.parent !== node) {
|
|
5815
|
+
countUpdateStart = succ.parent;
|
|
5495
5816
|
transplant(succ, succ.right);
|
|
5496
5817
|
succ.right = node.right;
|
|
5497
5818
|
if (succ.right) succ.right.parent = succ;
|
|
5819
|
+
} else {
|
|
5820
|
+
countUpdateStart = succ;
|
|
5498
5821
|
}
|
|
5499
5822
|
transplant(node, succ);
|
|
5500
5823
|
succ.left = node.left;
|
|
5501
5824
|
if (succ.left) succ.left.parent = succ;
|
|
5502
5825
|
}
|
|
5826
|
+
this._updateCountAlongPath(countUpdateStart);
|
|
5503
5827
|
this._size = Math.max(0, this._size - 1);
|
|
5504
5828
|
return true;
|
|
5505
5829
|
}
|
|
@@ -5786,6 +6110,18 @@ var AVLTree = class extends BST {
|
|
|
5786
6110
|
|
|
5787
6111
|
|
|
5788
6112
|
|
|
6113
|
+
|
|
6114
|
+
|
|
6115
|
+
|
|
6116
|
+
|
|
6117
|
+
|
|
6118
|
+
|
|
6119
|
+
|
|
6120
|
+
|
|
6121
|
+
|
|
6122
|
+
|
|
6123
|
+
|
|
6124
|
+
|
|
5789
6125
|
|
|
5790
6126
|
|
|
5791
6127
|
|
|
@@ -5904,6 +6240,15 @@ var AVLTree = class extends BST {
|
|
|
5904
6240
|
|
|
5905
6241
|
|
|
5906
6242
|
|
|
6243
|
+
|
|
6244
|
+
|
|
6245
|
+
|
|
6246
|
+
|
|
6247
|
+
|
|
6248
|
+
|
|
6249
|
+
|
|
6250
|
+
|
|
6251
|
+
|
|
5907
6252
|
|
|
5908
6253
|
|
|
5909
6254
|
|
|
@@ -5984,6 +6329,12 @@ var AVLTree = class extends BST {
|
|
|
5984
6329
|
|
|
5985
6330
|
|
|
5986
6331
|
|
|
6332
|
+
|
|
6333
|
+
|
|
6334
|
+
|
|
6335
|
+
|
|
6336
|
+
|
|
6337
|
+
|
|
5987
6338
|
|
|
5988
6339
|
|
|
5989
6340
|
|
|
@@ -6108,6 +6459,15 @@ var AVLTree = class extends BST {
|
|
|
6108
6459
|
|
|
6109
6460
|
|
|
6110
6461
|
|
|
6462
|
+
|
|
6463
|
+
|
|
6464
|
+
|
|
6465
|
+
|
|
6466
|
+
|
|
6467
|
+
|
|
6468
|
+
|
|
6469
|
+
|
|
6470
|
+
|
|
6111
6471
|
|
|
6112
6472
|
|
|
6113
6473
|
|
|
@@ -6236,6 +6596,8 @@ var AVLTree = class extends BST {
|
|
|
6236
6596
|
}
|
|
6237
6597
|
this._updateHeight(A);
|
|
6238
6598
|
if (B) this._updateHeight(B);
|
|
6599
|
+
this._updateCount(A);
|
|
6600
|
+
if (B) this._updateCount(B);
|
|
6239
6601
|
}
|
|
6240
6602
|
/**
|
|
6241
6603
|
* (Protected) Performs a Left-Right (LR) double rotation.
|
|
@@ -6281,6 +6643,9 @@ var AVLTree = class extends BST {
|
|
|
6281
6643
|
this._updateHeight(A);
|
|
6282
6644
|
if (B) this._updateHeight(B);
|
|
6283
6645
|
if (C) this._updateHeight(C);
|
|
6646
|
+
this._updateCount(A);
|
|
6647
|
+
if (B) this._updateCount(B);
|
|
6648
|
+
if (C) this._updateCount(C);
|
|
6284
6649
|
}
|
|
6285
6650
|
/**
|
|
6286
6651
|
* (Protected) Performs a Right-Right (RR) rotation (a single left rotation).
|
|
@@ -6315,6 +6680,8 @@ var AVLTree = class extends BST {
|
|
|
6315
6680
|
}
|
|
6316
6681
|
this._updateHeight(A);
|
|
6317
6682
|
if (B) this._updateHeight(B);
|
|
6683
|
+
this._updateCount(A);
|
|
6684
|
+
if (B) this._updateCount(B);
|
|
6318
6685
|
}
|
|
6319
6686
|
/**
|
|
6320
6687
|
* (Protected) Performs a Right-Left (RL) double rotation.
|
|
@@ -6358,6 +6725,9 @@ var AVLTree = class extends BST {
|
|
|
6358
6725
|
this._updateHeight(A);
|
|
6359
6726
|
if (B) this._updateHeight(B);
|
|
6360
6727
|
if (C) this._updateHeight(C);
|
|
6728
|
+
this._updateCount(A);
|
|
6729
|
+
if (B) this._updateCount(B);
|
|
6730
|
+
if (C) this._updateCount(C);
|
|
6361
6731
|
}
|
|
6362
6732
|
/**
|
|
6363
6733
|
* (Protected) Traverses up the tree from the specified node, updating heights and performing rotations as needed.
|
|
@@ -6372,6 +6742,7 @@ var AVLTree = class extends BST {
|
|
|
6372
6742
|
const A = path[i];
|
|
6373
6743
|
if (A) {
|
|
6374
6744
|
this._updateHeight(A);
|
|
6745
|
+
this._updateCount(A);
|
|
6375
6746
|
switch (this._balanceFactor(A)) {
|
|
6376
6747
|
case -2:
|
|
6377
6748
|
if (A && A.left) {
|