stack-typed 2.4.5 → 2.5.1

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 (94) hide show
  1. package/README.md +6 -36
  2. package/dist/cjs/index.cjs +480 -100
  3. package/dist/cjs/index.cjs.map +1 -1
  4. package/dist/cjs-legacy/index.cjs +479 -99
  5. package/dist/cjs-legacy/index.cjs.map +1 -1
  6. package/dist/esm/index.mjs +480 -100
  7. package/dist/esm/index.mjs.map +1 -1
  8. package/dist/esm-legacy/index.mjs +479 -99
  9. package/dist/esm-legacy/index.mjs.map +1 -1
  10. package/dist/types/data-structures/base/index.d.ts +1 -0
  11. package/dist/types/data-structures/base/iterable-element-base.d.ts +1 -1
  12. package/dist/types/data-structures/base/iterable-entry-base.d.ts +8 -8
  13. package/dist/types/data-structures/base/linear-base.d.ts +3 -3
  14. package/dist/types/data-structures/binary-tree/avl-tree.d.ts +380 -51
  15. package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +487 -147
  16. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +956 -80
  17. package/dist/types/data-structures/binary-tree/bst.d.ts +816 -29
  18. package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +610 -31
  19. package/dist/types/data-structures/binary-tree/segment-tree.d.ts +326 -135
  20. package/dist/types/data-structures/binary-tree/tree-map.d.ts +3781 -6
  21. package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +3607 -201
  22. package/dist/types/data-structures/binary-tree/tree-multi-set.d.ts +2874 -65
  23. package/dist/types/data-structures/binary-tree/tree-set.d.ts +3528 -6
  24. package/dist/types/data-structures/graph/abstract-graph.d.ts +4 -4
  25. package/dist/types/data-structures/graph/directed-graph.d.ts +429 -47
  26. package/dist/types/data-structures/graph/map-graph.d.ts +59 -1
  27. package/dist/types/data-structures/graph/undirected-graph.d.ts +393 -59
  28. package/dist/types/data-structures/hash/hash-map.d.ts +473 -89
  29. package/dist/types/data-structures/heap/heap.d.ts +581 -99
  30. package/dist/types/data-structures/heap/max-heap.d.ts +46 -0
  31. package/dist/types/data-structures/heap/min-heap.d.ts +59 -0
  32. package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +646 -47
  33. package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +596 -68
  34. package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +793 -12
  35. package/dist/types/data-structures/matrix/matrix.d.ts +499 -0
  36. package/dist/types/data-structures/priority-queue/max-priority-queue.d.ts +57 -0
  37. package/dist/types/data-structures/priority-queue/min-priority-queue.d.ts +60 -0
  38. package/dist/types/data-structures/priority-queue/priority-queue.d.ts +60 -0
  39. package/dist/types/data-structures/queue/deque.d.ts +593 -71
  40. package/dist/types/data-structures/queue/queue.d.ts +463 -42
  41. package/dist/types/data-structures/stack/stack.d.ts +384 -32
  42. package/dist/types/data-structures/trie/trie.d.ts +470 -48
  43. package/dist/types/interfaces/graph.d.ts +1 -1
  44. package/dist/types/types/common.d.ts +2 -2
  45. package/dist/types/types/data-structures/binary-tree/segment-tree.d.ts +1 -1
  46. package/dist/types/types/data-structures/heap/heap.d.ts +1 -0
  47. package/dist/types/types/data-structures/linked-list/skip-linked-list.d.ts +1 -4
  48. package/dist/types/types/data-structures/priority-queue/priority-queue.d.ts +1 -0
  49. package/dist/types/types/utils/validate-type.d.ts +4 -4
  50. package/dist/umd/stack-typed.js +477 -97
  51. package/dist/umd/stack-typed.js.map +1 -1
  52. package/dist/umd/stack-typed.min.js +1 -1
  53. package/dist/umd/stack-typed.min.js.map +1 -1
  54. package/package.json +2 -2
  55. package/src/data-structures/base/index.ts +1 -0
  56. package/src/data-structures/base/iterable-element-base.ts +4 -5
  57. package/src/data-structures/base/iterable-entry-base.ts +8 -8
  58. package/src/data-structures/base/linear-base.ts +3 -3
  59. package/src/data-structures/binary-tree/avl-tree.ts +386 -51
  60. package/src/data-structures/binary-tree/binary-indexed-tree.ts +596 -247
  61. package/src/data-structures/binary-tree/binary-tree.ts +956 -81
  62. package/src/data-structures/binary-tree/bst.ts +840 -35
  63. package/src/data-structures/binary-tree/red-black-tree.ts +689 -97
  64. package/src/data-structures/binary-tree/segment-tree.ts +498 -249
  65. package/src/data-structures/binary-tree/tree-map.ts +3784 -7
  66. package/src/data-structures/binary-tree/tree-multi-map.ts +3614 -211
  67. package/src/data-structures/binary-tree/tree-multi-set.ts +2874 -65
  68. package/src/data-structures/binary-tree/tree-set.ts +3531 -10
  69. package/src/data-structures/graph/abstract-graph.ts +4 -4
  70. package/src/data-structures/graph/directed-graph.ts +429 -47
  71. package/src/data-structures/graph/map-graph.ts +59 -1
  72. package/src/data-structures/graph/undirected-graph.ts +393 -59
  73. package/src/data-structures/hash/hash-map.ts +476 -92
  74. package/src/data-structures/heap/heap.ts +581 -99
  75. package/src/data-structures/heap/max-heap.ts +46 -0
  76. package/src/data-structures/heap/min-heap.ts +59 -0
  77. package/src/data-structures/linked-list/doubly-linked-list.ts +646 -47
  78. package/src/data-structures/linked-list/singly-linked-list.ts +596 -68
  79. package/src/data-structures/linked-list/skip-linked-list.ts +1067 -90
  80. package/src/data-structures/matrix/matrix.ts +584 -12
  81. package/src/data-structures/priority-queue/max-priority-queue.ts +57 -0
  82. package/src/data-structures/priority-queue/min-priority-queue.ts +60 -0
  83. package/src/data-structures/priority-queue/priority-queue.ts +60 -0
  84. package/src/data-structures/queue/deque.ts +592 -70
  85. package/src/data-structures/queue/queue.ts +463 -42
  86. package/src/data-structures/stack/stack.ts +384 -32
  87. package/src/data-structures/trie/trie.ts +470 -48
  88. package/src/interfaces/graph.ts +1 -1
  89. package/src/types/common.ts +2 -2
  90. package/src/types/data-structures/binary-tree/segment-tree.ts +1 -1
  91. package/src/types/data-structures/heap/heap.ts +1 -0
  92. package/src/types/data-structures/linked-list/skip-linked-list.ts +2 -1
  93. package/src/types/data-structures/priority-queue/priority-queue.ts +1 -0
  94. package/src/types/utils/validate-type.ts +4 -4
