binary-tree-typed 2.5.0 → 2.5.1

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 (75) hide show
  1. package/dist/cjs/index.cjs +609 -0
  2. package/dist/cjs/index.cjs.map +1 -1
  3. package/dist/cjs-legacy/index.cjs +609 -0
  4. package/dist/cjs-legacy/index.cjs.map +1 -1
  5. package/dist/esm/index.mjs +609 -0
  6. package/dist/esm/index.mjs.map +1 -1
  7. package/dist/esm-legacy/index.mjs +609 -0
  8. package/dist/esm-legacy/index.mjs.map +1 -1
  9. package/dist/types/data-structures/base/index.d.ts +1 -0
  10. package/dist/types/data-structures/base/iterable-entry-base.d.ts +8 -8
  11. package/dist/types/data-structures/base/linear-base.d.ts +3 -3
  12. package/dist/types/data-structures/binary-tree/avl-tree.d.ts +252 -0
  13. package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +294 -0
  14. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +527 -2
  15. package/dist/types/data-structures/binary-tree/bst.d.ts +505 -1
  16. package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +399 -0
  17. package/dist/types/data-structures/binary-tree/segment-tree.d.ts +126 -1
  18. package/dist/types/data-structures/binary-tree/tree-map.d.ts +2881 -382
  19. package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +2867 -347
  20. package/dist/types/data-structures/binary-tree/tree-multi-set.d.ts +2328 -312
  21. package/dist/types/data-structures/binary-tree/tree-set.d.ts +2671 -277
  22. package/dist/types/data-structures/graph/abstract-graph.d.ts +4 -4
  23. package/dist/types/data-structures/graph/directed-graph.d.ts +210 -0
  24. package/dist/types/data-structures/graph/undirected-graph.d.ts +189 -0
  25. package/dist/types/data-structures/hash/hash-map.d.ts +241 -10
  26. package/dist/types/data-structures/heap/heap.d.ts +294 -0
  27. package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +360 -3
  28. package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +318 -3
  29. package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +380 -2
  30. package/dist/types/data-structures/matrix/matrix.d.ts +168 -0
  31. package/dist/types/data-structures/queue/deque.d.ts +319 -4
  32. package/dist/types/data-structures/queue/queue.d.ts +252 -0
  33. package/dist/types/data-structures/stack/stack.d.ts +210 -0
  34. package/dist/types/data-structures/trie/trie.d.ts +256 -4
  35. package/dist/types/interfaces/graph.d.ts +1 -1
  36. package/dist/types/types/common.d.ts +2 -2
  37. package/dist/types/types/data-structures/heap/heap.d.ts +1 -0
  38. package/dist/types/types/data-structures/priority-queue/priority-queue.d.ts +1 -0
  39. package/dist/types/types/utils/validate-type.d.ts +4 -4
  40. package/dist/umd/binary-tree-typed.js +609 -0
  41. package/dist/umd/binary-tree-typed.js.map +1 -1
  42. package/dist/umd/binary-tree-typed.min.js +5 -5
  43. package/dist/umd/binary-tree-typed.min.js.map +1 -1
  44. package/package.json +2 -2
  45. package/src/data-structures/base/index.ts +1 -0
  46. package/src/data-structures/base/iterable-entry-base.ts +8 -8
  47. package/src/data-structures/base/linear-base.ts +3 -3
  48. package/src/data-structures/binary-tree/avl-tree.ts +252 -0
  49. package/src/data-structures/binary-tree/binary-indexed-tree.ts +295 -1
  50. package/src/data-structures/binary-tree/binary-tree.ts +527 -2
  51. package/src/data-structures/binary-tree/bst.ts +505 -1
  52. package/src/data-structures/binary-tree/red-black-tree.ts +399 -0
  53. package/src/data-structures/binary-tree/segment-tree.ts +127 -2
  54. package/src/data-structures/binary-tree/tree-map.ts +2958 -459
  55. package/src/data-structures/binary-tree/tree-multi-map.ts +3069 -549
  56. package/src/data-structures/binary-tree/tree-multi-set.ts +2476 -460
  57. package/src/data-structures/binary-tree/tree-set.ts +2816 -422
  58. package/src/data-structures/graph/abstract-graph.ts +4 -4
  59. package/src/data-structures/graph/directed-graph.ts +210 -0
  60. package/src/data-structures/graph/undirected-graph.ts +189 -0
  61. package/src/data-structures/hash/hash-map.ts +246 -15
  62. package/src/data-structures/heap/heap.ts +294 -0
  63. package/src/data-structures/linked-list/doubly-linked-list.ts +360 -3
  64. package/src/data-structures/linked-list/singly-linked-list.ts +318 -3
  65. package/src/data-structures/linked-list/skip-linked-list.ts +380 -2
  66. package/src/data-structures/matrix/matrix.ts +169 -1
  67. package/src/data-structures/queue/deque.ts +320 -5
  68. package/src/data-structures/queue/queue.ts +252 -0
  69. package/src/data-structures/stack/stack.ts +210 -0
  70. package/src/data-structures/trie/trie.ts +257 -5
  71. package/src/interfaces/graph.ts +1 -1
  72. package/src/types/common.ts +2 -2
  73. package/src/types/data-structures/heap/heap.ts +1 -0
  74. package/src/types/data-structures/priority-queue/priority-queue.ts +1 -0
  75. package/src/types/utils/validate-type.ts +4 -4
