undirected-graph-typed 2.5.0 → 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 (90) hide show
  1. package/dist/cjs/index.cjs +1054 -207
  2. package/dist/cjs/index.cjs.map +1 -1
  3. package/dist/cjs-legacy/index.cjs +1051 -204
  4. package/dist/cjs-legacy/index.cjs.map +1 -1
  5. package/dist/esm/index.mjs +1054 -208
  6. package/dist/esm/index.mjs.map +1 -1
  7. package/dist/esm-legacy/index.mjs +1051 -205
  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/base/index.d.ts +1 -0
  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 +288 -0
  15. package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +336 -0
  16. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +618 -18
  17. package/dist/types/data-structures/binary-tree/bst.d.ts +676 -1
  18. package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +456 -0
  19. package/dist/types/data-structures/binary-tree/segment-tree.d.ts +144 -1
  20. package/dist/types/data-structures/binary-tree/tree-map.d.ts +3307 -399
  21. package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +3285 -360
  22. package/dist/types/data-structures/binary-tree/tree-multi-set.d.ts +2674 -325
  23. package/dist/types/data-structures/binary-tree/tree-set.d.ts +3072 -287
  24. package/dist/types/data-structures/graph/abstract-graph.d.ts +4 -4
  25. package/dist/types/data-structures/graph/directed-graph.d.ts +240 -0
  26. package/dist/types/data-structures/graph/undirected-graph.d.ts +216 -0
  27. package/dist/types/data-structures/hash/hash-map.d.ts +274 -10
  28. package/dist/types/data-structures/heap/heap.d.ts +336 -0
  29. package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +411 -3
  30. package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +363 -3
  31. package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +434 -2
  32. package/dist/types/data-structures/matrix/matrix.d.ts +192 -0
  33. package/dist/types/data-structures/queue/deque.d.ts +364 -4
  34. package/dist/types/data-structures/queue/queue.d.ts +288 -0
  35. package/dist/types/data-structures/stack/stack.d.ts +240 -0
  36. package/dist/types/data-structures/trie/trie.d.ts +292 -4
  37. package/dist/types/interfaces/graph.d.ts +1 -1
  38. package/dist/types/types/common.d.ts +2 -2
  39. package/dist/types/types/data-structures/binary-tree/bst.d.ts +1 -0
  40. package/dist/types/types/data-structures/binary-tree/tree-map.d.ts +5 -0
  41. package/dist/types/types/data-structures/binary-tree/tree-multi-set.d.ts +4 -0
  42. package/dist/types/types/data-structures/binary-tree/tree-set.d.ts +4 -0
  43. package/dist/types/types/data-structures/heap/heap.d.ts +1 -0
  44. package/dist/types/types/data-structures/priority-queue/priority-queue.d.ts +1 -0
  45. package/dist/types/types/utils/validate-type.d.ts +4 -4
  46. package/dist/umd/undirected-graph-typed.js +1051 -205
  47. package/dist/umd/undirected-graph-typed.js.map +1 -1
  48. package/dist/umd/undirected-graph-typed.min.js +3 -3
  49. package/dist/umd/undirected-graph-typed.min.js.map +1 -1
  50. package/package.json +2 -2
  51. package/src/common/error.ts +19 -1
  52. package/src/common/index.ts +1 -1
  53. package/src/data-structures/base/index.ts +1 -0
  54. package/src/data-structures/base/iterable-element-base.ts +3 -2
  55. package/src/data-structures/base/iterable-entry-base.ts +8 -8
  56. package/src/data-structures/base/linear-base.ts +3 -3
  57. package/src/data-structures/binary-tree/avl-tree.ts +299 -0
  58. package/src/data-structures/binary-tree/binary-indexed-tree.ts +341 -5
  59. package/src/data-structures/binary-tree/binary-tree.ts +606 -6
  60. package/src/data-structures/binary-tree/bst.ts +946 -7
  61. package/src/data-structures/binary-tree/red-black-tree.ts +472 -0
  62. package/src/data-structures/binary-tree/segment-tree.ts +145 -2
  63. package/src/data-structures/binary-tree/tree-map.ts +3423 -499
  64. package/src/data-structures/binary-tree/tree-multi-map.ts +3537 -596
  65. package/src/data-structures/binary-tree/tree-multi-set.ts +2855 -495
  66. package/src/data-structures/binary-tree/tree-set.ts +3209 -413
  67. package/src/data-structures/graph/abstract-graph.ts +6 -6
  68. package/src/data-structures/graph/directed-graph.ts +240 -0
  69. package/src/data-structures/graph/undirected-graph.ts +216 -0
  70. package/src/data-structures/hash/hash-map.ts +281 -19
  71. package/src/data-structures/heap/heap.ts +340 -4
  72. package/src/data-structures/heap/max-heap.ts +2 -2
  73. package/src/data-structures/linked-list/doubly-linked-list.ts +411 -3
  74. package/src/data-structures/linked-list/singly-linked-list.ts +363 -3
  75. package/src/data-structures/linked-list/skip-linked-list.ts +439 -7
  76. package/src/data-structures/matrix/matrix.ts +202 -10
  77. package/src/data-structures/priority-queue/max-priority-queue.ts +2 -2
  78. package/src/data-structures/queue/deque.ts +365 -5
  79. package/src/data-structures/queue/queue.ts +288 -0
  80. package/src/data-structures/stack/stack.ts +240 -0
  81. package/src/data-structures/trie/trie.ts +295 -7
  82. package/src/interfaces/graph.ts +1 -1
  83. package/src/types/common.ts +2 -2
  84. package/src/types/data-structures/binary-tree/bst.ts +1 -0
  85. package/src/types/data-structures/binary-tree/tree-map.ts +6 -0
  86. package/src/types/data-structures/binary-tree/tree-multi-set.ts +5 -0
  87. package/src/types/data-structures/binary-tree/tree-set.ts +5 -0
  88. package/src/types/data-structures/heap/heap.ts +1 -0
  89. package/src/types/data-structures/priority-queue/priority-queue.ts +1 -0
  90. package/src/types/utils/validate-type.ts +4 -4
