binary-tree-typed 2.5.2 → 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 (63) hide show
  1. package/dist/cjs/index.cjs +320 -55
  2. package/dist/cjs/index.cjs.map +1 -1
  3. package/dist/cjs-legacy/index.cjs +320 -55
  4. package/dist/cjs-legacy/index.cjs.map +1 -1
  5. package/dist/esm/index.mjs +320 -55
  6. package/dist/esm/index.mjs.map +1 -1
  7. package/dist/esm-legacy/index.mjs +320 -55
  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 +86 -2
  12. package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +98 -0
  13. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +191 -15
  14. package/dist/types/data-structures/binary-tree/bst.d.ts +171 -3
  15. package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +136 -8
  16. package/dist/types/data-structures/binary-tree/segment-tree.d.ts +42 -0
  17. package/dist/types/data-structures/binary-tree/tree-map.d.ts +1061 -167
  18. package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +1232 -355
  19. package/dist/types/data-structures/binary-tree/tree-multi-set.d.ts +916 -194
  20. package/dist/types/data-structures/binary-tree/tree-set.d.ts +1078 -141
  21. package/dist/types/data-structures/graph/directed-graph.d.ts +70 -0
  22. package/dist/types/data-structures/graph/undirected-graph.d.ts +63 -0
  23. package/dist/types/data-structures/hash/hash-map.d.ts +84 -6
  24. package/dist/types/data-structures/heap/heap.d.ts +140 -12
  25. package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +150 -2
  26. package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +106 -1
  27. package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +126 -0
  28. package/dist/types/data-structures/matrix/matrix.d.ts +56 -0
  29. package/dist/types/data-structures/queue/deque.d.ts +171 -0
  30. package/dist/types/data-structures/queue/queue.d.ts +97 -0
  31. package/dist/types/data-structures/stack/stack.d.ts +72 -2
  32. package/dist/types/data-structures/trie/trie.d.ts +84 -0
  33. package/dist/types/interfaces/binary-tree.d.ts +2 -3
  34. package/dist/umd/binary-tree-typed.js +320 -55
  35. package/dist/umd/binary-tree-typed.js.map +1 -1
  36. package/dist/umd/binary-tree-typed.min.js +5 -5
  37. package/dist/umd/binary-tree-typed.min.js.map +1 -1
  38. package/package.json +2 -2
  39. package/src/data-structures/base/iterable-element-base.ts +32 -0
  40. package/src/data-structures/base/linear-base.ts +11 -0
  41. package/src/data-structures/binary-tree/avl-tree.ts +88 -5
  42. package/src/data-structures/binary-tree/binary-indexed-tree.ts +98 -0
  43. package/src/data-structures/binary-tree/binary-tree.ts +242 -81
  44. package/src/data-structures/binary-tree/bst.ts +173 -7
  45. package/src/data-structures/binary-tree/red-black-tree.ts +139 -15
  46. package/src/data-structures/binary-tree/segment-tree.ts +42 -0
  47. package/src/data-structures/binary-tree/tree-map.ts +948 -36
  48. package/src/data-structures/binary-tree/tree-multi-map.ts +893 -13
  49. package/src/data-structures/binary-tree/tree-multi-set.ts +761 -33
  50. package/src/data-structures/binary-tree/tree-set.ts +1260 -251
  51. package/src/data-structures/graph/directed-graph.ts +71 -1
  52. package/src/data-structures/graph/undirected-graph.ts +64 -1
  53. package/src/data-structures/hash/hash-map.ts +100 -12
  54. package/src/data-structures/heap/heap.ts +149 -19
  55. package/src/data-structures/linked-list/doubly-linked-list.ts +178 -2
  56. package/src/data-structures/linked-list/singly-linked-list.ts +106 -1
  57. package/src/data-structures/linked-list/skip-linked-list.ts +126 -0
  58. package/src/data-structures/matrix/matrix.ts +56 -0
  59. package/src/data-structures/queue/deque.ts +187 -0
  60. package/src/data-structures/queue/queue.ts +109 -0
  61. package/src/data-structures/stack/stack.ts +75 -5
  62. package/src/data-structures/trie/trie.ts +84 -0
  63. package/src/interfaces/binary-tree.ts +1 -9
@@ -212,6 +212,13 @@ export declare class DoublyLinkedList<E = any, R = any> extends LinearLinkedBase
212
212
 
213
213
 
214
214
 
215
+
216
+
217
+
218
+
219
+
220
+
221
+
215
222
 
216
223
 
217
224
 
