binary-tree-typed 2.5.1 → 2.5.2

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 (73) hide show
  1. package/dist/cjs/index.cjs +146 -52
  2. package/dist/cjs/index.cjs.map +1 -1
  3. package/dist/cjs-legacy/index.cjs +145 -51
  4. package/dist/cjs-legacy/index.cjs.map +1 -1
  5. package/dist/esm/index.mjs +146 -53
  6. package/dist/esm/index.mjs.map +1 -1
  7. package/dist/esm-legacy/index.mjs +145 -52
  8. package/dist/esm-legacy/index.mjs.map +1 -1
  9. package/dist/types/common/error.d.ts +9 -0
  10. package/dist/types/common/index.d.ts +1 -1
  11. package/dist/types/data-structures/binary-tree/avl-tree.d.ts +36 -0
  12. package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +42 -0
  13. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +77 -2
  14. package/dist/types/data-structures/binary-tree/bst.d.ts +171 -0
  15. package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +57 -0
  16. package/dist/types/data-structures/binary-tree/segment-tree.d.ts +18 -0
  17. package/dist/types/data-structures/binary-tree/tree-map.d.ts +409 -0
  18. package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +411 -6
  19. package/dist/types/data-structures/binary-tree/tree-multi-set.d.ts +339 -6
  20. package/dist/types/data-structures/binary-tree/tree-set.d.ts +391 -0
  21. package/dist/types/data-structures/graph/directed-graph.d.ts +30 -0
  22. package/dist/types/data-structures/graph/undirected-graph.d.ts +27 -0
  23. package/dist/types/data-structures/hash/hash-map.d.ts +33 -0
  24. package/dist/types/data-structures/heap/heap.d.ts +42 -0
  25. package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +51 -0
  26. package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +45 -0
  27. package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +54 -0
  28. package/dist/types/data-structures/matrix/matrix.d.ts +24 -0
  29. package/dist/types/data-structures/queue/deque.d.ts +45 -0
  30. package/dist/types/data-structures/queue/queue.d.ts +36 -0
  31. package/dist/types/data-structures/stack/stack.d.ts +30 -0
  32. package/dist/types/data-structures/trie/trie.d.ts +36 -0
  33. package/dist/types/types/data-structures/binary-tree/bst.d.ts +1 -0
  34. package/dist/types/types/data-structures/binary-tree/tree-map.d.ts +5 -0
  35. package/dist/types/types/data-structures/binary-tree/tree-multi-set.d.ts +4 -0
  36. package/dist/types/types/data-structures/binary-tree/tree-set.d.ts +4 -0
  37. package/dist/umd/binary-tree-typed.js +143 -50
  38. package/dist/umd/binary-tree-typed.js.map +1 -1
  39. package/dist/umd/binary-tree-typed.min.js +3 -3
  40. package/dist/umd/binary-tree-typed.min.js.map +1 -1
  41. package/package.json +2 -2
  42. package/src/common/error.ts +19 -1
  43. package/src/common/index.ts +1 -1
  44. package/src/data-structures/base/iterable-element-base.ts +3 -2
  45. package/src/data-structures/binary-tree/avl-tree.ts +47 -0
  46. package/src/data-structures/binary-tree/binary-indexed-tree.ts +46 -4
  47. package/src/data-structures/binary-tree/binary-tree.ts +79 -4
  48. package/src/data-structures/binary-tree/bst.ts +441 -6
  49. package/src/data-structures/binary-tree/red-black-tree.ts +73 -0
  50. package/src/data-structures/binary-tree/segment-tree.ts +18 -0
  51. package/src/data-structures/binary-tree/tree-map.ts +434 -9
  52. package/src/data-structures/binary-tree/tree-multi-map.ts +426 -5
  53. package/src/data-structures/binary-tree/tree-multi-set.ts +350 -6
  54. package/src/data-structures/binary-tree/tree-set.ts +410 -8
  55. package/src/data-structures/graph/abstract-graph.ts +2 -2
  56. package/src/data-structures/graph/directed-graph.ts +30 -0
  57. package/src/data-structures/graph/undirected-graph.ts +27 -0
  58. package/src/data-structures/hash/hash-map.ts +35 -4
  59. package/src/data-structures/heap/heap.ts +46 -4
  60. package/src/data-structures/heap/max-heap.ts +2 -2
  61. package/src/data-structures/linked-list/doubly-linked-list.ts +51 -0
  62. package/src/data-structures/linked-list/singly-linked-list.ts +45 -0
  63. package/src/data-structures/linked-list/skip-linked-list.ts +59 -5
  64. package/src/data-structures/matrix/matrix.ts +33 -9
  65. package/src/data-structures/priority-queue/max-priority-queue.ts +2 -2
  66. package/src/data-structures/queue/deque.ts +45 -0
  67. package/src/data-structures/queue/queue.ts +36 -0
  68. package/src/data-structures/stack/stack.ts +30 -0
  69. package/src/data-structures/trie/trie.ts +38 -2
  70. package/src/types/data-structures/binary-tree/bst.ts +1 -0
  71. package/src/types/data-structures/binary-tree/tree-map.ts +6 -0
  72. package/src/types/data-structures/binary-tree/tree-multi-set.ts +5 -0
  73. package/src/types/data-structures/binary-tree/tree-set.ts +5 -0
