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