@@ -428,7 +428,7 @@ export class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R> implemen
428
428
  * @param key - The key to validate.
429
429
  * @returns True if the key is valid, false otherwise.
430
430
  */
431
- override isValidKey(key: any): key is K {
431
+ override isValidKey(key: unknown): key is K {
432
432
  return isComparable(key);
433
433
  }
434
434
 
@@ -454,6 +454,48 @@ export class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R> implemen
454
454
 
455
455
 
456
456
 
457
+
458
+
459
+
460
+
461
+
462
+
463
+
464
+
465
+
466
+
467
+
468
+
469
+
470
+
471
+
472
+
473
+
474
+
475
+
476
+
477
+
478
+
479
+
480
+
481
+
482
+
483
+
484
+
485
+
486
+
487
+
488
+
489
+
490
+
491
+
492
+
493
+
494
+
495
+
496
+
497
+
498
+
457
499
 
458
500
 
459
501
  * @example
@@ -510,6 +552,48 @@ export class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R> implemen
510
552
 
511
553
 
512
554
 
555
+
556
+
557
+
558
+
559
+
560
+
561
+
562
+
563
+
564
+
565
+
566
+
567
+
568
+
569
+
570
+
571
+
572
+
573
+
574
+
575
+
576
+
577
+
578
+
579
+
580
+
581
+
582
+
583
+
584
+
585
+
586
+
587
+
588
+
589
+
590
+
591
+
592
+
593
+
594
+
595
+
596
+
513
597
  * @example
514
598
  * // Breadth-first traversal
515
599
  * const bst = new BST<number>([5, 3, 7]);
@@ -560,6 +644,48 @@ export class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R> implemen
560
644
 
561
645
 
562
646
 
647
+
648
+
649
+
650
+
651
+
652
+
653
+
654
+
655
+
656
+
657
+
658
+
659
+
660
+
661
+
662
+
663
+
664
+
665
+
666
+
667
+
668
+
669
+
670
+
671
+
672
+
673
+
674
+
675
+
676
+
677
+
678
+
679
+
680
+
681
+
682
+
683
+
684
+
685
+
686
+
687
+
688
+
563
689
  * @example
564
690
  * // Level-order grouping
565
691
  * const bst = new BST<number>([5, 3, 7, 1, 4]);
@@ -622,6 +748,48 @@ export class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R> implemen
622
748
 
623
749
 
624
750
 
751
+
752
+
753
+
754
+
755
+
756
+
757
+
758
+
759
+
760
+
761
+
762
+
763
+
764
+
765
+
766
+
767
+
768
+
769
+
770
+
771
+
772
+
773
+
774
+
775
+
776
+
777
+
778
+
779
+
780
+
781
+
782
+
783
+
784
+
785
+
786
+
787
+
788
+
789
+
790
+
791
+
792
+
625
793
  * @example
626
794
  * // Get node object by key
627
795
  * const bst = new BST<number, string>([[5, 'root'], [3, 'left'], [7, 'right']]);
@@ -703,6 +871,48 @@ export class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R> implemen
703
871
 
704
872
 
705
873
 
874
+
875
+
876
+
877
+
878
+
879
+
880
+
881
+
882
+
883
+
884
+
885
+
886
+
887
+
888
+
889
+
890
+
891
+
892
+
893
+
894
+
895
+
896
+
897
+
898
+
899
+
900
+
901
+
902
+
903
+
904
+
905
+
906
+
907
+
908
+
909
+
910
+
911
+
912
+
913
+
914
+
915
+
706
916
  * @example
707
917
  * // Search nodes by predicate
708
918
  * const bst = new BST<number, string>([[1, 'a'], [2, 'b'], [3, 'c'], [4, 'd']]);
@@ -874,6 +1084,27 @@ export class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R> implemen
874
1084
 
875
1085
 
876
1086
 
1087
+
1088
+
1089
+
1090
+
1091
+
1092
+
1093
+
1094
+
1095
+
1096
+
1097
+
1098
+
1099
+
1100
+
1101
+
1102
+
1103
+
1104
+
1105
+
1106
+
1107
+
877
1108
  * @example
878
1109
  * // Find all keys in a range
879
1110
  * const bst = new BST<number>([10, 20, 30, 40, 50]);
@@ -936,6 +1167,69 @@ export class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R> implemen
936
1167
 
937
1168
 
938
1169
 
1170
+
1171
+
1172
+
1173
+
1174
+
1175
+
1176
+
1177
+
1178
+
1179
+
1180
+
1181
+
1182
+
1183
+
1184
+
1185
+
1186
+
1187
+
1188
+
1189
+
1190
+
1191
+
1192
+
1193
+
1194
+
1195
+
1196
+
1197
+
1198
+
1199
+
1200
+
1201
+
1202
+
1203
+
1204
+
1205
+
1206
+
1207
+
1208
+
1209
+
1210
+
1211
+
1212
+
1213
+
1214
+
1215
+
1216
+
1217
+
1218
+
1219
+
1220
+
1221
+
1222
+
1223
+
1224
+
1225
+
1226
+
1227
+
1228
+
1229
+
1230
+
1231
+
1232
+
939
1233
 
940
1234
 
941
1235
 
@@ -1015,6 +1309,48 @@ export class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R> implemen
1015
1309
 
1016
1310
 
1017
1311
 
1312
+
1313
+
1314
+
1315
+
1316
+
1317
+
1318
+
1319
+
1320
+
1321
+
1322
+
1323
+
1324
+
1325
+
1326
+
1327
+
1328
+
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
+
1018
1354
  * @example
1019
1355
  * // Set multiple key-value pairs
1020
1356
  * const bst = new BST<number, string>();
@@ -1130,6 +1466,27 @@ export class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R> implemen
1130
1466
 
1131
1467
 
1132
1468
 
1469
+
1470
+
1471
+
1472
+
1473
+
1474
+
1475
+
1476
+
1477
+
1478
+
1479
+
1480
+
1481
+
1482
+
1483
+
1484
+
1485
+
1486
+
1487
+
1488
+
1489
+
1133
1490
  * @example
1134
1491
  * // Find the least key ≥ target
1135
1492
  * const bst = new BST<number>([10, 20, 30, 40, 50]);
@@ -1212,6 +1569,27 @@ export class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R> implemen
1212
1569
 
1213
1570
 
1214
1571
 
1572
+
1573
+
1574
+
1575
+
1576
+
1577
+
1578
+
1579
+
1580
+
1581
+
1582
+
1583
+
1584
+
1585
+
1586
+
1587
+
1588
+
1589
+
1590
+
1591
+
1592
+
1215
1593
  * @example
1216
1594
  * // Find the least key strictly > target
1217
1595
  * const bst = new BST<number>([10, 20, 30, 40]);
@@ -1293,6 +1671,27 @@ export class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R> implemen
1293
1671
 
1294
1672
 
1295
1673
 
1674
+
1675
+
1676
+
1677
+
1678
+
1679
+
1680
+
1681
+
1682
+
1683
+
1684
+
1685
+
1686
+
1687
+
1688
+
1689
+
1690
+
1691
+
1692
+
1693
+
1694
+
1296
1695
  * @example
1297
1696
  * // Find the greatest key ≤ target
1298
1697
  * const bst = new BST<number>([10, 20, 30, 40, 50]);
@@ -1418,6 +1817,27 @@ export class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R> implemen
1418
1817
 
1419
1818
 
1420
1819
 
1820
+
1821
+
1822
+
1823
+
1824
+
1825
+
1826
+
1827
+
1828
+
1829
+
1830
+
1831
+
1832
+
1833
+
1834
+
1835
+
1836
+
1837
+
1838
+
1839
+
1840
+
1421
1841
  * @example
1422
1842
  * // Find the greatest key strictly < target
1423
1843
  * const bst = new BST<number>([10, 20, 30, 40]);
@@ -1599,6 +2019,27 @@ export class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R> implemen
1599
2019
 
1600
2020
 
1601
2021
 
2022
+
2023
+
2024
+
2025
+
2026
+
2027
+
2028
+
2029
+
2030
+
2031
+
2032
+
2033
+
2034
+
2035
+
2036
+
2037
+
2038
+
2039
+
2040
+
2041
+
2042
+
1602
2043
  * @example
1603
2044
  * // Rebalance the tree
1604
2045
  * const bst = new BST<number>();
@@ -1648,6 +2089,27 @@ export class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R> implemen
1648
2089
 
1649
2090
 
1650
2091
 
2092
+
2093
+
2094
+
2095
+
2096
+
2097
+
2098
+
2099
+
2100
+
2101
+
2102
+
2103
+
2104
+
2105
+
2106
+
2107
+
2108
+
2109
+
2110
+
2111
+
2112
+
1651
2113
  * @example
1652
2114
  * // Check if tree is height-balanced
1653
2115
  * const bst = new BST<number>([3, 1, 5, 2, 4]);
@@ -1728,6 +2190,48 @@ export class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R> implemen
1728
2190
 
1729
2191
 
1730
2192
 
2193
+
2194
+
2195
+
2196
+
2197
+
2198
+
2199
+
2200
+
2201
+
2202
+
2203
+
2204
+
2205
+
2206
+
2207
+
2208
+
2209
+
2210
+
2211
+
2212
+
2213
+
2214
+
2215
+
2216
+
2217
+
2218
+
2219
+
2220
+
2221
+
2222
+
2223
+
2224
+
2225
+
2226
+
2227
+
2228
+
2229
+
2230
+
2231
+
2232
+
2233
+
2234
+
1731
2235
  * @example
1732
2236
  * // Transform to new tree
1733
2237
  * const bst = new BST<number, number>([[1, 10], [2, 20], [3, 30]]);