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
@@ -29,52 +29,6 @@ var stackTyped = (() => {
29
29
  Stack: () => Stack
30
30
  });
31
31
 
32
- // src/common/error.ts
33
- var ERR = {
34
- // Range / index
35
- indexOutOfRange: (index, min, max, ctx) => `${ctx ? ctx + ": " : ""}Index ${index} is out of range [${min}, ${max}].`,
36
- invalidIndex: (ctx) => `${ctx ? ctx + ": " : ""}Index must be an integer.`,
37
- // Type / argument
38
- invalidArgument: (reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`,
39
- comparatorRequired: (ctx) => `${ctx ? ctx + ": " : ""}Comparator is required for non-number/non-string/non-Date keys.`,
40
- invalidKey: (reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`,
41
- notAFunction: (name, ctx) => `${ctx ? ctx + ": " : ""}${name} must be a function.`,
42
- invalidEntry: (ctx) => `${ctx ? ctx + ": " : ""}Each entry must be a [key, value] tuple.`,
43
- invalidNaN: (ctx) => `${ctx ? ctx + ": " : ""}NaN is not a valid key.`,
44
- invalidDate: (ctx) => `${ctx ? ctx + ": " : ""}Invalid Date key.`,
45
- reduceEmpty: (ctx) => `${ctx ? ctx + ": " : ""}Reduce of empty structure with no initial value.`,
46
- callbackReturnType: (expected, got, ctx) => `${ctx ? ctx + ": " : ""}Callback must return ${expected}; got ${got}.`,
47
- // State / operation
48
- invalidOperation: (reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`,
49
- // Matrix
50
- matrixDimensionMismatch: (op) => `Matrix: Dimensions must be compatible for ${op}.`,
51
- matrixSingular: () => "Matrix: Singular matrix, inverse does not exist.",
52
- matrixNotSquare: () => "Matrix: Must be square for inversion.",
53
- matrixNotRectangular: () => "Matrix: Must be rectangular for transposition.",
54
- matrixRowMismatch: (expected, got) => `Matrix: Expected row length ${expected}, but got ${got}.`
55
- };
56
-
57
- // src/common/index.ts
58
- var DFSOperation = /* @__PURE__ */ ((DFSOperation2) => {
59
- DFSOperation2[DFSOperation2["VISIT"] = 0] = "VISIT";
60
- DFSOperation2[DFSOperation2["PROCESS"] = 1] = "PROCESS";
61
- return DFSOperation2;
62
- })(DFSOperation || {});
63
- var Range = class {
64
- constructor(low, high, includeLow = true, includeHigh = true) {
65
- this.low = low;
66
- this.high = high;
67
- this.includeLow = includeLow;
68
- this.includeHigh = includeHigh;
69
- }
70
- // Determine whether a key is within the range
71
- isInRange(key, comparator) {
72
- const lowCheck = this.includeLow ? comparator(key, this.low) >= 0 : comparator(key, this.low) > 0;
73
- const highCheck = this.includeHigh ? comparator(key, this.high) <= 0 : comparator(key, this.high) < 0;
74
- return lowCheck && highCheck;
75
- }
76
- };
77
-
78
32
  // src/data-structures/base/iterable-element-base.ts
79
33
  var IterableElementBase = class {
80
34
  /**
@@ -97,7 +51,7 @@ var stackTyped = (() => {
97
51
  if (options) {
98
52
  const { toElementFn } = options;
99
53
  if (typeof toElementFn === "function") this._toElementFn = toElementFn;
100
- else if (toElementFn) throw new TypeError(ERR.notAFunction("toElementFn"));
54
+ else if (toElementFn) throw new TypeError("toElementFn must be a function type");
101
55
  }
102
56
  }
103
57
  /**
@@ -253,7 +207,7 @@ var stackTyped = (() => {
253
207
  acc = initialValue;
254
208
  } else {
255
209
  const first = iter.next();
256
- if (first.done) throw new TypeError(ERR.reduceEmpty());
210
+ if (first.done) throw new TypeError("Reduce of empty structure with no initial value");
257
211
  acc = first.value;
258
212
  index = 1;
259
213
  }
@@ -319,10 +273,44 @@ var stackTyped = (() => {
319
273
  return this._elements;
320
274
  }
321
275
  /**
322
- * Get the number of stored elements.
323
- * @remarks Time O(1), Space O(1)
324
- * @returns Current size.
325
- */
276
+ * Get the number of stored elements.
277
+ * @remarks Time O(1), Space O(1)
278
+ * @returns Current size.
279
+
280
+
281
+
282
+
283
+
284
+
285
+
286
+
287
+
288
+
289
+
290
+
291
+
292
+
293
+
294
+
295
+
296
+
297
+
298
+
299
+
300
+
301
+
302
+
303
+
304
+
305
+
306
+
307
+
308
+
309
+ * @example
310
+ * // Get number of elements
311
+ * const stack = new Stack<number>([1, 2, 3]);
312
+ * console.log(stack.size); // 3;
313
+ */
326
314
  get size() {
327
315
  return this.elements.length;
328
316
  }
@@ -340,36 +328,207 @@ var stackTyped = (() => {
340
328
  return new this(elements, options);
341
329
  }
342
330
  /**
343
- * Check whether the stack is empty.
344
- * @remarks Time O(1), Space O(1)
345
- * @returns True if size is 0.
346
- */
331
+ * Check whether the stack is empty.
332
+ * @remarks Time O(1), Space O(1)
333
+ * @returns True if size is 0.
334
+
335
+
336
+
337
+
338
+
339
+
340
+
341
+
342
+
343
+
344
+
345
+
346
+
347
+
348
+
349
+
350
+
351
+
352
+
353
+
354
+
355
+
356
+
357
+
358
+
359
+
360
+
361
+
362
+
363
+
364
+
365
+
366
+ * @example
367
+ * // Check if stack has elements
368
+ * const stack = new Stack<number>();
369
+ * console.log(stack.isEmpty()); // true;
370
+ * stack.push(1);
371
+ * console.log(stack.isEmpty()); // false;
372
+ */
347
373
  isEmpty() {
348
374
  return this.elements.length === 0;
349
375
  }
350
376
  /**
351
- * Get the top element without removing it.
352
- * @remarks Time O(1), Space O(1)
353
- * @returns Top element or undefined.
354
- */
377
+ * Get the top element without removing it.
378
+ * @remarks Time O(1), Space O(1)
379
+ * @returns Top element or undefined.
380
+
381
+
382
+
383
+
384
+
385
+
386
+
387
+
388
+
389
+
390
+
391
+
392
+
393
+
394
+
395
+
396
+
397
+
398
+
399
+
400
+
401
+
402
+
403
+
404
+
405
+
406
+
407
+
408
+
409
+
410
+
411
+
412
+ * @example
413
+ * // View the top element without removing it
414
+ * const stack = new Stack<string>(['a', 'b', 'c']);
415
+ * console.log(stack.peek()); // 'c';
416
+ * console.log(stack.size); // 3;
417
+ */
355
418
  peek() {
356
419
  return this.isEmpty() ? void 0 : this.elements[this.elements.length - 1];
357
420
  }
358
421
  /**
359
- * Push one element onto the top.
360
- * @remarks Time O(1), Space O(1)
361
- * @param element - Element to push.
362
- * @returns True when pushed.
363
- */
422
+ * Push one element onto the top.
423
+ * @remarks Time O(1), Space O(1)
424
+ * @param element - Element to push.
425
+ * @returns True when pushed.
426
+
427
+
428
+
429
+
430
+
431
+
432
+
433
+
434
+
435
+
436
+
437
+
438
+
439
+
440
+
441
+
442
+
443
+
444
+
445
+
446
+
447
+
448
+
449
+
450
+
451
+
452
+
453
+
454
+
455
+
456
+
457
+
458
+ * @example
459
+ * // basic Stack creation and push operation
460
+ * // Create a simple Stack with initial values
461
+ * const stack = new Stack([1, 2, 3, 4, 5]);
462
+ *
463
+ * // Verify the stack maintains insertion order (LIFO will be shown in pop)
464
+ * console.log([...stack]); // [1, 2, 3, 4, 5];
465
+ *
466
+ * // Check length
467
+ * console.log(stack.size); // 5;
468
+ *
469
+ * // Push a new element to the top
470
+ * stack.push(6);
471
+ * console.log(stack.size); // 6;
472
+ */
364
473
  push(element) {
365
474
  this.elements.push(element);
366
475
  return true;
367
476
  }
368
477
  /**
369
- * Pop and return the top element.
370
- * @remarks Time O(1), Space O(1)
371
- * @returns Removed element or undefined.
372
- */
478
+ * Pop and return the top element.
479
+ * @remarks Time O(1), Space O(1)
480
+ * @returns Removed element or undefined.
481
+
482
+
483
+
484
+
485
+
486
+
487
+
488
+
489
+
490
+
491
+
492
+
493
+
494
+
495
+
496
+
497
+
498
+
499
+
500
+
501
+
502
+
503
+
504
+
505
+
506
+
507
+
508
+
509
+
510
+
511
+
512
+
513
+ * @example
514
+ * // Stack pop operation (LIFO - Last In First Out)
515
+ * const stack = new Stack<number>([10, 20, 30, 40, 50]);
516
+ *
517
+ * // Peek at the top element without removing
518
+ * const top = stack.peek();
519
+ * console.log(top); // 50;
520
+ *
521
+ * // Pop removes from the top (LIFO order)
522
+ * const popped = stack.pop();
523
+ * console.log(popped); // 50;
524
+ *
525
+ * // Next pop gets the previous element
526
+ * const next = stack.pop();
527
+ * console.log(next); // 40;
528
+ *
529
+ * // Verify length decreased
530
+ * console.log(stack.size); // 3;
531
+ */
373
532
  pop() {
374
533
  return this.isEmpty() ? void 0 : this.elements.pop();
375
534
  }
@@ -388,11 +547,45 @@ var stackTyped = (() => {
388
547
  return ans;
389
548
  }
390
549
  /**
391
- * Delete the first occurrence of a specific element.
392
- * @remarks Time O(N), Space O(1)
393
- * @param element - Element to remove (using the configured equality).
394
- * @returns True if an element was removed.
395
- */
550
+ * Delete the first occurrence of a specific element.
551
+ * @remarks Time O(N), Space O(1)
552
+ * @param element - Element to remove (using the configured equality).
553
+ * @returns True if an element was removed.
554
+
555
+
556
+
557
+
558
+
559
+
560
+
561
+
562
+
563
+
564
+
565
+
566
+
567
+
568
+
569
+
570
+
571
+
572
+
573
+
574
+
575
+
576
+
577
+
578
+
579
+
580
+
581
+
582
+
583
+ * @example
584
+ * // Remove element
585
+ * const stack = new Stack<number>([1, 2, 3]);
586
+ * stack.delete(2);
587
+ * console.log(stack.toArray()); // [1, 3];
588
+ */
396
589
  delete(element) {
397
590
  const idx = this._indexOfByEquals(element);
398
591
  return this.deleteAt(idx);
@@ -424,30 +617,137 @@ var stackTyped = (() => {
424
617
  return false;
425
618
  }
426
619
  /**
427
- * Remove all elements and reset storage.
428
- * @remarks Time O(1), Space O(1)
429
- * @returns void
430
- */
620
+ * Remove all elements and reset storage.
621
+ * @remarks Time O(1), Space O(1)
622
+ * @returns void
623
+
624
+
625
+
626
+
627
+
628
+
629
+
630
+
631
+
632
+
633
+
634
+
635
+
636
+
637
+
638
+
639
+
640
+
641
+
642
+
643
+
644
+
645
+
646
+
647
+
648
+
649
+
650
+
651
+
652
+
653
+ * @example
654
+ * // Remove all elements
655
+ * const stack = new Stack<number>([1, 2, 3]);
656
+ * stack.clear();
657
+ * console.log(stack.isEmpty()); // true;
658
+ */
431
659
  clear() {
432
660
  this._elements = [];
433
661
  }
434
662
  /**
435
- * Deep clone this stack.
436
- * @remarks Time O(N), Space O(N)
437
- * @returns A new stack with the same content.
438
- */
663
+ * Deep clone this stack.
664
+ * @remarks Time O(N), Space O(N)
665
+ * @returns A new stack with the same content.
666
+
667
+
668
+
669
+
670
+
671
+
672
+
673
+
674
+
675
+
676
+
677
+
678
+
679
+
680
+
681
+
682
+
683
+
684
+
685
+
686
+
687
+
688
+
689
+
690
+
691
+
692
+
693
+
694
+
695
+
696
+ * @example
697
+ * // Create independent copy
698
+ * const stack = new Stack<number>([1, 2, 3]);
699
+ * const copy = stack.clone();
700
+ * copy.pop();
701
+ * console.log(stack.size); // 3;
702
+ * console.log(copy.size); // 2;
703
+ */
439
704
  clone() {
440
705
  const out = this._createInstance({ toElementFn: this.toElementFn });
441
706
  for (const v of this) out.push(v);
442
707
  return out;
443
708
  }
444
709
  /**
445
- * Filter elements into a new stack of the same class.
446
- * @remarks Time O(N), Space O(N)
447
- * @param predicate - Predicate (value, index, stack) → boolean to keep value.
448
- * @param [thisArg] - Value for `this` inside the predicate.
449
- * @returns A new stack with kept values.
450
- */
710
+ * Filter elements into a new stack of the same class.
711
+ * @remarks Time O(N), Space O(N)
712
+ * @param predicate - Predicate (value, index, stack) → boolean to keep value.
713
+ * @param [thisArg] - Value for `this` inside the predicate.
714
+ * @returns A new stack with kept values.
715
+
716
+
717
+
718
+
719
+
720
+
721
+
722
+
723
+
724
+
725
+
726
+
727
+
728
+
729
+
730
+
731
+
732
+
733
+
734
+
735
+
736
+
737
+
738
+
739
+
740
+
741
+
742
+
743
+
744
+
745
+ * @example
746
+ * // Filter elements
747
+ * const stack = new Stack<number>([1, 2, 3, 4, 5]);
748
+ * const evens = stack.filter(x => x % 2 === 0);
749
+ * console.log(evens.toArray()); // [2, 4];
750
+ */
451
751
  filter(predicate, thisArg) {
452
752
  const out = this._createInstance({ toElementFn: this.toElementFn });
453
753
  let index = 0;
@@ -474,15 +774,49 @@ var stackTyped = (() => {
474
774
  return out;
475
775
  }
476
776
  /**
477
- * Map values into a new stack (possibly different element type).
478
- * @remarks Time O(N), Space O(N)
479
- * @template EM
480
- * @template RM
481
- * @param callback - Mapping function (value, index, stack) → newElement.
482
- * @param [options] - Options for the output stack (e.g., toElementFn).
483
- * @param [thisArg] - Value for `this` inside the callback.
484
- * @returns A new Stack with mapped elements.
485
- */
777
+ * Map values into a new stack (possibly different element type).
778
+ * @remarks Time O(N), Space O(N)
779
+ * @template EM
780
+ * @template RM
781
+ * @param callback - Mapping function (value, index, stack) → newElement.
782
+ * @param [options] - Options for the output stack (e.g., toElementFn).
783
+ * @param [thisArg] - Value for `this` inside the callback.
784
+ * @returns A new Stack with mapped elements.
785
+
786
+
787
+
788
+
789
+
790
+
791
+
792
+
793
+
794
+
795
+
796
+
797
+
798
+
799
+
800
+
801
+
802
+
803
+
804
+
805
+
806
+
807
+
808
+
809
+
810
+
811
+
812
+
813
+
814
+ * @example
815
+ * // Transform elements
816
+ * const stack = new Stack<number>([1, 2, 3]);
817
+ * const doubled = stack.map(x => x * 2);
818
+ * console.log(doubled.toArray()); // [2, 4, 6];
819
+ */
486
820
  map(callback, options, thisArg) {
487
821
  const out = this._createLike([], { ...options != null ? options : {} });
488
822
  let index = 0;
@@ -544,6 +878,52 @@ var stackTyped = (() => {
544
878
  for (let i = 0; i < this.elements.length; i++) yield this.elements[i];
545
879
  }
546
880
  };
881
+
882
+ // src/common/error.ts
883
+ var ERR = {
884
+ // Range / index
885
+ indexOutOfRange: (index, min, max, ctx) => `${ctx ? ctx + ": " : ""}Index ${index} is out of range [${min}, ${max}].`,
886
+ invalidIndex: (ctx) => `${ctx ? ctx + ": " : ""}Index must be an integer.`,
887
+ // Type / argument
888
+ invalidArgument: (reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`,
889
+ comparatorRequired: (ctx) => `${ctx ? ctx + ": " : ""}Comparator is required for non-number/non-string/non-Date keys.`,
890
+ invalidKey: (reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`,
891
+ notAFunction: (name, ctx) => `${ctx ? ctx + ": " : ""}${name} must be a function.`,
892
+ invalidEntry: (ctx) => `${ctx ? ctx + ": " : ""}Each entry must be a [key, value] tuple.`,
893
+ invalidNaN: (ctx) => `${ctx ? ctx + ": " : ""}NaN is not a valid key.`,
894
+ invalidDate: (ctx) => `${ctx ? ctx + ": " : ""}Invalid Date key.`,
895
+ reduceEmpty: (ctx) => `${ctx ? ctx + ": " : ""}Reduce of empty structure with no initial value.`,
896
+ callbackReturnType: (expected, got, ctx) => `${ctx ? ctx + ": " : ""}Callback must return ${expected}; got ${got}.`,
897
+ // State / operation
898
+ invalidOperation: (reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`,
899
+ // Matrix
900
+ matrixDimensionMismatch: (op) => `Matrix: Dimensions must be compatible for ${op}.`,
901
+ matrixSingular: () => "Matrix: Singular matrix, inverse does not exist.",
902
+ matrixNotSquare: () => "Matrix: Must be square for inversion.",
903
+ matrixNotRectangular: () => "Matrix: Must be rectangular for transposition.",
904
+ matrixRowMismatch: (expected, got) => `Matrix: Expected row length ${expected}, but got ${got}.`
905
+ };
906
+
907
+ // src/common/index.ts
908
+ var DFSOperation = /* @__PURE__ */ ((DFSOperation2) => {
909
+ DFSOperation2[DFSOperation2["VISIT"] = 0] = "VISIT";
910
+ DFSOperation2[DFSOperation2["PROCESS"] = 1] = "PROCESS";
911
+ return DFSOperation2;
912
+ })(DFSOperation || {});
913
+ var Range = class {
914
+ constructor(low, high, includeLow = true, includeHigh = true) {
915
+ this.low = low;
916
+ this.high = high;
917
+ this.includeLow = includeLow;
918
+ this.includeHigh = includeHigh;
919
+ }
920
+ // Determine whether a key is within the range
921
+ isInRange(key, comparator) {
922
+ const lowCheck = this.includeLow ? comparator(key, this.low) >= 0 : comparator(key, this.low) > 0;
923
+ const highCheck = this.includeHigh ? comparator(key, this.high) <= 0 : comparator(key, this.high) < 0;
924
+ return lowCheck && highCheck;
925
+ }
926
+ };
547
927
  return __toCommonJS(src_exports);
548
928
  })();
549
929
  /**