@@ -5,54 +5,6 @@ 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
- 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
- };
32
-
33
- // src/common/index.ts
34
- var DFSOperation = /* @__PURE__ */ ((DFSOperation2) => {
35
- DFSOperation2[DFSOperation2["VISIT"] = 0] = "VISIT";
36
- DFSOperation2[DFSOperation2["PROCESS"] = 1] = "PROCESS";
37
- return DFSOperation2;
38
- })(DFSOperation || {});
39
- var _Range = class _Range {
40
- constructor(low, high, includeLow = true, includeHigh = true) {
41
- this.low = low;
42
- this.high = high;
43
- this.includeLow = includeLow;
44
- this.includeHigh = includeHigh;
45
- }
46
- // Determine whether a key is within the range
47
- isInRange(key, comparator) {
48
- const lowCheck = this.includeLow ? comparator(key, this.low) >= 0 : comparator(key, this.low) > 0;
49
- const highCheck = this.includeHigh ? comparator(key, this.high) <= 0 : comparator(key, this.high) < 0;
50
- return lowCheck && highCheck;
51
- }
52
- };
53
- __name(_Range, "Range");
54
- var Range = _Range;
55
-
56
8
  // src/data-structures/base/iterable-element-base.ts
57
9
  var _IterableElementBase = class _IterableElementBase {
58
10
  /**
@@ -75,7 +27,7 @@ var _IterableElementBase = class _IterableElementBase {
75
27
  if (options) {
76
28
  const { toElementFn } = options;
77
29
  if (typeof toElementFn === "function") this._toElementFn = toElementFn;
78
- else if (toElementFn) throw new TypeError(ERR.notAFunction("toElementFn"));
30
+ else if (toElementFn) throw new TypeError("toElementFn must be a function type");
79
31
  }
80
32
  }
81
33
  /**
@@ -231,7 +183,7 @@ var _IterableElementBase = class _IterableElementBase {
231
183
  acc = initialValue;
232
184
  } else {
233
185
  const first = iter.next();
234
- if (first.done) throw new TypeError(ERR.reduceEmpty());
186
+ if (first.done) throw new TypeError("Reduce of empty structure with no initial value");
235
187
  acc = first.value;
236
188
  index = 1;
237
189
  }
@@ -299,10 +251,44 @@ var _Stack = class _Stack extends IterableElementBase {
299
251
  return this._elements;
300
252
  }
301
253
  /**
302
- * Get the number of stored elements.
303
- * @remarks Time O(1), Space O(1)
304
- * @returns Current size.
305
- */
254
+ * Get the number of stored elements.
255
+ * @remarks Time O(1), Space O(1)
256
+ * @returns Current size.
257
+
258
+
259
+
260
+
261
+
262
+
263
+
264
+
265
+
266
+
267
+
268
+
269
+
270
+
271
+
272
+
273
+
274
+
275
+
276
+
277
+
278
+
279
+
280
+
281
+
282
+
283
+
284
+
285
+
286
+
287
+ * @example
288
+ * // Get number of elements
289
+ * const stack = new Stack<number>([1, 2, 3]);
290
+ * console.log(stack.size); // 3;
291
+ */
306
292
  get size() {
307
293
  return this.elements.length;
308
294
  }
@@ -320,36 +306,207 @@ var _Stack = class _Stack extends IterableElementBase {
320
306
  return new this(elements, options);
321
307
  }
322
308
  /**
323
- * Check whether the stack is empty.
324
- * @remarks Time O(1), Space O(1)
325
- * @returns True if size is 0.
326
- */
309
+ * Check whether the stack is empty.
310
+ * @remarks Time O(1), Space O(1)
311
+ * @returns True if size is 0.
312
+
313
+
314
+
315
+
316
+
317
+
318
+
319
+
320
+
321
+
322
+
323
+
324
+
325
+
326
+
327
+
328
+
329
+
330
+
331
+
332
+
333
+
334
+
335
+
336
+
337
+
338
+
339
+
340
+
341
+
342
+
343
+
344
+ * @example
345
+ * // Check if stack has elements
346
+ * const stack = new Stack<number>();
347
+ * console.log(stack.isEmpty()); // true;
348
+ * stack.push(1);
349
+ * console.log(stack.isEmpty()); // false;
350
+ */
327
351
  isEmpty() {
328
352
  return this.elements.length === 0;
329
353
  }
330
354
  /**
331
- * Get the top element without removing it.
332
- * @remarks Time O(1), Space O(1)
333
- * @returns Top element or undefined.
334
- */
355
+ * Get the top element without removing it.
356
+ * @remarks Time O(1), Space O(1)
357
+ * @returns Top element or undefined.
358
+
359
+
360
+
361
+
362
+
363
+
364
+
365
+
366
+
367
+
368
+
369
+
370
+
371
+
372
+
373
+
374
+
375
+
376
+
377
+
378
+
379
+
380
+
381
+
382
+
383
+
384
+
385
+
386
+
387
+
388
+
389
+
390
+ * @example
391
+ * // View the top element without removing it
392
+ * const stack = new Stack<string>(['a', 'b', 'c']);
393
+ * console.log(stack.peek()); // 'c';
394
+ * console.log(stack.size); // 3;
395
+ */
335
396
  peek() {
336
397
  return this.isEmpty() ? void 0 : this.elements[this.elements.length - 1];
337
398
  }
338
399
  /**
339
- * Push one element onto the top.
340
- * @remarks Time O(1), Space O(1)
341
- * @param element - Element to push.
342
- * @returns True when pushed.
343
- */
400
+ * Push one element onto the top.
401
+ * @remarks Time O(1), Space O(1)
402
+ * @param element - Element to push.
403
+ * @returns True when pushed.
404
+
405
+
406
+
407
+
408
+
409
+
410
+
411
+
412
+
413
+
414
+
415
+
416
+
417
+
418
+
419
+
420
+
421
+
422
+
423
+
424
+
425
+
426
+
427
+
428
+
429
+
430
+
431
+
432
+
433
+
434
+
435
+
436
+ * @example
437
+ * // basic Stack creation and push operation
438
+ * // Create a simple Stack with initial values
439
+ * const stack = new Stack([1, 2, 3, 4, 5]);
440
+ *
441
+ * // Verify the stack maintains insertion order (LIFO will be shown in pop)
442
+ * console.log([...stack]); // [1, 2, 3, 4, 5];
443
+ *
444
+ * // Check length
445
+ * console.log(stack.size); // 5;
446
+ *
447
+ * // Push a new element to the top
448
+ * stack.push(6);
449
+ * console.log(stack.size); // 6;
450
+ */
344
451
  push(element) {
345
452
  this.elements.push(element);
346
453
  return true;
347
454
  }
348
455
  /**
349
- * Pop and return the top element.
350
- * @remarks Time O(1), Space O(1)
351
- * @returns Removed element or undefined.
352
- */
456
+ * Pop and return the top element.
457
+ * @remarks Time O(1), Space O(1)
458
+ * @returns Removed element or undefined.
459
+
460
+
461
+
462
+
463
+
464
+
465
+
466
+
467
+
468
+
469
+
470
+
471
+
472
+
473
+
474
+
475
+
476
+
477
+
478
+
479
+
480
+
481
+
482
+
483
+
484
+
485
+
486
+
487
+
488
+
489
+
490
+
491
+ * @example
492
+ * // Stack pop operation (LIFO - Last In First Out)
493
+ * const stack = new Stack<number>([10, 20, 30, 40, 50]);
494
+ *
495
+ * // Peek at the top element without removing
496
+ * const top = stack.peek();
497
+ * console.log(top); // 50;
498
+ *
499
+ * // Pop removes from the top (LIFO order)
500
+ * const popped = stack.pop();
501
+ * console.log(popped); // 50;
502
+ *
503
+ * // Next pop gets the previous element
504
+ * const next = stack.pop();
505
+ * console.log(next); // 40;
506
+ *
507
+ * // Verify length decreased
508
+ * console.log(stack.size); // 3;
509
+ */
353
510
  pop() {
354
511
  return this.isEmpty() ? void 0 : this.elements.pop();
355
512
  }
@@ -368,11 +525,45 @@ var _Stack = class _Stack extends IterableElementBase {
368
525
  return ans;
369
526
  }
370
527
  /**
371
- * Delete the first occurrence of a specific element.
372
- * @remarks Time O(N), Space O(1)
373
- * @param element - Element to remove (using the configured equality).
374
- * @returns True if an element was removed.
375
- */
528
+ * Delete the first occurrence of a specific element.
529
+ * @remarks Time O(N), Space O(1)
530
+ * @param element - Element to remove (using the configured equality).
531
+ * @returns True if an element was removed.
532
+
533
+
534
+
535
+
536
+
537
+
538
+
539
+
540
+
541
+
542
+
543
+
544
+
545
+
546
+
547
+
548
+
549
+
550
+
551
+
552
+
553
+
554
+
555
+
556
+
557
+
558
+
559
+
560
+
561
+ * @example
562
+ * // Remove element
563
+ * const stack = new Stack<number>([1, 2, 3]);
564
+ * stack.delete(2);
565
+ * console.log(stack.toArray()); // [1, 3];
566
+ */
376
567
  delete(element) {
377
568
  const idx = this._indexOfByEquals(element);
378
569
  return this.deleteAt(idx);
@@ -404,30 +595,137 @@ var _Stack = class _Stack extends IterableElementBase {
404
595
  return false;
405
596
  }
406
597
  /**
407
- * Remove all elements and reset storage.
408
- * @remarks Time O(1), Space O(1)
409
- * @returns void
410
- */
598
+ * Remove all elements and reset storage.
599
+ * @remarks Time O(1), Space O(1)
600
+ * @returns void
601
+
602
+
603
+
604
+
605
+
606
+
607
+
608
+
609
+
610
+
611
+
612
+
613
+
614
+
615
+
616
+
617
+
618
+
619
+
620
+
621
+
622
+
623
+
624
+
625
+
626
+
627
+
628
+
629
+
630
+
631
+ * @example
632
+ * // Remove all elements
633
+ * const stack = new Stack<number>([1, 2, 3]);
634
+ * stack.clear();
635
+ * console.log(stack.isEmpty()); // true;
636
+ */
411
637
  clear() {
412
638
  this._elements = [];
413
639
  }
414
640
  /**
415
- * Deep clone this stack.
416
- * @remarks Time O(N), Space O(N)
417
- * @returns A new stack with the same content.
418
- */
641
+ * Deep clone this stack.
642
+ * @remarks Time O(N), Space O(N)
643
+ * @returns A new stack with the same content.
644
+
645
+
646
+
647
+
648
+
649
+
650
+
651
+
652
+
653
+
654
+
655
+
656
+
657
+
658
+
659
+
660
+
661
+
662
+
663
+
664
+
665
+
666
+
667
+
668
+
669
+
670
+
671
+
672
+
673
+
674
+ * @example
675
+ * // Create independent copy
676
+ * const stack = new Stack<number>([1, 2, 3]);
677
+ * const copy = stack.clone();
678
+ * copy.pop();
679
+ * console.log(stack.size); // 3;
680
+ * console.log(copy.size); // 2;
681
+ */
419
682
  clone() {
420
683
  const out = this._createInstance({ toElementFn: this.toElementFn });
421
684
  for (const v of this) out.push(v);
422
685
  return out;
423
686
  }
424
687
  /**
425
- * Filter elements into a new stack of the same class.
426
- * @remarks Time O(N), Space O(N)
427
- * @param predicate - Predicate (value, index, stack) → boolean to keep value.
428
- * @param [thisArg] - Value for `this` inside the predicate.
429
- * @returns A new stack with kept values.
430
- */
688
+ * Filter elements into a new stack of the same class.
689
+ * @remarks Time O(N), Space O(N)
690
+ * @param predicate - Predicate (value, index, stack) → boolean to keep value.
691
+ * @param [thisArg] - Value for `this` inside the predicate.
692
+ * @returns A new stack with kept values.
693
+
694
+
695
+
696
+
697
+
698
+
699
+
700
+
701
+
702
+
703
+
704
+
705
+
706
+
707
+
708
+
709
+
710
+
711
+
712
+
713
+
714
+
715
+
716
+
717
+
718
+
719
+
720
+
721
+
722
+
723
+ * @example
724
+ * // Filter elements
725
+ * const stack = new Stack<number>([1, 2, 3, 4, 5]);
726
+ * const evens = stack.filter(x => x % 2 === 0);
727
+ * console.log(evens.toArray()); // [2, 4];
728
+ */
431
729
  filter(predicate, thisArg) {
432
730
  const out = this._createInstance({ toElementFn: this.toElementFn });
433
731
  let index = 0;
@@ -454,15 +752,49 @@ var _Stack = class _Stack extends IterableElementBase {
454
752
  return out;
455
753
  }
456
754
  /**
457
- * Map values into a new stack (possibly different element type).
458
- * @remarks Time O(N), Space O(N)
459
- * @template EM
460
- * @template RM
461
- * @param callback - Mapping function (value, index, stack) → newElement.
462
- * @param [options] - Options for the output stack (e.g., toElementFn).
463
- * @param [thisArg] - Value for `this` inside the callback.
464
- * @returns A new Stack with mapped elements.
465
- */
755
+ * Map values into a new stack (possibly different element type).
756
+ * @remarks Time O(N), Space O(N)
757
+ * @template EM
758
+ * @template RM
759
+ * @param callback - Mapping function (value, index, stack) → newElement.
760
+ * @param [options] - Options for the output stack (e.g., toElementFn).
761
+ * @param [thisArg] - Value for `this` inside the callback.
762
+ * @returns A new Stack with mapped elements.
763
+
764
+
765
+
766
+
767
+
768
+
769
+
770
+
771
+
772
+
773
+
774
+
775
+
776
+
777
+
778
+
779
+
780
+
781
+
782
+
783
+
784
+
785
+
786
+
787
+
788
+
789
+
790
+
791
+
792
+ * @example
793
+ * // Transform elements
794
+ * const stack = new Stack<number>([1, 2, 3]);
795
+ * const doubled = stack.map(x => x * 2);
796
+ * console.log(doubled.toArray()); // [2, 4, 6];
797
+ */
466
798
  map(callback, options, thisArg) {
467
799
  const out = this._createLike([], { ...options != null ? options : {} });
468
800
  let index = 0;
@@ -526,6 +858,54 @@ var _Stack = class _Stack extends IterableElementBase {
526
858
  };
527
859
  __name(_Stack, "Stack");
528
860
  var Stack = _Stack;
861
+
862
+ // src/common/error.ts
863
+ var ERR = {
864
+ // Range / index
865
+ indexOutOfRange: /* @__PURE__ */ __name((index, min, max, ctx) => `${ctx ? ctx + ": " : ""}Index ${index} is out of range [${min}, ${max}].`, "indexOutOfRange"),
866
+ invalidIndex: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Index must be an integer.`, "invalidIndex"),
867
+ // Type / argument
868
+ invalidArgument: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidArgument"),
869
+ comparatorRequired: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Comparator is required for non-number/non-string/non-Date keys.`, "comparatorRequired"),
870
+ invalidKey: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidKey"),
871
+ notAFunction: /* @__PURE__ */ __name((name, ctx) => `${ctx ? ctx + ": " : ""}${name} must be a function.`, "notAFunction"),
872
+ invalidEntry: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Each entry must be a [key, value] tuple.`, "invalidEntry"),
873
+ invalidNaN: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}NaN is not a valid key.`, "invalidNaN"),
874
+ invalidDate: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Invalid Date key.`, "invalidDate"),
875
+ reduceEmpty: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Reduce of empty structure with no initial value.`, "reduceEmpty"),
876
+ callbackReturnType: /* @__PURE__ */ __name((expected, got, ctx) => `${ctx ? ctx + ": " : ""}Callback must return ${expected}; got ${got}.`, "callbackReturnType"),
877
+ // State / operation
878
+ invalidOperation: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidOperation"),
879
+ // Matrix
880
+ matrixDimensionMismatch: /* @__PURE__ */ __name((op) => `Matrix: Dimensions must be compatible for ${op}.`, "matrixDimensionMismatch"),
881
+ matrixSingular: /* @__PURE__ */ __name(() => "Matrix: Singular matrix, inverse does not exist.", "matrixSingular"),
882
+ matrixNotSquare: /* @__PURE__ */ __name(() => "Matrix: Must be square for inversion.", "matrixNotSquare"),
883
+ matrixNotRectangular: /* @__PURE__ */ __name(() => "Matrix: Must be rectangular for transposition.", "matrixNotRectangular"),
884
+ matrixRowMismatch: /* @__PURE__ */ __name((expected, got) => `Matrix: Expected row length ${expected}, but got ${got}.`, "matrixRowMismatch")
885
+ };
886
+
887
+ // src/common/index.ts
888
+ var DFSOperation = /* @__PURE__ */ ((DFSOperation2) => {
889
+ DFSOperation2[DFSOperation2["VISIT"] = 0] = "VISIT";
890
+ DFSOperation2[DFSOperation2["PROCESS"] = 1] = "PROCESS";
891
+ return DFSOperation2;
892
+ })(DFSOperation || {});
893
+ var _Range = class _Range {
894
+ constructor(low, high, includeLow = true, includeHigh = true) {
895
+ this.low = low;
896
+ this.high = high;
897
+ this.includeLow = includeLow;
898
+ this.includeHigh = includeHigh;
899
+ }
900
+ // Determine whether a key is within the range
901
+ isInRange(key, comparator) {
902
+ const lowCheck = this.includeLow ? comparator(key, this.low) >= 0 : comparator(key, this.low) > 0;
903
+ const highCheck = this.includeHigh ? comparator(key, this.high) <= 0 : comparator(key, this.high) < 0;
904
+ return lowCheck && highCheck;
905
+ }
906
+ };
907
+ __name(_Range, "Range");
908
+ var Range = _Range;
529
909
  /**
530
910
  * data-structure-typed
531
911
  *