@@ -25,6 +25,10 @@ var arrayRemove = /* @__PURE__ */ __name(function(array, predicate) {
25
25
  }, "arrayRemove");
26
26
 
27
27
  // src/common/error.ts
28
+ function raise(ErrorClass, message) {
29
+ throw new ErrorClass(message);
30
+ }
31
+ __name(raise, "raise");
28
32
  var ERR = {
29
33
  // Range / index
30
34
  indexOutOfRange: /* @__PURE__ */ __name((index, min, max, ctx) => `${ctx ? ctx + ": " : ""}Index ${index} is out of range [${min}, ${max}].`, "indexOutOfRange"),
@@ -46,7 +50,9 @@ var ERR = {
46
50
  matrixSingular: /* @__PURE__ */ __name(() => "Matrix: Singular matrix, inverse does not exist.", "matrixSingular"),
47
51
  matrixNotSquare: /* @__PURE__ */ __name(() => "Matrix: Must be square for inversion.", "matrixNotSquare"),
48
52
  matrixNotRectangular: /* @__PURE__ */ __name(() => "Matrix: Must be rectangular for transposition.", "matrixNotRectangular"),
49
- matrixRowMismatch: /* @__PURE__ */ __name((expected, got) => `Matrix: Expected row length ${expected}, but got ${got}.`, "matrixRowMismatch")
53
+ matrixRowMismatch: /* @__PURE__ */ __name((expected, got) => `Matrix: Expected row length ${expected}, but got ${got}.`, "matrixRowMismatch"),
54
+ // Order statistic
55
+ orderStatisticNotEnabled: /* @__PURE__ */ __name((method, ctx) => `${ctx ? ctx + ": " : ""}${method}() requires enableOrderStatistic: true.`, "orderStatisticNotEnabled")
50
56
  };
51
57
 
52
58
  // src/common/index.ts
@@ -273,7 +279,7 @@ var IterableElementBase = class {
273
279
  if (options) {
274
280
  const { toElementFn } = options;
275
281
  if (typeof toElementFn === "function") this._toElementFn = toElementFn;
276
- else if (toElementFn) throw new TypeError("toElementFn must be a function type");
282
+ else if (toElementFn) raise(TypeError, "toElementFn must be a function type");
277
283
  }
278
284
  }
279
285
  /**
@@ -436,7 +442,7 @@ var IterableElementBase = class {
436
442
  acc = initialValue;
437
443
  } else {
438
444
  const first = iter.next();
439
- if (first.done) throw new TypeError("Reduce of empty structure with no initial value");
445
+ if (first.done) raise(TypeError, "Reduce of empty structure with no initial value");
440
446
  acc = first.value;
441
447
  index = 1;
442
448
  }
@@ -478,6 +484,199 @@ var IterableElementBase = class {
478
484
  }
479
485
  };
480
486
 
487
+ // src/data-structures/base/linear-base.ts
488
+ var LinearBase = class _LinearBase extends IterableElementBase {
489
+ static {
490
+ __name(this, "LinearBase");
491
+ }
492
+ /**
493
+ * Construct a linear container with runtime options.
494
+ * @param options - `{ maxLen?, ... }` bounds/behavior options.
495
+ * @remarks Time O(1), Space O(1)
496
+ */
497
+ constructor(options) {
498
+ super(options);
499
+ if (options) {
500
+ const { maxLen } = options;
501
+ if (typeof maxLen === "number" && maxLen > 0 && maxLen % 1 === 0) this._maxLen = maxLen;
502
+ }
503
+ }
504
+ _maxLen = -1;
505
+ /**
506
+ * Upper bound for length (if positive), or `-1` when unbounded.
507
+ * @returns Maximum allowed length.
508
+ * @remarks Time O(1), Space O(1)
509
+ */
510
+ get maxLen() {
511
+ return this._maxLen;
512
+ }
513
+ /**
514
+ * First index of a value from the left.
515
+ * @param searchElement - Value to match.
516
+ * @param fromIndex - Start position (supports negative index).
517
+ * @returns Index or `-1` if not found.
518
+ * @remarks Time O(n), Space O(1)
519
+ */
520
+ indexOf(searchElement, fromIndex = 0) {
521
+ if (this.length === 0) return -1;
522
+ if (fromIndex < 0) fromIndex = this.length + fromIndex;
523
+ if (fromIndex < 0) fromIndex = 0;
524
+ for (let i = fromIndex; i < this.length; i++) {
525
+ const element = this.at(i);
526
+ if (element === searchElement) return i;
527
+ }
528
+ return -1;
529
+ }
530
+ /**
531
+ * Last index of a value from the right.
532
+ * @param searchElement - Value to match.
533
+ * @param fromIndex - Start position (supports negative index).
534
+ * @returns Index or `-1` if not found.
535
+ * @remarks Time O(n), Space O(1)
536
+ */
537
+ lastIndexOf(searchElement, fromIndex = this.length - 1) {
538
+ if (this.length === 0) return -1;
539
+ if (fromIndex >= this.length) fromIndex = this.length - 1;
540
+ if (fromIndex < 0) fromIndex = this.length + fromIndex;
541
+ for (let i = fromIndex; i >= 0; i--) {
542
+ const element = this.at(i);
543
+ if (element === searchElement) return i;
544
+ }
545
+ return -1;
546
+ }
547
+ /**
548
+ * Find the first index matching a predicate.
549
+ * @param predicate - `(element, index, self) => boolean`.
550
+ * @param thisArg - Optional `this` for callback.
551
+ * @returns Index or `-1`.
552
+ * @remarks Time O(n), Space O(1)
553
+ */
554
+ findIndex(predicate, thisArg) {
555
+ for (let i = 0; i < this.length; i++) {
556
+ const item = this.at(i);
557
+ if (item !== void 0 && predicate.call(thisArg, item, i, this)) return i;
558
+ }
559
+ return -1;
560
+ }
561
+ /**
562
+ * Concatenate elements and/or containers.
563
+ * @param items - Elements or other containers.
564
+ * @returns New container with combined elements (`this` type).
565
+ * @remarks Time O(sum(length)), Space O(sum(length))
566
+ */
567
+ concat(...items) {
568
+ const newList = this.clone();
569
+ for (const item of items) {
570
+ if (item instanceof _LinearBase) {
571
+ newList.pushMany(item);
572
+ } else {
573
+ newList.push(item);
574
+ }
575
+ }
576
+ return newList;
577
+ }
578
+ /**
579
+ * In-place stable order via array sort semantics.
580
+ * @param compareFn - Comparator `(a, b) => number`.
581
+ * @returns This container.
582
+ * @remarks Time O(n log n), Space O(n) (materializes to array temporarily)
583
+ */
584
+ sort(compareFn) {
585
+ const arr = this.toArray();
586
+ arr.sort(compareFn);
587
+ this.clear();
588
+ for (const item of arr) this.push(item);
589
+ return this;
590
+ }
591
+ /**
592
+ * Remove and/or insert elements at a position (array-compatible).
593
+ * @param start - Start index (supports negative index).
594
+ * @param deleteCount - How many to remove.
595
+ * @param items - Elements to insert.
596
+ * @returns Removed elements as a new list (`this` type).
597
+ * @remarks Time O(n + m), Space O(min(n, m)) where `m = items.length`
598
+ */
599
+ splice(start, deleteCount = 0, ...items) {
600
+ const removedList = this._createInstance();
601
+ start = start < 0 ? this.length + start : start;
602
+ start = Math.max(0, Math.min(start, this.length));
603
+ deleteCount = Math.max(0, Math.min(deleteCount, this.length - start));
604
+ for (let i = 0; i < deleteCount; i++) {
605
+ const removed = this.deleteAt(start);
606
+ if (removed !== void 0) {
607
+ removedList.push(removed);
608
+ }
609
+ }
610
+ for (let i = 0; i < items.length; i++) {
611
+ this.addAt(start + i, items[i]);
612
+ }
613
+ return removedList;
614
+ }
615
+ /**
616
+ * Join all elements into a string.
617
+ * @param separator - Separator string.
618
+ * @returns Concatenated string.
619
+ * @remarks Time O(n), Space O(n)
620
+ */
621
+ join(separator = ",") {
622
+ return this.toArray().join(separator);
623
+ }
624
+ /**
625
+ * Snapshot elements into a reversed array.
626
+ * @returns New reversed array.
627
+ * @remarks Time O(n), Space O(n)
628
+ */
629
+ toReversedArray() {
630
+ const array = [];
631
+ for (let i = this.length - 1; i >= 0; i--) {
632
+ array.push(this.at(i));
633
+ }
634
+ return array;
635
+ }
636
+ reduceRight(callbackfn, initialValue) {
637
+ let accumulator = initialValue ?? 0;
638
+ for (let i = this.length - 1; i >= 0; i--) {
639
+ accumulator = callbackfn(accumulator, this.at(i), i, this);
640
+ }
641
+ return accumulator;
642
+ }
643
+ /**
644
+ * Create a shallow copy of a subrange.
645
+ * @param start - Inclusive start (supports negative index).
646
+ * @param end - Exclusive end (supports negative index).
647
+ * @returns New list with the range (`this` type).
648
+ * @remarks Time O(n), Space O(n)
649
+ */
650
+ slice(start = 0, end = this.length) {
651
+ start = start < 0 ? this.length + start : start;
652
+ end = end < 0 ? this.length + end : end;
653
+ const newList = this._createInstance();
654
+ for (let i = start; i < end; i++) {
655
+ newList.push(this.at(i));
656
+ }
657
+ return newList;
658
+ }
659
+ /**
660
+ * Fill a range with a value.
661
+ * @param value - Value to set.
662
+ * @param start - Inclusive start.
663
+ * @param end - Exclusive end.
664
+ * @returns This list.
665
+ * @remarks Time O(n), Space O(1)
666
+ */
667
+ fill(value, start = 0, end = this.length) {
668
+ start = start < 0 ? this.length + start : start;
669
+ end = end < 0 ? this.length + end : end;
670
+ if (start < 0) start = 0;
671
+ if (end > this.length) end = this.length;
672
+ if (start >= end) return this;
673
+ for (let i = start; i < end; i++) {
674
+ this.setAt(i, value);
675
+ }
676
+ return this;
677
+ }
678
+ };
679
+
481
680
  // src/data-structures/heap/heap.ts
