bst-typed 2.5.0 → 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 +1222 -57
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs-legacy/index.cjs +1222 -56
- package/dist/cjs-legacy/index.cjs.map +1 -1
- package/dist/esm/index.mjs +1222 -58
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm-legacy/index.mjs +1222 -57
- 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/base/index.d.ts +1 -0
- package/dist/types/data-structures/base/iterable-entry-base.d.ts +8 -8
- package/dist/types/data-structures/base/linear-base.d.ts +3 -3
- package/dist/types/data-structures/binary-tree/avl-tree.d.ts +288 -0
- package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +336 -0
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +618 -18
- package/dist/types/data-structures/binary-tree/bst.d.ts +676 -1
- package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +456 -0
- package/dist/types/data-structures/binary-tree/segment-tree.d.ts +144 -1
- package/dist/types/data-structures/binary-tree/tree-map.d.ts +3307 -399
- package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +3285 -360
- package/dist/types/data-structures/binary-tree/tree-multi-set.d.ts +2674 -325
- package/dist/types/data-structures/binary-tree/tree-set.d.ts +3072 -287
- package/dist/types/data-structures/graph/abstract-graph.d.ts +4 -4
- package/dist/types/data-structures/graph/directed-graph.d.ts +240 -0
- package/dist/types/data-structures/graph/undirected-graph.d.ts +216 -0
- package/dist/types/data-structures/hash/hash-map.d.ts +274 -10
- package/dist/types/data-structures/heap/heap.d.ts +336 -0
- package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +411 -3
- package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +363 -3
- package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +434 -2
- package/dist/types/data-structures/matrix/matrix.d.ts +192 -0
- package/dist/types/data-structures/queue/deque.d.ts +364 -4
- package/dist/types/data-structures/queue/queue.d.ts +288 -0
- package/dist/types/data-structures/stack/stack.d.ts +240 -0
- package/dist/types/data-structures/trie/trie.d.ts +292 -4
- package/dist/types/interfaces/graph.d.ts +1 -1
- package/dist/types/types/common.d.ts +2 -2
- 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/types/types/data-structures/heap/heap.d.ts +1 -0
- package/dist/types/types/data-structures/priority-queue/priority-queue.d.ts +1 -0
- package/dist/types/types/utils/validate-type.d.ts +4 -4
- package/dist/umd/bst-typed.js +1220 -55
- package/dist/umd/bst-typed.js.map +1 -1
- package/dist/umd/bst-typed.min.js +3 -3
- package/dist/umd/bst-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/index.ts +1 -0
- package/src/data-structures/base/iterable-element-base.ts +3 -2
- package/src/data-structures/base/iterable-entry-base.ts +8 -8
- package/src/data-structures/base/linear-base.ts +3 -3
- package/src/data-structures/binary-tree/avl-tree.ts +299 -0
- package/src/data-structures/binary-tree/binary-indexed-tree.ts +341 -5
- package/src/data-structures/binary-tree/binary-tree.ts +606 -6
- package/src/data-structures/binary-tree/bst.ts +946 -7
- package/src/data-structures/binary-tree/red-black-tree.ts +472 -0
- package/src/data-structures/binary-tree/segment-tree.ts +145 -2
- package/src/data-structures/binary-tree/tree-map.ts +3423 -499
- package/src/data-structures/binary-tree/tree-multi-map.ts +3537 -596
- package/src/data-structures/binary-tree/tree-multi-set.ts +2855 -495
- package/src/data-structures/binary-tree/tree-set.ts +3209 -413
- package/src/data-structures/graph/abstract-graph.ts +6 -6
- package/src/data-structures/graph/directed-graph.ts +240 -0
- package/src/data-structures/graph/undirected-graph.ts +216 -0
- package/src/data-structures/hash/hash-map.ts +281 -19
- package/src/data-structures/heap/heap.ts +340 -4
- package/src/data-structures/heap/max-heap.ts +2 -2
- package/src/data-structures/linked-list/doubly-linked-list.ts +411 -3
- package/src/data-structures/linked-list/singly-linked-list.ts +363 -3
- package/src/data-structures/linked-list/skip-linked-list.ts +439 -7
- package/src/data-structures/matrix/matrix.ts +202 -10
- package/src/data-structures/priority-queue/max-priority-queue.ts +2 -2
- package/src/data-structures/queue/deque.ts +365 -5
- package/src/data-structures/queue/queue.ts +288 -0
- package/src/data-structures/stack/stack.ts +240 -0
- package/src/data-structures/trie/trie.ts +295 -7
- package/src/interfaces/graph.ts +1 -1
- package/src/types/common.ts +2 -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/src/types/data-structures/heap/heap.ts +1 -0
- package/src/types/data-structures/priority-queue/priority-queue.ts +1 -0
- package/src/types/utils/validate-type.ts +4 -4
|
@@ -61,6 +61,60 @@ function makeTrampoline(fn) {
|
|
|
61
61
|
}
|
|
62
62
|
__name(makeTrampoline, "makeTrampoline");
|
|
63
63
|
|
|
64
|
+
// src/common/error.ts
|
|
65
|
+
function raise(ErrorClass, message) {
|
|
66
|
+
throw new ErrorClass(message);
|
|
67
|
+
}
|
|
68
|
+
__name(raise, "raise");
|
|
69
|
+
var ERR = {
|
|
70
|
+
// Range / index
|
|
71
|
+
indexOutOfRange: /* @__PURE__ */ __name((index, min, max, ctx) => `${ctx ? ctx + ": " : ""}Index ${index} is out of range [${min}, ${max}].`, "indexOutOfRange"),
|
|
72
|
+
invalidIndex: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Index must be an integer.`, "invalidIndex"),
|
|
73
|
+
// Type / argument
|
|
74
|
+
invalidArgument: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidArgument"),
|
|
75
|
+
comparatorRequired: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Comparator is required for non-number/non-string/non-Date keys.`, "comparatorRequired"),
|
|
76
|
+
invalidKey: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidKey"),
|
|
77
|
+
notAFunction: /* @__PURE__ */ __name((name, ctx) => `${ctx ? ctx + ": " : ""}${name} must be a function.`, "notAFunction"),
|
|
78
|
+
invalidEntry: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Each entry must be a [key, value] tuple.`, "invalidEntry"),
|
|
79
|
+
invalidNaN: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}NaN is not a valid key.`, "invalidNaN"),
|
|
80
|
+
invalidDate: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Invalid Date key.`, "invalidDate"),
|
|
81
|
+
reduceEmpty: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Reduce of empty structure with no initial value.`, "reduceEmpty"),
|
|
82
|
+
callbackReturnType: /* @__PURE__ */ __name((expected, got, ctx) => `${ctx ? ctx + ": " : ""}Callback must return ${expected}; got ${got}.`, "callbackReturnType"),
|
|
83
|
+
// State / operation
|
|
84
|
+
invalidOperation: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidOperation"),
|
|
85
|
+
// Matrix
|
|
86
|
+
matrixDimensionMismatch: /* @__PURE__ */ __name((op) => `Matrix: Dimensions must be compatible for ${op}.`, "matrixDimensionMismatch"),
|
|
87
|
+
matrixSingular: /* @__PURE__ */ __name(() => "Matrix: Singular matrix, inverse does not exist.", "matrixSingular"),
|
|
88
|
+
matrixNotSquare: /* @__PURE__ */ __name(() => "Matrix: Must be square for inversion.", "matrixNotSquare"),
|
|
89
|
+
matrixNotRectangular: /* @__PURE__ */ __name(() => "Matrix: Must be rectangular for transposition.", "matrixNotRectangular"),
|
|
90
|
+
matrixRowMismatch: /* @__PURE__ */ __name((expected, got) => `Matrix: Expected row length ${expected}, but got ${got}.`, "matrixRowMismatch"),
|
|
91
|
+
// Order statistic
|
|
92
|
+
orderStatisticNotEnabled: /* @__PURE__ */ __name((method, ctx) => `${ctx ? ctx + ": " : ""}${method}() requires enableOrderStatistic: true.`, "orderStatisticNotEnabled")
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
// src/common/index.ts
|
|
96
|
+
var DFSOperation = /* @__PURE__ */ ((DFSOperation2) => {
|
|
97
|
+
DFSOperation2[DFSOperation2["VISIT"] = 0] = "VISIT";
|
|
98
|
+
DFSOperation2[DFSOperation2["PROCESS"] = 1] = "PROCESS";
|
|
99
|
+
return DFSOperation2;
|
|
100
|
+
})(DFSOperation || {});
|
|
101
|
+
var _Range = class _Range {
|
|
102
|
+
constructor(low, high, includeLow = true, includeHigh = true) {
|
|
103
|
+
this.low = low;
|
|
104
|
+
this.high = high;
|
|
105
|
+
this.includeLow = includeLow;
|
|
106
|
+
this.includeHigh = includeHigh;
|
|
107
|
+
}
|
|
108
|
+
// Determine whether a key is within the range
|
|
109
|
+
isInRange(key, comparator) {
|
|
110
|
+
const lowCheck = this.includeLow ? comparator(key, this.low) >= 0 : comparator(key, this.low) > 0;
|
|
111
|
+
const highCheck = this.includeHigh ? comparator(key, this.high) <= 0 : comparator(key, this.high) < 0;
|
|
112
|
+
return lowCheck && highCheck;
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
__name(_Range, "Range");
|
|
116
|
+
var Range = _Range;
|
|
117
|
+
|
|
64
118
|
// src/data-structures/base/iterable-element-base.ts
|
|
65
119
|
var _IterableElementBase = class _IterableElementBase {
|
|
66
120
|
/**
|
|
@@ -83,7 +137,7 @@ var _IterableElementBase = class _IterableElementBase {
|
|
|
83
137
|
if (options) {
|
|
84
138
|
const { toElementFn } = options;
|
|
85
139
|
if (typeof toElementFn === "function") this._toElementFn = toElementFn;
|
|
86
|
-
else if (toElementFn)
|
|
140
|
+
else if (toElementFn) raise(TypeError, "toElementFn must be a function type");
|
|
87
141
|
}
|
|
88
142
|
}
|
|
89
143
|
/**
|
|
@@ -239,7 +293,7 @@ var _IterableElementBase = class _IterableElementBase {
|
|
|
239
293
|
acc = initialValue;
|
|
240
294
|
} else {
|
|
241
295
|
const first = iter.next();
|
|
242
|
-
if (first.done)
|
|
296
|
+
if (first.done) raise(TypeError, "Reduce of empty structure with no initial value");
|
|
243
297
|
acc = first.value;
|
|
244
298
|
index = 1;
|
|
245
299
|
}
|
|
@@ -475,54 +529,6 @@ var _LinearBase = class _LinearBase extends IterableElementBase {
|
|
|
475
529
|
__name(_LinearBase, "LinearBase");
|
|
476
530
|
var LinearBase = _LinearBase;
|
|
477
531
|
|
|
478
|
-
// src/common/error.ts
|
|
479
|
-
var ERR = {
|
|
480
|
-
// Range / index
|
|
481
|
-
indexOutOfRange: /* @__PURE__ */ __name((index, min, max, ctx) => `${ctx ? ctx + ": " : ""}Index ${index} is out of range [${min}, ${max}].`, "indexOutOfRange"),
|
|
482
|
-
invalidIndex: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Index must be an integer.`, "invalidIndex"),
|
|
483
|
-
// Type / argument
|
|
484
|
-
invalidArgument: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidArgument"),
|
|
485
|
-
comparatorRequired: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Comparator is required for non-number/non-string/non-Date keys.`, "comparatorRequired"),
|
|
486
|
-
invalidKey: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidKey"),
|
|
487
|
-
notAFunction: /* @__PURE__ */ __name((name, ctx) => `${ctx ? ctx + ": " : ""}${name} must be a function.`, "notAFunction"),
|
|
488
|
-
invalidEntry: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Each entry must be a [key, value] tuple.`, "invalidEntry"),
|
|
489
|
-
invalidNaN: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}NaN is not a valid key.`, "invalidNaN"),
|
|
490
|
-
invalidDate: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Invalid Date key.`, "invalidDate"),
|
|
491
|
-
reduceEmpty: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Reduce of empty structure with no initial value.`, "reduceEmpty"),
|
|
492
|
-
callbackReturnType: /* @__PURE__ */ __name((expected, got, ctx) => `${ctx ? ctx + ": " : ""}Callback must return ${expected}; got ${got}.`, "callbackReturnType"),
|
|
493
|
-
// State / operation
|
|
494
|
-
invalidOperation: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidOperation"),
|
|
495
|
-
// Matrix
|
|
496
|
-
matrixDimensionMismatch: /* @__PURE__ */ __name((op) => `Matrix: Dimensions must be compatible for ${op}.`, "matrixDimensionMismatch"),
|
|
497
|
-
matrixSingular: /* @__PURE__ */ __name(() => "Matrix: Singular matrix, inverse does not exist.", "matrixSingular"),
|
|
498
|
-
matrixNotSquare: /* @__PURE__ */ __name(() => "Matrix: Must be square for inversion.", "matrixNotSquare"),
|
|
499
|
-
matrixNotRectangular: /* @__PURE__ */ __name(() => "Matrix: Must be rectangular for transposition.", "matrixNotRectangular"),
|
|
500
|
-
matrixRowMismatch: /* @__PURE__ */ __name((expected, got) => `Matrix: Expected row length ${expected}, but got ${got}.`, "matrixRowMismatch")
|
|
501
|
-
};
|
|
502
|
-
|
|
503
|
-
// src/common/index.ts
|
|
504
|
-
var DFSOperation = /* @__PURE__ */ ((DFSOperation2) => {
|
|
505
|
-
DFSOperation2[DFSOperation2["VISIT"] = 0] = "VISIT";
|
|
506
|
-
DFSOperation2[DFSOperation2["PROCESS"] = 1] = "PROCESS";
|
|
507
|
-
return DFSOperation2;
|
|
508
|
-
})(DFSOperation || {});
|
|
509
|
-
var _Range = class _Range {
|
|
510
|
-
constructor(low, high, includeLow = true, includeHigh = true) {
|
|
511
|
-
this.low = low;
|
|
512
|
-
this.high = high;
|
|
513
|
-
this.includeLow = includeLow;
|
|
514
|
-
this.includeHigh = includeHigh;
|
|
515
|
-
}
|
|
516
|
-
// Determine whether a key is within the range
|
|
517
|
-
isInRange(key, comparator) {
|
|
518
|
-
const lowCheck = this.includeLow ? comparator(key, this.low) >= 0 : comparator(key, this.low) > 0;
|
|
519
|
-
const highCheck = this.includeHigh ? comparator(key, this.high) <= 0 : comparator(key, this.high) < 0;
|
|
520
|
-
return lowCheck && highCheck;
|
|
521
|
-
}
|
|
522
|
-
};
|
|
523
|
-
__name(_Range, "Range");
|
|
524
|
-
var Range = _Range;
|
|
525
|
-
|
|
526
532
|
// src/data-structures/base/iterable-entry-base.ts
|
|
527
533
|
var _IterableEntryBase = class _IterableEntryBase {
|
|
528
534
|
/**
|
|
@@ -772,6 +778,30 @@ var _Queue = class _Queue extends LinearBase {
|
|
|
772
778
|
|
|
773
779
|
|
|
774
780
|
|
|
781
|
+
|
|
782
|
+
|
|
783
|
+
|
|
784
|
+
|
|
785
|
+
|
|
786
|
+
|
|
787
|
+
|
|
788
|
+
|
|
789
|
+
|
|
790
|
+
|
|
791
|
+
|
|
792
|
+
|
|
793
|
+
|
|
794
|
+
|
|
795
|
+
|
|
796
|
+
|
|
797
|
+
|
|
798
|
+
|
|
799
|
+
|
|
800
|
+
|
|
801
|
+
|
|
802
|
+
|
|
803
|
+
|
|
804
|
+
|
|
775
805
|
* @example
|
|
776
806
|
* // Track queue length
|
|
777
807
|
* const q = new Queue<number>();
|
|
@@ -798,6 +828,30 @@ var _Queue = class _Queue extends LinearBase {
|
|
|
798
828
|
|
|
799
829
|
|
|
800
830
|
|
|
831
|
+
|
|
832
|
+
|
|
833
|
+
|
|
834
|
+
|
|
835
|
+
|
|
836
|
+
|
|
837
|
+
|
|
838
|
+
|
|
839
|
+
|
|
840
|
+
|
|
841
|
+
|
|
842
|
+
|
|
843
|
+
|
|
844
|
+
|
|
845
|
+
|
|
846
|
+
|
|
847
|
+
|
|
848
|
+
|
|
849
|
+
|
|
850
|
+
|
|
851
|
+
|
|
852
|
+
|
|
853
|
+
|
|
854
|
+
|
|
801
855
|
* @example
|
|
802
856
|
* // View the front element
|
|
803
857
|
* const q = new Queue<string>(['first', 'second', 'third']);
|
|
@@ -840,6 +894,30 @@ var _Queue = class _Queue extends LinearBase {
|
|
|
840
894
|
|
|
841
895
|
|
|
842
896
|
|
|
897
|
+
|
|
898
|
+
|
|
899
|
+
|
|
900
|
+
|
|
901
|
+
|
|
902
|
+
|
|
903
|
+
|
|
904
|
+
|
|
905
|
+
|
|
906
|
+
|
|
907
|
+
|
|
908
|
+
|
|
909
|
+
|
|
910
|
+
|
|
911
|
+
|
|
912
|
+
|
|
913
|
+
|
|
914
|
+
|
|
915
|
+
|
|
916
|
+
|
|
917
|
+
|
|
918
|
+
|
|
919
|
+
|
|
920
|
+
|
|
843
921
|
* @example
|
|
844
922
|
* // Queue for...of iteration and isEmpty check
|
|
845
923
|
* const queue = new Queue<string>(['A', 'B', 'C', 'D']);
|
|
@@ -878,6 +956,30 @@ var _Queue = class _Queue extends LinearBase {
|
|
|
878
956
|
|
|
879
957
|
|
|
880
958
|
|
|
959
|
+
|
|
960
|
+
|
|
961
|
+
|
|
962
|
+
|
|
963
|
+
|
|
964
|
+
|
|
965
|
+
|
|
966
|
+
|
|
967
|
+
|
|
968
|
+
|
|
969
|
+
|
|
970
|
+
|
|
971
|
+
|
|
972
|
+
|
|
973
|
+
|
|
974
|
+
|
|
975
|
+
|
|
976
|
+
|
|
977
|
+
|
|
978
|
+
|
|
979
|
+
|
|
980
|
+
|
|
981
|
+
|
|
982
|
+
|
|
881
983
|
* @example
|
|
882
984
|
* // basic Queue creation and push operation
|
|
883
985
|
* // Create a simple Queue with initial values
|
|
@@ -923,6 +1025,30 @@ var _Queue = class _Queue extends LinearBase {
|
|
|
923
1025
|
|
|
924
1026
|
|
|
925
1027
|
|
|
1028
|
+
|
|
1029
|
+
|
|
1030
|
+
|
|
1031
|
+
|
|
1032
|
+
|
|
1033
|
+
|
|
1034
|
+
|
|
1035
|
+
|
|
1036
|
+
|
|
1037
|
+
|
|
1038
|
+
|
|
1039
|
+
|
|
1040
|
+
|
|
1041
|
+
|
|
1042
|
+
|
|
1043
|
+
|
|
1044
|
+
|
|
1045
|
+
|
|
1046
|
+
|
|
1047
|
+
|
|
1048
|
+
|
|
1049
|
+
|
|
1050
|
+
|
|
1051
|
+
|
|
926
1052
|
* @example
|
|
927
1053
|
* // Queue shift and peek operations
|
|
928
1054
|
* const queue = new Queue<number>([10, 20, 30, 40]);
|
|
@@ -958,6 +1084,30 @@ var _Queue = class _Queue extends LinearBase {
|
|
|
958
1084
|
|
|
959
1085
|
|
|
960
1086
|
|
|
1087
|
+
|
|
1088
|
+
|
|
1089
|
+
|
|
1090
|
+
|
|
1091
|
+
|
|
1092
|
+
|
|
1093
|
+
|
|
1094
|
+
|
|
1095
|
+
|
|
1096
|
+
|
|
1097
|
+
|
|
1098
|
+
|
|
1099
|
+
|
|
1100
|
+
|
|
1101
|
+
|
|
1102
|
+
|
|
1103
|
+
|
|
1104
|
+
|
|
1105
|
+
|
|
1106
|
+
|
|
1107
|
+
|
|
1108
|
+
|
|
1109
|
+
|
|
1110
|
+
|
|
961
1111
|
* @example
|
|
962
1112
|
* // Remove specific element
|
|
963
1113
|
* const q = new Queue<number>([1, 2, 3, 2]);
|
|
@@ -986,6 +1136,30 @@ var _Queue = class _Queue extends LinearBase {
|
|
|
986
1136
|
|
|
987
1137
|
|
|
988
1138
|
|
|
1139
|
+
|
|
1140
|
+
|
|
1141
|
+
|
|
1142
|
+
|
|
1143
|
+
|
|
1144
|
+
|
|
1145
|
+
|
|
1146
|
+
|
|
1147
|
+
|
|
1148
|
+
|
|
1149
|
+
|
|
1150
|
+
|
|
1151
|
+
|
|
1152
|
+
|
|
1153
|
+
|
|
1154
|
+
|
|
1155
|
+
|
|
1156
|
+
|
|
1157
|
+
|
|
1158
|
+
|
|
1159
|
+
|
|
1160
|
+
|
|
1161
|
+
|
|
1162
|
+
|
|
989
1163
|
* @example
|
|
990
1164
|
* // Access element by index
|
|
991
1165
|
* const q = new Queue<string>(['a', 'b', 'c']);
|
|
@@ -1055,6 +1229,30 @@ var _Queue = class _Queue extends LinearBase {
|
|
|
1055
1229
|
|
|
1056
1230
|
|
|
1057
1231
|
|
|
1232
|
+
|
|
1233
|
+
|
|
1234
|
+
|
|
1235
|
+
|
|
1236
|
+
|
|
1237
|
+
|
|
1238
|
+
|
|
1239
|
+
|
|
1240
|
+
|
|
1241
|
+
|
|
1242
|
+
|
|
1243
|
+
|
|
1244
|
+
|
|
1245
|
+
|
|
1246
|
+
|
|
1247
|
+
|
|
1248
|
+
|
|
1249
|
+
|
|
1250
|
+
|
|
1251
|
+
|
|
1252
|
+
|
|
1253
|
+
|
|
1254
|
+
|
|
1255
|
+
|
|
1058
1256
|
* @example
|
|
1059
1257
|
* // Remove all elements
|
|
1060
1258
|
* const q = new Queue<number>([1, 2, 3]);
|
|
@@ -1077,6 +1275,30 @@ var _Queue = class _Queue extends LinearBase {
|
|
|
1077
1275
|
|
|
1078
1276
|
|
|
1079
1277
|
|
|
1278
|
+
|
|
1279
|
+
|
|
1280
|
+
|
|
1281
|
+
|
|
1282
|
+
|
|
1283
|
+
|
|
1284
|
+
|
|
1285
|
+
|
|
1286
|
+
|
|
1287
|
+
|
|
1288
|
+
|
|
1289
|
+
|
|
1290
|
+
|
|
1291
|
+
|
|
1292
|
+
|
|
1293
|
+
|
|
1294
|
+
|
|
1295
|
+
|
|
1296
|
+
|
|
1297
|
+
|
|
1298
|
+
|
|
1299
|
+
|
|
1300
|
+
|
|
1301
|
+
|
|
1080
1302
|
* @example
|
|
1081
1303
|
* // Reclaim unused memory
|
|
1082
1304
|
* const q = new Queue<number>([1, 2, 3, 4, 5]);
|
|
@@ -1122,6 +1344,30 @@ var _Queue = class _Queue extends LinearBase {
|
|
|
1122
1344
|
|
|
1123
1345
|
|
|
1124
1346
|
|
|
1347
|
+
|
|
1348
|
+
|
|
1349
|
+
|
|
1350
|
+
|
|
1351
|
+
|
|
1352
|
+
|
|
1353
|
+
|
|
1354
|
+
|
|
1355
|
+
|
|
1356
|
+
|
|
1357
|
+
|
|
1358
|
+
|
|
1359
|
+
|
|
1360
|
+
|
|
1361
|
+
|
|
1362
|
+
|
|
1363
|
+
|
|
1364
|
+
|
|
1365
|
+
|
|
1366
|
+
|
|
1367
|
+
|
|
1368
|
+
|
|
1369
|
+
|
|
1370
|
+
|
|
1125
1371
|
* @example
|
|
1126
1372
|
* // Create independent copy
|
|
1127
1373
|
* const q = new Queue<number>([1, 2, 3]);
|
|
@@ -1151,6 +1397,30 @@ var _Queue = class _Queue extends LinearBase {
|
|
|
1151
1397
|
|
|
1152
1398
|
|
|
1153
1399
|
|
|
1400
|
+
|
|
1401
|
+
|
|
1402
|
+
|
|
1403
|
+
|
|
1404
|
+
|
|
1405
|
+
|
|
1406
|
+
|
|
1407
|
+
|
|
1408
|
+
|
|
1409
|
+
|
|
1410
|
+
|
|
1411
|
+
|
|
1412
|
+
|
|
1413
|
+
|
|
1414
|
+
|
|
1415
|
+
|
|
1416
|
+
|
|
1417
|
+
|
|
1418
|
+
|
|
1419
|
+
|
|
1420
|
+
|
|
1421
|
+
|
|
1422
|
+
|
|
1423
|
+
|
|
1154
1424
|
* @example
|
|
1155
1425
|
* // Filter elements
|
|
1156
1426
|
* const q = new Queue<number>([1, 2, 3, 4, 5]);
|
|
@@ -1184,6 +1454,30 @@ var _Queue = class _Queue extends LinearBase {
|
|
|
1184
1454
|
|
|
1185
1455
|
|
|
1186
1456
|
|
|
1457
|
+
|
|
1458
|
+
|
|
1459
|
+
|
|
1460
|
+
|
|
1461
|
+
|
|
1462
|
+
|
|
1463
|
+
|
|
1464
|
+
|
|
1465
|
+
|
|
1466
|
+
|
|
1467
|
+
|
|
1468
|
+
|
|
1469
|
+
|
|
1470
|
+
|
|
1471
|
+
|
|
1472
|
+
|
|
1473
|
+
|
|
1474
|
+
|
|
1475
|
+
|
|
1476
|
+
|
|
1477
|
+
|
|
1478
|
+
|
|
1479
|
+
|
|
1480
|
+
|
|
1187
1481
|
* @example
|
|
1188
1482
|
* // Transform elements
|
|
1189
1483
|
* const q = new Queue<number>([1, 2, 3]);
|
|
@@ -1452,7 +1746,7 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
1452
1746
|
if (isMapMode !== void 0) this._isMapMode = isMapMode;
|
|
1453
1747
|
if (isDuplicate !== void 0) this._isDuplicate = isDuplicate;
|
|
1454
1748
|
if (typeof toEntryFn === "function") this._toEntryFn = toEntryFn;
|
|
1455
|
-
else if (toEntryFn)
|
|
1749
|
+
else if (toEntryFn) raise(TypeError, ERR.notAFunction("toEntryFn", "BinaryTree"));
|
|
1456
1750
|
}
|
|
1457
1751
|
if (keysNodesEntriesOrRaws) this.setMany(keysNodesEntriesOrRaws);
|
|
1458
1752
|
}
|
|
@@ -1668,6 +1962,30 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
1668
1962
|
|
|
1669
1963
|
|
|
1670
1964
|
|
|
1965
|
+
|
|
1966
|
+
|
|
1967
|
+
|
|
1968
|
+
|
|
1969
|
+
|
|
1970
|
+
|
|
1971
|
+
|
|
1972
|
+
|
|
1973
|
+
|
|
1974
|
+
|
|
1975
|
+
|
|
1976
|
+
|
|
1977
|
+
|
|
1978
|
+
|
|
1979
|
+
|
|
1980
|
+
|
|
1981
|
+
|
|
1982
|
+
|
|
1983
|
+
|
|
1984
|
+
|
|
1985
|
+
|
|
1986
|
+
|
|
1987
|
+
|
|
1988
|
+
|
|
1671
1989
|
* @example
|
|
1672
1990
|
* // Add a single node
|
|
1673
1991
|
* const tree = new BinaryTree<number>();
|
|
@@ -1698,6 +2016,30 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
1698
2016
|
|
|
1699
2017
|
|
|
1700
2018
|
|
|
2019
|
+
|
|
2020
|
+
|
|
2021
|
+
|
|
2022
|
+
|
|
2023
|
+
|
|
2024
|
+
|
|
2025
|
+
|
|
2026
|
+
|
|
2027
|
+
|
|
2028
|
+
|
|
2029
|
+
|
|
2030
|
+
|
|
2031
|
+
|
|
2032
|
+
|
|
2033
|
+
|
|
2034
|
+
|
|
2035
|
+
|
|
2036
|
+
|
|
2037
|
+
|
|
2038
|
+
|
|
2039
|
+
|
|
2040
|
+
|
|
2041
|
+
|
|
2042
|
+
|
|
1701
2043
|
* @example
|
|
1702
2044
|
* // basic BinaryTree creation and insertion
|
|
1703
2045
|
* // Create a BinaryTree with entries
|
|
@@ -1780,6 +2122,30 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
1780
2122
|
|
|
1781
2123
|
|
|
1782
2124
|
|
|
2125
|
+
|
|
2126
|
+
|
|
2127
|
+
|
|
2128
|
+
|
|
2129
|
+
|
|
2130
|
+
|
|
2131
|
+
|
|
2132
|
+
|
|
2133
|
+
|
|
2134
|
+
|
|
2135
|
+
|
|
2136
|
+
|
|
2137
|
+
|
|
2138
|
+
|
|
2139
|
+
|
|
2140
|
+
|
|
2141
|
+
|
|
2142
|
+
|
|
2143
|
+
|
|
2144
|
+
|
|
2145
|
+
|
|
2146
|
+
|
|
2147
|
+
|
|
2148
|
+
|
|
1783
2149
|
* @example
|
|
1784
2150
|
* // Bulk add
|
|
1785
2151
|
* const tree = new BinaryTree<number>();
|
|
@@ -1798,6 +2164,30 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
1798
2164
|
* @returns An array of booleans indicating the success of each individual `set` operation.
|
|
1799
2165
|
|
|
1800
2166
|
|
|
2167
|
+
|
|
2168
|
+
|
|
2169
|
+
|
|
2170
|
+
|
|
2171
|
+
|
|
2172
|
+
|
|
2173
|
+
|
|
2174
|
+
|
|
2175
|
+
|
|
2176
|
+
|
|
2177
|
+
|
|
2178
|
+
|
|
2179
|
+
|
|
2180
|
+
|
|
2181
|
+
|
|
2182
|
+
|
|
2183
|
+
|
|
2184
|
+
|
|
2185
|
+
|
|
2186
|
+
|
|
2187
|
+
|
|
2188
|
+
|
|
2189
|
+
|
|
2190
|
+
|
|
1801
2191
|
* @example
|
|
1802
2192
|
* // Set multiple entries
|
|
1803
2193
|
* const tree = new BinaryTree<number, string>();
|
|
@@ -1837,6 +2227,30 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
1837
2227
|
|
|
1838
2228
|
|
|
1839
2229
|
|
|
2230
|
+
|
|
2231
|
+
|
|
2232
|
+
|
|
2233
|
+
|
|
2234
|
+
|
|
2235
|
+
|
|
2236
|
+
|
|
2237
|
+
|
|
2238
|
+
|
|
2239
|
+
|
|
2240
|
+
|
|
2241
|
+
|
|
2242
|
+
|
|
2243
|
+
|
|
2244
|
+
|
|
2245
|
+
|
|
2246
|
+
|
|
2247
|
+
|
|
2248
|
+
|
|
2249
|
+
|
|
2250
|
+
|
|
2251
|
+
|
|
2252
|
+
|
|
2253
|
+
|
|
1840
2254
|
* @example
|
|
1841
2255
|
* // Combine trees
|
|
1842
2256
|
* const t1 = new BinaryTree<number>([1, 2]);
|
|
@@ -1875,6 +2289,30 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
1875
2289
|
|
|
1876
2290
|
|
|
1877
2291
|
|
|
2292
|
+
|
|
2293
|
+
|
|
2294
|
+
|
|
2295
|
+
|
|
2296
|
+
|
|
2297
|
+
|
|
2298
|
+
|
|
2299
|
+
|
|
2300
|
+
|
|
2301
|
+
|
|
2302
|
+
|
|
2303
|
+
|
|
2304
|
+
|
|
2305
|
+
|
|
2306
|
+
|
|
2307
|
+
|
|
2308
|
+
|
|
2309
|
+
|
|
2310
|
+
|
|
2311
|
+
|
|
2312
|
+
|
|
2313
|
+
|
|
2314
|
+
|
|
2315
|
+
|
|
1878
2316
|
* @example
|
|
1879
2317
|
* // Remove a node
|
|
1880
2318
|
* const tree = new BinaryTree<number>([1, 2, 3, 4, 5]);
|
|
@@ -1991,6 +2429,30 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
1991
2429
|
|
|
1992
2430
|
|
|
1993
2431
|
|
|
2432
|
+
|
|
2433
|
+
|
|
2434
|
+
|
|
2435
|
+
|
|
2436
|
+
|
|
2437
|
+
|
|
2438
|
+
|
|
2439
|
+
|
|
2440
|
+
|
|
2441
|
+
|
|
2442
|
+
|
|
2443
|
+
|
|
2444
|
+
|
|
2445
|
+
|
|
2446
|
+
|
|
2447
|
+
|
|
2448
|
+
|
|
2449
|
+
|
|
2450
|
+
|
|
2451
|
+
|
|
2452
|
+
|
|
2453
|
+
|
|
2454
|
+
|
|
2455
|
+
|
|
1994
2456
|
* @example
|
|
1995
2457
|
* // Get node by key
|
|
1996
2458
|
* const tree = new BinaryTree<number, string>([[1, 'root'], [2, 'child']]);
|
|
@@ -2025,6 +2487,30 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
2025
2487
|
|
|
2026
2488
|
|
|
2027
2489
|
|
|
2490
|
+
|
|
2491
|
+
|
|
2492
|
+
|
|
2493
|
+
|
|
2494
|
+
|
|
2495
|
+
|
|
2496
|
+
|
|
2497
|
+
|
|
2498
|
+
|
|
2499
|
+
|
|
2500
|
+
|
|
2501
|
+
|
|
2502
|
+
|
|
2503
|
+
|
|
2504
|
+
|
|
2505
|
+
|
|
2506
|
+
|
|
2507
|
+
|
|
2508
|
+
|
|
2509
|
+
|
|
2510
|
+
|
|
2511
|
+
|
|
2512
|
+
|
|
2513
|
+
|
|
2028
2514
|
* @example
|
|
2029
2515
|
* // Retrieve value by key
|
|
2030
2516
|
* const tree = new BinaryTree<number, string>([[1, 'root'], [2, 'left'], [3, 'right']]);
|
|
@@ -2062,6 +2548,30 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
2062
2548
|
|
|
2063
2549
|
|
|
2064
2550
|
|
|
2551
|
+
|
|
2552
|
+
|
|
2553
|
+
|
|
2554
|
+
|
|
2555
|
+
|
|
2556
|
+
|
|
2557
|
+
|
|
2558
|
+
|
|
2559
|
+
|
|
2560
|
+
|
|
2561
|
+
|
|
2562
|
+
|
|
2563
|
+
|
|
2564
|
+
|
|
2565
|
+
|
|
2566
|
+
|
|
2567
|
+
|
|
2568
|
+
|
|
2569
|
+
|
|
2570
|
+
|
|
2571
|
+
|
|
2572
|
+
|
|
2573
|
+
|
|
2574
|
+
|
|
2065
2575
|
* @example
|
|
2066
2576
|
* // Remove all nodes
|
|
2067
2577
|
* const tree = new BinaryTree<number>([1, 2, 3]);
|
|
@@ -2086,6 +2596,30 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
2086
2596
|
|
|
2087
2597
|
|
|
2088
2598
|
|
|
2599
|
+
|
|
2600
|
+
|
|
2601
|
+
|
|
2602
|
+
|
|
2603
|
+
|
|
2604
|
+
|
|
2605
|
+
|
|
2606
|
+
|
|
2607
|
+
|
|
2608
|
+
|
|
2609
|
+
|
|
2610
|
+
|
|
2611
|
+
|
|
2612
|
+
|
|
2613
|
+
|
|
2614
|
+
|
|
2615
|
+
|
|
2616
|
+
|
|
2617
|
+
|
|
2618
|
+
|
|
2619
|
+
|
|
2620
|
+
|
|
2621
|
+
|
|
2622
|
+
|
|
2089
2623
|
* @example
|
|
2090
2624
|
* // Check empty
|
|
2091
2625
|
* console.log(new BinaryTree().isEmpty()); // true;
|
|
@@ -2119,6 +2653,30 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
2119
2653
|
|
|
2120
2654
|
|
|
2121
2655
|
|
|
2656
|
+
|
|
2657
|
+
|
|
2658
|
+
|
|
2659
|
+
|
|
2660
|
+
|
|
2661
|
+
|
|
2662
|
+
|
|
2663
|
+
|
|
2664
|
+
|
|
2665
|
+
|
|
2666
|
+
|
|
2667
|
+
|
|
2668
|
+
|
|
2669
|
+
|
|
2670
|
+
|
|
2671
|
+
|
|
2672
|
+
|
|
2673
|
+
|
|
2674
|
+
|
|
2675
|
+
|
|
2676
|
+
|
|
2677
|
+
|
|
2678
|
+
|
|
2679
|
+
|
|
2122
2680
|
* @example
|
|
2123
2681
|
* // Check BST property
|
|
2124
2682
|
* const tree = new BinaryTree<number>([1, 2, 3]);
|
|
@@ -2179,6 +2737,30 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
2179
2737
|
|
|
2180
2738
|
|
|
2181
2739
|
|
|
2740
|
+
|
|
2741
|
+
|
|
2742
|
+
|
|
2743
|
+
|
|
2744
|
+
|
|
2745
|
+
|
|
2746
|
+
|
|
2747
|
+
|
|
2748
|
+
|
|
2749
|
+
|
|
2750
|
+
|
|
2751
|
+
|
|
2752
|
+
|
|
2753
|
+
|
|
2754
|
+
|
|
2755
|
+
|
|
2756
|
+
|
|
2757
|
+
|
|
2758
|
+
|
|
2759
|
+
|
|
2760
|
+
|
|
2761
|
+
|
|
2762
|
+
|
|
2763
|
+
|
|
2182
2764
|
* @example
|
|
2183
2765
|
* // Get depth of a node
|
|
2184
2766
|
* const tree = new BinaryTree<number>([1, 2, 3, 4, 5]);
|
|
@@ -2216,6 +2798,30 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
2216
2798
|
|
|
2217
2799
|
|
|
2218
2800
|
|
|
2801
|
+
|
|
2802
|
+
|
|
2803
|
+
|
|
2804
|
+
|
|
2805
|
+
|
|
2806
|
+
|
|
2807
|
+
|
|
2808
|
+
|
|
2809
|
+
|
|
2810
|
+
|
|
2811
|
+
|
|
2812
|
+
|
|
2813
|
+
|
|
2814
|
+
|
|
2815
|
+
|
|
2816
|
+
|
|
2817
|
+
|
|
2818
|
+
|
|
2819
|
+
|
|
2820
|
+
|
|
2821
|
+
|
|
2822
|
+
|
|
2823
|
+
|
|
2824
|
+
|
|
2219
2825
|
* @example
|
|
2220
2826
|
* // Get tree height
|
|
2221
2827
|
* const tree = new BinaryTree<number>([1, 2, 3, 4, 5]);
|
|
@@ -2669,6 +3275,30 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
2669
3275
|
|
|
2670
3276
|
|
|
2671
3277
|
|
|
3278
|
+
|
|
3279
|
+
|
|
3280
|
+
|
|
3281
|
+
|
|
3282
|
+
|
|
3283
|
+
|
|
3284
|
+
|
|
3285
|
+
|
|
3286
|
+
|
|
3287
|
+
|
|
3288
|
+
|
|
3289
|
+
|
|
3290
|
+
|
|
3291
|
+
|
|
3292
|
+
|
|
3293
|
+
|
|
3294
|
+
|
|
3295
|
+
|
|
3296
|
+
|
|
3297
|
+
|
|
3298
|
+
|
|
3299
|
+
|
|
3300
|
+
|
|
3301
|
+
|
|
2672
3302
|
* @example
|
|
2673
3303
|
* // Deep copy
|
|
2674
3304
|
* const tree = new BinaryTree<number>([1, 2, 3]);
|
|
@@ -2697,6 +3327,30 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
2697
3327
|
|
|
2698
3328
|
|
|
2699
3329
|
|
|
3330
|
+
|
|
3331
|
+
|
|
3332
|
+
|
|
3333
|
+
|
|
3334
|
+
|
|
3335
|
+
|
|
3336
|
+
|
|
3337
|
+
|
|
3338
|
+
|
|
3339
|
+
|
|
3340
|
+
|
|
3341
|
+
|
|
3342
|
+
|
|
3343
|
+
|
|
3344
|
+
|
|
3345
|
+
|
|
3346
|
+
|
|
3347
|
+
|
|
3348
|
+
|
|
3349
|
+
|
|
3350
|
+
|
|
3351
|
+
|
|
3352
|
+
|
|
3353
|
+
|
|
2700
3354
|
* @example
|
|
2701
3355
|
* // Filter nodes by condition
|
|
2702
3356
|
* const tree = new BinaryTree<number>([1, 2, 3, 4]);
|
|
@@ -2729,6 +3383,30 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
2729
3383
|
|
|
2730
3384
|
|
|
2731
3385
|
|
|
3386
|
+
|
|
3387
|
+
|
|
3388
|
+
|
|
3389
|
+
|
|
3390
|
+
|
|
3391
|
+
|
|
3392
|
+
|
|
3393
|
+
|
|
3394
|
+
|
|
3395
|
+
|
|
3396
|
+
|
|
3397
|
+
|
|
3398
|
+
|
|
3399
|
+
|
|
3400
|
+
|
|
3401
|
+
|
|
3402
|
+
|
|
3403
|
+
|
|
3404
|
+
|
|
3405
|
+
|
|
3406
|
+
|
|
3407
|
+
|
|
3408
|
+
|
|
3409
|
+
|
|
2732
3410
|
* @example
|
|
2733
3411
|
* // Transform to new tree
|
|
2734
3412
|
* const tree = new BinaryTree<number, number>([[1, 10], [2, 20]]);
|
|
@@ -2786,6 +3464,30 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
2786
3464
|
|
|
2787
3465
|
|
|
2788
3466
|
|
|
3467
|
+
|
|
3468
|
+
|
|
3469
|
+
|
|
3470
|
+
|
|
3471
|
+
|
|
3472
|
+
|
|
3473
|
+
|
|
3474
|
+
|
|
3475
|
+
|
|
3476
|
+
|
|
3477
|
+
|
|
3478
|
+
|
|
3479
|
+
|
|
3480
|
+
|
|
3481
|
+
|
|
3482
|
+
|
|
3483
|
+
|
|
3484
|
+
|
|
3485
|
+
|
|
3486
|
+
|
|
3487
|
+
|
|
3488
|
+
|
|
3489
|
+
|
|
3490
|
+
|
|
2789
3491
|
* @example
|
|
2790
3492
|
* // Display tree
|
|
2791
3493
|
* const tree = new BinaryTree<number>([1, 2, 3]);
|
|
@@ -3404,6 +4106,7 @@ var _BST = class _BST extends BinaryTree {
|
|
|
3404
4106
|
constructor(keysNodesEntriesOrRaws = [], options) {
|
|
3405
4107
|
super([], options);
|
|
3406
4108
|
__publicField(this, "_root");
|
|
4109
|
+
__publicField(this, "_enableOrderStatistic", false);
|
|
3407
4110
|
/**
|
|
3408
4111
|
* The comparator function used to determine the order of keys in the tree.
|
|
3409
4112
|
|
|
@@ -3416,6 +4119,9 @@ var _BST = class _BST extends BinaryTree {
|
|
|
3416
4119
|
} else {
|
|
3417
4120
|
this._comparator = this._createDefaultComparator();
|
|
3418
4121
|
}
|
|
4122
|
+
if (options.enableOrderStatistic) {
|
|
4123
|
+
this._enableOrderStatistic = true;
|
|
4124
|
+
}
|
|
3419
4125
|
} else {
|
|
3420
4126
|
this._comparator = this._createDefaultComparator();
|
|
3421
4127
|
}
|
|
@@ -3550,6 +4256,54 @@ var _BST = class _BST extends BinaryTree {
|
|
|
3550
4256
|
|
|
3551
4257
|
|
|
3552
4258
|
|
|
4259
|
+
|
|
4260
|
+
|
|
4261
|
+
|
|
4262
|
+
|
|
4263
|
+
|
|
4264
|
+
|
|
4265
|
+
|
|
4266
|
+
|
|
4267
|
+
|
|
4268
|
+
|
|
4269
|
+
|
|
4270
|
+
|
|
4271
|
+
|
|
4272
|
+
|
|
4273
|
+
|
|
4274
|
+
|
|
4275
|
+
|
|
4276
|
+
|
|
4277
|
+
|
|
4278
|
+
|
|
4279
|
+
|
|
4280
|
+
|
|
4281
|
+
|
|
4282
|
+
|
|
4283
|
+
|
|
4284
|
+
|
|
4285
|
+
|
|
4286
|
+
|
|
4287
|
+
|
|
4288
|
+
|
|
4289
|
+
|
|
4290
|
+
|
|
4291
|
+
|
|
4292
|
+
|
|
4293
|
+
|
|
4294
|
+
|
|
4295
|
+
|
|
4296
|
+
|
|
4297
|
+
|
|
4298
|
+
|
|
4299
|
+
|
|
4300
|
+
|
|
4301
|
+
|
|
4302
|
+
|
|
4303
|
+
|
|
4304
|
+
|
|
4305
|
+
|
|
4306
|
+
|
|
3553
4307
|
* @example
|
|
3554
4308
|
* // Get node object by key
|
|
3555
4309
|
* const bst = new BST<number, string>([[5, 'root'], [3, 'left'], [7, 'right']]);
|
|
@@ -3705,6 +4459,85 @@ var _BST = class _BST extends BinaryTree {
|
|
|
3705
4459
|
const searchRange = range instanceof Range ? range : new Range(range[0], range[1]);
|
|
3706
4460
|
return this.search(searchRange, false, callback, startNode, iterationType);
|
|
3707
4461
|
}
|
|
4462
|
+
getByRank(k, callback = this._DEFAULT_NODE_CALLBACK, iterationType = this.iterationType) {
|
|
4463
|
+
if (!this._enableOrderStatistic) {
|
|
4464
|
+
raise(Error, ERR.orderStatisticNotEnabled("getByRank"));
|
|
4465
|
+
}
|
|
4466
|
+
if (k < 0 || k >= this._size) return void 0;
|
|
4467
|
+
let actualCallback = void 0;
|
|
4468
|
+
let actualIterationType = this.iterationType;
|
|
4469
|
+
if (typeof callback === "string") {
|
|
4470
|
+
actualIterationType = callback;
|
|
4471
|
+
} else if (callback) {
|
|
4472
|
+
actualCallback = callback;
|
|
4473
|
+
if (iterationType) {
|
|
4474
|
+
actualIterationType = iterationType;
|
|
4475
|
+
}
|
|
4476
|
+
}
|
|
4477
|
+
const node = actualIterationType === "RECURSIVE" ? this._getByRankRecursive(this._root, k) : this._getByRankIterative(this._root, k);
|
|
4478
|
+
if (!node) return void 0;
|
|
4479
|
+
return actualCallback ? actualCallback(node) : node.key;
|
|
4480
|
+
}
|
|
4481
|
+
getRank(keyNodeEntryOrPredicate, iterationType = this.iterationType) {
|
|
4482
|
+
var _a;
|
|
4483
|
+
if (!this._enableOrderStatistic) {
|
|
4484
|
+
raise(Error, ERR.orderStatisticNotEnabled("getRank"));
|
|
4485
|
+
}
|
|
4486
|
+
if (!this._root || this._size === 0) return -1;
|
|
4487
|
+
let actualIterationType = this.iterationType;
|
|
4488
|
+
if (iterationType) actualIterationType = iterationType;
|
|
4489
|
+
let key;
|
|
4490
|
+
if (typeof keyNodeEntryOrPredicate === "function") {
|
|
4491
|
+
const results = this.search(keyNodeEntryOrPredicate, true);
|
|
4492
|
+
if (results.length === 0 || results[0] === void 0) return -1;
|
|
4493
|
+
key = results[0];
|
|
4494
|
+
} else if (keyNodeEntryOrPredicate === null || keyNodeEntryOrPredicate === void 0) {
|
|
4495
|
+
return -1;
|
|
4496
|
+
} else if (this.isNode(keyNodeEntryOrPredicate)) {
|
|
4497
|
+
key = keyNodeEntryOrPredicate.key;
|
|
4498
|
+
} else if (Array.isArray(keyNodeEntryOrPredicate)) {
|
|
4499
|
+
key = (_a = keyNodeEntryOrPredicate[0]) != null ? _a : void 0;
|
|
4500
|
+
if (key === void 0 || key === null) return -1;
|
|
4501
|
+
} else {
|
|
4502
|
+
key = keyNodeEntryOrPredicate;
|
|
4503
|
+
}
|
|
4504
|
+
if (key === void 0) return -1;
|
|
4505
|
+
return actualIterationType === "RECURSIVE" ? this._getRankRecursive(this._root, key) : this._getRankIterative(this._root, key);
|
|
4506
|
+
}
|
|
4507
|
+
rangeByRank(start, end, callback = this._DEFAULT_NODE_CALLBACK, iterationType = this.iterationType) {
|
|
4508
|
+
if (!this._enableOrderStatistic) {
|
|
4509
|
+
raise(Error, ERR.orderStatisticNotEnabled("rangeByRank"));
|
|
4510
|
+
}
|
|
4511
|
+
if (this._size === 0) return [];
|
|
4512
|
+
const lo = Math.max(0, start);
|
|
4513
|
+
const hi = Math.min(this._size - 1, end);
|
|
4514
|
+
if (lo > hi) return [];
|
|
4515
|
+
let actualCallback = void 0;
|
|
4516
|
+
let actualIterationType = this.iterationType;
|
|
4517
|
+
if (typeof callback === "string") {
|
|
4518
|
+
actualIterationType = callback;
|
|
4519
|
+
} else if (callback) {
|
|
4520
|
+
actualCallback = callback;
|
|
4521
|
+
if (iterationType) {
|
|
4522
|
+
actualIterationType = iterationType;
|
|
4523
|
+
}
|
|
4524
|
+
}
|
|
4525
|
+
const results = [];
|
|
4526
|
+
const count = hi - lo + 1;
|
|
4527
|
+
const startNode = actualIterationType === "RECURSIVE" ? this._getByRankRecursive(this._root, lo) : this._getByRankIterative(this._root, lo);
|
|
4528
|
+
if (!startNode) return [];
|
|
4529
|
+
let collected = 0;
|
|
4530
|
+
const cb = actualCallback != null ? actualCallback : this._DEFAULT_NODE_CALLBACK;
|
|
4531
|
+
let current = startNode;
|
|
4532
|
+
while (current && collected < count) {
|
|
4533
|
+
results.push(cb(current));
|
|
4534
|
+
collected++;
|
|
4535
|
+
if (collected < count) {
|
|
4536
|
+
current = this._next(current);
|
|
4537
|
+
}
|
|
4538
|
+
}
|
|
4539
|
+
return results;
|
|
4540
|
+
}
|
|
3708
4541
|
/**
|
|
3709
4542
|
* Adds a new node to the BST based on key comparison.
|
|
3710
4543
|
* @remarks Time O(log N), where H is tree height. O(N) worst-case (unbalanced tree), O(log N) average. Space O(1).
|
|
@@ -3732,6 +4565,78 @@ var _BST = class _BST extends BinaryTree {
|
|
|
3732
4565
|
|
|
3733
4566
|
|
|
3734
4567
|
|
|
4568
|
+
|
|
4569
|
+
|
|
4570
|
+
|
|
4571
|
+
|
|
4572
|
+
|
|
4573
|
+
|
|
4574
|
+
|
|
4575
|
+
|
|
4576
|
+
|
|
4577
|
+
|
|
4578
|
+
|
|
4579
|
+
|
|
4580
|
+
|
|
4581
|
+
|
|
4582
|
+
|
|
4583
|
+
|
|
4584
|
+
|
|
4585
|
+
|
|
4586
|
+
|
|
4587
|
+
|
|
4588
|
+
|
|
4589
|
+
|
|
4590
|
+
|
|
4591
|
+
|
|
4592
|
+
|
|
4593
|
+
|
|
4594
|
+
|
|
4595
|
+
|
|
4596
|
+
|
|
4597
|
+
|
|
4598
|
+
|
|
4599
|
+
|
|
4600
|
+
|
|
4601
|
+
|
|
4602
|
+
|
|
4603
|
+
|
|
4604
|
+
|
|
4605
|
+
|
|
4606
|
+
|
|
4607
|
+
|
|
4608
|
+
|
|
4609
|
+
|
|
4610
|
+
|
|
4611
|
+
|
|
4612
|
+
|
|
4613
|
+
|
|
4614
|
+
|
|
4615
|
+
|
|
4616
|
+
|
|
4617
|
+
|
|
4618
|
+
|
|
4619
|
+
|
|
4620
|
+
|
|
4621
|
+
|
|
4622
|
+
|
|
4623
|
+
|
|
4624
|
+
|
|
4625
|
+
|
|
4626
|
+
|
|
4627
|
+
|
|
4628
|
+
|
|
4629
|
+
|
|
4630
|
+
|
|
4631
|
+
|
|
4632
|
+
|
|
4633
|
+
|
|
4634
|
+
|
|
4635
|
+
|
|
4636
|
+
|
|
4637
|
+
|
|
4638
|
+
|
|
4639
|
+
|
|
3735
4640
|
|
|
3736
4641
|
|
|
3737
4642
|
|
|
@@ -3751,6 +4656,7 @@ var _BST = class _BST extends BinaryTree {
|
|
|
3751
4656
|
this._setRoot(newNode);
|
|
3752
4657
|
if (this._isMapMode && this.isRealNode(newNode)) this._store.set(newNode.key, newNode);
|
|
3753
4658
|
this._size++;
|
|
4659
|
+
this._updateCount(newNode);
|
|
3754
4660
|
return true;
|
|
3755
4661
|
}
|
|
3756
4662
|
let current = this._root;
|
|
@@ -3764,6 +4670,7 @@ var _BST = class _BST extends BinaryTree {
|
|
|
3764
4670
|
current.left = newNode;
|
|
3765
4671
|
if (this._isMapMode && this.isRealNode(newNode)) this._store.set(newNode.key, newNode);
|
|
3766
4672
|
this._size++;
|
|
4673
|
+
this._updateCountAlongPath(newNode);
|
|
3767
4674
|
return true;
|
|
3768
4675
|
}
|
|
3769
4676
|
if (current.left !== null) current = current.left;
|
|
@@ -3772,6 +4679,7 @@ var _BST = class _BST extends BinaryTree {
|
|
|
3772
4679
|
current.right = newNode;
|
|
3773
4680
|
if (this._isMapMode && this.isRealNode(newNode)) this._store.set(newNode.key, newNode);
|
|
3774
4681
|
this._size++;
|
|
4682
|
+
this._updateCountAlongPath(newNode);
|
|
3775
4683
|
return true;
|
|
3776
4684
|
}
|
|
3777
4685
|
if (current.right !== null) current = current.right;
|
|
@@ -3801,6 +4709,54 @@ var _BST = class _BST extends BinaryTree {
|
|
|
3801
4709
|
|
|
3802
4710
|
|
|
3803
4711
|
|
|
4712
|
+
|
|
4713
|
+
|
|
4714
|
+
|
|
4715
|
+
|
|
4716
|
+
|
|
4717
|
+
|
|
4718
|
+
|
|
4719
|
+
|
|
4720
|
+
|
|
4721
|
+
|
|
4722
|
+
|
|
4723
|
+
|
|
4724
|
+
|
|
4725
|
+
|
|
4726
|
+
|
|
4727
|
+
|
|
4728
|
+
|
|
4729
|
+
|
|
4730
|
+
|
|
4731
|
+
|
|
4732
|
+
|
|
4733
|
+
|
|
4734
|
+
|
|
4735
|
+
|
|
4736
|
+
|
|
4737
|
+
|
|
4738
|
+
|
|
4739
|
+
|
|
4740
|
+
|
|
4741
|
+
|
|
4742
|
+
|
|
4743
|
+
|
|
4744
|
+
|
|
4745
|
+
|
|
4746
|
+
|
|
4747
|
+
|
|
4748
|
+
|
|
4749
|
+
|
|
4750
|
+
|
|
4751
|
+
|
|
4752
|
+
|
|
4753
|
+
|
|
4754
|
+
|
|
4755
|
+
|
|
4756
|
+
|
|
4757
|
+
|
|
4758
|
+
|
|
4759
|
+
|
|
3804
4760
|
* @example
|
|
3805
4761
|
* // Set multiple key-value pairs
|
|
3806
4762
|
* const bst = new BST<number, string>();
|
|
@@ -4064,6 +5020,30 @@ var _BST = class _BST extends BinaryTree {
|
|
|
4064
5020
|
|
|
4065
5021
|
|
|
4066
5022
|
|
|
5023
|
+
|
|
5024
|
+
|
|
5025
|
+
|
|
5026
|
+
|
|
5027
|
+
|
|
5028
|
+
|
|
5029
|
+
|
|
5030
|
+
|
|
5031
|
+
|
|
5032
|
+
|
|
5033
|
+
|
|
5034
|
+
|
|
5035
|
+
|
|
5036
|
+
|
|
5037
|
+
|
|
5038
|
+
|
|
5039
|
+
|
|
5040
|
+
|
|
5041
|
+
|
|
5042
|
+
|
|
5043
|
+
|
|
5044
|
+
|
|
5045
|
+
|
|
5046
|
+
|
|
4067
5047
|
* @example
|
|
4068
5048
|
* // Rebalance the tree
|
|
4069
5049
|
* const bst = new BST<number>();
|
|
@@ -4109,6 +5089,30 @@ var _BST = class _BST extends BinaryTree {
|
|
|
4109
5089
|
|
|
4110
5090
|
|
|
4111
5091
|
|
|
5092
|
+
|
|
5093
|
+
|
|
5094
|
+
|
|
5095
|
+
|
|
5096
|
+
|
|
5097
|
+
|
|
5098
|
+
|
|
5099
|
+
|
|
5100
|
+
|
|
5101
|
+
|
|
5102
|
+
|
|
5103
|
+
|
|
5104
|
+
|
|
5105
|
+
|
|
5106
|
+
|
|
5107
|
+
|
|
5108
|
+
|
|
5109
|
+
|
|
5110
|
+
|
|
5111
|
+
|
|
5112
|
+
|
|
5113
|
+
|
|
5114
|
+
|
|
5115
|
+
|
|
4112
5116
|
* @example
|
|
4113
5117
|
* // Check if tree is height-balanced
|
|
4114
5118
|
* const bst = new BST<number>([3, 1, 5, 2, 4]);
|
|
@@ -4183,6 +5187,54 @@ var _BST = class _BST extends BinaryTree {
|
|
|
4183
5187
|
|
|
4184
5188
|
|
|
4185
5189
|
|
|
5190
|
+
|
|
5191
|
+
|
|
5192
|
+
|
|
5193
|
+
|
|
5194
|
+
|
|
5195
|
+
|
|
5196
|
+
|
|
5197
|
+
|
|
5198
|
+
|
|
5199
|
+
|
|
5200
|
+
|
|
5201
|
+
|
|
5202
|
+
|
|
5203
|
+
|
|
5204
|
+
|
|
5205
|
+
|
|
5206
|
+
|
|
5207
|
+
|
|
5208
|
+
|
|
5209
|
+
|
|
5210
|
+
|
|
5211
|
+
|
|
5212
|
+
|
|
5213
|
+
|
|
5214
|
+
|
|
5215
|
+
|
|
5216
|
+
|
|
5217
|
+
|
|
5218
|
+
|
|
5219
|
+
|
|
5220
|
+
|
|
5221
|
+
|
|
5222
|
+
|
|
5223
|
+
|
|
5224
|
+
|
|
5225
|
+
|
|
5226
|
+
|
|
5227
|
+
|
|
5228
|
+
|
|
5229
|
+
|
|
5230
|
+
|
|
5231
|
+
|
|
5232
|
+
|
|
5233
|
+
|
|
5234
|
+
|
|
5235
|
+
|
|
5236
|
+
|
|
5237
|
+
|
|
4186
5238
|
* @example
|
|
4187
5239
|
* // Transform to new tree
|
|
4188
5240
|
* const bst = new BST<number, number>([[1, 10], [2, 20], [3, 30]]);
|
|
@@ -4257,13 +5309,11 @@ var _BST = class _BST extends BinaryTree {
|
|
|
4257
5309
|
if (a instanceof Date && b instanceof Date) {
|
|
4258
5310
|
const ta = a.getTime();
|
|
4259
5311
|
const tb = b.getTime();
|
|
4260
|
-
if (Number.isNaN(ta) || Number.isNaN(tb))
|
|
5312
|
+
if (Number.isNaN(ta) || Number.isNaN(tb)) raise(TypeError, ERR.invalidDate("BST"));
|
|
4261
5313
|
return ta > tb ? 1 : ta < tb ? -1 : 0;
|
|
4262
5314
|
}
|
|
4263
5315
|
if (typeof a === "object" || typeof b === "object") {
|
|
4264
|
-
|
|
4265
|
-
ERR.comparatorRequired("BST")
|
|
4266
|
-
);
|
|
5316
|
+
raise(TypeError, ERR.comparatorRequired("BST"));
|
|
4267
5317
|
}
|
|
4268
5318
|
return 0;
|
|
4269
5319
|
};
|
|
@@ -4585,7 +5635,8 @@ var _BST = class _BST extends BinaryTree {
|
|
|
4585
5635
|
_snapshotOptions() {
|
|
4586
5636
|
return {
|
|
4587
5637
|
...super._snapshotOptions(),
|
|
4588
|
-
comparator: this._comparator
|
|
5638
|
+
comparator: this._comparator,
|
|
5639
|
+
enableOrderStatistic: this._enableOrderStatistic
|
|
4589
5640
|
};
|
|
4590
5641
|
}
|
|
4591
5642
|
/**
|
|
@@ -4607,6 +5658,113 @@ var _BST = class _BST extends BinaryTree {
|
|
|
4607
5658
|
*
|
|
4608
5659
|
* @param v - The node to set as root.
|
|
4609
5660
|
*/
|
|
5661
|
+
/**
|
|
5662
|
+
* (Protected) Recalculates the subtree count for a single node.
|
|
5663
|
+
* @remarks Time O(1). Only active when enableOrderStatistic is true.
|
|
5664
|
+
*/
|
|
5665
|
+
_updateCount(node) {
|
|
5666
|
+
if (!this._enableOrderStatistic) return;
|
|
5667
|
+
node._count = 1 + (this.isRealNode(node.left) ? node.left._count : 0) + (this.isRealNode(node.right) ? node.right._count : 0);
|
|
5668
|
+
}
|
|
5669
|
+
/**
|
|
5670
|
+
* (Protected) Updates subtree counts from a node up to the root.
|
|
5671
|
+
* @remarks Time O(log n). Only active when enableOrderStatistic is true.
|
|
5672
|
+
*/
|
|
5673
|
+
_updateCountAlongPath(node) {
|
|
5674
|
+
if (!this._enableOrderStatistic) return;
|
|
5675
|
+
let current = node;
|
|
5676
|
+
while (current) {
|
|
5677
|
+
this._updateCount(current);
|
|
5678
|
+
current = current.parent;
|
|
5679
|
+
}
|
|
5680
|
+
}
|
|
5681
|
+
/**
|
|
5682
|
+
* (Protected) Finds the node at position k in tree order (iterative).
|
|
5683
|
+
* @remarks Time O(log n), Space O(1)
|
|
5684
|
+
*/
|
|
5685
|
+
_getByRankIterative(node, k) {
|
|
5686
|
+
let current = node;
|
|
5687
|
+
let remaining = k;
|
|
5688
|
+
while (current) {
|
|
5689
|
+
const leftCount = this.isRealNode(current.left) ? current.left._count : 0;
|
|
5690
|
+
if (remaining < leftCount) {
|
|
5691
|
+
current = current.left;
|
|
5692
|
+
} else if (remaining === leftCount) {
|
|
5693
|
+
return current;
|
|
5694
|
+
} else {
|
|
5695
|
+
remaining = remaining - leftCount - 1;
|
|
5696
|
+
current = current.right;
|
|
5697
|
+
}
|
|
5698
|
+
}
|
|
5699
|
+
return void 0;
|
|
5700
|
+
}
|
|
5701
|
+
/**
|
|
5702
|
+
* (Protected) Finds the node at position k in tree order (recursive).
|
|
5703
|
+
* @remarks Time O(log n), Space O(log n) call stack
|
|
5704
|
+
*/
|
|
5705
|
+
_getByRankRecursive(node, k) {
|
|
5706
|
+
if (!node) return void 0;
|
|
5707
|
+
const leftCount = this.isRealNode(node.left) ? node.left._count : 0;
|
|
5708
|
+
if (k < leftCount) return this._getByRankRecursive(node.left, k);
|
|
5709
|
+
if (k === leftCount) return node;
|
|
5710
|
+
return this._getByRankRecursive(node.right, k - leftCount - 1);
|
|
5711
|
+
}
|
|
5712
|
+
/**
|
|
5713
|
+
* (Protected) Computes the rank of a key iteratively.
|
|
5714
|
+
* @remarks Time O(log n), Space O(1)
|
|
5715
|
+
*/
|
|
5716
|
+
_getRankIterative(node, key) {
|
|
5717
|
+
let rank = 0;
|
|
5718
|
+
let current = node;
|
|
5719
|
+
while (this.isRealNode(current)) {
|
|
5720
|
+
const cmp = this._compare(current.key, key);
|
|
5721
|
+
if (cmp > 0) {
|
|
5722
|
+
current = current.left;
|
|
5723
|
+
} else if (cmp < 0) {
|
|
5724
|
+
rank += (this.isRealNode(current.left) ? current.left._count : 0) + 1;
|
|
5725
|
+
current = current.right;
|
|
5726
|
+
} else {
|
|
5727
|
+
rank += this.isRealNode(current.left) ? current.left._count : 0;
|
|
5728
|
+
return rank;
|
|
5729
|
+
}
|
|
5730
|
+
}
|
|
5731
|
+
return rank;
|
|
5732
|
+
}
|
|
5733
|
+
/**
|
|
5734
|
+
* (Protected) Computes the rank of a key recursively.
|
|
5735
|
+
* @remarks Time O(log n), Space O(log n) call stack
|
|
5736
|
+
*/
|
|
5737
|
+
_getRankRecursive(node, key) {
|
|
5738
|
+
if (!node) return 0;
|
|
5739
|
+
const cmp = this._compare(node.key, key);
|
|
5740
|
+
if (cmp > 0) {
|
|
5741
|
+
return this._getRankRecursive(node.left, key);
|
|
5742
|
+
} else if (cmp < 0) {
|
|
5743
|
+
return (this.isRealNode(node.left) ? node.left._count : 0) + 1 + this._getRankRecursive(node.right, key);
|
|
5744
|
+
} else {
|
|
5745
|
+
return this.isRealNode(node.left) ? node.left._count : 0;
|
|
5746
|
+
}
|
|
5747
|
+
}
|
|
5748
|
+
/**
|
|
5749
|
+
* (Protected) Finds the in-order successor of a node.
|
|
5750
|
+
* @remarks Time O(log n), Space O(1)
|
|
5751
|
+
*/
|
|
5752
|
+
_next(node) {
|
|
5753
|
+
if (this.isRealNode(node.right)) {
|
|
5754
|
+
let current2 = node.right;
|
|
5755
|
+
while (this.isRealNode(current2.left)) {
|
|
5756
|
+
current2 = current2.left;
|
|
5757
|
+
}
|
|
5758
|
+
return current2;
|
|
5759
|
+
}
|
|
5760
|
+
let current = node;
|
|
5761
|
+
let parent = current.parent;
|
|
5762
|
+
while (parent && current === parent.right) {
|
|
5763
|
+
current = parent;
|
|
5764
|
+
parent = parent.parent;
|
|
5765
|
+
}
|
|
5766
|
+
return parent;
|
|
5767
|
+
}
|
|
4610
5768
|
_setRoot(v) {
|
|
4611
5769
|
if (v) v.parent = void 0;
|
|
4612
5770
|
this._root = v;
|
|
@@ -4653,21 +5811,28 @@ var _BST = class _BST extends BinaryTree {
|
|
|
4653
5811
|
while (x.left !== void 0 && x.left !== null) x = x.left;
|
|
4654
5812
|
return x;
|
|
4655
5813
|
}, "minNode");
|
|
5814
|
+
let countUpdateStart;
|
|
4656
5815
|
if (node.left === void 0) {
|
|
5816
|
+
countUpdateStart = node.parent;
|
|
4657
5817
|
transplant(node, node.right);
|
|
4658
5818
|
} else if (node.right === void 0) {
|
|
5819
|
+
countUpdateStart = node.parent;
|
|
4659
5820
|
transplant(node, node.left);
|
|
4660
5821
|
} else {
|
|
4661
5822
|
const succ = minNode(node.right);
|
|
4662
5823
|
if (succ.parent !== node) {
|
|
5824
|
+
countUpdateStart = succ.parent;
|
|
4663
5825
|
transplant(succ, succ.right);
|
|
4664
5826
|
succ.right = node.right;
|
|
4665
5827
|
if (succ.right) succ.right.parent = succ;
|
|
5828
|
+
} else {
|
|
5829
|
+
countUpdateStart = succ;
|
|
4666
5830
|
}
|
|
4667
5831
|
transplant(node, succ);
|
|
4668
5832
|
succ.left = node.left;
|
|
4669
5833
|
if (succ.left) succ.left.parent = succ;
|
|
4670
5834
|
}
|
|
5835
|
+
this._updateCountAlongPath(countUpdateStart);
|
|
4671
5836
|
this._size = Math.max(0, this._size - 1);
|
|
4672
5837
|
return true;
|
|
4673
5838
|
}
|
|
@@ -4689,5 +5854,6 @@ exports.BinaryTreeNode = BinaryTreeNode;
|
|
|
4689
5854
|
exports.DFSOperation = DFSOperation;
|
|
4690
5855
|
exports.ERR = ERR;
|
|
4691
5856
|
exports.Range = Range;
|
|
5857
|
+
exports.raise = raise;
|
|
4692
5858
|
//# sourceMappingURL=index.cjs.map
|
|
4693
5859
|
//# sourceMappingURL=index.cjs.map
|