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
@@ -8,6 +8,11 @@ export interface TreeMapOptions<K, V, R = [K, V]> {
8
8
  * - `false`: store values on tree nodes (Node Mode).
9
9
  */
10
10
  isMapMode?: boolean;
11
+ /**
12
+ * Enable order-statistic operations (select, rank, rangeByRank).
13
+ * When true, subtree counts are maintained on every node.
14
+ */
15
+ enableOrderStatistic?: boolean;
11
16
  /**
12
17
  * Transform raw elements into `[key, value]` entries.
13
18
  * When provided, the constructor accepts `Iterable<R>` instead of `Iterable<[K, V]>`.
@@ -8,6 +8,10 @@ export interface TreeMultiSetOptions<K, R = K> {
8
8
  * - `false`: Node Mode.
9
9
  */
10
10
  isMapMode?: boolean;
11
+ /**
12
+ * Enable order-statistic operations (select, rank, rangeByRank).
13
+ */
14
+ enableOrderStatistic?: boolean;
11
15
  /**
12
16
  * Transform raw elements into keys.
13
17
  * When provided, the constructor accepts `Iterable<R>` instead of `Iterable<K>`.
@@ -8,6 +8,10 @@ export interface TreeSetOptions<K, R = K> {
8
8
  * - `false`: store values on tree nodes (Node Mode).
9
9
  */
10
10
  isMapMode?: boolean;
11
+ /**
12
+ * Enable order-statistic operations (select, rank, rangeByRank).
13
+ */
14
+ enableOrderStatistic?: boolean;
11
15
  /**
12
16
  * Transform raw elements into keys.
13
17
  * When provided, the constructor accepts `Iterable<R>` instead of `Iterable<K>`.
@@ -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;
@@ -367,6 +373,9 @@ var maxPriorityQueueTyped = (() => {
367
373
 
368
374
 
369
375
 
376
+
377
+
378
+
370
379
 
371
380
 
372
381
 
@@ -451,6 +460,9 @@ var maxPriorityQueueTyped = (() => {
451
460
 
452
461
 
453
462
 
463
+
464
+
465
+
454
466
 
455
467
 
456
468
 
@@ -505,6 +517,9 @@ var maxPriorityQueueTyped = (() => {
505
517
 
506
518
 
507
519
 
520
+
521
+
522
+
508
523
 
509
524
 
510
525
 
@@ -561,6 +576,9 @@ var maxPriorityQueueTyped = (() => {
561
576
 
562
577
 
563
578
 
579
+
580
+
581
+
564
582
 
565
583
 
566
584
 
@@ -633,6 +651,9 @@ var maxPriorityQueueTyped = (() => {
633
651
 
634
652
 
635
653
 
654
+
655
+
656
+
636
657
 
637
658
 
638
659
 
@@ -730,6 +751,9 @@ var maxPriorityQueueTyped = (() => {
730
751
 
731
752
 
732
753
 
754
+
755
+
756
+
733
757
 
734
758
 
735
759
 
@@ -774,6 +798,9 @@ var maxPriorityQueueTyped = (() => {
774
798
 
775
799
 
776
800
 
801
+
802
+
803
+
777
804
 
778
805
 
779
806
 
@@ -821,6 +848,9 @@ var maxPriorityQueueTyped = (() => {
821
848
 
822
849
 
823
850
 
851
+
852
+
853
+
824
854
 
825
855
 
826
856
 
@@ -865,6 +895,9 @@ var maxPriorityQueueTyped = (() => {
865
895
 
866
896
 
867
897
 
898
+
899
+
900
+
868
901
 
869
902
 
870
903
 
@@ -955,6 +988,9 @@ var maxPriorityQueueTyped = (() => {
955
988
 
956
989
 
957
990
 
991
+
992
+
993
+
958
994
 
959
995
 
960
996
 
@@ -1032,6 +1068,9 @@ var maxPriorityQueueTyped = (() => {
1032
1068
 
1033
1069
 
1034
1070
 
1071
+
1072
+
1073
+
1035
1074
 
1036
1075
 
1037
1076
 
@@ -1082,6 +1121,9 @@ var maxPriorityQueueTyped = (() => {
1082
1121
 
1083
1122
 
1084
1123
 
1124
+
1125
+
1126
+
1085
1127
 
1086
1128
 
1087
1129
 
@@ -1131,6 +1173,9 @@ var maxPriorityQueueTyped = (() => {
1131
1173
 
1132
1174
 
1133
1175
 
1176
+
1177
+
1178
+
1134
1179
 
1135
1180
 
1136
1181
 
@@ -1187,6 +1232,9 @@ var maxPriorityQueueTyped = (() => {
1187
1232
 
1188
1233
 
1189
1234
 
1235
+
1236
+
1237
+
1190
1238
 
1191
1239
 
1192
1240
 
@@ -1199,7 +1247,7 @@ var maxPriorityQueueTyped = (() => {
1199
1247
  */
1200
1248
  map(callback, options, thisArg) {
1201
1249
  const { comparator, toElementFn, ...rest } = options != null ? options : {};
1202
- if (!comparator) throw new TypeError(ERR.comparatorRequired("Heap.map"));
1250
+ if (!comparator) raise(TypeError, ERR.comparatorRequired("Heap.map"));
1203
1251
  const out = this._createLike([], { ...rest, comparator, toElementFn });
1204
1252
  let i = 0;
1205
1253
  for (const x of this) {
@@ -1327,7 +1375,7 @@ var maxPriorityQueueTyped = (() => {
1327
1375
  __publicField(this, "_comparator");
1328
1376
  this.clear();
1329
1377
  this._comparator = comparator || this._defaultComparator;
1330
- if (typeof this.comparator !== "function") throw new TypeError(ERR.notAFunction("comparator", "FibonacciHeap"));
1378
+ if (typeof this.comparator !== "function") raise(TypeError, ERR.notAFunction("comparator", "FibonacciHeap"));
1331
1379
  }
1332
1380
  /**
1333
1381
  * Get the circular root list head.
@@ -1545,7 +1593,7 @@ var maxPriorityQueueTyped = (() => {
1545
1593
  super(elements, {
1546
1594
  comparator: (a, b) => {
1547
1595
  if (typeof a === "object" || typeof b === "object") {
1548
- throw new TypeError(ERR.comparatorRequired("MaxPriorityQueue"));
1596
+ raise(TypeError, ERR.comparatorRequired("MaxPriorityQueue"));
1549
1597
  }
1550
1598
  if (a < b) return 1;
1551
1599
  if (a > b) return -1;