binary-tree-typed 2.5.0 → 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 (90) hide show
  1. package/dist/cjs/index.cjs +771 -68
  2. package/dist/cjs/index.cjs.map +1 -1
  3. package/dist/cjs-legacy/index.cjs +771 -68
  4. package/dist/cjs-legacy/index.cjs.map +1 -1
  5. package/dist/esm/index.mjs +771 -69
  6. package/dist/esm/index.mjs.map +1 -1
  7. package/dist/esm-legacy/index.mjs +771 -69
  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/base/index.d.ts +1 -0
  12. package/dist/types/data-structures/base/iterable-entry-base.d.ts +8 -8
  13. package/dist/types/data-structures/base/linear-base.d.ts +3 -3
  14. package/dist/types/data-structures/binary-tree/avl-tree.d.ts +288 -0
  15. package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +336 -0
  16. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +618 -18
  17. package/dist/types/data-structures/binary-tree/bst.d.ts +676 -1
  18. package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +456 -0
  19. package/dist/types/data-structures/binary-tree/segment-tree.d.ts +144 -1
  20. package/dist/types/data-structures/binary-tree/tree-map.d.ts +3307 -399
  21. package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +3285 -360
  22. package/dist/types/data-structures/binary-tree/tree-multi-set.d.ts +2674 -325
  23. package/dist/types/data-structures/binary-tree/tree-set.d.ts +3072 -287
  24. package/dist/types/data-structures/graph/abstract-graph.d.ts +4 -4
  25. package/dist/types/data-structures/graph/directed-graph.d.ts +240 -0
  26. package/dist/types/data-structures/graph/undirected-graph.d.ts +216 -0
  27. package/dist/types/data-structures/hash/hash-map.d.ts +274 -10
  28. package/dist/types/data-structures/heap/heap.d.ts +336 -0
  29. package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +411 -3
  30. package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +363 -3
  31. package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +434 -2
  32. package/dist/types/data-structures/matrix/matrix.d.ts +192 -0
  33. package/dist/types/data-structures/queue/deque.d.ts +364 -4
  34. package/dist/types/data-structures/queue/queue.d.ts +288 -0
  35. package/dist/types/data-structures/stack/stack.d.ts +240 -0
  36. package/dist/types/data-structures/trie/trie.d.ts +292 -4
  37. package/dist/types/interfaces/graph.d.ts +1 -1
  38. package/dist/types/types/common.d.ts +2 -2
  39. package/dist/types/types/data-structures/binary-tree/bst.d.ts +1 -0
  40. package/dist/types/types/data-structures/binary-tree/tree-map.d.ts +5 -0
  41. package/dist/types/types/data-structures/binary-tree/tree-multi-set.d.ts +4 -0
  42. package/dist/types/types/data-structures/binary-tree/tree-set.d.ts +4 -0
  43. package/dist/types/types/data-structures/heap/heap.d.ts +1 -0
  44. package/dist/types/types/data-structures/priority-queue/priority-queue.d.ts +1 -0
  45. package/dist/types/types/utils/validate-type.d.ts +4 -4
  46. package/dist/umd/binary-tree-typed.js +773 -71
  47. package/dist/umd/binary-tree-typed.js.map +1 -1
  48. package/dist/umd/binary-tree-typed.min.js +5 -5
  49. package/dist/umd/binary-tree-typed.min.js.map +1 -1
  50. package/package.json +2 -2
  51. package/src/common/error.ts +19 -1
  52. package/src/common/index.ts +1 -1
  53. package/src/data-structures/base/index.ts +1 -0
  54. package/src/data-structures/base/iterable-element-base.ts +3 -2
  55. package/src/data-structures/base/iterable-entry-base.ts +8 -8
  56. package/src/data-structures/base/linear-base.ts +3 -3
  57. package/src/data-structures/binary-tree/avl-tree.ts +299 -0
  58. package/src/data-structures/binary-tree/binary-indexed-tree.ts +341 -5
  59. package/src/data-structures/binary-tree/binary-tree.ts +606 -6
  60. package/src/data-structures/binary-tree/bst.ts +946 -7
  61. package/src/data-structures/binary-tree/red-black-tree.ts +472 -0
  62. package/src/data-structures/binary-tree/segment-tree.ts +145 -2
  63. package/src/data-structures/binary-tree/tree-map.ts +3423 -499
  64. package/src/data-structures/binary-tree/tree-multi-map.ts +3537 -596
  65. package/src/data-structures/binary-tree/tree-multi-set.ts +2855 -495
  66. package/src/data-structures/binary-tree/tree-set.ts +3209 -413
  67. package/src/data-structures/graph/abstract-graph.ts +6 -6
  68. package/src/data-structures/graph/directed-graph.ts +240 -0
  69. package/src/data-structures/graph/undirected-graph.ts +216 -0
  70. package/src/data-structures/hash/hash-map.ts +281 -19
  71. package/src/data-structures/heap/heap.ts +340 -4
  72. package/src/data-structures/heap/max-heap.ts +2 -2
  73. package/src/data-structures/linked-list/doubly-linked-list.ts +411 -3
  74. package/src/data-structures/linked-list/singly-linked-list.ts +363 -3
  75. package/src/data-structures/linked-list/skip-linked-list.ts +439 -7
  76. package/src/data-structures/matrix/matrix.ts +202 -10
  77. package/src/data-structures/priority-queue/max-priority-queue.ts +2 -2
  78. package/src/data-structures/queue/deque.ts +365 -5
  79. package/src/data-structures/queue/queue.ts +288 -0
  80. package/src/data-structures/stack/stack.ts +240 -0
  81. package/src/data-structures/trie/trie.ts +295 -7
  82. package/src/interfaces/graph.ts +1 -1
  83. package/src/types/common.ts +2 -2
  84. package/src/types/data-structures/binary-tree/bst.ts +1 -0
  85. package/src/types/data-structures/binary-tree/tree-map.ts +6 -0
  86. package/src/types/data-structures/binary-tree/tree-multi-set.ts +5 -0
  87. package/src/types/data-structures/binary-tree/tree-set.ts +5 -0
  88. package/src/types/data-structures/heap/heap.ts +1 -0
  89. package/src/types/data-structures/priority-queue/priority-queue.ts +1 -0
  90. package/src/types/utils/validate-type.ts +4 -4
