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,60 @@ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { en
3
3
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
4
4
  var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
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 _Range {
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
+ // Determine whether a key is within the range
51
+ isInRange(key, comparator) {
52
+ const lowCheck = this.includeLow ? comparator(key, this.low) >= 0 : comparator(key, this.low) > 0;
53
+ const highCheck = this.includeHigh ? comparator(key, this.high) <= 0 : comparator(key, this.high) < 0;
54
+ return lowCheck && highCheck;
55
+ }
56
+ };
57
+ __name(_Range, "Range");
58
+ var Range = _Range;
59
+
6
60
  // src/data-structures/base/iterable-element-base.ts
7
61
  var _IterableElementBase = class _IterableElementBase {
8
62
  /**
@@ -25,7 +79,7 @@ var _IterableElementBase = class _IterableElementBase {
25
79
  if (options) {
26
80
  const { toElementFn } = options;
27
81
  if (typeof toElementFn === "function") this._toElementFn = toElementFn;
28
- else if (toElementFn) throw new TypeError("toElementFn must be a function type");
82
+ else if (toElementFn) raise(TypeError, "toElementFn must be a function type");
29
83
  }
30
84
  }
31
85
  /**
@@ -181,7 +235,7 @@ var _IterableElementBase = class _IterableElementBase {
181
235
  acc = initialValue;
182
236
  } else {
183
237
  const first = iter.next();
184
- if (first.done) throw new TypeError("Reduce of empty structure with no initial value");
238
+ if (first.done) raise(TypeError, "Reduce of empty structure with no initial value");
185
239
  acc = first.value;
186
240
  index = 1;
187
241
  }
@@ -225,54 +279,6 @@ var _IterableElementBase = class _IterableElementBase {
225
279
  __name(_IterableElementBase, "IterableElementBase");
226
280
  var IterableElementBase = _IterableElementBase;
227
281
 
228
- // src/common/error.ts
229
- var ERR = {
230
- // Range / index
231
- indexOutOfRange: /* @__PURE__ */ __name((index, min, max, ctx) => `${ctx ? ctx + ": " : ""}Index ${index} is out of range [${min}, ${max}].`, "indexOutOfRange"),
232
- invalidIndex: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Index must be an integer.`, "invalidIndex"),
233
- // Type / argument
234
- invalidArgument: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidArgument"),
235
- comparatorRequired: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Comparator is required for non-number/non-string/non-Date keys.`, "comparatorRequired"),
236
- invalidKey: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidKey"),
237
- notAFunction: /* @__PURE__ */ __name((name, ctx) => `${ctx ? ctx + ": " : ""}${name} must be a function.`, "notAFunction"),
238
- invalidEntry: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Each entry must be a [key, value] tuple.`, "invalidEntry"),
239
- invalidNaN: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}NaN is not a valid key.`, "invalidNaN"),
240
- invalidDate: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Invalid Date key.`, "invalidDate"),
241
- reduceEmpty: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Reduce of empty structure with no initial value.`, "reduceEmpty"),
242
- callbackReturnType: /* @__PURE__ */ __name((expected, got, ctx) => `${ctx ? ctx + ": " : ""}Callback must return ${expected}; got ${got}.`, "callbackReturnType"),
243
- // State / operation
244
- invalidOperation: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidOperation"),
245
- // Matrix
246
- matrixDimensionMismatch: /* @__PURE__ */ __name((op) => `Matrix: Dimensions must be compatible for ${op}.`, "matrixDimensionMismatch"),
247
- matrixSingular: /* @__PURE__ */ __name(() => "Matrix: Singular matrix, inverse does not exist.", "matrixSingular"),
248
- matrixNotSquare: /* @__PURE__ */ __name(() => "Matrix: Must be square for inversion.", "matrixNotSquare"),
249
- matrixNotRectangular: /* @__PURE__ */ __name(() => "Matrix: Must be rectangular for transposition.", "matrixNotRectangular"),
250
- matrixRowMismatch: /* @__PURE__ */ __name((expected, got) => `Matrix: Expected row length ${expected}, but got ${got}.`, "matrixRowMismatch")
251
- };
252
-
253
- // src/common/index.ts
254
- var DFSOperation = /* @__PURE__ */ ((DFSOperation2) => {
255
- DFSOperation2[DFSOperation2["VISIT"] = 0] = "VISIT";
256
- DFSOperation2[DFSOperation2["PROCESS"] = 1] = "PROCESS";
257
- return DFSOperation2;
258
- })(DFSOperation || {});
259
- var _Range = class _Range {
260
- constructor(low, high, includeLow = true, includeHigh = true) {
261
- this.low = low;
262
- this.high = high;
263
- this.includeLow = includeLow;
264
- this.includeHigh = includeHigh;
265
- }
266
- // Determine whether a key is within the range
267
- isInRange(key, comparator) {
268
- const lowCheck = this.includeLow ? comparator(key, this.low) >= 0 : comparator(key, this.low) > 0;
269
- const highCheck = this.includeHigh ? comparator(key, this.high) <= 0 : comparator(key, this.high) < 0;
270
- return lowCheck && highCheck;
271
- }
272
- };
273
- __name(_Range, "Range");
274
- var Range = _Range;
275
-
276
282
  // src/data-structures/heap/heap.ts
