binary-tree-typed 2.5.3 → 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 (61) hide show
  1. package/dist/cjs/index.cjs +126 -0
  2. package/dist/cjs/index.cjs.map +1 -1
  3. package/dist/cjs-legacy/index.cjs +126 -0
  4. package/dist/cjs-legacy/index.cjs.map +1 -1
  5. package/dist/esm/index.mjs +126 -0
  6. package/dist/esm/index.mjs.map +1 -1
  7. package/dist/esm-legacy/index.mjs +126 -0
  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 +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 +75 -0
  14. package/dist/types/data-structures/binary-tree/bst.d.ts +72 -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 +375 -0
  18. package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +389 -0
  19. package/dist/types/data-structures/binary-tree/tree-multi-set.d.ts +330 -0
  20. package/dist/types/data-structures/binary-tree/tree-set.d.ts +438 -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 +75 -2
  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 +90 -1
  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/umd/binary-tree-typed.js +126 -0
  34. package/dist/umd/binary-tree-typed.js.map +1 -1
  35. package/dist/umd/binary-tree-typed.min.js +1 -1
  36. package/dist/umd/binary-tree-typed.min.js.map +1 -1
  37. package/package.json +2 -2
  38. package/src/data-structures/base/iterable-element-base.ts +32 -0
  39. package/src/data-structures/base/linear-base.ts +11 -0
  40. package/src/data-structures/binary-tree/avl-tree.ts +36 -0
  41. package/src/data-structures/binary-tree/binary-indexed-tree.ts +42 -0
  42. package/src/data-structures/binary-tree/binary-tree.ts +75 -0
  43. package/src/data-structures/binary-tree/bst.ts +72 -0
  44. package/src/data-structures/binary-tree/red-black-tree.ts +57 -0
  45. package/src/data-structures/binary-tree/segment-tree.ts +18 -0
  46. package/src/data-structures/binary-tree/tree-map.ts +375 -0
  47. package/src/data-structures/binary-tree/tree-multi-map.ts +392 -0
  48. package/src/data-structures/binary-tree/tree-multi-set.ts +336 -0
  49. package/src/data-structures/binary-tree/tree-set.ts +492 -0
  50. package/src/data-structures/graph/directed-graph.ts +30 -0
  51. package/src/data-structures/graph/undirected-graph.ts +27 -0
  52. package/src/data-structures/hash/hash-map.ts +33 -0
  53. package/src/data-structures/heap/heap.ts +42 -0
  54. package/src/data-structures/linked-list/doubly-linked-list.ts +90 -2
  55. package/src/data-structures/linked-list/singly-linked-list.ts +45 -0
  56. package/src/data-structures/linked-list/skip-linked-list.ts +54 -0
  57. package/src/data-structures/matrix/matrix.ts +24 -0
  58. package/src/data-structures/queue/deque.ts +103 -1
  59. package/src/data-structures/queue/queue.ts +36 -0
  60. package/src/data-structures/stack/stack.ts +30 -0
  61. package/src/data-structures/trie/trie.ts +36 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "binary-tree-typed",
3
- "version": "2.5.3",
3
+ "version": "2.6.0",
4
4
  "description": "Binary Tree. Javascript & Typescript Data Structure.",
5
5
  "browser": "dist/umd/binary-tree-typed.min.js",
6
6
  "umd:main": "dist/umd/binary-tree-typed.min.js",
@@ -178,6 +178,6 @@
178
178
  "typescript": "^4.9.5"
179
179
  },
180
180
  "dependencies": {
181
- "data-structure-typed": "^2.5.3"
181
+ "data-structure-typed": "^2.6.0"
182
182
  }
183
183
  }
@@ -191,6 +191,38 @@ export abstract class IterableElementBase<E, R> implements Iterable<E> {
191
191
  return false;
192
192
  }
193
193
 
