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
@@ -181,6 +181,21 @@ export declare class TreeSet<K = any, R = K> implements Iterable<K> {
181
181
 
182
182
 
183
183
 
184
+
185
+
186
+
187
+
188
+
189
+
190
+
191
+
192
+
193
+
194
+
195
+
196
+
197
+
198
+
184
199
 
185
200
 
186
201
 
@@ -336,6 +351,21 @@ export declare class TreeSet<K = any, R = K> implements Iterable<K> {
336
351
 
337
352
 
338
353
 
354
+
355
+
356
+
357
+
358
+
359
+
360
+
361
+
362
+
363
+
364
+
365
+
366
+
367
+
368
+
339
369
 
340
370
 
341
371
 
@@ -506,6 +536,21 @@ export declare class TreeSet<K = any, R = K> implements Iterable<K> {
506
536
 
507
537
 
508
538
 
539
+
540
+
541
+
542
+
543
+
544
+
545
+
546
+
547
+
548
+
549
+
550
+
551
+
552
+
553
+
509
554
 
510
555
 
511
556
 
@@ -672,6 +717,21 @@ export declare class TreeSet<K = any, R = K> implements Iterable<K> {
672
717
 
673
718
 
674
719
 
720
+
721
+
722
+
723
+
724
+
725
+
726
+
727
+
728
+
729
+
730
+
731
+
732
+
733
+
734
+
675
735
 
676
736
 
677
737
 
@@ -826,6 +886,21 @@ export declare class TreeSet<K = any, R = K> implements Iterable<K> {
826
886
 
827
887
 
828
888
 
889
+
890
+
891
+
892
+
893
+
894
+
895
+
896
+
897
+
898
+
899
+
900
+
901
+
902
+
903
+
829
904
 
830
905
 
831
906
 
@@ -978,6 +1053,21 @@ export declare class TreeSet<K = any, R = K> implements Iterable<K> {
978
1053
 
979
1054
 
980
1055
 
1056
+
1057
+
1058
+
1059
+
1060
+
1061
+
1062
+
1063
+
1064
+
1065
+
1066
+
1067
+
1068
+
1069
+
1070
+
981
1071
 
982
1072
 
983
1073
 
@@ -1131,6 +1221,21 @@ export declare class TreeSet<K = any, R = K> implements Iterable<K> {
1131
1221
 
1132
1222
 
1133
1223
 
1224
+
1225
+
1226
+
1227
+
1228
+
1229
+
1230
+
1231
+
1232
+
1233
+
1234
+
1235
+
1236
+
1237
+
1238
+
1134
1239
 
1135
1240
 
1136
1241
 
@@ -1284,6 +1389,21 @@ export declare class TreeSet<K = any, R = K> implements Iterable<K> {
1284
1389
 
1285
1390
 
1286
1391
 
1392
+
1393
+
1394
+
1395
+
1396
+
1397
+
1398
+
1399
+
1400
+
1401
+
1402
+
1403
+
1404
+
1405
+
1406
+
1287
1407
 
1288
1408
 
1289
1409
 
@@ -1438,6 +1558,21 @@ export declare class TreeSet<K = any, R = K> implements Iterable<K> {
1438
1558
 
1439
1559
 
1440
1560
 
1561
+
1562
+
1563
+
1564
+
1565
+
1566
+
1567
+
1568
+
1569
+
1570
+
1571
+
1572
+
1573
+
1574
+
1575
+
1441
1576
 
1442
1577
 
1443
1578
 
@@ -1594,6 +1729,21 @@ export declare class TreeSet<K = any, R = K> implements Iterable<K> {
1594
1729
 
1595
1730
 
1596
1731
 
1732
+
1733
+
1734
+
1735
+
1736
+
1737
+
1738
+
1739
+
1740
+
1741
+
1742
+
1743
+
1744
+
1745
+
1746
+
1597
1747
 
1598
1748
 
1599
1749
 
@@ -1749,6 +1899,21 @@ export declare class TreeSet<K = any, R = K> implements Iterable<K> {
1749
1899
 
1750
1900
 
1751
1901
 
1902
+
1903
+
1904
+
1905
+
1906
+
1907
+
1908
+
1909
+
1910
+
1911
+
1912
+
1913
+
1914
+
1915
+
1916
+
1752
1917
 
1753
1918
 
1754
1919
 
@@ -1902,6 +2067,21 @@ export declare class TreeSet<K = any, R = K> implements Iterable<K> {
1902
2067
 
1903
2068
 
1904
2069
 
2070
+
2071
+
2072
+
2073
+
2074
+
2075
+
2076
+
2077
+
2078
+
2079
+
2080
+
2081
+
2082
+
2083
+
2084
+
1905
2085
 
1906
2086
 
1907
2087
 
@@ -2053,6 +2233,21 @@ export declare class TreeSet<K = any, R = K> implements Iterable<K> {
2053
2233
 
2054
2234
 
2055
2235
 
2236
+
2237
+
2238
+
2239
+
2240
+
2241
+
2242
+
2243
+
2244
+
2245
+
2246
+
2247
+
2248
+
2249
+
2250
+
2056
2251
 
2057
2252
 
2058
2253
 
@@ -2203,6 +2398,21 @@ export declare class TreeSet<K = any, R = K> implements Iterable<K> {
2203
2398
 
2204
2399
 
2205
2400
 
2401
+
2402
+
2403
+
2404
+
2405
+
2406
+
2407
+
2408
+
2409
+
2410
+
2411
+
2412
+
2413
+
2414
+
2415
+
2206
2416
 
2207
2417
 
2208
2418
 
@@ -2353,6 +2563,21 @@ export declare class TreeSet<K = any, R = K> implements Iterable<K> {
2353
2563
 
2354
2564
 
2355
2565
 
2566
+
2567
+
2568
+
2569
+
2570
+
2571
+
2572
+
2573
+
2574
+
2575
+
2576
+
2577
+
2578
+
2579
+
2580
+
2356
2581
 
2357
2582
 
2358
2583
 
@@ -2506,6 +2731,21 @@ export declare class TreeSet<K = any, R = K> implements Iterable<K> {
2506
2731
 
2507
2732
 
2508
2733
 
2734
+
2735
+
2736
+
2737
+
2738
+
2739
+
2740
+
2741
+
2742
+
2743
+
2744
+
2745
+
2746
+
2747
+
2748
+
2509
2749
 
2510
2750
 
2511
2751
 
@@ -2658,6 +2898,21 @@ export declare class TreeSet<K = any, R = K> implements Iterable<K> {
2658
2898
 
2659
2899
 
2660
2900
 
2901
+
2902
+
2903
+
2904
+
2905
+
2906
+
2907
+
2908
+
2909
+
2910
+
2911
+
2912
+
2913
+
2914
+
2915
+
2661
2916
 
2662
2917
 
2663
2918
 
@@ -2710,6 +2965,9 @@ export declare class TreeSet<K = any, R = K> implements Iterable<K> {
2710
2965
 
2711
2966
 
2712
2967
 
2968
+
2969
+
2970
+
2713
2971
 
2714
2972
 
2715
2973
 
@@ -2773,6 +3031,9 @@ export declare class TreeSet<K = any, R = K> implements Iterable<K> {
2773
3031
 
2774
3032
 
2775
3033
 
3034
+
3035
+
3036
+
2776
3037
 
2777
3038
 
2778
3039
 
@@ -2814,6 +3075,9 @@ export declare class TreeSet<K = any, R = K> implements Iterable<K> {
2814
3075
 
2815
3076
 
2816
3077
 
3078
+
3079
+
3080
+
2817
3081
 
2818
3082
 
2819
3083
 
@@ -2857,6 +3121,9 @@ export declare class TreeSet<K = any, R = K> implements Iterable<K> {
2857
3121
 
2858
3122
 
2859
3123
 
3124
+
3125
+
3126
+
2860
3127
 
2861
3128
 
2862
3129
 
@@ -2980,6 +3247,18 @@ export declare class TreeSet<K = any, R = K> implements Iterable<K> {
2980
3247
 
2981
3248
 
2982
3249
 
3250
+
3251
+
3252
+
3253
+
3254
+
3255
+
3256
+
3257
+
3258
+
3259
+
3260
+
3261
+
2983
3262
 
2984
3263
 
2985
3264
 
@@ -3122,6 +3401,18 @@ export declare class TreeSet<K = any, R = K> implements Iterable<K> {
3122
3401
 
3123
3402
 
3124
3403
 
3404
+
3405
+
3406
+
3407
+
3408
+
3409
+
3410
+
3411
+
3412
+
3413
+
3414
+
3415
+
3125
3416
 
3126
3417
 
3127
3418
 
@@ -3256,6 +3547,18 @@ export declare class TreeSet<K = any, R = K> implements Iterable<K> {
3256
3547
 
3257
3548
 
3258
3549
 
3550
+
3551
+
3552
+
3553
+
3554
+
3555
+
3556
+
3557
+
3558
+
3559
+
3560
+
3561
+
3259
3562
 
3260
3563
 
3261
3564
 
@@ -3388,6 +3691,18 @@ export declare class TreeSet<K = any, R = K> implements Iterable<K> {
3388
3691
 
3389
3692
 
3390
3693
 
3694
+
3695
+
3696
+
3697
+
3698
+
3699
+
3700
+
3701
+
3702
+
3703
+
3704
+
3705
+
3391
3706
 
3392
3707
 
3393
3708
 
@@ -3523,6 +3838,18 @@ export declare class TreeSet<K = any, R = K> implements Iterable<K> {
3523
3838
 
3524
3839
 
3525
3840
 
3841
+
3842
+
3843
+
3844
+
3845
+
3846
+
3847
+
3848
+
3849
+
3850
+
3851
+
3852
+
3526
3853
 
3527
3854
 
3528
3855
 
@@ -3555,6 +3882,55 @@ export declare class TreeSet<K = any, R = K> implements Iterable<K> {
3555
3882
  * console.log(blocklist.has(167772800)); // false;
3556
3883
  */
3557
3884
  rangeSearch(range: [K, K], options?: TreeSetRangeOptions): K[];
3885
+ /**
3886
+ * Returns the element at the k-th position in tree order (0-indexed).
3887
+ * @remarks Time O(log n). Requires `enableOrderStatistic: true`.
3888
+
3889
+
3890
+
3891
+ * @example
3892
+ * // Find k-th element in a TreeSet
3893
+ * const set = new TreeSet<number>([30, 10, 50, 20, 40], { enableOrderStatistic: true });
3894
+ * console.log(set.getByRank(0)); // 10;
3895
+ * console.log(set.getByRank(2)); // 30;
3896
+ * console.log(set.getRank(30)); // 2;
3897
+ */
3898
+ getByRank(k: number): K | undefined;
3899
+ /**
3900
+ * Returns the 0-based rank of a key (number of elements that precede it in tree order).
3901
+ * @remarks Time O(log n). Requires `enableOrderStatistic: true`.
3902
+ * @example
3903
+ * // Get the rank of a key in sorted order
3904
+ * const tree = new TreeSet<number>(
3905
+ * [10, 20, 30, 40, 50],
3906
+ * { enableOrderStatistic: true }
3907
+ * );
3908
+ * console.log(tree.getRank(10)); // 0; // smallest → rank 0
3909
+ * console.log(tree.getRank(30)); // 2; // 2 elements before 30 in tree order
3910
+ * console.log(tree.getRank(50)); // 4; // largest → rank 4
3911
+ * console.log(tree.getRank(25)); // 2;
3912
+ */
3913
+ getRank(key: K): number;
3914
+ /**
3915
+ * Returns elements by rank range (0-indexed, inclusive on both ends).
3916
+ * @remarks Time O(log n + k). Requires `enableOrderStatistic: true`.
3917
+
3918
+ * @example
3919
+ * // Pagination with rangeByRank
3920
+ * const tree = new TreeSet<number>(
3921
+ * [10, 20, 30, 40, 50, 60, 70, 80, 90],
3922
+ * { enableOrderStatistic: true }
3923
+ * );
3924
+ * const pageSize = 3;
3925
+ *
3926
+ * // Page 1
3927
+ * console.log(tree.rangeByRank(0, pageSize - 1)); // [10, 20, 30];
3928
+ * // Page 2
3929
+ * console.log(tree.rangeByRank(pageSize, 2 * pageSize - 1)); // [40, 50, 60];
3930
+ * // Page 3
3931
+ * console.log(tree.rangeByRank(2 * pageSize, 3 * pageSize - 1)); // [70, 80, 90];
3932
+ */
3933
+ rangeByRank(start: number, end: number): K[];
3558
3934
  /**
3559
3935
  * Creates a shallow clone of this set.
3560
3936
  * @remarks Time O(n log n), Space O(n)
@@ -3686,6 +4062,21 @@ export declare class TreeSet<K = any, R = K> implements Iterable<K> {
3686
4062
 
3687
4063
 
3688
4064
 
4065
+
4066
+
4067
+
4068
+
4069
+
4070
+
4071
+
4072
+
4073
+
4074
+
4075
+
4076
+
4077
+
4078
+
4079
+
3689
4080
 
3690
4081
 
3691
4082
 
@@ -182,6 +182,9 @@ export declare class DirectedGraph<V = any, E = any, VO extends DirectedVertex<V
182
182
 
183
183
 
184
184
 
185
+
186
+
187
+
185
188
 
186
189
 
187
190
 
@@ -238,6 +241,9 @@ export declare class DirectedGraph<V = any, E = any, VO extends DirectedVertex<V
238
241
 
239
242
 
240
243
 
244
+
245
+
246
+
241
247
 
242
248
 
243
249
 
@@ -296,6 +302,9 @@ export declare class DirectedGraph<V = any, E = any, VO extends DirectedVertex<V
296
302
 
297
303
 
298
304
 
305
+
306
+
307
+
299
308
 
300
309
 
301
310
 
@@ -342,6 +351,9 @@ export declare class DirectedGraph<V = any, E = any, VO extends DirectedVertex<V
342
351
 
343
352
 
344
353
 
354
+
355
+
356
+
345
357
 
346
358
 
347
359
 
@@ -387,6 +399,9 @@ export declare class DirectedGraph<V = any, E = any, VO extends DirectedVertex<V
387
399
 
388
400
 
389
401
 
402
+
403
+
404
+
390
405
 
391
406
 
392
407
 
@@ -460,6 +475,9 @@ export declare class DirectedGraph<V = any, E = any, VO extends DirectedVertex<V
460
475
 
461
476
 
462
477
 
478
+
479
+
480
+
463
481
 
464
482
 
465
483
 
@@ -515,6 +533,9 @@ export declare class DirectedGraph<V = any, E = any, VO extends DirectedVertex<V
515
533
 
516
534
 
517
535
 
536
+
537
+
538
+
518
539
 
519
540
 
520
541
 
@@ -556,6 +577,9 @@ export declare class DirectedGraph<V = any, E = any, VO extends DirectedVertex<V
556
577
 
557
578
 
558
579
 
580
+
581
+
582
+
559
583
 
560
584
 
561
585
 
@@ -624,6 +648,9 @@ export declare class DirectedGraph<V = any, E = any, VO extends DirectedVertex<V
624
648
 
625
649
 
626
650
 
651
+
652
+
653
+
627
654
 
628
655
 
629
656
 
@@ -688,6 +715,9 @@ export declare class DirectedGraph<V = any, E = any, VO extends DirectedVertex<V
688
715
 
689
716
 
690
717
 
718
+
719
+
720
+
691
721
 
692
722
 
693
723