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
@@ -3,6 +3,61 @@
3
3
  var __defProp = Object.defineProperty;
4
4
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
5
5
 
6
+ // src/common/error.ts
7
+ function raise(ErrorClass, message) {
8
+ throw new ErrorClass(message);
9
+ }
10
+ __name(raise, "raise");
11
+ var ERR = {
12
+ // Range / index
13
+ indexOutOfRange: /* @__PURE__ */ __name((index, min, max, ctx) => `${ctx ? ctx + ": " : ""}Index ${index} is out of range [${min}, ${max}].`, "indexOutOfRange"),
14
+ invalidIndex: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Index must be an integer.`, "invalidIndex"),
15
+ // Type / argument
16
+ invalidArgument: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidArgument"),
17
+ comparatorRequired: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Comparator is required for non-number/non-string/non-Date keys.`, "comparatorRequired"),
18
+ invalidKey: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidKey"),
19
+ notAFunction: /* @__PURE__ */ __name((name, ctx) => `${ctx ? ctx + ": " : ""}${name} must be a function.`, "notAFunction"),
20
+ invalidEntry: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Each entry must be a [key, value] tuple.`, "invalidEntry"),
21
+ invalidNaN: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}NaN is not a valid key.`, "invalidNaN"),
22
+ invalidDate: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Invalid Date key.`, "invalidDate"),
23
+ reduceEmpty: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Reduce of empty structure with no initial value.`, "reduceEmpty"),
24
+ callbackReturnType: /* @__PURE__ */ __name((expected, got, ctx) => `${ctx ? ctx + ": " : ""}Callback must return ${expected}; got ${got}.`, "callbackReturnType"),
25
+ // State / operation
26
+ invalidOperation: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidOperation"),
27
+ // Matrix
28
+ matrixDimensionMismatch: /* @__PURE__ */ __name((op) => `Matrix: Dimensions must be compatible for ${op}.`, "matrixDimensionMismatch"),
29
+ matrixSingular: /* @__PURE__ */ __name(() => "Matrix: Singular matrix, inverse does not exist.", "matrixSingular"),
30
+ matrixNotSquare: /* @__PURE__ */ __name(() => "Matrix: Must be square for inversion.", "matrixNotSquare"),
31
+ matrixNotRectangular: /* @__PURE__ */ __name(() => "Matrix: Must be rectangular for transposition.", "matrixNotRectangular"),
32
+ matrixRowMismatch: /* @__PURE__ */ __name((expected, got) => `Matrix: Expected row length ${expected}, but got ${got}.`, "matrixRowMismatch"),
33
+ // Order statistic
34
+ orderStatisticNotEnabled: /* @__PURE__ */ __name((method, ctx) => `${ctx ? ctx + ": " : ""}${method}() requires enableOrderStatistic: true.`, "orderStatisticNotEnabled")
35
+ };
36
+
37
+ // src/common/index.ts
38
+ var DFSOperation = /* @__PURE__ */ ((DFSOperation2) => {
39
+ DFSOperation2[DFSOperation2["VISIT"] = 0] = "VISIT";
40
+ DFSOperation2[DFSOperation2["PROCESS"] = 1] = "PROCESS";
41
+ return DFSOperation2;
42
+ })(DFSOperation || {});
43
+ var Range = class {
44
+ constructor(low, high, includeLow = true, includeHigh = true) {
45
+ this.low = low;
46
+ this.high = high;
47
+ this.includeLow = includeLow;
48
+ this.includeHigh = includeHigh;
49
+ }
50
+ static {
51
+ __name(this, "Range");
52
+ }
53
+ // Determine whether a key is within the range
54
+ isInRange(key, comparator) {
55
+ const lowCheck = this.includeLow ? comparator(key, this.low) >= 0 : comparator(key, this.low) > 0;
56
+ const highCheck = this.includeHigh ? comparator(key, this.high) <= 0 : comparator(key, this.high) < 0;
57
+ return lowCheck && highCheck;
58
+ }
59
+ };
60
+
6
61
  // src/data-structures/base/iterable-element-base.ts
