max-priority-queue-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 +104 -55
  2. package/dist/cjs/index.cjs.map +1 -1
  3. package/dist/cjs-legacy/index.cjs +103 -54
  4. package/dist/cjs-legacy/index.cjs.map +1 -1
  5. package/dist/esm/index.mjs +104 -56
  6. package/dist/esm/index.mjs.map +1 -1
  7. package/dist/esm-legacy/index.mjs +103 -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/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/max-priority-queue-typed.js +101 -53
  38. package/dist/umd/max-priority-queue-typed.js.map +1 -1
  39. package/dist/umd/max-priority-queue-typed.min.js +1 -1
  40. package/dist/umd/max-priority-queue-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
@@ -1,6 +1,61 @@
1
1
  var __defProp = Object.defineProperty;
2
2
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
3
 
4
+ // src/common/error.ts
5
+ function raise(ErrorClass, message) {
6
+ throw new ErrorClass(message);
7
+ }
8
+ __name(raise, "raise");
9
+ var ERR = {
10
+ // Range / index
11
+ indexOutOfRange: /* @__PURE__ */ __name((index, min, max, ctx) => `${ctx ? ctx + ": " : ""}Index ${index} is out of range [${min}, ${max}].`, "indexOutOfRange"),
12
+ invalidIndex: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Index must be an integer.`, "invalidIndex"),
13
+ // Type / argument
14
+ invalidArgument: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidArgument"),
15
+ comparatorRequired: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Comparator is required for non-number/non-string/non-Date keys.`, "comparatorRequired"),
16
+ invalidKey: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidKey"),
17
+ notAFunction: /* @__PURE__ */ __name((name, ctx) => `${ctx ? ctx + ": " : ""}${name} must be a function.`, "notAFunction"),
18
+ invalidEntry: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Each entry must be a [key, value] tuple.`, "invalidEntry"),
19
+ invalidNaN: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}NaN is not a valid key.`, "invalidNaN"),
20
+ invalidDate: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Invalid Date key.`, "invalidDate"),
21
+ reduceEmpty: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Reduce of empty structure with no initial value.`, "reduceEmpty"),
22
+ callbackReturnType: /* @__PURE__ */ __name((expected, got, ctx) => `${ctx ? ctx + ": " : ""}Callback must return ${expected}; got ${got}.`, "callbackReturnType"),
23
+ // State / operation
24
+ invalidOperation: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidOperation"),
25
+ // Matrix
26
+ matrixDimensionMismatch: /* @__PURE__ */ __name((op) => `Matrix: Dimensions must be compatible for ${op}.`, "matrixDimensionMismatch"),
27
+ matrixSingular: /* @__PURE__ */ __name(() => "Matrix: Singular matrix, inverse does not exist.", "matrixSingular"),
28
+ matrixNotSquare: /* @__PURE__ */ __name(() => "Matrix: Must be square for inversion.", "matrixNotSquare"),
29
+ matrixNotRectangular: /* @__PURE__ */ __name(() => "Matrix: Must be rectangular for transposition.", "matrixNotRectangular"),
30
+ matrixRowMismatch: /* @__PURE__ */ __name((expected, got) => `Matrix: Expected row length ${expected}, but got ${got}.`, "matrixRowMismatch"),
31
+ // Order statistic
32
+ orderStatisticNotEnabled: /* @__PURE__ */ __name((method, ctx) => `${ctx ? ctx + ": " : ""}${method}() requires enableOrderStatistic: true.`, "orderStatisticNotEnabled")
33
+ };
34
+
35
+ // src/common/index.ts
36
+ var DFSOperation = /* @__PURE__ */ ((DFSOperation2) => {
37
+ DFSOperation2[DFSOperation2["VISIT"] = 0] = "VISIT";
38
+ DFSOperation2[DFSOperation2["PROCESS"] = 1] = "PROCESS";
39
+ return DFSOperation2;
40
+ })(DFSOperation || {});
41
+ var Range = class {
42
+ constructor(low, high, includeLow = true, includeHigh = true) {
43
+ this.low = low;
44
+ this.high = high;
45
+ this.includeLow = includeLow;
46
+ this.includeHigh = includeHigh;
47
+ }
48
+ static {
49
+ __name(this, "Range");
50
+ }
51
+ // Determine whether a key is within the range
52
+ isInRange(key, comparator) {
53
+ const lowCheck = this.includeLow ? comparator(key, this.low) >= 0 : comparator(key, this.low) > 0;
54
+ const highCheck = this.includeHigh ? comparator(key, this.high) <= 0 : comparator(key, this.high) < 0;
55
+ return lowCheck && highCheck;
56
+ }
57
+ };
58
+
4
59
  // src/data-structures/base/iterable-element-base.ts