@@ -268,6 +275,13 @@ export declare class DoublyLinkedList<E = any, R = any> extends LinearLinkedBase
268
275
 
269
276
 
270
277
 
278
+
279
+
280
+
281
+
282
+
283
+
284
+
271
285
 
272
286
 
273
287
 
@@ -324,6 +338,13 @@ export declare class DoublyLinkedList<E = any, R = any> extends LinearLinkedBase
324
338
 
325
339
 
326
340
 
341
+
342
+
343
+
344
+
345
+
346
+
347
+
327
348
 
328
349
 
329
350
 
@@ -371,6 +392,13 @@ export declare class DoublyLinkedList<E = any, R = any> extends LinearLinkedBase
371
392
 
372
393
 
373
394
 
395
+
396
+
397
+
398
+
399
+
400
+
401
+
374
402
 
375
403
 
376
404
 
@@ -432,6 +460,13 @@ export declare class DoublyLinkedList<E = any, R = any> extends LinearLinkedBase
432
460
 
433
461
 
434
462
 
463
+
464
+
465
+
466
+
467
+
468
+
469
+
435
470
 
436
471
 
437
472
 
@@ -476,6 +511,13 @@ export declare class DoublyLinkedList<E = any, R = any> extends LinearLinkedBase
476
511
 
477
512
 
478
513
 
514
+
515
+
516
+
517
+
518
+
519
+
520
+
479
521
 
480
522
 
481
523
 
@@ -527,6 +569,13 @@ export declare class DoublyLinkedList<E = any, R = any> extends LinearLinkedBase
527
569
 
528
570
 
529
571
 
572
+
573
+
574
+
575
+
576
+
577
+
578
+
530
579
 
531
580
 
532
581
 
@@ -595,6 +644,13 @@ export declare class DoublyLinkedList<E = any, R = any> extends LinearLinkedBase
595
644
 
596
645
 
597
646
 
647
+
648
+
649
+
650
+
651
+
652
+
653
+
598
654
 
599
655
 
600
656
 
@@ -639,6 +695,13 @@ export declare class DoublyLinkedList<E = any, R = any> extends LinearLinkedBase
639
695
 
640
696
 
641
697
 
698
+
699
+
700
+
701
+
702
+
703
+
704
+
642
705
 
643
706
 
644
707
 
@@ -683,6 +746,13 @@ export declare class DoublyLinkedList<E = any, R = any> extends LinearLinkedBase
683
746
 
684
747
 
685
748
 
749
+
750
+
751
+
752
+
753
+
754
+
755
+
686
756
 
687
757
 
688
758
 
@@ -725,6 +795,13 @@ export declare class DoublyLinkedList<E = any, R = any> extends LinearLinkedBase
725
795
 
726
796
 
727
797
 
798
+
799
+
800
+
801
+
802
+
803
+
804
+
728
805
 
729
806
 
730
807
 
@@ -769,6 +846,13 @@ export declare class DoublyLinkedList<E = any, R = any> extends LinearLinkedBase
769
846
 
770
847
 
771
848
 
849
+
850
+
851
+
852
+
853
+
854
+
855
+
772
856
 
773
857
 
774
858
 
@@ -816,6 +900,10 @@ export declare class DoublyLinkedList<E = any, R = any> extends LinearLinkedBase
816
900
 
817
901
 
818
902
 
903
+
904
+
905
+
906
+
819
907
 
820
908
 
821
909
 
@@ -824,11 +912,36 @@ export declare class DoublyLinkedList<E = any, R = any> extends LinearLinkedBase
824
912
  * @example
825
913
  * // Find value scanning from tail
826
914
  * const list = new DoublyLinkedList<number>([1, 2, 3, 4]);
827
- * // getBackward scans from tail to head, returns first match
828
- * const found = list.getBackward(node => node.value < 4);
915
+ * // findLast scans from tail to head, returns first match
916
+ * const found = list.findLast(node => node.value < 4);
829
917
  * console.log(found); // 3;
830
918
  */
919
+ /**
920
+ * @deprecated Use `findLast` instead. Will be removed in a future major version.
921
+ */
831
922
  getBackward(elementNodeOrPredicate: E | DoublyLinkedListNode<E> | ((node: DoublyLinkedListNode<E>) => boolean)): E | undefined;