7
62
  var IterableElementBase = class {
8
63
  static {
@@ -21,7 +76,7 @@ var IterableElementBase = class {
21
76
  if (options) {
22
77
  const { toElementFn } = options;
23
78
  if (typeof toElementFn === "function") this._toElementFn = toElementFn;
24
- else if (toElementFn) throw new TypeError("toElementFn must be a function type");
79
+ else if (toElementFn) raise(TypeError, "toElementFn must be a function type");
25
80
  }
26
81
  }
27
82
  /**
@@ -184,7 +239,7 @@ var IterableElementBase = class {
184
239
  acc = initialValue;
185
240
  } else {
186
241
  const first = iter.next();
187
- if (first.done) throw new TypeError("Reduce of empty structure with no initial value");
242
+ if (first.done) raise(TypeError, "Reduce of empty structure with no initial value");
188
243
  acc = first.value;
189
244
  index = 1;
190
245
  }
@@ -226,55 +281,6 @@ var IterableElementBase = class {
226
281
  }
227
282
  };
228
283
 
229
- // src/common/error.ts
230
- var ERR = {
231
- // Range / index
232
- indexOutOfRange: /* @__PURE__ */ __name((index, min, max, ctx) => `${ctx ? ctx + ": " : ""}Index ${index} is out of range [${min}, ${max}].`, "indexOutOfRange"),
233
- invalidIndex: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Index must be an integer.`, "invalidIndex"),
234
- // Type / argument
235
- invalidArgument: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidArgument"),
236
- comparatorRequired: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Comparator is required for non-number/non-string/non-Date keys.`, "comparatorRequired"),
237
- invalidKey: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidKey"),
238
- notAFunction: /* @__PURE__ */ __name((name, ctx) => `${ctx ? ctx + ": " : ""}${name} must be a function.`, "notAFunction"),
239
- invalidEntry: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Each entry must be a [key, value] tuple.`, "invalidEntry"),
240
- invalidNaN: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}NaN is not a valid key.`, "invalidNaN"),
241
- invalidDate: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Invalid Date key.`, "invalidDate"),
242
- reduceEmpty: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Reduce of empty structure with no initial value.`, "reduceEmpty"),
243
- callbackReturnType: /* @__PURE__ */ __name((expected, got, ctx) => `${ctx ? ctx + ": " : ""}Callback must return ${expected}; got ${got}.`, "callbackReturnType"),
244
- // State / operation
245
- invalidOperation: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidOperation"),
246
- // Matrix
247
- matrixDimensionMismatch: /* @__PURE__ */ __name((op) => `Matrix: Dimensions must be compatible for ${op}.`, "matrixDimensionMismatch"),
248
- matrixSingular: /* @__PURE__ */ __name(() => "Matrix: Singular matrix, inverse does not exist.", "matrixSingular"),
249
- matrixNotSquare: /* @__PURE__ */ __name(() => "Matrix: Must be square for inversion.", "matrixNotSquare"),
250
- matrixNotRectangular: /* @__PURE__ */ __name(() => "Matrix: Must be rectangular for transposition.", "matrixNotRectangular"),
251
- matrixRowMismatch: /* @__PURE__ */ __name((expected, got) => `Matrix: Expected row length ${expected}, but got ${got}.`, "matrixRowMismatch")
252
- };
253
-
254
- // src/common/index.ts
255
- var DFSOperation = /* @__PURE__ */ ((DFSOperation2) => {
256
- DFSOperation2[DFSOperation2["VISIT"] = 0] = "VISIT";
257
- DFSOperation2[DFSOperation2["PROCESS"] = 1] = "PROCESS";
258
- return DFSOperation2;
259
- })(DFSOperation || {});
260
- var Range = class {
261
- constructor(low, high, includeLow = true, includeHigh = true) {
262
- this.low = low;
263
- this.high = high;
264
- this.includeLow = includeLow;
265
- this.includeHigh = includeHigh;
266
- }
267
- static {
268
- __name(this, "Range");
269
- }
270
- // Determine whether a key is within the range
271
- isInRange(key, comparator) {
272
- const lowCheck = this.includeLow ? comparator(key, this.low) >= 0 : comparator(key, this.low) > 0;
273
- const highCheck = this.includeHigh ? comparator(key, this.high) <= 0 : comparator(key, this.high) < 0;
274
- return lowCheck && highCheck;
275
- }
276
- };
277
-
278
284
  // src/data-structures/heap/heap.ts
