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
|
@@ -282,6 +282,35 @@ var binaryTreeTyped = (() => {
|
|
|
282
282
|
for (const ele of this) if (ele === element) return true;
|
|
283
283
|
return false;
|
|
284
284
|
}
|
|
285
|
+
/**
|
|
286
|
+
* Check whether a value exists (Array-compatible alias for `has`).
|
|
287
|
+
* @remarks Provided for familiarity when migrating from Array. Time O(n), Space O(1).
|
|
288
|
+
* @param element - Element to search for (uses `===`).
|
|
289
|
+
* @returns `true` if found.
|
|
290
|
+
*/
|
|
291
|
+
includes(element) {
|
|
292
|
+
return this.has(element);
|
|
293
|
+
}
|
|
294
|
+
/**
|
|
295
|
+
* Return an iterator of `[index, value]` pairs (Array-compatible).
|
|
296
|
+
* @remarks Provided for familiarity when migrating from Array. Time O(n), Space O(1) per step.
|
|
297
|
+
*/
|
|
298
|
+
*entries() {
|
|
299
|
+
let index = 0;
|
|
300
|
+
for (const value of this) {
|
|
301
|
+
yield [index++, value];
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
/**
|
|
305
|
+
* Return an iterator of numeric indices (Array-compatible).
|
|
306
|
+
* @remarks Provided for familiarity when migrating from Array. Time O(n), Space O(1) per step.
|
|
307
|
+
*/
|
|
308
|
+
*keys() {
|
|
309
|
+
let index = 0;
|
|
310
|
+
for (const _ of this) {
|
|
311
|
+
yield index++;
|
|
312
|
+
}
|
|
313
|
+
}
|
|
285
314
|
/**
|
|
286
315
|
* Reduces all elements to a single accumulated value.
|
|
287
316
|
*
|
|
@@ -541,6 +570,16 @@ var binaryTreeTyped = (() => {
|
|
|
541
570
|
}
|
|
542
571
|
return this;
|
|
543
572
|
}
|
|
573
|
+
/**
|
|
574
|
+
* Return a new instance of the same type with elements in reverse order (non-mutating).
|
|
575
|
+
* @remarks Provided for familiarity when migrating from Array (ES2023 `toReversed`). Time O(n), Space O(n).
|
|
576
|
+
* @returns A new reversed instance.
|
|
577
|
+
*/
|
|
578
|
+
toReversed() {
|
|
579
|
+
const cloned = this.clone();
|
|
580
|
+
cloned.reverse();
|
|
581
|
+
return cloned;
|
|
582
|
+
}
|
|
544
583
|
};
|
|
545
584
|
|
|
546
585
|
// src/data-structures/base/iterable-entry-base.ts
|
|
@@ -806,6 +845,13 @@ var binaryTreeTyped = (() => {
|
|
|
806
845
|
|
|
807
846
|
|
|
808
847
|
|
|
848
|
+
|
|
849
|
+
|
|
850
|
+
|
|
851
|
+
|
|
852
|
+
|
|
853
|
+
|
|
854
|
+
|
|
809
855
|
|
|
810
856
|
|
|
811
857
|
|
|
@@ -856,6 +902,13 @@ var binaryTreeTyped = (() => {
|
|
|
856
902
|
|
|
857
903
|
|
|
858
904
|
|
|
905
|
+
|
|
906
|
+
|
|
907
|
+
|
|
908
|
+
|
|
909
|
+
|
|
910
|
+
|
|
911
|
+
|
|
859
912
|
|
|
860
913
|
|
|
861
914
|
|
|
@@ -873,6 +926,14 @@ var binaryTreeTyped = (() => {
|
|
|
873
926
|
get first() {
|
|
874
927
|
return this.length > 0 ? this.elements[this._offset] : void 0;
|
|
875
928
|
}
|
|
929
|
+
/**
|
|
930
|
+
* Peek at the front element without removing it (alias for `first`).
|
|
931
|
+
* @remarks Time O(1), Space O(1)
|
|
932
|
+
* @returns Front element or undefined.
|
|
933
|
+
*/
|
|
934
|
+
peek() {
|
|
935
|
+
return this.first;
|
|
936
|
+
}
|
|
876
937
|
/**
|
|
877
938
|
* Get the last element (back) without removing it.
|
|
878
939
|
* @remarks Time O(1), Space O(1)
|
|
@@ -922,6 +983,13 @@ var binaryTreeTyped = (() => {
|
|
|
922
983
|
|
|
923
984
|
|
|
924
985
|
|
|
986
|
+
|
|
987
|
+
|
|
988
|
+
|
|
989
|
+
|
|
990
|
+
|
|
991
|
+
|
|
992
|
+
|
|
925
993
|
|
|
926
994
|
|
|
927
995
|
|
|
@@ -984,6 +1052,13 @@ var binaryTreeTyped = (() => {
|
|
|
984
1052
|
|
|
985
1053
|
|
|
986
1054
|
|
|
1055
|
+
|
|
1056
|
+
|
|
1057
|
+
|
|
1058
|
+
|
|
1059
|
+
|
|
1060
|
+
|
|
1061
|
+
|
|
987
1062
|
|
|
988
1063
|
|
|
989
1064
|
|
|
@@ -1053,6 +1128,13 @@ var binaryTreeTyped = (() => {
|
|
|
1053
1128
|
|
|
1054
1129
|
|
|
1055
1130
|
|
|
1131
|
+
|
|
1132
|
+
|
|
1133
|
+
|
|
1134
|
+
|
|
1135
|
+
|
|
1136
|
+
|
|
1137
|
+
|
|
1056
1138
|
|
|
1057
1139
|
|
|
1058
1140
|
|
|
@@ -1112,6 +1194,13 @@ var binaryTreeTyped = (() => {
|
|
|
1112
1194
|
|
|
1113
1195
|
|
|
1114
1196
|
|
|
1197
|
+
|
|
1198
|
+
|
|
1199
|
+
|
|
1200
|
+
|
|
1201
|
+
|
|
1202
|
+
|
|
1203
|
+
|
|
1115
1204
|
|
|
1116
1205
|
|
|
1117
1206
|
|
|
@@ -1164,6 +1253,13 @@ var binaryTreeTyped = (() => {
|
|
|
1164
1253
|
|
|
1165
1254
|
|
|
1166
1255
|
|
|
1256
|
+
|
|
1257
|
+
|
|
1258
|
+
|
|
1259
|
+
|
|
1260
|
+
|
|
1261
|
+
|
|
1262
|
+
|
|
1167
1263
|
|
|
1168
1264
|
|
|
1169
1265
|
|
|
@@ -1218,6 +1314,21 @@ var binaryTreeTyped = (() => {
|
|
|
1218
1314
|
this._elements[this._offset + index] = newElement;
|
|
1219
1315
|
return true;
|
|
1220
1316
|
}
|
|
1317
|
+
/**
|
|
1318
|
+
* Delete the first element that satisfies a predicate.
|
|
1319
|
+
* @remarks Time O(N), Space O(N)
|
|
1320
|
+
* @param predicate - Function (value, index, queue) → boolean to decide deletion.
|
|
1321
|
+
* @returns True if a match was removed.
|
|
1322
|
+
*/
|
|
1323
|
+
deleteWhere(predicate) {
|
|
1324
|
+
for (let i = 0; i < this.length; i++) {
|
|
1325
|
+
if (predicate(this._elements[this._offset + i], i, this)) {
|
|
1326
|
+
this.deleteAt(i);
|
|
1327
|
+
return true;
|
|
1328
|
+
}
|
|
1329
|
+
}
|
|
1330
|
+
return false;
|
|
1331
|
+
}
|
|
1221
1332
|
/**
|
|
1222
1333
|
* Reverse the queue in-place by compacting then reversing.
|
|
1223
1334
|
* @remarks Time O(N), Space O(N)
|
|
@@ -1257,6 +1368,13 @@ var binaryTreeTyped = (() => {
|
|
|
1257
1368
|
|
|
1258
1369
|
|
|
1259
1370
|
|
|
1371
|
+
|
|
1372
|
+
|
|
1373
|
+
|
|
1374
|
+
|
|
1375
|
+
|
|
1376
|
+
|
|
1377
|
+
|
|
1260
1378
|
|
|
1261
1379
|
|
|
1262
1380
|
|
|
@@ -1303,6 +1421,13 @@ var binaryTreeTyped = (() => {
|
|
|
1303
1421
|
|
|
1304
1422
|
|
|
1305
1423
|
|
|
1424
|
+
|
|
1425
|
+
|
|
1426
|
+
|
|
1427
|
+
|
|
1428
|
+
|
|
1429
|
+
|
|
1430
|
+
|
|
1306
1431
|
|
|
1307
1432
|
|
|
1308
1433
|
|
|
@@ -1372,6 +1497,13 @@ var binaryTreeTyped = (() => {
|
|
|
1372
1497
|
|
|
1373
1498
|
|
|
1374
1499
|
|
|
1500
|
+
|
|
1501
|
+
|
|
1502
|
+
|
|
1503
|
+
|
|
1504
|
+
|
|
1505
|
+
|
|
1506
|
+
|
|
1375
1507
|
|
|
1376
1508
|
|
|
1377
1509
|
|
|
@@ -1425,6 +1557,13 @@ var binaryTreeTyped = (() => {
|
|
|
1425
1557
|
|
|
1426
1558
|
|
|
1427
1559
|
|
|
1560
|
+
|
|
1561
|
+
|
|
1562
|
+
|
|
1563
|
+
|
|
1564
|
+
|
|
1565
|
+
|
|
1566
|
+
|
|
1428
1567
|
|
|
1429
1568
|
|
|
1430
1569
|
|
|
@@ -1482,6 +1621,13 @@ var binaryTreeTyped = (() => {
|
|
|
1482
1621
|
|
|
1483
1622
|
|
|
1484
1623
|
|
|
1624
|
+
|
|
1625
|
+
|
|
1626
|
+
|
|
1627
|
+
|
|
1628
|
+
|
|
1629
|
+
|
|
1630
|
+
|
|
1485
1631
|
|
|
1486
1632
|
|
|
1487
1633
|
|
|
@@ -1960,7 +2106,7 @@ var binaryTreeTyped = (() => {
|
|
|
1960
2106
|
}
|
|
1961
2107
|
/**
|
|
1962
2108
|
* Adds a new node to the tree.
|
|
1963
|
-
* @remarks Time O(
|
|
2109
|
+
* @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).
|
|
1964
2110
|
*
|
|
1965
2111
|
* @param keyNodeOrEntry - The key, node, or entry to add.
|
|
1966
2112
|
* @returns True if the addition was successful, false otherwise.
|
|
@@ -1986,6 +2132,13 @@ var binaryTreeTyped = (() => {
|
|
|
1986
2132
|
|
|
1987
2133
|
|
|
1988
2134
|
|
|
2135
|
+
|
|
2136
|
+
|
|
2137
|
+
|
|
2138
|
+
|
|
2139
|
+
|
|
2140
|
+
|
|
2141
|
+
|
|
1989
2142
|
|
|
1990
2143
|
|
|
1991
2144
|
|
|
@@ -2008,7 +2161,7 @@ var binaryTreeTyped = (() => {
|
|
|
2008
2161
|
}
|
|
2009
2162
|
/**
|
|
2010
2163
|
* Adds or updates a new node to the tree.
|
|
2011
|
-
* @remarks Time O(
|
|
2164
|
+
* @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).
|
|
2012
2165
|
*
|
|
2013
2166
|
* @param keyNodeOrEntry - The key, node, or entry to set or update.
|
|
2014
2167
|
* @param [value] - The value, if providing just a key.
|
|
@@ -2040,6 +2193,13 @@ var binaryTreeTyped = (() => {
|
|
|
2040
2193
|
|
|
2041
2194
|
|
|
2042
2195
|
|
|
2196
|
+
|
|
2197
|
+
|
|
2198
|
+
|
|
2199
|
+
|
|
2200
|
+
|
|
2201
|
+
|
|
2202
|
+
|
|
2043
2203
|
|
|
2044
2204
|
|
|
2045
2205
|
|
|
@@ -2146,6 +2306,13 @@ var binaryTreeTyped = (() => {
|
|
|
2146
2306
|
|
|
2147
2307
|
|
|
2148
2308
|
|
|
2309
|
+
|
|
2310
|
+
|
|
2311
|
+
|
|
2312
|
+
|
|
2313
|
+
|
|
2314
|
+
|
|
2315
|
+
|
|
2149
2316
|
|
|
2150
2317
|
|
|
2151
2318
|
|
|
@@ -2188,6 +2355,13 @@ var binaryTreeTyped = (() => {
|
|
|
2188
2355
|
|
|
2189
2356
|
|
|
2190
2357
|
|
|
2358
|
+
|
|
2359
|
+
|
|
2360
|
+
|
|
2361
|
+
|
|
2362
|
+
|
|
2363
|
+
|
|
2364
|
+
|
|
2191
2365
|
|
|
2192
2366
|
|
|
2193
2367
|
|
|
@@ -2251,6 +2425,13 @@ var binaryTreeTyped = (() => {
|
|
|
2251
2425
|
|
|
2252
2426
|
|
|
2253
2427
|
|
|
2428
|
+
|
|
2429
|
+
|
|
2430
|
+
|
|
2431
|
+
|
|
2432
|
+
|
|
2433
|
+
|
|
2434
|
+
|
|
2254
2435
|
|
|
2255
2436
|
|
|
2256
2437
|
|
|
@@ -2270,22 +2451,69 @@ var binaryTreeTyped = (() => {
|
|
|
2270
2451
|
this.setMany(anotherTree, []);
|
|
2271
2452
|
}
|
|
2272
2453
|
/**
|
|
2273
|
-
*
|
|
2274
|
-
* @remarks Time O(N)
|
|
2454
|
+
* Deletes a node from the tree (internal, returns balancing metadata).
|
|
2455
|
+
* @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).
|
|
2456
|
+
* @internal Used by AVL/BST subclasses that need balancing metadata after deletion.
|
|
2275
2457
|
*
|
|
2276
|
-
* @param
|
|
2277
|
-
* @
|
|
2458
|
+
* @param keyNodeEntryRawOrPredicate - The node to delete.
|
|
2459
|
+
* @returns An array containing deletion results with balancing metadata.
|
|
2278
2460
|
*/
|
|
2279
|
-
|
|
2280
|
-
|
|
2281
|
-
this.
|
|
2461
|
+
_deleteInternal(keyNodeEntryRawOrPredicate) {
|
|
2462
|
+
const deletedResult = [];
|
|
2463
|
+
if (!this._root) return deletedResult;
|
|
2464
|
+
const curr = this.getNode(keyNodeEntryRawOrPredicate);
|
|
2465
|
+
if (!curr) return deletedResult;
|
|
2466
|
+
const parent = curr == null ? void 0 : curr.parent;
|
|
2467
|
+
let needBalanced;
|
|
2468
|
+
let orgCurrent = curr;
|
|
2469
|
+
if (!curr.left && !curr.right && !parent) {
|
|
2470
|
+
this._setRoot(void 0);
|
|
2471
|
+
} else if (curr.left) {
|
|
2472
|
+
const leftSubTreeRightMost = this.getRightMost((node) => node, curr.left);
|
|
2473
|
+
if (leftSubTreeRightMost) {
|
|
2474
|
+
const parentOfLeftSubTreeMax = leftSubTreeRightMost.parent;
|
|
2475
|
+
orgCurrent = this._swapProperties(curr, leftSubTreeRightMost);
|
|
2476
|
+
if (this._isMapMode) {
|
|
2477
|
+
this._store.set(curr.key, curr);
|
|
2478
|
+
this._store.set(leftSubTreeRightMost.key, leftSubTreeRightMost);
|
|
2479
|
+
}
|
|
2480
|
+
if (parentOfLeftSubTreeMax) {
|
|
2481
|
+
if (parentOfLeftSubTreeMax.right === leftSubTreeRightMost)
|
|
2482
|
+
parentOfLeftSubTreeMax.right = leftSubTreeRightMost.left;
|
|
2483
|
+
else parentOfLeftSubTreeMax.left = leftSubTreeRightMost.left;
|
|
2484
|
+
needBalanced = parentOfLeftSubTreeMax;
|
|
2485
|
+
}
|
|
2486
|
+
}
|
|
2487
|
+
} else if (parent) {
|
|
2488
|
+
const { familyPosition: fp } = curr;
|
|
2489
|
+
if (fp === "LEFT" || fp === "ROOT_LEFT") {
|
|
2490
|
+
parent.left = curr.right;
|
|
2491
|
+
} else if (fp === "RIGHT" || fp === "ROOT_RIGHT") {
|
|
2492
|
+
parent.right = curr.right;
|
|
2493
|
+
}
|
|
2494
|
+
needBalanced = parent;
|
|
2495
|
+
} else {
|
|
2496
|
+
this._setRoot(curr.right);
|
|
2497
|
+
curr.right = void 0;
|
|
2498
|
+
}
|
|
2499
|
+
this._size = this._size - 1;
|
|
2500
|
+
deletedResult.push({ deleted: orgCurrent, needBalanced });
|
|
2501
|
+
if (this._isMapMode && orgCurrent) this._store.delete(orgCurrent.key);
|
|
2502
|
+
return deletedResult;
|
|
2282
2503
|
}
|
|
2283
2504
|
/**
|
|
2284
2505
|
* Deletes a node from the tree.
|
|
2285
|
-
* @remarks Time O(
|
|
2506
|
+
* @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).
|
|
2286
2507
|
*
|
|
2287
2508
|
* @param keyNodeEntryRawOrPredicate - The node to delete.
|
|
2288
|
-
* @returns
|
|
2509
|
+
* @returns True if the node was found and deleted, false otherwise.
|
|
2510
|
+
|
|
2511
|
+
|
|
2512
|
+
|
|
2513
|
+
|
|
2514
|
+
|
|
2515
|
+
|
|
2516
|
+
|
|
2289
2517
|
|
|
2290
2518
|
|
|
2291
2519
|
|
|
@@ -2329,51 +2557,11 @@ var binaryTreeTyped = (() => {
|
|
|
2329
2557
|
* console.log(tree.size); // 4;
|
|
2330
2558
|
*/
|
|
2331
2559
|
delete(keyNodeEntryRawOrPredicate) {
|
|
2332
|
-
|
|
2333
|
-
if (!this._root) return deletedResult;
|
|
2334
|
-
const curr = this.getNode(keyNodeEntryRawOrPredicate);
|
|
2335
|
-
if (!curr) return deletedResult;
|
|
2336
|
-
const parent = curr == null ? void 0 : curr.parent;
|
|
2337
|
-
let needBalanced;
|
|
2338
|
-
let orgCurrent = curr;
|
|
2339
|
-
if (!curr.left && !curr.right && !parent) {
|
|
2340
|
-
this._setRoot(void 0);
|
|
2341
|
-
} else if (curr.left) {
|
|
2342
|
-
const leftSubTreeRightMost = this.getRightMost((node) => node, curr.left);
|
|
2343
|
-
if (leftSubTreeRightMost) {
|
|
2344
|
-
const parentOfLeftSubTreeMax = leftSubTreeRightMost.parent;
|
|
2345
|
-
orgCurrent = this._swapProperties(curr, leftSubTreeRightMost);
|
|
2346
|
-
if (this._isMapMode) {
|
|
2347
|
-
this._store.set(curr.key, curr);
|
|
2348
|
-
this._store.set(leftSubTreeRightMost.key, leftSubTreeRightMost);
|
|
2349
|
-
}
|
|
2350
|
-
if (parentOfLeftSubTreeMax) {
|
|
2351
|
-
if (parentOfLeftSubTreeMax.right === leftSubTreeRightMost)
|
|
2352
|
-
parentOfLeftSubTreeMax.right = leftSubTreeRightMost.left;
|
|
2353
|
-
else parentOfLeftSubTreeMax.left = leftSubTreeRightMost.left;
|
|
2354
|
-
needBalanced = parentOfLeftSubTreeMax;
|
|
2355
|
-
}
|
|
2356
|
-
}
|
|
2357
|
-
} else if (parent) {
|
|
2358
|
-
const { familyPosition: fp } = curr;
|
|
2359
|
-
if (fp === "LEFT" || fp === "ROOT_LEFT") {
|
|
2360
|
-
parent.left = curr.right;
|
|
2361
|
-
} else if (fp === "RIGHT" || fp === "ROOT_RIGHT") {
|
|
2362
|
-
parent.right = curr.right;
|
|
2363
|
-
}
|
|
2364
|
-
needBalanced = parent;
|
|
2365
|
-
} else {
|
|
2366
|
-
this._setRoot(curr.right);
|
|
2367
|
-
curr.right = void 0;
|
|
2368
|
-
}
|
|
2369
|
-
this._size = this._size - 1;
|
|
2370
|
-
deletedResult.push({ deleted: orgCurrent, needBalanced });
|
|
2371
|
-
if (this._isMapMode && orgCurrent) this._store.delete(orgCurrent.key);
|
|
2372
|
-
return deletedResult;
|
|
2560
|
+
return this._deleteInternal(keyNodeEntryRawOrPredicate).length > 0;
|
|
2373
2561
|
}
|
|
2374
2562
|
/**
|
|
2375
2563
|
* Searches the tree for nodes matching a predicate.
|
|
2376
|
-
* @remarks Time O(
|
|
2564
|
+
* @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).
|
|
2377
2565
|
*
|
|
2378
2566
|
* @template C - The type of the callback function.
|
|
2379
2567
|
* @param keyNodeEntryOrPredicate - The key, node, entry, or predicate function to search for.
|
|
@@ -2422,7 +2610,7 @@ var binaryTreeTyped = (() => {
|
|
|
2422
2610
|
}
|
|
2423
2611
|
/**
|
|
2424
2612
|
* Gets the first node matching a predicate.
|
|
2425
|
-
* @remarks Time O(
|
|
2613
|
+
* @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.
|
|
2426
2614
|
*
|
|
2427
2615
|
* @param keyNodeEntryOrPredicate - The key, node, entry, or predicate function to search for.
|
|
2428
2616
|
* @param [startNode=this._root] - The node to start the search from.
|
|
@@ -2453,6 +2641,13 @@ var binaryTreeTyped = (() => {
|
|
|
2453
2641
|
|
|
2454
2642
|
|
|
2455
2643
|
|
|
2644
|
+
|
|
2645
|
+
|
|
2646
|
+
|
|
2647
|
+
|
|
2648
|
+
|
|
2649
|
+
|
|
2650
|
+
|
|
2456
2651
|
|
|
2457
2652
|
|
|
2458
2653
|
|
|
@@ -2478,7 +2673,7 @@ var binaryTreeTyped = (() => {
|
|
|
2478
2673
|
}
|
|
2479
2674
|
/**
|
|
2480
2675
|
* Gets the value associated with a key.
|
|
2481
|
-
* @remarks Time O(
|
|
2676
|
+
* @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).
|
|
2482
2677
|
*
|
|
2483
2678
|
* @param keyNodeEntryOrPredicate - The key, node, or entry to get the value for.
|
|
2484
2679
|
* @param [startNode=this._root] - The node to start searching from (if not in Map mode).
|
|
@@ -2511,6 +2706,13 @@ var binaryTreeTyped = (() => {
|
|
|
2511
2706
|
|
|
2512
2707
|
|
|
2513
2708
|
|
|
2709
|
+
|
|
2710
|
+
|
|
2711
|
+
|
|
2712
|
+
|
|
2713
|
+
|
|
2714
|
+
|
|
2715
|
+
|
|
2514
2716
|
|
|
2515
2717
|
|
|
2516
2718
|
|
|
@@ -2572,6 +2774,13 @@ var binaryTreeTyped = (() => {
|
|
|
2572
2774
|
|
|
2573
2775
|
|
|
2574
2776
|
|
|
2777
|
+
|
|
2778
|
+
|
|
2779
|
+
|
|
2780
|
+
|
|
2781
|
+
|
|
2782
|
+
|
|
2783
|
+
|
|
2575
2784
|
|
|
2576
2785
|
|
|
2577
2786
|
|
|
@@ -2620,6 +2829,13 @@ var binaryTreeTyped = (() => {
|
|
|
2620
2829
|
|
|
2621
2830
|
|
|
2622
2831
|
|
|
2832
|
+
|
|
2833
|
+
|
|
2834
|
+
|
|
2835
|
+
|
|
2836
|
+
|
|
2837
|
+
|
|
2838
|
+
|
|
2623
2839
|
|
|
2624
2840
|
|
|
2625
2841
|
|
|
@@ -2677,6 +2893,13 @@ var binaryTreeTyped = (() => {
|
|
|
2677
2893
|
|
|
2678
2894
|
|
|
2679
2895
|
|
|
2896
|
+
|
|
2897
|
+
|
|
2898
|
+
|
|
2899
|
+
|
|
2900
|
+
|
|
2901
|
+
|
|
2902
|
+
|
|
2680
2903
|
|
|
2681
2904
|
|
|
2682
2905
|
|
|
@@ -2761,6 +2984,13 @@ var binaryTreeTyped = (() => {
|
|
|
2761
2984
|
|
|
2762
2985
|
|
|
2763
2986
|
|
|
2987
|
+
|
|
2988
|
+
|
|
2989
|
+
|
|
2990
|
+
|
|
2991
|
+
|
|
2992
|
+
|
|
2993
|
+
|
|
2764
2994
|
|
|
2765
2995
|
|
|
2766
2996
|
|
|
@@ -2822,6 +3052,13 @@ var binaryTreeTyped = (() => {
|
|
|
2822
3052
|
|
|
2823
3053
|
|
|
2824
3054
|
|
|
3055
|
+
|
|
3056
|
+
|
|
3057
|
+
|
|
3058
|
+
|
|
3059
|
+
|
|
3060
|
+
|
|
3061
|
+
|
|
2825
3062
|
|
|
2826
3063
|
|
|
2827
3064
|
|
|
@@ -3299,6 +3536,13 @@ var binaryTreeTyped = (() => {
|
|
|
3299
3536
|
|
|
3300
3537
|
|
|
3301
3538
|
|
|
3539
|
+
|
|
3540
|
+
|
|
3541
|
+
|
|
3542
|
+
|
|
3543
|
+
|
|
3544
|
+
|
|
3545
|
+
|
|
3302
3546
|
|
|
3303
3547
|
|
|
3304
3548
|
|
|
@@ -3351,6 +3595,13 @@ var binaryTreeTyped = (() => {
|
|
|
3351
3595
|
|
|
3352
3596
|
|
|
3353
3597
|
|
|
3598
|
+
|
|
3599
|
+
|
|
3600
|
+
|
|
3601
|
+
|
|
3602
|
+
|
|
3603
|
+
|
|
3604
|
+
|
|
3354
3605
|
|
|
3355
3606
|
|
|
3356
3607
|
|
|
@@ -3407,6 +3658,13 @@ var binaryTreeTyped = (() => {
|
|
|
3407
3658
|
|
|
3408
3659
|
|
|
3409
3660
|
|
|
3661
|
+
|
|
3662
|
+
|
|
3663
|
+
|
|
3664
|
+
|
|
3665
|
+
|
|
3666
|
+
|
|
3667
|
+
|
|
3410
3668
|
|
|
3411
3669
|
|
|
3412
3670
|
|
|
@@ -3488,6 +3746,13 @@ var binaryTreeTyped = (() => {
|
|
|
3488
3746
|
|
|
3489
3747
|
|
|
3490
3748
|
|
|
3749
|
+
|
|
3750
|
+
|
|
3751
|
+
|
|
3752
|
+
|
|
3753
|
+
|
|
3754
|
+
|
|
3755
|
+
|
|
3491
3756
|
|
|
3492
3757
|
|
|
3493
3758
|
|