277
283
  var _Heap = class _Heap extends IterableElementBase {
278
284
  /**
@@ -288,7 +294,7 @@ var _Heap = class _Heap extends IterableElementBase {
288
294
  __publicField(this, "_elements", []);
289
295
  __publicField(this, "_DEFAULT_COMPARATOR", /* @__PURE__ */ __name((a, b) => {
290
296
  if (typeof a === "object" || typeof b === "object") {
291
- throw new TypeError(ERR.comparatorRequired("Heap"));
297
+ raise(TypeError, ERR.comparatorRequired("Heap"));
292
298
  }
293
299
  if (a > b) return 1;
294
300
  if (a < b) return -1;
@@ -341,6 +347,9 @@ var _Heap = class _Heap extends IterableElementBase {
341
347
 
342
348
 
343
349
 
350
+
351
+
352
+
344
353
 
345
354
 
346
355
 
@@ -425,6 +434,9 @@ var _Heap = class _Heap extends IterableElementBase {
425
434
 
426
435
 
427
436
 
437
+
438
+
439
+
428
440
 
429
441
 
430
442
 
@@ -479,6 +491,9 @@ var _Heap = class _Heap extends IterableElementBase {
479
491
 
480
492
 
481
493
 
494
+
495
+
496
+
482
497
 
483
498
 
484
499
 
@@ -535,6 +550,9 @@ var _Heap = class _Heap extends IterableElementBase {
535
550
 
536
551
 
537
552
 
553
+
554
+
555
+
538
556
 
539
557
 
540
558
 
@@ -607,6 +625,9 @@ var _Heap = class _Heap extends IterableElementBase {
607
625
 
608
626
 
609
627
 
628
+
629
+
630
+
610
631
 
611
632
 
612
633
 
@@ -704,6 +725,9 @@ var _Heap = class _Heap extends IterableElementBase {
704
725
 
705
726
 
706
727
 
728
+
729
+
730
+
707
731
 
708
732
 
709
733
 
@@ -748,6 +772,9 @@ var _Heap = class _Heap extends IterableElementBase {
748
772
 
749
773
 
750
774
 
775
+
776
+
777
+
751
778
 
752
779
 
753
780
 
@@ -795,6 +822,9 @@ var _Heap = class _Heap extends IterableElementBase {
795
822
 
796
823
 
797
824
 
825
+
826
+
827
+
798
828
 
799
829
 
800
830
 
@@ -839,6 +869,9 @@ var _Heap = class _Heap extends IterableElementBase {
839
869
 
840
870
 
841
871
 
872
+
873
+
874
+
842
875
 
843
876
 
844
877
 
@@ -929,6 +962,9 @@ var _Heap = class _Heap extends IterableElementBase {
929
962
 
930
963
 
931
964
 
965
+
966
+
967
+
932
968
 
933
969
 
934
970
 
@@ -1006,6 +1042,9 @@ var _Heap = class _Heap extends IterableElementBase {
1006
1042
 
1007
1043
 
1008
1044
 
1045
+
1046
+
1047
+
1009
1048
 
1010
1049
 
1011
1050
 
@@ -1056,6 +1095,9 @@ var _Heap = class _Heap extends IterableElementBase {
1056
1095
 
1057
1096
 
1058
1097
 
1098
+
1099
+
1100
+
1059
1101
 
1060
1102
 
1061
1103
 
@@ -1105,6 +1147,9 @@ var _Heap = class _Heap extends IterableElementBase {
1105
1147
 
1106
1148
 
1107
1149
 
1150
+
1151
+
1152
+
1108
1153
 
1109
1154
 
1110
1155
 
@@ -1161,6 +1206,9 @@ var _Heap = class _Heap extends IterableElementBase {
1161
1206
 
1162
1207
 
1163
1208
 
1209
+
1210
+
1211
+
1164
1212
 
1165
1213
 
1166
1214
 
@@ -1173,7 +1221,7 @@ var _Heap = class _Heap extends IterableElementBase {
1173
1221
  */
1174
1222
  map(callback, options, thisArg) {
1175
1223
  const { comparator, toElementFn, ...rest } = options != null ? options : {};
1176
- if (!comparator) throw new TypeError(ERR.comparatorRequired("Heap.map"));
1224
+ if (!comparator) raise(TypeError, ERR.comparatorRequired("Heap.map"));
1177
1225
  const out = this._createLike([], { ...rest, comparator, toElementFn });
1178
1226
  let i = 0;
1179
1227
  for (const x of this) {
@@ -1305,7 +1353,7 @@ var _FibonacciHeap = class _FibonacciHeap {
1305
1353
  __publicField(this, "_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
  /**
1311
1359
  * Get the circular root list head.
@@ -1527,7 +1575,7 @@ var _MaxPriorityQueue = class _MaxPriorityQueue extends PriorityQueue {
1527
1575
  super(elements, {
1528
1576
  comparator: /* @__PURE__ */ __name((a, b) => {
1529
1577
  if (typeof a === "object" || typeof b === "object") {
1530
- throw new TypeError(ERR.comparatorRequired("MaxPriorityQueue"));
1578
+ raise(TypeError, ERR.comparatorRequired("MaxPriorityQueue"));
1531
1579
  }
1532
1580
  if (a < b) return 1;
1533
1581
  if (a > b) return -1;
@@ -1554,6 +1602,6 @@ var MaxPriorityQueue = _MaxPriorityQueue;
1554
1602
  * @license MIT License
1555
1603
  */
1556
1604
 
1557
- export { DFSOperation, ERR, FibonacciHeap, FibonacciHeapNode, Heap, MaxPriorityQueue, PriorityQueue, Range };
1605
+ export { DFSOperation, ERR, FibonacciHeap, FibonacciHeapNode, Heap, MaxPriorityQueue, PriorityQueue, Range, raise };
1558
1606
  //# sourceMappingURL=index.mjs.map
1559
1607
  //# sourceMappingURL=index.mjs.map