avl-tree-typed 2.5.2 → 2.5.3
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 +291 -61
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs-legacy/index.cjs +291 -61
- package/dist/cjs-legacy/index.cjs.map +1 -1
- package/dist/esm/index.mjs +291 -61
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm-legacy/index.mjs +291 -61
- package/dist/esm-legacy/index.mjs.map +1 -1
- package/dist/types/data-structures/binary-tree/avl-tree.d.ts +50 -2
- package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +56 -0
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +116 -15
- package/dist/types/data-structures/binary-tree/bst.d.ts +99 -3
- package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +79 -8
- package/dist/types/data-structures/binary-tree/segment-tree.d.ts +24 -0
- package/dist/types/data-structures/binary-tree/tree-map.d.ts +520 -1
- package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +489 -1
- package/dist/types/data-structures/binary-tree/tree-multi-set.d.ts +393 -1
- package/dist/types/data-structures/binary-tree/tree-set.d.ts +500 -1
- package/dist/types/data-structures/graph/directed-graph.d.ts +40 -0
- package/dist/types/data-structures/graph/undirected-graph.d.ts +36 -0
- package/dist/types/data-structures/hash/hash-map.d.ts +51 -6
- package/dist/types/data-structures/heap/heap.d.ts +98 -12
- package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +75 -0
- package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +61 -1
- package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +72 -0
- package/dist/types/data-structures/matrix/matrix.d.ts +32 -0
- package/dist/types/data-structures/queue/deque.d.ts +82 -0
- package/dist/types/data-structures/queue/queue.d.ts +61 -0
- package/dist/types/data-structures/stack/stack.d.ts +42 -2
- package/dist/types/data-structures/trie/trie.d.ts +48 -0
- package/dist/types/interfaces/binary-tree.d.ts +2 -3
- package/dist/umd/avl-tree-typed.js +291 -61
- package/dist/umd/avl-tree-typed.js.map +1 -1
- package/dist/umd/avl-tree-typed.min.js +2 -2
- package/dist/umd/avl-tree-typed.min.js.map +1 -1
- package/package.json +2 -2
- package/src/data-structures/binary-tree/avl-tree.ts +52 -5
- package/src/data-structures/binary-tree/binary-indexed-tree.ts +56 -0
- package/src/data-structures/binary-tree/binary-tree.ts +167 -81
- package/src/data-structures/binary-tree/bst.ts +101 -7
- package/src/data-structures/binary-tree/red-black-tree.ts +82 -15
- package/src/data-structures/binary-tree/segment-tree.ts +24 -0
- package/src/data-structures/binary-tree/tree-map.ts +540 -3
- package/src/data-structures/binary-tree/tree-multi-map.ts +490 -2
- package/src/data-structures/binary-tree/tree-multi-set.ts +393 -1
- package/src/data-structures/binary-tree/tree-set.ts +520 -3
- package/src/data-structures/graph/directed-graph.ts +41 -1
- package/src/data-structures/graph/undirected-graph.ts +37 -1
- package/src/data-structures/hash/hash-map.ts +67 -12
- package/src/data-structures/heap/heap.ts +107 -19
- package/src/data-structures/linked-list/doubly-linked-list.ts +88 -0
- package/src/data-structures/linked-list/singly-linked-list.ts +61 -1
- package/src/data-structures/linked-list/skip-linked-list.ts +72 -0
- package/src/data-structures/matrix/matrix.ts +32 -0
- package/src/data-structures/queue/deque.ts +85 -0
- package/src/data-structures/queue/queue.ts +73 -0
- package/src/data-structures/stack/stack.ts +45 -5
- package/src/data-structures/trie/trie.ts +48 -0
- package/src/interfaces/binary-tree.ts +1 -9
package/dist/cjs/index.cjs
CHANGED
|
@@ -797,6 +797,10 @@ var Queue = class _Queue extends LinearBase {
|
|
|
797
797
|
|
|
798
798
|
|
|
799
799
|
|
|
800
|
+
|
|
801
|
+
|
|
802
|
+
|
|
803
|
+
|
|
800
804
|
|
|
801
805
|
|
|
802
806
|
|
|
@@ -847,6 +851,10 @@ var Queue = class _Queue extends LinearBase {
|
|
|
847
851
|
|
|
848
852
|
|
|
849
853
|
|
|
854
|
+
|
|
855
|
+
|
|
856
|
+
|
|
857
|
+
|
|
850
858
|
|
|
851
859
|
|
|
852
860
|
|
|
@@ -861,6 +869,14 @@ var Queue = class _Queue extends LinearBase {
|
|
|
861
869
|
get first() {
|
|
862
870
|
return this.length > 0 ? this.elements[this._offset] : void 0;
|
|
863
871
|
}
|
|
872
|
+
/**
|
|
873
|
+
* Peek at the front element without removing it (alias for `first`).
|
|
874
|
+
* @remarks Time O(1), Space O(1)
|
|
875
|
+
* @returns Front element or undefined.
|
|
876
|
+
*/
|
|
877
|
+
peek() {
|
|
878
|
+
return this.first;
|
|
879
|
+
}
|
|
864
880
|
/**
|
|
865
881
|
* Get the last element (back) without removing it.
|
|
866
882
|
* @remarks Time O(1), Space O(1)
|
|
@@ -913,6 +929,10 @@ var Queue = class _Queue extends LinearBase {
|
|
|
913
929
|
|
|
914
930
|
|
|
915
931
|
|
|
932
|
+
|
|
933
|
+
|
|
934
|
+
|
|
935
|
+
|
|
916
936
|
|
|
917
937
|
|
|
918
938
|
|
|
@@ -975,6 +995,10 @@ var Queue = class _Queue extends LinearBase {
|
|
|
975
995
|
|
|
976
996
|
|
|
977
997
|
|
|
998
|
+
|
|
999
|
+
|
|
1000
|
+
|
|
1001
|
+
|
|
978
1002
|
|
|
979
1003
|
|
|
980
1004
|
|
|
@@ -1044,6 +1068,10 @@ var Queue = class _Queue extends LinearBase {
|
|
|
1044
1068
|
|
|
1045
1069
|
|
|
1046
1070
|
|
|
1071
|
+
|
|
1072
|
+
|
|
1073
|
+
|
|
1074
|
+
|
|
1047
1075
|
|
|
1048
1076
|
|
|
1049
1077
|
|
|
@@ -1103,6 +1131,10 @@ var Queue = class _Queue extends LinearBase {
|
|
|
1103
1131
|
|
|
1104
1132
|
|
|
1105
1133
|
|
|
1134
|
+
|
|
1135
|
+
|
|
1136
|
+
|
|
1137
|
+
|
|
1106
1138
|
|
|
1107
1139
|
|
|
1108
1140
|
|
|
@@ -1155,6 +1187,10 @@ var Queue = class _Queue extends LinearBase {
|
|
|
1155
1187
|
|
|
1156
1188
|
|
|
1157
1189
|
|
|
1190
|
+
|
|
1191
|
+
|
|
1192
|
+
|
|
1193
|
+
|
|
1158
1194
|
|
|
1159
1195
|
|
|
1160
1196
|
|
|
@@ -1206,6 +1242,21 @@ var Queue = class _Queue extends LinearBase {
|
|
|
1206
1242
|
this._elements[this._offset + index] = newElement;
|
|
1207
1243
|
return true;
|
|
1208
1244
|
}
|
|
1245
|
+
/**
|
|
1246
|
+
* Delete the first element that satisfies a predicate.
|
|
1247
|
+
* @remarks Time O(N), Space O(N)
|
|
1248
|
+
* @param predicate - Function (value, index, queue) → boolean to decide deletion.
|
|
1249
|
+
* @returns True if a match was removed.
|
|
1250
|
+
*/
|
|
1251
|
+
deleteWhere(predicate) {
|
|
1252
|
+
for (let i = 0; i < this.length; i++) {
|
|
1253
|
+
if (predicate(this._elements[this._offset + i], i, this)) {
|
|
1254
|
+
this.deleteAt(i);
|
|
1255
|
+
return true;
|
|
1256
|
+
}
|
|
1257
|
+
}
|
|
1258
|
+
return false;
|
|
1259
|
+
}
|
|
1209
1260
|
/**
|
|
1210
1261
|
* Reverse the queue in-place by compacting then reversing.
|
|
1211
1262
|
* @remarks Time O(N), Space O(N)
|
|
@@ -1248,6 +1299,10 @@ var Queue = class _Queue extends LinearBase {
|
|
|
1248
1299
|
|
|
1249
1300
|
|
|
1250
1301
|
|
|
1302
|
+
|
|
1303
|
+
|
|
1304
|
+
|
|
1305
|
+
|
|
1251
1306
|
|
|
1252
1307
|
|
|
1253
1308
|
|
|
@@ -1294,6 +1349,10 @@ var Queue = class _Queue extends LinearBase {
|
|
|
1294
1349
|
|
|
1295
1350
|
|
|
1296
1351
|
|
|
1352
|
+
|
|
1353
|
+
|
|
1354
|
+
|
|
1355
|
+
|
|
1297
1356
|
|
|
1298
1357
|
|
|
1299
1358
|
|
|
@@ -1363,6 +1422,10 @@ var Queue = class _Queue extends LinearBase {
|
|
|
1363
1422
|
|
|
1364
1423
|
|
|
1365
1424
|
|
|
1425
|
+
|
|
1426
|
+
|
|
1427
|
+
|
|
1428
|
+
|
|
1366
1429
|
|
|
1367
1430
|
|
|
1368
1431
|
|
|
@@ -1416,6 +1479,10 @@ var Queue = class _Queue extends LinearBase {
|
|
|
1416
1479
|
|
|
1417
1480
|
|
|
1418
1481
|
|
|
1482
|
+
|
|
1483
|
+
|
|
1484
|
+
|
|
1485
|
+
|
|
1419
1486
|
|
|
1420
1487
|
|
|
1421
1488
|
|
|
@@ -1473,6 +1540,10 @@ var Queue = class _Queue extends LinearBase {
|
|
|
1473
1540
|
|
|
1474
1541
|
|
|
1475
1542
|
|
|
1543
|
+
|
|
1544
|
+
|
|
1545
|
+
|
|
1546
|
+
|
|
1476
1547
|
|
|
1477
1548
|
|
|
1478
1549
|
|
|
@@ -1944,7 +2015,7 @@ var BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
1944
2015
|
}
|
|
1945
2016
|
/**
|
|
1946
2017
|
* Adds a new node to the tree.
|
|
1947
|
-
* @remarks Time O(
|
|
2018
|
+
* @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).
|
|
1948
2019
|
*
|
|
1949
2020
|
* @param keyNodeOrEntry - The key, node, or entry to add.
|
|
1950
2021
|
* @returns True if the addition was successful, false otherwise.
|
|
@@ -1973,6 +2044,10 @@ var BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
1973
2044
|
|
|
1974
2045
|
|
|
1975
2046
|
|
|
2047
|
+
|
|
2048
|
+
|
|
2049
|
+
|
|
2050
|
+
|
|
1976
2051
|
|
|
1977
2052
|
|
|
1978
2053
|
|
|
@@ -1992,7 +2067,7 @@ var BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
1992
2067
|
}
|
|
1993
2068
|
/**
|
|
1994
2069
|
* Adds or updates a new node to the tree.
|
|
1995
|
-
* @remarks Time O(
|
|
2070
|
+
* @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).
|
|
1996
2071
|
*
|
|
1997
2072
|
* @param keyNodeOrEntry - The key, node, or entry to set or update.
|
|
1998
2073
|
* @param [value] - The value, if providing just a key.
|
|
@@ -2027,6 +2102,10 @@ var BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
2027
2102
|
|
|
2028
2103
|
|
|
2029
2104
|
|
|
2105
|
+
|
|
2106
|
+
|
|
2107
|
+
|
|
2108
|
+
|
|
2030
2109
|
|
|
2031
2110
|
|
|
2032
2111
|
|
|
@@ -2133,6 +2212,10 @@ var BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
2133
2212
|
|
|
2134
2213
|
|
|
2135
2214
|
|
|
2215
|
+
|
|
2216
|
+
|
|
2217
|
+
|
|
2218
|
+
|
|
2136
2219
|
|
|
2137
2220
|
|
|
2138
2221
|
|
|
@@ -2175,6 +2258,10 @@ var BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
2175
2258
|
|
|
2176
2259
|
|
|
2177
2260
|
|
|
2261
|
+
|
|
2262
|
+
|
|
2263
|
+
|
|
2264
|
+
|
|
2178
2265
|
|
|
2179
2266
|
|
|
2180
2267
|
|
|
@@ -2238,6 +2325,10 @@ var BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
2238
2325
|
|
|
2239
2326
|
|
|
2240
2327
|
|
|
2328
|
+
|
|
2329
|
+
|
|
2330
|
+
|
|
2331
|
+
|
|
2241
2332
|
|
|
2242
2333
|
|
|
2243
2334
|
|
|
@@ -2254,22 +2345,66 @@ var BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
2254
2345
|
this.setMany(anotherTree, []);
|
|
2255
2346
|
}
|
|
2256
2347
|
/**
|
|
2257
|
-
*
|
|
2258
|
-
* @remarks Time O(N)
|
|
2348
|
+
* Deletes a node from the tree (internal, returns balancing metadata).
|
|
2349
|
+
* @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).
|
|
2350
|
+
* @internal Used by AVL/BST subclasses that need balancing metadata after deletion.
|
|
2259
2351
|
*
|
|
2260
|
-
* @param
|
|
2261
|
-
* @
|
|
2352
|
+
* @param keyNodeEntryRawOrPredicate - The node to delete.
|
|
2353
|
+
* @returns An array containing deletion results with balancing metadata.
|
|
2262
2354
|
*/
|
|
2263
|
-
|
|
2264
|
-
|
|
2265
|
-
this.
|
|
2355
|
+
_deleteInternal(keyNodeEntryRawOrPredicate) {
|
|
2356
|
+
const deletedResult = [];
|
|
2357
|
+
if (!this._root) return deletedResult;
|
|
2358
|
+
const curr = this.getNode(keyNodeEntryRawOrPredicate);
|
|
2359
|
+
if (!curr) return deletedResult;
|
|
2360
|
+
const parent = curr?.parent;
|
|
2361
|
+
let needBalanced;
|
|
2362
|
+
let orgCurrent = curr;
|
|
2363
|
+
if (!curr.left && !curr.right && !parent) {
|
|
2364
|
+
this._setRoot(void 0);
|
|
2365
|
+
} else if (curr.left) {
|
|
2366
|
+
const leftSubTreeRightMost = this.getRightMost((node) => node, curr.left);
|
|
2367
|
+
if (leftSubTreeRightMost) {
|
|
2368
|
+
const parentOfLeftSubTreeMax = leftSubTreeRightMost.parent;
|
|
2369
|
+
orgCurrent = this._swapProperties(curr, leftSubTreeRightMost);
|
|
2370
|
+
if (this._isMapMode) {
|
|
2371
|
+
this._store.set(curr.key, curr);
|
|
2372
|
+
this._store.set(leftSubTreeRightMost.key, leftSubTreeRightMost);
|
|
2373
|
+
}
|
|
2374
|
+
if (parentOfLeftSubTreeMax) {
|
|
2375
|
+
if (parentOfLeftSubTreeMax.right === leftSubTreeRightMost)
|
|
2376
|
+
parentOfLeftSubTreeMax.right = leftSubTreeRightMost.left;
|
|
2377
|
+
else parentOfLeftSubTreeMax.left = leftSubTreeRightMost.left;
|
|
2378
|
+
needBalanced = parentOfLeftSubTreeMax;
|
|
2379
|
+
}
|
|
2380
|
+
}
|
|
2381
|
+
} else if (parent) {
|
|
2382
|
+
const { familyPosition: fp } = curr;
|
|
2383
|
+
if (fp === "LEFT" || fp === "ROOT_LEFT") {
|
|
2384
|
+
parent.left = curr.right;
|
|
2385
|
+
} else if (fp === "RIGHT" || fp === "ROOT_RIGHT") {
|
|
2386
|
+
parent.right = curr.right;
|
|
2387
|
+
}
|
|
2388
|
+
needBalanced = parent;
|
|
2389
|
+
} else {
|
|
2390
|
+
this._setRoot(curr.right);
|
|
2391
|
+
curr.right = void 0;
|
|
2392
|
+
}
|
|
2393
|
+
this._size = this._size - 1;
|
|
2394
|
+
deletedResult.push({ deleted: orgCurrent, needBalanced });
|
|
2395
|
+
if (this._isMapMode && orgCurrent) this._store.delete(orgCurrent.key);
|
|
2396
|
+
return deletedResult;
|
|
2266
2397
|
}
|
|
2267
2398
|
/**
|
|
2268
2399
|
* Deletes a node from the tree.
|
|
2269
|
-
* @remarks Time O(
|
|
2400
|
+
* @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).
|
|
2270
2401
|
*
|
|
2271
2402
|
* @param keyNodeEntryRawOrPredicate - The node to delete.
|
|
2272
|
-
* @returns
|
|
2403
|
+
* @returns True if the node was found and deleted, false otherwise.
|
|
2404
|
+
|
|
2405
|
+
|
|
2406
|
+
|
|
2407
|
+
|
|
2273
2408
|
|
|
2274
2409
|
|
|
2275
2410
|
|
|
@@ -2313,51 +2448,11 @@ var BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
2313
2448
|
* console.log(tree.size); // 4;
|
|
2314
2449
|
*/
|
|
2315
2450
|
delete(keyNodeEntryRawOrPredicate) {
|
|
2316
|
-
|
|
2317
|
-
if (!this._root) return deletedResult;
|
|
2318
|
-
const curr = this.getNode(keyNodeEntryRawOrPredicate);
|
|
2319
|
-
if (!curr) return deletedResult;
|
|
2320
|
-
const parent = curr?.parent;
|
|
2321
|
-
let needBalanced;
|
|
2322
|
-
let orgCurrent = curr;
|
|
2323
|
-
if (!curr.left && !curr.right && !parent) {
|
|
2324
|
-
this._setRoot(void 0);
|
|
2325
|
-
} else if (curr.left) {
|
|
2326
|
-
const leftSubTreeRightMost = this.getRightMost((node) => node, curr.left);
|
|
2327
|
-
if (leftSubTreeRightMost) {
|
|
2328
|
-
const parentOfLeftSubTreeMax = leftSubTreeRightMost.parent;
|
|
2329
|
-
orgCurrent = this._swapProperties(curr, leftSubTreeRightMost);
|
|
2330
|
-
if (this._isMapMode) {
|
|
2331
|
-
this._store.set(curr.key, curr);
|
|
2332
|
-
this._store.set(leftSubTreeRightMost.key, leftSubTreeRightMost);
|
|
2333
|
-
}
|
|
2334
|
-
if (parentOfLeftSubTreeMax) {
|
|
2335
|
-
if (parentOfLeftSubTreeMax.right === leftSubTreeRightMost)
|
|
2336
|
-
parentOfLeftSubTreeMax.right = leftSubTreeRightMost.left;
|
|
2337
|
-
else parentOfLeftSubTreeMax.left = leftSubTreeRightMost.left;
|
|
2338
|
-
needBalanced = parentOfLeftSubTreeMax;
|
|
2339
|
-
}
|
|
2340
|
-
}
|
|
2341
|
-
} else if (parent) {
|
|
2342
|
-
const { familyPosition: fp } = curr;
|
|
2343
|
-
if (fp === "LEFT" || fp === "ROOT_LEFT") {
|
|
2344
|
-
parent.left = curr.right;
|
|
2345
|
-
} else if (fp === "RIGHT" || fp === "ROOT_RIGHT") {
|
|
2346
|
-
parent.right = curr.right;
|
|
2347
|
-
}
|
|
2348
|
-
needBalanced = parent;
|
|
2349
|
-
} else {
|
|
2350
|
-
this._setRoot(curr.right);
|
|
2351
|
-
curr.right = void 0;
|
|
2352
|
-
}
|
|
2353
|
-
this._size = this._size - 1;
|
|
2354
|
-
deletedResult.push({ deleted: orgCurrent, needBalanced });
|
|
2355
|
-
if (this._isMapMode && orgCurrent) this._store.delete(orgCurrent.key);
|
|
2356
|
-
return deletedResult;
|
|
2451
|
+
return this._deleteInternal(keyNodeEntryRawOrPredicate).length > 0;
|
|
2357
2452
|
}
|
|
2358
2453
|
/**
|
|
2359
2454
|
* Searches the tree for nodes matching a predicate.
|
|
2360
|
-
* @remarks Time O(
|
|
2455
|
+
* @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).
|
|
2361
2456
|
*
|
|
2362
2457
|
* @template C - The type of the callback function.
|
|
2363
2458
|
* @param keyNodeEntryOrPredicate - The key, node, entry, or predicate function to search for.
|
|
@@ -2406,7 +2501,7 @@ var BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
2406
2501
|
}
|
|
2407
2502
|
/**
|
|
2408
2503
|
* Gets the first node matching a predicate.
|
|
2409
|
-
* @remarks Time O(
|
|
2504
|
+
* @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.
|
|
2410
2505
|
*
|
|
2411
2506
|
* @param keyNodeEntryOrPredicate - The key, node, entry, or predicate function to search for.
|
|
2412
2507
|
* @param [startNode=this._root] - The node to start the search from.
|
|
@@ -2440,6 +2535,10 @@ var BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
2440
2535
|
|
|
2441
2536
|
|
|
2442
2537
|
|
|
2538
|
+
|
|
2539
|
+
|
|
2540
|
+
|
|
2541
|
+
|
|
2443
2542
|
|
|
2444
2543
|
|
|
2445
2544
|
|
|
@@ -2462,7 +2561,7 @@ var BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
2462
2561
|
}
|
|
2463
2562
|
/**
|
|
2464
2563
|
* Gets the value associated with a key.
|
|
2465
|
-
* @remarks Time O(
|
|
2564
|
+
* @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).
|
|
2466
2565
|
*
|
|
2467
2566
|
* @param keyNodeEntryOrPredicate - The key, node, or entry to get the value for.
|
|
2468
2567
|
* @param [startNode=this._root] - The node to start searching from (if not in Map mode).
|
|
@@ -2498,6 +2597,10 @@ var BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
2498
2597
|
|
|
2499
2598
|
|
|
2500
2599
|
|
|
2600
|
+
|
|
2601
|
+
|
|
2602
|
+
|
|
2603
|
+
|
|
2501
2604
|
|
|
2502
2605
|
|
|
2503
2606
|
|
|
@@ -2558,6 +2661,10 @@ var BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
2558
2661
|
|
|
2559
2662
|
|
|
2560
2663
|
|
|
2664
|
+
|
|
2665
|
+
|
|
2666
|
+
|
|
2667
|
+
|
|
2561
2668
|
|
|
2562
2669
|
|
|
2563
2670
|
|
|
@@ -2606,6 +2713,10 @@ var BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
2606
2713
|
|
|
2607
2714
|
|
|
2608
2715
|
|
|
2716
|
+
|
|
2717
|
+
|
|
2718
|
+
|
|
2719
|
+
|
|
2609
2720
|
|
|
2610
2721
|
|
|
2611
2722
|
|
|
@@ -2663,6 +2774,10 @@ var BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
2663
2774
|
|
|
2664
2775
|
|
|
2665
2776
|
|
|
2777
|
+
|
|
2778
|
+
|
|
2779
|
+
|
|
2780
|
+
|
|
2666
2781
|
|
|
2667
2782
|
|
|
2668
2783
|
|
|
@@ -2747,6 +2862,10 @@ var BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
2747
2862
|
|
|
2748
2863
|
|
|
2749
2864
|
|
|
2865
|
+
|
|
2866
|
+
|
|
2867
|
+
|
|
2868
|
+
|
|
2750
2869
|
|
|
2751
2870
|
|
|
2752
2871
|
|
|
@@ -2808,6 +2927,10 @@ var BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
2808
2927
|
|
|
2809
2928
|
|
|
2810
2929
|
|
|
2930
|
+
|
|
2931
|
+
|
|
2932
|
+
|
|
2933
|
+
|
|
2811
2934
|
|
|
2812
2935
|
|
|
2813
2936
|
|
|
@@ -3285,6 +3408,10 @@ var BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
3285
3408
|
|
|
3286
3409
|
|
|
3287
3410
|
|
|
3411
|
+
|
|
3412
|
+
|
|
3413
|
+
|
|
3414
|
+
|
|
3288
3415
|
|
|
3289
3416
|
|
|
3290
3417
|
|
|
@@ -3337,6 +3464,10 @@ var BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
3337
3464
|
|
|
3338
3465
|
|
|
3339
3466
|
|
|
3467
|
+
|
|
3468
|
+
|
|
3469
|
+
|
|
3470
|
+
|
|
3340
3471
|
|
|
3341
3472
|
|
|
3342
3473
|
|
|
@@ -3393,6 +3524,10 @@ var BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
3393
3524
|
|
|
3394
3525
|
|
|
3395
3526
|
|
|
3527
|
+
|
|
3528
|
+
|
|
3529
|
+
|
|
3530
|
+
|
|
3396
3531
|
|
|
3397
3532
|
|
|
3398
3533
|
|
|
@@ -3474,6 +3609,10 @@ var BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
3474
3609
|
|
|
3475
3610
|
|
|
3476
3611
|
|
|
3612
|
+
|
|
3613
|
+
|
|
3614
|
+
|
|
3615
|
+
|
|
3477
3616
|
|
|
3478
3617
|
|
|
3479
3618
|
|
|
@@ -4293,6 +4432,14 @@ var BST = class extends BinaryTree {
|
|
|
4293
4432
|
|
|
4294
4433
|
|
|
4295
4434
|
|
|
4435
|
+
|
|
4436
|
+
|
|
4437
|
+
|
|
4438
|
+
|
|
4439
|
+
|
|
4440
|
+
|
|
4441
|
+
|
|
4442
|
+
|
|
4296
4443
|
|
|
4297
4444
|
|
|
4298
4445
|
|
|
@@ -4625,6 +4772,18 @@ var BST = class extends BinaryTree {
|
|
|
4625
4772
|
|
|
4626
4773
|
|
|
4627
4774
|
|
|
4775
|
+
|
|
4776
|
+
|
|
4777
|
+
|
|
4778
|
+
|
|
4779
|
+
|
|
4780
|
+
|
|
4781
|
+
|
|
4782
|
+
|
|
4783
|
+
|
|
4784
|
+
|
|
4785
|
+
|
|
4786
|
+
|
|
4628
4787
|
|
|
4629
4788
|
|
|
4630
4789
|
|
|
@@ -4744,6 +4903,14 @@ var BST = class extends BinaryTree {
|
|
|
4744
4903
|
|
|
4745
4904
|
|
|
4746
4905
|
|
|
4906
|
+
|
|
4907
|
+
|
|
4908
|
+
|
|
4909
|
+
|
|
4910
|
+
|
|
4911
|
+
|
|
4912
|
+
|
|
4913
|
+
|
|
4747
4914
|
|
|
4748
4915
|
|
|
4749
4916
|
|
|
@@ -5035,6 +5202,10 @@ var BST = class extends BinaryTree {
|
|
|
5035
5202
|
|
|
5036
5203
|
|
|
5037
5204
|
|
|
5205
|
+
|
|
5206
|
+
|
|
5207
|
+
|
|
5208
|
+
|
|
5038
5209
|
|
|
5039
5210
|
|
|
5040
5211
|
|
|
@@ -5104,6 +5275,10 @@ var BST = class extends BinaryTree {
|
|
|
5104
5275
|
|
|
5105
5276
|
|
|
5106
5277
|
|
|
5278
|
+
|
|
5279
|
+
|
|
5280
|
+
|
|
5281
|
+
|
|
5107
5282
|
|
|
5108
5283
|
|
|
5109
5284
|
|
|
@@ -5222,6 +5397,14 @@ var BST = class extends BinaryTree {
|
|
|
5222
5397
|
|
|
5223
5398
|
|
|
5224
5399
|
|
|
5400
|
+
|
|
5401
|
+
|
|
5402
|
+
|
|
5403
|
+
|
|
5404
|
+
|
|
5405
|
+
|
|
5406
|
+
|
|
5407
|
+
|
|
5225
5408
|
|
|
5226
5409
|
|
|
5227
5410
|
|
|
@@ -5283,12 +5466,11 @@ var BST = class extends BinaryTree {
|
|
|
5283
5466
|
*/
|
|
5284
5467
|
deleteWhere(keyNodeEntryOrPredicate, onlyOne = false, startNode = this._root, iterationType = this.iterationType) {
|
|
5285
5468
|
const toDelete = this.search(keyNodeEntryOrPredicate, onlyOne, (node) => node, startNode, iterationType);
|
|
5286
|
-
let
|
|
5469
|
+
let deleted = false;
|
|
5287
5470
|
for (const node of toDelete) {
|
|
5288
|
-
|
|
5289
|
-
results = results.concat(deleteInfo);
|
|
5471
|
+
if (this.delete(node)) deleted = true;
|
|
5290
5472
|
}
|
|
5291
|
-
return
|
|
5473
|
+
return deleted;
|
|
5292
5474
|
}
|
|
5293
5475
|
/**
|
|
5294
5476
|
* (Protected) Creates the default comparator function for keys that don't have a custom comparator.
|
|
@@ -6120,6 +6302,22 @@ var AVLTree = class extends BST {
|
|
|
6120
6302
|
|
|
6121
6303
|
|
|
6122
6304
|
|
|
6305
|
+
|
|
6306
|
+
|
|
6307
|
+
|
|
6308
|
+
|
|
6309
|
+
|
|
6310
|
+
|
|
6311
|
+
|
|
6312
|
+
|
|
6313
|
+
|
|
6314
|
+
|
|
6315
|
+
|
|
6316
|
+
|
|
6317
|
+
|
|
6318
|
+
|
|
6319
|
+
|
|
6320
|
+
|
|
6123
6321
|
|
|
6124
6322
|
|
|
6125
6323
|
|
|
@@ -6248,6 +6446,18 @@ var AVLTree = class extends BST {
|
|
|
6248
6446
|
|
|
6249
6447
|
|
|
6250
6448
|
|
|
6449
|
+
|
|
6450
|
+
|
|
6451
|
+
|
|
6452
|
+
|
|
6453
|
+
|
|
6454
|
+
|
|
6455
|
+
|
|
6456
|
+
|
|
6457
|
+
|
|
6458
|
+
|
|
6459
|
+
|
|
6460
|
+
|
|
6251
6461
|
|
|
6252
6462
|
|
|
6253
6463
|
|
|
@@ -6269,13 +6479,13 @@ var AVLTree = class extends BST {
|
|
|
6269
6479
|
* console.log(avl.size); // 6;
|
|
6270
6480
|
*/
|
|
6271
6481
|
delete(keyNodeOrEntry) {
|
|
6272
|
-
const deletedResults =
|
|
6482
|
+
const deletedResults = this._deleteInternal(keyNodeOrEntry);
|
|
6273
6483
|
for (const { needBalanced } of deletedResults) {
|
|
6274
6484
|
if (needBalanced) {
|
|
6275
6485
|
this._balancePath(needBalanced);
|
|
6276
6486
|
}
|
|
6277
6487
|
}
|
|
6278
|
-
return deletedResults;
|
|
6488
|
+
return deletedResults.length > 0;
|
|
6279
6489
|
}
|
|
6280
6490
|
/**
|
|
6281
6491
|
* Rebuilds the tree to be perfectly balanced.
|
|
@@ -6335,6 +6545,14 @@ var AVLTree = class extends BST {
|
|
|
6335
6545
|
|
|
6336
6546
|
|
|
6337
6547
|
|
|
6548
|
+
|
|
6549
|
+
|
|
6550
|
+
|
|
6551
|
+
|
|
6552
|
+
|
|
6553
|
+
|
|
6554
|
+
|
|
6555
|
+
|
|
6338
6556
|
|
|
6339
6557
|
|
|
6340
6558
|
|
|
@@ -6467,6 +6685,18 @@ var AVLTree = class extends BST {
|
|
|
6467
6685
|
|
|
6468
6686
|
|
|
6469
6687
|
|
|
6688
|
+
|
|
6689
|
+
|
|
6690
|
+
|
|
6691
|
+
|
|
6692
|
+
|
|
6693
|
+
|
|
6694
|
+
|
|
6695
|
+
|
|
6696
|
+
|
|
6697
|
+
|
|
6698
|
+
|
|
6699
|
+
|
|
6470
6700
|
|
|
6471
6701
|
|
|
6472
6702
|
|