max-priority-queue-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.
Files changed (63) hide show
  1. package/dist/cjs/index.cjs +174 -16
  2. package/dist/cjs/index.cjs.map +1 -1
  3. package/dist/cjs-legacy/index.cjs +174 -16
  4. package/dist/cjs-legacy/index.cjs.map +1 -1
  5. package/dist/esm/index.mjs +174 -16
  6. package/dist/esm/index.mjs.map +1 -1
  7. package/dist/esm-legacy/index.mjs +174 -16
  8. package/dist/esm-legacy/index.mjs.map +1 -1
  9. package/dist/types/data-structures/base/iterable-element-base.d.ts +17 -0
  10. package/dist/types/data-structures/base/linear-base.d.ts +6 -0
  11. package/dist/types/data-structures/binary-tree/avl-tree.d.ts +86 -2
  12. package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +98 -0
  13. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +191 -15
  14. package/dist/types/data-structures/binary-tree/bst.d.ts +171 -3
  15. package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +136 -8
  16. package/dist/types/data-structures/binary-tree/segment-tree.d.ts +42 -0
  17. package/dist/types/data-structures/binary-tree/tree-map.d.ts +1061 -167
  18. package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +1232 -355
  19. package/dist/types/data-structures/binary-tree/tree-multi-set.d.ts +916 -194
  20. package/dist/types/data-structures/binary-tree/tree-set.d.ts +1078 -141
  21. package/dist/types/data-structures/graph/directed-graph.d.ts +70 -0
  22. package/dist/types/data-structures/graph/undirected-graph.d.ts +63 -0
  23. package/dist/types/data-structures/hash/hash-map.d.ts +84 -6
  24. package/dist/types/data-structures/heap/heap.d.ts +140 -12
  25. package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +150 -2
  26. package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +106 -1
  27. package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +126 -0
  28. package/dist/types/data-structures/matrix/matrix.d.ts +56 -0
  29. package/dist/types/data-structures/queue/deque.d.ts +171 -0
  30. package/dist/types/data-structures/queue/queue.d.ts +97 -0
  31. package/dist/types/data-structures/stack/stack.d.ts +72 -2
  32. package/dist/types/data-structures/trie/trie.d.ts +84 -0
  33. package/dist/types/interfaces/binary-tree.d.ts +2 -3
  34. package/dist/umd/max-priority-queue-typed.js +174 -16
  35. package/dist/umd/max-priority-queue-typed.js.map +1 -1
  36. package/dist/umd/max-priority-queue-typed.min.js +1 -1
  37. package/dist/umd/max-priority-queue-typed.min.js.map +1 -1
  38. package/package.json +2 -2
  39. package/src/data-structures/base/iterable-element-base.ts +32 -0
  40. package/src/data-structures/base/linear-base.ts +11 -0
  41. package/src/data-structures/binary-tree/avl-tree.ts +88 -5
  42. package/src/data-structures/binary-tree/binary-indexed-tree.ts +98 -0
  43. package/src/data-structures/binary-tree/binary-tree.ts +242 -81
  44. package/src/data-structures/binary-tree/bst.ts +173 -7
  45. package/src/data-structures/binary-tree/red-black-tree.ts +139 -15
  46. package/src/data-structures/binary-tree/segment-tree.ts +42 -0
  47. package/src/data-structures/binary-tree/tree-map.ts +948 -36
  48. package/src/data-structures/binary-tree/tree-multi-map.ts +893 -13
  49. package/src/data-structures/binary-tree/tree-multi-set.ts +761 -33
  50. package/src/data-structures/binary-tree/tree-set.ts +1260 -251
  51. package/src/data-structures/graph/directed-graph.ts +71 -1
  52. package/src/data-structures/graph/undirected-graph.ts +64 -1
  53. package/src/data-structures/hash/hash-map.ts +100 -12
  54. package/src/data-structures/heap/heap.ts +149 -19
  55. package/src/data-structures/linked-list/doubly-linked-list.ts +178 -2
  56. package/src/data-structures/linked-list/singly-linked-list.ts +106 -1
  57. package/src/data-structures/linked-list/skip-linked-list.ts +126 -0
  58. package/src/data-structures/matrix/matrix.ts +56 -0
  59. package/src/data-structures/queue/deque.ts +187 -0
  60. package/src/data-structures/queue/queue.ts +109 -0
  61. package/src/data-structures/stack/stack.ts +75 -5
  62. package/src/data-structures/trie/trie.ts +84 -0
  63. 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,
