max-priority-queue-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 +398 -55
  2. package/dist/cjs/index.cjs.map +1 -1
  3. package/dist/cjs-legacy/index.cjs +397 -54
  4. package/dist/cjs-legacy/index.cjs.map +1 -1
  5. package/dist/esm/index.mjs +398 -56
  6. package/dist/esm/index.mjs.map +1 -1
  7. package/dist/esm-legacy/index.mjs +397 -55
  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/max-priority-queue-typed.js +395 -53
  47. package/dist/umd/max-priority-queue-typed.js.map +1 -1
  48. package/dist/umd/max-priority-queue-typed.min.js +1 -1
  49. package/dist/umd/max-priority-queue-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 { 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.
@@ -196,6 +196,30 @@ export class Heap<E = any, R = any> extends IterableElementBase<E, R> {
196
196
 
197
197
 
198
198
 
199
+
200
+
201
+
202
+
203
+
204
+
205
+
206
+
207
+
208
+
209
+
210
+
211
+
212
+
213
+
214
+
215
+
216
+
217
+
218
+
219
+
220
+
221
+
222
+
199
223
  * @example
200
224
  * // Track heap capacity
201
225
  * const heap = new Heap<number>();
@@ -270,6 +294,30 @@ export class Heap<E = any, R = any> extends IterableElementBase<E, R> {
270
294
 
271
295
 
272
296
 
297
+
298
+
299
+
300
+
301
+
302
+
303
+
304
+
305
+
306
+
307
+
308
+
309
+
310
+
311
+
312
+
313
+
314
+
315
+
316
+
317
+
318
+
319
+
320
+
273
321
  * @example
274
322
  * // basic Heap creation and add operation
275
323
  * // Create a min heap (default)
@@ -305,6 +353,30 @@ export class Heap<E = any, R = any> extends IterableElementBase<E, R> {
305
353
 
306
354
 
307
355
 
356
+
357
+
358
+
359
+
360
+
361
+
362
+
363
+
364
+
365
+
366
+
367
+
368
+
369
+
370
+
371
+
372
+
373
+
374
+
375
+
376
+
377
+
378
+
379
+
308
380
  * @example
309
381
  * // Add multiple elements
310
382
  * const heap = new Heap<number>([], { comparator: (a, b) => a - b });
@@ -342,6 +414,30 @@ export class Heap<E = any, R = any> extends IterableElementBase<E, R> {
342
414
 
343
415
 
344
416
 
417
+
418
+
419
+
420
+
421
+
422
+
423
+
424
+
425
+
426
+
427
+
428
+
429
+
430
+
431
+
432
+
433
+
434
+
435
+
436
+
437
+
438
+
439
+
440
+
345
441
  * @example
346
442
  * // Heap with custom comparator (MaxHeap behavior)
347
443
  * interface Task {
@@ -395,6 +491,30 @@ export class Heap<E = any, R = any> extends IterableElementBase<E, R> {
395
491
 
396
492
 
397
493
 
494
+
495
+
496
+
497
+
498
+
499
+
500
+
501
+
502
+
503
+
504
+
505
+
506
+
507
+
508
+
509
+
510
+
511
+
512
+
513
+
514
+
515
+
516
+
517
+
398
518
  * @example
399
519
  * // Heap for event processing with priority
400
520
  * interface Event {
@@ -473,6 +593,30 @@ export class Heap<E = any, R = any> extends IterableElementBase<E, R> {
473
593
 
474
594
 
475
595
 
596
+
597
+
598
+
599
+
600
+
601
+
602
+
603
+
604
+
605
+
606
+
607
+
608
+
609
+
610
+
611
+
612
+
613
+
614
+
615
+
616
+
617
+
618
+
619
+
476
620
  * @example
477
621
  * // Check if heap is empty
478
622
  * const heap = new Heap<number>([], { comparator: (a, b) => a - b });
@@ -498,6 +642,30 @@ export class Heap<E = any, R = any> extends IterableElementBase<E, R> {
498
642
 
499
643
 
500
644
 
645
+
646
+
647
+
648
+
649
+
650
+
651
+
652
+
653
+
654
+
655
+
656
+
657
+
658
+
659
+
660
+
661
+
662
+
663
+
664
+
665
+
666
+
667
+
668
+
501
669
  * @example
502
670
  * // Remove all elements
503
671
  * const heap = new Heap<number>([1, 2, 3], { comparator: (a, b) => a - b });
@@ -528,6 +696,30 @@ export class Heap<E = any, R = any> extends IterableElementBase<E, R> {
528
696
  * @returns True if found.
529
697
 
530
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
+
531
723
  * @example
532
724
  * // Check element existence
533
725
  * const heap = new Heap<number>([3, 1, 2], { comparator: (a, b) => a - b });
@@ -553,6 +745,30 @@ export class Heap<E = any, R = any> extends IterableElementBase<E, R> {
553
745
 
554
746
 
555
747
 
748
+
749
+
750
+
751
+
752
+
753
+
754
+
755
+
756
+
757
+
758
+
759
+
760
+
761
+
762
+
763
+
764
+
765
+
766
+
767
+
768
+
769
+
770
+
771
+
556
772
  * @example
557
773
  * // Remove specific element
558
774
  * const heap = new Heap<number>([3, 1, 4, 1, 5], { comparator: (a, b) => a - b });
@@ -628,6 +844,30 @@ export class Heap<E = any, R = any> extends IterableElementBase<E, R> {
628
844
  * @returns Array of visited elements.
629
845
 
630
846
 
847
+
848
+
849
+
850
+
851
+
852
+
853
+
854
+
855
+
856
+
857
+
858
+
859
+
860
+
861
+
862
+
863
+
864
+
865
+
866
+
867
+
868
+
869
+
870
+
631
871
  * @example
632
872
  * // Depth-first traversal
633
873
  * const heap = new Heap<number>([3, 1, 2], { comparator: (a, b) => a - b });
@@ -689,6 +929,30 @@ export class Heap<E = any, R = any> extends IterableElementBase<E, R> {
689
929
 
690
930
 
691
931
 
932
+
933
+
934
+
935
+
936
+
937
+
938
+
939
+
940
+
941
+
942
+
943
+
944
+
945
+
946
+
947
+
948
+
949
+
950
+
951
+
952
+
953
+
954
+
955
+
692
956
  * @example
693
957
  * // Sort elements using heap
694
958
  * const heap = new Heap<number>([5, 1, 3, 2, 4]);
@@ -720,6 +984,30 @@ export class Heap<E = any, R = any> extends IterableElementBase<E, R> {
720
984
 
721
985
 
722
986
 
987
+
988
+
989
+
990
+
991
+
992
+
993
+
994
+
995
+
996
+
997
+
998
+
999
+
1000
+
1001
+
1002
+
1003
+
1004
+
1005
+
1006
+
1007
+
1008
+
1009
+
1010
+
723
1011
  * @example
724
1012
  * // Create independent copy
725
1013
  * const heap = new Heap<number>([3, 1, 4], { comparator: (a, b) => a - b });
@@ -750,6 +1038,30 @@ export class Heap<E = any, R = any> extends IterableElementBase<E, R> {
750
1038
 
751
1039
 
752
1040
 
1041
+
1042
+
1043
+
1044
+
1045
+
1046
+
1047
+
1048
+
1049
+
1050
+
1051
+
1052
+
1053
+
1054
+
1055
+
1056
+
1057
+
1058
+
1059
+
1060
+
1061
+
1062
+
1063
+
1064
+
753
1065
  * @example
754
1066
  * // Filter elements
755
1067
  * const heap = new Heap<number>([1, 2, 3, 4, 5], { comparator: (a, b) => a - b });
@@ -787,6 +1099,30 @@ export class Heap<E = any, R = any> extends IterableElementBase<E, R> {
787
1099
 
788
1100
 
789
1101
 
1102
+
1103
+
1104
+
1105
+
1106
+
1107
+
1108
+
1109
+
1110
+
1111
+
1112
+
1113
+
1114
+
1115
+
1116
+
1117
+
1118
+
1119
+
1120
+
1121
+
1122
+
1123
+
1124
+
1125
+
790
1126
  * @example
791
1127
  * // Transform elements
792
1128
  * const heap = new Heap<number>([1, 2, 3], { comparator: (a, b) => a - b });
@@ -800,7 +1136,7 @@ export class Heap<E = any, R = any> extends IterableElementBase<E, R> {
800
1136
  thisArg?: unknown
801
1137
  ): Heap<EM, RM> {
802
1138
  const { comparator, toElementFn, ...rest } = options ?? {};
803
- if (!comparator) throw new TypeError(ERR.comparatorRequired('Heap.map'));
1139
+ if (!comparator) raise(TypeError, ERR.comparatorRequired('Heap.map'));
804
1140
  const out = this._createLike<EM, RM>([], { ...rest, comparator, toElementFn });
805
1141
  let i = 0;
806
1142
  for (const x of this) {
@@ -830,7 +1166,7 @@ export class Heap<E = any, R = any> extends IterableElementBase<E, R> {
830
1166
 
831
1167
  protected readonly _DEFAULT_COMPARATOR: Comparator<E> = (a: E, b: E): number => {
832
1168
  if (typeof a === 'object' || typeof b === 'object') {
833
- throw new TypeError(ERR.comparatorRequired('Heap'));
1169
+ raise(TypeError, ERR.comparatorRequired('Heap'));
834
1170
  }
835
1171
  if (a > b) return 1;
836
1172
  if (a < b) return -1;
@@ -972,7 +1308,7 @@ export class FibonacciHeap<E> {
972
1308
  constructor(comparator?: Comparator<E>) {
973
1309
  this.clear();
974
1310
  this._comparator = comparator || this._defaultComparator;
975
- if (typeof this.comparator !== 'function') throw new TypeError(ERR.notAFunction('comparator', 'FibonacciHeap'));
1311
+ if (typeof this.comparator !== 'function') raise(TypeError, ERR.notAFunction('comparator', 'FibonacciHeap'));
976
1312
  }
977
1313
 
978
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;