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
|
@@ -264,6 +264,35 @@ var _IterableElementBase = class _IterableElementBase {
|
|
|
264
264
|
for (const ele of this) if (ele === element) return true;
|
|
265
265
|
return false;
|
|
266
266
|
}
|
|
267
|
+
/**
|
|
268
|
+
* Check whether a value exists (Array-compatible alias for `has`).
|
|
269
|
+
* @remarks Provided for familiarity when migrating from Array. Time O(n), Space O(1).
|
|
270
|
+
* @param element - Element to search for (uses `===`).
|
|
271
|
+
* @returns `true` if found.
|
|
272
|
+
*/
|
|
273
|
+
includes(element) {
|
|
274
|
+
return this.has(element);
|
|
275
|
+
}
|
|
276
|
+
/**
|
|
277
|
+
* Return an iterator of `[index, value]` pairs (Array-compatible).
|
|
278
|
+
* @remarks Provided for familiarity when migrating from Array. Time O(n), Space O(1) per step.
|
|
279
|
+
*/
|
|
280
|
+
*entries() {
|
|
281
|
+
let index = 0;
|
|
282
|
+
for (const value of this) {
|
|
283
|
+
yield [index++, value];
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
/**
|
|
287
|
+
* Return an iterator of numeric indices (Array-compatible).
|
|
288
|
+
* @remarks Provided for familiarity when migrating from Array. Time O(n), Space O(1) per step.
|
|
289
|
+
*/
|
|
290
|
+
*keys() {
|
|
291
|
+
let index = 0;
|
|
292
|
+
for (const _ of this) {
|
|
293
|
+
yield index++;
|
|
294
|
+
}
|
|
295
|
+
}
|
|
267
296
|
/**
|
|
268
297
|
* Reduces all elements to a single accumulated value.
|
|
269
298
|
*
|
|
@@ -525,6 +554,16 @@ var _LinearBase = class _LinearBase extends IterableElementBase {
|
|
|
525
554
|
}
|
|
526
555
|
return this;
|
|
527
556
|
}
|
|
557
|
+
/**
|
|
558
|
+
* Return a new instance of the same type with elements in reverse order (non-mutating).
|
|
559
|
+
* @remarks Provided for familiarity when migrating from Array (ES2023 `toReversed`). Time O(n), Space O(n).
|
|
560
|
+
* @returns A new reversed instance.
|
|
561
|
+
*/
|
|
562
|
+
toReversed() {
|
|
563
|
+
const cloned = this.clone();
|
|
564
|
+
cloned.reverse();
|
|
565
|
+
return cloned;
|
|
566
|
+
}
|
|
528
567
|
};
|
|
529
568
|
__name(_LinearBase, "LinearBase");
|
|
530
569
|
var LinearBase = _LinearBase;
|
|
@@ -794,6 +833,13 @@ var _Queue = class _Queue extends LinearBase {
|
|
|
794
833
|
|
|
795
834
|
|
|
796
835
|
|
|
836
|
+
|
|
837
|
+
|
|
838
|
+
|
|
839
|
+
|
|
840
|
+
|
|
841
|
+
|
|
842
|
+
|
|
797
843
|
|
|
798
844
|
|
|
799
845
|
|
|
@@ -844,6 +890,13 @@ var _Queue = class _Queue extends LinearBase {
|
|
|
844
890
|
|
|
845
891
|
|
|
846
892
|
|
|
893
|
+
|
|
894
|
+
|
|
895
|
+
|
|
896
|
+
|
|
897
|
+
|
|
898
|
+
|
|
899
|
+
|
|
847
900
|
|
|
848
901
|
|
|
849
902
|
|
|
@@ -861,6 +914,14 @@ var _Queue = class _Queue extends LinearBase {
|
|
|
861
914
|
get first() {
|
|
862
915
|
return this.length > 0 ? this.elements[this._offset] : void 0;
|
|
863
916
|
}
|
|
917
|
+
/**
|
|
918
|
+
* Peek at the front element without removing it (alias for `first`).
|
|
919
|
+
* @remarks Time O(1), Space O(1)
|
|
920
|
+
* @returns Front element or undefined.
|
|
921
|
+
*/
|
|
922
|
+
peek() {
|
|
923
|
+
return this.first;
|
|
924
|
+
}
|
|
864
925
|
/**
|
|
865
926
|
* Get the last element (back) without removing it.
|
|
866
927
|
* @remarks Time O(1), Space O(1)
|
|
@@ -910,6 +971,13 @@ var _Queue = class _Queue extends LinearBase {
|
|
|
910
971
|
|
|
911
972
|
|
|
912
973
|
|
|
974
|
+
|
|
975
|
+
|
|
976
|
+
|
|
977
|
+
|
|
978
|
+
|
|
979
|
+
|
|
980
|
+
|
|
913
981
|
|
|
914
982
|
|
|
915
983
|
|
|
@@ -972,6 +1040,13 @@ var _Queue = class _Queue extends LinearBase {
|
|
|
972
1040
|
|
|
973
1041
|
|
|
974
1042
|
|
|
1043
|
+
|
|
1044
|
+
|
|
1045
|
+
|
|
1046
|
+
|
|
1047
|
+
|
|
1048
|
+
|
|
1049
|
+
|
|
975
1050
|
|
|
976
1051
|
|
|
977
1052
|
|
|
@@ -1041,6 +1116,13 @@ var _Queue = class _Queue extends LinearBase {
|
|
|
1041
1116
|
|
|
1042
1117
|
|
|
1043
1118
|
|
|
1119
|
+
|
|
1120
|
+
|
|
1121
|
+
|
|
1122
|
+
|
|
1123
|
+
|
|
1124
|
+
|
|
1125
|
+
|
|
1044
1126
|
|
|
1045
1127
|
|
|
1046
1128
|
|
|
@@ -1100,6 +1182,13 @@ var _Queue = class _Queue extends LinearBase {
|
|
|
1100
1182
|
|
|
1101
1183
|
|
|
1102
1184
|
|
|
1185
|
+
|
|
1186
|
+
|
|
1187
|
+
|
|
1188
|
+
|
|
1189
|
+
|
|
1190
|
+
|
|
1191
|
+
|
|
1103
1192
|
|
|
1104
1193
|
|
|
1105
1194
|
|
|
@@ -1152,6 +1241,13 @@ var _Queue = class _Queue extends LinearBase {
|
|
|
1152
1241
|
|
|
1153
1242
|
|
|
1154
1243
|
|
|
1244
|
+
|
|
1245
|
+
|
|
1246
|
+
|
|
1247
|
+
|
|
1248
|
+
|
|
1249
|
+
|
|
1250
|
+
|
|
1155
1251
|
|
|
1156
1252
|
|
|
1157
1253
|
|
|
@@ -1206,6 +1302,21 @@ var _Queue = class _Queue extends LinearBase {
|
|
|
1206
1302
|
this._elements[this._offset + index] = newElement;
|
|
1207
1303
|
return true;
|
|
1208
1304
|
}
|
|
1305
|
+
/**
|
|
1306
|
+
* Delete the first element that satisfies a predicate.
|
|
1307
|
+
* @remarks Time O(N), Space O(N)
|
|
1308
|
+
* @param predicate - Function (value, index, queue) → boolean to decide deletion.
|
|
1309
|
+
* @returns True if a match was removed.
|
|
1310
|
+
*/
|
|
1311
|
+
deleteWhere(predicate) {
|
|
1312
|
+
for (let i = 0; i < this.length; i++) {
|
|
1313
|
+
if (predicate(this._elements[this._offset + i], i, this)) {
|
|
1314
|
+
this.deleteAt(i);
|
|
1315
|
+
return true;
|
|
1316
|
+
}
|
|
1317
|
+
}
|
|
1318
|
+
return false;
|
|
1319
|
+
}
|
|
1209
1320
|
/**
|
|
1210
1321
|
* Reverse the queue in-place by compacting then reversing.
|
|
1211
1322
|
* @remarks Time O(N), Space O(N)
|
|
@@ -1245,6 +1356,13 @@ var _Queue = class _Queue extends LinearBase {
|
|
|
1245
1356
|
|
|
1246
1357
|
|
|
1247
1358
|
|
|
1359
|
+
|
|
1360
|
+
|
|
1361
|
+
|
|
1362
|
+
|
|
1363
|
+
|
|
1364
|
+
|
|
1365
|
+
|
|
1248
1366
|
|
|
1249
1367
|
|
|
1250
1368
|
|
|
@@ -1291,6 +1409,13 @@ var _Queue = class _Queue extends LinearBase {
|
|
|
1291
1409
|
|
|
1292
1410
|
|
|
1293
1411
|
|
|
1412
|
+
|
|
1413
|
+
|
|
1414
|
+
|
|
1415
|
+
|
|
1416
|
+
|
|
1417
|
+
|
|
1418
|
+
|
|
1294
1419
|
|
|
1295
1420
|
|
|
1296
1421
|
|
|
@@ -1360,6 +1485,13 @@ var _Queue = class _Queue extends LinearBase {
|
|
|
1360
1485
|
|
|
1361
1486
|
|
|
1362
1487
|
|
|
1488
|
+
|
|
1489
|
+
|
|
1490
|
+
|
|
1491
|
+
|
|
1492
|
+
|
|
1493
|
+
|
|
1494
|
+
|
|
1363
1495
|
|
|
1364
1496
|
|
|
1365
1497
|
|
|
@@ -1413,6 +1545,13 @@ var _Queue = class _Queue extends LinearBase {
|
|
|
1413
1545
|
|
|
1414
1546
|
|
|
1415
1547
|
|
|
1548
|
+
|
|
1549
|
+
|
|
1550
|
+
|
|
1551
|
+
|
|
1552
|
+
|
|
1553
|
+
|
|
1554
|
+
|
|
1416
1555
|
|
|
1417
1556
|
|
|
1418
1557
|
|
|
@@ -1470,6 +1609,13 @@ var _Queue = class _Queue extends LinearBase {
|
|
|
1470
1609
|
|
|
1471
1610
|
|
|
1472
1611
|
|
|
1612
|
+
|
|
1613
|
+
|
|
1614
|
+
|
|
1615
|
+
|
|
1616
|
+
|
|
1617
|
+
|
|
1618
|
+
|
|
1473
1619
|
|
|
1474
1620
|
|
|
1475
1621
|
|
|
@@ -1952,7 +2098,7 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
1952
2098
|
}
|
|
1953
2099
|
/**
|
|
1954
2100
|
* Adds a new node to the tree.
|
|
1955
|
-
* @remarks Time O(
|
|
2101
|
+
* @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).
|
|
1956
2102
|
*
|
|
1957
2103
|
* @param keyNodeOrEntry - The key, node, or entry to add.
|
|
1958
2104
|
* @returns True if the addition was successful, false otherwise.
|
|
@@ -1978,6 +2124,13 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
1978
2124
|
|
|
1979
2125
|
|
|
1980
2126
|
|
|
2127
|
+
|
|
2128
|
+
|
|
2129
|
+
|
|
2130
|
+
|
|
2131
|
+
|
|
2132
|
+
|
|
2133
|
+
|
|
1981
2134
|
|
|
1982
2135
|
|
|
1983
2136
|
|
|
@@ -2000,7 +2153,7 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
2000
2153
|
}
|
|
2001
2154
|
/**
|
|
2002
2155
|
* Adds or updates a new node to the tree.
|
|
2003
|
-
* @remarks Time O(
|
|
2156
|
+
* @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).
|
|
2004
2157
|
*
|
|
2005
2158
|
* @param keyNodeOrEntry - The key, node, or entry to set or update.
|
|
2006
2159
|
* @param [value] - The value, if providing just a key.
|
|
@@ -2032,6 +2185,13 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
2032
2185
|
|
|
2033
2186
|
|
|
2034
2187
|
|
|
2188
|
+
|
|
2189
|
+
|
|
2190
|
+
|
|
2191
|
+
|
|
2192
|
+
|
|
2193
|
+
|
|
2194
|
+
|
|
2035
2195
|
|
|
2036
2196
|
|
|
2037
2197
|
|
|
@@ -2138,6 +2298,13 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
2138
2298
|
|
|
2139
2299
|
|
|
2140
2300
|
|
|
2301
|
+
|
|
2302
|
+
|
|
2303
|
+
|
|
2304
|
+
|
|
2305
|
+
|
|
2306
|
+
|
|
2307
|
+
|
|
2141
2308
|
|
|
2142
2309
|
|
|
2143
2310
|
|
|
@@ -2180,6 +2347,13 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
2180
2347
|
|
|
2181
2348
|
|
|
2182
2349
|
|
|
2350
|
+
|
|
2351
|
+
|
|
2352
|
+
|
|
2353
|
+
|
|
2354
|
+
|
|
2355
|
+
|
|
2356
|
+
|
|
2183
2357
|
|
|
2184
2358
|
|
|
2185
2359
|
|
|
@@ -2243,6 +2417,13 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
2243
2417
|
|
|
2244
2418
|
|
|
2245
2419
|
|
|
2420
|
+
|
|
2421
|
+
|
|
2422
|
+
|
|
2423
|
+
|
|
2424
|
+
|
|
2425
|
+
|
|
2426
|
+
|
|
2246
2427
|
|
|
2247
2428
|
|
|
2248
2429
|
|
|
@@ -2262,22 +2443,69 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
2262
2443
|
this.setMany(anotherTree, []);
|
|
2263
2444
|
}
|
|
2264
2445
|
/**
|
|
2265
|
-
*
|
|
2266
|
-
* @remarks Time O(N)
|
|
2446
|
+
* Deletes a node from the tree (internal, returns balancing metadata).
|
|
2447
|
+
* @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).
|
|
2448
|
+
* @internal Used by AVL/BST subclasses that need balancing metadata after deletion.
|
|
2267
2449
|
*
|
|
2268
|
-
* @param
|
|
2269
|
-
* @
|
|
2450
|
+
* @param keyNodeEntryRawOrPredicate - The node to delete.
|
|
2451
|
+
* @returns An array containing deletion results with balancing metadata.
|
|
2270
2452
|
*/
|
|
2271
|
-
|
|
2272
|
-
|
|
2273
|
-
this.
|
|
2453
|
+
_deleteInternal(keyNodeEntryRawOrPredicate) {
|
|
2454
|
+
const deletedResult = [];
|
|
2455
|
+
if (!this._root) return deletedResult;
|
|
2456
|
+
const curr = this.getNode(keyNodeEntryRawOrPredicate);
|
|
2457
|
+
if (!curr) return deletedResult;
|
|
2458
|
+
const parent = curr == null ? void 0 : curr.parent;
|
|
2459
|
+
let needBalanced;
|
|
2460
|
+
let orgCurrent = curr;
|
|
2461
|
+
if (!curr.left && !curr.right && !parent) {
|
|
2462
|
+
this._setRoot(void 0);
|
|
2463
|
+
} else if (curr.left) {
|
|
2464
|
+
const leftSubTreeRightMost = this.getRightMost((node) => node, curr.left);
|
|
2465
|
+
if (leftSubTreeRightMost) {
|
|
2466
|
+
const parentOfLeftSubTreeMax = leftSubTreeRightMost.parent;
|
|
2467
|
+
orgCurrent = this._swapProperties(curr, leftSubTreeRightMost);
|
|
2468
|
+
if (this._isMapMode) {
|
|
2469
|
+
this._store.set(curr.key, curr);
|
|
2470
|
+
this._store.set(leftSubTreeRightMost.key, leftSubTreeRightMost);
|
|
2471
|
+
}
|
|
2472
|
+
if (parentOfLeftSubTreeMax) {
|
|
2473
|
+
if (parentOfLeftSubTreeMax.right === leftSubTreeRightMost)
|
|
2474
|
+
parentOfLeftSubTreeMax.right = leftSubTreeRightMost.left;
|
|
2475
|
+
else parentOfLeftSubTreeMax.left = leftSubTreeRightMost.left;
|
|
2476
|
+
needBalanced = parentOfLeftSubTreeMax;
|
|
2477
|
+
}
|
|
2478
|
+
}
|
|
2479
|
+
} else if (parent) {
|
|
2480
|
+
const { familyPosition: fp } = curr;
|
|
2481
|
+
if (fp === "LEFT" || fp === "ROOT_LEFT") {
|
|
2482
|
+
parent.left = curr.right;
|
|
2483
|
+
} else if (fp === "RIGHT" || fp === "ROOT_RIGHT") {
|
|
2484
|
+
parent.right = curr.right;
|
|
2485
|
+
}
|
|
2486
|
+
needBalanced = parent;
|
|
2487
|
+
} else {
|
|
2488
|
+
this._setRoot(curr.right);
|
|
2489
|
+
curr.right = void 0;
|
|
2490
|
+
}
|
|
2491
|
+
this._size = this._size - 1;
|
|
2492
|
+
deletedResult.push({ deleted: orgCurrent, needBalanced });
|
|
2493
|
+
if (this._isMapMode && orgCurrent) this._store.delete(orgCurrent.key);
|
|
2494
|
+
return deletedResult;
|
|
2274
2495
|
}
|
|
2275
2496
|
/**
|
|
2276
2497
|
* Deletes a node from the tree.
|
|
2277
|
-
* @remarks Time O(
|
|
2498
|
+
* @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).
|
|
2278
2499
|
*
|
|
2279
2500
|
* @param keyNodeEntryRawOrPredicate - The node to delete.
|
|
2280
|
-
* @returns
|
|
2501
|
+
* @returns True if the node was found and deleted, false otherwise.
|
|
2502
|
+
|
|
2503
|
+
|
|
2504
|
+
|
|
2505
|
+
|
|
2506
|
+
|
|
2507
|
+
|
|
2508
|
+
|
|
2281
2509
|
|
|
2282
2510
|
|
|
2283
2511
|
|
|
@@ -2321,51 +2549,11 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
2321
2549
|
* console.log(tree.size); // 4;
|
|
2322
2550
|
*/
|
|
2323
2551
|
delete(keyNodeEntryRawOrPredicate) {
|
|
2324
|
-
|
|
2325
|
-
if (!this._root) return deletedResult;
|
|
2326
|
-
const curr = this.getNode(keyNodeEntryRawOrPredicate);
|
|
2327
|
-
if (!curr) return deletedResult;
|
|
2328
|
-
const parent = curr == null ? void 0 : curr.parent;
|
|
2329
|
-
let needBalanced;
|
|
2330
|
-
let orgCurrent = curr;
|
|
2331
|
-
if (!curr.left && !curr.right && !parent) {
|
|
2332
|
-
this._setRoot(void 0);
|
|
2333
|
-
} else if (curr.left) {
|
|
2334
|
-
const leftSubTreeRightMost = this.getRightMost((node) => node, curr.left);
|
|
2335
|
-
if (leftSubTreeRightMost) {
|
|
2336
|
-
const parentOfLeftSubTreeMax = leftSubTreeRightMost.parent;
|
|
2337
|
-
orgCurrent = this._swapProperties(curr, leftSubTreeRightMost);
|
|
2338
|
-
if (this._isMapMode) {
|
|
2339
|
-
this._store.set(curr.key, curr);
|
|
2340
|
-
this._store.set(leftSubTreeRightMost.key, leftSubTreeRightMost);
|
|
2341
|
-
}
|
|
2342
|
-
if (parentOfLeftSubTreeMax) {
|
|
2343
|
-
if (parentOfLeftSubTreeMax.right === leftSubTreeRightMost)
|
|
2344
|
-
parentOfLeftSubTreeMax.right = leftSubTreeRightMost.left;
|
|
2345
|
-
else parentOfLeftSubTreeMax.left = leftSubTreeRightMost.left;
|
|
2346
|
-
needBalanced = parentOfLeftSubTreeMax;
|
|
2347
|
-
}
|
|
2348
|
-
}
|
|
2349
|
-
} else if (parent) {
|
|
2350
|
-
const { familyPosition: fp } = curr;
|
|
2351
|
-
if (fp === "LEFT" || fp === "ROOT_LEFT") {
|
|
2352
|
-
parent.left = curr.right;
|
|
2353
|
-
} else if (fp === "RIGHT" || fp === "ROOT_RIGHT") {
|
|
2354
|
-
parent.right = curr.right;
|
|
2355
|
-
}
|
|
2356
|
-
needBalanced = parent;
|
|
2357
|
-
} else {
|
|
2358
|
-
this._setRoot(curr.right);
|
|
2359
|
-
curr.right = void 0;
|
|
2360
|
-
}
|
|
2361
|
-
this._size = this._size - 1;
|
|
2362
|
-
deletedResult.push({ deleted: orgCurrent, needBalanced });
|
|
2363
|
-
if (this._isMapMode && orgCurrent) this._store.delete(orgCurrent.key);
|
|
2364
|
-
return deletedResult;
|
|
2552
|
+
return this._deleteInternal(keyNodeEntryRawOrPredicate).length > 0;
|
|
2365
2553
|
}
|
|
2366
2554
|
/**
|
|
2367
2555
|
* Searches the tree for nodes matching a predicate.
|
|
2368
|
-
* @remarks Time O(
|
|
2556
|
+
* @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).
|
|
2369
2557
|
*
|
|
2370
2558
|
* @template C - The type of the callback function.
|
|
2371
2559
|
* @param keyNodeEntryOrPredicate - The key, node, entry, or predicate function to search for.
|
|
@@ -2414,7 +2602,7 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
2414
2602
|
}
|
|
2415
2603
|
/**
|
|
2416
2604
|
* Gets the first node matching a predicate.
|
|
2417
|
-
* @remarks Time O(
|
|
2605
|
+
* @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.
|
|
2418
2606
|
*
|
|
2419
2607
|
* @param keyNodeEntryOrPredicate - The key, node, entry, or predicate function to search for.
|
|
2420
2608
|
* @param [startNode=this._root] - The node to start the search from.
|
|
@@ -2445,6 +2633,13 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
2445
2633
|
|
|
2446
2634
|
|
|
2447
2635
|
|
|
2636
|
+
|
|
2637
|
+
|
|
2638
|
+
|
|
2639
|
+
|
|
2640
|
+
|
|
2641
|
+
|
|
2642
|
+
|
|
2448
2643
|
|
|
2449
2644
|
|
|
2450
2645
|
|
|
@@ -2470,7 +2665,7 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
2470
2665
|
}
|
|
2471
2666
|
/**
|
|
2472
2667
|
* Gets the value associated with a key.
|
|
2473
|
-
* @remarks Time O(
|
|
2668
|
+
* @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).
|
|
2474
2669
|
*
|
|
2475
2670
|
* @param keyNodeEntryOrPredicate - The key, node, or entry to get the value for.
|
|
2476
2671
|
* @param [startNode=this._root] - The node to start searching from (if not in Map mode).
|
|
@@ -2503,6 +2698,13 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
2503
2698
|
|
|
2504
2699
|
|
|
2505
2700
|
|
|
2701
|
+
|
|
2702
|
+
|
|
2703
|
+
|
|
2704
|
+
|
|
2705
|
+
|
|
2706
|
+
|
|
2707
|
+
|
|
2506
2708
|
|
|
2507
2709
|
|
|
2508
2710
|
|
|
@@ -2564,6 +2766,13 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
2564
2766
|
|
|
2565
2767
|
|
|
2566
2768
|
|
|
2769
|
+
|
|
2770
|
+
|
|
2771
|
+
|
|
2772
|
+
|
|
2773
|
+
|
|
2774
|
+
|
|
2775
|
+
|
|
2567
2776
|
|
|
2568
2777
|
|
|
2569
2778
|
|
|
@@ -2612,6 +2821,13 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
2612
2821
|
|
|
2613
2822
|
|
|
2614
2823
|
|
|
2824
|
+
|
|
2825
|
+
|
|
2826
|
+
|
|
2827
|
+
|
|
2828
|
+
|
|
2829
|
+
|
|
2830
|
+
|
|
2615
2831
|
|
|
2616
2832
|
|
|
2617
2833
|
|
|
@@ -2669,6 +2885,13 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
2669
2885
|
|
|
2670
2886
|
|
|
2671
2887
|
|
|
2888
|
+
|
|
2889
|
+
|
|
2890
|
+
|
|
2891
|
+
|
|
2892
|
+
|
|
2893
|
+
|
|
2894
|
+
|
|
2672
2895
|
|
|
2673
2896
|
|
|
2674
2897
|
|
|
@@ -2753,6 +2976,13 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
2753
2976
|
|
|
2754
2977
|
|
|
2755
2978
|
|
|
2979
|
+
|
|
2980
|
+
|
|
2981
|
+
|
|
2982
|
+
|
|
2983
|
+
|
|
2984
|
+
|
|
2985
|
+
|
|
2756
2986
|
|
|
2757
2987
|
|
|
2758
2988
|
|
|
@@ -2814,6 +3044,13 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
2814
3044
|
|
|
2815
3045
|
|
|
2816
3046
|
|
|
3047
|
+
|
|
3048
|
+
|
|
3049
|
+
|
|
3050
|
+
|
|
3051
|
+
|
|
3052
|
+
|
|
3053
|
+
|
|
2817
3054
|
|
|
2818
3055
|
|
|
2819
3056
|
|
|
@@ -3291,6 +3528,13 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
3291
3528
|
|
|
3292
3529
|
|
|
3293
3530
|
|
|
3531
|
+
|
|
3532
|
+
|
|
3533
|
+
|
|
3534
|
+
|
|
3535
|
+
|
|
3536
|
+
|
|
3537
|
+
|
|
3294
3538
|
|
|
3295
3539
|
|
|
3296
3540
|
|
|
@@ -3343,6 +3587,13 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
3343
3587
|
|
|
3344
3588
|
|
|
3345
3589
|
|
|
3590
|
+
|
|
3591
|
+
|
|
3592
|
+
|
|
3593
|
+
|
|
3594
|
+
|
|
3595
|
+
|
|
3596
|
+
|
|
3346
3597
|
|
|
3347
3598
|
|
|
3348
3599
|
|
|
@@ -3399,6 +3650,13 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
3399
3650
|
|
|
3400
3651
|
|
|
3401
3652
|
|
|
3653
|
+
|
|
3654
|
+
|
|
3655
|
+
|
|
3656
|
+
|
|
3657
|
+
|
|
3658
|
+
|
|
3659
|
+
|
|
3402
3660
|
|
|
3403
3661
|
|
|
3404
3662
|
|
|
@@ -3480,6 +3738,13 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
3480
3738
|
|
|
3481
3739
|
|
|
3482
3740
|
|
|
3741
|
+
|
|
3742
|
+
|
|
3743
|
+
|
|
3744
|
+
|
|
3745
|
+
|
|
3746
|
+
|
|
3747
|
+
|
|
3483
3748
|
|
|
3484
3749
|
|
|
3485
3750
|
|