194
+ /**
195
+ * Check whether a value exists (Array-compatible alias for `has`).
196
+ * @remarks Provided for familiarity when migrating from Array. Time O(n), Space O(1).
197
+ * @param element - Element to search for (uses `===`).
198
+ * @returns `true` if found.
199
+ */
200
+ includes(element: E): boolean {
201
+ return this.has(element);
202
+ }
203
+
204
+ /**
205
+ * Return an iterator of `[index, value]` pairs (Array-compatible).
206
+ * @remarks Provided for familiarity when migrating from Array. Time O(n), Space O(1) per step.
207
+ */
208
+ *entries(): IterableIterator<[number, E]> {
209
+ let index = 0;
210
+ for (const value of this) {
211
+ yield [index++, value];
212
+ }
213
+ }
214
+
215
+ /**
216
+ * Return an iterator of numeric indices (Array-compatible).
217
+ * @remarks Provided for familiarity when migrating from Array. Time O(n), Space O(1) per step.
218
+ */
219
+ *keys(): IterableIterator<number> {
220
+ let index = 0;
221
+ for (const _ of this) {
222
+ yield index++;
223
+ }
224
+ }
225
+
194
226
  reduce(callbackfn: ReduceElementCallback<E, R>): E;
195
227
  reduce(callbackfn: ReduceElementCallback<E, R>, initialValue: E): E;
196
228
  reduce<U>(callbackfn: ReduceElementCallback<E, R, U>, initialValue: U): U;
@@ -327,6 +327,17 @@ export abstract class LinearBase<
327
327
  */
328
328
  abstract reverse(): this;
329
329
 
