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
@@ -5,6 +5,60 @@ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { en
5
5
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
6
6
  var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
7
7
 
8
+ // src/common/error.ts
9
+ function raise(ErrorClass, message) {
10
+ throw new ErrorClass(message);
11
+ }
12
+ __name(raise, "raise");
13
+ var ERR = {
14
+ // Range / index
15
+ indexOutOfRange: /* @__PURE__ */ __name((index, min, max, ctx) => `${ctx ? ctx + ": " : ""}Index ${index} is out of range [${min}, ${max}].`, "indexOutOfRange"),
16
+ invalidIndex: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Index must be an integer.`, "invalidIndex"),
17
+ // Type / argument
18
+ invalidArgument: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidArgument"),
19
+ comparatorRequired: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Comparator is required for non-number/non-string/non-Date keys.`, "comparatorRequired"),
20
+ invalidKey: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidKey"),
21
+ notAFunction: /* @__PURE__ */ __name((name, ctx) => `${ctx ? ctx + ": " : ""}${name} must be a function.`, "notAFunction"),
22
+ invalidEntry: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Each entry must be a [key, value] tuple.`, "invalidEntry"),
23
+ invalidNaN: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}NaN is not a valid key.`, "invalidNaN"),
24
+ invalidDate: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Invalid Date key.`, "invalidDate"),
25
+ reduceEmpty: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Reduce of empty structure with no initial value.`, "reduceEmpty"),
26
+ callbackReturnType: /* @__PURE__ */ __name((expected, got, ctx) => `${ctx ? ctx + ": " : ""}Callback must return ${expected}; got ${got}.`, "callbackReturnType"),
27
+ // State / operation
28
+ invalidOperation: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidOperation"),
29
+ // Matrix
30
+ matrixDimensionMismatch: /* @__PURE__ */ __name((op) => `Matrix: Dimensions must be compatible for ${op}.`, "matrixDimensionMismatch"),
31
+ matrixSingular: /* @__PURE__ */ __name(() => "Matrix: Singular matrix, inverse does not exist.", "matrixSingular"),
32
+ matrixNotSquare: /* @__PURE__ */ __name(() => "Matrix: Must be square for inversion.", "matrixNotSquare"),
33
+ matrixNotRectangular: /* @__PURE__ */ __name(() => "Matrix: Must be rectangular for transposition.", "matrixNotRectangular"),
34
+ matrixRowMismatch: /* @__PURE__ */ __name((expected, got) => `Matrix: Expected row length ${expected}, but got ${got}.`, "matrixRowMismatch"),
35
+ // Order statistic
36
+ orderStatisticNotEnabled: /* @__PURE__ */ __name((method, ctx) => `${ctx ? ctx + ": " : ""}${method}() requires enableOrderStatistic: true.`, "orderStatisticNotEnabled")
37
+ };
38
+
39
+ // src/common/index.ts
40
+ var DFSOperation = /* @__PURE__ */ ((DFSOperation2) => {
41
+ DFSOperation2[DFSOperation2["VISIT"] = 0] = "VISIT";
42
+ DFSOperation2[DFSOperation2["PROCESS"] = 1] = "PROCESS";
43
+ return DFSOperation2;
44
+ })(DFSOperation || {});
45
+ var _Range = class _Range {
46
+ constructor(low, high, includeLow = true, includeHigh = true) {
47
+ this.low = low;
48
+ this.high = high;
49
+ this.includeLow = includeLow;
50
+ this.includeHigh = includeHigh;
51
+ }
52
+ // Determine whether a key is within the range
53
+ isInRange(key, comparator) {
54
+ const lowCheck = this.includeLow ? comparator(key, this.low) >= 0 : comparator(key, this.low) > 0;
55
+ const highCheck = this.includeHigh ? comparator(key, this.high) <= 0 : comparator(key, this.high) < 0;
56
+ return lowCheck && highCheck;
57
+ }
58
+ };
59
+ __name(_Range, "Range");
60
+ var Range = _Range;
61
+
8
62
  // src/data-structures/base/iterable-element-base.ts
