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
|
@@ -59,6 +59,55 @@ function makeTrampoline(fn) {
|
|
|
59
59
|
}
|
|
60
60
|
__name(makeTrampoline, "makeTrampoline");
|
|
61
61
|
|
|
62
|
+
// src/common/error.ts
|
|
63
|
+
function raise(ErrorClass, message) {
|
|
64
|
+
throw new ErrorClass(message);
|
|
65
|
+
}
|
|
66
|
+
__name(raise, "raise");
|
|
67
|
+
var ERR = {
|
|
68
|
+
// Range / index
|
|
69
|
+
indexOutOfRange: /* @__PURE__ */ __name((index, min, max, ctx) => `${ctx ? ctx + ": " : ""}Index ${index} is out of range [${min}, ${max}].`, "indexOutOfRange"),
|
|
70
|
+
invalidIndex: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Index must be an integer.`, "invalidIndex"),
|
|
71
|
+
// Type / argument
|
|
72
|
+
invalidArgument: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidArgument"),
|
|
73
|
+
comparatorRequired: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Comparator is required for non-number/non-string/non-Date keys.`, "comparatorRequired"),
|
|
74
|
+
invalidKey: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidKey"),
|
|
75
|
+
notAFunction: /* @__PURE__ */ __name((name, ctx) => `${ctx ? ctx + ": " : ""}${name} must be a function.`, "notAFunction"),
|
|
76
|
+
invalidEntry: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Each entry must be a [key, value] tuple.`, "invalidEntry"),
|
|
77
|
+
invalidNaN: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}NaN is not a valid key.`, "invalidNaN"),
|
|
78
|
+
invalidDate: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Invalid Date key.`, "invalidDate"),
|
|
79
|
+
reduceEmpty: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Reduce of empty structure with no initial value.`, "reduceEmpty"),
|
|
80
|
+
callbackReturnType: /* @__PURE__ */ __name((expected, got, ctx) => `${ctx ? ctx + ": " : ""}Callback must return ${expected}; got ${got}.`, "callbackReturnType"),
|
|
81
|
+
// State / operation
|
|
82
|
+
invalidOperation: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidOperation"),
|
|
83
|
+
// Matrix
|
|
84
|
+
matrixDimensionMismatch: /* @__PURE__ */ __name((op) => `Matrix: Dimensions must be compatible for ${op}.`, "matrixDimensionMismatch"),
|
|
85
|
+
matrixSingular: /* @__PURE__ */ __name(() => "Matrix: Singular matrix, inverse does not exist.", "matrixSingular"),
|
|
86
|
+
matrixNotSquare: /* @__PURE__ */ __name(() => "Matrix: Must be square for inversion.", "matrixNotSquare"),
|
|
87
|
+
matrixNotRectangular: /* @__PURE__ */ __name(() => "Matrix: Must be rectangular for transposition.", "matrixNotRectangular"),
|
|
88
|
+
matrixRowMismatch: /* @__PURE__ */ __name((expected, got) => `Matrix: Expected row length ${expected}, but got ${got}.`, "matrixRowMismatch"),
|
|
89
|
+
// Order statistic
|
|
90
|
+
orderStatisticNotEnabled: /* @__PURE__ */ __name((method, ctx) => `${ctx ? ctx + ": " : ""}${method}() requires enableOrderStatistic: true.`, "orderStatisticNotEnabled")
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
// src/common/index.ts
|
|
94
|
+
var _Range = class _Range {
|
|
95
|
+
constructor(low, high, includeLow = true, includeHigh = true) {
|
|
96
|
+
this.low = low;
|
|
97
|
+
this.high = high;
|
|
98
|
+
this.includeLow = includeLow;
|
|
99
|
+
this.includeHigh = includeHigh;
|
|
100
|
+
}
|
|
101
|
+
// Determine whether a key is within the range
|
|
102
|
+
isInRange(key, comparator) {
|
|
103
|
+
const lowCheck = this.includeLow ? comparator(key, this.low) >= 0 : comparator(key, this.low) > 0;
|
|
104
|
+
const highCheck = this.includeHigh ? comparator(key, this.high) <= 0 : comparator(key, this.high) < 0;
|
|
105
|
+
return lowCheck && highCheck;
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
__name(_Range, "Range");
|
|
109
|
+
var Range = _Range;
|
|
110
|
+
|
|
62
111
|
// src/data-structures/base/iterable-element-base.ts
|
|
63
112
|
var _IterableElementBase = class _IterableElementBase {
|
|
64
113
|
/**
|
|
@@ -81,7 +130,7 @@ var _IterableElementBase = class _IterableElementBase {
|
|
|
81
130
|
if (options) {
|
|
82
131
|
const { toElementFn } = options;
|
|
83
132
|
if (typeof toElementFn === "function") this._toElementFn = toElementFn;
|
|
84
|
-
else if (toElementFn)
|
|
133
|
+
else if (toElementFn) raise(TypeError, "toElementFn must be a function type");
|
|
85
134
|
}
|
|
86
135
|
}
|
|
87
136
|
/**
|
|
@@ -237,7 +286,7 @@ var _IterableElementBase = class _IterableElementBase {
|
|
|
237
286
|
acc = initialValue;
|
|
238
287
|
} else {
|
|
239
288
|
const first = iter.next();
|
|
240
|
-
if (first.done)
|
|
289
|
+
if (first.done) raise(TypeError, "Reduce of empty structure with no initial value");
|
|
241
290
|
acc = first.value;
|
|
242
291
|
index = 1;
|
|
243
292
|
}
|
|
@@ -473,49 +522,6 @@ var _LinearBase = class _LinearBase extends IterableElementBase {
|
|
|
473
522
|
__name(_LinearBase, "LinearBase");
|
|
474
523
|
var LinearBase = _LinearBase;
|
|
475
524
|
|
|
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 _Range {
|
|
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
|
-
// Determine whether a key is within the range
|
|
510
|
-
isInRange(key, comparator) {
|
|
511
|
-
const lowCheck = this.includeLow ? comparator(key, this.low) >= 0 : comparator(key, this.low) > 0;
|
|
512
|
-
const highCheck = this.includeHigh ? comparator(key, this.high) <= 0 : comparator(key, this.high) < 0;
|
|
513
|
-
return lowCheck && highCheck;
|
|
514
|
-
}
|
|
515
|
-
};
|
|
516
|
-
__name(_Range, "Range");
|
|
517
|
-
var Range = _Range;
|
|
518
|
-
|
|
519
525
|
// src/data-structures/base/iterable-entry-base.ts
|
|
520
526
|
var _IterableEntryBase = class _IterableEntryBase {
|
|
521
527
|
/**
|
|
@@ -782,6 +788,9 @@ var _Queue = class _Queue extends LinearBase {
|
|
|
782
788
|
|
|
783
789
|
|
|
784
790
|
|
|
791
|
+
|
|
792
|
+
|
|
793
|
+
|
|
785
794
|
|
|
786
795
|
|
|
787
796
|
|
|
@@ -829,6 +838,9 @@ var _Queue = class _Queue extends LinearBase {
|
|
|
829
838
|
|
|
830
839
|
|
|
831
840
|
|
|
841
|
+
|
|
842
|
+
|
|
843
|
+
|
|
832
844
|
|
|
833
845
|
|
|
834
846
|
|
|
@@ -892,6 +904,9 @@ var _Queue = class _Queue extends LinearBase {
|
|
|
892
904
|
|
|
893
905
|
|
|
894
906
|
|
|
907
|
+
|
|
908
|
+
|
|
909
|
+
|
|
895
910
|
|
|
896
911
|
|
|
897
912
|
|
|
@@ -951,6 +966,9 @@ var _Queue = class _Queue extends LinearBase {
|
|
|
951
966
|
|
|
952
967
|
|
|
953
968
|
|
|
969
|
+
|
|
970
|
+
|
|
971
|
+
|
|
954
972
|
|
|
955
973
|
|
|
956
974
|
|
|
@@ -1017,6 +1035,9 @@ var _Queue = class _Queue extends LinearBase {
|
|
|
1017
1035
|
|
|
1018
1036
|
|
|
1019
1037
|
|
|
1038
|
+
|
|
1039
|
+
|
|
1040
|
+
|
|
1020
1041
|
|
|
1021
1042
|
|
|
1022
1043
|
|
|
@@ -1073,6 +1094,9 @@ var _Queue = class _Queue extends LinearBase {
|
|
|
1073
1094
|
|
|
1074
1095
|
|
|
1075
1096
|
|
|
1097
|
+
|
|
1098
|
+
|
|
1099
|
+
|
|
1076
1100
|
|
|
1077
1101
|
|
|
1078
1102
|
|
|
@@ -1122,6 +1146,9 @@ var _Queue = class _Queue extends LinearBase {
|
|
|
1122
1146
|
|
|
1123
1147
|
|
|
1124
1148
|
|
|
1149
|
+
|
|
1150
|
+
|
|
1151
|
+
|
|
1125
1152
|
|
|
1126
1153
|
|
|
1127
1154
|
|
|
@@ -1212,6 +1239,9 @@ var _Queue = class _Queue extends LinearBase {
|
|
|
1212
1239
|
|
|
1213
1240
|
|
|
1214
1241
|
|
|
1242
|
+
|
|
1243
|
+
|
|
1244
|
+
|
|
1215
1245
|
|
|
1216
1246
|
|
|
1217
1247
|
|
|
@@ -1255,6 +1285,9 @@ var _Queue = class _Queue extends LinearBase {
|
|
|
1255
1285
|
|
|
1256
1286
|
|
|
1257
1287
|
|
|
1288
|
+
|
|
1289
|
+
|
|
1290
|
+
|
|
1258
1291
|
|
|
1259
1292
|
|
|
1260
1293
|
|
|
@@ -1321,6 +1354,9 @@ var _Queue = class _Queue extends LinearBase {
|
|
|
1321
1354
|
|
|
1322
1355
|
|
|
1323
1356
|
|
|
1357
|
+
|
|
1358
|
+
|
|
1359
|
+
|
|
1324
1360
|
|
|
1325
1361
|
|
|
1326
1362
|
|
|
@@ -1371,6 +1407,9 @@ var _Queue = class _Queue extends LinearBase {
|
|
|
1371
1407
|
|
|
1372
1408
|
|
|
1373
1409
|
|
|
1410
|
+
|
|
1411
|
+
|
|
1412
|
+
|
|
1374
1413
|
|
|
1375
1414
|
|
|
1376
1415
|
|
|
@@ -1425,6 +1464,9 @@ var _Queue = class _Queue extends LinearBase {
|
|
|
1425
1464
|
|
|
1426
1465
|
|
|
1427
1466
|
|
|
1467
|
+
|
|
1468
|
+
|
|
1469
|
+
|
|
1428
1470
|
|
|
1429
1471
|
|
|
1430
1472
|
|
|
@@ -1697,7 +1739,7 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
1697
1739
|
if (isMapMode !== void 0) this._isMapMode = isMapMode;
|
|
1698
1740
|
if (isDuplicate !== void 0) this._isDuplicate = isDuplicate;
|
|
1699
1741
|
if (typeof toEntryFn === "function") this._toEntryFn = toEntryFn;
|
|
1700
|
-
else if (toEntryFn)
|
|
1742
|
+
else if (toEntryFn) raise(TypeError, ERR.notAFunction("toEntryFn", "BinaryTree"));
|
|
1701
1743
|
}
|
|
1702
1744
|
if (keysNodesEntriesOrRaws) this.setMany(keysNodesEntriesOrRaws);
|
|
1703
1745
|
}
|
|
@@ -1930,6 +1972,9 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
1930
1972
|
|
|
1931
1973
|
|
|
1932
1974
|
|
|
1975
|
+
|
|
1976
|
+
|
|
1977
|
+
|
|
1933
1978
|
|
|
1934
1979
|
|
|
1935
1980
|
|
|
@@ -1981,6 +2026,9 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
1981
2026
|
|
|
1982
2027
|
|
|
1983
2028
|
|
|
2029
|
+
|
|
2030
|
+
|
|
2031
|
+
|
|
1984
2032
|
|
|
1985
2033
|
|
|
1986
2034
|
|
|
@@ -2084,6 +2132,9 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
2084
2132
|
|
|
2085
2133
|
|
|
2086
2134
|
|
|
2135
|
+
|
|
2136
|
+
|
|
2137
|
+
|
|
2087
2138
|
|
|
2088
2139
|
|
|
2089
2140
|
|
|
@@ -2123,6 +2174,9 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
2123
2174
|
|
|
2124
2175
|
|
|
2125
2176
|
|
|
2177
|
+
|
|
2178
|
+
|
|
2179
|
+
|
|
2126
2180
|
|
|
2127
2181
|
|
|
2128
2182
|
|
|
@@ -2183,6 +2237,9 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
2183
2237
|
|
|
2184
2238
|
|
|
2185
2239
|
|
|
2240
|
+
|
|
2241
|
+
|
|
2242
|
+
|
|
2186
2243
|
|
|
2187
2244
|
|
|
2188
2245
|
|
|
@@ -2242,6 +2299,9 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
2242
2299
|
|
|
2243
2300
|
|
|
2244
2301
|
|
|
2302
|
+
|
|
2303
|
+
|
|
2304
|
+
|
|
2245
2305
|
|
|
2246
2306
|
|
|
2247
2307
|
|
|
@@ -2379,6 +2439,9 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
2379
2439
|
|
|
2380
2440
|
|
|
2381
2441
|
|
|
2442
|
+
|
|
2443
|
+
|
|
2444
|
+
|
|
2382
2445
|
|
|
2383
2446
|
|
|
2384
2447
|
|
|
@@ -2434,6 +2497,9 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
2434
2497
|
|
|
2435
2498
|
|
|
2436
2499
|
|
|
2500
|
+
|
|
2501
|
+
|
|
2502
|
+
|
|
2437
2503
|
|
|
2438
2504
|
|
|
2439
2505
|
|
|
@@ -2492,6 +2558,9 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
2492
2558
|
|
|
2493
2559
|
|
|
2494
2560
|
|
|
2561
|
+
|
|
2562
|
+
|
|
2563
|
+
|
|
2495
2564
|
|
|
2496
2565
|
|
|
2497
2566
|
|
|
@@ -2537,6 +2606,9 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
2537
2606
|
|
|
2538
2607
|
|
|
2539
2608
|
|
|
2609
|
+
|
|
2610
|
+
|
|
2611
|
+
|
|
2540
2612
|
|
|
2541
2613
|
|
|
2542
2614
|
|
|
@@ -2591,6 +2663,9 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
2591
2663
|
|
|
2592
2664
|
|
|
2593
2665
|
|
|
2666
|
+
|
|
2667
|
+
|
|
2668
|
+
|
|
2594
2669
|
|
|
2595
2670
|
|
|
2596
2671
|
|
|
@@ -2672,6 +2747,9 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
2672
2747
|
|
|
2673
2748
|
|
|
2674
2749
|
|
|
2750
|
+
|
|
2751
|
+
|
|
2752
|
+
|
|
2675
2753
|
|
|
2676
2754
|
|
|
2677
2755
|
|
|
@@ -2730,6 +2808,9 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
2730
2808
|
|
|
2731
2809
|
|
|
2732
2810
|
|
|
2811
|
+
|
|
2812
|
+
|
|
2813
|
+
|
|
2733
2814
|
|
|
2734
2815
|
|
|
2735
2816
|
|
|
@@ -3204,6 +3285,9 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
3204
3285
|
|
|
3205
3286
|
|
|
3206
3287
|
|
|
3288
|
+
|
|
3289
|
+
|
|
3290
|
+
|
|
3207
3291
|
|
|
3208
3292
|
|
|
3209
3293
|
|
|
@@ -3253,6 +3337,9 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
3253
3337
|
|
|
3254
3338
|
|
|
3255
3339
|
|
|
3340
|
+
|
|
3341
|
+
|
|
3342
|
+
|
|
3256
3343
|
|
|
3257
3344
|
|
|
3258
3345
|
|
|
@@ -3306,6 +3393,9 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
3306
3393
|
|
|
3307
3394
|
|
|
3308
3395
|
|
|
3396
|
+
|
|
3397
|
+
|
|
3398
|
+
|
|
3309
3399
|
|
|
3310
3400
|
|
|
3311
3401
|
|
|
@@ -3384,6 +3474,9 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
3384
3474
|
|
|
3385
3475
|
|
|
3386
3476
|
|
|
3477
|
+
|
|
3478
|
+
|
|
3479
|
+
|
|
3387
3480
|
|
|
3388
3481
|
|
|
3389
3482
|
|
|
@@ -4006,6 +4099,7 @@ var _BST = class _BST extends BinaryTree {
|
|
|
4006
4099
|
constructor(keysNodesEntriesOrRaws = [], options) {
|
|
4007
4100
|
super([], options);
|
|
4008
4101
|
__publicField(this, "_root");
|
|
4102
|
+
__publicField(this, "_enableOrderStatistic", false);
|
|
4009
4103
|
/**
|
|
4010
4104
|
* The comparator function used to determine the order of keys in the tree.
|
|
4011
4105
|
|
|
@@ -4018,6 +4112,9 @@ var _BST = class _BST extends BinaryTree {
|
|
|
4018
4112
|
} else {
|
|
4019
4113
|
this._comparator = this._createDefaultComparator();
|
|
4020
4114
|
}
|
|
4115
|
+
if (options.enableOrderStatistic) {
|
|
4116
|
+
this._enableOrderStatistic = true;
|
|
4117
|
+
}
|
|
4021
4118
|
} else {
|
|
4022
4119
|
this._comparator = this._createDefaultComparator();
|
|
4023
4120
|
}
|
|
@@ -4187,6 +4284,12 @@ var _BST = class _BST extends BinaryTree {
|
|
|
4187
4284
|
|
|
4188
4285
|
|
|
4189
4286
|
|
|
4287
|
+
|
|
4288
|
+
|
|
4289
|
+
|
|
4290
|
+
|
|
4291
|
+
|
|
4292
|
+
|
|
4190
4293
|
|
|
4191
4294
|
|
|
4192
4295
|
|
|
@@ -4349,6 +4452,85 @@ var _BST = class _BST extends BinaryTree {
|
|
|
4349
4452
|
const searchRange = range instanceof Range ? range : new Range(range[0], range[1]);
|
|
4350
4453
|
return this.search(searchRange, false, callback, startNode, iterationType);
|
|
4351
4454
|
}
|
|
4455
|
+
getByRank(k, callback = this._DEFAULT_NODE_CALLBACK, iterationType = this.iterationType) {
|
|
4456
|
+
if (!this._enableOrderStatistic) {
|
|
4457
|
+
raise(Error, ERR.orderStatisticNotEnabled("getByRank"));
|
|
4458
|
+
}
|
|
4459
|
+
if (k < 0 || k >= this._size) return void 0;
|
|
4460
|
+
let actualCallback = void 0;
|
|
4461
|
+
let actualIterationType = this.iterationType;
|
|
4462
|
+
if (typeof callback === "string") {
|
|
4463
|
+
actualIterationType = callback;
|
|
4464
|
+
} else if (callback) {
|
|
4465
|
+
actualCallback = callback;
|
|
4466
|
+
if (iterationType) {
|
|
4467
|
+
actualIterationType = iterationType;
|
|
4468
|
+
}
|
|
4469
|
+
}
|
|
4470
|
+
const node = actualIterationType === "RECURSIVE" ? this._getByRankRecursive(this._root, k) : this._getByRankIterative(this._root, k);
|
|
4471
|
+
if (!node) return void 0;
|
|
4472
|
+
return actualCallback ? actualCallback(node) : node.key;
|
|
4473
|
+
}
|
|
4474
|
+
getRank(keyNodeEntryOrPredicate, iterationType = this.iterationType) {
|
|
4475
|
+
var _a;
|
|
4476
|
+
if (!this._enableOrderStatistic) {
|
|
4477
|
+
raise(Error, ERR.orderStatisticNotEnabled("getRank"));
|
|
4478
|
+
}
|
|
4479
|
+
if (!this._root || this._size === 0) return -1;
|
|
4480
|
+
let actualIterationType = this.iterationType;
|
|
4481
|
+
if (iterationType) actualIterationType = iterationType;
|
|
4482
|
+
let key;
|
|
4483
|
+
if (typeof keyNodeEntryOrPredicate === "function") {
|
|
4484
|
+
const results = this.search(keyNodeEntryOrPredicate, true);
|
|
4485
|
+
if (results.length === 0 || results[0] === void 0) return -1;
|
|
4486
|
+
key = results[0];
|
|
4487
|
+
} else if (keyNodeEntryOrPredicate === null || keyNodeEntryOrPredicate === void 0) {
|
|
4488
|
+
return -1;
|
|
4489
|
+
} else if (this.isNode(keyNodeEntryOrPredicate)) {
|
|
4490
|
+
key = keyNodeEntryOrPredicate.key;
|
|
4491
|
+
} else if (Array.isArray(keyNodeEntryOrPredicate)) {
|
|
4492
|
+
key = (_a = keyNodeEntryOrPredicate[0]) != null ? _a : void 0;
|
|
4493
|
+
if (key === void 0 || key === null) return -1;
|
|
4494
|
+
} else {
|
|
4495
|
+
key = keyNodeEntryOrPredicate;
|
|
4496
|
+
}
|
|
4497
|
+
if (key === void 0) return -1;
|
|
4498
|
+
return actualIterationType === "RECURSIVE" ? this._getRankRecursive(this._root, key) : this._getRankIterative(this._root, key);
|
|
4499
|
+
}
|
|
4500
|
+
rangeByRank(start, end, callback = this._DEFAULT_NODE_CALLBACK, iterationType = this.iterationType) {
|
|
4501
|
+
if (!this._enableOrderStatistic) {
|
|
4502
|
+
raise(Error, ERR.orderStatisticNotEnabled("rangeByRank"));
|
|
4503
|
+
}
|
|
4504
|
+
if (this._size === 0) return [];
|
|
4505
|
+
const lo = Math.max(0, start);
|
|
4506
|
+
const hi = Math.min(this._size - 1, end);
|
|
4507
|
+
if (lo > hi) return [];
|
|
4508
|
+
let actualCallback = void 0;
|
|
4509
|
+
let actualIterationType = this.iterationType;
|
|
4510
|
+
if (typeof callback === "string") {
|
|
4511
|
+
actualIterationType = callback;
|
|
4512
|
+
} else if (callback) {
|
|
4513
|
+
actualCallback = callback;
|
|
4514
|
+
if (iterationType) {
|
|
4515
|
+
actualIterationType = iterationType;
|
|
4516
|
+
}
|
|
4517
|
+
}
|
|
4518
|
+
const results = [];
|
|
4519
|
+
const count = hi - lo + 1;
|
|
4520
|
+
const startNode = actualIterationType === "RECURSIVE" ? this._getByRankRecursive(this._root, lo) : this._getByRankIterative(this._root, lo);
|
|
4521
|
+
if (!startNode) return [];
|
|
4522
|
+
let collected = 0;
|
|
4523
|
+
const cb = actualCallback != null ? actualCallback : this._DEFAULT_NODE_CALLBACK;
|
|
4524
|
+
let current = startNode;
|
|
4525
|
+
while (current && collected < count) {
|
|
4526
|
+
results.push(cb(current));
|
|
4527
|
+
collected++;
|
|
4528
|
+
if (collected < count) {
|
|
4529
|
+
current = this._next(current);
|
|
4530
|
+
}
|
|
4531
|
+
}
|
|
4532
|
+
return results;
|
|
4533
|
+
}
|
|
4352
4534
|
/**
|
|
4353
4535
|
* Adds a new node to the BST based on key comparison.
|
|
4354
4536
|
* @remarks Time O(log N), where H is tree height. O(N) worst-case (unbalanced tree), O(log N) average. Space O(1).
|
|
@@ -4434,6 +4616,15 @@ var _BST = class _BST extends BinaryTree {
|
|
|
4434
4616
|
|
|
4435
4617
|
|
|
4436
4618
|
|
|
4619
|
+
|
|
4620
|
+
|
|
4621
|
+
|
|
4622
|
+
|
|
4623
|
+
|
|
4624
|
+
|
|
4625
|
+
|
|
4626
|
+
|
|
4627
|
+
|
|
4437
4628
|
|
|
4438
4629
|
|
|
4439
4630
|
|
|
@@ -4458,6 +4649,7 @@ var _BST = class _BST extends BinaryTree {
|
|
|
4458
4649
|
this._setRoot(newNode);
|
|
4459
4650
|
if (this._isMapMode && this.isRealNode(newNode)) this._store.set(newNode.key, newNode);
|
|
4460
4651
|
this._size++;
|
|
4652
|
+
this._updateCount(newNode);
|
|
4461
4653
|
return true;
|
|
4462
4654
|
}
|
|
4463
4655
|
let current = this._root;
|
|
@@ -4471,6 +4663,7 @@ var _BST = class _BST extends BinaryTree {
|
|
|
4471
4663
|
current.left = newNode;
|
|
4472
4664
|
if (this._isMapMode && this.isRealNode(newNode)) this._store.set(newNode.key, newNode);
|
|
4473
4665
|
this._size++;
|
|
4666
|
+
this._updateCountAlongPath(newNode);
|
|
4474
4667
|
return true;
|
|
4475
4668
|
}
|
|
4476
4669
|
if (current.left !== null) current = current.left;
|
|
@@ -4479,6 +4672,7 @@ var _BST = class _BST extends BinaryTree {
|
|
|
4479
4672
|
current.right = newNode;
|
|
4480
4673
|
if (this._isMapMode && this.isRealNode(newNode)) this._store.set(newNode.key, newNode);
|
|
4481
4674
|
this._size++;
|
|
4675
|
+
this._updateCountAlongPath(newNode);
|
|
4482
4676
|
return true;
|
|
4483
4677
|
}
|
|
4484
4678
|
if (current.right !== null) current = current.right;
|
|
@@ -4543,6 +4737,12 @@ var _BST = class _BST extends BinaryTree {
|
|
|
4543
4737
|
|
|
4544
4738
|
|
|
4545
4739
|
|
|
4740
|
+
|
|
4741
|
+
|
|
4742
|
+
|
|
4743
|
+
|
|
4744
|
+
|
|
4745
|
+
|
|
4546
4746
|
|
|
4547
4747
|
|
|
4548
4748
|
|
|
@@ -4830,6 +5030,9 @@ var _BST = class _BST extends BinaryTree {
|
|
|
4830
5030
|
|
|
4831
5031
|
|
|
4832
5032
|
|
|
5033
|
+
|
|
5034
|
+
|
|
5035
|
+
|
|
4833
5036
|
|
|
4834
5037
|
|
|
4835
5038
|
|
|
@@ -4896,6 +5099,9 @@ var _BST = class _BST extends BinaryTree {
|
|
|
4896
5099
|
|
|
4897
5100
|
|
|
4898
5101
|
|
|
5102
|
+
|
|
5103
|
+
|
|
5104
|
+
|
|
4899
5105
|
|
|
4900
5106
|
|
|
4901
5107
|
|
|
@@ -5009,6 +5215,12 @@ var _BST = class _BST extends BinaryTree {
|
|
|
5009
5215
|
|
|
5010
5216
|
|
|
5011
5217
|
|
|
5218
|
+
|
|
5219
|
+
|
|
5220
|
+
|
|
5221
|
+
|
|
5222
|
+
|
|
5223
|
+
|
|
5012
5224
|
|
|
5013
5225
|
|
|
5014
5226
|
|
|
@@ -5090,13 +5302,11 @@ var _BST = class _BST extends BinaryTree {
|
|
|
5090
5302
|
if (a instanceof Date && b instanceof Date) {
|
|
5091
5303
|
const ta = a.getTime();
|
|
5092
5304
|
const tb = b.getTime();
|
|
5093
|
-
if (Number.isNaN(ta) || Number.isNaN(tb))
|
|
5305
|
+
if (Number.isNaN(ta) || Number.isNaN(tb)) raise(TypeError, ERR.invalidDate("BST"));
|
|
5094
5306
|
return ta > tb ? 1 : ta < tb ? -1 : 0;
|
|
5095
5307
|
}
|
|
5096
5308
|
if (typeof a === "object" || typeof b === "object") {
|
|
5097
|
-
|
|
5098
|
-
ERR.comparatorRequired("BST")
|
|
5099
|
-
);
|
|
5309
|
+
raise(TypeError, ERR.comparatorRequired("BST"));
|
|
5100
5310
|
}
|
|
5101
5311
|
return 0;
|
|
5102
5312
|
};
|
|
@@ -5418,7 +5628,8 @@ var _BST = class _BST extends BinaryTree {
|
|
|
5418
5628
|
_snapshotOptions() {
|
|
5419
5629
|
return {
|
|
5420
5630
|
...super._snapshotOptions(),
|
|
5421
|
-
comparator: this._comparator
|
|
5631
|
+
comparator: this._comparator,
|
|
5632
|
+
enableOrderStatistic: this._enableOrderStatistic
|
|
5422
5633
|
};
|
|
5423
5634
|
}
|
|
5424
5635
|
/**
|
|
@@ -5440,6 +5651,113 @@ var _BST = class _BST extends BinaryTree {
|
|
|
5440
5651
|
*
|
|
5441
5652
|
* @param v - The node to set as root.
|
|
5442
5653
|
*/
|
|
5654
|
+
/**
|
|
5655
|
+
* (Protected) Recalculates the subtree count for a single node.
|
|
5656
|
+
* @remarks Time O(1). Only active when enableOrderStatistic is true.
|
|
5657
|
+
*/
|
|
5658
|
+
_updateCount(node) {
|
|
5659
|
+
if (!this._enableOrderStatistic) return;
|
|
5660
|
+
node._count = 1 + (this.isRealNode(node.left) ? node.left._count : 0) + (this.isRealNode(node.right) ? node.right._count : 0);
|
|
5661
|
+
}
|
|
5662
|
+
/**
|
|
5663
|
+
* (Protected) Updates subtree counts from a node up to the root.
|
|
5664
|
+
* @remarks Time O(log n). Only active when enableOrderStatistic is true.
|
|
5665
|
+
*/
|
|
5666
|
+
_updateCountAlongPath(node) {
|
|
5667
|
+
if (!this._enableOrderStatistic) return;
|
|
5668
|
+
let current = node;
|
|
5669
|
+
while (current) {
|
|
5670
|
+
this._updateCount(current);
|
|
5671
|
+
current = current.parent;
|
|
5672
|
+
}
|
|
5673
|
+
}
|
|
5674
|
+
/**
|
|
5675
|
+
* (Protected) Finds the node at position k in tree order (iterative).
|
|
5676
|
+
* @remarks Time O(log n), Space O(1)
|
|
5677
|
+
*/
|
|
5678
|
+
_getByRankIterative(node, k) {
|
|
5679
|
+
let current = node;
|
|
5680
|
+
let remaining = k;
|
|
5681
|
+
while (current) {
|
|
5682
|
+
const leftCount = this.isRealNode(current.left) ? current.left._count : 0;
|
|
5683
|
+
if (remaining < leftCount) {
|
|
5684
|
+
current = current.left;
|
|
5685
|
+
} else if (remaining === leftCount) {
|
|
5686
|
+
return current;
|
|
5687
|
+
} else {
|
|
5688
|
+
remaining = remaining - leftCount - 1;
|
|
5689
|
+
current = current.right;
|
|
5690
|
+
}
|
|
5691
|
+
}
|
|
5692
|
+
return void 0;
|
|
5693
|
+
}
|
|
5694
|
+
/**
|
|
5695
|
+
* (Protected) Finds the node at position k in tree order (recursive).
|
|
5696
|
+
* @remarks Time O(log n), Space O(log n) call stack
|
|
5697
|
+
*/
|
|
5698
|
+
_getByRankRecursive(node, k) {
|
|
5699
|
+
if (!node) return void 0;
|
|
5700
|
+
const leftCount = this.isRealNode(node.left) ? node.left._count : 0;
|
|
5701
|
+
if (k < leftCount) return this._getByRankRecursive(node.left, k);
|
|
5702
|
+
if (k === leftCount) return node;
|
|
5703
|
+
return this._getByRankRecursive(node.right, k - leftCount - 1);
|
|
5704
|
+
}
|
|
5705
|
+
/**
|
|
5706
|
+
* (Protected) Computes the rank of a key iteratively.
|
|
5707
|
+
* @remarks Time O(log n), Space O(1)
|
|
5708
|
+
*/
|
|
5709
|
+
_getRankIterative(node, key) {
|
|
5710
|
+
let rank = 0;
|
|
5711
|
+
let current = node;
|
|
5712
|
+
while (this.isRealNode(current)) {
|
|
5713
|
+
const cmp = this._compare(current.key, key);
|
|
5714
|
+
if (cmp > 0) {
|
|
5715
|
+
current = current.left;
|
|
5716
|
+
} else if (cmp < 0) {
|
|
5717
|
+
rank += (this.isRealNode(current.left) ? current.left._count : 0) + 1;
|
|
5718
|
+
current = current.right;
|
|
5719
|
+
} else {
|
|
5720
|
+
rank += this.isRealNode(current.left) ? current.left._count : 0;
|
|
5721
|
+
return rank;
|
|
5722
|
+
}
|
|
5723
|
+
}
|
|
5724
|
+
return rank;
|
|
5725
|
+
}
|
|
5726
|
+
/**
|
|
5727
|
+
* (Protected) Computes the rank of a key recursively.
|
|
5728
|
+
* @remarks Time O(log n), Space O(log n) call stack
|
|
5729
|
+
*/
|
|
5730
|
+
_getRankRecursive(node, key) {
|
|
5731
|
+
if (!node) return 0;
|
|
5732
|
+
const cmp = this._compare(node.key, key);
|
|
5733
|
+
if (cmp > 0) {
|
|
5734
|
+
return this._getRankRecursive(node.left, key);
|
|
5735
|
+
} else if (cmp < 0) {
|
|
5736
|
+
return (this.isRealNode(node.left) ? node.left._count : 0) + 1 + this._getRankRecursive(node.right, key);
|
|
5737
|
+
} else {
|
|
5738
|
+
return this.isRealNode(node.left) ? node.left._count : 0;
|
|
5739
|
+
}
|
|
5740
|
+
}
|
|
5741
|
+
/**
|
|
5742
|
+
* (Protected) Finds the in-order successor of a node.
|
|
5743
|
+
* @remarks Time O(log n), Space O(1)
|
|
5744
|
+
*/
|
|
5745
|
+
_next(node) {
|
|
5746
|
+
if (this.isRealNode(node.right)) {
|
|
5747
|
+
let current2 = node.right;
|
|
5748
|
+
while (this.isRealNode(current2.left)) {
|
|
5749
|
+
current2 = current2.left;
|
|
5750
|
+
}
|
|
5751
|
+
return current2;
|
|
5752
|
+
}
|
|
5753
|
+
let current = node;
|
|
5754
|
+
let parent = current.parent;
|
|
5755
|
+
while (parent && current === parent.right) {
|
|
5756
|
+
current = parent;
|
|
5757
|
+
parent = parent.parent;
|
|
5758
|
+
}
|
|
5759
|
+
return parent;
|
|
5760
|
+
}
|
|
5443
5761
|
_setRoot(v) {
|
|
5444
5762
|
if (v) v.parent = void 0;
|
|
5445
5763
|
this._root = v;
|
|
@@ -5486,21 +5804,28 @@ var _BST = class _BST extends BinaryTree {
|
|
|
5486
5804
|
while (x.left !== void 0 && x.left !== null) x = x.left;
|
|
5487
5805
|
return x;
|
|
5488
5806
|
}, "minNode");
|
|
5807
|
+
let countUpdateStart;
|
|
5489
5808
|
if (node.left === void 0) {
|
|
5809
|
+
countUpdateStart = node.parent;
|
|
5490
5810
|
transplant(node, node.right);
|
|
5491
5811
|
} else if (node.right === void 0) {
|
|
5812
|
+
countUpdateStart = node.parent;
|
|
5492
5813
|
transplant(node, node.left);
|
|
5493
5814
|
} else {
|
|
5494
5815
|
const succ = minNode(node.right);
|
|
5495
5816
|
if (succ.parent !== node) {
|
|
5817
|
+
countUpdateStart = succ.parent;
|
|
5496
5818
|
transplant(succ, succ.right);
|
|
5497
5819
|
succ.right = node.right;
|
|
5498
5820
|
if (succ.right) succ.right.parent = succ;
|
|
5821
|
+
} else {
|
|
5822
|
+
countUpdateStart = succ;
|
|
5499
5823
|
}
|
|
5500
5824
|
transplant(node, succ);
|
|
5501
5825
|
succ.left = node.left;
|
|
5502
5826
|
if (succ.left) succ.left.parent = succ;
|
|
5503
5827
|
}
|
|
5828
|
+
this._updateCountAlongPath(countUpdateStart);
|
|
5504
5829
|
this._size = Math.max(0, this._size - 1);
|
|
5505
5830
|
return true;
|
|
5506
5831
|
}
|
|
@@ -5785,6 +6110,18 @@ var _AVLTree = class _AVLTree extends BST {
|
|
|
5785
6110
|
|
|
5786
6111
|
|
|
5787
6112
|
|
|
6113
|
+
|
|
6114
|
+
|
|
6115
|
+
|
|
6116
|
+
|
|
6117
|
+
|
|
6118
|
+
|
|
6119
|
+
|
|
6120
|
+
|
|
6121
|
+
|
|
6122
|
+
|
|
6123
|
+
|
|
6124
|
+
|
|
5788
6125
|
|
|
5789
6126
|
|
|
5790
6127
|
|
|
@@ -5903,6 +6240,15 @@ var _AVLTree = class _AVLTree extends BST {
|
|
|
5903
6240
|
|
|
5904
6241
|
|
|
5905
6242
|
|
|
6243
|
+
|
|
6244
|
+
|
|
6245
|
+
|
|
6246
|
+
|
|
6247
|
+
|
|
6248
|
+
|
|
6249
|
+
|
|
6250
|
+
|
|
6251
|
+
|
|
5906
6252
|
|
|
5907
6253
|
|
|
5908
6254
|
|
|
@@ -5983,6 +6329,12 @@ var _AVLTree = class _AVLTree extends BST {
|
|
|
5983
6329
|
|
|
5984
6330
|
|
|
5985
6331
|
|
|
6332
|
+
|
|
6333
|
+
|
|
6334
|
+
|
|
6335
|
+
|
|
6336
|
+
|
|
6337
|
+
|
|
5986
6338
|
|
|
5987
6339
|
|
|
5988
6340
|
|
|
@@ -6107,6 +6459,15 @@ var _AVLTree = class _AVLTree extends BST {
|
|
|
6107
6459
|
|
|
6108
6460
|
|
|
6109
6461
|
|
|
6462
|
+
|
|
6463
|
+
|
|
6464
|
+
|
|
6465
|
+
|
|
6466
|
+
|
|
6467
|
+
|
|
6468
|
+
|
|
6469
|
+
|
|
6470
|
+
|
|
6110
6471
|
|
|
6111
6472
|
|
|
6112
6473
|
|
|
@@ -6235,6 +6596,8 @@ var _AVLTree = class _AVLTree extends BST {
|
|
|
6235
6596
|
}
|
|
6236
6597
|
this._updateHeight(A);
|
|
6237
6598
|
if (B) this._updateHeight(B);
|
|
6599
|
+
this._updateCount(A);
|
|
6600
|
+
if (B) this._updateCount(B);
|
|
6238
6601
|
}
|
|
6239
6602
|
/**
|
|
6240
6603
|
* (Protected) Performs a Left-Right (LR) double rotation.
|
|
@@ -6280,6 +6643,9 @@ var _AVLTree = class _AVLTree extends BST {
|
|
|
6280
6643
|
this._updateHeight(A);
|
|
6281
6644
|
if (B) this._updateHeight(B);
|
|
6282
6645
|
if (C) this._updateHeight(C);
|
|
6646
|
+
this._updateCount(A);
|
|
6647
|
+
if (B) this._updateCount(B);
|
|
6648
|
+
if (C) this._updateCount(C);
|
|
6283
6649
|
}
|
|
6284
6650
|
/**
|
|
6285
6651
|
* (Protected) Performs a Right-Right (RR) rotation (a single left rotation).
|
|
@@ -6314,6 +6680,8 @@ var _AVLTree = class _AVLTree extends BST {
|
|
|
6314
6680
|
}
|
|
6315
6681
|
this._updateHeight(A);
|
|
6316
6682
|
if (B) this._updateHeight(B);
|
|
6683
|
+
this._updateCount(A);
|
|
6684
|
+
if (B) this._updateCount(B);
|
|
6317
6685
|
}
|
|
6318
6686
|
/**
|
|
6319
6687
|
* (Protected) Performs a Right-Left (RL) double rotation.
|
|
@@ -6357,6 +6725,9 @@ var _AVLTree = class _AVLTree extends BST {
|
|
|
6357
6725
|
this._updateHeight(A);
|
|
6358
6726
|
if (B) this._updateHeight(B);
|
|
6359
6727
|
if (C) this._updateHeight(C);
|
|
6728
|
+
this._updateCount(A);
|
|
6729
|
+
if (B) this._updateCount(B);
|
|
6730
|
+
if (C) this._updateCount(C);
|
|
6360
6731
|
}
|
|
6361
6732
|
/**
|
|
6362
6733
|
* (Protected) Traverses up the tree from the specified node, updating heights and performing rotations as needed.
|
|
@@ -6371,6 +6742,7 @@ var _AVLTree = class _AVLTree extends BST {
|
|
|
6371
6742
|
const A = path[i];
|
|
6372
6743
|
if (A) {
|
|
6373
6744
|
this._updateHeight(A);
|
|
6745
|
+
this._updateCount(A);
|
|
6374
6746
|
switch (this._balanceFactor(A)) {
|
|
6375
6747
|
case -2:
|
|
6376
6748
|
if (A && A.left) {
|