482
681
  var Heap = class _Heap extends IterableElementBase {
483
682
  static {
@@ -523,6 +722,30 @@ var Heap = class _Heap extends IterableElementBase {
523
722
 
524
723
 
525
724
 
725
+
726
+
727
+
728
+
729
+
730
+
731
+
732
+
733
+
734
+
735
+
736
+
737
+
738
+
739
+
740
+
741
+
742
+
743
+
744
+
745
+
746
+
747
+
748
+
526
749
  * @example
527
750
  * // Track heap capacity
528
751
  * const heap = new Heap<number>();
@@ -585,6 +808,30 @@ var Heap = class _Heap extends IterableElementBase {
585
808
 
586
809
 
587
810
 
811
+
812
+
813
+
814
+
815
+
816
+
817
+
818
+
819
+
820
+
821
+
822
+
823
+
824
+
825
+
826
+
827
+
828
+
829
+
830
+
831
+
832
+
833
+
834
+
588
835
  * @example
589
836
  * // basic Heap creation and add operation
590
837
  * // Create a min heap (default)
@@ -618,6 +865,30 @@ var Heap = class _Heap extends IterableElementBase {
618
865
 
619
866
 
620
867
 
868
+
869
+
870
+
871
+
872
+
873
+
874
+
875
+
876
+
877
+
878
+
879
+
880
+
881
+
882
+
883
+
884
+
885
+
886
+
887
+
888
+
889
+
890
+
891
+
621
892
  * @example
622
893
  * // Add multiple elements
623
894
  * const heap = new Heap<number>([], { comparator: (a, b) => a - b });
@@ -653,6 +924,30 @@ var Heap = class _Heap extends IterableElementBase {
653
924
 
654
925
 
655
926
 
927
+
928
+
929
+
930
+
931
+
932
+
933
+
934
+
935
+
936
+
937
+
938
+
939
+
940
+
941
+
942
+
943
+
944
+
945
+
946
+
947
+
948
+
949
+
950
+
656
951
  * @example
657
952
  * // Heap with custom comparator (MaxHeap behavior)
658
953
  * interface Task {
@@ -704,6 +999,30 @@ var Heap = class _Heap extends IterableElementBase {
704
999
 
705
1000
 
706
1001
 
1002
+
1003
+
1004
+
1005
+
1006
+
1007
+
1008
+
1009
+
1010
+
1011
+
1012
+
1013
+
1014
+
1015
+
1016
+
1017
+
1018
+
1019
+
1020
+
1021
+
1022
+
1023
+
1024
+
1025
+
707
1026
  * @example
708
1027
  * // Heap for event processing with priority
709
1028
  * interface Event {
@@ -780,6 +1099,30 @@ var Heap = class _Heap extends IterableElementBase {
780
1099
 
781
1100
 
782
1101
 
1102
+
1103
+
1104
+
1105
+
1106
+
1107
+
1108
+
1109
+
1110
+
1111
+
1112
+
1113
+
1114
+
1115
+
1116
+
1117
+
1118
+
1119
+
1120
+
1121
+
1122
+
1123
+
1124
+
1125
+
783
1126
  * @example
784
1127
  * // Check if heap is empty
785
1128
  * const heap = new Heap<number>([], { comparator: (a, b) => a - b });
@@ -803,6 +1146,30 @@ var Heap = class _Heap extends IterableElementBase {
803
1146
 
804
1147
 
805
1148
 
1149
+
1150
+
1151
+
1152
+
1153
+
1154
+
1155
+
1156
+
1157
+
1158
+
1159
+
1160
+
1161
+
1162
+
1163
+
1164
+
1165
+
1166
+
1167
+
1168
+
1169
+
1170
+
1171
+
1172
+
806
1173
  * @example
807
1174
  * // Remove all elements
808
1175
  * const heap = new Heap<number>([1, 2, 3], { comparator: (a, b) => a - b });
@@ -829,6 +1196,30 @@ var Heap = class _Heap extends IterableElementBase {
829
1196
  * @returns True if found.
830
1197
 
831
1198
 
1199
+
1200
+
1201
+
1202
+
1203
+
1204
+
1205
+
1206
+
1207
+
1208
+
1209
+
1210
+
1211
+
1212
+
1213
+
1214
+
1215
+
1216
+
1217
+
1218
+
1219
+
1220
+
1221
+
1222
+
832
1223
  * @example
833
1224
  * // Check element existence
834
1225
  * const heap = new Heap<number>([3, 1, 2], { comparator: (a, b) => a - b });
@@ -852,6 +1243,30 @@ var Heap = class _Heap extends IterableElementBase {
852
1243
 
853
1244
 
854
1245
 
1246
+
1247
+
1248
+
1249
+
1250
+
1251
+
1252
+
1253
+
1254
+
1255
+
1256
+
1257
+
1258
+
1259
+
1260
+
1261
+
1262
+
1263
+
1264
+
1265
+
1266
+
1267
+
1268
+
1269
+
855
1270
  * @example
856
1271
  * // Remove specific element
857
1272
  * const heap = new Heap<number>([3, 1, 4, 1, 5], { comparator: (a, b) => a - b });
@@ -921,6 +1336,30 @@ var Heap = class _Heap extends IterableElementBase {
921
1336
  * @returns Array of visited elements.
922
1337
 
923
1338
 
1339
+
1340
+
1341
+
1342
+
1343
+
1344
+
1345
+
1346
+
1347
+
1348
+
1349
+
1350
+
1351
+
1352
+
1353
+
1354
+
1355
+
1356
+
1357
+
1358
+
1359
+
1360
+
1361
+
1362
+
924
1363
  * @example
925
1364
  * // Depth-first traversal
926
1365
  * const heap = new Heap<number>([3, 1, 2], { comparator: (a, b) => a - b });
@@ -977,6 +1416,30 @@ var Heap = class _Heap extends IterableElementBase {
977
1416
 
978
1417
 
979
1418
 
1419
+
1420
+
1421
+
1422
+
1423
+
1424
+
1425
+
1426
+
1427
+
1428
+
1429
+
1430
+
1431
+
1432
+
1433
+
1434
+
1435
+
1436
+
1437
+
1438
+
1439
+
1440
+
1441
+
1442
+
980
1443
  * @example
981
1444
  * // Sort elements using heap
982
1445
  * const heap = new Heap<number>([5, 1, 3, 2, 4]);
@@ -1006,6 +1469,30 @@ var Heap = class _Heap extends IterableElementBase {
1006
1469
 
1007
1470
 
1008
1471
 
1472
+
1473
+
1474
+
1475
+
1476
+
1477
+
1478
+
1479
+
1480
+
1481
+
1482
+
1483
+
1484
+
1485
+
1486
+
1487
+
1488
+
1489
+
1490
+
1491
+
1492
+
1493
+
1494
+
1495
+
1009
1496
  * @example
1010
1497
  * // Create independent copy
1011
1498
  * const heap = new Heap<number>([3, 1, 4], { comparator: (a, b) => a - b });
@@ -1034,6 +1521,30 @@ var Heap = class _Heap extends IterableElementBase {
1034
1521
 
1035
1522
 
1036
1523
 
1524
+
1525
+
1526
+
1527
+
1528
+
1529
+
1530
+
1531
+
1532
+
1533
+
1534
+
1535
+
1536
+
1537
+
1538
+
1539
+
1540
+
1541
+
1542
+
1543
+
1544
+
1545
+
1546
+
1547
+
1037
1548
  * @example
1038
1549
  * // Filter elements
1039
1550
  * const heap = new Heap<number>([1, 2, 3, 4, 5], { comparator: (a, b) => a - b });
@@ -1069,6 +1580,30 @@ var Heap = class _Heap extends IterableElementBase {
1069
1580
 
1070
1581
 
1071
1582
 
1583
+
1584
+
1585
+
1586
+
1587
+
1588
+
1589
+
1590
+
1591
+
1592
+
1593
+
1594
+
1595
+
1596
+
1597
+
1598
+
1599
+
1600
+
1601
+
1602
+
1603
+
1604
+
1605
+
1606
+
1072
1607
  * @example
1073
1608
  * // Transform elements
1074
1609
  * const heap = new Heap<number>([1, 2, 3], { comparator: (a, b) => a - b });
@@ -1077,7 +1612,7 @@ var Heap = class _Heap extends IterableElementBase {
1077
1612
  */
1078
1613
  map(callback, options, thisArg) {
1079
1614
  const { comparator, toElementFn, ...rest } = options ?? {};
1080
- if (!comparator) throw new TypeError(ERR.comparatorRequired("Heap.map"));
1615
+ if (!comparator) raise(TypeError, ERR.comparatorRequired("Heap.map"));
1081
1616
  const out = this._createLike([], { ...rest, comparator, toElementFn });
1082
1617
  let i = 0;
1083
1618
  for (const x of this) {
@@ -1104,7 +1639,7 @@ var Heap = class _Heap extends IterableElementBase {
1104
1639
  }
1105
1640
  _DEFAULT_COMPARATOR = /* @__PURE__ */ __name((a, b) => {
1106
1641
  if (typeof a === "object" || typeof b === "object") {
1107
- throw new TypeError(ERR.comparatorRequired("Heap"));
1642
+ raise(TypeError, ERR.comparatorRequired("Heap"));
1108
1643
  }
1109
1644
  if (a > b) return 1;
1110
1645
  if (a < b) return -1;
@@ -1176,207 +1711,14 @@ var Heap = class _Heap extends IterableElementBase {
1176
1711
  }
1177
1712
  /**
1178
1713
  * (Protected) Spawn an empty like-kind heap instance.
1179
- * @remarks Time O(1), Space O(1)
1180
- * @template EM
1181
- * @template RM
1182
- * @param [options] - Options forwarded to the constructor.
1183
- * @returns An empty like-kind heap instance.
1184
- */
1185
- _spawnLike(options) {
1186
- return this._createLike([], options);
1187
- }
1188
- };
1189
-
1190
- // src/data-structures/base/linear-base.ts
1191
- var LinearBase = class _LinearBase extends IterableElementBase {
1192
- static {
1193
- __name(this, "LinearBase");
1194
- }
1195
- /**
1196
- * Construct a linear container with runtime options.
1197
- * @param options - `{ maxLen?, ... }` bounds/behavior options.
1198
- * @remarks Time O(1), Space O(1)
1199
- */
1200
- constructor(options) {
1201
- super(options);
1202
- if (options) {
1203
- const { maxLen } = options;
1204
- if (typeof maxLen === "number" && maxLen > 0 && maxLen % 1 === 0) this._maxLen = maxLen;
1205
- }
1206
- }
1207
- _maxLen = -1;
1208
- /**
1209
- * Upper bound for length (if positive), or `-1` when unbounded.
1210
- * @returns Maximum allowed length.
1211
- * @remarks Time O(1), Space O(1)
1212
- */
1213
- get maxLen() {
1214
- return this._maxLen;
1215
- }
1216
- /**
1217
- * First index of a value from the left.
1218
- * @param searchElement - Value to match.
1219
- * @param fromIndex - Start position (supports negative index).
1220
- * @returns Index or `-1` if not found.
1221
- * @remarks Time O(n), Space O(1)
1222
- */
1223
- indexOf(searchElement, fromIndex = 0) {
1224
- if (this.length === 0) return -1;
1225
- if (fromIndex < 0) fromIndex = this.length + fromIndex;
1226
- if (fromIndex < 0) fromIndex = 0;
1227
- for (let i = fromIndex; i < this.length; i++) {
1228
- const element = this.at(i);
1229
- if (element === searchElement) return i;
1230
- }
1231
- return -1;
1232
- }
1233
- /**
1234
- * Last index of a value from the right.
1235
- * @param searchElement - Value to match.
1236
- * @param fromIndex - Start position (supports negative index).
1237
- * @returns Index or `-1` if not found.
1238
- * @remarks Time O(n), Space O(1)
1239
- */
1240
- lastIndexOf(searchElement, fromIndex = this.length - 1) {
1241
- if (this.length === 0) return -1;
1242
- if (fromIndex >= this.length) fromIndex = this.length - 1;
1243
- if (fromIndex < 0) fromIndex = this.length + fromIndex;
1244
- for (let i = fromIndex; i >= 0; i--) {
1245
- const element = this.at(i);
1246
- if (element === searchElement) return i;
1247
- }
1248
- return -1;
1249
- }
1250
- /**
1251
- * Find the first index matching a predicate.
1252
- * @param predicate - `(element, index, self) => boolean`.
1253
- * @param thisArg - Optional `this` for callback.
1254
- * @returns Index or `-1`.
1255
- * @remarks Time O(n), Space O(1)
1256
- */
1257
- findIndex(predicate, thisArg) {
1258
- for (let i = 0; i < this.length; i++) {
1259
- const item = this.at(i);
1260
- if (item !== void 0 && predicate.call(thisArg, item, i, this)) return i;
1261
- }
1262
- return -1;
1263
- }
1264
- /**
1265
- * Concatenate elements and/or containers.
1266
- * @param items - Elements or other containers.
1267
- * @returns New container with combined elements (`this` type).
1268
- * @remarks Time O(sum(length)), Space O(sum(length))
1269
- */
1270
- concat(...items) {
1271
- const newList = this.clone();
1272
- for (const item of items) {
1273
- if (item instanceof _LinearBase) {
1274
- newList.pushMany(item);
1275
- } else {
1276
- newList.push(item);
1277
- }
1278
- }
1279
- return newList;
1280
- }
1281
- /**
1282
- * In-place stable order via array sort semantics.
1283
- * @param compareFn - Comparator `(a, b) => number`.
1284
- * @returns This container.
1285
- * @remarks Time O(n log n), Space O(n) (materializes to array temporarily)
1286
- */
1287
- sort(compareFn) {
1288
- const arr = this.toArray();
1289
- arr.sort(compareFn);
1290
- this.clear();
1291
- for (const item of arr) this.push(item);
1292
- return this;
1293
- }
1294
- /**
1295
- * Remove and/or insert elements at a position (array-compatible).
1296
- * @param start - Start index (supports negative index).
1297
- * @param deleteCount - How many to remove.
1298
- * @param items - Elements to insert.
1299
- * @returns Removed elements as a new list (`this` type).
1300
- * @remarks Time O(n + m), Space O(min(n, m)) where `m = items.length`
1301
- */
1302
- splice(start, deleteCount = 0, ...items) {
1303
- const removedList = this._createInstance();
1304
- start = start < 0 ? this.length + start : start;
1305
- start = Math.max(0, Math.min(start, this.length));
1306
- deleteCount = Math.max(0, Math.min(deleteCount, this.length - start));
1307
- for (let i = 0; i < deleteCount; i++) {
1308
- const removed = this.deleteAt(start);
1309
- if (removed !== void 0) {
1310
- removedList.push(removed);
1311
- }
1312
- }
1313
- for (let i = 0; i < items.length; i++) {
1314
- this.addAt(start + i, items[i]);
1315
- }
1316
- return removedList;
1317
- }
1318
- /**
1319
- * Join all elements into a string.
1320
- * @param separator - Separator string.
1321
- * @returns Concatenated string.
1322
- * @remarks Time O(n), Space O(n)
1323
- */
1324
- join(separator = ",") {
1325
- return this.toArray().join(separator);
1326
- }
1327
- /**
1328
- * Snapshot elements into a reversed array.
1329
- * @returns New reversed array.
1330
- * @remarks Time O(n), Space O(n)
1331
- */
1332
- toReversedArray() {
1333
- const array = [];
1334
- for (let i = this.length - 1; i >= 0; i--) {
1335
- array.push(this.at(i));
1336
- }
1337
- return array;
1338
- }
1339
- reduceRight(callbackfn, initialValue) {
1340
- let accumulator = initialValue ?? 0;
1341
- for (let i = this.length - 1; i >= 0; i--) {
1342
- accumulator = callbackfn(accumulator, this.at(i), i, this);
1343
- }
1344
- return accumulator;
1345
- }
1346
- /**
1347
- * Create a shallow copy of a subrange.
1348
- * @param start - Inclusive start (supports negative index).
1349
- * @param end - Exclusive end (supports negative index).
1350
- * @returns New list with the range (`this` type).
1351
- * @remarks Time O(n), Space O(n)
1352
- */
1353
- slice(start = 0, end = this.length) {
1354
- start = start < 0 ? this.length + start : start;
1355
- end = end < 0 ? this.length + end : end;
1356
- const newList = this._createInstance();
1357
- for (let i = start; i < end; i++) {
1358
- newList.push(this.at(i));
1359
- }
1360
- return newList;
1361
- }
1362
- /**
1363
- * Fill a range with a value.
1364
- * @param value - Value to set.
1365
- * @param start - Inclusive start.
1366
- * @param end - Exclusive end.
1367
- * @returns This list.
1368
- * @remarks Time O(n), Space O(1)
1369
- */
1370
- fill(value, start = 0, end = this.length) {
1371
- start = start < 0 ? this.length + start : start;
1372
- end = end < 0 ? this.length + end : end;
1373
- if (start < 0) start = 0;
1374
- if (end > this.length) end = this.length;
1375
- if (start >= end) return this;
1376
- for (let i = start; i < end; i++) {
1377
- this.setAt(i, value);
1378
- }
1379
- return this;
1714
+ * @remarks Time O(1), Space O(1)
1715
+ * @template EM
1716
+ * @template RM
1717
+ * @param [options] - Options forwarded to the constructor.
1718
+ * @returns An empty like-kind heap instance.
1719
+ */
1720
+ _spawnLike(options) {
1721
+ return this._createLike([], options);
1380
1722
  }
1381
1723
  };
1382
1724
 
@@ -1451,6 +1793,30 @@ var Queue = class _Queue extends LinearBase {
1451
1793
 
1452
1794
 
1453
1795
 
1796
+
1797
+
1798
+
1799
+
1800
+
1801
+
1802
+
1803
+
1804
+
1805
+
1806
+
1807
+
1808
+
1809
+
1810
+
1811
+
1812
+
1813
+
1814
+
1815
+
1816
+
1817
+
1818
+
1819
+
1454
1820
  * @example
1455
1821
  * // Track queue length
1456
1822
  * const q = new Queue<number>();
@@ -1477,6 +1843,30 @@ var Queue = class _Queue extends LinearBase {
1477
1843
 
1478
1844
 
1479
1845
 
1846
+
1847
+
1848
+
1849
+
1850
+
1851
+
1852
+
1853
+
1854
+
1855
+
1856
+
1857
+
1858
+
1859
+
1860
+
1861
+
1862
+
1863
+
1864
+
1865
+
1866
+
1867
+
1868
+
1869
+
1480
1870
  * @example
1481
1871
  * // View the front element
1482
1872
  * const q = new Queue<string>(['first', 'second', 'third']);
@@ -1519,6 +1909,30 @@ var Queue = class _Queue extends LinearBase {
1519
1909
 
1520
1910
 
1521
1911
 
1912
+
1913
+
1914
+
1915
+
1916
+
1917
+
1918
+
1919
+
1920
+
1921
+
1922
+
1923
+
1924
+
1925
+
1926
+
1927
+
1928
+
1929
+
1930
+
1931
+
1932
+
1933
+
1934
+
1935
+
1522
1936
  * @example
1523
1937
  * // Queue for...of iteration and isEmpty check
1524
1938
  * const queue = new Queue<string>(['A', 'B', 'C', 'D']);
@@ -1557,6 +1971,30 @@ var Queue = class _Queue extends LinearBase {
1557
1971
 
1558
1972
 
1559
1973
 
1974
+
1975
+
1976
+
1977
+
1978
+
1979
+
1980
+
1981
+
1982
+
1983
+
1984
+
1985
+
1986
+
1987
+
1988
+
1989
+
1990
+
1991
+
1992
+
1993
+
1994
+
1995
+
1996
+
1997
+
1560
1998
  * @example
1561
1999
  * // basic Queue creation and push operation
1562
2000
  * // Create a simple Queue with initial values
@@ -1602,6 +2040,30 @@ var Queue = class _Queue extends LinearBase {
1602
2040
 
1603
2041
 
1604
2042
 
2043
+
2044
+
2045
+
2046
+
2047
+
2048
+
2049
+
2050
+
2051
+
2052
+
2053
+
2054
+
2055
+
2056
+
2057
+
2058
+
2059
+
2060
+
2061
+
2062
+
2063
+
2064
+
2065
+
2066
+
1605
2067
  * @example
1606
2068
  * // Queue shift and peek operations
1607
2069
  * const queue = new Queue<number>([10, 20, 30, 40]);
@@ -1637,6 +2099,30 @@ var Queue = class _Queue extends LinearBase {
1637
2099
 
1638
2100
 
1639
2101
 
2102
+
2103
+
2104
+
2105
+
2106
+
2107
+
2108
+
2109
+
2110
+
2111
+
2112
+
2113
+
2114
+
2115
+
2116
+
2117
+
2118
+
2119
+
2120
+
2121
+
2122
+
2123
+
2124
+
2125
+
1640
2126
  * @example
1641
2127
  * // Remove specific element
1642
2128
  * const q = new Queue<number>([1, 2, 3, 2]);
@@ -1665,6 +2151,30 @@ var Queue = class _Queue extends LinearBase {
1665
2151
 
1666
2152
 
1667
2153
 
2154
+
2155
+
2156
+
2157
+
2158
+
2159
+
2160
+
2161
+
2162
+
2163
+
2164
+
2165
+
2166
+
2167
+
2168
+
2169
+
2170
+
2171
+
2172
+
2173
+
2174
+
2175
+
2176
+
2177
+
1668
2178
  * @example
1669
2179
  * // Access element by index
1670
2180
  * const q = new Queue<string>(['a', 'b', 'c']);
@@ -1734,6 +2244,30 @@ var Queue = class _Queue extends LinearBase {
1734
2244
 
1735
2245
 
1736
2246
 
2247
+
2248
+
2249
+
2250
+
2251
+
2252
+
2253
+
2254
+
2255
+
2256
+
2257
+
2258
+
2259
+
2260
+
2261
+
2262
+
2263
+
2264
+
2265
+
2266
+
2267
+
2268
+
2269
+
2270
+
1737
2271
  * @example
1738
2272
  * // Remove all elements
1739
2273
  * const q = new Queue<number>([1, 2, 3]);
@@ -1756,6 +2290,30 @@ var Queue = class _Queue extends LinearBase {
1756
2290
 
1757
2291
 
1758
2292
 
2293
+
2294
+
2295
+
2296
+
2297
+
2298
+
2299
+
2300
+
2301
+
2302
+
2303
+
2304
+
2305
+
2306
+
2307
+
2308
+
2309
+
2310
+
2311
+
2312
+
2313
+
2314
+
2315
+
2316
+
1759
2317
  * @example
1760
2318
  * // Reclaim unused memory
1761
2319
  * const q = new Queue<number>([1, 2, 3, 4, 5]);
@@ -1801,6 +2359,30 @@ var Queue = class _Queue extends LinearBase {
1801
2359
 
1802
2360
 
1803
2361
 
2362
+
2363
+
2364
+
2365
+
2366
+
2367
+
2368
+
2369
+
2370
+
2371
+
2372
+
2373
+
2374
+
2375
+
2376
+
2377
+
2378
+
2379
+
2380
+
2381
+
2382
+
2383
+
2384
+
2385
+
1804
2386
  * @example
1805
2387
  * // Create independent copy
1806
2388
  * const q = new Queue<number>([1, 2, 3]);
@@ -1830,6 +2412,30 @@ var Queue = class _Queue extends LinearBase {
1830
2412
 
1831
2413
 
1832
2414
 
2415
+
2416
+
2417
+
2418
+
2419
+
2420
+
2421
+
2422
+
2423
+
2424
+
2425
+
2426
+
2427
+
2428
+
2429
+
2430
+
2431
+
2432
+
2433
+
2434
+
2435
+
2436
+
2437
+
2438
+
1833
2439
  * @example
1834
2440
  * // Filter elements
1835
2441
  * const q = new Queue<number>([1, 2, 3, 4, 5]);
@@ -1863,6 +2469,30 @@ var Queue = class _Queue extends LinearBase {
1863
2469
 
1864
2470
 
1865
2471
 
2472
+
2473
+
2474
+
2475
+
2476
+
2477
+
2478
+
2479
+
2480
+
2481
+
2482
+
2483
+
2484
+
2485
+
2486
+
2487
+
2488
+
2489
+
2490
+
2491
+
2492
+
2493
+
2494
+
2495
+
1866
2496
  * @example
1867
2497
  * // Transform elements
1868
2498
  * const q = new Queue<number>([1, 2, 3]);
@@ -2098,7 +2728,7 @@ var AbstractGraph = class extends IterableEntryBase {
2098
2728
  const newEdge = this.createEdge(srcOrEdge, dest, weight, value);
2099
2729
  return this._addEdge(newEdge);
2100
2730
  } else {
2101
- throw new TypeError(ERR.invalidArgument("dest must be a Vertex or vertex key when srcOrEdge is an Edge.", "Graph"));
2731
+ raise(TypeError, ERR.invalidArgument("dest must be a Vertex or vertex key when srcOrEdge is an Edge.", "Graph"));
2102
2732
  }
2103
2733
  }
2104
2734
  }
@@ -2967,6 +3597,30 @@ var UndirectedGraph = class _UndirectedGraph extends AbstractGraph {
2967
3597
 
2968
3598
 
2969
3599
 
3600
+
3601
+
3602
+
3603
+
3604
+
3605
+
3606
+
3607
+
3608
+
3609
+
3610
+
3611
+
3612
+
3613
+
3614
+
3615
+
3616
+
3617
+
3618
+
3619
+
3620
+
3621
+
3622
+
3623
+
2970
3624
  * @example
2971
3625
  * // Get edge between vertices
2972
3626
  * const g = new UndirectedGraph();
@@ -3027,6 +3681,30 @@ var UndirectedGraph = class _UndirectedGraph extends AbstractGraph {
3027
3681
 
3028
3682
 
3029
3683
 
3684
+
3685
+
3686
+
3687
+
3688
+
3689
+
3690
+
3691
+
3692
+
3693
+
3694
+
3695
+
3696
+
3697
+
3698
+
3699
+
3700
+
3701
+
3702
+
3703
+
3704
+
3705
+
3706
+
3707
+
3030
3708
  * @example
3031
3709
  * // UndirectedGraph deleteEdge and vertex operations
3032
3710
  * const graph = new UndirectedGraph<string>();
@@ -3087,6 +3765,30 @@ var UndirectedGraph = class _UndirectedGraph extends AbstractGraph {
3087
3765
 
3088
3766
 
3089
3767
 
3768
+
3769
+
3770
+
3771
+
3772
+
3773
+
3774
+
3775
+
3776
+
3777
+
3778
+
3779
+
3780
+
3781
+
3782
+
3783
+
3784
+
3785
+
3786
+
3787
+
3788
+
3789
+
3790
+
3791
+
3090
3792
  * @example
3091
3793
  * // Remove vertex and edges
3092
3794
  * const g = new UndirectedGraph();
@@ -3161,6 +3863,30 @@ var UndirectedGraph = class _UndirectedGraph extends AbstractGraph {
3161
3863
 
3162
3864
 
3163
3865
 
3866
+
3867
+
3868
+
3869
+
3870
+
3871
+
3872
+
3873
+
3874
+
3875
+
3876
+
3877
+
3878
+
3879
+
3880
+
3881
+
3882
+
3883
+
3884
+
3885
+
3886
+
3887
+
3888
+
3889
+
3164
3890
  * @example
3165
3891
  * // Get all edges
3166
3892
  * const g = new UndirectedGraph();
@@ -3191,6 +3917,30 @@ var UndirectedGraph = class _UndirectedGraph extends AbstractGraph {
3191
3917
 
3192
3918
 
3193
3919
 
3920
+
3921
+
3922
+
3923
+
3924
+
3925
+
3926
+
3927
+
3928
+
3929
+
3930
+
3931
+
3932
+
3933
+
3934
+
3935
+
3936
+
3937
+
3938
+
3939
+
3940
+
3941
+
3942
+
3943
+
3194
3944
  * @example
3195
3945
  * // UndirectedGraph connectivity and neighbors
3196
3946
  * const graph = new UndirectedGraph<string>();
@@ -3291,6 +4041,30 @@ var UndirectedGraph = class _UndirectedGraph extends AbstractGraph {
3291
4041
 
3292
4042
 
3293
4043
 
4044
+
4045
+
4046
+
4047
+
4048
+
4049
+
4050
+
4051
+
4052
+
4053
+
4054
+
4055
+
4056
+
4057
+
4058
+
4059
+
4060
+
4061
+
4062
+
4063
+
4064
+
4065
+
4066
+
4067
+
3294
4068
  * @example
3295
4069
  * // Find articulation points and bridges
3296
4070
  * const g = new UndirectedGraph();
@@ -3413,6 +4187,30 @@ var UndirectedGraph = class _UndirectedGraph extends AbstractGraph {
3413
4187
 
3414
4188
 
3415
4189
 
4190
+
4191
+
4192
+
4193
+
4194
+
4195
+
4196
+
4197
+
4198
+
4199
+
4200
+
4201
+
4202
+
4203
+
4204
+
4205
+
4206
+
4207
+
4208
+
4209
+
4210
+
4211
+
4212
+
4213
+
3416
4214
  * @example
3417
4215
  * // Detect cycle
3418
4216
  * const g = new UndirectedGraph();
@@ -3457,6 +4255,30 @@ var UndirectedGraph = class _UndirectedGraph extends AbstractGraph {
3457
4255
 
3458
4256
 
3459
4257
 
4258
+
4259
+
4260
+
4261
+
4262
+
4263
+
4264
+
4265
+
4266
+
4267
+
4268
+
4269
+
4270
+
4271
+
4272
+
4273
+
4274
+
4275
+
4276
+
4277
+
4278
+
4279
+
4280
+
4281
+
3460
4282
  * @example
3461
4283
  * // Find bridge edges
3462
4284
  * const g = new UndirectedGraph();
@@ -3483,6 +4305,30 @@ var UndirectedGraph = class _UndirectedGraph extends AbstractGraph {
3483
4305
 
3484
4306
 
3485
4307
 
4308
+
4309
+
4310
+
4311
+
4312
+
4313
+
4314
+
4315
+
4316
+
4317
+
4318
+
4319
+
4320
+
4321
+
4322
+
4323
+
4324
+
4325
+
4326
+
4327
+
4328
+
4329
+
4330
+
4331
+
3486
4332
  * @example
3487
4333
  * // Find articulation points
3488
4334
  * const g = new UndirectedGraph();
@@ -3550,5 +4396,6 @@ exports.Range = Range;
3550
4396
  exports.UndirectedEdge = UndirectedEdge;
3551
4397
  exports.UndirectedGraph = UndirectedGraph;
3552
4398
  exports.UndirectedVertex = UndirectedVertex;
4399
+ exports.raise = raise;
3553
4400
  //# sourceMappingURL=index.cjs.map
3554
4401
  //# sourceMappingURL=index.cjs.map