@@ -494,6 +493,20 @@ export class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R> implemen
494
493
 
495
494
 
496
495
 
496
+
497
+
498
+
499
+
500
+
501
+
502
+
503
+
504
+
505
+
506
+
507
+
508
+
509
+
497
510
 
498
511
 
499
512
 
@@ -596,6 +609,20 @@ export class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R> implemen
596
609
 
597
610
 
598
611
 
612
+
613
+
614
+
615
+
616
+
617
+
618
+
619
+
620
+
621
+
622
+
623
+
624
+
625
+
599
626
 
600
627
 
601
628
 
@@ -694,6 +721,20 @@ export class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R> implemen
694
721
 
695
722
 
696
723
 
724
+
725
+
726
+
727
+
728
+
729
+
730
+
731
+
732
+
733
+
734
+
735
+
736
+
737
+
697
738
 
698
739
 
699
740
 
@@ -713,7 +754,7 @@ export class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R> implemen
713
754
  * // Level-order grouping
714
755
  * const bst = new BST<number>([5, 3, 7, 1, 4]);
715
756
  * const levels = bst.listLevels(node => node.key);
716
- * console.log(levels.length); // > 0;
757
+ * console.log(levels); // toBeInstanceOf;
717
758
  * console.log(levels[0].length); // 1; // root level has 1 node
718
759
  * const allKeys = levels.flat().sort((a, b) => a - b);
719
760
  * console.log(allKeys); // [1, 3, 4, 5, 7];
@@ -804,6 +845,20 @@ export class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R> implemen
804
845
 
805
846
 
806
847
 
848
+
849
+
850
+
851
+
852
+
853
+
854
+
855
+
856
+
857
+
858
+
859
+
860
+
861
+
807
862
 
808
863
 
809
864
 
@@ -933,6 +988,20 @@ export class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R> implemen
933
988
 
934
989
 
935
990
 
991
+
992
+
993
+
994
+
995
+
996
+
997
+
998
+
999
+
1000
+
1001
+
1002
+
1003
+
1004
+
936
1005
 
937
1006
 
938
1007
 
@@ -1135,6 +1204,13 @@ export class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R> implemen
1135
1204
 
1136
1205
 
1137
1206
 
1207
+
1208
+
1209
+
1210
+
1211
+
1212
+
1213
+
1138
1214
 
1139
1215
 
1140
1216
 
@@ -1487,6 +1563,27 @@ export class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R> implemen
1487
1563
 
1488
1564
 
1489
1565
 
1566
+
1567
+
1568
+
1569
+
1570
+
1571
+
1572
+
1573
+
1574
+
1575
+
1576
+
1577
+
1578
+
1579
+
1580
+
1581
+
1582
+
1583
+
1584
+
1585
+
1586
+
1490
1587
 
1491
1588
 
1492
1589
 
@@ -1618,6 +1715,20 @@ export class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R> implemen
1618
1715
 
1619
1716
 
1620
1717
 
1718
+
1719
+
1720
+
1721
+
1722
+
1723
+
1724
+
1725
+
1726
+
1727
+
1728
+
1729
+
1730
+
1731
+
1621
1732
 
1622
1733
 
1623
1734
 
@@ -1764,6 +1875,13 @@ export class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R> implemen
1764
1875
 
1765
1876
 
1766
1877
 
1878
+
1879
+
1880
+
1881
+
1882
+
1883
+
1884
+
1767
1885
 
1768
1886
 
1769
1887
 
@@ -1870,6 +1988,13 @@ export class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R> implemen
1870
1988
 
1871
1989
 
1872
1990
 
1991
+
1992
+
1993
+
1994
+
1995
+
1996
+
1997
+
1873
1998
 
1874
1999
 
1875
2000
 
@@ -1975,6 +2100,13 @@ export class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R> implemen
1975
2100
 
1976
2101
 
1977
2102
 
2103
+
2104
+
2105
+
2106
+
2107
+
2108
+
2109
+
1978
2110
 
1979
2111
 
1980
2112
 
@@ -2124,6 +2256,13 @@ export class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R> implemen
2124
2256
 
2125
2257
 
2126
2258
 
2259
+
2260
+
2261
+
2262
+
2263
+
2264
+
2265
+
2127
2266
 