9
63
  var _IterableElementBase = class _IterableElementBase {
10
64
  /**
@@ -27,7 +81,7 @@ var _IterableElementBase = class _IterableElementBase {
27
81
  if (options) {
28
82
  const { toElementFn } = options;
29
83
  if (typeof toElementFn === "function") this._toElementFn = toElementFn;
30
- else if (toElementFn) throw new TypeError("toElementFn must be a function type");
84
+ else if (toElementFn) raise(TypeError, "toElementFn must be a function type");
31
85
  }
32
86
  }
33
87
  /**
@@ -183,7 +237,7 @@ var _IterableElementBase = class _IterableElementBase {
183
237
  acc = initialValue;
184
238
  } else {
185
239
  const first = iter.next();
186
- 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");
187
241
  acc = first.value;
188
242
  index = 1;
189
243
  }
@@ -227,54 +281,6 @@ var _IterableElementBase = class _IterableElementBase {
227
281
  __name(_IterableElementBase, "IterableElementBase");
228
282
  var IterableElementBase = _IterableElementBase;
229
283
 
230
- // src/common/error.ts
231
- var ERR = {
232
- // Range / index
233
- indexOutOfRange: /* @__PURE__ */ __name((index, min, max, ctx) => `${ctx ? ctx + ": " : ""}Index ${index} is out of range [${min}, ${max}].`, "indexOutOfRange"),
234
- invalidIndex: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Index must be an integer.`, "invalidIndex"),
235
- // Type / argument
236
- invalidArgument: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidArgument"),
237
- comparatorRequired: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Comparator is required for non-number/non-string/non-Date keys.`, "comparatorRequired"),
238
- invalidKey: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidKey"),
239
- notAFunction: /* @__PURE__ */ __name((name, ctx) => `${ctx ? ctx + ": " : ""}${name} must be a function.`, "notAFunction"),
240
- invalidEntry: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Each entry must be a [key, value] tuple.`, "invalidEntry"),
241
- invalidNaN: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}NaN is not a valid key.`, "invalidNaN"),
242
- invalidDate: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Invalid Date key.`, "invalidDate"),
243
- reduceEmpty: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Reduce of empty structure with no initial value.`, "reduceEmpty"),
244
- callbackReturnType: /* @__PURE__ */ __name((expected, got, ctx) => `${ctx ? ctx + ": " : ""}Callback must return ${expected}; got ${got}.`, "callbackReturnType"),
245
- // State / operation
246
- invalidOperation: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidOperation"),
247
- // Matrix
248
- matrixDimensionMismatch: /* @__PURE__ */ __name((op) => `Matrix: Dimensions must be compatible for ${op}.`, "matrixDimensionMismatch"),
249
- matrixSingular: /* @__PURE__ */ __name(() => "Matrix: Singular matrix, inverse does not exist.", "matrixSingular"),
250
- matrixNotSquare: /* @__PURE__ */ __name(() => "Matrix: Must be square for inversion.", "matrixNotSquare"),
251
- matrixNotRectangular: /* @__PURE__ */ __name(() => "Matrix: Must be rectangular for transposition.", "matrixNotRectangular"),
252
- matrixRowMismatch: /* @__PURE__ */ __name((expected, got) => `Matrix: Expected row length ${expected}, but got ${got}.`, "matrixRowMismatch")
253
- };
254
-
255
- // src/common/index.ts
256
- var DFSOperation = /* @__PURE__ */ ((DFSOperation2) => {
257
- DFSOperation2[DFSOperation2["VISIT"] = 0] = "VISIT";
258
- DFSOperation2[DFSOperation2["PROCESS"] = 1] = "PROCESS";
259
- return DFSOperation2;
260
- })(DFSOperation || {});
261
- var _Range = class _Range {
262
- constructor(low, high, includeLow = true, includeHigh = true) {
263
- this.low = low;
264
- this.high = high;
265
- this.includeLow = includeLow;
266
- this.includeHigh = includeHigh;
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
- __name(_Range, "Range");
276
- var Range = _Range;
277
-
278
284
  // src/data-structures/heap/heap.ts
279
285
  var _Heap = class _Heap extends IterableElementBase {
280
286
  /**
@@ -290,7 +296,7 @@ var _Heap = class _Heap extends IterableElementBase {
290
296
  __publicField(this, "_elements", []);
291
297
  __publicField(this, "_DEFAULT_COMPARATOR", /* @__PURE__ */ __name((a, b) => {
292
298
  if (typeof a === "object" || typeof b === "object") {
293
- throw new TypeError(ERR.comparatorRequired("Heap"));
299
+ raise(TypeError, ERR.comparatorRequired("Heap"));
294
300
  }
295
301
  if (a > b) return 1;
296
302
  if (a < b) return -1;
@@ -343,6 +349,9 @@ var _Heap = class _Heap extends IterableElementBase {
343
349
 
344
350
 
345
351
 
352
+
353
+
354
+
346
355
 
347
356
 
348
357
 
@@ -427,6 +436,9 @@ var _Heap = class _Heap extends IterableElementBase {
427
436
 
428
437
 
429
438
 
439
+
440
+
441
+
430
442
 
431
443
 
432
444
 
@@ -481,6 +493,9 @@ var _Heap = class _Heap extends IterableElementBase {
481
493
 
482
494
 
483
495
 
496
+
497
+
498
+
484
499
 
485
500
 
486
501
 
@@ -537,6 +552,9 @@ var _Heap = class _Heap extends IterableElementBase {
537
552
 
538
553
 
539
554
 
555
+
556
+
557
+
540
558
 
541
559
 
542
560
 
@@ -609,6 +627,9 @@ var _Heap = class _Heap extends IterableElementBase {
609
627
 
610
628
 
611
629
 
630
+
631
+
632
+
612
633
 
613
634
 
614
635
 
@@ -706,6 +727,9 @@ var _Heap = class _Heap extends IterableElementBase {
706
727
 
707
728
 
708
729
 
730
+
731
+
732
+
709
733
 
710
734
 
711
735
 
@@ -750,6 +774,9 @@ var _Heap = class _Heap extends IterableElementBase {
750
774
 
751
775
 
752
776
 
777
+
778
+
779
+
753
780
 
754
781
 
755
782
 
@@ -797,6 +824,9 @@ var _Heap = class _Heap extends IterableElementBase {
797
824
 
798
825
 
799
826
 
827
+
828
+
829
+
800
830
 
801
831
 
802
832
 
@@ -841,6 +871,9 @@ var _Heap = class _Heap extends IterableElementBase {
841
871
 
842
872
 
843
873
 
874
+
875
+
876
+
844
877
 
845
878
 
846
879
 
@@ -931,6 +964,9 @@ var _Heap = class _Heap extends IterableElementBase {
931
964
 
932
965
 
933
966
 
967
+
968
+
969
+
934
970
 
935
971
 
936
972
 
@@ -1008,6 +1044,9 @@ var _Heap = class _Heap extends IterableElementBase {
1008
1044
 
1009
1045
 
1010
1046
 
1047
+
1048
+
1049
+
1011
1050
 
1012
1051
 
1013
1052
 
@@ -1058,6 +1097,9 @@ var _Heap = class _Heap extends IterableElementBase {
1058
1097
 
1059
1098
 
1060
1099
 
1100
+
1101
+
1102
+
1061
1103
 
1062
1104
 
1063
1105
 
@@ -1107,6 +1149,9 @@ var _Heap = class _Heap extends IterableElementBase {
1107
1149
 
1108
1150
 
1109
1151
 
1152
+
1153
+
1154
+
1110
1155
 
1111
1156
 
1112
1157
 
@@ -1163,6 +1208,9 @@ var _Heap = class _Heap extends IterableElementBase {
1163
1208
 
1164
1209
 
1165
1210
 
1211
+
1212
+
1213
+
1166
1214
 
1167
1215
 
1168
1216
 
@@ -1175,7 +1223,7 @@ var _Heap = class _Heap extends IterableElementBase {
1175
1223
  */
1176
1224
  map(callback, options, thisArg) {
1177
1225
  const { comparator, toElementFn, ...rest } = options != null ? options : {};
1178
- if (!comparator) throw new TypeError(ERR.comparatorRequired("Heap.map"));
1226
+ if (!comparator) raise(TypeError, ERR.comparatorRequired("Heap.map"));
1179
1227
  const out = this._createLike([], { ...rest, comparator, toElementFn });
1180
1228
  let i = 0;
1181
1229
  for (const x of this) {
@@ -1307,7 +1355,7 @@ var _FibonacciHeap = class _FibonacciHeap {
1307
1355
  __publicField(this, "_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
  /**
1313
1361
  * Get the circular root list head.
@@ -1529,7 +1577,7 @@ var _MaxPriorityQueue = class _MaxPriorityQueue extends PriorityQueue {
1529
1577
  super(elements, {
1530
1578
  comparator: /* @__PURE__ */ __name((a, b) => {
1531
1579
  if (typeof a === "object" || typeof b === "object") {
1532
- throw new TypeError(ERR.comparatorRequired("MaxPriorityQueue"));
1580
+ raise(TypeError, ERR.comparatorRequired("MaxPriorityQueue"));
1533
1581
  }
1534
1582
  if (a < b) return 1;
1535
1583
  if (a > b) return -1;
@@ -1564,5 +1612,6 @@ exports.Heap = Heap;
1564
1612
  exports.MaxPriorityQueue = MaxPriorityQueue;
1565
1613
  exports.PriorityQueue = PriorityQueue;
1566
1614
  exports.Range = Range;
1615
+ exports.raise = raise;
1567
1616
  //# sourceMappingURL=index.cjs.map
1568
1617
  //# sourceMappingURL=index.cjs.map