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
@@ -8,7 +8,7 @@
8
8
 
9
9
  import type { DijkstraResult, EntryCallback, GraphOptions, VertexKey } from '../../types';
10
10
  import { uuidV4 } from '../../utils';
11
- import { ERR } from '../../common';
11
+ import { ERR, raise } from '../../common';
12
12
  import { IterableEntryBase } from '../base';
13
13
  import { IGraph } from '../../interfaces';
14
14
  import { Heap } from '../heap';
@@ -212,7 +212,7 @@ export abstract class AbstractGraph<
212
212
  * @returns `true` if string/number; else `false`.
213
213
  * @remarks Time O(1), Space O(1)
214
214
  */
215
- isVertexKey(potentialKey: any): potentialKey is VertexKey {
215
+ isVertexKey(potentialKey: unknown): potentialKey is VertexKey {
216
216
  const potentialKeyType = typeof potentialKey;
217
217
  return potentialKeyType === 'string' || potentialKeyType === 'number';
218
218
  }
@@ -275,7 +275,7 @@ export abstract class AbstractGraph<
275
275
  const newEdge = this.createEdge(srcOrEdge, dest, weight, value);
276
276
  return this._addEdge(newEdge);
277
277
  } else {
278
- throw new TypeError(ERR.invalidArgument('dest must be a Vertex or vertex key when srcOrEdge is an Edge.', 'Graph'));
278
+ raise(TypeError, ERR.invalidArgument('dest must be a Vertex or vertex key when srcOrEdge is an Edge.', 'Graph'));
279
279
  }
280
280
  }
281
281
  }
@@ -894,7 +894,7 @@ export abstract class AbstractGraph<
894
894
  * @returns A new graph of the same concrete class (`this` type).
895
895
  * @remarks Time O(V + E), Space O(V + E)
896
896
  */