2128
2267
 
2129
2268
 
@@ -2329,6 +2468,13 @@ export class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R> implemen
2329
2468
 
2330
2469
 
2331
2470
 
2471
+
2472
+
2473
+
2474
+
2475
+
2476
+
2477
+
2332
2478
 
2333
2479
 
2334
2480
 
@@ -2402,6 +2548,13 @@ export class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R> implemen
2402
2548
 
2403
2549
 
2404
2550
 
2551
+
2552
+
2553
+
2554
+
2555
+
2556
+
2557
+
2405
2558
 
2406
2559
 
2407
2560
 
@@ -2523,6 +2676,20 @@ export class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R> implemen
2523
2676
 
2524
2677
 
2525
2678
 
2679
+
2680
+
2681
+
2682
+
2683
+
2684
+
2685
+
2686
+
2687
+
2688
+
2689
+
2690
+
2691
+
2692
+
2526
2693
 
2527
2694
 
2528
2695
 
@@ -2606,16 +2773,15 @@ export class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R> implemen
2606
2773
  onlyOne = false,
2607
2774
  startNode: K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined = this._root,
2608
2775
  iterationType: IterationType = this.iterationType
2609
- ): BinaryTreeDeleteResult<BSTNode<K, V>>[] {
2776
+ ): boolean {
2610
2777
  const toDelete = this.search(keyNodeEntryOrPredicate, onlyOne, node => node, startNode, iterationType);
2611
2778
 
2612
- let results: BinaryTreeDeleteResult<BSTNode<K, V>>[] = [];
2779
+ let deleted = false;
2613
2780
  for (const node of toDelete) {
2614
- const deleteInfo = this.delete(node);
2615
- results = results.concat(deleteInfo);
2781
+ if (this.delete(node)) deleted = true;
2616
2782
  }
2617
2783
 
2618
- return results;
2784
+ return deleted;
2619
2785
  }
2620
2786
 
2621
2787
  /**
@@ -7,7 +7,7 @@
7
7
  */
8
8
 
9
9
  import type {
10
- BinaryTreeDeleteResult, BTNRep,
10
+ BTNRep,
11
11
  CRUD,
12
12
  EntryCallback,
13
13
  FamilyPosition, NodePredicate,
@@ -332,14 +332,36 @@ 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 and clear the key→value store (if in map mode).
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
- * @returns void
338
- */
339
-
340
- /**
341
- * Remove all nodes and clear internal caches.
342
- * @remarks Time O(n) average, Space O(1)
337
+
338
+
339
+
340
+
341
+
342
+
343
+
344
+
345
+
346
+
347
+
348
+
349
+
350
+
351
+
352
+
353
+
354
+
355
+
356
+
357
+
358
+
359
+
360
+
361
+
362
+
363
+
364
+
343
365
 
344
366
 
345
367
 
@@ -982,6 +1004,34 @@ export class RedBlackTree<K = any, V = any, R = any> extends BST<K, V, R> implem
982
1004
 
983
1005
 
984
1006
 
1007
+
1008
+
1009
+
1010
+
1011
+
1012
+
1013
+
1014
+
1015
+
1016
+
1017
+
1018
+
1019
+
1020
+
1021
+
1022
+
1023
+
1024
+
1025
+
1026
+
1027
+
1028
+
1029
+
1030
+
1031
+
1032
+
1033
+
1034
+
985
1035
 
986
1036
 
987
1037
 
@@ -1194,6 +1244,34 @@ export class RedBlackTree<K = any, V = any, R = any> extends BST<K, V, R> implem
1194
1244
 
1195
1245
 
1196
1246
 
1247
+
1248
+
1249
+
1250
+
1251
+
1252
+
1253
+
1254
+
1255
+
1256
+
1257
+
1258
+
1259
+
1260
+
1261
+
1262
+
1263
+
1264
+
1265
+
1266
+
1267
+
1268
+
1269
+
1270
+
1271
+
1272
+
1273
+
1274
+
1197
1275
 
1198
1276
 
1199
1277
 
@@ -1224,16 +1302,15 @@ export class RedBlackTree<K = any, V = any, R = any> extends BST<K, V, R> implem
1224
1302
  */
1225
1303
  override delete(
1226
1304
  keyNodeEntryRawOrPredicate: BTNRep<K, V, RedBlackTreeNode<K, V>> | NodePredicate<RedBlackTreeNode<K, V> | null>
1227
- ): BinaryTreeDeleteResult<RedBlackTreeNode<K, V>>[] {
1228
- if (keyNodeEntryRawOrPredicate === null) return [];
1305
+ ): boolean {
1306
+ if (keyNodeEntryRawOrPredicate === null) return false;
1229
1307
 
1230
- const results: BinaryTreeDeleteResult<RedBlackTreeNode<K, V>>[] = [];
1231
1308
  let nodeToDelete: OptNode<RedBlackTreeNode<K, V>>;
1232
1309
  if (this._isPredicate(keyNodeEntryRawOrPredicate)) nodeToDelete = this.getNode(keyNodeEntryRawOrPredicate);
1233
1310
  else nodeToDelete = this.isRealNode(keyNodeEntryRawOrPredicate) ? keyNodeEntryRawOrPredicate : this.getNode(keyNodeEntryRawOrPredicate);
1234
1311
 
1235
1312
  if (!nodeToDelete) {
1236
- return results;
1313
+ return false;
1237
1314
  }
1238
1315
 
1239
1316
  // Track min/max cache updates before structural modifications.
@@ -1306,9 +1383,7 @@ export class RedBlackTree<K = any, V = any, R = any> extends BST<K, V, R> implem
1306
1383
  this._deleteFixup(replacementNode);
1307
1384
  }
1308
1385
 
1309
- results.push({ deleted: nodeToDelete, needBalanced: undefined });
1310
-
1311
- return results;
1386
+ return true;
1312
1387
  }