330
+ /**
331
+ * Return a new instance of the same type with elements in reverse order (non-mutating).
332
+ * @remarks Provided for familiarity when migrating from Array (ES2023 `toReversed`). Time O(n), Space O(n).
333
+ * @returns A new reversed instance.
334
+ */
335
+ toReversed(): this {
336
+ const cloned = this.clone();
337
+ cloned.reverse();
338
+ return cloned as this;
339
+ }
340
+
330
341
  /**
331
342
  * Append one element or node to the tail.
332
343
  * @param elementOrNode - Element or node.
@@ -494,6 +494,18 @@ export class AVLTree<K = any, V = any, R = any> extends BST<K, V, R> implements
494
494
 
495
495
 
496
496
 
497
+
498
+
499
+
500
+
501
+
502
+
503
+
504
+
505
+
506
+
507
+
508
+
497
509
 
498
510
 
499
511
 
@@ -638,6 +650,15 @@ export class AVLTree<K = any, V = any, R = any> extends BST<K, V, R> implements
638
650
 
639
651
 
640
652
 
653
+
654
+
655
+
656
+
657
+
658
+
659
+
660
+
661
+
641
662
 
642
663
 
643
664
 
@@ -736,6 +757,12 @@ export class AVLTree<K = any, V = any, R = any> extends BST<K, V, R> implements
736
757
 
737
758
 
738
759
 
760
+
761
+
762
+
763
+
764
+
765
+
739
766
 
740
767
 
741
768
 
@@ -888,6 +915,15 @@ export class AVLTree<K = any, V = any, R = any> extends BST<K, V, R> implements
888
915
 
889
916
 
890
917
 
918
+
919
+
920
+
921
+
922
+
923
+
924
+
925
+
926
+
891
927
 
892
928
 
893
929
 
@@ -119,6 +119,12 @@ export class BinaryIndexedTree implements Iterable<number> {
119
119
 
120
120
 
121
121
 
122
+
123
+
124
+
125
+
126
+
127
+
122
128
 
123
129
 
124
130
 
@@ -204,6 +210,12 @@ export class BinaryIndexedTree implements Iterable<number> {
204
210
 
205
211
 
206
212
 
213
+
214
+
215
+
216
+
217
+
218
+
207
219
 
208
220
 
209
221
 
@@ -289,6 +301,12 @@ export class BinaryIndexedTree implements Iterable<number> {
289
301
 
290
302
 
291
303
 
304
+
305
+
306
+
307
+
308
+
309
+
292
310
 
293
311
 
294
312
 
@@ -374,6 +392,12 @@ export class BinaryIndexedTree implements Iterable<number> {
374
392
 
375
393
 
376
394
 
395
+
396
+
397
+
398
+
399
+
400
+
377
401
 
378
402
 
379
403
 
@@ -457,6 +481,12 @@ export class BinaryIndexedTree implements Iterable<number> {
457
481
 
458
482
 
459
483
 
484
+
485
+
486
+
487
+
488
+
489
+
460
490
 
461
491
 
462
492
 
@@ -548,6 +578,12 @@ export class BinaryIndexedTree implements Iterable<number> {
548
578
 
549
579
 
550
580
 
581
+
582
+
583
+
584
+
585
+
586
+
551
587
 
552
588
 
553
589
 
@@ -608,6 +644,9 @@ export class BinaryIndexedTree implements Iterable<number> {
608
644
 
609
645
 
610
646
 
647
+
648
+
649
+
611
650
 
612
651
 
613
652
 
@@ -681,6 +720,9 @@ export class BinaryIndexedTree implements Iterable<number> {
681
720
 
682
721
 
683
722
 
723
+
724
+
725
+
684
726
 
685
727
 
686
728
 
@@ -596,6 +596,9 @@ export class BinaryTree<K = any, V = any, R = any>
596
596
 
597
597
 
598
598
 
599
+
600
+
601
+
599
602
 
600
603
 
601
604
 
@@ -657,6 +660,9 @@ export class BinaryTree<K = any, V = any, R = any>
657
660
 
658
661
 
659
662
 
663
+
664
+
665
+
660
666
 
661
667
 
662
668
 
@@ -780,6 +786,9 @@ export class BinaryTree<K = any, V = any, R = any>
780
786
 
781
787
 
782
788
 
789
+
790
+
791
+
783
792
 
784
793
 
785
794
 
@@ -831,6 +840,9 @@ export class BinaryTree<K = any, V = any, R = any>
831
840
 
832
841
 
833
842
 
843
+
844
+
845
+
834
846
 
835
847
 
836
848
 
@@ -908,6 +920,9 @@ export class BinaryTree<K = any, V = any, R = any>
908
920
 
909
921
 
910
922
 
923
+
924
+
925
+
911
926
 
912
927
 
913
928
 
@@ -1025,6 +1040,9 @@ export class BinaryTree<K = any, V = any, R = any>
1025
1040
 
1026
1041
 
1027
1042
 
1043
+
1044
+
1045
+
1028
1046
 
1029
1047
 
1030
1048
 
@@ -1070,6 +1088,9 @@ export class BinaryTree<K = any, V = any, R = any>
1070
1088
 
1071
1089
 
1072
1090
 
1091
+
1092
+
1093
+
1073
1094
 
1074
1095
 
1075
1096
 
@@ -1210,6 +1231,9 @@ export class BinaryTree<K = any, V = any, R = any>
1210
1231
 
1211
1232
 
1212
1233
 
1234
+
1235
+
1236
+
1213
1237
 
1214
1238
 
1215
1239
 
@@ -1289,6 +1313,9 @@ export class BinaryTree<K = any, V = any, R = any>
1289
1313
 
1290
1314
 
1291
1315
 
1316
+
1317
+
1318
+
1292
1319
 
1293
1320
 
1294
1321
 
@@ -1362,6 +1389,9 @@ export class BinaryTree<K = any, V = any, R = any>
1362
1389
 
1363
1390
 
1364
1391
 
1392
+
1393
+
1394
+
1365
1395
 
1366
1396
 
1367
1397
 
@@ -1428,6 +1458,9 @@ export class BinaryTree<K = any, V = any, R = any>
1428
1458
 
1429
1459
 
1430
1460
 
1461
+
1462
+
1463
+
1431
1464
 
1432
1465
 
1433
1466
 
@@ -1530,6 +1563,9 @@ export class BinaryTree<K = any, V = any, R = any>
1530
1563
 
1531
1564
 
1532
1565
 
1566
+
1567
+
1568
+
1533
1569
 
1534
1570
 
1535
1571
 
@@ -1583,6 +1619,9 @@ export class BinaryTree<K = any, V = any, R = any>
1583
1619
 
1584
1620
 
1585
1621
 
1622
+
1623
+
1624
+
1586
1625
 
1587
1626
 
1588
1627
 
@@ -1648,6 +1687,9 @@ export class BinaryTree<K = any, V = any, R = any>
1648
1687
 
1649
1688
 
1650
1689
 
1690
+
1691
+
1692
+
1651
1693
 
1652
1694
 
1653
1695
 
@@ -1743,6 +1785,9 @@ export class BinaryTree<K = any, V = any, R = any>
1743
1785
 
1744
1786
 
1745
1787
 
1788
+
1789
+
1790
+
1746
1791
 
1747
1792
 
1748
1793
 
@@ -1812,6 +1857,9 @@ export class BinaryTree<K = any, V = any, R = any>
1812
1857
 
1813
1858
 
1814
1859
 
1860
+
1861
+
1862
+
1815
1863
 
1816
1864
 
1817
1865
 
@@ -2122,6 +2170,9 @@ export class BinaryTree<K = any, V = any, R = any>
2122
2170
 
2123
2171
 
2124
2172
 
2173
+
2174
+
2175
+
2125
2176
 
2126
2177
 
2127
2178
 
@@ -2214,6 +2265,9 @@ export class BinaryTree<K = any, V = any, R = any>
2214
2265
 
2215
2266
 
2216
2267
 
2268
+
2269
+
2270
+
2217
2271
 
2218
2272
 
2219
2273
 
@@ -2365,6 +2419,9 @@ export class BinaryTree<K = any, V = any, R = any>
2365
2419
 
2366
2420
 
2367
2421
 
2422
+
2423
+
2424
+
2368
2425
 
2369
2426
 
2370
2427
 
@@ -2469,6 +2526,9 @@ export class BinaryTree<K = any, V = any, R = any>
2469
2526
 
2470
2527
 
2471
2528
 
2529
+
2530
+
2531
+
2472
2532
 
2473
2533
 
2474
2534
 
@@ -2591,6 +2651,9 @@ export class BinaryTree<K = any, V = any, R = any>
2591
2651
 
2592
2652
 
2593
2653
 
2654
+
2655
+
2656
+
2594
2657
 
2595
2658
 
2596
2659
 
@@ -2757,6 +2820,9 @@ export class BinaryTree<K = any, V = any, R = any>
2757
2820
 
2758
2821
 
2759
2822
 
2823
+
2824
+
2825
+
2760
2826
 
2761
2827
 
2762
2828
 
@@ -2814,6 +2880,9 @@ export class BinaryTree<K = any, V = any, R = any>
2814
2880
 
2815
2881
 
2816
2882
 
2883
+
2884
+
2885
+
2817
2886
 
2818
2887
 
2819
2888
 
@@ -2875,6 +2944,9 @@ export class BinaryTree<K = any, V = any, R = any>
2875
2944
 
2876
2945
 
2877
2946
 
2947
+
2948
+
2949
+
2878
2950
 
2879
2951
 
2880
2952
 
@@ -2969,6 +3041,9 @@ export class BinaryTree<K = any, V = any, R = any>
2969
3041
 
2970
3042
 
2971
3043
 
3044
+
3045
+
3046
+
2972
3047
 
2973
3048
 
2974
3049
 
@@ -509,6 +509,12 @@ export class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R> implemen
509
509
 
510
510
 
511
511
 
512
+
513
+
514
+
515
+
516
+
517
+
512
518
 
513
519
 
514
520
 
@@ -619,6 +625,12 @@ export class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R> implemen
619
625
 
620
626
 
621
627
 
628
+
629
+
630
+
631
+
632
+
633
+
622
634
 
623
635
 
624
636
 
@@ -725,6 +737,12 @@ export class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R> implemen
725
737
 
726
738
 
727
739
 
740
+
741
+
742
+
743
+
744
+
745
+
728
746
 
729
747
 
730
748
 
@@ -843,6 +861,12 @@ export class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R> implemen
843
861
 
844
862
 
845
863
 
864
+
865
+
866
+
867
+
868
+
869
+
846
870
 
847
871
 
848
872
 
@@ -980,6 +1004,12 @@ export class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R> implemen
980
1004
 
981
1005
 
982
1006
 
1007
+
1008
+
1009
+
1010
+
1011
+
1012
+
983
1013
 
984
1014
 
985
1015
 
@@ -1182,6 +1212,9 @@ export class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R> implemen
1182
1212
 
1183
1213
 
1184
1214
 
1215
+
1216
+
1217
+
1185
1218
 
1186
1219
 
1187
1220
 
@@ -1553,6 +1586,15 @@ export class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R> implemen
1553
1586
 
1554
1587
 
1555
1588
 
1589
+
1590
+
1591
+
1592
+
1593
+
1594
+
1595
+
1596
+
1597
+
1556
1598
 
1557
1599
 
1558
1600
 
@@ -1689,6 +1731,12 @@ export class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R> implemen
1689
1731
 
1690
1732
 
1691
1733
 
1734
+
1735
+
1736
+
1737
+
1738
+
1739
+
1692
1740
 
1693
1741
 
1694
1742
 
@@ -1835,6 +1883,9 @@ export class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R> implemen
1835
1883
 
1836
1884
 
1837
1885
 
1886
+
1887
+
1888
+
1838
1889
 
1839
1890
 
1840
1891
 
@@ -1945,6 +1996,9 @@ export class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R> implemen
1945
1996
 
1946
1997
 
1947
1998
 
1999
+
2000
+
2001
+
1948
2002
 
1949
2003
 
1950
2004
 
@@ -2054,6 +2108,9 @@ export class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R> implemen
2054
2108
 
2055
2109
 
2056
2110
 
2111
+
2112
+
2113
+
2057
2114
 
2058
2115
 
2059
2116
 
@@ -2207,6 +2264,9 @@ export class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R> implemen
2207
2264
 
2208
2265
 
2209
2266
 
2267
+
2268
+
2269
+
2210
2270
 
2211
2271
 
2212
2272
 
@@ -2416,6 +2476,9 @@ export class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R> implemen
2416
2476
 
2417
2477
 
2418
2478
 
2479
+
2480
+
2481
+
2419
2482
 
2420
2483
 
2421
2484
 
@@ -2493,6 +2556,9 @@ export class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R> implemen
2493
2556
 
2494
2557
 
2495
2558
 
2559
+
2560
+
2561
+
2496
2562
 
2497
2563
 
2498
2564
 
@@ -2626,6 +2692,12 @@ export class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R> implemen
2626
2692
 
2627
2693
 
2628
2694
 
2695
+
2696
+
2697
+
2698
+
2699
+
2700
+
2629
2701
 
2630
2702
 
2631
2703
 
@@ -468,6 +468,18 @@ export class RedBlackTree<K = any, V = any, R = any> extends BST<K, V, R> implem
468
468
 
469
469
 
470
470
 
471
+
472
+
473
+
474
+
475
+
476
+
477
+
478
+
479
+
480
+
481
+
482
+
471
483
 
472
484
 
473
485
 
@@ -1016,6 +1028,18 @@ export class RedBlackTree<K = any, V = any, R = any> extends BST<K, V, R> implem
1016
1028
 
1017
1029
 
1018
1030
 
1031
+
1032
+
1033
+
1034
+
1035
+
1036
+
1037
+
1038
+
1039
+
1040
+
1041
+
1042
+
1019
1043
 
1020
1044
 
1021
1045
 
@@ -1244,6 +1268,18 @@ export class RedBlackTree<K = any, V = any, R = any> extends BST<K, V, R> implem
1244
1268
 
1245
1269
 
1246
1270
 
1271
+
1272
+
1273
+
1274
+
1275
+
1276
+
1277
+
1278
+
1279
+
1280
+
1281
+
1282
+
1247
1283
 
1248
1284
 
1249
1285
 
@@ -1464,6 +1500,15 @@ export class RedBlackTree<K = any, V = any, R = any> extends BST<K, V, R> implem
1464
1500
 
1465
1501
 
1466
1502
 
1503
+
1504
+
1505
+
1506
+
1507
+
1508
+
1509
+
1510
+
1511
+
1467
1512
 
1468
1513
 
1469
1514
 
@@ -1630,6 +1675,18 @@ export class RedBlackTree<K = any, V = any, R = any> extends BST<K, V, R> implem
1630
1675
 
1631
1676
 
1632
1677
 
1678
+
1679
+
1680
+
1681
+
1682
+
1683
+
1684
+
1685
+
1686
+
1687
+
1688
+
1689
+
1633
1690
 
1634
1691
 
1635
1692