@@ -307,6 +307,30 @@ export class SinglyLinkedList<E = any, R = any> extends LinearLinkedBase<E, R, S
307
307
 
308
308
 
309
309
 
310
+
311
+
312
+
313
+
314
+
315
+
316
+
317
+
318
+
319
+
320
+
321
+
322
+
323
+
324
+
325
+
326
+
327
+
328
+
329
+
330
+
331
+
332
+
333
+
310
334
  * @example
311
335
  * // basic SinglyLinkedList creation and push operation
312
336
  * // Create a simple SinglyLinkedList with initial values
@@ -352,6 +376,30 @@ export class SinglyLinkedList<E = any, R = any> extends LinearLinkedBase<E, R, S
352
376
 
353
377
 
354
378
 
379
+
380
+
381
+
382
+
383
+
384
+
385
+
386
+
387
+
388
+
389
+
390
+
391
+
392
+
393
+
394
+
395
+
396
+
397
+
398
+
399
+
400
+
401
+
402
+
355
403
  * @example
356
404
  * // SinglyLinkedList pop and shift operations
357
405
  * const list = new SinglyLinkedList<number>([10, 20, 30, 40, 50]);
@@ -402,6 +450,30 @@ export class SinglyLinkedList<E = any, R = any> extends LinearLinkedBase<E, R, S
402
450
 
403
451
 
404
452
 
453
+
454
+
455
+
456
+
457
+
458
+
459
+
460
+
461
+
462
+
463
+
464
+
465
+
466
+
467
+
468
+
469
+
470
+
471
+
472
+
473
+
474
+
475
+
476
+
405
477
  * @example
406
478
  * // Remove from the front
407
479
  * const list = new SinglyLinkedList<number>([10, 20, 30]);
@@ -434,6 +506,30 @@ export class SinglyLinkedList<E = any, R = any> extends LinearLinkedBase<E, R, S
434
506
 
435
507
 
436
508
 
509
+
510
+
511
+
512
+
513
+
514
+
515
+
516
+
517
+
518
+
519
+
520
+
521
+
522
+
523
+
524
+
525
+
526
+
527
+
528
+
529
+
530
+
531
+
532
+
437
533
  * @example
