binary-tree-typed 2.5.1 → 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 (73) hide show
  1. package/dist/cjs/index.cjs +146 -52
  2. package/dist/cjs/index.cjs.map +1 -1
  3. package/dist/cjs-legacy/index.cjs +145 -51
  4. package/dist/cjs-legacy/index.cjs.map +1 -1
  5. package/dist/esm/index.mjs +146 -53
  6. package/dist/esm/index.mjs.map +1 -1
  7. package/dist/esm-legacy/index.mjs +145 -52
  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/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 +77 -2
  14. package/dist/types/data-structures/binary-tree/bst.d.ts +171 -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 +409 -0
  18. package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +411 -6
  19. package/dist/types/data-structures/binary-tree/tree-multi-set.d.ts +339 -6
  20. package/dist/types/data-structures/binary-tree/tree-set.d.ts +391 -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 +51 -0
  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 +45 -0
  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/types/types/data-structures/binary-tree/bst.d.ts +1 -0
  34. package/dist/types/types/data-structures/binary-tree/tree-map.d.ts +5 -0
  35. package/dist/types/types/data-structures/binary-tree/tree-multi-set.d.ts +4 -0
  36. package/dist/types/types/data-structures/binary-tree/tree-set.d.ts +4 -0
  37. package/dist/umd/binary-tree-typed.js +143 -50
  38. package/dist/umd/binary-tree-typed.js.map +1 -1
  39. package/dist/umd/binary-tree-typed.min.js +3 -3
  40. package/dist/umd/binary-tree-typed.min.js.map +1 -1
  41. package/package.json +2 -2
  42. package/src/common/error.ts +19 -1
  43. package/src/common/index.ts +1 -1
  44. package/src/data-structures/base/iterable-element-base.ts +3 -2
  45. package/src/data-structures/binary-tree/avl-tree.ts +47 -0
  46. package/src/data-structures/binary-tree/binary-indexed-tree.ts +46 -4
  47. package/src/data-structures/binary-tree/binary-tree.ts +79 -4
  48. package/src/data-structures/binary-tree/bst.ts +441 -6
  49. package/src/data-structures/binary-tree/red-black-tree.ts +73 -0
  50. package/src/data-structures/binary-tree/segment-tree.ts +18 -0
  51. package/src/data-structures/binary-tree/tree-map.ts +434 -9
  52. package/src/data-structures/binary-tree/tree-multi-map.ts +426 -5
  53. package/src/data-structures/binary-tree/tree-multi-set.ts +350 -6
  54. package/src/data-structures/binary-tree/tree-set.ts +410 -8
  55. package/src/data-structures/graph/abstract-graph.ts +2 -2
  56. package/src/data-structures/graph/directed-graph.ts +30 -0
  57. package/src/data-structures/graph/undirected-graph.ts +27 -0
  58. package/src/data-structures/hash/hash-map.ts +35 -4
  59. package/src/data-structures/heap/heap.ts +46 -4
  60. package/src/data-structures/heap/max-heap.ts +2 -2
  61. package/src/data-structures/linked-list/doubly-linked-list.ts +51 -0
  62. package/src/data-structures/linked-list/singly-linked-list.ts +45 -0
  63. package/src/data-structures/linked-list/skip-linked-list.ts +59 -5
  64. package/src/data-structures/matrix/matrix.ts +33 -9
  65. package/src/data-structures/priority-queue/max-priority-queue.ts +2 -2
  66. package/src/data-structures/queue/deque.ts +45 -0
  67. package/src/data-structures/queue/queue.ts +36 -0
  68. package/src/data-structures/stack/stack.ts +30 -0
  69. package/src/data-structures/trie/trie.ts +38 -2
  70. package/src/types/data-structures/binary-tree/bst.ts +1 -0
  71. package/src/types/data-structures/binary-tree/tree-map.ts +6 -0
  72. package/src/types/data-structures/binary-tree/tree-multi-set.ts +5 -0
  73. package/src/types/data-structures/binary-tree/tree-set.ts +5 -0
@@ -242,6 +242,9 @@ export class DirectedGraph<
242
242
 
243
243
 
244
244
 
245
+
246
+
247
+
245
248
 
246
249
 
247
250
 
@@ -334,6 +337,9 @@ export class DirectedGraph<
334
337
 
335
338
 
336
339
 
340
+
341
+
342
+
337
343
 
338
344
 
339
345
 
@@ -421,6 +427,9 @@ export class DirectedGraph<
421
427
 
422
428
 
423
429
 
