max-priority-queue-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 +103 -16
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs-legacy/index.cjs +103 -16
- package/dist/cjs-legacy/index.cjs.map +1 -1
- package/dist/esm/index.mjs +103 -16
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm-legacy/index.mjs +103 -16
- 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/max-priority-queue-typed.js +103 -16
- package/dist/umd/max-priority-queue-typed.js.map +1 -1
- package/dist/umd/max-priority-queue-typed.min.js +1 -1
- package/dist/umd/max-priority-queue-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
|
@@ -7,7 +7,6 @@
|
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
import type {
|
|
10
|
-
BinaryTreeDeleteResult,
|
|
11
10
|
BSTNOptKeyOrNode,
|
|
12
11
|
BSTOptions,
|
|
13
12
|
BTNRep,
|
|
@@ -500,6 +499,14 @@ export class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R> implemen
|
|
|
500
499
|
|
|
501
500
|
|
|
502
501
|
|
|
502
|
+
|
|
503
|
+
|
|
504
|
+
|
|
505
|
+
|
|
506
|
+
|
|
507
|
+
|
|
508
|
+
|
|
509
|
+
|
|
503
510
|
|
|
504
511
|
|
|
505
512
|
|
|
@@ -602,6 +609,14 @@ export class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R> implemen
|
|
|
602
609
|
|
|
603
610
|
|
|
604
611
|
|
|
612
|
+
|
|
613
|
+
|
|
614
|
+
|
|
615
|
+
|
|
616
|
+
|
|
617
|
+
|
|
618
|
+
|
|
619
|
+
|
|
605
620
|
|
|
606
621
|
|
|
607
622
|
|
|
@@ -700,6 +715,14 @@ export class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R> implemen
|
|
|
700
715
|
|
|
701
716
|
|
|
702
717
|
|
|
718
|
+
|
|
719
|
+
|
|
720
|
+
|
|
721
|
+
|
|
722
|
+
|
|
723
|
+
|
|
724
|
+
|
|
725
|
+
|
|
703
726
|
|
|
704
727
|
|
|
705
728
|
|
|
@@ -713,7 +736,7 @@ export class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R> implemen
|
|
|
713
736
|
* // Level-order grouping
|
|
714
737
|
* const bst = new BST<number>([5, 3, 7, 1, 4]);
|
|
715
738
|
* const levels = bst.listLevels(node => node.key);
|
|
716
|
-
* console.log(levels
|
|
739
|
+
* console.log(levels); // toBeInstanceOf;
|
|
717
740
|
* console.log(levels[0].length); // 1; // root level has 1 node
|
|
718
741
|
* const allKeys = levels.flat().sort((a, b) => a - b);
|
|
719
742
|
* console.log(allKeys); // [1, 3, 4, 5, 7];
|
|
@@ -810,6 +833,14 @@ export class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R> implemen
|
|
|
810
833
|
|
|
811
834
|
|
|
812
835
|
|
|
836
|
+
|
|
837
|
+
|
|
838
|
+
|
|
839
|
+
|
|
840
|
+
|
|
841
|
+
|
|
842
|
+
|
|
843
|
+
|
|
813
844
|
|
|
814
845
|
|
|
815
846
|
|
|
@@ -939,6 +970,14 @@ export class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R> implemen
|
|
|
939
970
|
|
|
940
971
|
|
|
941
972
|
|
|
973
|
+
|
|
974
|
+
|
|
975
|
+
|
|
976
|
+
|
|
977
|
+
|
|
978
|
+
|
|
979
|
+
|
|
980
|
+
|
|
942
981
|
|
|
943
982
|
|
|
944
983
|
|
|
@@ -1138,6 +1177,10 @@ export class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R> implemen
|
|
|
1138
1177
|
|
|
1139
1178
|
|
|
1140
1179
|
|
|
1180
|
+
|
|
1181
|
+
|
|
1182
|
+
|
|
1183
|
+
|
|
1141
1184
|
|
|
1142
1185
|
|
|
1143
1186
|
|
|
@@ -1495,6 +1538,18 @@ export class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R> implemen
|
|
|
1495
1538
|
|
|
1496
1539
|
|
|
1497
1540
|
|
|
1541
|
+
|
|
1542
|
+
|
|
1543
|
+
|
|
1544
|
+
|
|
1545
|
+
|
|
1546
|
+
|
|
1547
|
+
|
|
1548
|
+
|
|
1549
|
+
|
|
1550
|
+
|
|
1551
|
+
|
|
1552
|
+
|
|
1498
1553
|
|
|
1499
1554
|
|
|
1500
1555
|
|
|
@@ -1624,6 +1679,14 @@ export class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R> implemen
|
|
|
1624
1679
|
|
|
1625
1680
|
|
|
1626
1681
|
|
|
1682
|
+
|
|
1683
|
+
|
|
1684
|
+
|
|
1685
|
+
|
|
1686
|
+
|
|
1687
|
+
|
|
1688
|
+
|
|
1689
|
+
|
|
1627
1690
|
|
|
1628
1691
|
|
|
1629
1692
|
|
|
@@ -1767,6 +1830,10 @@ export class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R> implemen
|
|
|
1767
1830
|
|
|
1768
1831
|
|
|
1769
1832
|
|
|
1833
|
+
|
|
1834
|
+
|
|
1835
|
+
|
|
1836
|
+
|
|
1770
1837
|
|
|
1771
1838
|
|
|
1772
1839
|
|
|
@@ -1873,6 +1940,10 @@ export class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R> implemen
|
|
|
1873
1940
|
|
|
1874
1941
|
|
|
1875
1942
|
|
|
1943
|
+
|
|
1944
|
+
|
|
1945
|
+
|
|
1946
|
+
|
|
1876
1947
|
|
|
1877
1948
|
|
|
1878
1949
|
|
|
@@ -1978,6 +2049,10 @@ export class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R> implemen
|
|
|
1978
2049
|
|
|
1979
2050
|
|
|
1980
2051
|
|
|
2052
|
+
|
|
2053
|
+
|
|
2054
|
+
|
|
2055
|
+
|
|
1981
2056
|
|
|
1982
2057
|
|
|
1983
2058
|
|
|
@@ -2127,6 +2202,10 @@ export class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R> implemen
|
|
|
2127
2202
|
|
|
2128
2203
|
|
|
2129
2204
|
|
|
2205
|
+
|
|
2206
|
+
|
|
2207
|
+
|
|
2208
|
+
|
|
2130
2209
|
|
|
2131
2210
|
|
|
2132
2211
|
|
|
@@ -2332,6 +2411,10 @@ export class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R> implemen
|
|
|
2332
2411
|
|
|
2333
2412
|
|
|
2334
2413
|
|
|
2414
|
+
|
|
2415
|
+
|
|
2416
|
+
|
|
2417
|
+
|
|
2335
2418
|
|
|
2336
2419
|
|
|
2337
2420
|
|
|
@@ -2405,6 +2488,10 @@ export class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R> implemen
|
|
|
2405
2488
|
|
|
2406
2489
|
|
|
2407
2490
|
|
|
2491
|
+
|
|
2492
|
+
|
|
2493
|
+
|
|
2494
|
+
|
|
2408
2495
|
|
|
2409
2496
|
|
|
2410
2497
|
|
|
@@ -2529,6 +2616,14 @@ export class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R> implemen
|
|
|
2529
2616
|
|
|
2530
2617
|
|
|
2531
2618
|
|
|
2619
|
+
|
|
2620
|
+
|
|
2621
|
+
|
|
2622
|
+
|
|
2623
|
+
|
|
2624
|
+
|
|
2625
|
+
|
|
2626
|
+
|
|
2532
2627
|
|
|
2533
2628
|
|
|
2534
2629
|
|
|
@@ -2606,16 +2701,15 @@ export class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R> implemen
|
|
|
2606
2701
|
onlyOne = false,
|
|
2607
2702
|
startNode: K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined = this._root,
|
|
2608
2703
|
iterationType: IterationType = this.iterationType
|
|
2609
|
-
):
|
|
2704
|
+
): boolean {
|
|
2610
2705
|
const toDelete = this.search(keyNodeEntryOrPredicate, onlyOne, node => node, startNode, iterationType);
|
|
2611
2706
|
|
|
2612
|
-
let
|
|
2707
|
+
let deleted = false;
|
|
2613
2708
|
for (const node of toDelete) {
|
|
2614
|
-
|
|
2615
|
-
results = results.concat(deleteInfo);
|
|
2709
|
+
if (this.delete(node)) deleted = true;
|
|
2616
2710
|
}
|
|
2617
2711
|
|
|
2618
|
-
return
|
|
2712
|
+
return deleted;
|
|
2619
2713
|
}
|
|
2620
2714
|
|
|
2621
2715
|
/**
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
import type {
|
|
10
|
-
|
|
10
|
+
BTNRep,
|
|
11
11
|
CRUD,
|
|
12
12
|
EntryCallback,
|
|
13
13
|
FamilyPosition, NodePredicate,
|
|
@@ -332,14 +332,24 @@ export class RedBlackTree<K = any, V = any, R = any> extends BST<K, V, R> implem
|
|
|
332
332
|
}
|
|
333
333
|
|
|
334
334
|
/**
|
|
335
|
-
* Remove all nodes
|
|
335
|
+
* Remove all nodes, clear the key→value store (if in map mode) and internal caches.
|
|
336
336
|
* @remarks Time O(n), Space O(1)
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
337
|
+
|
|
338
|
+
|
|
339
|
+
|
|
340
|
+
|
|
341
|
+
|
|
342
|
+
|
|
343
|
+
|
|
344
|
+
|
|
345
|
+
|
|
346
|
+
|
|
347
|
+
|
|
348
|
+
|
|
349
|
+
|
|
350
|
+
|
|
351
|
+
|
|
352
|
+
|
|
343
353
|
|
|
344
354
|
|
|
345
355
|
|
|
@@ -986,6 +996,22 @@ export class RedBlackTree<K = any, V = any, R = any> extends BST<K, V, R> implem
|
|
|
986
996
|
|
|
987
997
|
|
|
988
998
|
|
|
999
|
+
|
|
1000
|
+
|
|
1001
|
+
|
|
1002
|
+
|
|
1003
|
+
|
|
1004
|
+
|
|
1005
|
+
|
|
1006
|
+
|
|
1007
|
+
|
|
1008
|
+
|
|
1009
|
+
|
|
1010
|
+
|
|
1011
|
+
|
|
1012
|
+
|
|
1013
|
+
|
|
1014
|
+
|
|
989
1015
|
|
|
990
1016
|
|
|
991
1017
|
|
|
@@ -1198,6 +1224,22 @@ export class RedBlackTree<K = any, V = any, R = any> extends BST<K, V, R> implem
|
|
|
1198
1224
|
|
|
1199
1225
|
|
|
1200
1226
|
|
|
1227
|
+
|
|
1228
|
+
|
|
1229
|
+
|
|
1230
|
+
|
|
1231
|
+
|
|
1232
|
+
|
|
1233
|
+
|
|
1234
|
+
|
|
1235
|
+
|
|
1236
|
+
|
|
1237
|
+
|
|
1238
|
+
|
|
1239
|
+
|
|
1240
|
+
|
|
1241
|
+
|
|
1242
|
+
|
|
1201
1243
|
|
|
1202
1244
|
|
|
1203
1245
|
|
|
@@ -1224,16 +1266,15 @@ export class RedBlackTree<K = any, V = any, R = any> extends BST<K, V, R> implem
|
|
|
1224
1266
|
*/
|
|
1225
1267
|
override delete(
|
|
1226
1268
|
keyNodeEntryRawOrPredicate: BTNRep<K, V, RedBlackTreeNode<K, V>> | NodePredicate<RedBlackTreeNode<K, V> | null>
|
|
1227
|
-
):
|
|
1228
|
-
if (keyNodeEntryRawOrPredicate === null) return
|
|
1269
|
+
): boolean {
|
|
1270
|
+
if (keyNodeEntryRawOrPredicate === null) return false;
|
|
1229
1271
|
|
|
1230
|
-
const results: BinaryTreeDeleteResult<RedBlackTreeNode<K, V>>[] = [];
|
|
1231
1272
|
let nodeToDelete: OptNode<RedBlackTreeNode<K, V>>;
|
|
1232
1273
|
if (this._isPredicate(keyNodeEntryRawOrPredicate)) nodeToDelete = this.getNode(keyNodeEntryRawOrPredicate);
|
|
1233
1274
|
else nodeToDelete = this.isRealNode(keyNodeEntryRawOrPredicate) ? keyNodeEntryRawOrPredicate : this.getNode(keyNodeEntryRawOrPredicate);
|
|
1234
1275
|
|
|
1235
1276
|
if (!nodeToDelete) {
|
|
1236
|
-
return
|
|
1277
|
+
return false;
|
|
1237
1278
|
}
|
|
1238
1279
|
|
|
1239
1280
|
// Track min/max cache updates before structural modifications.
|
|
@@ -1306,9 +1347,7 @@ export class RedBlackTree<K = any, V = any, R = any> extends BST<K, V, R> implem
|
|
|
1306
1347
|
this._deleteFixup(replacementNode);
|
|
1307
1348
|
}
|
|
1308
1349
|
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
return results;
|
|
1350
|
+
return true;
|
|
1312
1351
|
}
|
|
1313
1352
|
|
|
1314
1353
|
/**
|
|
@@ -1410,6 +1449,18 @@ export class RedBlackTree<K = any, V = any, R = any> extends BST<K, V, R> implem
|
|
|
1410
1449
|
|
|
1411
1450
|
|
|
1412
1451
|
|
|
1452
|
+
|
|
1453
|
+
|
|
1454
|
+
|
|
1455
|
+
|
|
1456
|
+
|
|
1457
|
+
|
|
1458
|
+
|
|
1459
|
+
|
|
1460
|
+
|
|
1461
|
+
|
|
1462
|
+
|
|
1463
|
+
|
|
1413
1464
|
|
|
1414
1465
|
|
|
1415
1466
|
|
|
@@ -1559,6 +1610,22 @@ export class RedBlackTree<K = any, V = any, R = any> extends BST<K, V, R> implem
|
|
|
1559
1610
|
|
|
1560
1611
|
|
|
1561
1612
|
|
|
1613
|
+
|
|
1614
|
+
|
|
1615
|
+
|
|
1616
|
+
|
|
1617
|
+
|
|
1618
|
+
|
|
1619
|
+
|
|
1620
|
+
|
|
1621
|
+
|
|
1622
|
+
|
|
1623
|
+
|
|
1624
|
+
|
|
1625
|
+
|
|
1626
|
+
|
|
1627
|
+
|
|
1628
|
+
|
|
1562
1629
|
|
|
1563
1630
|
|
|
1564
1631
|
|
|
@@ -108,6 +108,10 @@ export class SegmentTree<E = number> implements Iterable<E> {
|
|
|
108
108
|
|
|
109
109
|
|
|
110
110
|
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
|
|
111
115
|
|
|
112
116
|
|
|
113
117
|
|
|
@@ -183,6 +187,10 @@ export class SegmentTree<E = number> implements Iterable<E> {
|
|
|
183
187
|
|
|
184
188
|
|
|
185
189
|
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
|
|
186
194
|
|
|
187
195
|
|
|
188
196
|
|
|
@@ -253,6 +261,10 @@ export class SegmentTree<E = number> implements Iterable<E> {
|
|
|
253
261
|
|
|
254
262
|
|
|
255
263
|
|
|
264
|
+
|
|
265
|
+
|
|
266
|
+
|
|
267
|
+
|
|
256
268
|
|
|
257
269
|
|
|
258
270
|
|
|
@@ -330,6 +342,10 @@ export class SegmentTree<E = number> implements Iterable<E> {
|
|
|
330
342
|
|
|
331
343
|
|
|
332
344
|
|
|
345
|
+
|
|
346
|
+
|
|
347
|
+
|
|
348
|
+
|
|
333
349
|
|
|
334
350
|
|
|
335
351
|
|
|
@@ -383,6 +399,10 @@ export class SegmentTree<E = number> implements Iterable<E> {
|
|
|
383
399
|
|
|
384
400
|
|
|
385
401
|
|
|
402
|
+
|
|
403
|
+
|
|
404
|
+
|
|
405
|
+
|
|
386
406
|
|
|
387
407
|
|
|
388
408
|
|
|
@@ -475,6 +495,10 @@ export class SegmentTree<E = number> implements Iterable<E> {
|
|
|
475
495
|
|
|
476
496
|
|
|
477
497
|
|
|
498
|
+
|
|
499
|
+
|
|
500
|
+
|
|
501
|
+
|
|
478
502
|
|
|
479
503
|
|
|
480
504
|
|