@@ -182,6 +182,21 @@ export declare class TreeMap<K = any, V = any, R = [K, V]> implements Iterable<[
182
182
 
183
183
 
184
184
 
185
+
186
+
187
+
188
+
189
+
190
+
191
+
192
+
193
+
194
+
195
+
196
+
197
+
198
+
199
+
185
200
 
186
201
 
187
202
 
@@ -342,6 +357,21 @@ export declare class TreeMap<K = any, V = any, R = [K, V]> implements Iterable<[
342
357
 
343
358
 
344
359
 
360
+
361
+
362
+
363
+
364
+
365
+
366
+
367
+
368
+
369
+
370
+
371
+
372
+
373
+
374
+
345
375
 
346
376
 
347
377
 
@@ -521,6 +551,21 @@ export declare class TreeMap<K = any, V = any, R = [K, V]> implements Iterable<[
521
551
 
522
552
 
523
553
 
554
+
555
+
556
+
557
+
558
+
559
+
560
+
561
+
562
+
563
+
564
+
565
+
566
+
567
+
568
+
524
569
 
525
570
 
526
571
 
@@ -691,6 +736,21 @@ export declare class TreeMap<K = any, V = any, R = [K, V]> implements Iterable<[
691
736
 
692
737
 
693
738
 
739
+
740
+
741
+
742
+
743
+
744
+
745
+
746
+
747
+
748
+
749
+
750
+
751
+
752
+
753
+
694
754
 
695
755
 
696
756
 
@@ -861,6 +921,21 @@ export declare class TreeMap<K = any, V = any, R = [K, V]> implements Iterable<[
861
921
 
862
922
 
863
923
 
924
+
925
+
926
+
927
+
928
+
929
+
930
+
931
+
932
+
933
+
934
+
935
+
936
+
937
+
938
+
864
939
 
865
940
 
866
941
 
@@ -1020,6 +1095,21 @@ export declare class TreeMap<K = any, V = any, R = [K, V]> implements Iterable<[
1020
1095
 
1021
1096
 
1022
1097
 
1098
+
1099
+
1100
+
1101
+
1102
+
1103
+
1104
+
1105
+
1106
+
1107
+
1108
+
1109
+
1110
+
1111
+
1112
+
1023
1113
 
1024
1114
 
1025
1115
 
@@ -1172,6 +1262,21 @@ export declare class TreeMap<K = any, V = any, R = [K, V]> implements Iterable<[
1172
1262
 
1173
1263
 
1174
1264
 
1265
+
1266
+
1267
+
1268
+
1269
+
1270
+
1271
+
1272
+
1273
+
1274
+
1275
+
1276
+
1277
+
1278
+
1279
+
1175
1280
 
1176
1281
 
1177
1282
 
@@ -1326,6 +1431,21 @@ export declare class TreeMap<K = any, V = any, R = [K, V]> implements Iterable<[
1326
1431
 
1327
1432
 
1328
1433
 
1434
+
1435
+
1436
+
1437
+
1438
+
1439
+
1440
+
1441
+
1442
+
1443
+
1444
+
1445
+
1446
+
1447
+
1448
+
1329
1449
 
1330
1450
 
1331
1451
 
@@ -1479,6 +1599,21 @@ export declare class TreeMap<K = any, V = any, R = [K, V]> implements Iterable<[
1479
1599
 
1480
1600
 
1481
1601
 
1602
+
1603
+
1604
+
1605
+
1606
+
1607
+
1608
+
1609
+
1610
+
1611
+
1612
+
1613
+
1614
+
1615
+
1616
+
1482
1617
 
1483
1618
 
1484
1619
 
@@ -1633,6 +1768,21 @@ export declare class TreeMap<K = any, V = any, R = [K, V]> implements Iterable<[
1633
1768
 
1634
1769
 
1635
1770
 
1771
+
1772
+
1773
+
1774
+
1775
+
1776
+
1777
+
1778
+
1779
+
1780
+
1781
+
1782
+
1783
+
1784
+
1785
+
1636
1786
 
1637
1787
 
1638
1788
 
@@ -1789,6 +1939,21 @@ export declare class TreeMap<K = any, V = any, R = [K, V]> implements Iterable<[
1789
1939
 
1790
1940
 
1791
1941
 
1942
+
1943
+
1944
+
1945
+
1946
+
1947
+
1948
+
1949
+
1950
+
1951
+
1952
+
1953
+
1954
+
1955
+
1956
+
1792
1957
 
1793
1958
 
1794
1959
 
@@ -1944,6 +2109,21 @@ export declare class TreeMap<K = any, V = any, R = [K, V]> implements Iterable<[
1944
2109
 
1945
2110
 
1946
2111
 
2112
+
2113
+
2114
+
2115
+
2116
+
2117
+
2118
+
2119
+
2120
+
2121
+
2122
+
2123
+
2124
+
2125
+
2126
+
1947
2127
 
1948
2128
 
1949
2129
 
@@ -2097,6 +2277,21 @@ export declare class TreeMap<K = any, V = any, R = [K, V]> implements Iterable<[
2097
2277
 
2098
2278
 
2099
2279
 
2280
+
2281
+
2282
+
2283
+
2284
+
2285
+
2286
+
2287
+
2288
+
2289
+
2290
+
2291
+
2292
+
2293
+
2294
+
2100
2295
 
2101
2296
 
2102
2297
 
@@ -2247,6 +2442,21 @@ export declare class TreeMap<K = any, V = any, R = [K, V]> implements Iterable<[
2247
2442
 
2248
2443
 
2249
2444
 
2445
+
2446
+
2447
+
2448
+
2449
+
2450
+
2451
+
2452
+
2453
+
2454
+
2455
+
2456
+
2457
+
2458
+
2459
+
2250
2460
 
2251
2461
 
2252
2462
 
@@ -2397,6 +2607,21 @@ export declare class TreeMap<K = any, V = any, R = [K, V]> implements Iterable<[
2397
2607
 
2398
2608
 
2399
2609
 
2610
+
2611
+
2612
+
2613
+
2614
+
2615
+
2616
+
2617
+
2618
+
2619
+
2620
+
2621
+
2622
+
2623
+
2624
+
2400
2625
 
2401
2626
 
2402
2627
 
@@ -2548,6 +2773,21 @@ export declare class TreeMap<K = any, V = any, R = [K, V]> implements Iterable<[
2548
2773
 
2549
2774
 
2550
2775
 
2776
+
2777
+
2778
+
2779
+
2780
+
2781
+
2782
+
2783
+
2784
+
2785
+
2786
+
2787
+
2788
+
2789
+
2790
+
2551
2791
 
2552
2792
 
2553
2793
 
@@ -2700,6 +2940,21 @@ export declare class TreeMap<K = any, V = any, R = [K, V]> implements Iterable<[
2700
2940
 
2701
2941
 
2702
2942
 
2943
+
2944
+
2945
+
2946
+
2947
+
2948
+
2949
+
2950
+
2951
+
2952
+
2953
+
2954
+
2955
+
2956
+
2957
+
2703
2958
 
2704
2959
 
2705
2960
 
@@ -2852,6 +3107,21 @@ export declare class TreeMap<K = any, V = any, R = [K, V]> implements Iterable<[
2852
3107
 
2853
3108
 
2854
3109
 
3110
+
3111
+
3112
+
3113
+
3114
+
3115
+
3116
+
3117
+
3118
+
3119
+
3120
+
3121
+
3122
+
3123
+
3124
+
2855
3125
 
2856
3126
 
2857
3127
 
@@ -2904,6 +3174,9 @@ export declare class TreeMap<K = any, V = any, R = [K, V]> implements Iterable<[
2904
3174
 
2905
3175
 
2906
3176
 
3177
+
3178
+
3179
+
2907
3180
 
2908
3181
 
2909
3182
 
@@ -2966,6 +3239,9 @@ export declare class TreeMap<K = any, V = any, R = [K, V]> implements Iterable<[
2966
3239
 
2967
3240
 
2968
3241
 
3242
+
3243
+
3244
+
2969
3245
 
2970
3246
 
2971
3247
 
@@ -3012,6 +3288,9 @@ export declare class TreeMap<K = any, V = any, R = [K, V]> implements Iterable<[
3012
3288
 
3013
3289
 
3014
3290
 
3291
+
3292
+
3293
+
3015
3294
 
3016
3295
 
3017
3296
 
@@ -3060,6 +3339,9 @@ export declare class TreeMap<K = any, V = any, R = [K, V]> implements Iterable<[
3060
3339
 
3061
3340
 
3062
3341
 
3342
+
3343
+
3344
+
3063
3345
 
3064
3346
 
3065
3347
 
@@ -3189,6 +3471,18 @@ export declare class TreeMap<K = any, V = any, R = [K, V]> implements Iterable<[
3189
3471
 
3190
3472
 
3191
3473
 
3474
+
3475
+
3476
+
3477
+
3478
+
3479
+
3480
+
3481
+
3482
+
3483
+
3484
+
3485
+
3192
3486
 
3193
3487
 
3194
3488
 
@@ -3346,6 +3640,18 @@ export declare class TreeMap<K = any, V = any, R = [K, V]> implements Iterable<[
3346
3640
 
3347
3641
 
3348
3642
 
3643
+
3644
+
3645
+
3646
+
3647
+
3648
+
3649
+
3650
+
3651
+
3652
+
3653
+
3654
+
3349
3655
 
3350
3656
 
3351
3657
 
@@ -3487,6 +3793,18 @@ export declare class TreeMap<K = any, V = any, R = [K, V]> implements Iterable<[
3487
3793
 
3488
3794
 
3489
3795
 
3796
+
3797
+
3798
+
3799
+
3800
+
3801
+
3802
+
3803
+
3804
+
3805
+
3806
+
3807
+
3490
3808
 
3491
3809
 
3492
3810
 
@@ -3628,6 +3946,18 @@ export declare class TreeMap<K = any, V = any, R = [K, V]> implements Iterable<[
3628
3946
 
3629
3947
 
3630
3948
 
3949
+
3950
+
3951
+
3952
+
3953
+
3954
+
3955
+
3956
+
3957
+
3958
+
3959
+
3960
+
3631
3961
 
3632
3962
 
3633
3963
 
@@ -3770,6 +4100,18 @@ export declare class TreeMap<K = any, V = any, R = [K, V]> implements Iterable<[
3770
4100
 
3771
4101
 
3772
4102
 
4103
+
4104
+
4105
+
4106
+
4107
+
4108
+
4109
+
4110
+
4111
+
4112
+
4113
+
4114
+
3773
4115
 
3774
4116
 
3775
4117
 
@@ -3815,6 +4157,58 @@ export declare class TreeMap<K = any, V = any, R = [K, V]> implements Iterable<[
3815
4157
  * console.log(totalValue); // toBeCloseTo;
3816
4158
  */
3817
4159
  rangeSearch(range: [K, K], options?: TreeMapRangeOptions): Array<[K, V | undefined]>;
4160
+ /**
4161
+ * Returns the entry at the k-th position in tree order (0-indexed).
4162
+ * @remarks Time O(log n). Requires `enableOrderStatistic: true`.
4163
+
4164
+
4165
+
4166
+ * @example
4167
+ * // Find k-th entry in a TreeMap
4168
+ * const map = new TreeMap<string, number>(
4169
+ * [['alice', 95], ['bob', 87], ['charlie', 92]],
4170
+ * { enableOrderStatistic: true }
4171
+ * );
4172
+ * console.log(map.getByRank(0)); // 'alice';
4173
+ * console.log(map.getByRank(1)); // 'bob';
4174
+ * console.log(map.getByRank(2)); // 'charlie';
4175
+ */
4176
+ getByRank(k: number): [K, V | undefined] | undefined;
4177
+ /**
4178
+ * Returns the 0-based rank of a key (number of elements that precede it in tree order).
4179
+ * @remarks Time O(log n). Requires `enableOrderStatistic: true`.
4180
+ * @example
4181
+ * // Get the rank of a key in sorted order
4182
+ * const tree = new TreeMap<number>(
4183
+ * [10, 20, 30, 40, 50],
4184
+ * { enableOrderStatistic: true }
4185
+ * );
4186
+ * console.log(tree.getRank(10)); // 0; // smallest → rank 0
4187
+ * console.log(tree.getRank(30)); // 2; // 2 elements before 30 in tree order
4188
+ * console.log(tree.getRank(50)); // 4; // largest → rank 4
4189
+ * console.log(tree.getRank(25)); // 2;
4190
+ */
4191
+ getRank(key: K): number;
4192
+ /**
4193
+ * Returns keys by rank range (0-indexed, inclusive on both ends).
4194
+ * @remarks Time O(log n + k). Requires `enableOrderStatistic: true`.
4195
+
4196
+ * @example
4197
+ * // Pagination with rangeByRank
4198
+ * const tree = new TreeMap<number>(
4199
+ * [10, 20, 30, 40, 50, 60, 70, 80, 90],
4200
+ * { enableOrderStatistic: true }
4201
+ * );
4202
+ * const pageSize = 3;
4203
+ *
4204
+ * // Page 1
4205
+ * console.log(tree.rangeByRank(0, pageSize - 1)); // [10, 20, 30];
4206
+ * // Page 2
4207
+ * console.log(tree.rangeByRank(pageSize, 2 * pageSize - 1)); // [40, 50, 60];
4208
+ * // Page 3
4209
+ * console.log(tree.rangeByRank(2 * pageSize, 3 * pageSize - 1)); // [70, 80, 90];
4210
+ */
4211
+ rangeByRank(start: number, end: number): Array<[K, V | undefined]>;
3818
4212
  /**
3819
4213
  * Creates a shallow clone of this map.
3820
4214
  * @remarks Time O(n log n), Space O(n)
@@ -3946,6 +4340,21 @@ export declare class TreeMap<K = any, V = any, R = [K, V]> implements Iterable<[
3946
4340
 
3947
4341
 
3948
4342
 
4343
+
4344
+
4345
+
4346
+
4347
+
4348
+
4349
+
4350
+
4351
+
4352
+
4353
+
4354
+
4355
+
4356
+
4357
+
3949
4358
 
3950
4359
 
3951
4360