directed-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 +1089 -218
  2. package/dist/cjs/index.cjs.map +1 -1
  3. package/dist/cjs-legacy/index.cjs +1069 -198
  4. package/dist/cjs-legacy/index.cjs.map +1 -1
  5. package/dist/esm/index.mjs +1089 -219
  6. package/dist/esm/index.mjs.map +1 -1
  7. package/dist/esm-legacy/index.mjs +1069 -199
  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/directed-graph-typed.js +1067 -197
  47. package/dist/umd/directed-graph-typed.js.map +1 -1
  48. package/dist/umd/directed-graph-typed.min.js +2 -2
  49. package/dist/umd/directed-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,25 +1469,73 @@ var Heap = class _Heap extends IterableElementBase {
1006
1469
 
1007
1470
 
1008
1471
 
1009
- * @example
1010
- * // Create independent copy
1011
- * const heap = new Heap<number>([3, 1, 4], { comparator: (a, b) => a - b });
1012
- * const copy = heap.clone();
1013
- * copy.poll();
1014
- * console.log(heap.size); // 3;
1015
- * console.log(copy.size); // 2;
1016
- */
1017
- clone() {
1018
- const next = this._createInstance();
1019
- for (const x of this.elements) next.add(x);
1020
- return next;
1021
- }
1022
- /**
1023
- * Filter elements into a new heap of the same class.
1024
- * @remarks Time O(N log N), Space O(N)
1025
- * @param callback - Predicate (element, index, heap) → boolean to keep element.
1026
- * @param [thisArg] - Value for `this` inside the callback.
1027
- * @returns A new heap with the kept elements.
1472
+
1473
+
1474
+
1475
+
1476
+
1477
+
1478
+
1479
+
1480
+
1481
+
1482
+
1483
+
1484
+
1485
+
1486
+
1487
+
1488
+
1489
+
1490
+
1491
+
1492
+
1493
+
1494
+
1495
+
1496
+ * @example
1497
+ * // Create independent copy
1498
+ * const heap = new Heap<number>([3, 1, 4], { comparator: (a, b) => a - b });
1499
+ * const copy = heap.clone();
1500
+ * copy.poll();
1501
+ * console.log(heap.size); // 3;
1502
+ * console.log(copy.size); // 2;
1503
+ */
1504
+ clone() {
1505
+ const next = this._createInstance();
1506
+ for (const x of this.elements) next.add(x);
1507
+ return next;
1508
+ }
1509
+ /**
1510
+ * Filter elements into a new heap of the same class.
1511
+ * @remarks Time O(N log N), Space O(N)
1512
+ * @param callback - Predicate (element, index, heap) → boolean to keep element.
1513
+ * @param [thisArg] - Value for `this` inside the callback.
1514
+ * @returns A new heap with the kept elements.
1515
+
1516
+
1517
+
1518
+
1519
+
1520
+
1521
+
1522
+
1523
+
1524
+
1525
+
1526
+
1527
+
1528
+
1529
+
1530
+
1531
+
1532
+
1533
+
1534
+
1535
+
1536
+
1537
+
1538
+
1028
1539
 
1029
1540
 
1030
1541
 
@@ -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;
@@ -1187,199 +1722,6 @@ var Heap = class _Heap extends IterableElementBase {
1187
1722
  }
1188
1723
  };
1189
1724
 
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;
1380
- }
1381
- };
1382
-
1383
1725
  // src/data-structures/queue/queue.ts
1384
1726
  var Queue = class _Queue extends LinearBase {
1385
1727
  static {
@@ -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
  }
@@ -2978,6 +3608,30 @@ var DirectedGraph = class _DirectedGraph extends AbstractGraph {
2978
3608
 
2979
3609
 
2980
3610
 
3611
+
3612
+
3613
+
3614
+
3615
+
3616
+
3617
+
3618
+
3619
+
3620
+
3621
+
3622
+
3623
+
3624
+
3625
+
3626
+
3627
+
3628
+
3629
+
3630
+
3631
+
3632
+
3633
+
3634
+
2981
3635
  * @example
2982
3636
  * // Get edge between vertices
2983
3637
  * const g = new DirectedGraph();
@@ -3042,6 +3696,30 @@ var DirectedGraph = class _DirectedGraph extends AbstractGraph {
3042
3696
 
3043
3697
 
3044
3698
 
3699
+
3700
+
3701
+
3702
+
3703
+
3704
+
3705
+
3706
+
3707
+
3708
+
3709
+
3710
+
3711
+
3712
+
3713
+
3714
+
3715
+
3716
+
3717
+
3718
+
3719
+
3720
+
3721
+
3722
+
3045
3723
  * @example
3046
3724
  * // DirectedGraph deleteEdge and vertex operations
3047
3725
  * const graph = new DirectedGraph<string>();
@@ -3104,6 +3782,30 @@ var DirectedGraph = class _DirectedGraph extends AbstractGraph {
3104
3782
 
3105
3783
 
3106
3784
 
3785
+
3786
+
3787
+
3788
+
3789
+
3790
+
3791
+
3792
+
3793
+
3794
+
3795
+
3796
+
3797
+
3798
+
3799
+
3800
+
3801
+
3802
+
3803
+
3804
+
3805
+
3806
+
3807
+
3808
+
3107
3809
  * @example
3108
3810
  * // Remove a vertex
3109
3811
  * const g = new DirectedGraph();
@@ -3157,6 +3859,30 @@ var DirectedGraph = class _DirectedGraph extends AbstractGraph {
3157
3859
 
3158
3860
 
3159
3861
 
3862
+
3863
+
3864
+
3865
+
3866
+
3867
+
3868
+
3869
+
3870
+
3871
+
3872
+
3873
+
3874
+
3875
+
3876
+
3877
+
3878
+
3879
+
3880
+
3881
+
3882
+
3883
+
3884
+
3885
+
3160
3886
  * @example
3161
3887
  * // Get incoming edges
3162
3888
  * const g = new DirectedGraph();
@@ -3187,6 +3913,30 @@ var DirectedGraph = class _DirectedGraph extends AbstractGraph {
3187
3913
 
3188
3914
 
3189
3915
 
3916
+
3917
+
3918
+
3919
+
3920
+
3921
+
3922
+
3923
+
3924
+
3925
+
3926
+
3927
+
3928
+
3929
+
3930
+
3931
+
3932
+
3933
+
3934
+
3935
+
3936
+
3937
+
3938
+
3939
+
3190
3940
  * @example
3191
3941
  * // Get outgoing edges
3192
3942
  * const g = new DirectedGraph();
@@ -3270,6 +4020,30 @@ var DirectedGraph = class _DirectedGraph extends AbstractGraph {
3270
4020
 
3271
4021
 
3272
4022
 
4023
+
4024
+
4025
+
4026
+
4027
+
4028
+
4029
+
4030
+
4031
+
4032
+
4033
+
4034
+
4035
+
4036
+
4037
+
4038
+
4039
+
4040
+
4041
+
4042
+
4043
+
4044
+
4045
+
4046
+
3273
4047
  * @example
3274
4048
  * // DirectedGraph topologicalSort for task scheduling
3275
4049
  * const graph = new DirectedGraph<string>();
@@ -3334,6 +4108,30 @@ var DirectedGraph = class _DirectedGraph extends AbstractGraph {
3334
4108
 
3335
4109
 
3336
4110
 
4111
+
4112
+
4113
+
4114
+
4115
+
4116
+
4117
+
4118
+
4119
+
4120
+
4121
+
4122
+
4123
+
4124
+
4125
+
4126
+
4127
+
4128
+
4129
+
4130
+
4131
+
4132
+
4133
+
4134
+
3337
4135
  * @example
3338
4136
  * // Get all edges
3339
4137
  * const g = new DirectedGraph();
@@ -3360,6 +4158,30 @@ var DirectedGraph = class _DirectedGraph extends AbstractGraph {
3360
4158
 
3361
4159
 
3362
4160
 
4161
+
4162
+
4163
+
4164
+
4165
+
4166
+
4167
+
4168
+
4169
+
4170
+
4171
+
4172
+
4173
+
4174
+
4175
+
4176
+
4177
+
4178
+
4179
+
4180
+
4181
+
4182
+
4183
+
4184
+
3363
4185
  * @example
3364
4186
  * // Get outgoing neighbors
3365
4187
  * const g = new DirectedGraph();
@@ -3439,6 +4261,30 @@ var DirectedGraph = class _DirectedGraph extends AbstractGraph {
3439
4261
 
3440
4262
 
3441
4263
 
4264
+
4265
+
4266
+
4267
+
4268
+
4269
+
4270
+
4271
+
4272
+
4273
+
4274
+
4275
+
4276
+
4277
+
4278
+
4279
+
4280
+
4281
+
4282
+
4283
+
4284
+
4285
+
4286
+
4287
+
3442
4288
  * @example
3443
4289
  * // Find strongly connected components
3444
4290
  * const g = new DirectedGraph();
@@ -3521,6 +4367,30 @@ var DirectedGraph = class _DirectedGraph extends AbstractGraph {
3521
4367
 
3522
4368
 
3523
4369
 
4370
+
4371
+
4372
+
4373
+
4374
+
4375
+
4376
+
4377
+
4378
+
4379
+
4380
+
4381
+
4382
+
4383
+
4384
+
4385
+
4386
+
4387
+
4388
+
4389
+
4390
+
4391
+
4392
+
4393
+
3524
4394
  * @example
3525
4395
  * // Get strongly connected components
3526
4396
  * const g = new DirectedGraph();
@@ -3584,5 +4454,6 @@ exports.DirectedGraph = DirectedGraph;
3584
4454
  exports.DirectedVertex = DirectedVertex;
3585
4455
  exports.ERR = ERR;
3586
4456
  exports.Range = Range;
4457
+ exports.raise = raise;
3587
4458
  //# sourceMappingURL=index.cjs.map
3588
4459
  //# sourceMappingURL=index.cjs.map