binary-tree-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 +771 -68
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs-legacy/index.cjs +771 -68
- package/dist/cjs-legacy/index.cjs.map +1 -1
- package/dist/esm/index.mjs +771 -69
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm-legacy/index.mjs +771 -69
- 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/binary-tree-typed.js +773 -71
- package/dist/umd/binary-tree-typed.js.map +1 -1
- package/dist/umd/binary-tree-typed.min.js +5 -5
- package/dist/umd/binary-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/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
|
@@ -27,7 +27,8 @@ var binaryTreeTyped = (() => {
|
|
|
27
27
|
BinaryTreeNode: () => BinaryTreeNode,
|
|
28
28
|
DFSOperation: () => DFSOperation,
|
|
29
29
|
ERR: () => ERR,
|
|
30
|
-
Range: () => Range
|
|
30
|
+
Range: () => Range,
|
|
31
|
+
raise: () => raise
|
|
31
32
|
});
|
|
32
33
|
|
|
33
34
|
// src/utils/utils.ts
|
|
@@ -81,6 +82,57 @@ var binaryTreeTyped = (() => {
|
|
|
81
82
|
return (...args) => trampoline(fn(...args));
|
|
82
83
|
}
|
|
83
84
|
|
|
85
|
+
// src/common/error.ts
|
|
86
|
+
function raise(ErrorClass, message) {
|
|
87
|
+
throw new ErrorClass(message);
|
|
88
|
+
}
|
|
89
|
+
var ERR = {
|
|
90
|
+
// Range / index
|
|
91
|
+
indexOutOfRange: (index, min, max, ctx) => `${ctx ? ctx + ": " : ""}Index ${index} is out of range [${min}, ${max}].`,
|
|
92
|
+
invalidIndex: (ctx) => `${ctx ? ctx + ": " : ""}Index must be an integer.`,
|
|
93
|
+
// Type / argument
|
|
94
|
+
invalidArgument: (reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`,
|
|
95
|
+
comparatorRequired: (ctx) => `${ctx ? ctx + ": " : ""}Comparator is required for non-number/non-string/non-Date keys.`,
|
|
96
|
+
invalidKey: (reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`,
|
|
97
|
+
notAFunction: (name, ctx) => `${ctx ? ctx + ": " : ""}${name} must be a function.`,
|
|
98
|
+
invalidEntry: (ctx) => `${ctx ? ctx + ": " : ""}Each entry must be a [key, value] tuple.`,
|
|
99
|
+
invalidNaN: (ctx) => `${ctx ? ctx + ": " : ""}NaN is not a valid key.`,
|
|
100
|
+
invalidDate: (ctx) => `${ctx ? ctx + ": " : ""}Invalid Date key.`,
|
|
101
|
+
reduceEmpty: (ctx) => `${ctx ? ctx + ": " : ""}Reduce of empty structure with no initial value.`,
|
|
102
|
+
callbackReturnType: (expected, got, ctx) => `${ctx ? ctx + ": " : ""}Callback must return ${expected}; got ${got}.`,
|
|
103
|
+
// State / operation
|
|
104
|
+
invalidOperation: (reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`,
|
|
105
|
+
// Matrix
|
|
106
|
+
matrixDimensionMismatch: (op) => `Matrix: Dimensions must be compatible for ${op}.`,
|
|
107
|
+
matrixSingular: () => "Matrix: Singular matrix, inverse does not exist.",
|
|
108
|
+
matrixNotSquare: () => "Matrix: Must be square for inversion.",
|
|
109
|
+
matrixNotRectangular: () => "Matrix: Must be rectangular for transposition.",
|
|
110
|
+
matrixRowMismatch: (expected, got) => `Matrix: Expected row length ${expected}, but got ${got}.`,
|
|
111
|
+
// Order statistic
|
|
112
|
+
orderStatisticNotEnabled: (method, ctx) => `${ctx ? ctx + ": " : ""}${method}() requires enableOrderStatistic: true.`
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
// src/common/index.ts
|
|
116
|
+
var DFSOperation = /* @__PURE__ */ ((DFSOperation2) => {
|
|
117
|
+
DFSOperation2[DFSOperation2["VISIT"] = 0] = "VISIT";
|
|
118
|
+
DFSOperation2[DFSOperation2["PROCESS"] = 1] = "PROCESS";
|
|
119
|
+
return DFSOperation2;
|
|
120
|
+
})(DFSOperation || {});
|
|
121
|
+
var Range = class {
|
|
122
|
+
constructor(low, high, includeLow = true, includeHigh = true) {
|
|
123
|
+
this.low = low;
|
|
124
|
+
this.high = high;
|
|
125
|
+
this.includeLow = includeLow;
|
|
126
|
+
this.includeHigh = includeHigh;
|
|
127
|
+
}
|
|
128
|
+
// Determine whether a key is within the range
|
|
129
|
+
isInRange(key, comparator) {
|
|
130
|
+
const lowCheck = this.includeLow ? comparator(key, this.low) >= 0 : comparator(key, this.low) > 0;
|
|
131
|
+
const highCheck = this.includeHigh ? comparator(key, this.high) <= 0 : comparator(key, this.high) < 0;
|
|
132
|
+
return lowCheck && highCheck;
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
|
|
84
136
|
// src/data-structures/base/iterable-element-base.ts
|
|
85
137
|
var IterableElementBase = class {
|
|
86
138
|
/**
|
|
@@ -103,7 +155,7 @@ var binaryTreeTyped = (() => {
|
|
|
103
155
|
if (options) {
|
|
104
156
|
const { toElementFn } = options;
|
|
105
157
|
if (typeof toElementFn === "function") this._toElementFn = toElementFn;
|
|
106
|
-
else if (toElementFn)
|
|
158
|
+
else if (toElementFn) raise(TypeError, "toElementFn must be a function type");
|
|
107
159
|
}
|
|
108
160
|
}
|
|
109
161
|
/**
|
|
@@ -259,7 +311,7 @@ var binaryTreeTyped = (() => {
|
|
|
259
311
|
acc = initialValue;
|
|
260
312
|
} else {
|
|
261
313
|
const first = iter.next();
|
|
262
|
-
if (first.done)
|
|
314
|
+
if (first.done) raise(TypeError, "Reduce of empty structure with no initial value");
|
|
263
315
|
acc = first.value;
|
|
264
316
|
index = 1;
|
|
265
317
|
}
|
|
@@ -491,52 +543,6 @@ var binaryTreeTyped = (() => {
|
|
|
491
543
|
}
|
|
492
544
|
};
|
|
493
545
|
|
|
494
|
-
// src/common/error.ts
|
|
495
|
-
var ERR = {
|
|
496
|
-
// Range / index
|
|
497
|
-
indexOutOfRange: (index, min, max, ctx) => `${ctx ? ctx + ": " : ""}Index ${index} is out of range [${min}, ${max}].`,
|
|
498
|
-
invalidIndex: (ctx) => `${ctx ? ctx + ": " : ""}Index must be an integer.`,
|
|
499
|
-
// Type / argument
|
|
500
|
-
invalidArgument: (reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`,
|
|
501
|
-
comparatorRequired: (ctx) => `${ctx ? ctx + ": " : ""}Comparator is required for non-number/non-string/non-Date keys.`,
|
|
502
|
-
invalidKey: (reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`,
|
|
503
|
-
notAFunction: (name, ctx) => `${ctx ? ctx + ": " : ""}${name} must be a function.`,
|
|
504
|
-
invalidEntry: (ctx) => `${ctx ? ctx + ": " : ""}Each entry must be a [key, value] tuple.`,
|
|
505
|
-
invalidNaN: (ctx) => `${ctx ? ctx + ": " : ""}NaN is not a valid key.`,
|
|
506
|
-
invalidDate: (ctx) => `${ctx ? ctx + ": " : ""}Invalid Date key.`,
|
|
507
|
-
reduceEmpty: (ctx) => `${ctx ? ctx + ": " : ""}Reduce of empty structure with no initial value.`,
|
|
508
|
-
callbackReturnType: (expected, got, ctx) => `${ctx ? ctx + ": " : ""}Callback must return ${expected}; got ${got}.`,
|
|
509
|
-
// State / operation
|
|
510
|
-
invalidOperation: (reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`,
|
|
511
|
-
// Matrix
|
|
512
|
-
matrixDimensionMismatch: (op) => `Matrix: Dimensions must be compatible for ${op}.`,
|
|
513
|
-
matrixSingular: () => "Matrix: Singular matrix, inverse does not exist.",
|
|
514
|
-
matrixNotSquare: () => "Matrix: Must be square for inversion.",
|
|
515
|
-
matrixNotRectangular: () => "Matrix: Must be rectangular for transposition.",
|
|
516
|
-
matrixRowMismatch: (expected, got) => `Matrix: Expected row length ${expected}, but got ${got}.`
|
|
517
|
-
};
|
|
518
|
-
|
|
519
|
-
// src/common/index.ts
|
|
520
|
-
var DFSOperation = /* @__PURE__ */ ((DFSOperation2) => {
|
|
521
|
-
DFSOperation2[DFSOperation2["VISIT"] = 0] = "VISIT";
|
|
522
|
-
DFSOperation2[DFSOperation2["PROCESS"] = 1] = "PROCESS";
|
|
523
|
-
return DFSOperation2;
|
|
524
|
-
})(DFSOperation || {});
|
|
525
|
-
var Range = class {
|
|
526
|
-
constructor(low, high, includeLow = true, includeHigh = true) {
|
|
527
|
-
this.low = low;
|
|
528
|
-
this.high = high;
|
|
529
|
-
this.includeLow = includeLow;
|
|
530
|
-
this.includeHigh = includeHigh;
|
|
531
|
-
}
|
|
532
|
-
// Determine whether a key is within the range
|
|
533
|
-
isInRange(key, comparator) {
|
|
534
|
-
const lowCheck = this.includeLow ? comparator(key, this.low) >= 0 : comparator(key, this.low) > 0;
|
|
535
|
-
const highCheck = this.includeHigh ? comparator(key, this.high) <= 0 : comparator(key, this.high) < 0;
|
|
536
|
-
return lowCheck && highCheck;
|
|
537
|
-
}
|
|
538
|
-
};
|
|
539
|
-
|
|
540
546
|
// src/data-structures/base/iterable-entry-base.ts
|
|
541
547
|
var IterableEntryBase = class {
|
|
542
548
|
/**
|
|
@@ -784,6 +790,30 @@ var binaryTreeTyped = (() => {
|
|
|
784
790
|
|
|
785
791
|
|
|
786
792
|
|
|
793
|
+
|
|
794
|
+
|
|
795
|
+
|
|
796
|
+
|
|
797
|
+
|
|
798
|
+
|
|
799
|
+
|
|
800
|
+
|
|
801
|
+
|
|
802
|
+
|
|
803
|
+
|
|
804
|
+
|
|
805
|
+
|
|
806
|
+
|
|
807
|
+
|
|
808
|
+
|
|
809
|
+
|
|
810
|
+
|
|
811
|
+
|
|
812
|
+
|
|
813
|
+
|
|
814
|
+
|
|
815
|
+
|
|
816
|
+
|
|
787
817
|
* @example
|
|
788
818
|
* // Track queue length
|
|
789
819
|
* const q = new Queue<number>();
|
|
@@ -810,6 +840,30 @@ var binaryTreeTyped = (() => {
|
|
|
810
840
|
|
|
811
841
|
|
|
812
842
|
|
|
843
|
+
|
|
844
|
+
|
|
845
|
+
|
|
846
|
+
|
|
847
|
+
|
|
848
|
+
|
|
849
|
+
|
|
850
|
+
|
|
851
|
+
|
|
852
|
+
|
|
853
|
+
|
|
854
|
+
|
|
855
|
+
|
|
856
|
+
|
|
857
|
+
|
|
858
|
+
|
|
859
|
+
|
|
860
|
+
|
|
861
|
+
|
|
862
|
+
|
|
863
|
+
|
|
864
|
+
|
|
865
|
+
|
|
866
|
+
|
|
813
867
|
* @example
|
|
814
868
|
* // View the front element
|
|
815
869
|
* const q = new Queue<string>(['first', 'second', 'third']);
|
|
@@ -852,6 +906,30 @@ var binaryTreeTyped = (() => {
|
|
|
852
906
|
|
|
853
907
|
|
|
854
908
|
|
|
909
|
+
|
|
910
|
+
|
|
911
|
+
|
|
912
|
+
|
|
913
|
+
|
|
914
|
+
|
|
915
|
+
|
|
916
|
+
|
|
917
|
+
|
|
918
|
+
|
|
919
|
+
|
|
920
|
+
|
|
921
|
+
|
|
922
|
+
|
|
923
|
+
|
|
924
|
+
|
|
925
|
+
|
|
926
|
+
|
|
927
|
+
|
|
928
|
+
|
|
929
|
+
|
|
930
|
+
|
|
931
|
+
|
|
932
|
+
|
|
855
933
|
* @example
|
|
856
934
|
* // Queue for...of iteration and isEmpty check
|
|
857
935
|
* const queue = new Queue<string>(['A', 'B', 'C', 'D']);
|
|
@@ -890,6 +968,30 @@ var binaryTreeTyped = (() => {
|
|
|
890
968
|
|
|
891
969
|
|
|
892
970
|
|
|
971
|
+
|
|
972
|
+
|
|
973
|
+
|
|
974
|
+
|
|
975
|
+
|
|
976
|
+
|
|
977
|
+
|
|
978
|
+
|
|
979
|
+
|
|
980
|
+
|
|
981
|
+
|
|
982
|
+
|
|
983
|
+
|
|
984
|
+
|
|
985
|
+
|
|
986
|
+
|
|
987
|
+
|
|
988
|
+
|
|
989
|
+
|
|
990
|
+
|
|
991
|
+
|
|
992
|
+
|
|
993
|
+
|
|
994
|
+
|
|
893
995
|
* @example
|
|
894
996
|
* // basic Queue creation and push operation
|
|
895
997
|
* // Create a simple Queue with initial values
|
|
@@ -935,6 +1037,30 @@ var binaryTreeTyped = (() => {
|
|
|
935
1037
|
|
|
936
1038
|
|
|
937
1039
|
|
|
1040
|
+
|
|
1041
|
+
|
|
1042
|
+
|
|
1043
|
+
|
|
1044
|
+
|
|
1045
|
+
|
|
1046
|
+
|
|
1047
|
+
|
|
1048
|
+
|
|
1049
|
+
|
|
1050
|
+
|
|
1051
|
+
|
|
1052
|
+
|
|
1053
|
+
|
|
1054
|
+
|
|
1055
|
+
|
|
1056
|
+
|
|
1057
|
+
|
|
1058
|
+
|
|
1059
|
+
|
|
1060
|
+
|
|
1061
|
+
|
|
1062
|
+
|
|
1063
|
+
|
|
938
1064
|
* @example
|
|
939
1065
|
* // Queue shift and peek operations
|
|
940
1066
|
* const queue = new Queue<number>([10, 20, 30, 40]);
|
|
@@ -970,6 +1096,30 @@ var binaryTreeTyped = (() => {
|
|
|
970
1096
|
|
|
971
1097
|
|
|
972
1098
|
|
|
1099
|
+
|
|
1100
|
+
|
|
1101
|
+
|
|
1102
|
+
|
|
1103
|
+
|
|
1104
|
+
|
|
1105
|
+
|
|
1106
|
+
|
|
1107
|
+
|
|
1108
|
+
|
|
1109
|
+
|
|
1110
|
+
|
|
1111
|
+
|
|
1112
|
+
|
|
1113
|
+
|
|
1114
|
+
|
|
1115
|
+
|
|
1116
|
+
|
|
1117
|
+
|
|
1118
|
+
|
|
1119
|
+
|
|
1120
|
+
|
|
1121
|
+
|
|
1122
|
+
|
|
973
1123
|
* @example
|
|
974
1124
|
* // Remove specific element
|
|
975
1125
|
* const q = new Queue<number>([1, 2, 3, 2]);
|
|
@@ -998,27 +1148,51 @@ var binaryTreeTyped = (() => {
|
|
|
998
1148
|
|
|
999
1149
|
|
|
1000
1150
|
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1151
|
+
|
|
1152
|
+
|
|
1153
|
+
|
|
1154
|
+
|
|
1155
|
+
|
|
1156
|
+
|
|
1157
|
+
|
|
1158
|
+
|
|
1159
|
+
|
|
1160
|
+
|
|
1161
|
+
|
|
1162
|
+
|
|
1163
|
+
|
|
1164
|
+
|
|
1165
|
+
|
|
1166
|
+
|
|
1167
|
+
|
|
1168
|
+
|
|
1169
|
+
|
|
1170
|
+
|
|
1171
|
+
|
|
1172
|
+
|
|
1173
|
+
|
|
1174
|
+
|
|
1175
|
+
* @example
|
|
1176
|
+
* // Access element by index
|
|
1177
|
+
* const q = new Queue<string>(['a', 'b', 'c']);
|
|
1178
|
+
* console.log(q.at(0)); // 'a';
|
|
1179
|
+
* console.log(q.at(2)); // 'c';
|
|
1180
|
+
*/
|
|
1181
|
+
at(index) {
|
|
1182
|
+
if (index < 0 || index >= this.length) return void 0;
|
|
1183
|
+
return this._elements[this._offset + index];
|
|
1184
|
+
}
|
|
1185
|
+
/**
|
|
1186
|
+
* Delete the element at a given index.
|
|
1187
|
+
* @remarks Time O(N), Space O(1)
|
|
1188
|
+
* @param index - Zero-based index from the front.
|
|
1189
|
+
* @returns Removed element or undefined.
|
|
1190
|
+
*/
|
|
1191
|
+
deleteAt(index) {
|
|
1192
|
+
if (index < 0 || index >= this.length) return void 0;
|
|
1193
|
+
const gi = this._offset + index;
|
|
1194
|
+
const [deleted] = this.elements.splice(gi, 1);
|
|
1195
|
+
return deleted;
|
|
1022
1196
|
}
|
|
1023
1197
|
/**
|
|
1024
1198
|
* Insert a new element at a given index.
|
|
@@ -1067,6 +1241,30 @@ var binaryTreeTyped = (() => {
|
|
|
1067
1241
|
|
|
1068
1242
|
|
|
1069
1243
|
|
|
1244
|
+
|
|
1245
|
+
|
|
1246
|
+
|
|
1247
|
+
|
|
1248
|
+
|
|
1249
|
+
|
|
1250
|
+
|
|
1251
|
+
|
|
1252
|
+
|
|
1253
|
+
|
|
1254
|
+
|
|
1255
|
+
|
|
1256
|
+
|
|
1257
|
+
|
|
1258
|
+
|
|
1259
|
+
|
|
1260
|
+
|
|
1261
|
+
|
|
1262
|
+
|
|
1263
|
+
|
|
1264
|
+
|
|
1265
|
+
|
|
1266
|
+
|
|
1267
|
+
|
|
1070
1268
|
* @example
|
|
1071
1269
|
* // Remove all elements
|
|
1072
1270
|
* const q = new Queue<number>([1, 2, 3]);
|
|
@@ -1089,6 +1287,30 @@ var binaryTreeTyped = (() => {
|
|
|
1089
1287
|
|
|
1090
1288
|
|
|
1091
1289
|
|
|
1290
|
+
|
|
1291
|
+
|
|
1292
|
+
|
|
1293
|
+
|
|
1294
|
+
|
|
1295
|
+
|
|
1296
|
+
|
|
1297
|
+
|
|
1298
|
+
|
|
1299
|
+
|
|
1300
|
+
|
|
1301
|
+
|
|
1302
|
+
|
|
1303
|
+
|
|
1304
|
+
|
|
1305
|
+
|
|
1306
|
+
|
|
1307
|
+
|
|
1308
|
+
|
|
1309
|
+
|
|
1310
|
+
|
|
1311
|
+
|
|
1312
|
+
|
|
1313
|
+
|
|
1092
1314
|
* @example
|
|
1093
1315
|
* // Reclaim unused memory
|
|
1094
1316
|
* const q = new Queue<number>([1, 2, 3, 4, 5]);
|
|
@@ -1134,6 +1356,30 @@ var binaryTreeTyped = (() => {
|
|
|
1134
1356
|
|
|
1135
1357
|
|
|
1136
1358
|
|
|
1359
|
+
|
|
1360
|
+
|
|
1361
|
+
|
|
1362
|
+
|
|
1363
|
+
|
|
1364
|
+
|
|
1365
|
+
|
|
1366
|
+
|
|
1367
|
+
|
|
1368
|
+
|
|
1369
|
+
|
|
1370
|
+
|
|
1371
|
+
|
|
1372
|
+
|
|
1373
|
+
|
|
1374
|
+
|
|
1375
|
+
|
|
1376
|
+
|
|
1377
|
+
|
|
1378
|
+
|
|
1379
|
+
|
|
1380
|
+
|
|
1381
|
+
|
|
1382
|
+
|
|
1137
1383
|
* @example
|
|
1138
1384
|
* // Create independent copy
|
|
1139
1385
|
* const q = new Queue<number>([1, 2, 3]);
|
|
@@ -1163,6 +1409,30 @@ var binaryTreeTyped = (() => {
|
|
|
1163
1409
|
|
|
1164
1410
|
|
|
1165
1411
|
|
|
1412
|
+
|
|
1413
|
+
|
|
1414
|
+
|
|
1415
|
+
|
|
1416
|
+
|
|
1417
|
+
|
|
1418
|
+
|
|
1419
|
+
|
|
1420
|
+
|
|
1421
|
+
|
|
1422
|
+
|
|
1423
|
+
|
|
1424
|
+
|
|
1425
|
+
|
|
1426
|
+
|
|
1427
|
+
|
|
1428
|
+
|
|
1429
|
+
|
|
1430
|
+
|
|
1431
|
+
|
|
1432
|
+
|
|
1433
|
+
|
|
1434
|
+
|
|
1435
|
+
|
|
1166
1436
|
* @example
|
|
1167
1437
|
* // Filter elements
|
|
1168
1438
|
* const q = new Queue<number>([1, 2, 3, 4, 5]);
|
|
@@ -1196,6 +1466,30 @@ var binaryTreeTyped = (() => {
|
|
|
1196
1466
|
|
|
1197
1467
|
|
|
1198
1468
|
|
|
1469
|
+
|
|
1470
|
+
|
|
1471
|
+
|
|
1472
|
+
|
|
1473
|
+
|
|
1474
|
+
|
|
1475
|
+
|
|
1476
|
+
|
|
1477
|
+
|
|
1478
|
+
|
|
1479
|
+
|
|
1480
|
+
|
|
1481
|
+
|
|
1482
|
+
|
|
1483
|
+
|
|
1484
|
+
|
|
1485
|
+
|
|
1486
|
+
|
|
1487
|
+
|
|
1488
|
+
|
|
1489
|
+
|
|
1490
|
+
|
|
1491
|
+
|
|
1492
|
+
|
|
1199
1493
|
* @example
|
|
1200
1494
|
* // Transform elements
|
|
1201
1495
|
* const q = new Queue<number>([1, 2, 3]);
|
|
@@ -1460,7 +1754,7 @@ var binaryTreeTyped = (() => {
|
|
|
1460
1754
|
if (isMapMode !== void 0) this._isMapMode = isMapMode;
|
|
1461
1755
|
if (isDuplicate !== void 0) this._isDuplicate = isDuplicate;
|
|
1462
1756
|
if (typeof toEntryFn === "function") this._toEntryFn = toEntryFn;
|
|
1463
|
-
else if (toEntryFn)
|
|
1757
|
+
else if (toEntryFn) raise(TypeError, ERR.notAFunction("toEntryFn", "BinaryTree"));
|
|
1464
1758
|
}
|
|
1465
1759
|
if (keysNodesEntriesOrRaws) this.setMany(keysNodesEntriesOrRaws);
|
|
1466
1760
|
}
|
|
@@ -1676,6 +1970,30 @@ var binaryTreeTyped = (() => {
|
|
|
1676
1970
|
|
|
1677
1971
|
|
|
1678
1972
|
|
|
1973
|
+
|
|
1974
|
+
|
|
1975
|
+
|
|
1976
|
+
|
|
1977
|
+
|
|
1978
|
+
|
|
1979
|
+
|
|
1980
|
+
|
|
1981
|
+
|
|
1982
|
+
|
|
1983
|
+
|
|
1984
|
+
|
|
1985
|
+
|
|
1986
|
+
|
|
1987
|
+
|
|
1988
|
+
|
|
1989
|
+
|
|
1990
|
+
|
|
1991
|
+
|
|
1992
|
+
|
|
1993
|
+
|
|
1994
|
+
|
|
1995
|
+
|
|
1996
|
+
|
|
1679
1997
|
* @example
|
|
1680
1998
|
* // Add a single node
|
|
1681
1999
|
* const tree = new BinaryTree<number>();
|
|
@@ -1706,6 +2024,30 @@ var binaryTreeTyped = (() => {
|
|
|
1706
2024
|
|
|
1707
2025
|
|
|
1708
2026
|
|
|
2027
|
+
|
|
2028
|
+
|
|
2029
|
+
|
|
2030
|
+
|
|
2031
|
+
|
|
2032
|
+
|
|
2033
|
+
|
|
2034
|
+
|
|
2035
|
+
|
|
2036
|
+
|
|
2037
|
+
|
|
2038
|
+
|
|
2039
|
+
|
|
2040
|
+
|
|
2041
|
+
|
|
2042
|
+
|
|
2043
|
+
|
|
2044
|
+
|
|
2045
|
+
|
|
2046
|
+
|
|
2047
|
+
|
|
2048
|
+
|
|
2049
|
+
|
|
2050
|
+
|
|
1709
2051
|
* @example
|
|
1710
2052
|
* // basic BinaryTree creation and insertion
|
|
1711
2053
|
* // Create a BinaryTree with entries
|
|
@@ -1788,6 +2130,30 @@ var binaryTreeTyped = (() => {
|
|
|
1788
2130
|
|
|
1789
2131
|
|
|
1790
2132
|
|
|
2133
|
+
|
|
2134
|
+
|
|
2135
|
+
|
|
2136
|
+
|
|
2137
|
+
|
|
2138
|
+
|
|
2139
|
+
|
|
2140
|
+
|
|
2141
|
+
|
|
2142
|
+
|
|
2143
|
+
|
|
2144
|
+
|
|
2145
|
+
|
|
2146
|
+
|
|
2147
|
+
|
|
2148
|
+
|
|
2149
|
+
|
|
2150
|
+
|
|
2151
|
+
|
|
2152
|
+
|
|
2153
|
+
|
|
2154
|
+
|
|
2155
|
+
|
|
2156
|
+
|
|
1791
2157
|
* @example
|
|
1792
2158
|
* // Bulk add
|
|
1793
2159
|
* const tree = new BinaryTree<number>();
|
|
@@ -1806,6 +2172,30 @@ var binaryTreeTyped = (() => {
|
|
|
1806
2172
|
* @returns An array of booleans indicating the success of each individual `set` operation.
|
|
1807
2173
|
|
|
1808
2174
|
|
|
2175
|
+
|
|
2176
|
+
|
|
2177
|
+
|
|
2178
|
+
|
|
2179
|
+
|
|
2180
|
+
|
|
2181
|
+
|
|
2182
|
+
|
|
2183
|
+
|
|
2184
|
+
|
|
2185
|
+
|
|
2186
|
+
|
|
2187
|
+
|
|
2188
|
+
|
|
2189
|
+
|
|
2190
|
+
|
|
2191
|
+
|
|
2192
|
+
|
|
2193
|
+
|
|
2194
|
+
|
|
2195
|
+
|
|
2196
|
+
|
|
2197
|
+
|
|
2198
|
+
|
|
1809
2199
|
* @example
|
|
1810
2200
|
* // Set multiple entries
|
|
1811
2201
|
* const tree = new BinaryTree<number, string>();
|
|
@@ -1845,6 +2235,30 @@ var binaryTreeTyped = (() => {
|
|
|
1845
2235
|
|
|
1846
2236
|
|
|
1847
2237
|
|
|
2238
|
+
|
|
2239
|
+
|
|
2240
|
+
|
|
2241
|
+
|
|
2242
|
+
|
|
2243
|
+
|
|
2244
|
+
|
|
2245
|
+
|
|
2246
|
+
|
|
2247
|
+
|
|
2248
|
+
|
|
2249
|
+
|
|
2250
|
+
|
|
2251
|
+
|
|
2252
|
+
|
|
2253
|
+
|
|
2254
|
+
|
|
2255
|
+
|
|
2256
|
+
|
|
2257
|
+
|
|
2258
|
+
|
|
2259
|
+
|
|
2260
|
+
|
|
2261
|
+
|
|
1848
2262
|
* @example
|
|
1849
2263
|
* // Combine trees
|
|
1850
2264
|
* const t1 = new BinaryTree<number>([1, 2]);
|
|
@@ -1883,6 +2297,30 @@ var binaryTreeTyped = (() => {
|
|
|
1883
2297
|
|
|
1884
2298
|
|
|
1885
2299
|
|
|
2300
|
+
|
|
2301
|
+
|
|
2302
|
+
|
|
2303
|
+
|
|
2304
|
+
|
|
2305
|
+
|
|
2306
|
+
|
|
2307
|
+
|
|
2308
|
+
|
|
2309
|
+
|
|
2310
|
+
|
|
2311
|
+
|
|
2312
|
+
|
|
2313
|
+
|
|
2314
|
+
|
|
2315
|
+
|
|
2316
|
+
|
|
2317
|
+
|
|
2318
|
+
|
|
2319
|
+
|
|
2320
|
+
|
|
2321
|
+
|
|
2322
|
+
|
|
2323
|
+
|
|
1886
2324
|
* @example
|
|
1887
2325
|
* // Remove a node
|
|
1888
2326
|
* const tree = new BinaryTree<number>([1, 2, 3, 4, 5]);
|
|
@@ -1999,6 +2437,30 @@ var binaryTreeTyped = (() => {
|
|
|
1999
2437
|
|
|
2000
2438
|
|
|
2001
2439
|
|
|
2440
|
+
|
|
2441
|
+
|
|
2442
|
+
|
|
2443
|
+
|
|
2444
|
+
|
|
2445
|
+
|
|
2446
|
+
|
|
2447
|
+
|
|
2448
|
+
|
|
2449
|
+
|
|
2450
|
+
|
|
2451
|
+
|
|
2452
|
+
|
|
2453
|
+
|
|
2454
|
+
|
|
2455
|
+
|
|
2456
|
+
|
|
2457
|
+
|
|
2458
|
+
|
|
2459
|
+
|
|
2460
|
+
|
|
2461
|
+
|
|
2462
|
+
|
|
2463
|
+
|
|
2002
2464
|
* @example
|
|
2003
2465
|
* // Get node by key
|
|
2004
2466
|
* const tree = new BinaryTree<number, string>([[1, 'root'], [2, 'child']]);
|
|
@@ -2033,6 +2495,30 @@ var binaryTreeTyped = (() => {
|
|
|
2033
2495
|
|
|
2034
2496
|
|
|
2035
2497
|
|
|
2498
|
+
|
|
2499
|
+
|
|
2500
|
+
|
|
2501
|
+
|
|
2502
|
+
|
|
2503
|
+
|
|
2504
|
+
|
|
2505
|
+
|
|
2506
|
+
|
|
2507
|
+
|
|
2508
|
+
|
|
2509
|
+
|
|
2510
|
+
|
|
2511
|
+
|
|
2512
|
+
|
|
2513
|
+
|
|
2514
|
+
|
|
2515
|
+
|
|
2516
|
+
|
|
2517
|
+
|
|
2518
|
+
|
|
2519
|
+
|
|
2520
|
+
|
|
2521
|
+
|
|
2036
2522
|
* @example
|
|
2037
2523
|
* // Retrieve value by key
|
|
2038
2524
|
* const tree = new BinaryTree<number, string>([[1, 'root'], [2, 'left'], [3, 'right']]);
|
|
@@ -2070,6 +2556,30 @@ var binaryTreeTyped = (() => {
|
|
|
2070
2556
|
|
|
2071
2557
|
|
|
2072
2558
|
|
|
2559
|
+
|
|
2560
|
+
|
|
2561
|
+
|
|
2562
|
+
|
|
2563
|
+
|
|
2564
|
+
|
|
2565
|
+
|
|
2566
|
+
|
|
2567
|
+
|
|
2568
|
+
|
|
2569
|
+
|
|
2570
|
+
|
|
2571
|
+
|
|
2572
|
+
|
|
2573
|
+
|
|
2574
|
+
|
|
2575
|
+
|
|
2576
|
+
|
|
2577
|
+
|
|
2578
|
+
|
|
2579
|
+
|
|
2580
|
+
|
|
2581
|
+
|
|
2582
|
+
|
|
2073
2583
|
* @example
|
|
2074
2584
|
* // Remove all nodes
|
|
2075
2585
|
* const tree = new BinaryTree<number>([1, 2, 3]);
|
|
@@ -2094,6 +2604,30 @@ var binaryTreeTyped = (() => {
|
|
|
2094
2604
|
|
|
2095
2605
|
|
|
2096
2606
|
|
|
2607
|
+
|
|
2608
|
+
|
|
2609
|
+
|
|
2610
|
+
|
|
2611
|
+
|
|
2612
|
+
|
|
2613
|
+
|
|
2614
|
+
|
|
2615
|
+
|
|
2616
|
+
|
|
2617
|
+
|
|
2618
|
+
|
|
2619
|
+
|
|
2620
|
+
|
|
2621
|
+
|
|
2622
|
+
|
|
2623
|
+
|
|
2624
|
+
|
|
2625
|
+
|
|
2626
|
+
|
|
2627
|
+
|
|
2628
|
+
|
|
2629
|
+
|
|
2630
|
+
|
|
2097
2631
|
* @example
|
|
2098
2632
|
* // Check empty
|
|
2099
2633
|
* console.log(new BinaryTree().isEmpty()); // true;
|
|
@@ -2127,6 +2661,30 @@ var binaryTreeTyped = (() => {
|
|
|
2127
2661
|
|
|
2128
2662
|
|
|
2129
2663
|
|
|
2664
|
+
|
|
2665
|
+
|
|
2666
|
+
|
|
2667
|
+
|
|
2668
|
+
|
|
2669
|
+
|
|
2670
|
+
|
|
2671
|
+
|
|
2672
|
+
|
|
2673
|
+
|
|
2674
|
+
|
|
2675
|
+
|
|
2676
|
+
|
|
2677
|
+
|
|
2678
|
+
|
|
2679
|
+
|
|
2680
|
+
|
|
2681
|
+
|
|
2682
|
+
|
|
2683
|
+
|
|
2684
|
+
|
|
2685
|
+
|
|
2686
|
+
|
|
2687
|
+
|
|
2130
2688
|
* @example
|
|
2131
2689
|
* // Check BST property
|
|
2132
2690
|
* const tree = new BinaryTree<number>([1, 2, 3]);
|
|
@@ -2187,6 +2745,30 @@ var binaryTreeTyped = (() => {
|
|
|
2187
2745
|
|
|
2188
2746
|
|
|
2189
2747
|
|
|
2748
|
+
|
|
2749
|
+
|
|
2750
|
+
|
|
2751
|
+
|
|
2752
|
+
|
|
2753
|
+
|
|
2754
|
+
|
|
2755
|
+
|
|
2756
|
+
|
|
2757
|
+
|
|
2758
|
+
|
|
2759
|
+
|
|
2760
|
+
|
|
2761
|
+
|
|
2762
|
+
|
|
2763
|
+
|
|
2764
|
+
|
|
2765
|
+
|
|
2766
|
+
|
|
2767
|
+
|
|
2768
|
+
|
|
2769
|
+
|
|
2770
|
+
|
|
2771
|
+
|
|
2190
2772
|
* @example
|
|
2191
2773
|
* // Get depth of a node
|
|
2192
2774
|
* const tree = new BinaryTree<number>([1, 2, 3, 4, 5]);
|
|
@@ -2224,6 +2806,30 @@ var binaryTreeTyped = (() => {
|
|
|
2224
2806
|
|
|
2225
2807
|
|
|
2226
2808
|
|
|
2809
|
+
|
|
2810
|
+
|
|
2811
|
+
|
|
2812
|
+
|
|
2813
|
+
|
|
2814
|
+
|
|
2815
|
+
|
|
2816
|
+
|
|
2817
|
+
|
|
2818
|
+
|
|
2819
|
+
|
|
2820
|
+
|
|
2821
|
+
|
|
2822
|
+
|
|
2823
|
+
|
|
2824
|
+
|
|
2825
|
+
|
|
2826
|
+
|
|
2827
|
+
|
|
2828
|
+
|
|
2829
|
+
|
|
2830
|
+
|
|
2831
|
+
|
|
2832
|
+
|
|
2227
2833
|
* @example
|
|
2228
2834
|
* // Get tree height
|
|
2229
2835
|
* const tree = new BinaryTree<number>([1, 2, 3, 4, 5]);
|
|
@@ -2677,6 +3283,30 @@ var binaryTreeTyped = (() => {
|
|
|
2677
3283
|
|
|
2678
3284
|
|
|
2679
3285
|
|
|
3286
|
+
|
|
3287
|
+
|
|
3288
|
+
|
|
3289
|
+
|
|
3290
|
+
|
|
3291
|
+
|
|
3292
|
+
|
|
3293
|
+
|
|
3294
|
+
|
|
3295
|
+
|
|
3296
|
+
|
|
3297
|
+
|
|
3298
|
+
|
|
3299
|
+
|
|
3300
|
+
|
|
3301
|
+
|
|
3302
|
+
|
|
3303
|
+
|
|
3304
|
+
|
|
3305
|
+
|
|
3306
|
+
|
|
3307
|
+
|
|
3308
|
+
|
|
3309
|
+
|
|
2680
3310
|
* @example
|
|
2681
3311
|
* // Deep copy
|
|
2682
3312
|
* const tree = new BinaryTree<number>([1, 2, 3]);
|
|
@@ -2705,6 +3335,30 @@ var binaryTreeTyped = (() => {
|
|
|
2705
3335
|
|
|
2706
3336
|
|
|
2707
3337
|
|
|
3338
|
+
|
|
3339
|
+
|
|
3340
|
+
|
|
3341
|
+
|
|
3342
|
+
|
|
3343
|
+
|
|
3344
|
+
|
|
3345
|
+
|
|
3346
|
+
|
|
3347
|
+
|
|
3348
|
+
|
|
3349
|
+
|
|
3350
|
+
|
|
3351
|
+
|
|
3352
|
+
|
|
3353
|
+
|
|
3354
|
+
|
|
3355
|
+
|
|
3356
|
+
|
|
3357
|
+
|
|
3358
|
+
|
|
3359
|
+
|
|
3360
|
+
|
|
3361
|
+
|
|
2708
3362
|
* @example
|
|
2709
3363
|
* // Filter nodes by condition
|
|
2710
3364
|
* const tree = new BinaryTree<number>([1, 2, 3, 4]);
|
|
@@ -2737,6 +3391,30 @@ var binaryTreeTyped = (() => {
|
|
|
2737
3391
|
|
|
2738
3392
|
|
|
2739
3393
|
|
|
3394
|
+
|
|
3395
|
+
|
|
3396
|
+
|
|
3397
|
+
|
|
3398
|
+
|
|
3399
|
+
|
|
3400
|
+
|
|
3401
|
+
|
|
3402
|
+
|
|
3403
|
+
|
|
3404
|
+
|
|
3405
|
+
|
|
3406
|
+
|
|
3407
|
+
|
|
3408
|
+
|
|
3409
|
+
|
|
3410
|
+
|
|
3411
|
+
|
|
3412
|
+
|
|
3413
|
+
|
|
3414
|
+
|
|
3415
|
+
|
|
3416
|
+
|
|
3417
|
+
|
|
2740
3418
|
* @example
|
|
2741
3419
|
* // Transform to new tree
|
|
2742
3420
|
* const tree = new BinaryTree<number, number>([[1, 10], [2, 20]]);
|
|
@@ -2794,6 +3472,30 @@ var binaryTreeTyped = (() => {
|
|
|
2794
3472
|
|
|
2795
3473
|
|
|
2796
3474
|
|
|
3475
|
+
|
|
3476
|
+
|
|
3477
|
+
|
|
3478
|
+
|
|
3479
|
+
|
|
3480
|
+
|
|
3481
|
+
|
|
3482
|
+
|
|
3483
|
+
|
|
3484
|
+
|
|
3485
|
+
|
|
3486
|
+
|
|
3487
|
+
|
|
3488
|
+
|
|
3489
|
+
|
|
3490
|
+
|
|
3491
|
+
|
|
3492
|
+
|
|
3493
|
+
|
|
3494
|
+
|
|
3495
|
+
|
|
3496
|
+
|
|
3497
|
+
|
|
3498
|
+
|
|
2797
3499
|
* @example
|
|
2798
3500
|
* // Display tree
|
|
2799
3501
|
* const tree = new BinaryTree<number>([1, 2, 3]);
|