897
- filter(predicate: EntryCallback<VertexKey, V | undefined, boolean>, thisArg?: any): this {
897
+ filter(predicate: EntryCallback<VertexKey, V | undefined, boolean>, thisArg?: unknown): this {
898
898
  const filtered: [VertexKey, V | undefined][] = [];
899
899
  let index = 0;
900
900
  for (const [key, value] of this) {
@@ -912,7 +912,7 @@ export abstract class AbstractGraph<
912
912
  */
913
913
  filterEntries(
914
914
  predicate: EntryCallback<VertexKey, V | undefined, boolean>,
915
- thisArg?: any
915
+ thisArg?: unknown
916
916
  ): [VertexKey, V | undefined][] {
917
917
  const filtered: [VertexKey, V | undefined][] = [];
918
918
  let index = 0;
@@ -925,7 +925,7 @@ export abstract class AbstractGraph<
925
925
  return filtered;
926
926
  }
927
927
 
928
- map<T>(callback: EntryCallback<VertexKey, V | undefined, T>, thisArg?: any): T[] {
928
+ map<T>(callback: EntryCallback<VertexKey, V | undefined, T>, thisArg?: unknown): T[] {
929
929
  const mapped: T[] = [];
930
930
  let index = 0;
931
931
  for (const [key, value] of this) {
@@ -225,6 +225,30 @@ export class DirectedGraph<
225
225
 
226
226
 
227
227
 
228
+
229
+
230
+
231
+
232
+
233
+
234
+
235
+
236
+
237
+
238
+
239
+
240
+
241
+
242
+
243
+
244
+
245
+
246
+
247
+
248
+
249
+
250
+
251
+
228
252
  * @example
229
253
  * // Get edge between vertices
230
254
  * const g = new DirectedGraph();
@@ -296,6 +320,30 @@ export class DirectedGraph<
296
320
 
297
321
 
298
322
 
323
+
324
+
325
+
326
+
327
+
328
+
329
+
330
+
331
+
332
+
333
+
334
+
335
+
336
+
337
+
338
+
339
+
340
+
341
+
342
+
343
+
344
+
345
+
346
+
299
347
  * @example
300
348
  * // DirectedGraph deleteEdge and vertex operations
301
349
  * const graph = new DirectedGraph<string>();
@@ -362,6 +410,30 @@ export class DirectedGraph<
362
410
 
363
411
 
364
412
 
413
+
414
+
415
+
416
+
417
+
418
+
419
+
420
+
421
+
422
+
423
+
424
+
425
+
426
+
427
+
428
+
429
+
430
+
431
+
432
+
433
+
434
+
435
+
436
+
365
437
  * @example
366
438
  * // Remove a vertex
367
439
  * const g = new DirectedGraph();
@@ -428,6 +500,30 @@ export class DirectedGraph<
428
500
 
429
501
 
430
502
 
503
+
504
+
505
+
506
+
507
+
508
+
509
+
510
+
511
+
512
+
513
+
514
+
515
+
516
+
517
+
518
+
519
+
520
+
521
+
522
+
523
+
524
+
525
+
526
+
431
527
  * @example
432
528
  * // Get incoming edges
433
529
  * const g = new DirectedGraph();
@@ -459,6 +555,30 @@ export class DirectedGraph<
459
555
 
460
556
 
461
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
+
462
582
  * @example
463
583
  * // Get outgoing edges
464
584
  * const g = new DirectedGraph();
@@ -562,6 +682,30 @@ export class DirectedGraph<
562
682
 
563
683
 
564
684
 
685
+
686
+
687
+
688
+
689
+
690
+
691
+
692
+
693
+
694
+
695
+
696
+
697
+
698
+
699
+
700
+
701
+
702
+
703
+
704
+
705
+
706
+
707
+
708
+
565
709
  * @example
566
710
  * // DirectedGraph topologicalSort for task scheduling
567
711
  * const graph = new DirectedGraph<string>();
@@ -632,6 +776,30 @@ export class DirectedGraph<
632
776
 
633
777
 
634
778
 
779
+
780
+
781
+
782
+
783
+
784
+
785
+
786
+
787
+
788
+
789
+
790
+
791
+
792
+
793
+
794
+
795
+
796
+
797
+
798
+
799
+
800
+
801
+
802
+
635
803
  * @example
636
804
  * // Get all edges
637
805
  * const g = new DirectedGraph();
@@ -659,6 +827,30 @@ export class DirectedGraph<
659
827
 
660
828
 
661
829
 
830
+
831
+
832
+
833
+
834
+
835
+
836
+
837
+
838
+
839
+
840
+
841
+
842
+
843
+
844
+
845
+
846
+
847
+
848
+
849
+
850
+
851
+
852
+
853
+
662
854
  * @example
663
855
  * // Get outgoing neighbors
664
856
  * const g = new DirectedGraph();
@@ -744,6 +936,30 @@ export class DirectedGraph<
744
936
 
745
937
 
746
938
 
939
+
940
+
941
+
942
+
943
+
944
+
945
+
946
+
947
+
948
+
949
+
950
+
951
+
952
+
953
+
954
+
955
+
956
+
957
+
958
+
959
+
960
+
961
+
962
+
747
963
  * @example
748
964
  * // Find strongly connected components
749
965
  * const g = new DirectedGraph();
@@ -839,6 +1055,30 @@ export class DirectedGraph<
839
1055
 
840
1056
 
841
1057
 
1058
+
1059
+
1060
+
1061
+
1062
+
1063
+
1064
+
1065
+
1066
+
1067
+
1068
+
1069
+
1070
+
1071
+
1072
+
1073
+
1074
+
1075
+
1076
+
1077
+
1078
+
1079
+
1080
+
1081
+
842
1082
  * @example
843
1083
  * // Get strongly connected components
844
1084
  * const g = new DirectedGraph();
@@ -234,6 +234,30 @@ export class UndirectedGraph<
234
234
 
235
235
 
236
236
 
237
+
238
+
239
+
240
+
241
+
242
+
243
+
244
+
245
+
246
+
247
+
248
+
249
+
250
+
251
+
252
+
253
+
254
+
255
+
256
+
257
+
258
+
259
+
260
+
237
261
  * @example
238
262
  * // Get edge between vertices
239
263
  * const g = new UndirectedGraph();
@@ -301,6 +325,30 @@ export class UndirectedGraph<
301
325
 
302
326
 
303
327
 
328
+
329
+
330
+
331
+
332
+
333
+
334
+
335
+
336
+
337
+
338
+
339
+
340
+
341
+
342
+
343
+
344
+
345
+
346
+
347
+
348
+
349
+
350
+
351
+
304
352
  * @example
305
353
  * // UndirectedGraph deleteEdge and vertex operations
306
354
  * const graph = new UndirectedGraph<string>();
@@ -363,6 +411,30 @@ export class UndirectedGraph<
363
411
 
364
412
 
365
413
 
414
+
415
+
416
+
417
+
418
+
419
+
420
+
421
+
422
+
423
+
424
+
425
+
426
+
427
+
428
+
429
+
430
+
431
+
432
+
433
+
434
+
435
+
436
+
437
+
366
438
  * @example
367
439
  * // Remove vertex and edges
368
440
  * const g = new UndirectedGraph();
@@ -449,6 +521,30 @@ export class UndirectedGraph<
449
521
 
450
522
 
451
523
 
524
+
525
+
526
+
527
+
528
+
529
+
530
+
531
+
532
+
533
+
534
+
535
+
536
+
537
+
538
+
539
+
540
+
541
+
542
+
543
+
544
+
545
+
546
+
547
+
452
548
  * @example
453
549
  * // Get all edges
454
550
  * const g = new UndirectedGraph();
@@ -480,6 +576,30 @@ export class UndirectedGraph<
480
576
 
481
577
 
482
578
 
579
+
580
+
581
+
582
+
583
+
584
+
585
+
586
+
587
+
588
+
589
+
590
+
591
+
592
+
593
+
594
+
595
+
596
+
597
+
598
+
599
+
600
+
601
+
602
+
483
603
  * @example
484
604
  * // UndirectedGraph connectivity and neighbors
485
605
  * const graph = new UndirectedGraph<string>();
@@ -585,6 +705,30 @@ export class UndirectedGraph<
585
705
 
586
706
 
587
707
 
708
+
709
+
710
+
711
+
712
+
713
+
714
+
715
+
716
+
717
+
718
+
719
+
720
+
721
+
722
+
723
+
724
+
725
+
726
+
727
+
728
+
729
+
730
+
731
+
588
732
  * @example
589
733
  * // Find articulation points and bridges
590
734
  * const g = new UndirectedGraph();
@@ -734,6 +878,30 @@ export class UndirectedGraph<
734
878
 
735
879
 
736
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
+
737
905
  * @example
738
906
  * // Detect cycle
739
907
  * const g = new UndirectedGraph();
@@ -781,6 +949,30 @@ export class UndirectedGraph<
781
949
 
782
950
 
783
951
 
952
+
953
+
954
+
955
+
956
+
957
+
958
+
959
+
960
+
961
+
962
+
963
+
964
+
965
+
966
+
967
+
968
+
969
+
970
+
971
+
972
+
973
+
974
+
975
+
784
976
  * @example
785
977
  * // Find bridge edges
786
978
  * const g = new UndirectedGraph();
@@ -808,6 +1000,30 @@ export class UndirectedGraph<
808
1000
 
809
1001
 
810
1002
 
1003
+
1004
+
1005
+
1006
+
1007
+
1008
+
1009
+
1010
+
1011
+
1012
+
1013
+
1014
+
1015
+
1016
+
1017
+
1018
+
1019
+
1020
+
1021
+
1022
+
1023
+
1024
+
1025
+
1026
+
811
1027
  * @example
812
1028
  * // Find articulation points
813
1029
  * const g = new UndirectedGraph();