279
285
  var Heap = class _Heap extends IterableElementBase {
280
286
  static {
@@ -337,6 +343,9 @@ var Heap = class _Heap extends IterableElementBase {
337
343
 
338
344
 
339
345
 
346
+
347
+
348
+
340
349
 
341
350
 
342
351
 
@@ -420,6 +429,9 @@ var Heap = class _Heap extends IterableElementBase {
420
429
 
421
430
 
422
431
 
432
+
433
+
434
+
423
435
 
424
436
 
425
437
 
@@ -474,6 +486,9 @@ var Heap = class _Heap extends IterableElementBase {
474
486
 
475
487
 
476
488
 
489
+
490
+
491
+
477
492
 
478
493
 
479
494
 
@@ -530,6 +545,9 @@ var Heap = class _Heap extends IterableElementBase {
530
545
 
531
546
 
532
547
 
548
+
549
+
550
+
533
551
 
534
552
 
535
553
 
@@ -602,6 +620,9 @@ var Heap = class _Heap extends IterableElementBase {
602
620
 
603
621
 
604
622
 
623
+
624
+
625
+
605
626
 
606
627
 
607
628
 
@@ -699,6 +720,9 @@ var Heap = class _Heap extends IterableElementBase {
699
720
 
700
721
 
701
722
 
723
+
724
+
725
+
702
726
 
703
727
 
704
728
 
@@ -743,6 +767,9 @@ var Heap = class _Heap extends IterableElementBase {
743
767
 
744
768
 
745
769
 
770
+
771
+
772
+
746
773
 
747
774
 
748
775
 
@@ -790,6 +817,9 @@ var Heap = class _Heap extends IterableElementBase {
790
817
 
791
818
 
792
819
 
820
+
821
+
822
+
793
823
 
794
824
 
795
825
 
@@ -834,6 +864,9 @@ var Heap = class _Heap extends IterableElementBase {
834
864
 
835
865
 
836
866
 
867
+
868
+
869
+
837
870
 
838
871
 
839
872
 
@@ -924,6 +957,9 @@ var Heap = class _Heap extends IterableElementBase {
924
957
 
925
958
 
926
959
 
960
+
961
+
962
+
927
963
 
928
964
 
929
965
 
@@ -1001,6 +1037,9 @@ var Heap = class _Heap extends IterableElementBase {
1001
1037
 
1002
1038
 
1003
1039
 
1040
+
1041
+
1042
+
1004
1043
 
1005
1044
 
1006
1045
 
@@ -1051,6 +1090,9 @@ var Heap = class _Heap extends IterableElementBase {
1051
1090
 
1052
1091
 
1053
1092
 
1093
+
1094
+
1095
+
1054
1096
 
1055
1097
 
1056
1098
 
@@ -1100,6 +1142,9 @@ var Heap = class _Heap extends IterableElementBase {
1100
1142
 
1101
1143
 
1102
1144
 
1145
+
1146
+
1147
+
1103
1148
 
1104
1149
 
1105
1150
 
@@ -1156,6 +1201,9 @@ var Heap = class _Heap extends IterableElementBase {
1156
1201
 
1157
1202
 
1158
1203
 
1204
+
1205
+
1206
+
1159
1207
 
1160
1208
 
1161
1209
 
@@ -1168,7 +1216,7 @@ var Heap = class _Heap extends IterableElementBase {
1168
1216
  */
1169
1217
  map(callback, options, thisArg) {
1170
1218
  const { comparator, toElementFn, ...rest } = options ?? {};
1171
- if (!comparator) throw new TypeError(ERR.comparatorRequired("Heap.map"));
1219
+ if (!comparator) raise(TypeError, ERR.comparatorRequired("Heap.map"));
1172
1220
  const out = this._createLike([], { ...rest, comparator, toElementFn });
1173
1221
  let i = 0;
1174
1222
  for (const x of this) {
@@ -1195,7 +1243,7 @@ var Heap = class _Heap extends IterableElementBase {
1195
1243
  }
1196
1244
  _DEFAULT_COMPARATOR = /* @__PURE__ */ __name((a, b) => {
1197
1245
  if (typeof a === "object" || typeof b === "object") {
1198
- throw new TypeError(ERR.comparatorRequired("Heap"));
1246
+ raise(TypeError, ERR.comparatorRequired("Heap"));
1199
1247
  }
1200
1248
  if (a > b) return 1;
1201
1249
  if (a < b) return -1;
@@ -1307,7 +1355,7 @@ var FibonacciHeap = class {
1307
1355
  constructor(comparator) {
1308
1356
  this.clear();
1309
1357
  this._comparator = comparator || this._defaultComparator;
1310
- if (typeof this.comparator !== "function") throw new TypeError(ERR.notAFunction("comparator", "FibonacciHeap"));
1358
+ if (typeof this.comparator !== "function") raise(TypeError, ERR.notAFunction("comparator", "FibonacciHeap"));
1311
1359
  }
1312
1360
  _root;
1313
1361
  /**
@@ -1535,7 +1583,7 @@ var MaxPriorityQueue = class extends PriorityQueue {
1535
1583
  super(elements, {
1536
1584
  comparator: /* @__PURE__ */ __name((a, b) => {
1537
1585
  if (typeof a === "object" || typeof b === "object") {
1538
- throw new TypeError(ERR.comparatorRequired("MaxPriorityQueue"));
1586
+ raise(TypeError, ERR.comparatorRequired("MaxPriorityQueue"));
1539
1587
  }
1540
1588
  if (a < b) return 1;
1541
1589
  if (a > b) return -1;
@@ -1568,5 +1616,6 @@ exports.Heap = Heap;
1568
1616
  exports.MaxPriorityQueue = MaxPriorityQueue;
1569
1617
  exports.PriorityQueue = PriorityQueue;
1570
1618
  exports.Range = Range;
1619
+ exports.raise = raise;
1571
1620
  //# sourceMappingURL=index.cjs.map
1572
1621
  //# sourceMappingURL=index.cjs.map