438
534
  * // SinglyLinkedList unshift and forward traversal
439
535
  * const list = new SinglyLinkedList<number>([20, 30, 40]);
@@ -535,6 +631,30 @@ export class SinglyLinkedList<E = any, R = any> extends LinearLinkedBase<E, R, S
535
631
 
536
632
 
537
633
 
634
+
635
+
636
+
637
+
638
+
639
+
640
+
641
+
642
+
643
+
644
+
645
+
646
+
647
+
648
+
649
+
650
+
651
+
652
+
653
+
654
+
655
+
656
+
657
+
538
658
  * @example
539
659
  * // Access element by index
540
660
  * const list = new SinglyLinkedList<string>(['a', 'b', 'c', 'd']);
@@ -576,6 +696,30 @@ export class SinglyLinkedList<E = any, R = any> extends LinearLinkedBase<E, R, S
576
696
 
577
697
 
578
698
 
699
+
700
+
701
+
702
+
703
+
704
+
705
+
706
+
707
+
708
+
709
+
710
+
711
+
712
+
713
+
714
+
715
+
716
+
717
+
718
+
719
+
720
+
721
+
722
+
579
723
  * @example
580
724
  * // Get node at index
581
725
  * const list = new SinglyLinkedList<string>(['a', 'b', 'c']);
@@ -602,6 +746,30 @@ export class SinglyLinkedList<E = any, R = any> extends LinearLinkedBase<E, R, S
602
746
 
603
747
 
604
748
 
749
+
750
+
751
+
752
+
753
+
754
+
755
+
756
+
757
+
758
+
759
+
760
+
761
+
762
+
763
+
764
+
765
+
766
+
767
+
768
+
769
+
770
+
771
+
772
+
605
773
  * @example
606
774
  * // Remove by index
607
775
  * const list = new SinglyLinkedList<string>(['a', 'b', 'c']);
@@ -634,6 +802,30 @@ export class SinglyLinkedList<E = any, R = any> extends LinearLinkedBase<E, R, S
634
802
 
635
803
 
636
804
 
805
+
806
+
807
+
808
+
809
+
810
+
811
+
812
+
813
+
814
+
815
+
816
+
817
+
818
+
819
+
820
+
821
+
822
+
823
+
824
+
825
+
826
+
827
+
828
+
637
829
  * @example
638
830
  * // Remove first occurrence
639
831
  * const list = new SinglyLinkedList<number>([1, 2, 3, 2]);
@@ -672,6 +864,30 @@ export class SinglyLinkedList<E = any, R = any> extends LinearLinkedBase<E, R, S
672
864
 
673
865
 
674
866
 
867
+
868
+
869
+
870
+
871
+
872
+
873
+
874
+
875
+
876
+
877
+
878
+
879
+
880
+
881
+
882
+
883
+
884
+
885
+
886
+
887
+
888
+
889
+
890
+
675
891
  * @example
676
892
  * // Insert at index
677
893
  * const list = new SinglyLinkedList<number>([1, 3]);
@@ -719,6 +935,30 @@ export class SinglyLinkedList<E = any, R = any> extends LinearLinkedBase<E, R, S
719
935
 
720
936
 
721
937
 
938
+
939
+
940
+
941
+
942
+
943
+
944
+
945
+
946
+
947
+
948
+
949
+
950
+
951
+
952
+
953
+
954
+
955
+
956
+
957
+
958
+
959
+
960
+
961
+
722
962
  * @example
723
963
  * // Check empty
724
964
  * console.log(new SinglyLinkedList().isEmpty()); // true;
@@ -741,6 +981,30 @@ export class SinglyLinkedList<E = any, R = any> extends LinearLinkedBase<E, R, S
741
981
 
742
982
 
743
983
 
984
+
985
+
986
+
987
+
988
+
989
+
990
+
991
+
992
+
993
+
994
+
995
+
996
+
997
+
998
+
999
+
1000
+
1001
+
1002
+
1003
+
1004
+
1005
+
1006
+
1007
+
744
1008
  * @example
745
1009
  * // Remove all
746
1010
  * const list = new SinglyLinkedList<number>([1, 2, 3]);
@@ -769,6 +1033,30 @@ export class SinglyLinkedList<E = any, R = any> extends LinearLinkedBase<E, R, S
769
1033
 
