binary-tree-typed 2.5.2 → 2.6.0
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 +320 -55
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs-legacy/index.cjs +320 -55
- package/dist/cjs-legacy/index.cjs.map +1 -1
- package/dist/esm/index.mjs +320 -55
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm-legacy/index.mjs +320 -55
- package/dist/esm-legacy/index.mjs.map +1 -1
- package/dist/types/data-structures/base/iterable-element-base.d.ts +17 -0
- package/dist/types/data-structures/base/linear-base.d.ts +6 -0
- package/dist/types/data-structures/binary-tree/avl-tree.d.ts +86 -2
- package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +98 -0
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +191 -15
- package/dist/types/data-structures/binary-tree/bst.d.ts +171 -3
- package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +136 -8
- package/dist/types/data-structures/binary-tree/segment-tree.d.ts +42 -0
- package/dist/types/data-structures/binary-tree/tree-map.d.ts +1061 -167
- package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +1232 -355
- package/dist/types/data-structures/binary-tree/tree-multi-set.d.ts +916 -194
- package/dist/types/data-structures/binary-tree/tree-set.d.ts +1078 -141
- package/dist/types/data-structures/graph/directed-graph.d.ts +70 -0
- package/dist/types/data-structures/graph/undirected-graph.d.ts +63 -0
- package/dist/types/data-structures/hash/hash-map.d.ts +84 -6
- package/dist/types/data-structures/heap/heap.d.ts +140 -12
- package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +150 -2
- package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +106 -1
- package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +126 -0
- package/dist/types/data-structures/matrix/matrix.d.ts +56 -0
- package/dist/types/data-structures/queue/deque.d.ts +171 -0
- package/dist/types/data-structures/queue/queue.d.ts +97 -0
- package/dist/types/data-structures/stack/stack.d.ts +72 -2
- package/dist/types/data-structures/trie/trie.d.ts +84 -0
- package/dist/types/interfaces/binary-tree.d.ts +2 -3
- package/dist/umd/binary-tree-typed.js +320 -55
- 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/data-structures/base/iterable-element-base.ts +32 -0
- package/src/data-structures/base/linear-base.ts +11 -0
- package/src/data-structures/binary-tree/avl-tree.ts +88 -5
- package/src/data-structures/binary-tree/binary-indexed-tree.ts +98 -0
- package/src/data-structures/binary-tree/binary-tree.ts +242 -81
- package/src/data-structures/binary-tree/bst.ts +173 -7
- package/src/data-structures/binary-tree/red-black-tree.ts +139 -15
- package/src/data-structures/binary-tree/segment-tree.ts +42 -0
- package/src/data-structures/binary-tree/tree-map.ts +948 -36
- package/src/data-structures/binary-tree/tree-multi-map.ts +893 -13
- package/src/data-structures/binary-tree/tree-multi-set.ts +761 -33
- package/src/data-structures/binary-tree/tree-set.ts +1260 -251
- package/src/data-structures/graph/directed-graph.ts +71 -1
- package/src/data-structures/graph/undirected-graph.ts +64 -1
- package/src/data-structures/hash/hash-map.ts +100 -12
- package/src/data-structures/heap/heap.ts +149 -19
- package/src/data-structures/linked-list/doubly-linked-list.ts +178 -2
- package/src/data-structures/linked-list/singly-linked-list.ts +106 -1
- package/src/data-structures/linked-list/skip-linked-list.ts +126 -0
- package/src/data-structures/matrix/matrix.ts +56 -0
- package/src/data-structures/queue/deque.ts +187 -0
- package/src/data-structures/queue/queue.ts +109 -0
- package/src/data-structures/stack/stack.ts +75 -5
- package/src/data-structures/trie/trie.ts +84 -0
- package/src/interfaces/binary-tree.ts +1 -9
|
@@ -262,6 +262,35 @@ var _IterableElementBase = class _IterableElementBase {
|
|
|
262
262
|
for (const ele of this) if (ele === element) return true;
|
|
263
263
|
return false;
|
|
264
264
|
}
|
|
265
|
+
/**
|
|
266
|
+
* Check whether a value exists (Array-compatible alias for `has`).
|
|
267
|
+
* @remarks Provided for familiarity when migrating from Array. Time O(n), Space O(1).
|
|
268
|
+
* @param element - Element to search for (uses `===`).
|
|
269
|
+
* @returns `true` if found.
|
|
270
|
+
*/
|
|
271
|
+
includes(element) {
|
|
272
|
+
return this.has(element);
|
|
273
|
+
}
|
|
274
|
+
/**
|
|
275
|
+
* Return an iterator of `[index, value]` pairs (Array-compatible).
|
|
276
|
+
* @remarks Provided for familiarity when migrating from Array. Time O(n), Space O(1) per step.
|
|
277
|
+
*/
|
|
278
|
+
*entries() {
|
|
279
|
+
let index = 0;
|
|
280
|
+
for (const value of this) {
|
|
281
|
+
yield [index++, value];
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
/**
|
|
285
|
+
* Return an iterator of numeric indices (Array-compatible).
|
|
286
|
+
* @remarks Provided for familiarity when migrating from Array. Time O(n), Space O(1) per step.
|
|
287
|
+
*/
|
|
288
|
+
*keys() {
|
|
289
|
+
let index = 0;
|
|
290
|
+
for (const _ of this) {
|
|
291
|
+
yield index++;
|
|
292
|
+
}
|
|
293
|
+
}
|
|
265
294
|
/**
|
|
266
295
|
* Reduces all elements to a single accumulated value.
|
|
267
296
|
*
|
|
@@ -523,6 +552,16 @@ var _LinearBase = class _LinearBase extends IterableElementBase {
|
|
|
523
552
|
}
|
|
524
553
|
return this;
|
|
525
554
|
}
|
|
555
|
+
/**
|
|
556
|
+
* Return a new instance of the same type with elements in reverse order (non-mutating).
|
|
557
|
+
* @remarks Provided for familiarity when migrating from Array (ES2023 `toReversed`). Time O(n), Space O(n).
|
|
558
|
+
* @returns A new reversed instance.
|
|
559
|
+
*/
|
|
560
|
+
toReversed() {
|
|
561
|
+
const cloned = this.clone();
|
|
562
|
+
cloned.reverse();
|
|
563
|
+
return cloned;
|
|
564
|
+
}
|
|
526
565
|
};
|
|
527
566
|
__name(_LinearBase, "LinearBase");
|
|
528
567
|
var LinearBase = _LinearBase;
|
|
@@ -792,6 +831,13 @@ var _Queue = class _Queue extends LinearBase {
|
|
|
792
831
|
|
|
793
832
|
|
|
794
833
|
|
|
834
|
+
|
|
835
|
+
|
|
836
|
+
|
|
837
|
+
|
|
838
|
+
|
|
839
|
+
|
|
840
|
+
|
|
795
841
|
|
|
796
842
|
|
|
797
843
|
|
|
@@ -842,6 +888,13 @@ var _Queue = class _Queue extends LinearBase {
|
|
|
842
888
|
|
|
843
889
|
|
|
844
890
|
|
|
891
|
+
|
|
892
|
+
|
|
893
|
+
|
|
894
|
+
|
|
895
|
+
|
|
896
|
+
|
|
897
|
+
|
|
845
898
|
|
|
846
899
|
|
|
847
900
|
|
|
@@ -859,6 +912,14 @@ var _Queue = class _Queue extends LinearBase {
|
|
|
859
912
|
get first() {
|
|
860
913
|
return this.length > 0 ? this.elements[this._offset] : void 0;
|
|
861
914
|
}
|
|
915
|
+
/**
|
|
916
|
+
* Peek at the front element without removing it (alias for `first`).
|
|
917
|
+
* @remarks Time O(1), Space O(1)
|
|
918
|
+
* @returns Front element or undefined.
|
|
919
|
+
*/
|
|
920
|
+
peek() {
|
|
921
|
+
return this.first;
|
|
922
|
+
}
|
|
862
923
|
/**
|
|
863
924
|
* Get the last element (back) without removing it.
|
|
864
925
|
* @remarks Time O(1), Space O(1)
|
|
@@ -908,6 +969,13 @@ var _Queue = class _Queue extends LinearBase {
|
|
|
908
969
|
|
|
909
970
|
|
|
910
971
|
|
|
972
|
+
|
|
973
|
+
|
|
974
|
+
|
|
975
|
+
|
|
976
|
+
|
|
977
|
+
|
|
978
|
+
|
|
911
979
|
|
|
912
980
|
|
|
913
981
|
|
|
@@ -970,6 +1038,13 @@ var _Queue = class _Queue extends LinearBase {
|
|
|
970
1038
|
|
|
971
1039
|
|
|
972
1040
|
|
|
1041
|
+
|
|
1042
|
+
|
|
1043
|
+
|
|
1044
|
+
|
|
1045
|
+
|
|
1046
|
+
|
|
1047
|
+
|
|
973
1048
|
|
|
974
1049
|
|
|
975
1050
|
|
|
@@ -1039,6 +1114,13 @@ var _Queue = class _Queue extends LinearBase {
|
|
|
1039
1114
|
|
|
1040
1115
|
|
|
1041
1116
|
|
|
1117
|
+
|
|
1118
|
+
|
|
1119
|
+
|
|
1120
|
+
|
|
1121
|
+
|
|
1122
|
+
|
|
1123
|
+
|
|
1042
1124
|
|
|
1043
1125
|
|
|
1044
1126
|
|
|
@@ -1098,6 +1180,13 @@ var _Queue = class _Queue extends LinearBase {
|
|
|
1098
1180
|
|
|
1099
1181
|
|
|
1100
1182
|
|
|
1183
|
+
|
|
1184
|
+
|
|
1185
|
+
|
|
1186
|
+
|
|
1187
|
+
|
|
1188
|
+
|
|
1189
|
+
|
|
1101
1190
|
|
|
1102
1191
|
|
|
1103
1192
|
|
|
@@ -1150,6 +1239,13 @@ var _Queue = class _Queue extends LinearBase {
|
|
|
1150
1239
|
|
|
1151
1240
|
|
|
1152
1241
|
|
|
1242
|
+
|
|
1243
|
+
|
|
1244
|
+
|
|
1245
|
+
|
|
1246
|
+
|
|
1247
|
+
|
|
1248
|
+
|
|
1153
1249
|
|
|
1154
1250
|
|
|
1155
1251
|
|
|
@@ -1204,6 +1300,21 @@ var _Queue = class _Queue extends LinearBase {
|
|
|
1204
1300
|
this._elements[this._offset + index] = newElement;
|
|
1205
1301
|
return true;
|
|
1206
1302
|
}
|
|
1303
|
+
/**
|
|
1304
|
+
* Delete the first element that satisfies a predicate.
|
|
1305
|
+
* @remarks Time O(N), Space O(N)
|
|
1306
|
+
* @param predicate - Function (value, index, queue) → boolean to decide deletion.
|
|
1307
|
+
* @returns True if a match was removed.
|
|
1308
|
+
*/
|
|
1309
|
+
deleteWhere(predicate) {
|
|
1310
|
+
for (let i = 0; i < this.length; i++) {
|
|
1311
|
+
if (predicate(this._elements[this._offset + i], i, this)) {
|
|
1312
|
+
this.deleteAt(i);
|
|
1313
|
+
return true;
|
|
1314
|
+
}
|
|
1315
|
+
}
|
|
1316
|
+
return false;
|
|
1317
|
+
}
|
|
1207
1318
|
/**
|
|
1208
1319
|
* Reverse the queue in-place by compacting then reversing.
|
|
1209
1320
|
* @remarks Time O(N), Space O(N)
|
|
@@ -1243,6 +1354,13 @@ var _Queue = class _Queue extends LinearBase {
|
|
|
1243
1354
|
|
|
1244
1355
|
|
|
1245
1356
|
|
|
1357
|
+
|
|
1358
|
+
|
|
1359
|
+
|
|
1360
|
+
|
|
1361
|
+
|
|
1362
|
+
|
|
1363
|
+
|
|
1246
1364
|
|
|
1247
1365
|
|
|
1248
1366
|
|
|
@@ -1289,6 +1407,13 @@ var _Queue = class _Queue extends LinearBase {
|
|
|
1289
1407
|
|
|
1290
1408
|
|
|
1291
1409
|
|
|
1410
|
+
|
|
1411
|
+
|
|
1412
|
+
|
|
1413
|
+
|
|
1414
|
+
|
|
1415
|
+
|
|
1416
|
+
|
|
1292
1417
|
|
|
1293
1418
|
|
|
1294
1419
|
|
|
@@ -1358,6 +1483,13 @@ var _Queue = class _Queue extends LinearBase {
|
|
|
1358
1483
|
|
|
1359
1484
|
|
|
1360
1485
|
|
|
1486
|
+
|
|
1487
|
+
|
|
1488
|
+
|
|
1489
|
+
|
|
1490
|
+
|
|
1491
|
+
|
|
1492
|
+
|
|
1361
1493
|
|
|
1362
1494
|
|
|
1363
1495
|
|
|
@@ -1411,6 +1543,13 @@ var _Queue = class _Queue extends LinearBase {
|
|
|
1411
1543
|
|
|
1412
1544
|
|
|
1413
1545
|
|
|
1546
|
+
|
|
1547
|
+
|
|
1548
|
+
|
|
1549
|
+
|
|
1550
|
+
|
|
1551
|
+
|
|
1552
|
+
|
|
1414
1553
|
|
|
1415
1554
|
|
|
1416
1555
|
|
|
@@ -1468,6 +1607,13 @@ var _Queue = class _Queue extends LinearBase {
|
|
|
1468
1607
|
|
|
1469
1608
|
|
|
1470
1609
|
|
|
1610
|
+
|
|
1611
|
+
|
|
1612
|
+
|
|
1613
|
+
|
|
1614
|
+
|
|
1615
|
+
|
|
1616
|
+
|
|
1471
1617
|
|
|
1472
1618
|
|
|
1473
1619
|
|
|
@@ -1950,7 +2096,7 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
1950
2096
|
}
|
|
1951
2097
|
/**
|
|
1952
2098
|
* Adds a new node to the tree.
|
|
1953
|
-
* @remarks Time O(
|
|
2099
|
+
* @remarks Time O(N) — level-order traversal to find an empty slot. Space O(N) for the BFS queue. BST/Red-Black Tree/AVL Tree subclasses override to O(log N).
|
|
1954
2100
|
*
|
|
1955
2101
|
* @param keyNodeOrEntry - The key, node, or entry to add.
|
|
1956
2102
|
* @returns True if the addition was successful, false otherwise.
|
|
@@ -1976,6 +2122,13 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
1976
2122
|
|
|
1977
2123
|
|
|
1978
2124
|
|
|
2125
|
+
|
|
2126
|
+
|
|
2127
|
+
|
|
2128
|
+
|
|
2129
|
+
|
|
2130
|
+
|
|
2131
|
+
|
|
1979
2132
|
|
|
1980
2133
|
|
|
1981
2134
|
|
|
@@ -1998,7 +2151,7 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
1998
2151
|
}
|
|
1999
2152
|
/**
|
|
2000
2153
|
* Adds or updates a new node to the tree.
|
|
2001
|
-
* @remarks Time O(
|
|
2154
|
+
* @remarks Time O(N) — level-order traversal to find an empty slot. Space O(N) for the BFS queue. BST/Red-Black Tree/AVL Tree subclasses override to O(log N).
|
|
2002
2155
|
*
|
|
2003
2156
|
* @param keyNodeOrEntry - The key, node, or entry to set or update.
|
|
2004
2157
|
* @param [value] - The value, if providing just a key.
|
|
@@ -2030,6 +2183,13 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
2030
2183
|
|
|
2031
2184
|
|
|
2032
2185
|
|
|
2186
|
+
|
|
2187
|
+
|
|
2188
|
+
|
|
2189
|
+
|
|
2190
|
+
|
|
2191
|
+
|
|
2192
|
+
|
|
2033
2193
|
|
|
2034
2194
|
|
|
2035
2195
|
|
|
@@ -2136,6 +2296,13 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
2136
2296
|
|
|
2137
2297
|
|
|
2138
2298
|
|
|
2299
|
+
|
|
2300
|
+
|
|
2301
|
+
|
|
2302
|
+
|
|
2303
|
+
|
|
2304
|
+
|
|
2305
|
+
|
|
2139
2306
|
|
|
2140
2307
|
|
|
2141
2308
|
|
|
@@ -2178,6 +2345,13 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
2178
2345
|
|
|
2179
2346
|
|
|
2180
2347
|
|
|
2348
|
+
|
|
2349
|
+
|
|
2350
|
+
|
|
2351
|
+
|
|
2352
|
+
|
|
2353
|
+
|
|
2354
|
+
|
|
2181
2355
|
|
|
2182
2356
|
|
|
2183
2357
|
|
|
@@ -2241,6 +2415,13 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
2241
2415
|
|
|
2242
2416
|
|
|
2243
2417
|
|
|
2418
|
+
|
|
2419
|
+
|
|
2420
|
+
|
|
2421
|
+
|
|
2422
|
+
|
|
2423
|
+
|
|
2424
|
+
|
|
2244
2425
|
|
|
2245
2426
|
|
|
2246
2427
|
|
|
@@ -2260,22 +2441,69 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
2260
2441
|
this.setMany(anotherTree, []);
|
|
2261
2442
|
}
|
|
2262
2443
|
/**
|
|
2263
|
-
*
|
|
2264
|
-
* @remarks Time O(N)
|
|
2444
|
+
* Deletes a node from the tree (internal, returns balancing metadata).
|
|
2445
|
+
* @remarks Time O(N) — O(N) to find the node + O(H) for predecessor swap. Space O(1). BST/Red-Black Tree/AVL Tree subclasses override to O(log N).
|
|
2446
|
+
* @internal Used by AVL/BST subclasses that need balancing metadata after deletion.
|
|
2265
2447
|
*
|
|
2266
|
-
* @param
|
|
2267
|
-
* @
|
|
2448
|
+
* @param keyNodeEntryRawOrPredicate - The node to delete.
|
|
2449
|
+
* @returns An array containing deletion results with balancing metadata.
|
|
2268
2450
|
*/
|
|
2269
|
-
|
|
2270
|
-
|
|
2271
|
-
this.
|
|
2451
|
+
_deleteInternal(keyNodeEntryRawOrPredicate) {
|
|
2452
|
+
const deletedResult = [];
|
|
2453
|
+
if (!this._root) return deletedResult;
|
|
2454
|
+
const curr = this.getNode(keyNodeEntryRawOrPredicate);
|
|
2455
|
+
if (!curr) return deletedResult;
|
|
2456
|
+
const parent = curr == null ? void 0 : curr.parent;
|
|
2457
|
+
let needBalanced;
|
|
2458
|
+
let orgCurrent = curr;
|
|
2459
|
+
if (!curr.left && !curr.right && !parent) {
|
|
2460
|
+
this._setRoot(void 0);
|
|
2461
|
+
} else if (curr.left) {
|
|
2462
|
+
const leftSubTreeRightMost = this.getRightMost((node) => node, curr.left);
|
|
2463
|
+
if (leftSubTreeRightMost) {
|
|
2464
|
+
const parentOfLeftSubTreeMax = leftSubTreeRightMost.parent;
|
|
2465
|
+
orgCurrent = this._swapProperties(curr, leftSubTreeRightMost);
|
|
2466
|
+
if (this._isMapMode) {
|
|
2467
|
+
this._store.set(curr.key, curr);
|
|
2468
|
+
this._store.set(leftSubTreeRightMost.key, leftSubTreeRightMost);
|
|
2469
|
+
}
|
|
2470
|
+
if (parentOfLeftSubTreeMax) {
|
|
2471
|
+
if (parentOfLeftSubTreeMax.right === leftSubTreeRightMost)
|
|
2472
|
+
parentOfLeftSubTreeMax.right = leftSubTreeRightMost.left;
|
|
2473
|
+
else parentOfLeftSubTreeMax.left = leftSubTreeRightMost.left;
|
|
2474
|
+
needBalanced = parentOfLeftSubTreeMax;
|
|
2475
|
+
}
|
|
2476
|
+
}
|
|
2477
|
+
} else if (parent) {
|
|
2478
|
+
const { familyPosition: fp } = curr;
|
|
2479
|
+
if (fp === "LEFT" || fp === "ROOT_LEFT") {
|
|
2480
|
+
parent.left = curr.right;
|
|
2481
|
+
} else if (fp === "RIGHT" || fp === "ROOT_RIGHT") {
|
|
2482
|
+
parent.right = curr.right;
|
|
2483
|
+
}
|
|
2484
|
+
needBalanced = parent;
|
|
2485
|
+
} else {
|
|
2486
|
+
this._setRoot(curr.right);
|
|
2487
|
+
curr.right = void 0;
|
|
2488
|
+
}
|
|
2489
|
+
this._size = this._size - 1;
|
|
2490
|
+
deletedResult.push({ deleted: orgCurrent, needBalanced });
|
|
2491
|
+
if (this._isMapMode && orgCurrent) this._store.delete(orgCurrent.key);
|
|
2492
|
+
return deletedResult;
|
|
2272
2493
|
}
|
|
2273
2494
|
/**
|
|
2274
2495
|
* Deletes a node from the tree.
|
|
2275
|
-
* @remarks Time O(
|
|
2496
|
+
* @remarks Time O(N) — O(N) to find the node + O(H) for predecessor swap. Space O(1). BST/Red-Black Tree/AVL Tree subclasses override to O(log N).
|
|
2276
2497
|
*
|
|
2277
2498
|
* @param keyNodeEntryRawOrPredicate - The node to delete.
|
|
2278
|
-
* @returns
|
|
2499
|
+
* @returns True if the node was found and deleted, false otherwise.
|
|
2500
|
+
|
|
2501
|
+
|
|
2502
|
+
|
|
2503
|
+
|
|
2504
|
+
|
|
2505
|
+
|
|
2506
|
+
|
|
2279
2507
|
|
|
2280
2508
|
|
|
2281
2509
|
|
|
@@ -2319,51 +2547,11 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
2319
2547
|
* console.log(tree.size); // 4;
|
|
2320
2548
|
*/
|
|
2321
2549
|
delete(keyNodeEntryRawOrPredicate) {
|
|
2322
|
-
|
|
2323
|
-
if (!this._root) return deletedResult;
|
|
2324
|
-
const curr = this.getNode(keyNodeEntryRawOrPredicate);
|
|
2325
|
-
if (!curr) return deletedResult;
|
|
2326
|
-
const parent = curr == null ? void 0 : curr.parent;
|
|
2327
|
-
let needBalanced;
|
|
2328
|
-
let orgCurrent = curr;
|
|
2329
|
-
if (!curr.left && !curr.right && !parent) {
|
|
2330
|
-
this._setRoot(void 0);
|
|
2331
|
-
} else if (curr.left) {
|
|
2332
|
-
const leftSubTreeRightMost = this.getRightMost((node) => node, curr.left);
|
|
2333
|
-
if (leftSubTreeRightMost) {
|
|
2334
|
-
const parentOfLeftSubTreeMax = leftSubTreeRightMost.parent;
|
|
2335
|
-
orgCurrent = this._swapProperties(curr, leftSubTreeRightMost);
|
|
2336
|
-
if (this._isMapMode) {
|
|
2337
|
-
this._store.set(curr.key, curr);
|
|
2338
|
-
this._store.set(leftSubTreeRightMost.key, leftSubTreeRightMost);
|
|
2339
|
-
}
|
|
2340
|
-
if (parentOfLeftSubTreeMax) {
|
|
2341
|
-
if (parentOfLeftSubTreeMax.right === leftSubTreeRightMost)
|
|
2342
|
-
parentOfLeftSubTreeMax.right = leftSubTreeRightMost.left;
|
|
2343
|
-
else parentOfLeftSubTreeMax.left = leftSubTreeRightMost.left;
|
|
2344
|
-
needBalanced = parentOfLeftSubTreeMax;
|
|
2345
|
-
}
|
|
2346
|
-
}
|
|
2347
|
-
} else if (parent) {
|
|
2348
|
-
const { familyPosition: fp } = curr;
|
|
2349
|
-
if (fp === "LEFT" || fp === "ROOT_LEFT") {
|
|
2350
|
-
parent.left = curr.right;
|
|
2351
|
-
} else if (fp === "RIGHT" || fp === "ROOT_RIGHT") {
|
|
2352
|
-
parent.right = curr.right;
|
|
2353
|
-
}
|
|
2354
|
-
needBalanced = parent;
|
|
2355
|
-
} else {
|
|
2356
|
-
this._setRoot(curr.right);
|
|
2357
|
-
curr.right = void 0;
|
|
2358
|
-
}
|
|
2359
|
-
this._size = this._size - 1;
|
|
2360
|
-
deletedResult.push({ deleted: orgCurrent, needBalanced });
|
|
2361
|
-
if (this._isMapMode && orgCurrent) this._store.delete(orgCurrent.key);
|
|
2362
|
-
return deletedResult;
|
|
2550
|
+
return this._deleteInternal(keyNodeEntryRawOrPredicate).length > 0;
|
|
2363
2551
|
}
|
|
2364
2552
|
/**
|
|
2365
2553
|
* Searches the tree for nodes matching a predicate.
|
|
2366
|
-
* @remarks Time O(
|
|
2554
|
+
* @remarks Time O(N) — full DFS scan; may visit every node. Space O(H) for call/explicit stack (O(N) worst-case). BST subclasses with key search override to O(log N).
|
|
2367
2555
|
*
|
|
2368
2556
|
* @template C - The type of the callback function.
|
|
2369
2557
|
* @param keyNodeEntryOrPredicate - The key, node, entry, or predicate function to search for.
|
|
@@ -2412,7 +2600,7 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
2412
2600
|
}
|
|
2413
2601
|
/**
|
|
2414
2602
|
* Gets the first node matching a predicate.
|
|
2415
|
-
* @remarks Time O(
|
|
2603
|
+
* @remarks Time O(N) via `search`. Space O(H) or O(N). BST/Red-Black Tree/AVL Tree subclasses override to O(log N) for key lookups.
|
|
2416
2604
|
*
|
|
2417
2605
|
* @param keyNodeEntryOrPredicate - The key, node, entry, or predicate function to search for.
|
|
2418
2606
|
* @param [startNode=this._root] - The node to start the search from.
|
|
@@ -2443,6 +2631,13 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
2443
2631
|
|
|
2444
2632
|
|
|
2445
2633
|
|
|
2634
|
+
|
|
2635
|
+
|
|
2636
|
+
|
|
2637
|
+
|
|
2638
|
+
|
|
2639
|
+
|
|
2640
|
+
|
|
2446
2641
|
|
|
2447
2642
|
|
|
2448
2643
|
|
|
@@ -2468,7 +2663,7 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
2468
2663
|
}
|
|
2469
2664
|
/**
|
|
2470
2665
|
* Gets the value associated with a key.
|
|
2471
|
-
* @remarks Time O(
|
|
2666
|
+
* @remarks Time O(1) in Map mode, O(N) otherwise (via `getNode`). Space O(1) in Map mode, O(H) or O(N) otherwise. BST subclasses override non-Map-mode to O(log N).
|
|
2472
2667
|
*
|
|
2473
2668
|
* @param keyNodeEntryOrPredicate - The key, node, or entry to get the value for.
|
|
2474
2669
|
* @param [startNode=this._root] - The node to start searching from (if not in Map mode).
|
|
@@ -2501,6 +2696,13 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
2501
2696
|
|
|
2502
2697
|
|
|
2503
2698
|
|
|
2699
|
+
|
|
2700
|
+
|
|
2701
|
+
|
|
2702
|
+
|
|
2703
|
+
|
|
2704
|
+
|
|
2705
|
+
|
|
2504
2706
|
|
|
2505
2707
|
|
|
2506
2708
|
|
|
@@ -2562,6 +2764,13 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
2562
2764
|
|
|
2563
2765
|
|
|
2564
2766
|
|
|
2767
|
+
|
|
2768
|
+
|
|
2769
|
+
|
|
2770
|
+
|
|
2771
|
+
|
|
2772
|
+
|
|
2773
|
+
|
|
2565
2774
|
|
|
2566
2775
|
|
|
2567
2776
|
|
|
@@ -2610,6 +2819,13 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
2610
2819
|
|
|
2611
2820
|
|
|
2612
2821
|
|
|
2822
|
+
|
|
2823
|
+
|
|
2824
|
+
|
|
2825
|
+
|
|
2826
|
+
|
|
2827
|
+
|
|
2828
|
+
|
|
2613
2829
|
|
|
2614
2830
|
|
|
2615
2831
|
|
|
@@ -2667,6 +2883,13 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
2667
2883
|
|
|
2668
2884
|
|
|
2669
2885
|
|
|
2886
|
+
|
|
2887
|
+
|
|
2888
|
+
|
|
2889
|
+
|
|
2890
|
+
|
|
2891
|
+
|
|
2892
|
+
|
|
2670
2893
|
|
|
2671
2894
|
|
|
2672
2895
|
|
|
@@ -2751,6 +2974,13 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
2751
2974
|
|
|
2752
2975
|
|
|
2753
2976
|
|
|
2977
|
+
|
|
2978
|
+
|
|
2979
|
+
|
|
2980
|
+
|
|
2981
|
+
|
|
2982
|
+
|
|
2983
|
+
|
|
2754
2984
|
|
|
2755
2985
|
|
|
2756
2986
|
|
|
@@ -2812,6 +3042,13 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
2812
3042
|
|
|
2813
3043
|
|
|
2814
3044
|
|
|
3045
|
+
|
|
3046
|
+
|
|
3047
|
+
|
|
3048
|
+
|
|
3049
|
+
|
|
3050
|
+
|
|
3051
|
+
|
|
2815
3052
|
|
|
2816
3053
|
|
|
2817
3054
|
|
|
@@ -3289,6 +3526,13 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
3289
3526
|
|
|
3290
3527
|
|
|
3291
3528
|
|
|
3529
|
+
|
|
3530
|
+
|
|
3531
|
+
|
|
3532
|
+
|
|
3533
|
+
|
|
3534
|
+
|
|
3535
|
+
|
|
3292
3536
|
|
|
3293
3537
|
|
|
3294
3538
|
|
|
@@ -3341,6 +3585,13 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
3341
3585
|
|
|
3342
3586
|
|
|
3343
3587
|
|
|
3588
|
+
|
|
3589
|
+
|
|
3590
|
+
|
|
3591
|
+
|
|
3592
|
+
|
|
3593
|
+
|
|
3594
|
+
|
|
3344
3595
|
|
|
3345
3596
|
|
|
3346
3597
|
|
|
@@ -3397,6 +3648,13 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
3397
3648
|
|
|
3398
3649
|
|
|
3399
3650
|
|
|
3651
|
+
|
|
3652
|
+
|
|
3653
|
+
|
|
3654
|
+
|
|
3655
|
+
|
|
3656
|
+
|
|
3657
|
+
|
|
3400
3658
|
|
|
3401
3659
|
|
|
3402
3660
|
|
|
@@ -3478,6 +3736,13 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
3478
3736
|
|
|
3479
3737
|
|
|
3480
3738
|
|
|
3739
|
+
|
|
3740
|
+
|
|
3741
|
+
|
|
3742
|
+
|
|
3743
|
+
|
|
3744
|
+
|
|
3745
|
+
|
|
3481
3746
|
|
|
3482
3747
|
|
|
3483
3748
|
|