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.
Files changed (63) hide show
  1. package/dist/cjs/index.cjs +320 -55
  2. package/dist/cjs/index.cjs.map +1 -1
  3. package/dist/cjs-legacy/index.cjs +320 -55
  4. package/dist/cjs-legacy/index.cjs.map +1 -1
  5. package/dist/esm/index.mjs +320 -55
  6. package/dist/esm/index.mjs.map +1 -1
  7. package/dist/esm-legacy/index.mjs +320 -55
  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/binary-tree-typed.js +320 -55
  35. package/dist/umd/binary-tree-typed.js.map +1 -1
  36. package/dist/umd/binary-tree-typed.min.js +5 -5
  37. package/dist/umd/binary-tree-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
@@ -102,6 +102,13 @@ export class TreeMultiSet<K = any, R = K> implements Iterable<K> {
102
102
 
103
103
 
104
104
 
105
+
106
+
107
+
108
+
109
+
110
+
111
+
105
112
 
106
113
 
107
114
 
@@ -261,6 +268,41 @@ export class TreeMultiSet<K = any, R = K> implements Iterable<K> {
261
268
 
262
269
 
263
270
 
271
+
272
+
273
+
274
+
275
+
276
+
277
+
278
+
279
+
280
+
281
+
282
+
283
+
284
+
285
+
286
+
287
+
288
+
289
+
290
+
291
+
292
+
293
+
294
+
295
+
296
+
297
+
298
+
299
+
300
+
301
+
302
+
303
+
304
+
305
+
264
306
 
265
307
 
266
308
 
@@ -433,6 +475,41 @@ export class TreeMultiSet<K = any, R = K> implements Iterable<K> {
433
475
 
434
476
 
435
477
 
478
+
479
+
480
+
481
+
482
+
483
+
484
+
485
+
486
+
487
+
488
+
489
+
490
+
491
+
492
+
493
+
494
+
495
+
496
+
497
+
498
+
499
+
500
+
501
+
502
+
503
+
504
+
505
+
506
+
507
+
508
+
509
+
510
+
511
+
512
+
436
513
 
437
514
 
438
515
 
@@ -487,6 +564,13 @@ export class TreeMultiSet<K = any, R = K> implements Iterable<K> {
487
564
 
488
565
 
489
566
 
567
+
568
+
569
+
570
+
571
+
572
+
573
+
490
574
 
491
575
 
492
576
 
@@ -641,6 +725,41 @@ export class TreeMultiSet<K = any, R = K> implements Iterable<K> {
641
725
 
642
726
 
643
727
 
728
+
729
+
730
+
731
+
732
+
733
+
734
+
735
+
736
+
737
+
738
+
739
+
740
+
741
+
742
+
743
+
744
+
745
+
746
+
747
+
748
+
749
+
750
+
751
+
752
+
753
+
754
+
755
+
756
+
757
+
758
+
759
+
760
+
761
+
762
+
644
763
 
645
764
 
646
765
 
@@ -705,6 +824,13 @@ export class TreeMultiSet<K = any, R = K> implements Iterable<K> {
705
824
 
706
825
 
707
826
 
827
+
828
+
829
+
830
+
831
+
832
+
833
+
708
834
 
709
835
 
710
836
 
@@ -880,6 +1006,41 @@ export class TreeMultiSet<K = any, R = K> implements Iterable<K> {
880
1006
 
881
1007
 
882
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
+
1035
+
1036
+
1037
+
1038
+
1039
+
1040
+
1041
+
1042
+
1043
+
883
1044
 
884
1045
 
885
1046
 
@@ -948,6 +1109,13 @@ export class TreeMultiSet<K = any, R = K> implements Iterable<K> {
948
1109
 
949
1110
 
950
1111
 
1112
+
1113
+
1114
+
1115
+
1116
+
1117
+
1118
+
951
1119
 
952
1120
 
953
1121
 
@@ -993,6 +1161,13 @@ export class TreeMultiSet<K = any, R = K> implements Iterable<K> {
993
1161
 
994
1162
 
995
1163
 
1164
+
1165
+
1166
+
1167
+
1168
+
1169
+
1170
+
996
1171
 
997
1172
 
998
1173
 
@@ -1152,6 +1327,41 @@ export class TreeMultiSet<K = any, R = K> implements Iterable<K> {
1152
1327
 
1153
1328
 
1154
1329
 
1330
+
1331
+
1332
+
1333
+
1334
+
1335
+
1336
+
1337
+
1338
+
1339
+
1340
+
1341
+
1342
+
1343
+
1344
+
1345
+
1346
+
1347
+
1348
+
1349
+
1350
+
1351
+
1352
+
1353
+
1354
+
1355
+
1356
+
1357
+
1358
+
1359
+
1360
+
1361
+
1362
+
1363
+
1364
+
1155
1365
 
1156
1366
 
1157
1367
 
@@ -1196,9 +1406,8 @@ export class TreeMultiSet<K = any, R = K> implements Iterable<K> {
1196
1406
  }
1197
1407
 
1198
1408
  /**
1199
- * Returns an array with all elements (expanded).
1200
- * @remarks Time O(size), Space O(size)
1201
-
1409
+ * Iterate over all elements with multiplicity (Set-compatible, alias for `[Symbol.iterator]`).
1410
+ * @remarks Each key is yielded `count(key)` times. Time O(size), Space O(1) per step.
1202
1411
 
1203
1412
 
1204
1413
 
@@ -1207,6 +1416,19 @@ export class TreeMultiSet<K = any, R = K> implements Iterable<K> {
1207
1416
 
1208
1417
 
1209
1418
 
1419
+ * @example
1420
+ * // Iterate with multiplicity
1421
+ * const ms = new TreeMultiSet<number>();
1422
+ * ms.add(1); ms.add(1); ms.add(2); ms.add(3); ms.add(3); ms.add(3);
1423
+ * console.log([...ms.keys()]); // [1, 1, 2, 3, 3, 3];
1424
+ */
1425
+ *keys(): IterableIterator<K> {
1426
+ yield* this;
1427
+ }
1428
+
1429
+ /**
1430
+ * Iterate over all elements with multiplicity (Set-compatible, alias for `[Symbol.iterator]`).
1431
+ * @remarks Each key is yielded `count(key)` times. Time O(size), Space O(1) per step.
1210
1432
 
1211
1433
 
1212
1434
 
@@ -1215,6 +1437,19 @@ export class TreeMultiSet<K = any, R = K> implements Iterable<K> {
1215
1437
 
1216
1438
 
1217
1439
 
1440
+ * @example
1441
+ * // Iterate with multiplicity
1442
+ * const ms = new TreeMultiSet<number>();
1443
+ * ms.add(5); ms.add(5); ms.add(10);
1444
+ * console.log([...ms.values()]); // [5, 5, 10];
1445
+ */
1446
+ *values(): IterableIterator<K> {
1447
+ yield* this;
1448
+ }
1449
+
1450
+ /**
1451
+ * Returns an array with all elements (expanded).
1452
+ * @remarks Time O(size), Space O(size)
1218
1453
 
1219
1454
 
1220
1455
 
@@ -1356,20 +1591,6 @@ export class TreeMultiSet<K = any, R = K> implements Iterable<K> {
1356
1591
 
1357
1592
 
1358
1593
 
1359
- * @example
1360
- * // All elements (with duplicates)
1361
- * const ms = new TreeMultiSet<number>();
1362
- * ms.add(1, 2);
1363
- * ms.add(2);
1364
- * console.log(ms.toArray()); // [1, 1, 2];
1365
- */
1366
- toArray(): K[] {
1367
- return [...this];
1368
- }
1369
-
1370
- /**
1371
- * Returns an array with distinct keys only.
1372
- * @remarks Time O(n), Space O(n)
1373
1594
 
1374
1595
 
1375
1596
 
@@ -1396,20 +1617,6 @@ export class TreeMultiSet<K = any, R = K> implements Iterable<K> {
1396
1617
 
1397
1618
 
1398
1619
 
1399
- * @example
1400
- * // Unique keys only
1401
- * const ms = new TreeMultiSet<number>();
1402
- * ms.add(1, 3);
1403
- * ms.add(2);
1404
- * console.log(ms.toDistinctArray()); // [1, 2];
1405
- */
1406
- toDistinctArray(): K[] {
1407
- return [...this.keysDistinct()];
1408
- }
1409
-
1410
- /**
1411
- * Returns an array of [key, count] entries.
1412
- * @remarks Time O(n), Space O(n)
1413
1620
 
1414
1621
 
1415
1622
 
@@ -1437,7 +1644,101 @@ export class TreeMultiSet<K = any, R = K> implements Iterable<K> {
1437
1644
 
1438
1645
 
1439
1646
  * @example
1440
- * // Key-count pairs
1647
+ * // All elements (with duplicates)
1648
+ * const ms = new TreeMultiSet<number>();
1649
+ * ms.add(1, 2);
1650
+ * ms.add(2);
1651
+ * console.log(ms.toArray()); // [1, 1, 2];
1652
+ */
1653
+ toArray(): K[] {
1654
+ return [...this];
1655
+ }
1656
+
1657
+ /**
1658
+ * Returns an array with distinct keys only.
1659
+ * @remarks Time O(n), Space O(n)
1660
+
1661
+
1662
+
1663
+
1664
+
1665
+
1666
+
1667
+
1668
+
1669
+
1670
+
1671
+
1672
+
1673
+
1674
+
1675
+
1676
+
1677
+
1678
+
1679
+
1680
+
1681
+
1682
+
1683
+
1684
+
1685
+
1686
+
1687
+
1688
+
1689
+
1690
+
1691
+
1692
+
1693
+ * @example
1694
+ * // Unique keys only
1695
+ * const ms = new TreeMultiSet<number>();
1696
+ * ms.add(1, 3);
1697
+ * ms.add(2);
1698
+ * console.log(ms.toDistinctArray()); // [1, 2];
1699
+ */
1700
+ toDistinctArray(): K[] {
1701
+ return [...this.keysDistinct()];
1702
+ }
1703
+
1704
+ /**
1705
+ * Returns an array of [key, count] entries.
1706
+ * @remarks Time O(n), Space O(n)
1707
+
1708
+
1709
+
1710
+
1711
+
1712
+
1713
+
1714
+
1715
+
1716
+
1717
+
1718
+
1719
+
1720
+
1721
+
1722
+
1723
+
1724
+
1725
+
1726
+
1727
+
1728
+
1729
+
1730
+
1731
+
1732
+
1733
+
1734
+
1735
+
1736
+
1737
+
1738
+
1739
+
1740
+ * @example
1741
+ * // Key-count pairs
1441
1742
  * const ms = new TreeMultiSet<number>();
1442
1743
  * ms.add(1, 2);
1443
1744
  * ms.add(3);
@@ -1598,6 +1899,41 @@ export class TreeMultiSet<K = any, R = K> implements Iterable<K> {
1598
1899
 
1599
1900
 
1600
1901
 
1902
+
1903
+
1904
+
1905
+
1906
+
1907
+
1908
+
1909
+
1910
+
1911
+
1912
+
1913
+
1914
+
1915
+
1916
+
1917
+
1918
+
1919
+
1920
+
1921
+
1922
+
1923
+
1924
+
1925
+
1926
+
1927
+
1928
+
1929
+
1930
+
1931
+
1932
+
1933
+
1934
+
1935
+
1936
+
1601
1937
 
1602
1938
 
1603
1939
 
@@ -1655,6 +1991,13 @@ export class TreeMultiSet<K = any, R = K> implements Iterable<K> {
1655
1991
 
1656
1992
 
1657
1993
 
1994
+
1995
+
1996
+
1997
+
1998
+
1999
+
2000
+
1658
2001
 
1659
2002
 
1660
2003
 
@@ -1696,6 +2039,13 @@ export class TreeMultiSet<K = any, R = K> implements Iterable<K> {
1696
2039
 
1697
2040
 
1698
2041
 
2042
+
2043
+
2044
+
2045
+
2046
+
2047
+
2048
+
1699
2049
 
1700
2050
 
1701
2051
 
@@ -1737,6 +2087,13 @@ export class TreeMultiSet<K = any, R = K> implements Iterable<K> {
1737
2087
 
1738
2088
 
1739
2089
 
2090
+
2091
+
2092
+
2093
+
2094
+
2095
+
2096
+
1740
2097
 
1741
2098
 
1742
2099
 
@@ -1782,6 +2139,13 @@ export class TreeMultiSet<K = any, R = K> implements Iterable<K> {
1782
2139
 
1783
2140
 
1784
2141
 
2142
+
2143
+
2144
+
2145
+
2146
+
2147
+
2148
+
1785
2149
 
1786
2150
 
1787
2151
 
@@ -1912,6 +2276,34 @@ export class TreeMultiSet<K = any, R = K> implements Iterable<K> {
1912
2276
 
1913
2277
 
1914
2278
 
2279
+
2280
+
2281
+
2282
+
2283
+
2284
+
2285
+
2286
+
2287
+
2288
+
2289
+
2290
+
2291
+
2292
+
2293
+
2294
+
2295
+
2296
+
2297
+
2298
+
2299
+
2300
+
2301
+
2302
+
2303
+
2304
+
2305
+
2306
+
1915
2307
 
1916
2308
 
1917
2309
 
@@ -2054,6 +2446,34 @@ export class TreeMultiSet<K = any, R = K> implements Iterable<K> {
2054
2446
 
2055
2447
 
2056
2448
 
2449
+
2450
+
2451
+
2452
+
2453
+
2454
+
2455
+
2456
+
2457
+
2458
+
2459
+
2460
+
2461
+
2462
+
2463
+
2464
+
2465
+
2466
+
2467
+
2468
+
2469
+
2470
+
2471
+
2472
+
2473
+
2474
+
2475
+
2476
+
2057
2477
 
2058
2478
 
2059
2479
 
@@ -2196,6 +2616,34 @@ export class TreeMultiSet<K = any, R = K> implements Iterable<K> {
2196
2616
 
2197
2617
 
2198
2618
 
2619
+
2620
+
2621
+
2622
+
2623
+
2624
+
2625
+
2626
+
2627
+
2628
+
2629
+
2630
+
2631
+
2632
+
2633
+
2634
+
2635
+
2636
+
2637
+
2638
+
2639
+
2640
+
2641
+
2642
+
2643
+
2644
+
2645
+
2646
+
2199
2647
 
2200
2648
 
2201
2649
 
@@ -2337,6 +2785,34 @@ export class TreeMultiSet<K = any, R = K> implements Iterable<K> {
2337
2785
 
2338
2786
 
2339
2787
 
2788
+
2789
+
2790
+
2791
+
2792
+
2793
+
2794
+
2795
+
2796
+
2797
+
2798
+
2799
+
2800
+
2801
+
2802
+
2803
+
2804
+
2805
+
2806
+
2807
+
2808
+
2809
+
2810
+
2811
+
2812
+
2813
+
2814
+
2815
+
2340
2816
 
2341
2817
 
2342
2818
 
@@ -2513,6 +2989,41 @@ export class TreeMultiSet<K = any, R = K> implements Iterable<K> {
2513
2989
 
2514
2990
 
2515
2991
 
2992
+
2993
+
2994
+
2995
+
2996
+
2997
+
2998
+
2999
+
3000
+
3001
+
3002
+
3003
+
3004
+
3005
+
3006
+
3007
+
3008
+
3009
+
3010
+
3011
+
3012
+
3013
+
3014
+
3015
+
3016
+
3017
+
3018
+
3019
+
3020
+
3021
+
3022
+
3023
+
3024
+
3025
+
3026
+
2516
3027
 
2517
3028
 
2518
3029
 
@@ -2690,6 +3201,41 @@ export class TreeMultiSet<K = any, R = K> implements Iterable<K> {
2690
3201
 
2691
3202
 
2692
3203
 
3204
+
3205
+
3206
+
3207
+
3208
+
3209
+
3210
+
3211
+
3212
+
3213
+
3214
+
3215
+
3216
+
3217
+
3218
+
3219
+
3220
+
3221
+
3222
+
3223
+
3224
+
3225
+
3226
+
3227
+
3228
+
3229
+
3230
+
3231
+
3232
+
3233
+
3234
+
3235
+
3236
+
3237
+
3238
+
2693
3239
 
2694
3240
 
2695
3241
 
@@ -2874,6 +3420,41 @@ export class TreeMultiSet<K = any, R = K> implements Iterable<K> {
2874
3420
 
2875
3421
 
2876
3422
 
3423
+
3424
+
3425
+
3426
+
3427
+
3428
+
3429
+
3430
+
3431
+
3432
+
3433
+
3434
+
3435
+
3436
+
3437
+
3438
+
3439
+
3440
+
3441
+
3442
+
3443
+
3444
+
3445
+
3446
+
3447
+
3448
+
3449
+
3450
+
3451
+
3452
+
3453
+
3454
+
3455
+
3456
+
3457
+
2877
3458
 
2878
3459
 
2879
3460
 
@@ -3053,6 +3634,41 @@ export class TreeMultiSet<K = any, R = K> implements Iterable<K> {
3053
3634
 
3054
3635
 
3055
3636
 
3637
+
3638
+
3639
+
3640
+
3641
+
3642
+
3643
+
3644
+
3645
+
3646
+
3647
+
3648
+
3649
+
3650
+
3651
+
3652
+
3653
+
3654
+
3655
+
3656
+
3657
+
3658
+
3659
+
3660
+
3661
+
3662
+
3663
+
3664
+
3665
+
3666
+
3667
+
3668
+
3669
+
3670
+
3671
+
3056
3672
 
3057
3673
 
3058
3674
 
@@ -3290,8 +3906,22 @@ export class TreeMultiSet<K = any, R = K> implements Iterable<K> {
3290
3906
  /**
3291
3907
  * Get elements by rank range
3292
3908
 
3909
+
3910
+
3911
+
3912
+
3913
+
3914
+
3915
+
3916
+
3917
+
3918
+
3919
+
3920
+
3921
+
3922
+
3293
3923
  * @example
3294
- * // Pagination with rangeByRank
3924
+ * // Pagination by position in tree order
3295
3925
  * const tree = new TreeMultiSet<number>(
3296
3926
  * [10, 20, 30, 40, 50, 60, 70, 80, 90],
3297
3927
  * { enableOrderStatistic: true }
@@ -3315,6 +3945,41 @@ export class TreeMultiSet<K = any, R = K> implements Iterable<K> {
3315
3945
 
3316
3946
 
3317
3947
 
3948
+
3949
+
3950
+
3951
+
3952
+
3953
+
3954
+
3955
+
3956
+
3957
+
3958
+
3959
+
3960
+
3961
+
3962
+
3963
+
3964
+
3965
+
3966
+
3967
+
3968
+
3969
+
3970
+
3971
+
3972
+
3973
+
3974
+
3975
+
3976
+
3977
+
3978
+
3979
+
3980
+
3981
+
3982
+
3318
3983
  * @example
3319
3984
  * // Deep clone
3320
3985
  * const ms = new TreeMultiSet<number>();
@@ -3444,6 +4109,34 @@ export class TreeMultiSet<K = any, R = K> implements Iterable<K> {
3444
4109
 
3445
4110
 
3446
4111
 
4112
+
4113
+
4114
+
4115
+
4116
+
4117
+
4118
+
4119
+
4120
+
4121
+
4122
+
4123
+
4124
+
4125
+
4126
+
4127
+
4128
+
4129
+
4130
+
4131
+
4132
+
4133
+
4134
+
4135
+
4136
+
4137
+
4138
+
4139
+
3447
4140
 
3448
4141
 
3449
4142
 
@@ -3623,6 +4316,41 @@ export class TreeMultiSet<K = any, R = K> implements Iterable<K> {
3623
4316
 
3624
4317
 
3625
4318
 
4319
+
4320
+
4321
+
4322
+
4323
+
4324
+
4325
+
4326
+
4327
+
4328
+
4329
+
4330
+
4331
+
4332
+
4333
+
4334
+
4335
+
4336
+
4337
+
4338
+
4339
+
4340
+
4341
+
4342
+
4343
+
4344
+
4345
+
4346
+
4347
+
4348
+
4349
+
4350
+
4351
+
4352
+
4353
+
3626
4354
 
3627
4355
 
3628
4356