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.
- package/dist/cjs/index.cjs +1054 -207
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs-legacy/index.cjs +1051 -204
- package/dist/cjs-legacy/index.cjs.map +1 -1
- package/dist/esm/index.mjs +1054 -208
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm-legacy/index.mjs +1051 -205
- package/dist/esm-legacy/index.mjs.map +1 -1
- package/dist/types/common/error.d.ts +9 -0
- package/dist/types/common/index.d.ts +1 -1
- package/dist/types/data-structures/base/index.d.ts +1 -0
- package/dist/types/data-structures/base/iterable-entry-base.d.ts +8 -8
- package/dist/types/data-structures/base/linear-base.d.ts +3 -3
- package/dist/types/data-structures/binary-tree/avl-tree.d.ts +288 -0
- package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +336 -0
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +618 -18
- package/dist/types/data-structures/binary-tree/bst.d.ts +676 -1
- package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +456 -0
- package/dist/types/data-structures/binary-tree/segment-tree.d.ts +144 -1
- package/dist/types/data-structures/binary-tree/tree-map.d.ts +3307 -399
- package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +3285 -360
- package/dist/types/data-structures/binary-tree/tree-multi-set.d.ts +2674 -325
- package/dist/types/data-structures/binary-tree/tree-set.d.ts +3072 -287
- package/dist/types/data-structures/graph/abstract-graph.d.ts +4 -4
- package/dist/types/data-structures/graph/directed-graph.d.ts +240 -0
- package/dist/types/data-structures/graph/undirected-graph.d.ts +216 -0
- package/dist/types/data-structures/hash/hash-map.d.ts +274 -10
- package/dist/types/data-structures/heap/heap.d.ts +336 -0
- package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +411 -3
- package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +363 -3
- package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +434 -2
- package/dist/types/data-structures/matrix/matrix.d.ts +192 -0
- package/dist/types/data-structures/queue/deque.d.ts +364 -4
- package/dist/types/data-structures/queue/queue.d.ts +288 -0
- package/dist/types/data-structures/stack/stack.d.ts +240 -0
- package/dist/types/data-structures/trie/trie.d.ts +292 -4
- package/dist/types/interfaces/graph.d.ts +1 -1
- package/dist/types/types/common.d.ts +2 -2
- package/dist/types/types/data-structures/binary-tree/bst.d.ts +1 -0
- package/dist/types/types/data-structures/binary-tree/tree-map.d.ts +5 -0
- package/dist/types/types/data-structures/binary-tree/tree-multi-set.d.ts +4 -0
- package/dist/types/types/data-structures/binary-tree/tree-set.d.ts +4 -0
- package/dist/types/types/data-structures/heap/heap.d.ts +1 -0
- package/dist/types/types/data-structures/priority-queue/priority-queue.d.ts +1 -0
- package/dist/types/types/utils/validate-type.d.ts +4 -4
- package/dist/umd/undirected-graph-typed.js +1051 -205
- package/dist/umd/undirected-graph-typed.js.map +1 -1
- package/dist/umd/undirected-graph-typed.min.js +3 -3
- package/dist/umd/undirected-graph-typed.min.js.map +1 -1
- package/package.json +2 -2
- package/src/common/error.ts +19 -1
- package/src/common/index.ts +1 -1
- package/src/data-structures/base/index.ts +1 -0
- package/src/data-structures/base/iterable-element-base.ts +3 -2
- package/src/data-structures/base/iterable-entry-base.ts +8 -8
- package/src/data-structures/base/linear-base.ts +3 -3
- package/src/data-structures/binary-tree/avl-tree.ts +299 -0
- package/src/data-structures/binary-tree/binary-indexed-tree.ts +341 -5
- package/src/data-structures/binary-tree/binary-tree.ts +606 -6
- package/src/data-structures/binary-tree/bst.ts +946 -7
- package/src/data-structures/binary-tree/red-black-tree.ts +472 -0
- package/src/data-structures/binary-tree/segment-tree.ts +145 -2
- package/src/data-structures/binary-tree/tree-map.ts +3423 -499
- package/src/data-structures/binary-tree/tree-multi-map.ts +3537 -596
- package/src/data-structures/binary-tree/tree-multi-set.ts +2855 -495
- package/src/data-structures/binary-tree/tree-set.ts +3209 -413
- package/src/data-structures/graph/abstract-graph.ts +6 -6
- package/src/data-structures/graph/directed-graph.ts +240 -0
- package/src/data-structures/graph/undirected-graph.ts +216 -0
- package/src/data-structures/hash/hash-map.ts +281 -19
- package/src/data-structures/heap/heap.ts +340 -4
- package/src/data-structures/heap/max-heap.ts +2 -2
- package/src/data-structures/linked-list/doubly-linked-list.ts +411 -3
- package/src/data-structures/linked-list/singly-linked-list.ts +363 -3
- package/src/data-structures/linked-list/skip-linked-list.ts +439 -7
- package/src/data-structures/matrix/matrix.ts +202 -10
- package/src/data-structures/priority-queue/max-priority-queue.ts +2 -2
- package/src/data-structures/queue/deque.ts +365 -5
- package/src/data-structures/queue/queue.ts +288 -0
- package/src/data-structures/stack/stack.ts +240 -0
- package/src/data-structures/trie/trie.ts +295 -7
- package/src/interfaces/graph.ts +1 -1
- package/src/types/common.ts +2 -2
- package/src/types/data-structures/binary-tree/bst.ts +1 -0
- package/src/types/data-structures/binary-tree/tree-map.ts +6 -0
- package/src/types/data-structures/binary-tree/tree-multi-set.ts +5 -0
- package/src/types/data-structures/binary-tree/tree-set.ts +5 -0
- package/src/types/data-structures/heap/heap.ts +1 -0
- package/src/types/data-structures/priority-queue/priority-queue.ts +1 -0
- 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
|
|
@@ -275,7 +281,7 @@ var _IterableElementBase = class _IterableElementBase {
|
|
|
275
281
|
if (options) {
|
|
276
282
|
const { toElementFn } = options;
|
|
277
283
|
if (typeof toElementFn === "function") this._toElementFn = toElementFn;
|
|
278
|
-
else if (toElementFn)
|
|
284
|
+
else if (toElementFn) raise(TypeError, "toElementFn must be a function type");
|
|
279
285
|
}
|
|
280
286
|
}
|
|
281
287
|
/**
|
|
@@ -431,7 +437,7 @@ var _IterableElementBase = class _IterableElementBase {
|
|
|
431
437
|
acc = initialValue;
|
|
432
438
|
} else {
|
|
433
439
|
const first = iter.next();
|
|
434
|
-
if (first.done)
|
|
440
|
+
if (first.done) raise(TypeError, "Reduce of empty structure with no initial value");
|
|
435
441
|
acc = first.value;
|
|
436
442
|
index = 1;
|
|
437
443
|
}
|
|
@@ -475,6 +481,198 @@ var _IterableElementBase = class _IterableElementBase {
|
|
|
475
481
|
__name(_IterableElementBase, "IterableElementBase");
|
|
476
482
|
var IterableElementBase = _IterableElementBase;
|
|
477
483
|
|
|
484
|
+
// src/data-structures/base/linear-base.ts
|
|
485
|
+
var _LinearBase = class _LinearBase extends IterableElementBase {
|
|
486
|
+
/**
|
|
487
|
+
* Construct a linear container with runtime options.
|
|
488
|
+
* @param options - `{ maxLen?, ... }` bounds/behavior options.
|
|
489
|
+
* @remarks Time O(1), Space O(1)
|
|
490
|
+
*/
|
|
491
|
+
constructor(options) {
|
|
492
|
+
super(options);
|
|
493
|
+
__publicField(this, "_maxLen", -1);
|
|
494
|
+
if (options) {
|
|
495
|
+
const { maxLen } = options;
|
|
496
|
+
if (typeof maxLen === "number" && maxLen > 0 && maxLen % 1 === 0) this._maxLen = maxLen;
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
/**
|
|
500
|
+
* Upper bound for length (if positive), or `-1` when unbounded.
|
|
501
|
+
* @returns Maximum allowed length.
|
|
502
|
+
* @remarks Time O(1), Space O(1)
|
|
503
|
+
*/
|
|
504
|
+
get maxLen() {
|
|
505
|
+
return this._maxLen;
|
|
506
|
+
}
|
|
507
|
+
/**
|
|
508
|
+
* First index of a value from the left.
|
|
509
|
+
* @param searchElement - Value to match.
|
|
510
|
+
* @param fromIndex - Start position (supports negative index).
|
|
511
|
+
* @returns Index or `-1` if not found.
|
|
512
|
+
* @remarks Time O(n), Space O(1)
|
|
513
|
+
*/
|
|
514
|
+
indexOf(searchElement, fromIndex = 0) {
|
|
515
|
+
if (this.length === 0) return -1;
|
|
516
|
+
if (fromIndex < 0) fromIndex = this.length + fromIndex;
|
|
517
|
+
if (fromIndex < 0) fromIndex = 0;
|
|
518
|
+
for (let i = fromIndex; i < this.length; i++) {
|
|
519
|
+
const element = this.at(i);
|
|
520
|
+
if (element === searchElement) return i;
|
|
521
|
+
}
|
|
522
|
+
return -1;
|
|
523
|
+
}
|
|
524
|
+
/**
|
|
525
|
+
* Last index of a value from the right.
|
|
526
|
+
* @param searchElement - Value to match.
|
|
527
|
+
* @param fromIndex - Start position (supports negative index).
|
|
528
|
+
* @returns Index or `-1` if not found.
|
|
529
|
+
* @remarks Time O(n), Space O(1)
|
|
530
|
+
*/
|
|
531
|
+
lastIndexOf(searchElement, fromIndex = this.length - 1) {
|
|
532
|
+
if (this.length === 0) return -1;
|
|
533
|
+
if (fromIndex >= this.length) fromIndex = this.length - 1;
|
|
534
|
+
if (fromIndex < 0) fromIndex = this.length + fromIndex;
|
|
535
|
+
for (let i = fromIndex; i >= 0; i--) {
|
|
536
|
+
const element = this.at(i);
|
|
537
|
+
if (element === searchElement) return i;
|
|
538
|
+
}
|
|
539
|
+
return -1;
|
|
540
|
+
}
|
|
541
|
+
/**
|
|
542
|
+
* Find the first index matching a predicate.
|
|
543
|
+
* @param predicate - `(element, index, self) => boolean`.
|
|
544
|
+
* @param thisArg - Optional `this` for callback.
|
|
545
|
+
* @returns Index or `-1`.
|
|
546
|
+
* @remarks Time O(n), Space O(1)
|
|
547
|
+
*/
|
|
548
|
+
findIndex(predicate, thisArg) {
|
|
549
|
+
for (let i = 0; i < this.length; i++) {
|
|
550
|
+
const item = this.at(i);
|
|
551
|
+
if (item !== void 0 && predicate.call(thisArg, item, i, this)) return i;
|
|
552
|
+
}
|
|
553
|
+
return -1;
|
|
554
|
+
}
|
|
555
|
+
/**
|
|
556
|
+
* Concatenate elements and/or containers.
|
|
557
|
+
* @param items - Elements or other containers.
|
|
558
|
+
* @returns New container with combined elements (`this` type).
|
|
559
|
+
* @remarks Time O(sum(length)), Space O(sum(length))
|
|
560
|
+
*/
|
|
561
|
+
concat(...items) {
|
|
562
|
+
const newList = this.clone();
|
|
563
|
+
for (const item of items) {
|
|
564
|
+
if (item instanceof _LinearBase) {
|
|
565
|
+
newList.pushMany(item);
|
|
566
|
+
} else {
|
|
567
|
+
newList.push(item);
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
return newList;
|
|
571
|
+
}
|
|
572
|
+
/**
|
|
573
|
+
* In-place stable order via array sort semantics.
|
|
574
|
+
* @param compareFn - Comparator `(a, b) => number`.
|
|
575
|
+
* @returns This container.
|
|
576
|
+
* @remarks Time O(n log n), Space O(n) (materializes to array temporarily)
|
|
577
|
+
*/
|
|
578
|
+
sort(compareFn) {
|
|
579
|
+
const arr = this.toArray();
|
|
580
|
+
arr.sort(compareFn);
|
|
581
|
+
this.clear();
|
|
582
|
+
for (const item of arr) this.push(item);
|
|
583
|
+
return this;
|
|
584
|
+
}
|
|
585
|
+
/**
|
|
586
|
+
* Remove and/or insert elements at a position (array-compatible).
|
|
587
|
+
* @param start - Start index (supports negative index).
|
|
588
|
+
* @param deleteCount - How many to remove.
|
|
589
|
+
* @param items - Elements to insert.
|
|
590
|
+
* @returns Removed elements as a new list (`this` type).
|
|
591
|
+
* @remarks Time O(n + m), Space O(min(n, m)) where `m = items.length`
|
|
592
|
+
*/
|
|
593
|
+
splice(start, deleteCount = 0, ...items) {
|
|
594
|
+
const removedList = this._createInstance();
|
|
595
|
+
start = start < 0 ? this.length + start : start;
|
|
596
|
+
start = Math.max(0, Math.min(start, this.length));
|
|
597
|
+
deleteCount = Math.max(0, Math.min(deleteCount, this.length - start));
|
|
598
|
+
for (let i = 0; i < deleteCount; i++) {
|
|
599
|
+
const removed = this.deleteAt(start);
|
|
600
|
+
if (removed !== void 0) {
|
|
601
|
+
removedList.push(removed);
|
|
602
|
+
}
|
|
603
|
+
}
|
|
604
|
+
for (let i = 0; i < items.length; i++) {
|
|
605
|
+
this.addAt(start + i, items[i]);
|
|
606
|
+
}
|
|
607
|
+
return removedList;
|
|
608
|
+
}
|
|
609
|
+
/**
|
|
610
|
+
* Join all elements into a string.
|
|
611
|
+
* @param separator - Separator string.
|
|
612
|
+
* @returns Concatenated string.
|
|
613
|
+
* @remarks Time O(n), Space O(n)
|
|
614
|
+
*/
|
|
615
|
+
join(separator = ",") {
|
|
616
|
+
return this.toArray().join(separator);
|
|
617
|
+
}
|
|
618
|
+
/**
|
|
619
|
+
* Snapshot elements into a reversed array.
|
|
620
|
+
* @returns New reversed array.
|
|
621
|
+
* @remarks Time O(n), Space O(n)
|
|
622
|
+
*/
|
|
623
|
+
toReversedArray() {
|
|
624
|
+
const array = [];
|
|
625
|
+
for (let i = this.length - 1; i >= 0; i--) {
|
|
626
|
+
array.push(this.at(i));
|
|
627
|
+
}
|
|
628
|
+
return array;
|
|
629
|
+
}
|
|
630
|
+
reduceRight(callbackfn, initialValue) {
|
|
631
|
+
let accumulator = initialValue != null ? initialValue : 0;
|
|
632
|
+
for (let i = this.length - 1; i >= 0; i--) {
|
|
633
|
+
accumulator = callbackfn(accumulator, this.at(i), i, this);
|
|
634
|
+
}
|
|
635
|
+
return accumulator;
|
|
636
|
+
}
|
|
637
|
+
/**
|
|
638
|
+
* Create a shallow copy of a subrange.
|
|
639
|
+
* @param start - Inclusive start (supports negative index).
|
|
640
|
+
* @param end - Exclusive end (supports negative index).
|
|
641
|
+
* @returns New list with the range (`this` type).
|
|
642
|
+
* @remarks Time O(n), Space O(n)
|
|
643
|
+
*/
|
|
644
|
+
slice(start = 0, end = this.length) {
|
|
645
|
+
start = start < 0 ? this.length + start : start;
|
|
646
|
+
end = end < 0 ? this.length + end : end;
|
|
647
|
+
const newList = this._createInstance();
|
|
648
|
+
for (let i = start; i < end; i++) {
|
|
649
|
+
newList.push(this.at(i));
|
|
650
|
+
}
|
|
651
|
+
return newList;
|
|
652
|
+
}
|
|
653
|
+
/**
|
|
654
|
+
* Fill a range with a value.
|
|
655
|
+
* @param value - Value to set.
|
|
656
|
+
* @param start - Inclusive start.
|
|
657
|
+
* @param end - Exclusive end.
|
|
658
|
+
* @returns This list.
|
|
659
|
+
* @remarks Time O(n), Space O(1)
|
|
660
|
+
*/
|
|
661
|
+
fill(value, start = 0, end = this.length) {
|
|
662
|
+
start = start < 0 ? this.length + start : start;
|
|
663
|
+
end = end < 0 ? this.length + end : end;
|
|
664
|
+
if (start < 0) start = 0;
|
|
665
|
+
if (end > this.length) end = this.length;
|
|
666
|
+
if (start >= end) return this;
|
|
667
|
+
for (let i = start; i < end; i++) {
|
|
668
|
+
this.setAt(i, value);
|
|
669
|
+
}
|
|
670
|
+
return this;
|
|
671
|
+
}
|
|
672
|
+
};
|
|
673
|
+
__name(_LinearBase, "LinearBase");
|
|
674
|
+
var LinearBase = _LinearBase;
|
|
675
|
+
|
|
478
676
|
// src/data-structures/heap/heap.ts
|
|
479
677
|
var _Heap = class _Heap extends IterableElementBase {
|
|
480
678
|
/**
|
|
@@ -490,7 +688,7 @@ var _Heap = class _Heap extends IterableElementBase {
|
|
|
490
688
|
__publicField(this, "_elements", []);
|
|
491
689
|
__publicField(this, "_DEFAULT_COMPARATOR", /* @__PURE__ */ __name((a, b) => {
|
|
492
690
|
if (typeof a === "object" || typeof b === "object") {
|
|
493
|
-
|
|
691
|
+
raise(TypeError, ERR.comparatorRequired("Heap"));
|
|
494
692
|
}
|
|
495
693
|
if (a > b) return 1;
|
|
496
694
|
if (a < b) return -1;
|
|
@@ -526,6 +724,30 @@ var _Heap = class _Heap extends IterableElementBase {
|
|
|
526
724
|
|
|
527
725
|
|
|
528
726
|
|
|
727
|
+
|
|
728
|
+
|
|
729
|
+
|
|
730
|
+
|
|
731
|
+
|
|
732
|
+
|
|
733
|
+
|
|
734
|
+
|
|
735
|
+
|
|
736
|
+
|
|
737
|
+
|
|
738
|
+
|
|
739
|
+
|
|
740
|
+
|
|
741
|
+
|
|
742
|
+
|
|
743
|
+
|
|
744
|
+
|
|
745
|
+
|
|
746
|
+
|
|
747
|
+
|
|
748
|
+
|
|
749
|
+
|
|
750
|
+
|
|
529
751
|
* @example
|
|
530
752
|
* // Track heap capacity
|
|
531
753
|
* const heap = new Heap<number>();
|
|
@@ -589,6 +811,30 @@ var _Heap = class _Heap extends IterableElementBase {
|
|
|
589
811
|
|
|
590
812
|
|
|
591
813
|
|
|
814
|
+
|
|
815
|
+
|
|
816
|
+
|
|
817
|
+
|
|
818
|
+
|
|
819
|
+
|
|
820
|
+
|
|
821
|
+
|
|
822
|
+
|
|
823
|
+
|
|
824
|
+
|
|
825
|
+
|
|
826
|
+
|
|
827
|
+
|
|
828
|
+
|
|
829
|
+
|
|
830
|
+
|
|
831
|
+
|
|
832
|
+
|
|
833
|
+
|
|
834
|
+
|
|
835
|
+
|
|
836
|
+
|
|
837
|
+
|
|
592
838
|
* @example
|
|
593
839
|
* // basic Heap creation and add operation
|
|
594
840
|
* // Create a min heap (default)
|
|
@@ -622,6 +868,30 @@ var _Heap = class _Heap extends IterableElementBase {
|
|
|
622
868
|
|
|
623
869
|
|
|
624
870
|
|
|
871
|
+
|
|
872
|
+
|
|
873
|
+
|
|
874
|
+
|
|
875
|
+
|
|
876
|
+
|
|
877
|
+
|
|
878
|
+
|
|
879
|
+
|
|
880
|
+
|
|
881
|
+
|
|
882
|
+
|
|
883
|
+
|
|
884
|
+
|
|
885
|
+
|
|
886
|
+
|
|
887
|
+
|
|
888
|
+
|
|
889
|
+
|
|
890
|
+
|
|
891
|
+
|
|
892
|
+
|
|
893
|
+
|
|
894
|
+
|
|
625
895
|
* @example
|
|
626
896
|
* // Add multiple elements
|
|
627
897
|
* const heap = new Heap<number>([], { comparator: (a, b) => a - b });
|
|
@@ -657,6 +927,30 @@ var _Heap = class _Heap extends IterableElementBase {
|
|
|
657
927
|
|
|
658
928
|
|
|
659
929
|
|
|
930
|
+
|
|
931
|
+
|
|
932
|
+
|
|
933
|
+
|
|
934
|
+
|
|
935
|
+
|
|
936
|
+
|
|
937
|
+
|
|
938
|
+
|
|
939
|
+
|
|
940
|
+
|
|
941
|
+
|
|
942
|
+
|
|
943
|
+
|
|
944
|
+
|
|
945
|
+
|
|
946
|
+
|
|
947
|
+
|
|
948
|
+
|
|
949
|
+
|
|
950
|
+
|
|
951
|
+
|
|
952
|
+
|
|
953
|
+
|
|
660
954
|
* @example
|
|
661
955
|
* // Heap with custom comparator (MaxHeap behavior)
|
|
662
956
|
* interface Task {
|
|
@@ -708,6 +1002,30 @@ var _Heap = class _Heap extends IterableElementBase {
|
|
|
708
1002
|
|
|
709
1003
|
|
|
710
1004
|
|
|
1005
|
+
|
|
1006
|
+
|
|
1007
|
+
|
|
1008
|
+
|
|
1009
|
+
|
|
1010
|
+
|
|
1011
|
+
|
|
1012
|
+
|
|
1013
|
+
|
|
1014
|
+
|
|
1015
|
+
|
|
1016
|
+
|
|
1017
|
+
|
|
1018
|
+
|
|
1019
|
+
|
|
1020
|
+
|
|
1021
|
+
|
|
1022
|
+
|
|
1023
|
+
|
|
1024
|
+
|
|
1025
|
+
|
|
1026
|
+
|
|
1027
|
+
|
|
1028
|
+
|
|
711
1029
|
* @example
|
|
712
1030
|
* // Heap for event processing with priority
|
|
713
1031
|
* interface Event {
|
|
@@ -784,6 +1102,30 @@ var _Heap = class _Heap extends IterableElementBase {
|
|
|
784
1102
|
|
|
785
1103
|
|
|
786
1104
|
|
|
1105
|
+
|
|
1106
|
+
|
|
1107
|
+
|
|
1108
|
+
|
|
1109
|
+
|
|
1110
|
+
|
|
1111
|
+
|
|
1112
|
+
|
|
1113
|
+
|
|
1114
|
+
|
|
1115
|
+
|
|
1116
|
+
|
|
1117
|
+
|
|
1118
|
+
|
|
1119
|
+
|
|
1120
|
+
|
|
1121
|
+
|
|
1122
|
+
|
|
1123
|
+
|
|
1124
|
+
|
|
1125
|
+
|
|
1126
|
+
|
|
1127
|
+
|
|
1128
|
+
|
|
787
1129
|
* @example
|
|
788
1130
|
* // Check if heap is empty
|
|
789
1131
|
* const heap = new Heap<number>([], { comparator: (a, b) => a - b });
|
|
@@ -807,6 +1149,30 @@ var _Heap = class _Heap extends IterableElementBase {
|
|
|
807
1149
|
|
|
808
1150
|
|
|
809
1151
|
|
|
1152
|
+
|
|
1153
|
+
|
|
1154
|
+
|
|
1155
|
+
|
|
1156
|
+
|
|
1157
|
+
|
|
1158
|
+
|
|
1159
|
+
|
|
1160
|
+
|
|
1161
|
+
|
|
1162
|
+
|
|
1163
|
+
|
|
1164
|
+
|
|
1165
|
+
|
|
1166
|
+
|
|
1167
|
+
|
|
1168
|
+
|
|
1169
|
+
|
|
1170
|
+
|
|
1171
|
+
|
|
1172
|
+
|
|
1173
|
+
|
|
1174
|
+
|
|
1175
|
+
|
|
810
1176
|
* @example
|
|
811
1177
|
* // Remove all elements
|
|
812
1178
|
* const heap = new Heap<number>([1, 2, 3], { comparator: (a, b) => a - b });
|
|
@@ -833,6 +1199,30 @@ var _Heap = class _Heap extends IterableElementBase {
|
|
|
833
1199
|
* @returns True if found.
|
|
834
1200
|
|
|
835
1201
|
|
|
1202
|
+
|
|
1203
|
+
|
|
1204
|
+
|
|
1205
|
+
|
|
1206
|
+
|
|
1207
|
+
|
|
1208
|
+
|
|
1209
|
+
|
|
1210
|
+
|
|
1211
|
+
|
|
1212
|
+
|
|
1213
|
+
|
|
1214
|
+
|
|
1215
|
+
|
|
1216
|
+
|
|
1217
|
+
|
|
1218
|
+
|
|
1219
|
+
|
|
1220
|
+
|
|
1221
|
+
|
|
1222
|
+
|
|
1223
|
+
|
|
1224
|
+
|
|
1225
|
+
|
|
836
1226
|
* @example
|
|
837
1227
|
* // Check element existence
|
|
838
1228
|
* const heap = new Heap<number>([3, 1, 2], { comparator: (a, b) => a - b });
|
|
@@ -856,6 +1246,30 @@ var _Heap = class _Heap extends IterableElementBase {
|
|
|
856
1246
|
|
|
857
1247
|
|
|
858
1248
|
|
|
1249
|
+
|
|
1250
|
+
|
|
1251
|
+
|
|
1252
|
+
|
|
1253
|
+
|
|
1254
|
+
|
|
1255
|
+
|
|
1256
|
+
|
|
1257
|
+
|
|
1258
|
+
|
|
1259
|
+
|
|
1260
|
+
|
|
1261
|
+
|
|
1262
|
+
|
|
1263
|
+
|
|
1264
|
+
|
|
1265
|
+
|
|
1266
|
+
|
|
1267
|
+
|
|
1268
|
+
|
|
1269
|
+
|
|
1270
|
+
|
|
1271
|
+
|
|
1272
|
+
|
|
859
1273
|
* @example
|
|
860
1274
|
* // Remove specific element
|
|
861
1275
|
* const heap = new Heap<number>([3, 1, 4, 1, 5], { comparator: (a, b) => a - b });
|
|
@@ -925,6 +1339,30 @@ var _Heap = class _Heap extends IterableElementBase {
|
|
|
925
1339
|
* @returns Array of visited elements.
|
|
926
1340
|
|
|
927
1341
|
|
|
1342
|
+
|
|
1343
|
+
|
|
1344
|
+
|
|
1345
|
+
|
|
1346
|
+
|
|
1347
|
+
|
|
1348
|
+
|
|
1349
|
+
|
|
1350
|
+
|
|
1351
|
+
|
|
1352
|
+
|
|
1353
|
+
|
|
1354
|
+
|
|
1355
|
+
|
|
1356
|
+
|
|
1357
|
+
|
|
1358
|
+
|
|
1359
|
+
|
|
1360
|
+
|
|
1361
|
+
|
|
1362
|
+
|
|
1363
|
+
|
|
1364
|
+
|
|
1365
|
+
|
|
928
1366
|
* @example
|
|
929
1367
|
* // Depth-first traversal
|
|
930
1368
|
* const heap = new Heap<number>([3, 1, 2], { comparator: (a, b) => a - b });
|
|
@@ -981,6 +1419,30 @@ var _Heap = class _Heap extends IterableElementBase {
|
|
|
981
1419
|
|
|
982
1420
|
|
|
983
1421
|
|
|
1422
|
+
|
|
1423
|
+
|
|
1424
|
+
|
|
1425
|
+
|
|
1426
|
+
|
|
1427
|
+
|
|
1428
|
+
|
|
1429
|
+
|
|
1430
|
+
|
|
1431
|
+
|
|
1432
|
+
|
|
1433
|
+
|
|
1434
|
+
|
|
1435
|
+
|
|
1436
|
+
|
|
1437
|
+
|
|
1438
|
+
|
|
1439
|
+
|
|
1440
|
+
|
|
1441
|
+
|
|
1442
|
+
|
|
1443
|
+
|
|
1444
|
+
|
|
1445
|
+
|
|
984
1446
|
* @example
|
|
985
1447
|
* // Sort elements using heap
|
|
986
1448
|
* const heap = new Heap<number>([5, 1, 3, 2, 4]);
|
|
@@ -1010,6 +1472,30 @@ var _Heap = class _Heap extends IterableElementBase {
|
|
|
1010
1472
|
|
|
1011
1473
|
|
|
1012
1474
|
|
|
1475
|
+
|
|
1476
|
+
|
|
1477
|
+
|
|
1478
|
+
|
|
1479
|
+
|
|
1480
|
+
|
|
1481
|
+
|
|
1482
|
+
|
|
1483
|
+
|
|
1484
|
+
|
|
1485
|
+
|
|
1486
|
+
|
|
1487
|
+
|
|
1488
|
+
|
|
1489
|
+
|
|
1490
|
+
|
|
1491
|
+
|
|
1492
|
+
|
|
1493
|
+
|
|
1494
|
+
|
|
1495
|
+
|
|
1496
|
+
|
|
1497
|
+
|
|
1498
|
+
|
|
1013
1499
|
* @example
|
|
1014
1500
|
* // Create independent copy
|
|
1015
1501
|
* const heap = new Heap<number>([3, 1, 4], { comparator: (a, b) => a - b });
|
|
@@ -1038,6 +1524,30 @@ var _Heap = class _Heap extends IterableElementBase {
|
|
|
1038
1524
|
|
|
1039
1525
|
|
|
1040
1526
|
|
|
1527
|
+
|
|
1528
|
+
|
|
1529
|
+
|
|
1530
|
+
|
|
1531
|
+
|
|
1532
|
+
|
|
1533
|
+
|
|
1534
|
+
|
|
1535
|
+
|
|
1536
|
+
|
|
1537
|
+
|
|
1538
|
+
|
|
1539
|
+
|
|
1540
|
+
|
|
1541
|
+
|
|
1542
|
+
|
|
1543
|
+
|
|
1544
|
+
|
|
1545
|
+
|
|
1546
|
+
|
|
1547
|
+
|
|
1548
|
+
|
|
1549
|
+
|
|
1550
|
+
|
|
1041
1551
|
* @example
|
|
1042
1552
|
* // Filter elements
|
|
1043
1553
|
* const heap = new Heap<number>([1, 2, 3, 4, 5], { comparator: (a, b) => a - b });
|
|
@@ -1073,6 +1583,30 @@ var _Heap = class _Heap extends IterableElementBase {
|
|
|
1073
1583
|
|
|
1074
1584
|
|
|
1075
1585
|
|
|
1586
|
+
|
|
1587
|
+
|
|
1588
|
+
|
|
1589
|
+
|
|
1590
|
+
|
|
1591
|
+
|
|
1592
|
+
|
|
1593
|
+
|
|
1594
|
+
|
|
1595
|
+
|
|
1596
|
+
|
|
1597
|
+
|
|
1598
|
+
|
|
1599
|
+
|
|
1600
|
+
|
|
1601
|
+
|
|
1602
|
+
|
|
1603
|
+
|
|
1604
|
+
|
|
1605
|
+
|
|
1606
|
+
|
|
1607
|
+
|
|
1608
|
+
|
|
1609
|
+
|
|
1076
1610
|
* @example
|
|
1077
1611
|
* // Transform elements
|
|
1078
1612
|
* const heap = new Heap<number>([1, 2, 3], { comparator: (a, b) => a - b });
|
|
@@ -1081,7 +1615,7 @@ var _Heap = class _Heap extends IterableElementBase {
|
|
|
1081
1615
|
*/
|
|
1082
1616
|
map(callback, options, thisArg) {
|
|
1083
1617
|
const { comparator, toElementFn, ...rest } = options != null ? options : {};
|
|
1084
|
-
if (!comparator)
|
|
1618
|
+
if (!comparator) raise(TypeError, ERR.comparatorRequired("Heap.map"));
|
|
1085
1619
|
const out = this._createLike([], { ...rest, comparator, toElementFn });
|
|
1086
1620
|
let i = 0;
|
|
1087
1621
|
for (const x of this) {
|
|
@@ -1175,206 +1709,14 @@ var _Heap = class _Heap extends IterableElementBase {
|
|
|
1175
1709
|
* @template EM
|
|
1176
1710
|
* @template RM
|
|
1177
1711
|
* @param [options] - Options forwarded to the constructor.
|
|
1178
|
-
* @returns An empty like-kind heap instance.
|
|
1179
|
-
*/
|
|
1180
|
-
_spawnLike(options) {
|
|
1181
|
-
return this._createLike([], options);
|
|
1182
|
-
}
|
|
1183
|
-
};
|
|
1184
|
-
__name(_Heap, "Heap");
|
|
1185
|
-
var Heap = _Heap;
|
|
1186
|
-
|
|
1187
|
-
// src/data-structures/base/linear-base.ts
|
|
1188
|
-
var _LinearBase = class _LinearBase extends IterableElementBase {
|
|
1189
|
-
/**
|
|
1190
|
-
* Construct a linear container with runtime options.
|
|
1191
|
-
* @param options - `{ maxLen?, ... }` bounds/behavior options.
|
|
1192
|
-
* @remarks Time O(1), Space O(1)
|
|
1193
|
-
*/
|
|
1194
|
-
constructor(options) {
|
|
1195
|
-
super(options);
|
|
1196
|
-
__publicField(this, "_maxLen", -1);
|
|
1197
|
-
if (options) {
|
|
1198
|
-
const { maxLen } = options;
|
|
1199
|
-
if (typeof maxLen === "number" && maxLen > 0 && maxLen % 1 === 0) this._maxLen = maxLen;
|
|
1200
|
-
}
|
|
1201
|
-
}
|
|
1202
|
-
/**
|
|
1203
|
-
* Upper bound for length (if positive), or `-1` when unbounded.
|
|
1204
|
-
* @returns Maximum allowed length.
|
|
1205
|
-
* @remarks Time O(1), Space O(1)
|
|
1206
|
-
*/
|
|
1207
|
-
get maxLen() {
|
|
1208
|
-
return this._maxLen;
|
|
1209
|
-
}
|
|
1210
|
-
/**
|
|
1211
|
-
* First index of a value from the left.
|
|
1212
|
-
* @param searchElement - Value to match.
|
|
1213
|
-
* @param fromIndex - Start position (supports negative index).
|
|
1214
|
-
* @returns Index or `-1` if not found.
|
|
1215
|
-
* @remarks Time O(n), Space O(1)
|
|
1216
|
-
*/
|
|
1217
|
-
indexOf(searchElement, fromIndex = 0) {
|
|
1218
|
-
if (this.length === 0) return -1;
|
|
1219
|
-
if (fromIndex < 0) fromIndex = this.length + fromIndex;
|
|
1220
|
-
if (fromIndex < 0) fromIndex = 0;
|
|
1221
|
-
for (let i = fromIndex; i < this.length; i++) {
|
|
1222
|
-
const element = this.at(i);
|
|
1223
|
-
if (element === searchElement) return i;
|
|
1224
|
-
}
|
|
1225
|
-
return -1;
|
|
1226
|
-
}
|
|
1227
|
-
/**
|
|
1228
|
-
* Last index of a value from the right.
|
|
1229
|
-
* @param searchElement - Value to match.
|
|
1230
|
-
* @param fromIndex - Start position (supports negative index).
|
|
1231
|
-
* @returns Index or `-1` if not found.
|
|
1232
|
-
* @remarks Time O(n), Space O(1)
|
|
1233
|
-
*/
|
|
1234
|
-
lastIndexOf(searchElement, fromIndex = this.length - 1) {
|
|
1235
|
-
if (this.length === 0) return -1;
|
|
1236
|
-
if (fromIndex >= this.length) fromIndex = this.length - 1;
|
|
1237
|
-
if (fromIndex < 0) fromIndex = this.length + fromIndex;
|
|
1238
|
-
for (let i = fromIndex; i >= 0; i--) {
|
|
1239
|
-
const element = this.at(i);
|
|
1240
|
-
if (element === searchElement) return i;
|
|
1241
|
-
}
|
|
1242
|
-
return -1;
|
|
1243
|
-
}
|
|
1244
|
-
/**
|
|
1245
|
-
* Find the first index matching a predicate.
|
|
1246
|
-
* @param predicate - `(element, index, self) => boolean`.
|
|
1247
|
-
* @param thisArg - Optional `this` for callback.
|
|
1248
|
-
* @returns Index or `-1`.
|
|
1249
|
-
* @remarks Time O(n), Space O(1)
|
|
1250
|
-
*/
|
|
1251
|
-
findIndex(predicate, thisArg) {
|
|
1252
|
-
for (let i = 0; i < this.length; i++) {
|
|
1253
|
-
const item = this.at(i);
|
|
1254
|
-
if (item !== void 0 && predicate.call(thisArg, item, i, this)) return i;
|
|
1255
|
-
}
|
|
1256
|
-
return -1;
|
|
1257
|
-
}
|
|
1258
|
-
/**
|
|
1259
|
-
* Concatenate elements and/or containers.
|
|
1260
|
-
* @param items - Elements or other containers.
|
|
1261
|
-
* @returns New container with combined elements (`this` type).
|
|
1262
|
-
* @remarks Time O(sum(length)), Space O(sum(length))
|
|
1263
|
-
*/
|
|
1264
|
-
concat(...items) {
|
|
1265
|
-
const newList = this.clone();
|
|
1266
|
-
for (const item of items) {
|
|
1267
|
-
if (item instanceof _LinearBase) {
|
|
1268
|
-
newList.pushMany(item);
|
|
1269
|
-
} else {
|
|
1270
|
-
newList.push(item);
|
|
1271
|
-
}
|
|
1272
|
-
}
|
|
1273
|
-
return newList;
|
|
1274
|
-
}
|
|
1275
|
-
/**
|
|
1276
|
-
* In-place stable order via array sort semantics.
|
|
1277
|
-
* @param compareFn - Comparator `(a, b) => number`.
|
|
1278
|
-
* @returns This container.
|
|
1279
|
-
* @remarks Time O(n log n), Space O(n) (materializes to array temporarily)
|
|
1280
|
-
*/
|
|
1281
|
-
sort(compareFn) {
|
|
1282
|
-
const arr = this.toArray();
|
|
1283
|
-
arr.sort(compareFn);
|
|
1284
|
-
this.clear();
|
|
1285
|
-
for (const item of arr) this.push(item);
|
|
1286
|
-
return this;
|
|
1287
|
-
}
|
|
1288
|
-
/**
|
|
1289
|
-
* Remove and/or insert elements at a position (array-compatible).
|
|
1290
|
-
* @param start - Start index (supports negative index).
|
|
1291
|
-
* @param deleteCount - How many to remove.
|
|
1292
|
-
* @param items - Elements to insert.
|
|
1293
|
-
* @returns Removed elements as a new list (`this` type).
|
|
1294
|
-
* @remarks Time O(n + m), Space O(min(n, m)) where `m = items.length`
|
|
1295
|
-
*/
|
|
1296
|
-
splice(start, deleteCount = 0, ...items) {
|
|
1297
|
-
const removedList = this._createInstance();
|
|
1298
|
-
start = start < 0 ? this.length + start : start;
|
|
1299
|
-
start = Math.max(0, Math.min(start, this.length));
|
|
1300
|
-
deleteCount = Math.max(0, Math.min(deleteCount, this.length - start));
|
|
1301
|
-
for (let i = 0; i < deleteCount; i++) {
|
|
1302
|
-
const removed = this.deleteAt(start);
|
|
1303
|
-
if (removed !== void 0) {
|
|
1304
|
-
removedList.push(removed);
|
|
1305
|
-
}
|
|
1306
|
-
}
|
|
1307
|
-
for (let i = 0; i < items.length; i++) {
|
|
1308
|
-
this.addAt(start + i, items[i]);
|
|
1309
|
-
}
|
|
1310
|
-
return removedList;
|
|
1311
|
-
}
|
|
1312
|
-
/**
|
|
1313
|
-
* Join all elements into a string.
|
|
1314
|
-
* @param separator - Separator string.
|
|
1315
|
-
* @returns Concatenated string.
|
|
1316
|
-
* @remarks Time O(n), Space O(n)
|
|
1317
|
-
*/
|
|
1318
|
-
join(separator = ",") {
|
|
1319
|
-
return this.toArray().join(separator);
|
|
1320
|
-
}
|
|
1321
|
-
/**
|
|
1322
|
-
* Snapshot elements into a reversed array.
|
|
1323
|
-
* @returns New reversed array.
|
|
1324
|
-
* @remarks Time O(n), Space O(n)
|
|
1325
|
-
*/
|
|
1326
|
-
toReversedArray() {
|
|
1327
|
-
const array = [];
|
|
1328
|
-
for (let i = this.length - 1; i >= 0; i--) {
|
|
1329
|
-
array.push(this.at(i));
|
|
1330
|
-
}
|
|
1331
|
-
return array;
|
|
1332
|
-
}
|
|
1333
|
-
reduceRight(callbackfn, initialValue) {
|
|
1334
|
-
let accumulator = initialValue != null ? initialValue : 0;
|
|
1335
|
-
for (let i = this.length - 1; i >= 0; i--) {
|
|
1336
|
-
accumulator = callbackfn(accumulator, this.at(i), i, this);
|
|
1337
|
-
}
|
|
1338
|
-
return accumulator;
|
|
1339
|
-
}
|
|
1340
|
-
/**
|
|
1341
|
-
* Create a shallow copy of a subrange.
|
|
1342
|
-
* @param start - Inclusive start (supports negative index).
|
|
1343
|
-
* @param end - Exclusive end (supports negative index).
|
|
1344
|
-
* @returns New list with the range (`this` type).
|
|
1345
|
-
* @remarks Time O(n), Space O(n)
|
|
1346
|
-
*/
|
|
1347
|
-
slice(start = 0, end = this.length) {
|
|
1348
|
-
start = start < 0 ? this.length + start : start;
|
|
1349
|
-
end = end < 0 ? this.length + end : end;
|
|
1350
|
-
const newList = this._createInstance();
|
|
1351
|
-
for (let i = start; i < end; i++) {
|
|
1352
|
-
newList.push(this.at(i));
|
|
1353
|
-
}
|
|
1354
|
-
return newList;
|
|
1355
|
-
}
|
|
1356
|
-
/**
|
|
1357
|
-
* Fill a range with a value.
|
|
1358
|
-
* @param value - Value to set.
|
|
1359
|
-
* @param start - Inclusive start.
|
|
1360
|
-
* @param end - Exclusive end.
|
|
1361
|
-
* @returns This list.
|
|
1362
|
-
* @remarks Time O(n), Space O(1)
|
|
1363
|
-
*/
|
|
1364
|
-
fill(value, start = 0, end = this.length) {
|
|
1365
|
-
start = start < 0 ? this.length + start : start;
|
|
1366
|
-
end = end < 0 ? this.length + end : end;
|
|
1367
|
-
if (start < 0) start = 0;
|
|
1368
|
-
if (end > this.length) end = this.length;
|
|
1369
|
-
if (start >= end) return this;
|
|
1370
|
-
for (let i = start; i < end; i++) {
|
|
1371
|
-
this.setAt(i, value);
|
|
1372
|
-
}
|
|
1373
|
-
return this;
|
|
1712
|
+
* @returns An empty like-kind heap instance.
|
|
1713
|
+
*/
|
|
1714
|
+
_spawnLike(options) {
|
|
1715
|
+
return this._createLike([], options);
|
|
1374
1716
|
}
|
|
1375
1717
|
};
|
|
1376
|
-
__name(
|
|
1377
|
-
var
|
|
1718
|
+
__name(_Heap, "Heap");
|
|
1719
|
+
var Heap = _Heap;
|
|
1378
1720
|
|
|
1379
1721
|
// src/data-structures/queue/queue.ts
|
|
1380
1722
|
var _Queue = class _Queue extends LinearBase {
|
|
@@ -1444,6 +1786,30 @@ var _Queue = class _Queue extends LinearBase {
|
|
|
1444
1786
|
|
|
1445
1787
|
|
|
1446
1788
|
|
|
1789
|
+
|
|
1790
|
+
|
|
1791
|
+
|
|
1792
|
+
|
|
1793
|
+
|
|
1794
|
+
|
|
1795
|
+
|
|
1796
|
+
|
|
1797
|
+
|
|
1798
|
+
|
|
1799
|
+
|
|
1800
|
+
|
|
1801
|
+
|
|
1802
|
+
|
|
1803
|
+
|
|
1804
|
+
|
|
1805
|
+
|
|
1806
|
+
|
|
1807
|
+
|
|
1808
|
+
|
|
1809
|
+
|
|
1810
|
+
|
|
1811
|
+
|
|
1812
|
+
|
|
1447
1813
|
* @example
|
|
1448
1814
|
* // Track queue length
|
|
1449
1815
|
* const q = new Queue<number>();
|
|
@@ -1470,6 +1836,30 @@ var _Queue = class _Queue extends LinearBase {
|
|
|
1470
1836
|
|
|
1471
1837
|
|
|
1472
1838
|
|
|
1839
|
+
|
|
1840
|
+
|
|
1841
|
+
|
|
1842
|
+
|
|
1843
|
+
|
|
1844
|
+
|
|
1845
|
+
|
|
1846
|
+
|
|
1847
|
+
|
|
1848
|
+
|
|
1849
|
+
|
|
1850
|
+
|
|
1851
|
+
|
|
1852
|
+
|
|
1853
|
+
|
|
1854
|
+
|
|
1855
|
+
|
|
1856
|
+
|
|
1857
|
+
|
|
1858
|
+
|
|
1859
|
+
|
|
1860
|
+
|
|
1861
|
+
|
|
1862
|
+
|
|
1473
1863
|
* @example
|
|
1474
1864
|
* // View the front element
|
|
1475
1865
|
* const q = new Queue<string>(['first', 'second', 'third']);
|
|
@@ -1512,6 +1902,30 @@ var _Queue = class _Queue extends LinearBase {
|
|
|
1512
1902
|
|
|
1513
1903
|
|
|
1514
1904
|
|
|
1905
|
+
|
|
1906
|
+
|
|
1907
|
+
|
|
1908
|
+
|
|
1909
|
+
|
|
1910
|
+
|
|
1911
|
+
|
|
1912
|
+
|
|
1913
|
+
|
|
1914
|
+
|
|
1915
|
+
|
|
1916
|
+
|
|
1917
|
+
|
|
1918
|
+
|
|
1919
|
+
|
|
1920
|
+
|
|
1921
|
+
|
|
1922
|
+
|
|
1923
|
+
|
|
1924
|
+
|
|
1925
|
+
|
|
1926
|
+
|
|
1927
|
+
|
|
1928
|
+
|
|
1515
1929
|
* @example
|
|
1516
1930
|
* // Queue for...of iteration and isEmpty check
|
|
1517
1931
|
* const queue = new Queue<string>(['A', 'B', 'C', 'D']);
|
|
@@ -1550,6 +1964,30 @@ var _Queue = class _Queue extends LinearBase {
|
|
|
1550
1964
|
|
|
1551
1965
|
|
|
1552
1966
|
|
|
1967
|
+
|
|
1968
|
+
|
|
1969
|
+
|
|
1970
|
+
|
|
1971
|
+
|
|
1972
|
+
|
|
1973
|
+
|
|
1974
|
+
|
|
1975
|
+
|
|
1976
|
+
|
|
1977
|
+
|
|
1978
|
+
|
|
1979
|
+
|
|
1980
|
+
|
|
1981
|
+
|
|
1982
|
+
|
|
1983
|
+
|
|
1984
|
+
|
|
1985
|
+
|
|
1986
|
+
|
|
1987
|
+
|
|
1988
|
+
|
|
1989
|
+
|
|
1990
|
+
|
|
1553
1991
|
* @example
|
|
1554
1992
|
* // basic Queue creation and push operation
|
|
1555
1993
|
* // Create a simple Queue with initial values
|
|
@@ -1595,6 +2033,30 @@ var _Queue = class _Queue extends LinearBase {
|
|
|
1595
2033
|
|
|
1596
2034
|
|
|
1597
2035
|
|
|
2036
|
+
|
|
2037
|
+
|
|
2038
|
+
|
|
2039
|
+
|
|
2040
|
+
|
|
2041
|
+
|
|
2042
|
+
|
|
2043
|
+
|
|
2044
|
+
|
|
2045
|
+
|
|
2046
|
+
|
|
2047
|
+
|
|
2048
|
+
|
|
2049
|
+
|
|
2050
|
+
|
|
2051
|
+
|
|
2052
|
+
|
|
2053
|
+
|
|
2054
|
+
|
|
2055
|
+
|
|
2056
|
+
|
|
2057
|
+
|
|
2058
|
+
|
|
2059
|
+
|
|
1598
2060
|
* @example
|
|
1599
2061
|
* // Queue shift and peek operations
|
|
1600
2062
|
* const queue = new Queue<number>([10, 20, 30, 40]);
|
|
@@ -1630,6 +2092,30 @@ var _Queue = class _Queue extends LinearBase {
|
|
|
1630
2092
|
|
|
1631
2093
|
|
|
1632
2094
|
|
|
2095
|
+
|
|
2096
|
+
|
|
2097
|
+
|
|
2098
|
+
|
|
2099
|
+
|
|
2100
|
+
|
|
2101
|
+
|
|
2102
|
+
|
|
2103
|
+
|
|
2104
|
+
|
|
2105
|
+
|
|
2106
|
+
|
|
2107
|
+
|
|
2108
|
+
|
|
2109
|
+
|
|
2110
|
+
|
|
2111
|
+
|
|
2112
|
+
|
|
2113
|
+
|
|
2114
|
+
|
|
2115
|
+
|
|
2116
|
+
|
|
2117
|
+
|
|
2118
|
+
|
|
1633
2119
|
* @example
|
|
1634
2120
|
* // Remove specific element
|
|
1635
2121
|
* const q = new Queue<number>([1, 2, 3, 2]);
|
|
@@ -1658,6 +2144,30 @@ var _Queue = class _Queue extends LinearBase {
|
|
|
1658
2144
|
|
|
1659
2145
|
|
|
1660
2146
|
|
|
2147
|
+
|
|
2148
|
+
|
|
2149
|
+
|
|
2150
|
+
|
|
2151
|
+
|
|
2152
|
+
|
|
2153
|
+
|
|
2154
|
+
|
|
2155
|
+
|
|
2156
|
+
|
|
2157
|
+
|
|
2158
|
+
|
|
2159
|
+
|
|
2160
|
+
|
|
2161
|
+
|
|
2162
|
+
|
|
2163
|
+
|
|
2164
|
+
|
|
2165
|
+
|
|
2166
|
+
|
|
2167
|
+
|
|
2168
|
+
|
|
2169
|
+
|
|
2170
|
+
|
|
1661
2171
|
* @example
|
|
1662
2172
|
* // Access element by index
|
|
1663
2173
|
* const q = new Queue<string>(['a', 'b', 'c']);
|
|
@@ -1727,6 +2237,30 @@ var _Queue = class _Queue extends LinearBase {
|
|
|
1727
2237
|
|
|
1728
2238
|
|
|
1729
2239
|
|
|
2240
|
+
|
|
2241
|
+
|
|
2242
|
+
|
|
2243
|
+
|
|
2244
|
+
|
|
2245
|
+
|
|
2246
|
+
|
|
2247
|
+
|
|
2248
|
+
|
|
2249
|
+
|
|
2250
|
+
|
|
2251
|
+
|
|
2252
|
+
|
|
2253
|
+
|
|
2254
|
+
|
|
2255
|
+
|
|
2256
|
+
|
|
2257
|
+
|
|
2258
|
+
|
|
2259
|
+
|
|
2260
|
+
|
|
2261
|
+
|
|
2262
|
+
|
|
2263
|
+
|
|
1730
2264
|
* @example
|
|
1731
2265
|
* // Remove all elements
|
|
1732
2266
|
* const q = new Queue<number>([1, 2, 3]);
|
|
@@ -1749,6 +2283,30 @@ var _Queue = class _Queue extends LinearBase {
|
|
|
1749
2283
|
|
|
1750
2284
|
|
|
1751
2285
|
|
|
2286
|
+
|
|
2287
|
+
|
|
2288
|
+
|
|
2289
|
+
|
|
2290
|
+
|
|
2291
|
+
|
|
2292
|
+
|
|
2293
|
+
|
|
2294
|
+
|
|
2295
|
+
|
|
2296
|
+
|
|
2297
|
+
|
|
2298
|
+
|
|
2299
|
+
|
|
2300
|
+
|
|
2301
|
+
|
|
2302
|
+
|
|
2303
|
+
|
|
2304
|
+
|
|
2305
|
+
|
|
2306
|
+
|
|
2307
|
+
|
|
2308
|
+
|
|
2309
|
+
|
|
1752
2310
|
* @example
|
|
1753
2311
|
* // Reclaim unused memory
|
|
1754
2312
|
* const q = new Queue<number>([1, 2, 3, 4, 5]);
|
|
@@ -1794,6 +2352,30 @@ var _Queue = class _Queue extends LinearBase {
|
|
|
1794
2352
|
|
|
1795
2353
|
|
|
1796
2354
|
|
|
2355
|
+
|
|
2356
|
+
|
|
2357
|
+
|
|
2358
|
+
|
|
2359
|
+
|
|
2360
|
+
|
|
2361
|
+
|
|
2362
|
+
|
|
2363
|
+
|
|
2364
|
+
|
|
2365
|
+
|
|
2366
|
+
|
|
2367
|
+
|
|
2368
|
+
|
|
2369
|
+
|
|
2370
|
+
|
|
2371
|
+
|
|
2372
|
+
|
|
2373
|
+
|
|
2374
|
+
|
|
2375
|
+
|
|
2376
|
+
|
|
2377
|
+
|
|
2378
|
+
|
|
1797
2379
|
* @example
|
|
1798
2380
|
* // Create independent copy
|
|
1799
2381
|
* const q = new Queue<number>([1, 2, 3]);
|
|
@@ -1823,6 +2405,30 @@ var _Queue = class _Queue extends LinearBase {
|
|
|
1823
2405
|
|
|
1824
2406
|
|
|
1825
2407
|
|
|
2408
|
+
|
|
2409
|
+
|
|
2410
|
+
|
|
2411
|
+
|
|
2412
|
+
|
|
2413
|
+
|
|
2414
|
+
|
|
2415
|
+
|
|
2416
|
+
|
|
2417
|
+
|
|
2418
|
+
|
|
2419
|
+
|
|
2420
|
+
|
|
2421
|
+
|
|
2422
|
+
|
|
2423
|
+
|
|
2424
|
+
|
|
2425
|
+
|
|
2426
|
+
|
|
2427
|
+
|
|
2428
|
+
|
|
2429
|
+
|
|
2430
|
+
|
|
2431
|
+
|
|
1826
2432
|
* @example
|
|
1827
2433
|
* // Filter elements
|
|
1828
2434
|
* const q = new Queue<number>([1, 2, 3, 4, 5]);
|
|
@@ -1856,6 +2462,30 @@ var _Queue = class _Queue extends LinearBase {
|
|
|
1856
2462
|
|
|
1857
2463
|
|
|
1858
2464
|
|
|
2465
|
+
|
|
2466
|
+
|
|
2467
|
+
|
|
2468
|
+
|
|
2469
|
+
|
|
2470
|
+
|
|
2471
|
+
|
|
2472
|
+
|
|
2473
|
+
|
|
2474
|
+
|
|
2475
|
+
|
|
2476
|
+
|
|
2477
|
+
|
|
2478
|
+
|
|
2479
|
+
|
|
2480
|
+
|
|
2481
|
+
|
|
2482
|
+
|
|
2483
|
+
|
|
2484
|
+
|
|
2485
|
+
|
|
2486
|
+
|
|
2487
|
+
|
|
2488
|
+
|
|
1859
2489
|
* @example
|
|
1860
2490
|
* // Transform elements
|
|
1861
2491
|
* const q = new Queue<number>([1, 2, 3]);
|
|
@@ -2090,7 +2720,7 @@ var _AbstractGraph = class _AbstractGraph extends IterableEntryBase {
|
|
|
2090
2720
|
const newEdge = this.createEdge(srcOrEdge, dest, weight, value);
|
|
2091
2721
|
return this._addEdge(newEdge);
|
|
2092
2722
|
} else {
|
|
2093
|
-
|
|
2723
|
+
raise(TypeError, ERR.invalidArgument("dest must be a Vertex or vertex key when srcOrEdge is an Edge.", "Graph"));
|
|
2094
2724
|
}
|
|
2095
2725
|
}
|
|
2096
2726
|
}
|
|
@@ -2963,6 +3593,30 @@ var _UndirectedGraph = class _UndirectedGraph extends AbstractGraph {
|
|
|
2963
3593
|
|
|
2964
3594
|
|
|
2965
3595
|
|
|
3596
|
+
|
|
3597
|
+
|
|
3598
|
+
|
|
3599
|
+
|
|
3600
|
+
|
|
3601
|
+
|
|
3602
|
+
|
|
3603
|
+
|
|
3604
|
+
|
|
3605
|
+
|
|
3606
|
+
|
|
3607
|
+
|
|
3608
|
+
|
|
3609
|
+
|
|
3610
|
+
|
|
3611
|
+
|
|
3612
|
+
|
|
3613
|
+
|
|
3614
|
+
|
|
3615
|
+
|
|
3616
|
+
|
|
3617
|
+
|
|
3618
|
+
|
|
3619
|
+
|
|
2966
3620
|
* @example
|
|
2967
3621
|
* // Get edge between vertices
|
|
2968
3622
|
* const g = new UndirectedGraph();
|
|
@@ -3024,6 +3678,30 @@ var _UndirectedGraph = class _UndirectedGraph extends AbstractGraph {
|
|
|
3024
3678
|
|
|
3025
3679
|
|
|
3026
3680
|
|
|
3681
|
+
|
|
3682
|
+
|
|
3683
|
+
|
|
3684
|
+
|
|
3685
|
+
|
|
3686
|
+
|
|
3687
|
+
|
|
3688
|
+
|
|
3689
|
+
|
|
3690
|
+
|
|
3691
|
+
|
|
3692
|
+
|
|
3693
|
+
|
|
3694
|
+
|
|
3695
|
+
|
|
3696
|
+
|
|
3697
|
+
|
|
3698
|
+
|
|
3699
|
+
|
|
3700
|
+
|
|
3701
|
+
|
|
3702
|
+
|
|
3703
|
+
|
|
3704
|
+
|
|
3027
3705
|
* @example
|
|
3028
3706
|
* // UndirectedGraph deleteEdge and vertex operations
|
|
3029
3707
|
* const graph = new UndirectedGraph<string>();
|
|
@@ -3084,6 +3762,30 @@ var _UndirectedGraph = class _UndirectedGraph extends AbstractGraph {
|
|
|
3084
3762
|
|
|
3085
3763
|
|
|
3086
3764
|
|
|
3765
|
+
|
|
3766
|
+
|
|
3767
|
+
|
|
3768
|
+
|
|
3769
|
+
|
|
3770
|
+
|
|
3771
|
+
|
|
3772
|
+
|
|
3773
|
+
|
|
3774
|
+
|
|
3775
|
+
|
|
3776
|
+
|
|
3777
|
+
|
|
3778
|
+
|
|
3779
|
+
|
|
3780
|
+
|
|
3781
|
+
|
|
3782
|
+
|
|
3783
|
+
|
|
3784
|
+
|
|
3785
|
+
|
|
3786
|
+
|
|
3787
|
+
|
|
3788
|
+
|
|
3087
3789
|
* @example
|
|
3088
3790
|
* // Remove vertex and edges
|
|
3089
3791
|
* 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();
|
|
@@ -3544,6 +4390,6 @@ var UndirectedGraph = _UndirectedGraph;
|
|
|
3544
4390
|
* @license MIT License
|
|
3545
4391
|
*/
|
|
3546
4392
|
|
|
3547
|
-
export { DFSOperation, ERR, Range, UndirectedEdge, UndirectedGraph, UndirectedVertex };
|
|
4393
|
+
export { DFSOperation, ERR, Range, UndirectedEdge, UndirectedGraph, UndirectedVertex, raise };
|
|
3548
4394
|
//# sourceMappingURL=index.mjs.map
|
|
3549
4395
|
//# sourceMappingURL=index.mjs.map
|