1313
1388
 
1314
1389
  /**
@@ -1402,6 +1477,27 @@ export class RedBlackTree<K = any, V = any, R = any> extends BST<K, V, R> implem
1402
1477
 
1403
1478
 
1404
1479
 
1480
+
1481
+
1482
+
1483
+
1484
+
1485
+
1486
+
1487
+
1488
+
1489
+
1490
+
1491
+
1492
+
1493
+
1494
+
1495
+
1496
+
1497
+
1498
+
1499
+
1500
+
1405
1501
 
1406
1502
 
1407
1503
 
@@ -1555,6 +1651,34 @@ export class RedBlackTree<K = any, V = any, R = any> extends BST<K, V, R> implem
1555
1651
 
1556
1652
 
1557
1653
 
1654
+
1655
+
1656
+
1657
+
1658
+
1659
+
1660
+
1661
+
1662
+
1663
+
1664
+
1665
+
1666
+
1667
+
1668
+
1669
+
1670
+
1671
+
1672
+
1673
+
1674
+
1675
+
1676
+
1677
+
1678
+
1679
+
1680
+
1681
+
1558
1682
 
1559
1683
 
1560
1684
 
@@ -105,6 +105,13 @@ export class SegmentTree<E = number> implements Iterable<E> {
105
105
 
106
106
 
107
107
 
108
+
109
+
110
+
111
+
112
+
113
+
114
+
108
115
 
109
116
 
110
117
 
@@ -180,6 +187,13 @@ export class SegmentTree<E = number> implements Iterable<E> {
180
187
 
181
188
 
182
189
 
190
+
191
+
192
+
193
+
194
+
195
+
196
+
183
197
 
184
198
 
185
199
 
@@ -250,6 +264,13 @@ export class SegmentTree<E = number> implements Iterable<E> {
250
264
 
251
265
 
252
266
 
267
+
268
+
269
+
270
+
271
+
272
+
273
+
253
274
 
254
275
 
255
276
 
@@ -327,6 +348,13 @@ export class SegmentTree<E = number> implements Iterable<E> {
327
348
 
328
349
 
329
350
 
351
+
352
+
353
+
354
+
355
+
356
+
357
+
330
358
 
331
359
 
332
360
 
@@ -380,6 +408,13 @@ export class SegmentTree<E = number> implements Iterable<E> {
380
408
 
381
409
 
382
410
 
411
+
412
+
413
+
414
+
415
+
416
+
417
+
383
418
 
384
419
 
385
420
 
@@ -472,6 +507,13 @@ export class SegmentTree<E = number> implements Iterable<E> {
472
507
 
473
508
 
474
509
 
510
+
511
+
512
+
513
+
514
+
515
+
516
+
475
517
 
476
518
 
477
519