430
+
431
+
432
+
424
433
 
425
434
 
426
435
 
@@ -508,6 +517,9 @@ export class DirectedGraph<
508
517
 
509
518
 
510
519
 
520
+
521
+
522
+
511
523
 
512
524
 
513
525
 
@@ -560,6 +572,9 @@ export class DirectedGraph<
560
572
 
561
573
 
562
574
 
575
+
576
+
577
+
563
578
 
564
579
 
565
580
 
@@ -684,6 +699,9 @@ export class DirectedGraph<
684
699
 
685
700
 
686
701
 
702
+
703
+
704
+
687
705
 
688
706
 
689
707
 
@@ -775,6 +793,9 @@ export class DirectedGraph<
775
793
 
776
794
 
777
795
 
796
+
797
+
798
+
778
799
 
779
800
 
780
801
 
@@ -823,6 +844,9 @@ export class DirectedGraph<
823
844
 
824
845
 
825
846
 
847
+
848
+
849
+
826
850
 
827
851
 
828
852
 
@@ -929,6 +953,9 @@ export class DirectedGraph<
929
953
 
930
954
 
931
955
 
956
+
957
+
958
+
932
959
 
933
960
 
934
961
 
@@ -1045,6 +1072,9 @@ export class DirectedGraph<
1045
1072
 
1046
1073
 
1047
1074
 
1075
+
1076
+
1077
+
1048
1078
 
1049
1079
 
1050
1080
 
@@ -251,6 +251,9 @@ export class UndirectedGraph<
251
251
 
252
252
 
253
253
 
254
+
255
+
256
+
254
257
 
255
258
 
256
259
 
@@ -339,6 +342,9 @@ export class UndirectedGraph<
339
342
 
340
343
 
341
344
 
345
+
346
+
347
+
342
348
 
343
349
 
344
350
 
@@ -422,6 +428,9 @@ export class UndirectedGraph<
422
428
 
423
429
 
424
430
 
431
+
432
+
433
+
425
434
 
426
435
 
427
436
 
@@ -529,6 +538,9 @@ export class UndirectedGraph<
529
538
 
530
539
 
531
540
 
541
+
542
+
543
+
532
544
 
533
545
 
534
546
 
@@ -581,6 +593,9 @@ export class UndirectedGraph<
581
593
 
582
594
 
583
595
 
596
+
597
+
598
+
584
599
 
585
600
 
586
601
 
@@ -707,6 +722,9 @@ export class UndirectedGraph<
707
722
 
708
723
 
709
724
 
725
+
726
+
727
+
710
728
 
711
729
 
712
730
 
@@ -877,6 +895,9 @@ export class UndirectedGraph<
877
895
 
878
896
 
879
897
 
898
+
899
+
900
+
880
901
 
881
902
 
882
903
 
@@ -945,6 +966,9 @@ export class UndirectedGraph<
945
966
 
946
967
 
947
968
 
969
+
970
+
971
+
948
972
 
949
973
 
950
974
 
@@ -993,6 +1017,9 @@ export class UndirectedGraph<
993
1017
 
994
1018
 
995
1019
 
1020
+
1021
+
1022
+
996
1023
 
997
1024
 
998
1025
 
@@ -15,7 +15,7 @@ import type {
15
15
  } from '../../types';
16
16
  import { IterableEntryBase } from '../base';
17
17
  import { isWeakKey, rangeCheck } from '../../utils';
18
- import { ERR } from '../../common';
18
+ import { ERR, raise } from '../../common';
19
19
 
