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
@@ -249,6 +249,9 @@ export class DirectedGraph<
249
249
 
250
250
 
251
251
 
252
+
253
+
254
+
252
255
 
253
256
 
254
257
 
@@ -348,6 +351,9 @@ export class DirectedGraph<
348
351
 
349
352
 
350
353
 
354
+
355
+
356
+
351
357
 
352
358
 
353
359
 
@@ -442,6 +448,9 @@ export class DirectedGraph<
442
448
 
443
449
 
444
450
 
451
+
452
+
453
+
445
454
 
446
455
 
447
456
 
@@ -536,6 +545,9 @@ export class DirectedGraph<
536
545
 
537
546
 
538
547
 
548
+
549
+
550
+
539
551
 
540
552
 
541
553
 
@@ -595,6 +607,9 @@ export class DirectedGraph<
595
607
 
596
608
 
597
609
 
610
+
611
+
612
+
598
613
 
599
614
 
600
615
 
@@ -726,6 +741,9 @@ export class DirectedGraph<
726
741
 
727
742
 
728
743
 
744
+
745
+
746
+
729
747
 
730
748
 
731
749
 
@@ -824,6 +842,9 @@ export class DirectedGraph<
824
842
 
825
843
 
826
844
 
845
+
846
+
847
+
827
848
 
828
849
 
829
850
 
@@ -879,6 +900,9 @@ export class DirectedGraph<
879
900
 
880
901
 
881
902
 
903
+
904
+
905
+
882
906
 
883
907
 
884
908
 
@@ -992,6 +1016,9 @@ export class DirectedGraph<
992
1016
 
993
1017
 
994
1018
 
1019
+
1020
+
1021
+
995
1022
 
996
1023
 
997
1024
 
@@ -1115,6 +1142,9 @@ export class DirectedGraph<
1115
1142
 
1116
1143
 
1117
1144
 
1145
+
1146
+
1147
+
1118
1148
 
1119
1149
 
1120
1150
 
@@ -258,6 +258,9 @@ export class UndirectedGraph<
258
258
 
259
259
 
260
260
 
261
+
262
+
263
+
261
264
 
262
265
 
263
266
 
@@ -353,6 +356,9 @@ export class UndirectedGraph<
353
356
 
354
357
 
355
358
 
359
+
360
+
361
+
356
362
 
357
363
 
358
364
 
@@ -443,6 +449,9 @@ export class UndirectedGraph<
443
449
 
444
450
 
445
451
 
452
+
453
+
454
+
446
455
 
447
456
 
448
457
 
@@ -557,6 +566,9 @@ export class UndirectedGraph<
557
566
 
558
567
 
559
568
 
569
+
570
+
571
+
560
572
 
561
573
 
562
574
 
@@ -616,6 +628,9 @@ export class UndirectedGraph<
616
628
 
617
629
 
618
630
 
631
+
632
+
633
+
619
634
 
620
635
 
621
636
 
@@ -749,6 +764,9 @@ export class UndirectedGraph<
749
764
 
750
765
 
751
766
 
767
+
768
+
769
+
752
770
 
753
771
 
754
772
 
@@ -926,6 +944,9 @@ export class UndirectedGraph<
926
944
 
927
945
 
928
946
 
947
+
948
+
949
+
929
950
 
930
951
 
931
952
 
@@ -1001,6 +1022,9 @@ export class UndirectedGraph<
1001
1022
 
1002
1023
 
1003
1024
 
1025
+
1026
+
1027
+
1004
1028
 
1005
1029
 
1006
1030
 
@@ -1056,6 +1080,9 @@ export class UndirectedGraph<
1056
1080
 
1057
1081
 
1058
1082
 
1083
+
1084
+
1085
+
1059
1086
 
1060
1087
 
1061
1088
 
@@ -204,6 +204,9 @@ export class HashMap<K = any, V = any, R = [K, V]> extends IterableEntryBase<K,
204
204
 
205
205
 
206
206
 
207
+
208
+
209
+
207
210
 
208
211
 
209
212
 
@@ -254,6 +257,9 @@ export class HashMap<K = any, V = any, R = [K, V]> extends IterableEntryBase<K,
254
257
 
255
258
 
256
259
 
260
+
261
+
262
+
257
263
 
258
264
 
259
265
 
@@ -356,6 +362,12 @@ export class HashMap<K = any, V = any, R = [K, V]> extends IterableEntryBase<K,
356
362
 
