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
@@ -30,9 +30,61 @@ var maxPriorityQueueTyped = (() => {
30
30
  Heap: () => Heap,
31
31
  MaxPriorityQueue: () => MaxPriorityQueue,
32
32
  PriorityQueue: () => PriorityQueue,
33
- Range: () => Range
33
+ Range: () => Range,
34
+ raise: () => raise
34
35
  });
35
36
 
37
+ // src/common/error.ts
38
+ function raise(ErrorClass, message) {
39
+ throw new ErrorClass(message);
40
+ }
41
+ var ERR = {
42
+ // Range / index
43
+ indexOutOfRange: (index, min, max, ctx) => `${ctx ? ctx + ": " : ""}Index ${index} is out of range [${min}, ${max}].`,
44
+ invalidIndex: (ctx) => `${ctx ? ctx + ": " : ""}Index must be an integer.`,
45
+ // Type / argument
46
+ invalidArgument: (reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`,
47
+ comparatorRequired: (ctx) => `${ctx ? ctx + ": " : ""}Comparator is required for non-number/non-string/non-Date keys.`,
48
+ invalidKey: (reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`,
49
+ notAFunction: (name, ctx) => `${ctx ? ctx + ": " : ""}${name} must be a function.`,
50
+ invalidEntry: (ctx) => `${ctx ? ctx + ": " : ""}Each entry must be a [key, value] tuple.`,
51
+ invalidNaN: (ctx) => `${ctx ? ctx + ": " : ""}NaN is not a valid key.`,
52
+ invalidDate: (ctx) => `${ctx ? ctx + ": " : ""}Invalid Date key.`,
53
+ reduceEmpty: (ctx) => `${ctx ? ctx + ": " : ""}Reduce of empty structure with no initial value.`,
54
+ callbackReturnType: (expected, got, ctx) => `${ctx ? ctx + ": " : ""}Callback must return ${expected}; got ${got}.`,
55
+ // State / operation
56
+ invalidOperation: (reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`,
57
+ // Matrix
58
+ matrixDimensionMismatch: (op) => `Matrix: Dimensions must be compatible for ${op}.`,
59
+ matrixSingular: () => "Matrix: Singular matrix, inverse does not exist.",
60
+ matrixNotSquare: () => "Matrix: Must be square for inversion.",
61
+ matrixNotRectangular: () => "Matrix: Must be rectangular for transposition.",
62
+ matrixRowMismatch: (expected, got) => `Matrix: Expected row length ${expected}, but got ${got}.`,
63
+ // Order statistic
64
+ orderStatisticNotEnabled: (method, ctx) => `${ctx ? ctx + ": " : ""}${method}() requires enableOrderStatistic: true.`
65
+ };
66
+
67
+ // src/common/index.ts
68
+ var DFSOperation = /* @__PURE__ */ ((DFSOperation2) => {
69
+ DFSOperation2[DFSOperation2["VISIT"] = 0] = "VISIT";
70
+ DFSOperation2[DFSOperation2["PROCESS"] = 1] = "PROCESS";
71
+ return DFSOperation2;
72
+ })(DFSOperation || {});
73
+ var Range = class {
74
+ constructor(low, high, includeLow = true, includeHigh = true) {
75
+ this.low = low;
76
+ this.high = high;
77
+ this.includeLow = includeLow;
78
+ this.includeHigh = includeHigh;
79
+ }
80
+ // Determine whether a key is within the range
81
+ isInRange(key, comparator) {
82
+ const lowCheck = this.includeLow ? comparator(key, this.low) >= 0 : comparator(key, this.low) > 0;
83
+ const highCheck = this.includeHigh ? comparator(key, this.high) <= 0 : comparator(key, this.high) < 0;
84
+ return lowCheck && highCheck;
85
+ }
86
+ };
87
+
36
88
  // src/data-structures/base/iterable-element-base.ts
37
89
  var IterableElementBase = class {
38
90
  /**
@@ -55,7 +107,7 @@ var maxPriorityQueueTyped = (() => {
55
107
  if (options) {
56
108
  const { toElementFn } = options;
57
109
  if (typeof toElementFn === "function") this._toElementFn = toElementFn;
58
- else if (toElementFn) throw new TypeError("toElementFn must be a function type");
110
+ else if (toElementFn) raise(TypeError, "toElementFn must be a function type");
59
111
  }
60
112
  }
61
113
  /**
@@ -211,7 +263,7 @@ var maxPriorityQueueTyped = (() => {
211
263
  acc = initialValue;
212
264
  } else {
213
265
  const first = iter.next();
214
- if (first.done) throw new TypeError("Reduce of empty structure with no initial value");
266
+ if (first.done) raise(TypeError, "Reduce of empty structure with no initial value");
215
267
  acc = first.value;
216
268
  index = 1;
217
269
  }
@@ -253,52 +305,6 @@ var maxPriorityQueueTyped = (() => {
253
305
  }
254
306
  };
255
307
 
256
- // src/common/error.ts
257
- var ERR = {
258
- // Range / index
259
- indexOutOfRange: (index, min, max, ctx) => `${ctx ? ctx + ": " : ""}Index ${index} is out of range [${min}, ${max}].`,
260
- invalidIndex: (ctx) => `${ctx ? ctx + ": " : ""}Index must be an integer.`,
261
- // Type / argument
262
- invalidArgument: (reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`,
263
- comparatorRequired: (ctx) => `${ctx ? ctx + ": " : ""}Comparator is required for non-number/non-string/non-Date keys.`,
264
- invalidKey: (reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`,
265
- notAFunction: (name, ctx) => `${ctx ? ctx + ": " : ""}${name} must be a function.`,
266
- invalidEntry: (ctx) => `${ctx ? ctx + ": " : ""}Each entry must be a [key, value] tuple.`,
267
- invalidNaN: (ctx) => `${ctx ? ctx + ": " : ""}NaN is not a valid key.`,
268
- invalidDate: (ctx) => `${ctx ? ctx + ": " : ""}Invalid Date key.`,
269
- reduceEmpty: (ctx) => `${ctx ? ctx + ": " : ""}Reduce of empty structure with no initial value.`,
270
- callbackReturnType: (expected, got, ctx) => `${ctx ? ctx + ": " : ""}Callback must return ${expected}; got ${got}.`,
271
- // State / operation
272
- invalidOperation: (reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`,
273
- // Matrix
274
- matrixDimensionMismatch: (op) => `Matrix: Dimensions must be compatible for ${op}.`,
275
- matrixSingular: () => "Matrix: Singular matrix, inverse does not exist.",
276
- matrixNotSquare: () => "Matrix: Must be square for inversion.",
277
- matrixNotRectangular: () => "Matrix: Must be rectangular for transposition.",
278
- matrixRowMismatch: (expected, got) => `Matrix: Expected row length ${expected}, but got ${got}.`
279
- };
280
-
281
- // src/common/index.ts
282
- var DFSOperation = /* @__PURE__ */ ((DFSOperation2) => {
283
- DFSOperation2[DFSOperation2["VISIT"] = 0] = "VISIT";
284
- DFSOperation2[DFSOperation2["PROCESS"] = 1] = "PROCESS";
285
- return DFSOperation2;
286
- })(DFSOperation || {});
287
- var Range = class {
288
- constructor(low, high, includeLow = true, includeHigh = true) {
289
- this.low = low;
290
- this.high = high;
291
- this.includeLow = includeLow;
292
- this.includeHigh = includeHigh;
293
- }
294
- // Determine whether a key is within the range
295
- isInRange(key, comparator) {
296
- const lowCheck = this.includeLow ? comparator(key, this.low) >= 0 : comparator(key, this.low) > 0;
297
- const highCheck = this.includeHigh ? comparator(key, this.high) <= 0 : comparator(key, this.high) < 0;
298
- return lowCheck && highCheck;
299
- }
300
- };
301
-
302
308
  // src/data-structures/heap/heap.ts
303
309
  var Heap = class _Heap extends IterableElementBase {
304
310
  /**
@@ -314,7 +320,7 @@ var maxPriorityQueueTyped = (() => {
314
320
  __publicField(this, "_elements", []);
315
321
  __publicField(this, "_DEFAULT_COMPARATOR", (a, b) => {
316
322
  if (typeof a === "object" || typeof b === "object") {
317
- throw new TypeError(ERR.comparatorRequired("Heap"));
323
+ raise(TypeError, ERR.comparatorRequired("Heap"));
318
324
  }
319
325
  if (a > b) return 1;
320
326
  if (a < b) return -1;
@@ -350,6 +356,30 @@ var maxPriorityQueueTyped = (() => {
350
356
 
351
357
 
352
358
 
359
+
360
+
361
+
362
+
363
+
364
+
365
+
366
+
367
+
368
+
369
+
370
+
371
+
372
+
373
+
374
+
375
+
376
+
377
+
378
+
379
+
380
+
381
+
382
+
353
383
  * @example
354
384
  * // Track heap capacity
355
385
  * const heap = new Heap<number>();
@@ -413,6 +443,30 @@ var maxPriorityQueueTyped = (() => {
413
443
 
414
444
 
415
445
 
446
+
447
+
448
+
449
+
450
+
451
+
452
+
453
+
454
+
455
+
456
+
457
+
458
+
459
+
460
+
461
+
462
+
463
+
464
+
465
+
466
+
467
+
468
+
469
+
416
470
  * @example
417
471
  * // basic Heap creation and add operation
418
472
  * // Create a min heap (default)
@@ -446,6 +500,30 @@ var maxPriorityQueueTyped = (() => {
446
500
 
447
501
 
448
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
+
449
527
  * @example
450
528
  * // Add multiple elements
451
529
  * const heap = new Heap<number>([], { comparator: (a, b) => a - b });
@@ -481,6 +559,30 @@ var maxPriorityQueueTyped = (() => {
481
559
 
482
560
 
483
561
 
562
+
563
+
564
+
565
+
566
+
567
+
568
+
569
+
570
+
571
+
572
+
573
+
574
+
575
+
576
+
577
+
578
+
579
+
580
+
581
+
582
+
583
+
584
+
585
+
484
586
  * @example
485
587
  * // Heap with custom comparator (MaxHeap behavior)
486
588
  * interface Task {
@@ -532,6 +634,30 @@ var maxPriorityQueueTyped = (() => {
532
634
 
533
635
 
534
636
 
637
+
638
+
639
+
640
+
641
+
642
+
643
+
644
+
645
+
646
+
647
+
648
+
649
+
650
+
651
+
652
+
653
+
654
+
655
+
656
+
657
+
658
+
659
+
660
+
535
661
  * @example
536
662
  * // Heap for event processing with priority
537
663
  * interface Event {
@@ -608,6 +734,30 @@ var maxPriorityQueueTyped = (() => {
608
734
 
609
735
 
610
736
 
737
+
738
+
739
+
740
+
741
+
742
+
743
+
744
+
745
+
746
+
747
+
748
+
749
+
750
+
751
+
752
+
753
+
754
+
755
+
756
+
757
+
758
+
759
+
760
+
611
761
  * @example
612
762
  * // Check if heap is empty
613
763
  * const heap = new Heap<number>([], { comparator: (a, b) => a - b });
@@ -631,6 +781,30 @@ var maxPriorityQueueTyped = (() => {
631
781
 
632
782
 
633
783
 
784
+
785
+
786
+
787
+
788
+
789
+
790
+
791
+
792
+
793
+
794
+
795
+
796
+
797
+
798
+
799
+
800
+
801
+
802
+
803
+
804
+
805
+
806
+
807
+
634
808
  * @example
635
809
  * // Remove all elements
636
810
  * const heap = new Heap<number>([1, 2, 3], { comparator: (a, b) => a - b });
@@ -657,6 +831,30 @@ var maxPriorityQueueTyped = (() => {
657
831
  * @returns True if found.
658
832
 
659
833
 
834
+
835
+
836
+
837
+
838
+
839
+
840
+
841
+
842
+
843
+
844
+
845
+
846
+
847
+
848
+
849
+
850
+
851
+
852
+
853
+
854
+
855
+
856
+
857
+
660
858
  * @example
661
859
  * // Check element existence
662
860
  * const heap = new Heap<number>([3, 1, 2], { comparator: (a, b) => a - b });
@@ -680,6 +878,30 @@ var maxPriorityQueueTyped = (() => {
680
878
 
681
879
 
682
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
+
683
905
  * @example
684
906
  * // Remove specific element
685
907
  * const heap = new Heap<number>([3, 1, 4, 1, 5], { comparator: (a, b) => a - b });
@@ -749,6 +971,30 @@ var maxPriorityQueueTyped = (() => {
749
971
  * @returns Array of visited elements.
750
972
 
751
973
 
974
+
975
+
976
+
977
+
978
+
979
+
980
+
981
+
982
+
983
+
984
+
985
+
986
+
987
+
988
+
989
+
990
+
991
+
992
+
993
+
994
+
995
+
996
+
997
+
752
998
  * @example
753
999
  * // Depth-first traversal
754
1000
  * const heap = new Heap<number>([3, 1, 2], { comparator: (a, b) => a - b });
@@ -805,6 +1051,30 @@ var maxPriorityQueueTyped = (() => {
805
1051
 
806
1052
 
807
1053
 
1054
+
1055
+
1056
+
1057
+
1058
+
1059
+
1060
+
1061
+
1062
+
1063
+
1064
+
1065
+
1066
+
1067
+
1068
+
1069
+
1070
+
1071
+
1072
+
1073
+
1074
+
1075
+
1076
+
1077
+
808
1078
  * @example
809
1079
  * // Sort elements using heap
810
1080
  * const heap = new Heap<number>([5, 1, 3, 2, 4]);
@@ -834,6 +1104,30 @@ var maxPriorityQueueTyped = (() => {
834
1104
 
835
1105
 
836
1106
 
1107
+
1108
+
1109
+
1110
+
1111
+
1112
+
1113
+
1114
+
1115
+
1116
+
1117
+
1118
+
1119
+
1120
+
1121
+
1122
+
1123
+
1124
+
1125
+
1126
+
1127
+
1128
+
1129
+
1130
+
837
1131
  * @example
838
1132
  * // Create independent copy
839
1133
  * const heap = new Heap<number>([3, 1, 4], { comparator: (a, b) => a - b });
@@ -862,6 +1156,30 @@ var maxPriorityQueueTyped = (() => {
862
1156
 
863
1157
 
864
1158
 
1159
+
1160
+
1161
+
1162
+
1163
+
1164
+
1165
+
1166
+
1167
+
1168
+
1169
+
1170
+
1171
+
1172
+
1173
+
1174
+
1175
+
1176
+
1177
+
1178
+
1179
+
1180
+
1181
+
1182
+
865
1183
  * @example
866
1184
  * // Filter elements
867
1185
  * const heap = new Heap<number>([1, 2, 3, 4, 5], { comparator: (a, b) => a - b });
@@ -897,6 +1215,30 @@ var maxPriorityQueueTyped = (() => {
897
1215
 
898
1216
 
899
1217
 
1218
+
1219
+
1220
+
1221
+
1222
+
1223
+
1224
+
1225
+
1226
+
1227
+
1228
+
1229
+
1230
+
1231
+
1232
+
1233
+
1234
+
1235
+
1236
+
1237
+
1238
+
1239
+
1240
+
1241
+
900
1242
  * @example
901
1243
  * // Transform elements
902
1244
  * const heap = new Heap<number>([1, 2, 3], { comparator: (a, b) => a - b });
@@ -905,7 +1247,7 @@ var maxPriorityQueueTyped = (() => {
905
1247
  */
906
1248
  map(callback, options, thisArg) {
907
1249
  const { comparator, toElementFn, ...rest } = options != null ? options : {};
908
- if (!comparator) throw new TypeError(ERR.comparatorRequired("Heap.map"));
1250
+ if (!comparator) raise(TypeError, ERR.comparatorRequired("Heap.map"));
909
1251
  const out = this._createLike([], { ...rest, comparator, toElementFn });
910
1252
  let i = 0;
911
1253
  for (const x of this) {
@@ -1033,7 +1375,7 @@ var maxPriorityQueueTyped = (() => {
1033
1375
  __publicField(this, "_comparator");
1034
1376
  this.clear();
1035
1377
  this._comparator = comparator || this._defaultComparator;
1036
- if (typeof this.comparator !== "function") throw new TypeError(ERR.notAFunction("comparator", "FibonacciHeap"));
1378
+ if (typeof this.comparator !== "function") raise(TypeError, ERR.notAFunction("comparator", "FibonacciHeap"));
1037
1379
  }
1038
1380
  /**
1039
1381
  * Get the circular root list head.
@@ -1251,7 +1593,7 @@ var maxPriorityQueueTyped = (() => {
1251
1593
  super(elements, {
1252
1594
  comparator: (a, b) => {
1253
1595
  if (typeof a === "object" || typeof b === "object") {
1254
- throw new TypeError(ERR.comparatorRequired("MaxPriorityQueue"));
1596
+ raise(TypeError, ERR.comparatorRequired("MaxPriorityQueue"));
1255
1597
  }
1256
1598
  if (a < b) return 1;
1257
1599
  if (a > b) return -1;