20
20
  /**
21
21
  * Hash-based map. Supports object keys and custom hashing; offers O(1) average set/get/has.
@@ -197,6 +197,9 @@ export class HashMap<K = any, V = any, R = [K, V]> extends IterableEntryBase<K,
197
197
 
198
198
 
199
199
 
200
+
201
+
202
+
200
203
 
201
204
 
202
205
 
@@ -240,6 +243,9 @@ export class HashMap<K = any, V = any, R = [K, V]> extends IterableEntryBase<K,
240
243
 
241
244
 
242
245
 
246
+
247
+
248
+
243
249
 
244
250
 
245
251
 
@@ -328,6 +334,12 @@ export class HashMap<K = any, V = any, R = [K, V]> extends IterableEntryBase<K,
328
334
 
329
335
 
330
336
 
337
+
338
+
339
+
340
+
341
+
342
+
331
343
 
332
344
 
333
345
 
@@ -397,6 +409,9 @@ export class HashMap<K = any, V = any, R = [K, V]> extends IterableEntryBase<K,
397
409
 
398
410
 
399
411
 
412
+
413
+
414
+
400
415
 
401
416
 
402
417
 
@@ -451,6 +466,9 @@ export class HashMap<K = any, V = any, R = [K, V]> extends IterableEntryBase<K,
451
466
 
452
467
 
453
468
 
469
+
470
+
471
+
454
472
 
455
473
 
456
474
 
@@ -516,6 +534,9 @@ export class HashMap<K = any, V = any, R = [K, V]> extends IterableEntryBase<K,
516
534
 
517
535
 
518
536
 
537
+
538
+
539
+
519
540
 
520
541
 
521
542
 
@@ -566,6 +587,9 @@ export class HashMap<K = any, V = any, R = [K, V]> extends IterableEntryBase<K,
566
587
 
567
588
 
568
589
 
590
+
591
+
592
+
569
593
 
570
594
 
571
595
 
@@ -635,6 +659,9 @@ export class HashMap<K = any, V = any, R = [K, V]> extends IterableEntryBase<K,
635
659
 
636
660
 
637
661
 
662
+
663
+
664
+
638
665
 
639
666
 
640
667
 
@@ -686,6 +713,9 @@ export class HashMap<K = any, V = any, R = [K, V]> extends IterableEntryBase<K,
686
713
 
687
714
 
688
715
 
716
+
717
+
718
+
689
719
 
690
720
 
691
721
 
@@ -739,6 +769,9 @@ export class HashMap<K = any, V = any, R = [K, V]> extends IterableEntryBase<K,
739
769
 
740
770
 
741
771
 
772
+
773
+
774
+
742
775
 
743
776
 
744
777
 
@@ -919,9 +952,7 @@ export class LinkedHashMap<K = any, V = any, R = [K, V]> extends IterableEntryBa
919
952
  if (this.isEntry(rawElement)) {
920
953
  return rawElement;
921
954
  }
922
- throw new TypeError(
923
- ERR.invalidArgument('If elements do not adhere to [key, value], provide options.toEntryFn to transform raw records.', 'HashMap')
924
- );
955
+ raise(TypeError, ERR.invalidArgument('If elements do not adhere to [key, value], provide options.toEntryFn to transform raw records.', 'HashMap'));
925
956
  };
926
957
 
927
958
  get toEntryFn() {
@@ -8,7 +8,7 @@
8
8
 
9
9
  import type { Comparator, DFSOrderPattern, ElementCallback, HeapOptions } from '../../types';
10
10
  import { IterableElementBase } from '../base';
11
- import { ERR } from '../../common';
11
+ import { ERR, raise } from '../../common';
12
12
 
13
13
  /**
14
14
  * Binary heap with pluggable comparator; supports fast insertion and removal of the top element.
@@ -213,6 +213,9 @@ export class Heap<E = any, R = any> extends IterableElementBase<E, R> {
213
213
 
214
214
 
215
215
 
216
+
217
+
218
+
216
219
 
217
220
 
218
221
 
@@ -308,6 +311,9 @@ export class Heap<E = any, R = any> extends IterableElementBase<E, R> {
308
311
 
309
312
 
310
313
 
314
+
315
+
316
+
311
317
 
312
318
 
313
319
 
@@ -364,6 +370,9 @@ export class Heap<E = any, R = any> extends IterableElementBase<E, R> {
364
370
 
365
371
 
366
372
 
373
+
374
+
375
+
367
376
 
368
377
 
369
378
 
@@ -422,6 +431,9 @@ export class Heap<E = any, R = any> extends IterableElementBase<E, R> {
422
431
 
423
432
 
424
433
 
434
+
435
+
436
+
425
437
 
426
438
 
427
439
 
@@ -496,6 +508,9 @@ export class Heap<E = any, R = any> extends IterableElementBase<E, R> {
496
508
 
497
509
 
498
510
 
511
+
512
+
513
+
499
514
 
500
515
 
501
516
 
@@ -595,6 +610,9 @@ export class Heap<E = any, R = any> extends IterableElementBase<E, R> {
595
610
 
596
611
 
597
612
 
613
+
614
+
615
+
598
616
 
599
617
 
600
618
 
@@ -641,6 +659,9 @@ export class Heap<E = any, R = any> extends IterableElementBase<E, R> {
641
659
 
642
660
 
643
661
 
662
+
663
+
664
+
644
665
 
645
666
 
646
667
 
@@ -692,6 +713,9 @@ export class Heap<E = any, R = any> extends IterableElementBase<E, R> {
692
713
 
693
714
 
694
715
 
716
+
717
+
718
+
695
719
 
696
720
 
697
721
 
@@ -738,6 +762,9 @@ export class Heap<E = any, R = any> extends IterableElementBase<E, R> {
738
762
 
739
763
 
740
764
 
765
+
766
+
767
+
741
768
 
742
769
 
743
770
 
@@ -834,6 +861,9 @@ export class Heap<E = any, R = any> extends IterableElementBase<E, R> {
834
861
 
835
862
 
836
863
 
864
+
865
+
866
+
837
867
 
838
868
 
839
869
 
@@ -916,6 +946,9 @@ export class Heap<E = any, R = any> extends IterableElementBase<E, R> {
916
946
 
917
947
 
918
948
 
949
+
950
+
951
+
919
952
 
920
953
 
921
954
 
@@ -968,6 +1001,9 @@ export class Heap<E = any, R = any> extends IterableElementBase<E, R> {
968
1001
 
969
1002
 
970
1003
 
1004
+
1005
+
1006
+
971
1007
 
972
1008
 
973
1009
 
@@ -1019,6 +1055,9 @@ export class Heap<E = any, R = any> extends IterableElementBase<E, R> {
1019
1055
 
1020
1056
 
1021
1057
 
1058
+
1059
+
1060
+
1022
1061
 
1023
1062
 
1024
1063
 
@@ -1077,6 +1116,9 @@ export class Heap<E = any, R = any> extends IterableElementBase<E, R> {
1077
1116
 
1078
1117
 
1079
1118
 
1119
+
1120
+
1121
+
1080
1122
 
1081
1123
 
1082
1124
 
@@ -1094,7 +1136,7 @@ export class Heap<E = any, R = any> extends IterableElementBase<E, R> {
1094
1136
  thisArg?: unknown
1095
1137
  ): Heap<EM, RM> {
1096
1138
  const { comparator, toElementFn, ...rest } = options ?? {};
1097
- if (!comparator) throw new TypeError(ERR.comparatorRequired('Heap.map'));
1139
+ if (!comparator) raise(TypeError, ERR.comparatorRequired('Heap.map'));
1098
1140
  const out = this._createLike<EM, RM>([], { ...rest, comparator, toElementFn });
1099
1141
  let i = 0;
1100
1142
  for (const x of this) {
@@ -1124,7 +1166,7 @@ export class Heap<E = any, R = any> extends IterableElementBase<E, R> {
1124
1166
 
1125
1167
  protected readonly _DEFAULT_COMPARATOR: Comparator<E> = (a: E, b: E): number => {
1126
1168
  if (typeof a === 'object' || typeof b === 'object') {
1127
- throw new TypeError(ERR.comparatorRequired('Heap'));
1169
+ raise(TypeError, ERR.comparatorRequired('Heap'));
1128
1170
  }
1129
1171
  if (a > b) return 1;
1130
1172
  if (a < b) return -1;
@@ -1266,7 +1308,7 @@ export class FibonacciHeap<E> {
1266
1308
  constructor(comparator?: Comparator<E>) {
1267
1309
  this.clear();
1268
1310
  this._comparator = comparator || this._defaultComparator;
1269
- if (typeof this.comparator !== 'function') throw new TypeError(ERR.notAFunction('comparator', 'FibonacciHeap'));
1311
+ if (typeof this.comparator !== 'function') raise(TypeError, ERR.notAFunction('comparator', 'FibonacciHeap'));
1270
1312
  }
1271
1313
 
1272
1314
  protected _root?: FibonacciHeapNode<E>;
@@ -6,7 +6,7 @@
6
6
  */