357
363
 
358
364
 
365
+
366
+
367
+
368
+
369
+
370
+
359
371
 
360
372
 
361
373
 
@@ -432,6 +444,9 @@ export class HashMap<K = any, V = any, R = [K, V]> extends IterableEntryBase<K,
432
444
 
433
445
 
434
446
 
447
+
448
+
449
+
435
450
 
436
451
 
437
452
 
@@ -497,6 +512,9 @@ export class HashMap<K = any, V = any, R = [K, V]> extends IterableEntryBase<K,
497
512
 
498
513
 
499
514
 
515
+
516
+
517
+
500
518
 
501
519
 
502
520
 
@@ -569,6 +587,9 @@ export class HashMap<K = any, V = any, R = [K, V]> extends IterableEntryBase<K,
569
587
 
570
588
 
571
589
 
590
+
591
+
592
+
572
593
 
573
594
 
574
595
 
@@ -626,6 +647,9 @@ export class HashMap<K = any, V = any, R = [K, V]> extends IterableEntryBase<K,
626
647
 
627
648
 
628
649
 
650
+
651
+
652
+
629
653
 
630
654
 
631
655
 
@@ -702,6 +726,9 @@ export class HashMap<K = any, V = any, R = [K, V]> extends IterableEntryBase<K,
702
726
 
703
727
 
704
728
 
729
+
730
+
731
+
705
732
 
706
733
 
707
734
 
@@ -760,6 +787,9 @@ export class HashMap<K = any, V = any, R = [K, V]> extends IterableEntryBase<K,
760
787
 
761
788
 
762
789
 
790
+
791
+
792
+
763
793
 
764
794
 
765
795
 
@@ -820,6 +850,9 @@ export class HashMap<K = any, V = any, R = [K, V]> extends IterableEntryBase<K,
820
850
 
821
851
 
822
852
 
853
+
854
+
855
+
823
856
 
824
857
 
825
858
 