923
+ /**
924
+ * Find the first value matching a predicate scanning backward (tail → head).
925
+ * @remarks Time O(N), Space O(1)
926
+ * @param elementNodeOrPredicate - Element, node, or predicate to match.
927
+ * @returns Matching value or undefined.
928
+
929
+
930
+ * @example
931
+ * // Find value scanning from tail
932
+ * const list = new DoublyLinkedList<number>([1, 2, 3, 4]);
933
+ * // findLast scans from tail to head, returns first match
934
+ * const found = list.findLast(node => node.value < 4);
935
+ * console.log(found); // 3;
936
+ */
937
+ findLast(elementNodeOrPredicate: E | DoublyLinkedListNode<E> | ((node: DoublyLinkedListNode<E>) => boolean)): E | undefined;
938
+ /**
939
+ * Find the index of the last value matching a predicate (scans tail → head).
940
+ * @remarks Provided for familiarity when migrating from Array. Time O(n), Space O(1).
941
+ * @param predicate - Function called with (value, index, list).
942
+ * @returns Matching index, or -1 if not found.
943
+ */
944
+ findLastIndex(predicate: (value: E, index: number, list: this) => boolean): number;
832
945
  /**
833
946
  * Reverse the list in place.
834
947
  * @remarks Time O(N), Space O(1)
@@ -860,6 +973,13 @@ export declare class DoublyLinkedList<E = any, R = any> extends LinearLinkedBase
860
973
 
861
974
 
862
975
 
976
+
977
+
978
+
979
+
980
+
981
+
982
+
863
983
 
864
984
 
865
985
 
@@ -875,6 +995,13 @@ export declare class DoublyLinkedList<E = any, R = any> extends LinearLinkedBase
875
995
  * console.log([...list]); // [3, 2, 1];
876
996
  */
877
997
  reverse(): this;