5
60
  var IterableElementBase = class {
6
61
  static {
@@ -19,7 +74,7 @@ var IterableElementBase = class {
19
74
  if (options) {
20
75
  const { toElementFn } = options;
21
76
  if (typeof toElementFn === "function") this._toElementFn = toElementFn;
22
- else if (toElementFn) throw new TypeError("toElementFn must be a function type");
77
+ else if (toElementFn) raise(TypeError, "toElementFn must be a function type");
23
78
  }
24
79
  }
25
80
  /**
@@ -182,7 +237,7 @@ var IterableElementBase = class {
182
237
  acc = initialValue;
183
238
  } else {
184
239
  const first = iter.next();
185
- if (first.done) throw new TypeError("Reduce of empty structure with no initial value");
240
+ if (first.done) raise(TypeError, "Reduce of empty structure with no initial value");
186
241
  acc = first.value;
187
242
  index = 1;
188
243
  }
@@ -224,55 +279,6 @@ var IterableElementBase = class {
224
279
  }
225
280
  };
226
281
 
227
- // src/common/error.ts
228
- var ERR = {
229
- // Range / index
230
- indexOutOfRange: /* @__PURE__ */ __name((index, min, max, ctx) => `${ctx ? ctx + ": " : ""}Index ${index} is out of range [${min}, ${max}].`, "indexOutOfRange"),
231
- invalidIndex: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Index must be an integer.`, "invalidIndex"),
232
- // Type / argument
233
- invalidArgument: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidArgument"),
234
- comparatorRequired: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Comparator is required for non-number/non-string/non-Date keys.`, "comparatorRequired"),
235
- invalidKey: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidKey"),
236
- notAFunction: /* @__PURE__ */ __name((name, ctx) => `${ctx ? ctx + ": " : ""}${name} must be a function.`, "notAFunction"),
237
- invalidEntry: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Each entry must be a [key, value] tuple.`, "invalidEntry"),
238
- invalidNaN: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}NaN is not a valid key.`, "invalidNaN"),
239
- invalidDate: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Invalid Date key.`, "invalidDate"),
240
- reduceEmpty: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Reduce of empty structure with no initial value.`, "reduceEmpty"),
241
- callbackReturnType: /* @__PURE__ */ __name((expected, got, ctx) => `${ctx ? ctx + ": " : ""}Callback must return ${expected}; got ${got}.`, "callbackReturnType"),
242
- // State / operation
243
- invalidOperation: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidOperation"),
244
- // Matrix
245
- matrixDimensionMismatch: /* @__PURE__ */ __name((op) => `Matrix: Dimensions must be compatible for ${op}.`, "matrixDimensionMismatch"),
246
- matrixSingular: /* @__PURE__ */ __name(() => "Matrix: Singular matrix, inverse does not exist.", "matrixSingular"),
247
- matrixNotSquare: /* @__PURE__ */ __name(() => "Matrix: Must be square for inversion.", "matrixNotSquare"),
248
- matrixNotRectangular: /* @__PURE__ */ __name(() => "Matrix: Must be rectangular for transposition.", "matrixNotRectangular"),
249
- matrixRowMismatch: /* @__PURE__ */ __name((expected, got) => `Matrix: Expected row length ${expected}, but got ${got}.`, "matrixRowMismatch")
250
- };
251
-
252
- // src/common/index.ts
253
- var DFSOperation = /* @__PURE__ */ ((DFSOperation2) => {
254
- DFSOperation2[DFSOperation2["VISIT"] = 0] = "VISIT";
255
- DFSOperation2[DFSOperation2["PROCESS"] = 1] = "PROCESS";
256
- return DFSOperation2;
257
- })(DFSOperation || {});
258
- var Range = class {
259
- constructor(low, high, includeLow = true, includeHigh = true) {
260
- this.low = low;
261
- this.high = high;
262
- this.includeLow = includeLow;
263
- this.includeHigh = includeHigh;
264
- }
265
- static {
266
- __name(this, "Range");
267
- }
268
- // Determine whether a key is within the range
269
- isInRange(key, comparator) {
270
- const lowCheck = this.includeLow ? comparator(key, this.low) >= 0 : comparator(key, this.low) > 0;
271
- const highCheck = this.includeHigh ? comparator(key, this.high) <= 0 : comparator(key, this.high) < 0;
272
- return lowCheck && highCheck;
273
- }
274
- };
275
-
276
282
  // src/data-structures/heap/heap.ts