@@ -220,6 +220,9 @@ export class Heap<E = any, R = any> extends IterableElementBase<E, R> {
220
220
 
221
221
 
222
222
 
223
+
224
+
225
+
223
226
 
224
227
 
225
228
 
@@ -322,6 +325,9 @@ export class Heap<E = any, R = any> extends IterableElementBase<E, R> {
322
325
 
323
326
 
324
327
 
328
+
329
+
330
+
325
331
 
326
332
 
327
333
 
@@ -385,6 +391,9 @@ export class Heap<E = any, R = any> extends IterableElementBase<E, R> {
385
391
 
386
392
 
387
393
 
394
+
395
+
396
+
388
397
 
389
398
 
390
399
 
@@ -482,6 +491,9 @@ export class Heap<E = any, R = any> extends IterableElementBase<E, R> {
482
491
 
483
492
  /**
484
493
  * @deprecated Use `pop` instead. Will be removed in a future major version.
494
+
495
+
496
+
485
497
  * @example
486
498
  * // Heap with custom comparator (MaxHeap behavior)
487
499
  * interface Task {
@@ -567,6 +579,9 @@ export class Heap<E = any, R = any> extends IterableElementBase<E, R> {
567
579
 
568
580
 
569
581
 
582
+
583
+
584
+
570
585
 
571
586
 
572
587
 
@@ -673,6 +688,9 @@ export class Heap<E = any, R = any> extends IterableElementBase<E, R> {
673
688
 
674
689
 
675
690
 
691
+
692
+
693
+
676
694
 
677
695
 
678
696
 
@@ -726,6 +744,9 @@ export class Heap<E = any, R = any> extends IterableElementBase<E, R> {
726
744
 
727
745
 
728
746
 
747
+
748
+
749
+
729
750
 
730
751
 
731
752
 
@@ -774,6 +795,9 @@ export class Heap<E = any, R = any> extends IterableElementBase<E, R> {
774
795
 
775
796
 
776
797
 
798
+
799
+
800
+
777
801
 
778
802
 
779
803
 
@@ -827,6 +851,9 @@ export class Heap<E = any, R = any> extends IterableElementBase<E, R> {
827
851
 
828
852
 
829
853
 
854
+
855
+
856
+
830
857
 
831
858
 
832
859
 
@@ -936,6 +963,9 @@ export class Heap<E = any, R = any> extends IterableElementBase<E, R> {
936
963
 
937
964
 
938
965
 
966
+
967
+
968
+
939
969
 
940
970
 
941
971
 
@@ -1025,6 +1055,9 @@ export class Heap<E = any, R = any> extends IterableElementBase<E, R> {
1025
1055
 
1026
1056
 
1027
1057
 
1058
+
1059
+
1060
+
1028
1061
 
1029
1062
 
1030
1063
 
@@ -1084,6 +1117,9 @@ export class Heap<E = any, R = any> extends IterableElementBase<E, R> {
1084
1117
 
1085
1118
 
1086
1119
 
1120
+
1121
+
1122
+
1087
1123
 
1088
1124
 
1089
1125
 
@@ -1142,6 +1178,9 @@ export class Heap<E = any, R = any> extends IterableElementBase<E, R> {
1142
1178
 
1143
1179
 
1144
1180
 
1181
+
1182
+
1183
+
1145
1184
 
1146
1185
 
1147
1186
 
@@ -1207,6 +1246,9 @@ export class Heap<E = any, R = any> extends IterableElementBase<E, R> {
1207
1246
 
1208
1247
 
1209
1248
 
1249
+
1250
+
1251
+
1210
1252
 
1211
1253
 
1212
1254
 
@@ -303,6 +303,9 @@ export class DoublyLinkedList<E = any, R = any> extends LinearLinkedBase<E, R, D
303
303
 
304
304
 
305
305
 
306
+
307
+
308
+
306
309
 
307
310
 
308
311
 
@@ -378,6 +381,9 @@ export class DoublyLinkedList<E = any, R = any> extends LinearLinkedBase<E, R, D
378
381
 
379
382
 
380
383
 
384
+
385
+
386
+
381
387
 
382
388
 
383
389
 
@@ -452,6 +458,9 @@ export class DoublyLinkedList<E = any, R = any> extends LinearLinkedBase<E, R, D
452
458
 
453
459
 
454
460
 
461
+
462
+
463
+
455
464
 
456
465
 
457
466
 
@@ -517,6 +526,9 @@ export class DoublyLinkedList<E = any, R = any> extends LinearLinkedBase<E, R, D
517
526
 
518
527
 
519
528
 
529
+
530
+
531
+
520
532
 
521
533
 
522
534
 
@@ -615,6 +627,9 @@ export class DoublyLinkedList<E = any, R = any> extends LinearLinkedBase<E, R, D
615
627
 
616
628
 
617
629
 
630
+
631
+
632
+
618
633
 
619
634
 
620
635
 
@@ -670,6 +685,9 @@ export class DoublyLinkedList<E = any, R = any> extends LinearLinkedBase<E, R, D
670
685
 
671
686
 
672
687
 
688
+
689
+
690
+
673
691
 
674
692
 
675
693
 
@@ -764,6 +782,9 @@ export class DoublyLinkedList<E = any, R = any> extends LinearLinkedBase<E, R, D
764
782
 
765
783
 
766
784
 
785
+
786
+
787
+
767
788
 
768
789
 
769
790
 
@@ -894,6 +915,9 @@ export class DoublyLinkedList<E = any, R = any> extends LinearLinkedBase<E, R, D
894
915
 
895
916
 
896
917
 
918
+
919
+
920
+
897
921
 
898
922
 
899
923
 
@@ -956,6 +980,9 @@ export class DoublyLinkedList<E = any, R = any> extends LinearLinkedBase<E, R, D
956
980
 
957
981
 
958
982
 
983
+
984
+
985
+
959
986
 
960
987
 
961
988
 
@@ -1020,6 +1047,9 @@ export class DoublyLinkedList<E = any, R = any> extends LinearLinkedBase<E, R, D
1020
1047
 
1021
1048
 
1022
1049
 
1050
+
1051
+
1052
+
1023
1053
 
1024
1054
 
1025
1055
 
@@ -1070,6 +1100,9 @@ export class DoublyLinkedList<E = any, R = any> extends LinearLinkedBase<E, R, D
1070
1100
 
1071
1101
 
1072
1102
 
1103
+
1104
+
1105
+
1073
1106
 
1074
1107
 
1075
1108
 
@@ -1124,6 +1157,9 @@ export class DoublyLinkedList<E = any, R = any> extends LinearLinkedBase<E, R, D
1124
1157
 
1125
1158
 
1126
1159
 
1160
+
1161
+
1162
+
1127
1163
 
1128
1164
 
1129
1165
 
@@ -1191,13 +1227,36 @@ export class DoublyLinkedList<E = any, R = any> extends LinearLinkedBase<E, R, D
1191
1227
  * @example
1192
1228
  * // Find value scanning from tail
1193
1229
  * const list = new DoublyLinkedList<number>([1, 2, 3, 4]);
1194
- * // getBackward scans from tail to head, returns first match
1195
- * const found = list.getBackward(node => node.value < 4);
1230
+ * // findLast scans from tail to head, returns first match
1231
+ * const found = list.findLast(node => node.value < 4);
1196
1232
  * console.log(found); // 3;
1197
1233
  */
1198
1234
 
1235
+ /**
1236
+ * @deprecated Use `findLast` instead. Will be removed in a future major version.
1237
+ */
1199
1238
  getBackward(
1200
1239
  elementNodeOrPredicate: E | DoublyLinkedListNode<E> | ((node: DoublyLinkedListNode<E>) => boolean)
1240
+ ): E | undefined {
1241
+ return this.findLast(elementNodeOrPredicate);
1242
+ }
1243
+
1244
+ /**
1245
+ * Find the first value matching a predicate scanning backward (tail → head).
1246
+ * @remarks Time O(N), Space O(1)
1247
+ * @param elementNodeOrPredicate - Element, node, or predicate to match.
1248
+ * @returns Matching value or undefined.
1249
+
1250
+
1251
+ * @example
1252
+ * // Find value scanning from tail
1253
+ * const list = new DoublyLinkedList<number>([1, 2, 3, 4]);
1254
+ * // findLast scans from tail to head, returns first match
1255
+ * const found = list.findLast(node => node.value < 4);
1256
+ * console.log(found); // 3;
1257
+ */
1258
+ findLast(
1259
+ elementNodeOrPredicate: E | DoublyLinkedListNode<E> | ((node: DoublyLinkedListNode<E>) => boolean)
1201
1260
  ): E | undefined {
1202
1261
  const predicate = this._ensurePredicate(elementNodeOrPredicate);
1203
1262
  let current = this.tail;
@@ -1208,6 +1267,23 @@ export class DoublyLinkedList<E = any, R = any> extends LinearLinkedBase<E, R, D
1208
1267
  return undefined;
1209
1268
  }
1210
1269
 
1270
+ /**
1271
+ * Find the index of the last value matching a predicate (scans tail → head).
1272
+ * @remarks Provided for familiarity when migrating from Array. Time O(n), Space O(1).
1273
+ * @param predicate - Function called with (value, index, list).
1274
+ * @returns Matching index, or -1 if not found.
1275
+ */
1276
+ findLastIndex(predicate: (value: E, index: number, list: this) => boolean): number {
1277
+ let current = this.tail;
1278
+ let index = this.length - 1;
1279
+ while (current) {
1280
+ if (predicate(current.value, index, this)) return index;
1281
+ current = current.prev;
1282
+ index--;
1283
+ }
1284
+ return -1;
1285
+ }
1286
+
1211
1287
  /**
1212
1288
  * Reverse the list in place.
1213
1289
  * @remarks Time O(N), Space O(1)
@@ -1247,6 +1323,9 @@ export class DoublyLinkedList<E = any, R = any> extends LinearLinkedBase<E, R, D
1247
1323
 
1248
1324
 
1249
1325
 
1326
+
1327
+
1328
+
1250
1329
 
1251
1330
 
1252
1331
 
@@ -1338,6 +1417,9 @@ export class DoublyLinkedList<E = any, R = any> extends LinearLinkedBase<E, R, D
1338
1417
 
1339
1418
 
1340
1419
 
1420
+
1421
+
1422
+
1341
1423
 
1342
1424
 
1343
1425
 
@@ -1397,6 +1479,9 @@ export class DoublyLinkedList<E = any, R = any> extends LinearLinkedBase<E, R, D
1397
1479
 
1398
1480
 
1399
1481
 
1482
+
1483
+
1484
+
1400
1485
 
1401
1486
 
1402
1487
 
@@ -1477,6 +1562,9 @@ export class DoublyLinkedList<E = any, R = any> extends LinearLinkedBase<E, R, D
1477
1562
 
1478
1563
 
1479
1564
 
1565
+
1566
+
1567
+
1480
1568
 
1481
1569
 
1482
1570