998
+ /**
999
+ * Delete the first element that satisfies a predicate.
1000
+ * @remarks Time O(N), Space O(1)
1001
+ * @param predicate - Function (value, index, list) → boolean to decide deletion.
1002
+ * @returns True if a match was removed.
1003
+ */
1004
+ deleteWhere(predicate: (value: E, index: number, list: this) => boolean): boolean;
878
1005
  /**
879
1006
  * Set the equality comparator used to compare values.
880
1007
  * @remarks Time O(1), Space O(1)
@@ -911,6 +1038,13 @@ export declare class DoublyLinkedList<E = any, R = any> extends LinearLinkedBase
911
1038
 
912
1039
 
913
1040
 
1041
+
1042
+
1043
+
1044
+
1045
+
1046
+
1047
+
914
1048
 
915
1049
 
916
1050
 
@@ -960,6 +1094,13 @@ export declare class DoublyLinkedList<E = any, R = any> extends LinearLinkedBase
960
1094
 
961
1095
 
962
1096
 
1097
+
1098
+
1099
+
1100
+
1101
+
1102
+
1103
+
963
1104
 
964
1105
 
965
1106
 
@@ -1019,6 +1160,13 @@ export declare class DoublyLinkedList<E = any, R = any> extends LinearLinkedBase
1019
1160
 
1020
1161
 
1021
1162
 
1163
+
1164
+
1165
+
1166
+
1167
+
1168
+
1169
+
1022
1170
 
1023
1171
 
1024
1172
 
@@ -40,7 +40,7 @@ export declare class SinglyLinkedListNode<E = any> extends LinkedListNode<E> {
40
40
  * @remarks Time O(1), Space O(1)
41
41
  * @template E
42
42
  * @template R
43
- * 1. Node Structure: Each node contains three parts: a data field, a pointer (or reference) to the previous node, and a pointer to the next node. This structure allows traversal of the linked list in both directions.
43
+ * 1. Node Structure: Each node contains two parts: a data field and a pointer (or reference) to the next node. This structure allows forward-only traversal of the linked list.
44
44
  * 2. Bidirectional Traversal: Unlike doubly linked lists, singly linked lists can be easily traversed forwards but not backwards.
45
45
  * 3. No Centralized Index: Unlike arrays, elements in a linked list are not stored contiguously, so there is no centralized index. Accessing elements in a linked list typically requires traversing from the head or tail node.
46
46
  * 4. High Efficiency in Insertion and Deletion: Adding or removing elements in a linked list does not require moving other elements, making these operations more efficient than in arrays.
@@ -261,6 +261,13 @@ export declare class SinglyLinkedList<E = any, R = any> extends LinearLinkedBase
261
261
 
262
262
 
263
263
 
264
+
265
+
266
+
267
+
268
+
269
+
270
+
264
271
 
265
272
 
266
273
 
@@ -317,6 +324,13 @@ export declare class SinglyLinkedList<E = any, R = any> extends LinearLinkedBase
317
324
 
318
325
 
319
326
 
327
+
328
+
329
+
330
+
331
+
332
+
333
+
320
334
 
321
335
 
322
336
 
@@ -373,6 +387,13 @@ export declare class SinglyLinkedList<E = any, R = any> extends LinearLinkedBase
373
387
 
374
388
 
375
389
 
390
+
391
+
392
+
393
+
394
+
395
+
396
+
376
397
 
377
398
 
378
399
 
@@ -420,6 +441,13 @@ export declare class SinglyLinkedList<E = any, R = any> extends LinearLinkedBase
420
441
 
421
442
 
422
443
 
444
+
445
+
446
+
447
+
448
+
449
+
450
+
423
451
 
424
452
 
425
453
 
@@ -503,6 +531,13 @@ export declare class SinglyLinkedList<E = any, R = any> extends LinearLinkedBase
503
531
 
504
532
 
505
533
 
534
+
535
+
536
+
537
+
538
+
539
+
540
+
506
541
 
507
542
 
508
543
 
@@ -555,6 +590,13 @@ export declare class SinglyLinkedList<E = any, R = any> extends LinearLinkedBase
555
590
 
556
591
 
557
592
 
593
+
594
+
595
+
596
+
597
+
598
+
599
+
558
600
 
559
601
 
560
602
 
@@ -598,6 +640,13 @@ export declare class SinglyLinkedList<E = any, R = any> extends LinearLinkedBase
598
640
 
599
641
 
600
642
 
643
+
644
+
645
+
646
+
647
+
648
+
649
+
601
650
 
602
651
 
603
652
 
@@ -642,6 +691,13 @@ export declare class SinglyLinkedList<E = any, R = any> extends LinearLinkedBase
642
691
 
643
692
 
644
693
 
694
+
695
+
696
+
697
+
698
+
699
+
700
+
645
701
 
646
702
 
647
703
 
@@ -687,6 +743,13 @@ export declare class SinglyLinkedList<E = any, R = any> extends LinearLinkedBase
687
743
 
688
744
 
689
745
 
746
+
747
+
748
+
749
+
750
+
751
+
752
+
690
753
 
691
754
 
692
755
 
@@ -739,6 +802,13 @@ export declare class SinglyLinkedList<E = any, R = any> extends LinearLinkedBase
739
802
 
740
803
 
741
804
 
805
+
806
+
807
+
808
+
809
+
810
+
811
+
742
812
 
743
813
 
744
814
 
@@ -781,6 +851,13 @@ export declare class SinglyLinkedList<E = any, R = any> extends LinearLinkedBase
781
851
 
782
852
 
783
853
 
854
+
855
+
856
+
857
+
858
+
859
+
860
+
784
861
 
785
862
 
786
863
 
@@ -827,6 +904,13 @@ export declare class SinglyLinkedList<E = any, R = any> extends LinearLinkedBase
827
904
 
828
905
 
829
906
 
907
+
908
+
909
+
910
+
911
+
912
+
913
+
830
914
 
831
915
 
832
916
 
@@ -924,6 +1008,13 @@ export declare class SinglyLinkedList<E = any, R = any> extends LinearLinkedBase
924
1008
 
925
1009
 
926
1010
 
1011
+
1012
+
1013
+
1014
+
1015
+
1016
+
1017
+
927
1018
 
928
1019
 
929
1020
 
@@ -974,6 +1065,13 @@ export declare class SinglyLinkedList<E = any, R = any> extends LinearLinkedBase
974
1065
 
975
1066
 
976
1067
 
1068
+
1069
+
1070
+
1071
+
1072
+
1073
+
1074
+
977
1075
 
978
1076
 
979
1077
 
@@ -1043,6 +1141,13 @@ export declare class SinglyLinkedList<E = any, R = any> extends LinearLinkedBase
1043
1141
 
1044
1142
 
1045
1143
 
1144
+
1145
+
1146
+
1147
+
1148
+
1149
+
1150
+
1046
1151
 
1047
1152
 
1048
1153
 
@@ -76,6 +76,13 @@ export declare class SkipList<K = any, V = any, R = [K, V]> extends IterableEntr
76
76
 
77
77
 
78
78
 
79
+
80
+
81
+
82
+
83
+
84
+
85
+
79
86
 
80
87
 
81
88
 
@@ -116,6 +123,13 @@ export declare class SkipList<K = any, V = any, R = [K, V]> extends IterableEntr
116
123
 
117
124
 
118
125
 
126
+
127
+
128
+
129
+
130
+
131
+
132
+
119
133
 
120
134
 
121
135
 
@@ -157,6 +171,13 @@ export declare class SkipList<K = any, V = any, R = [K, V]> extends IterableEntr
157
171
 
158
172
 
159
173
 
174
+
175
+
176
+
177
+
178
+
179
+
180
+
160
181
 
161
182
 
162
183
 
@@ -203,6 +224,13 @@ export declare class SkipList<K = any, V = any, R = [K, V]> extends IterableEntr
203
224
 
204
225
 
205
226
 
227
+
228
+
229
+
230
+
231
+
232
+
233
+
206
234
 
207
235
 
208
236
 
@@ -259,6 +287,13 @@ export declare class SkipList<K = any, V = any, R = [K, V]> extends IterableEntr
259
287
 
260
288
 
261
289
 
290
+
291
+
292
+
293
+
294
+
295
+
296
+
262
297
 
263
298
 
264
299
 
@@ -319,6 +354,13 @@ export declare class SkipList<K = any, V = any, R = [K, V]> extends IterableEntr
319
354
 
320
355
 
321
356
 
357
+
358
+
359
+
360
+
361
+
362
+
363
+
322
364
 
323
365
 
324
366
 
@@ -363,6 +405,13 @@ export declare class SkipList<K = any, V = any, R = [K, V]> extends IterableEntr
363
405
 
364
406
 
365
407
 
408
+
409
+
410
+
411
+
412
+
413
+
414
+
366
415
 
367
416
 
368
417
 
@@ -414,6 +463,13 @@ export declare class SkipList<K = any, V = any, R = [K, V]> extends IterableEntr
414
463
 
415
464
 
416
465
 
466
+
467
+
468
+
469
+
470
+
471
+
472
+
417
473
 
418
474
 
419
475
 
@@ -457,6 +513,13 @@ export declare class SkipList<K = any, V = any, R = [K, V]> extends IterableEntr
457
513
 
458
514
 
459
515
 
516
+
517
+
518
+
519
+
520
+
521
+
522
+
460
523
 
461
524
 
462
525
 
@@ -497,6 +560,13 @@ export declare class SkipList<K = any, V = any, R = [K, V]> extends IterableEntr
497
560
 
498
561
 
499
562
 
563
+
564
+
565
+
566
+
567
+
568
+
569
+
500
570
 
501
571
 
502
572
 
@@ -538,6 +608,13 @@ export declare class SkipList<K = any, V = any, R = [K, V]> extends IterableEntr
538
608
 
539
609
 
540
610
 
611
+
612
+
613
+
614
+
615
+
616
+
617
+
541
618
 
542
619
 
543
620
 
@@ -582,6 +659,13 @@ export declare class SkipList<K = any, V = any, R = [K, V]> extends IterableEntr
582
659
 
583
660
 
584
661
 
662
+
663
+
664
+
665
+
666
+
667
+
668
+
585
669
 
586
670
 
587
671
 
@@ -626,6 +710,13 @@ export declare class SkipList<K = any, V = any, R = [K, V]> extends IterableEntr
626
710
 
627
711
 
628
712
 
713
+
714
+
715
+
716
+
717
+
718
+
719
+
629
720
 
630
721
 
631
722
 
@@ -667,6 +758,13 @@ export declare class SkipList<K = any, V = any, R = [K, V]> extends IterableEntr
667
758
 
668
759
 
669
760
 
761
+
762
+
763
+
764
+
765
+
766
+
767
+
670
768
 
671
769
 
672
770
 
@@ -708,6 +806,13 @@ export declare class SkipList<K = any, V = any, R = [K, V]> extends IterableEntr
708
806
 
709
807
 
710
808
 
809
+
810
+
811
+
812
+
813
+
814
+
815
+
711
816
 
712
817
 
713
818
 
@@ -752,6 +857,13 @@ export declare class SkipList<K = any, V = any, R = [K, V]> extends IterableEntr
752
857
 
753
858
 
754
859
 
860
+
861
+
862
+
863
+
864
+
865
+
866
+
755
867
 
756
868
 
757
869
 
@@ -793,6 +905,13 @@ export declare class SkipList<K = any, V = any, R = [K, V]> extends IterableEntr
793
905
 
794
906
 
795
907
 
908
+
909
+
910
+
911
+
912
+
913
+
914
+
796
915
 
797
916
 
798
917
 
@@ -834,6 +953,13 @@ export declare class SkipList<K = any, V = any, R = [K, V]> extends IterableEntr
834
953
 
835
954
 
836
955
 
956
+
957
+
958
+
959
+
960
+
961
+
962
+
837
963
 
838
964
 
839
965