277
283
  var Heap = class _Heap extends IterableElementBase {
278
284
  static {
@@ -335,6 +341,9 @@ var Heap = class _Heap extends IterableElementBase {
335
341
 
336
342
 
337
343
 
344
+
345
+
346
+
338
347
 
339
348
 
340
349
 
@@ -418,6 +427,9 @@ var Heap = class _Heap extends IterableElementBase {
418
427
 
419
428
 
420
429
 
430
+
431
+
432
+
421
433
 
422
434
 
423
435
 
@@ -472,6 +484,9 @@ var Heap = class _Heap extends IterableElementBase {
472
484
 
473
485
 
474
486
 
487
+
488
+
489
+
475
490
 
476
491
 
477
492
 
@@ -528,6 +543,9 @@ var Heap = class _Heap extends IterableElementBase {
528
543
 
529
544
 
530
545
 
546
+
547
+
548
+
531
549
 
532
550
 
533
551
 
@@ -600,6 +618,9 @@ var Heap = class _Heap extends IterableElementBase {
600
618
 
601
619
 
602
620
 
621
+
622
+
623
+
603
624
 
604
625
 
605
626
 
@@ -697,6 +718,9 @@ var Heap = class _Heap extends IterableElementBase {
697
718
 
698
719
 
699
720
 
721
+
722
+
723
+
700
724
 
701
725
 
702
726
 
@@ -741,6 +765,9 @@ var Heap = class _Heap extends IterableElementBase {
741
765
 
742
766
 
743
767
 
768
+
769
+
770
+
744
771
 
745
772
 
746
773
 
@@ -788,6 +815,9 @@ var Heap = class _Heap extends IterableElementBase {
788
815
 
789
816
 
790
817
 
818
+
819
+
820
+
791
821
 
792
822
 
793
823
 
@@ -832,6 +862,9 @@ var Heap = class _Heap extends IterableElementBase {
832
862
 
833
863
 
834
864
 
865
+
866
+
867
+
835
868
 
836
869
 
837
870
 
@@ -922,6 +955,9 @@ var Heap = class _Heap extends IterableElementBase {
922
955
 
923
956
 
924
957
 
958
+
959
+
960
+
925
961
 
926
962
 
927
963
 
@@ -999,6 +1035,9 @@ var Heap = class _Heap extends IterableElementBase {
999
1035
 
1000
1036
 
1001
1037
 
1038
+
1039
+
1040
+
1002
1041
 
1003
1042
 
1004
1043
 
@@ -1049,6 +1088,9 @@ var Heap = class _Heap extends IterableElementBase {
1049
1088
 
1050
1089
 
1051
1090
 
1091
+
1092
+
1093
+
1052
1094
 
1053
1095
 
1054
1096
 
@@ -1098,6 +1140,9 @@ var Heap = class _Heap extends IterableElementBase {
1098
1140
 
1099
1141
 
1100
1142
 
1143
+
1144
+
1145
+
1101
1146
 
1102
1147
 
1103
1148
 
@@ -1154,6 +1199,9 @@ var Heap = class _Heap extends IterableElementBase {
1154
1199
 
1155
1200
 
1156
1201
 
1202
+
1203
+
1204
+
1157
1205
 
1158
1206
 
1159
1207
 
@@ -1166,7 +1214,7 @@ var Heap = class _Heap extends IterableElementBase {
1166
1214
  */
1167
1215
  map(callback, options, thisArg) {
1168
1216
  const { comparator, toElementFn, ...rest } = options ?? {};
1169
- if (!comparator) throw new TypeError(ERR.comparatorRequired("Heap.map"));
1217
+ if (!comparator) raise(TypeError, ERR.comparatorRequired("Heap.map"));
1170
1218
  const out = this._createLike([], { ...rest, comparator, toElementFn });
1171
1219
  let i = 0;
1172
1220
  for (const x of this) {
@@ -1193,7 +1241,7 @@ var Heap = class _Heap extends IterableElementBase {
1193
1241
  }
1194
1242
  _DEFAULT_COMPARATOR = /* @__PURE__ */ __name((a, b) => {
1195
1243
  if (typeof a === "object" || typeof b === "object") {
1196
- throw new TypeError(ERR.comparatorRequired("Heap"));
1244
+ raise(TypeError, ERR.comparatorRequired("Heap"));
1197
1245
  }
1198
1246
  if (a > b) return 1;
1199
1247
  if (a < b) return -1;
@@ -1305,7 +1353,7 @@ var FibonacciHeap = class {
1305
1353
  constructor(comparator) {
1306
1354
  this.clear();
1307
1355
  this._comparator = comparator || this._defaultComparator;
1308
- if (typeof this.comparator !== "function") throw new TypeError(ERR.notAFunction("comparator", "FibonacciHeap"));
1356
+ if (typeof this.comparator !== "function") raise(TypeError, ERR.notAFunction("comparator", "FibonacciHeap"));
1309
1357
  }
1310
1358
  _root;
1311
1359
  /**
@@ -1533,7 +1581,7 @@ var MaxPriorityQueue = class extends PriorityQueue {
1533
1581
  super(elements, {
1534
1582
  comparator: /* @__PURE__ */ __name((a, b) => {
1535
1583
  if (typeof a === "object" || typeof b === "object") {
1536
- throw new TypeError(ERR.comparatorRequired("MaxPriorityQueue"));
1584
+ raise(TypeError, ERR.comparatorRequired("MaxPriorityQueue"));
1537
1585
  }
1538
1586
  if (a < b) return 1;
1539
1587
  if (a > b) return -1;
@@ -1558,6 +1606,6 @@ var MaxPriorityQueue = class extends PriorityQueue {
1558
1606
  * @license MIT License
1559
1607
  */
1560
1608
 
1561
- export { DFSOperation, ERR, FibonacciHeap, FibonacciHeapNode, Heap, MaxPriorityQueue, PriorityQueue, Range };
1609
+ export { DFSOperation, ERR, FibonacciHeap, FibonacciHeapNode, Heap, MaxPriorityQueue, PriorityQueue, Range, raise };
1562
1610
  //# sourceMappingURL=index.mjs.map
1563
1611
  //# sourceMappingURL=index.mjs.map