770
1034
 
771
1035
 
1036
+
1037
+
1038
+
1039
+
1040
+
1041
+
1042
+
1043
+
1044
+
1045
+
1046
+
1047
+
1048
+
1049
+
1050
+
1051
+
1052
+
1053
+
1054
+
1055
+
1056
+
1057
+
1058
+
1059
+
772
1060
  * @example
773
1061
  * // Reverse the list in-place
774
1062
  * const list = new SinglyLinkedList<number>([1, 2, 3, 4]);
@@ -991,6 +1279,30 @@ export class SinglyLinkedList<E = any, R = any> extends LinearLinkedBase<E, R, S
991
1279
 
992
1280
 
993
1281
 
1282
+
1283
+
1284
+
1285
+
1286
+
1287
+
1288
+
1289
+
1290
+
1291
+
1292
+
1293
+
1294
+
1295
+
1296
+
1297
+
1298
+
1299
+
1300
+
1301
+
1302
+
1303
+
1304
+
1305
+
994
1306
  * @example
995
1307
  * // Deep copy
996
1308
  * const list = new SinglyLinkedList<number>([1, 2, 3]);
@@ -1023,6 +1335,30 @@ export class SinglyLinkedList<E = any, R = any> extends LinearLinkedBase<E, R, S
1023
1335
 
1024
1336
 
1025
1337
 
1338
+
1339
+
1340
+
1341
+
1342
+
1343
+
1344
+
1345
+
1346
+
1347
+
1348
+
1349
+
1350
+
1351
+
1352
+
1353
+
1354
+
1355
+
1356
+
1357
+
1358
+
1359
+
1360
+
1361
+
1026
1362
  * @example
1027
1363
  * // SinglyLinkedList filter and map operations
1028
1364
  * const list = new SinglyLinkedList<number>([1, 2, 3, 4, 5]);
@@ -1040,7 +1376,7 @@ export class SinglyLinkedList<E = any, R = any> extends LinearLinkedBase<E, R, S
1040
1376
  * console.log(sum); // 15;
1041
1377
  */
1042
1378
 
1043
- filter(callback: ElementCallback<E, R, boolean>, thisArg?: any): this {
1379
+ filter(callback: ElementCallback<E, R, boolean>, thisArg?: unknown): this {
1044
1380
  const out = this._createInstance();
1045
1381
  let index = 0;
1046
1382
  for (const value of this) if (callback.call(thisArg, value, index++, this)) out.push(value);
@@ -1055,7 +1391,7 @@ export class SinglyLinkedList<E = any, R = any> extends LinearLinkedBase<E, R, S
1055
1391
  * @returns A new list with mapped values.
1056
1392
  */
1057
1393
 
1058
- mapSame(callback: ElementCallback<E, R, E>, thisArg?: any): this {
1394
+ mapSame(callback: ElementCallback<E, R, E>, thisArg?: unknown): this {
1059
1395
  const out = this._createInstance();
1060
1396
  let index = 0;
1061
1397
  for (const value of this) {
@@ -1085,6 +1421,30 @@ export class SinglyLinkedList<E = any, R = any> extends LinearLinkedBase<E, R, S
1085
1421
 
1086
1422
 
1087
1423
 
1424
+
1425
+
1426
+
1427
+
1428
+
1429
+
1430
+
1431
+
1432
+
1433
+
1434
+
1435
+
1436
+
1437
+
1438
+
1439
+
1440
+
1441
+
1442
+
1443
+
1444
+
1445
+
1446
+
1447
+
1088
1448
  * @example
1089
1449
  * // Transform elements
1090
1450
  * const list = new SinglyLinkedList<number>([1, 2, 3]);
@@ -1095,7 +1455,7 @@ export class SinglyLinkedList<E = any, R = any> extends LinearLinkedBase<E, R, S
1095
1455
  map<EM, RM = any>(
1096
1456
  callback: ElementCallback<E, R, EM>,
1097
1457
  options?: SinglyLinkedListOptions<EM, RM>,
1098
- thisArg?: any
1458
+ thisArg?: unknown
1099
1459
  ): SinglyLinkedList<EM, RM> {
1100
1460
  const out = this._createLike<EM, RM>([], { ...(options ?? {}), maxLen: this._maxLen as number });
1101
1461
  let index = 0;