7
7
  import type { HeapOptions } from '../../types';
8
8
  import { Heap } from './heap';
9
- import { ERR } from '../../common';
9
+ import { ERR, raise } from '../../common';
10
10
 
11
11
  /**
12
12
  * @template E
@@ -80,7 +80,7 @@ export class MaxHeap<E = any, R = any> extends Heap<E, R> {
80
80
  super(elements, {
81
81
  comparator: (a: E, b: E): number => {
82
82
  if (typeof a === 'object' || typeof b === 'object') {
83
- throw new TypeError(ERR.comparatorRequired('MaxHeap'));
83
+ raise(TypeError, ERR.comparatorRequired('MaxHeap'));
84
84
  }
85
85
  if (a < b) return 1;
86
86
  if (a > b) return -1;
@@ -296,6 +296,9 @@ export class DoublyLinkedList<E = any, R = any> extends LinearLinkedBase<E, R, D
296
296
 
297
297
 
298
298
 
299
+
300
+
301
+
299
302
 
300
303
 
301
304
 
@@ -364,6 +367,9 @@ export class DoublyLinkedList<E = any, R = any> extends LinearLinkedBase<E, R, D
364
367
 
365
368
 
366
369
 
370
+
371
+
372
+
367
373
 
368
374
 
369
375
 
@@ -431,6 +437,9 @@ export class DoublyLinkedList<E = any, R = any> extends LinearLinkedBase<E, R, D
431
437
 
432
438
 
433
439
 
440
+
441
+
442
+
434
443
 
435
444
 
436
445
 
@@ -489,6 +498,9 @@ export class DoublyLinkedList<E = any, R = any> extends LinearLinkedBase<E, R, D
489
498
 
490
499
 
491
500
 
501
+
502
+
503
+
492
504
 
493
505
 
494
506
 
@@ -580,6 +592,9 @@ export class DoublyLinkedList<E = any, R = any> extends LinearLinkedBase<E, R, D
580
592
 
581
593
 
582
594
 
595
+
596
+
597
+
583
598
 
584
599
 
585
600
 
@@ -628,6 +643,9 @@ export class DoublyLinkedList<E = any, R = any> extends LinearLinkedBase<E, R, D
628
643
 
629
644
 
630
645
 
646
+
647
+
648
+
631
649
 
632
650
 
633
651
 
@@ -715,6 +733,9 @@ export class DoublyLinkedList<E = any, R = any> extends LinearLinkedBase<E, R, D
715
733
 
716
734
 
717
735
 
736
+
737
+
738
+
718
739
 
719
740
 
720
741
 
@@ -838,6 +859,9 @@ export class DoublyLinkedList<E = any, R = any> extends LinearLinkedBase<E, R, D
838
859
 
839
860
 
840
861
 
862
+
863
+
864
+
841
865
 
842
866
 
843
867
 
@@ -893,6 +917,9 @@ export class DoublyLinkedList<E = any, R = any> extends LinearLinkedBase<E, R, D
893
917
 
894
918
 
895
919
 
920
+
921
+
922
+
896
923
 
897
924
 
898
925
 
@@ -950,6 +977,9 @@ export class DoublyLinkedList<E = any, R = any> extends LinearLinkedBase<E, R, D
950
977
 
951
978
 
952
979
 
980
+
981
+
982
+
953
983
 
954
984
 
955
985
 
@@ -993,6 +1023,9 @@ export class DoublyLinkedList<E = any, R = any> extends LinearLinkedBase<E, R, D
993
1023
 
994
1024
 
995
1025
 
1026
+
1027
+
1028
+
996
1029
 
997
1030
 
998
1031
 
@@ -1040,6 +1073,9 @@ export class DoublyLinkedList<E = any, R = any> extends LinearLinkedBase<E, R, D
1040
1073
 
1041
1074
 
1042
1075
 
1076
+
1077
+
1078
+
1043
1079
 
1044
1080
 
1045
1081
 
@@ -1093,6 +1129,9 @@ export class DoublyLinkedList<E = any, R = any> extends LinearLinkedBase<E, R, D
1093
1129
 
1094
1130
 
1095
1131
 
1132
+
1133
+
1134
+
1096
1135
 
1097
1136
 
1098
1137
 
@@ -1149,6 +1188,9 @@ export class DoublyLinkedList<E = any, R = any> extends LinearLinkedBase<E, R, D
1149
1188
 
1150
1189
 
1151
1190
 
1191
+
1192
+
1193
+
1152
1194
 
1153
1195
 
1154
1196
 
@@ -1213,6 +1255,9 @@ export class DoublyLinkedList<E = any, R = any> extends LinearLinkedBase<E, R, D
1213
1255
 
1214
1256
 
1215
1257
 
1258
+
1259
+
1260
+
1216
1261
 
1217
1262
 
1218
1263
 
@@ -1265,6 +1310,9 @@ export class DoublyLinkedList<E = any, R = any> extends LinearLinkedBase<E, R, D
1265
1310
 
1266
1311
 
1267
1312
 
1313
+
1314
+
1315
+
1268
1316
 
1269
1317
 
1270
1318
 
@@ -1338,6 +1386,9 @@ export class DoublyLinkedList<E = any, R = any> extends LinearLinkedBase<E, R, D
1338
1386
 
1339
1387
 
1340
1388
 
1389
+
1390
+
1391
+
1341
1392
 
1342
1393
 
1343
1394