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
|
@@ -28,7 +28,8 @@ var undirectedGraphTyped = (() => {
|
|
|
28
28
|
Range: () => Range,
|
|
29
29
|
UndirectedEdge: () => UndirectedEdge,
|
|
30
30
|
UndirectedGraph: () => UndirectedGraph,
|
|
31
|
-
UndirectedVertex: () => UndirectedVertex
|
|
31
|
+
UndirectedVertex: () => UndirectedVertex,
|
|
32
|
+
raise: () => raise
|
|
32
33
|
});
|
|
33
34
|
|
|
34
35
|
// src/utils/utils.ts
|
|
@@ -53,6 +54,9 @@ var undirectedGraphTyped = (() => {
|
|
|
53
54
|
};
|
|
54
55
|
|
|
55
56
|
// src/common/error.ts
|
|
57
|
+
function raise(ErrorClass, message) {
|
|
58
|
+
throw new ErrorClass(message);
|
|
59
|
+
}
|
|
56
60
|
var ERR = {
|
|
57
61
|
// Range / index
|
|
58
62
|
indexOutOfRange: (index, min, max, ctx) => `${ctx ? ctx + ": " : ""}Index ${index} is out of range [${min}, ${max}].`,
|
|
@@ -74,7 +78,9 @@ var undirectedGraphTyped = (() => {
|
|
|
74
78
|
matrixSingular: () => "Matrix: Singular matrix, inverse does not exist.",
|
|
75
79
|
matrixNotSquare: () => "Matrix: Must be square for inversion.",
|
|
76
80
|
matrixNotRectangular: () => "Matrix: Must be rectangular for transposition.",
|
|
77
|
-
matrixRowMismatch: (expected, got) => `Matrix: Expected row length ${expected}, but got ${got}
|
|
81
|
+
matrixRowMismatch: (expected, got) => `Matrix: Expected row length ${expected}, but got ${got}.`,
|
|
82
|
+
// Order statistic
|
|
83
|
+
orderStatisticNotEnabled: (method, ctx) => `${ctx ? ctx + ": " : ""}${method}() requires enableOrderStatistic: true.`
|
|
78
84
|
};
|
|
79
85
|
|
|
80
86
|
// src/common/index.ts
|
|
@@ -299,7 +305,7 @@ var undirectedGraphTyped = (() => {
|
|
|
299
305
|
if (options) {
|
|
300
306
|
const { toElementFn } = options;
|
|
301
307
|
if (typeof toElementFn === "function") this._toElementFn = toElementFn;
|
|
302
|
-
else if (toElementFn)
|
|
308
|
+
else if (toElementFn) raise(TypeError, "toElementFn must be a function type");
|
|
303
309
|
}
|
|
304
310
|
}
|
|
305
311
|
/**
|
|
@@ -455,7 +461,7 @@ var undirectedGraphTyped = (() => {
|
|
|
455
461
|
acc = initialValue;
|
|
456
462
|
} else {
|
|
457
463
|
const first = iter.next();
|
|
458
|
-
if (first.done)
|
|
464
|
+
if (first.done) raise(TypeError, "Reduce of empty structure with no initial value");
|
|
459
465
|
acc = first.value;
|
|
460
466
|
index = 1;
|
|
461
467
|
}
|
|
@@ -497,6 +503,196 @@ var undirectedGraphTyped = (() => {
|
|
|
497
503
|
}
|
|
498
504
|
};
|
|
499
505
|
|
|
506
|
+
// src/data-structures/base/linear-base.ts
|
|
507
|
+
var LinearBase = class _LinearBase extends IterableElementBase {
|
|
508
|
+
/**
|
|
509
|
+
* Construct a linear container with runtime options.
|
|
510
|
+
* @param options - `{ maxLen?, ... }` bounds/behavior options.
|
|
511
|
+
* @remarks Time O(1), Space O(1)
|
|
512
|
+
*/
|
|
513
|
+
constructor(options) {
|
|
514
|
+
super(options);
|
|
515
|
+
__publicField(this, "_maxLen", -1);
|
|
516
|
+
if (options) {
|
|
517
|
+
const { maxLen } = options;
|
|
518
|
+
if (typeof maxLen === "number" && maxLen > 0 && maxLen % 1 === 0) this._maxLen = maxLen;
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
/**
|
|
522
|
+
* Upper bound for length (if positive), or `-1` when unbounded.
|
|
523
|
+
* @returns Maximum allowed length.
|
|
524
|
+
* @remarks Time O(1), Space O(1)
|
|
525
|
+
*/
|
|
526
|
+
get maxLen() {
|
|
527
|
+
return this._maxLen;
|
|
528
|
+
}
|
|
529
|
+
/**
|
|
530
|
+
* First index of a value from the left.
|
|
531
|
+
* @param searchElement - Value to match.
|
|
532
|
+
* @param fromIndex - Start position (supports negative index).
|
|
533
|
+
* @returns Index or `-1` if not found.
|
|
534
|
+
* @remarks Time O(n), Space O(1)
|
|
535
|
+
*/
|
|
536
|
+
indexOf(searchElement, fromIndex = 0) {
|
|
537
|
+
if (this.length === 0) return -1;
|
|
538
|
+
if (fromIndex < 0) fromIndex = this.length + fromIndex;
|
|
539
|
+
if (fromIndex < 0) fromIndex = 0;
|
|
540
|
+
for (let i = fromIndex; i < this.length; i++) {
|
|
541
|
+
const element = this.at(i);
|
|
542
|
+
if (element === searchElement) return i;
|
|
543
|
+
}
|
|
544
|
+
return -1;
|
|
545
|
+
}
|
|
546
|
+
/**
|
|
547
|
+
* Last index of a value from the right.
|
|
548
|
+
* @param searchElement - Value to match.
|
|
549
|
+
* @param fromIndex - Start position (supports negative index).
|
|
550
|
+
* @returns Index or `-1` if not found.
|
|
551
|
+
* @remarks Time O(n), Space O(1)
|
|
552
|
+
*/
|
|
553
|
+
lastIndexOf(searchElement, fromIndex = this.length - 1) {
|
|
554
|
+
if (this.length === 0) return -1;
|
|
555
|
+
if (fromIndex >= this.length) fromIndex = this.length - 1;
|
|
556
|
+
if (fromIndex < 0) fromIndex = this.length + fromIndex;
|
|
557
|
+
for (let i = fromIndex; i >= 0; i--) {
|
|
558
|
+
const element = this.at(i);
|
|
559
|
+
if (element === searchElement) return i;
|
|
560
|
+
}
|
|
561
|
+
return -1;
|
|
562
|
+
}
|
|
563
|
+
/**
|
|
564
|
+
* Find the first index matching a predicate.
|
|
565
|
+
* @param predicate - `(element, index, self) => boolean`.
|
|
566
|
+
* @param thisArg - Optional `this` for callback.
|
|
567
|
+
* @returns Index or `-1`.
|
|
568
|
+
* @remarks Time O(n), Space O(1)
|
|
569
|
+
*/
|
|
570
|
+
findIndex(predicate, thisArg) {
|
|
571
|
+
for (let i = 0; i < this.length; i++) {
|
|
572
|
+
const item = this.at(i);
|
|
573
|
+
if (item !== void 0 && predicate.call(thisArg, item, i, this)) return i;
|
|
574
|
+
}
|
|
575
|
+
return -1;
|
|
576
|
+
}
|
|
577
|
+
/**
|
|
578
|
+
* Concatenate elements and/or containers.
|
|
579
|
+
* @param items - Elements or other containers.
|
|
580
|
+
* @returns New container with combined elements (`this` type).
|
|
581
|
+
* @remarks Time O(sum(length)), Space O(sum(length))
|
|
582
|
+
*/
|
|
583
|
+
concat(...items) {
|
|
584
|
+
const newList = this.clone();
|
|
585
|
+
for (const item of items) {
|
|
586
|
+
if (item instanceof _LinearBase) {
|
|
587
|
+
newList.pushMany(item);
|
|
588
|
+
} else {
|
|
589
|
+
newList.push(item);
|
|
590
|
+
}
|
|
591
|
+
}
|
|
592
|
+
return newList;
|
|
593
|
+
}
|
|
594
|
+
/**
|
|
595
|
+
* In-place stable order via array sort semantics.
|
|
596
|
+
* @param compareFn - Comparator `(a, b) => number`.
|
|
597
|
+
* @returns This container.
|
|
598
|
+
* @remarks Time O(n log n), Space O(n) (materializes to array temporarily)
|
|
599
|
+
*/
|
|
600
|
+
sort(compareFn) {
|
|
601
|
+
const arr = this.toArray();
|
|
602
|
+
arr.sort(compareFn);
|
|
603
|
+
this.clear();
|
|
604
|
+
for (const item of arr) this.push(item);
|
|
605
|
+
return this;
|
|
606
|
+
}
|
|
607
|
+
/**
|
|
608
|
+
* Remove and/or insert elements at a position (array-compatible).
|
|
609
|
+
* @param start - Start index (supports negative index).
|
|
610
|
+
* @param deleteCount - How many to remove.
|
|
611
|
+
* @param items - Elements to insert.
|
|
612
|
+
* @returns Removed elements as a new list (`this` type).
|
|
613
|
+
* @remarks Time O(n + m), Space O(min(n, m)) where `m = items.length`
|
|
614
|
+
*/
|
|
615
|
+
splice(start, deleteCount = 0, ...items) {
|
|
616
|
+
const removedList = this._createInstance();
|
|
617
|
+
start = start < 0 ? this.length + start : start;
|
|
618
|
+
start = Math.max(0, Math.min(start, this.length));
|
|
619
|
+
deleteCount = Math.max(0, Math.min(deleteCount, this.length - start));
|
|
620
|
+
for (let i = 0; i < deleteCount; i++) {
|
|
621
|
+
const removed = this.deleteAt(start);
|
|
622
|
+
if (removed !== void 0) {
|
|
623
|
+
removedList.push(removed);
|
|
624
|
+
}
|
|
625
|
+
}
|
|
626
|
+
for (let i = 0; i < items.length; i++) {
|
|
627
|
+
this.addAt(start + i, items[i]);
|
|
628
|
+
}
|
|
629
|
+
return removedList;
|
|
630
|
+
}
|
|
631
|
+
/**
|
|
632
|
+
* Join all elements into a string.
|
|
633
|
+
* @param separator - Separator string.
|
|
634
|
+
* @returns Concatenated string.
|
|
635
|
+
* @remarks Time O(n), Space O(n)
|
|
636
|
+
*/
|
|
637
|
+
join(separator = ",") {
|
|
638
|
+
return this.toArray().join(separator);
|
|
639
|
+
}
|
|
640
|
+
/**
|
|
641
|
+
* Snapshot elements into a reversed array.
|
|
642
|
+
* @returns New reversed array.
|
|
643
|
+
* @remarks Time O(n), Space O(n)
|
|
644
|
+
*/
|
|
645
|
+
toReversedArray() {
|
|
646
|
+
const array = [];
|
|
647
|
+
for (let i = this.length - 1; i >= 0; i--) {
|
|
648
|
+
array.push(this.at(i));
|
|
649
|
+
}
|
|
650
|
+
return array;
|
|
651
|
+
}
|
|
652
|
+
reduceRight(callbackfn, initialValue) {
|
|
653
|
+
let accumulator = initialValue != null ? initialValue : 0;
|
|
654
|
+
for (let i = this.length - 1; i >= 0; i--) {
|
|
655
|
+
accumulator = callbackfn(accumulator, this.at(i), i, this);
|
|
656
|
+
}
|
|
657
|
+
return accumulator;
|
|
658
|
+
}
|
|
659
|
+
/**
|
|
660
|
+
* Create a shallow copy of a subrange.
|
|
661
|
+
* @param start - Inclusive start (supports negative index).
|
|
662
|
+
* @param end - Exclusive end (supports negative index).
|
|
663
|
+
* @returns New list with the range (`this` type).
|
|
664
|
+
* @remarks Time O(n), Space O(n)
|
|
665
|
+
*/
|
|
666
|
+
slice(start = 0, end = this.length) {
|
|
667
|
+
start = start < 0 ? this.length + start : start;
|
|
668
|
+
end = end < 0 ? this.length + end : end;
|
|
669
|
+
const newList = this._createInstance();
|
|
670
|
+
for (let i = start; i < end; i++) {
|
|
671
|
+
newList.push(this.at(i));
|
|
672
|
+
}
|
|
673
|
+
return newList;
|
|
674
|
+
}
|
|
675
|
+
/**
|
|
676
|
+
* Fill a range with a value.
|
|
677
|
+
* @param value - Value to set.
|
|
678
|
+
* @param start - Inclusive start.
|
|
679
|
+
* @param end - Exclusive end.
|
|
680
|
+
* @returns This list.
|
|
681
|
+
* @remarks Time O(n), Space O(1)
|
|
682
|
+
*/
|
|
683
|
+
fill(value, start = 0, end = this.length) {
|
|
684
|
+
start = start < 0 ? this.length + start : start;
|
|
685
|
+
end = end < 0 ? this.length + end : end;
|
|
686
|
+
if (start < 0) start = 0;
|
|
687
|
+
if (end > this.length) end = this.length;
|
|
688
|
+
if (start >= end) return this;
|
|
689
|
+
for (let i = start; i < end; i++) {
|
|
690
|
+
this.setAt(i, value);
|
|
691
|
+
}
|
|
692
|
+
return this;
|
|
693
|
+
}
|
|
694
|
+
};
|
|
695
|
+
|
|
500
696
|
// src/data-structures/heap/heap.ts
|
|
501
697
|
var Heap = class _Heap extends IterableElementBase {
|
|
502
698
|
/**
|
|
@@ -512,7 +708,7 @@ var undirectedGraphTyped = (() => {
|
|
|
512
708
|
__publicField(this, "_elements", []);
|
|
513
709
|
__publicField(this, "_DEFAULT_COMPARATOR", (a, b) => {
|
|
514
710
|
if (typeof a === "object" || typeof b === "object") {
|
|
515
|
-
|
|
711
|
+
raise(TypeError, ERR.comparatorRequired("Heap"));
|
|
516
712
|
}
|
|
517
713
|
if (a > b) return 1;
|
|
518
714
|
if (a < b) return -1;
|
|
@@ -548,6 +744,30 @@ var undirectedGraphTyped = (() => {
|
|
|
548
744
|
|
|
549
745
|
|
|
550
746
|
|
|
747
|
+
|
|
748
|
+
|
|
749
|
+
|
|
750
|
+
|
|
751
|
+
|
|
752
|
+
|
|
753
|
+
|
|
754
|
+
|
|
755
|
+
|
|
756
|
+
|
|
757
|
+
|
|
758
|
+
|
|
759
|
+
|
|
760
|
+
|
|
761
|
+
|
|
762
|
+
|
|
763
|
+
|
|
764
|
+
|
|
765
|
+
|
|
766
|
+
|
|
767
|
+
|
|
768
|
+
|
|
769
|
+
|
|
770
|
+
|
|
551
771
|
* @example
|
|
552
772
|
* // Track heap capacity
|
|
553
773
|
* const heap = new Heap<number>();
|
|
@@ -611,6 +831,30 @@ var undirectedGraphTyped = (() => {
|
|
|
611
831
|
|
|
612
832
|
|
|
613
833
|
|
|
834
|
+
|
|
835
|
+
|
|
836
|
+
|
|
837
|
+
|
|
838
|
+
|
|
839
|
+
|
|
840
|
+
|
|
841
|
+
|
|
842
|
+
|
|
843
|
+
|
|
844
|
+
|
|
845
|
+
|
|
846
|
+
|
|
847
|
+
|
|
848
|
+
|
|
849
|
+
|
|
850
|
+
|
|
851
|
+
|
|
852
|
+
|
|
853
|
+
|
|
854
|
+
|
|
855
|
+
|
|
856
|
+
|
|
857
|
+
|
|
614
858
|
* @example
|
|
615
859
|
* // basic Heap creation and add operation
|
|
616
860
|
* // Create a min heap (default)
|
|
@@ -644,6 +888,30 @@ var undirectedGraphTyped = (() => {
|
|
|
644
888
|
|
|
645
889
|
|
|
646
890
|
|
|
891
|
+
|
|
892
|
+
|
|
893
|
+
|
|
894
|
+
|
|
895
|
+
|
|
896
|
+
|
|
897
|
+
|
|
898
|
+
|
|
899
|
+
|
|
900
|
+
|
|
901
|
+
|
|
902
|
+
|
|
903
|
+
|
|
904
|
+
|
|
905
|
+
|
|
906
|
+
|
|
907
|
+
|
|
908
|
+
|
|
909
|
+
|
|
910
|
+
|
|
911
|
+
|
|
912
|
+
|
|
913
|
+
|
|
914
|
+
|
|
647
915
|
* @example
|
|
648
916
|
* // Add multiple elements
|
|
649
917
|
* const heap = new Heap<number>([], { comparator: (a, b) => a - b });
|
|
@@ -679,6 +947,30 @@ var undirectedGraphTyped = (() => {
|
|
|
679
947
|
|
|
680
948
|
|
|
681
949
|
|
|
950
|
+
|
|
951
|
+
|
|
952
|
+
|
|
953
|
+
|
|
954
|
+
|
|
955
|
+
|
|
956
|
+
|
|
957
|
+
|
|
958
|
+
|
|
959
|
+
|
|
960
|
+
|
|
961
|
+
|
|
962
|
+
|
|
963
|
+
|
|
964
|
+
|
|
965
|
+
|
|
966
|
+
|
|
967
|
+
|
|
968
|
+
|
|
969
|
+
|
|
970
|
+
|
|
971
|
+
|
|
972
|
+
|
|
973
|
+
|
|
682
974
|
* @example
|
|
683
975
|
* // Heap with custom comparator (MaxHeap behavior)
|
|
684
976
|
* interface Task {
|
|
@@ -730,6 +1022,30 @@ var undirectedGraphTyped = (() => {
|
|
|
730
1022
|
|
|
731
1023
|
|
|
732
1024
|
|
|
1025
|
+
|
|
1026
|
+
|
|
1027
|
+
|
|
1028
|
+
|
|
1029
|
+
|
|
1030
|
+
|
|
1031
|
+
|
|
1032
|
+
|
|
1033
|
+
|
|
1034
|
+
|
|
1035
|
+
|
|
1036
|
+
|
|
1037
|
+
|
|
1038
|
+
|
|
1039
|
+
|
|
1040
|
+
|
|
1041
|
+
|
|
1042
|
+
|
|
1043
|
+
|
|
1044
|
+
|
|
1045
|
+
|
|
1046
|
+
|
|
1047
|
+
|
|
1048
|
+
|
|
733
1049
|
* @example
|
|
734
1050
|
* // Heap for event processing with priority
|
|
735
1051
|
* interface Event {
|
|
@@ -806,6 +1122,30 @@ var undirectedGraphTyped = (() => {
|
|
|
806
1122
|
|
|
807
1123
|
|
|
808
1124
|
|
|
1125
|
+
|
|
1126
|
+
|
|
1127
|
+
|
|
1128
|
+
|
|
1129
|
+
|
|
1130
|
+
|
|
1131
|
+
|
|
1132
|
+
|
|
1133
|
+
|
|
1134
|
+
|
|
1135
|
+
|
|
1136
|
+
|
|
1137
|
+
|
|
1138
|
+
|
|
1139
|
+
|
|
1140
|
+
|
|
1141
|
+
|
|
1142
|
+
|
|
1143
|
+
|
|
1144
|
+
|
|
1145
|
+
|
|
1146
|
+
|
|
1147
|
+
|
|
1148
|
+
|
|
809
1149
|
* @example
|
|
810
1150
|
* // Check if heap is empty
|
|
811
1151
|
* const heap = new Heap<number>([], { comparator: (a, b) => a - b });
|
|
@@ -829,6 +1169,30 @@ var undirectedGraphTyped = (() => {
|
|
|
829
1169
|
|
|
830
1170
|
|
|
831
1171
|
|
|
1172
|
+
|
|
1173
|
+
|
|
1174
|
+
|
|
1175
|
+
|
|
1176
|
+
|
|
1177
|
+
|
|
1178
|
+
|
|
1179
|
+
|
|
1180
|
+
|
|
1181
|
+
|
|
1182
|
+
|
|
1183
|
+
|
|
1184
|
+
|
|
1185
|
+
|
|
1186
|
+
|
|
1187
|
+
|
|
1188
|
+
|
|
1189
|
+
|
|
1190
|
+
|
|
1191
|
+
|
|
1192
|
+
|
|
1193
|
+
|
|
1194
|
+
|
|
1195
|
+
|
|
832
1196
|
* @example
|
|
833
1197
|
* // Remove all elements
|
|
834
1198
|
* const heap = new Heap<number>([1, 2, 3], { comparator: (a, b) => a - b });
|
|
@@ -855,6 +1219,30 @@ var undirectedGraphTyped = (() => {
|
|
|
855
1219
|
* @returns True if found.
|
|
856
1220
|
|
|
857
1221
|
|
|
1222
|
+
|
|
1223
|
+
|
|
1224
|
+
|
|
1225
|
+
|
|
1226
|
+
|
|
1227
|
+
|
|
1228
|
+
|
|
1229
|
+
|
|
1230
|
+
|
|
1231
|
+
|
|
1232
|
+
|
|
1233
|
+
|
|
1234
|
+
|
|
1235
|
+
|
|
1236
|
+
|
|
1237
|
+
|
|
1238
|
+
|
|
1239
|
+
|
|
1240
|
+
|
|
1241
|
+
|
|
1242
|
+
|
|
1243
|
+
|
|
1244
|
+
|
|
1245
|
+
|
|
858
1246
|
* @example
|
|
859
1247
|
* // Check element existence
|
|
860
1248
|
* const heap = new Heap<number>([3, 1, 2], { comparator: (a, b) => a - b });
|
|
@@ -878,6 +1266,30 @@ var undirectedGraphTyped = (() => {
|
|
|
878
1266
|
|
|
879
1267
|
|
|
880
1268
|
|
|
1269
|
+
|
|
1270
|
+
|
|
1271
|
+
|
|
1272
|
+
|
|
1273
|
+
|
|
1274
|
+
|
|
1275
|
+
|
|
1276
|
+
|
|
1277
|
+
|
|
1278
|
+
|
|
1279
|
+
|
|
1280
|
+
|
|
1281
|
+
|
|
1282
|
+
|
|
1283
|
+
|
|
1284
|
+
|
|
1285
|
+
|
|
1286
|
+
|
|
1287
|
+
|
|
1288
|
+
|
|
1289
|
+
|
|
1290
|
+
|
|
1291
|
+
|
|
1292
|
+
|
|
881
1293
|
* @example
|
|
882
1294
|
* // Remove specific element
|
|
883
1295
|
* const heap = new Heap<number>([3, 1, 4, 1, 5], { comparator: (a, b) => a - b });
|
|
@@ -947,6 +1359,30 @@ var undirectedGraphTyped = (() => {
|
|
|
947
1359
|
* @returns Array of visited elements.
|
|
948
1360
|
|
|
949
1361
|
|
|
1362
|
+
|
|
1363
|
+
|
|
1364
|
+
|
|
1365
|
+
|
|
1366
|
+
|
|
1367
|
+
|
|
1368
|
+
|
|
1369
|
+
|
|
1370
|
+
|
|
1371
|
+
|
|
1372
|
+
|
|
1373
|
+
|
|
1374
|
+
|
|
1375
|
+
|
|
1376
|
+
|
|
1377
|
+
|
|
1378
|
+
|
|
1379
|
+
|
|
1380
|
+
|
|
1381
|
+
|
|
1382
|
+
|
|
1383
|
+
|
|
1384
|
+
|
|
1385
|
+
|
|
950
1386
|
* @example
|
|
951
1387
|
* // Depth-first traversal
|
|
952
1388
|
* const heap = new Heap<number>([3, 1, 2], { comparator: (a, b) => a - b });
|
|
@@ -1003,6 +1439,30 @@ var undirectedGraphTyped = (() => {
|
|
|
1003
1439
|
|
|
1004
1440
|
|
|
1005
1441
|
|
|
1442
|
+
|
|
1443
|
+
|
|
1444
|
+
|
|
1445
|
+
|
|
1446
|
+
|
|
1447
|
+
|
|
1448
|
+
|
|
1449
|
+
|
|
1450
|
+
|
|
1451
|
+
|
|
1452
|
+
|
|
1453
|
+
|
|
1454
|
+
|
|
1455
|
+
|
|
1456
|
+
|
|
1457
|
+
|
|
1458
|
+
|
|
1459
|
+
|
|
1460
|
+
|
|
1461
|
+
|
|
1462
|
+
|
|
1463
|
+
|
|
1464
|
+
|
|
1465
|
+
|
|
1006
1466
|
* @example
|
|
1007
1467
|
* // Sort elements using heap
|
|
1008
1468
|
* const heap = new Heap<number>([5, 1, 3, 2, 4]);
|
|
@@ -1032,6 +1492,30 @@ var undirectedGraphTyped = (() => {
|
|
|
1032
1492
|
|
|
1033
1493
|
|
|
1034
1494
|
|
|
1495
|
+
|
|
1496
|
+
|
|
1497
|
+
|
|
1498
|
+
|
|
1499
|
+
|
|
1500
|
+
|
|
1501
|
+
|
|
1502
|
+
|
|
1503
|
+
|
|
1504
|
+
|
|
1505
|
+
|
|
1506
|
+
|
|
1507
|
+
|
|
1508
|
+
|
|
1509
|
+
|
|
1510
|
+
|
|
1511
|
+
|
|
1512
|
+
|
|
1513
|
+
|
|
1514
|
+
|
|
1515
|
+
|
|
1516
|
+
|
|
1517
|
+
|
|
1518
|
+
|
|
1035
1519
|
* @example
|
|
1036
1520
|
* // Create independent copy
|
|
1037
1521
|
* const heap = new Heap<number>([3, 1, 4], { comparator: (a, b) => a - b });
|
|
@@ -1060,6 +1544,30 @@ var undirectedGraphTyped = (() => {
|
|
|
1060
1544
|
|
|
1061
1545
|
|
|
1062
1546
|
|
|
1547
|
+
|
|
1548
|
+
|
|
1549
|
+
|
|
1550
|
+
|
|
1551
|
+
|
|
1552
|
+
|
|
1553
|
+
|
|
1554
|
+
|
|
1555
|
+
|
|
1556
|
+
|
|
1557
|
+
|
|
1558
|
+
|
|
1559
|
+
|
|
1560
|
+
|
|
1561
|
+
|
|
1562
|
+
|
|
1563
|
+
|
|
1564
|
+
|
|
1565
|
+
|
|
1566
|
+
|
|
1567
|
+
|
|
1568
|
+
|
|
1569
|
+
|
|
1570
|
+
|
|
1063
1571
|
* @example
|
|
1064
1572
|
* // Filter elements
|
|
1065
1573
|
* const heap = new Heap<number>([1, 2, 3, 4, 5], { comparator: (a, b) => a - b });
|
|
@@ -1095,6 +1603,30 @@ var undirectedGraphTyped = (() => {
|
|
|
1095
1603
|
|
|
1096
1604
|
|
|
1097
1605
|
|
|
1606
|
+
|
|
1607
|
+
|
|
1608
|
+
|
|
1609
|
+
|
|
1610
|
+
|
|
1611
|
+
|
|
1612
|
+
|
|
1613
|
+
|
|
1614
|
+
|
|
1615
|
+
|
|
1616
|
+
|
|
1617
|
+
|
|
1618
|
+
|
|
1619
|
+
|
|
1620
|
+
|
|
1621
|
+
|
|
1622
|
+
|
|
1623
|
+
|
|
1624
|
+
|
|
1625
|
+
|
|
1626
|
+
|
|
1627
|
+
|
|
1628
|
+
|
|
1629
|
+
|
|
1098
1630
|
* @example
|
|
1099
1631
|
* // Transform elements
|
|
1100
1632
|
* const heap = new Heap<number>([1, 2, 3], { comparator: (a, b) => a - b });
|
|
@@ -1103,7 +1635,7 @@ var undirectedGraphTyped = (() => {
|
|
|
1103
1635
|
*/
|
|
1104
1636
|
map(callback, options, thisArg) {
|
|
1105
1637
|
const { comparator, toElementFn, ...rest } = options != null ? options : {};
|
|
1106
|
-
if (!comparator)
|
|
1638
|
+
if (!comparator) raise(TypeError, ERR.comparatorRequired("Heap.map"));
|
|
1107
1639
|
const out = this._createLike([], { ...rest, comparator, toElementFn });
|
|
1108
1640
|
let i = 0;
|
|
1109
1641
|
for (const x of this) {
|
|
@@ -1193,204 +1725,14 @@ var undirectedGraphTyped = (() => {
|
|
|
1193
1725
|
}
|
|
1194
1726
|
/**
|
|
1195
1727
|
* (Protected) Spawn an empty like-kind heap instance.
|
|
1196
|
-
* @remarks Time O(1), Space O(1)
|
|
1197
|
-
* @template EM
|
|
1198
|
-
* @template RM
|
|
1199
|
-
* @param [options] - Options forwarded to the constructor.
|
|
1200
|
-
* @returns An empty like-kind heap instance.
|
|
1201
|
-
*/
|
|
1202
|
-
_spawnLike(options) {
|
|
1203
|
-
return this._createLike([], options);
|
|
1204
|
-
}
|
|
1205
|
-
};
|
|
1206
|
-
|
|
1207
|
-
// src/data-structures/base/linear-base.ts
|
|
1208
|
-
var LinearBase = class _LinearBase extends IterableElementBase {
|
|
1209
|
-
/**
|
|
1210
|
-
* Construct a linear container with runtime options.
|
|
1211
|
-
* @param options - `{ maxLen?, ... }` bounds/behavior options.
|
|
1212
|
-
* @remarks Time O(1), Space O(1)
|
|
1213
|
-
*/
|
|
1214
|
-
constructor(options) {
|
|
1215
|
-
super(options);
|
|
1216
|
-
__publicField(this, "_maxLen", -1);
|
|
1217
|
-
if (options) {
|
|
1218
|
-
const { maxLen } = options;
|
|
1219
|
-
if (typeof maxLen === "number" && maxLen > 0 && maxLen % 1 === 0) this._maxLen = maxLen;
|
|
1220
|
-
}
|
|
1221
|
-
}
|
|
1222
|
-
/**
|
|
1223
|
-
* Upper bound for length (if positive), or `-1` when unbounded.
|
|
1224
|
-
* @returns Maximum allowed length.
|
|
1225
|
-
* @remarks Time O(1), Space O(1)
|
|
1226
|
-
*/
|
|
1227
|
-
get maxLen() {
|
|
1228
|
-
return this._maxLen;
|
|
1229
|
-
}
|
|
1230
|
-
/**
|
|
1231
|
-
* First index of a value from the left.
|
|
1232
|
-
* @param searchElement - Value to match.
|
|
1233
|
-
* @param fromIndex - Start position (supports negative index).
|
|
1234
|
-
* @returns Index or `-1` if not found.
|
|
1235
|
-
* @remarks Time O(n), Space O(1)
|
|
1236
|
-
*/
|
|
1237
|
-
indexOf(searchElement, fromIndex = 0) {
|
|
1238
|
-
if (this.length === 0) return -1;
|
|
1239
|
-
if (fromIndex < 0) fromIndex = this.length + fromIndex;
|
|
1240
|
-
if (fromIndex < 0) fromIndex = 0;
|
|
1241
|
-
for (let i = fromIndex; i < this.length; i++) {
|
|
1242
|
-
const element = this.at(i);
|
|
1243
|
-
if (element === searchElement) return i;
|
|
1244
|
-
}
|
|
1245
|
-
return -1;
|
|
1246
|
-
}
|
|
1247
|
-
/**
|
|
1248
|
-
* Last index of a value from the right.
|
|
1249
|
-
* @param searchElement - Value to match.
|
|
1250
|
-
* @param fromIndex - Start position (supports negative index).
|
|
1251
|
-
* @returns Index or `-1` if not found.
|
|
1252
|
-
* @remarks Time O(n), Space O(1)
|
|
1253
|
-
*/
|
|
1254
|
-
lastIndexOf(searchElement, fromIndex = this.length - 1) {
|
|
1255
|
-
if (this.length === 0) return -1;
|
|
1256
|
-
if (fromIndex >= this.length) fromIndex = this.length - 1;
|
|
1257
|
-
if (fromIndex < 0) fromIndex = this.length + fromIndex;
|
|
1258
|
-
for (let i = fromIndex; i >= 0; i--) {
|
|
1259
|
-
const element = this.at(i);
|
|
1260
|
-
if (element === searchElement) return i;
|
|
1261
|
-
}
|
|
1262
|
-
return -1;
|
|
1263
|
-
}
|
|
1264
|
-
/**
|
|
1265
|
-
* Find the first index matching a predicate.
|
|
1266
|
-
* @param predicate - `(element, index, self) => boolean`.
|
|
1267
|
-
* @param thisArg - Optional `this` for callback.
|
|
1268
|
-
* @returns Index or `-1`.
|
|
1269
|
-
* @remarks Time O(n), Space O(1)
|
|
1270
|
-
*/
|
|
1271
|
-
findIndex(predicate, thisArg) {
|
|
1272
|
-
for (let i = 0; i < this.length; i++) {
|
|
1273
|
-
const item = this.at(i);
|
|
1274
|
-
if (item !== void 0 && predicate.call(thisArg, item, i, this)) return i;
|
|
1275
|
-
}
|
|
1276
|
-
return -1;
|
|
1277
|
-
}
|
|
1278
|
-
/**
|
|
1279
|
-
* Concatenate elements and/or containers.
|
|
1280
|
-
* @param items - Elements or other containers.
|
|
1281
|
-
* @returns New container with combined elements (`this` type).
|
|
1282
|
-
* @remarks Time O(sum(length)), Space O(sum(length))
|
|
1283
|
-
*/
|
|
1284
|
-
concat(...items) {
|
|
1285
|
-
const newList = this.clone();
|
|
1286
|
-
for (const item of items) {
|
|
1287
|
-
if (item instanceof _LinearBase) {
|
|
1288
|
-
newList.pushMany(item);
|
|
1289
|
-
} else {
|
|
1290
|
-
newList.push(item);
|
|
1291
|
-
}
|
|
1292
|
-
}
|
|
1293
|
-
return newList;
|
|
1294
|
-
}
|
|
1295
|
-
/**
|
|
1296
|
-
* In-place stable order via array sort semantics.
|
|
1297
|
-
* @param compareFn - Comparator `(a, b) => number`.
|
|
1298
|
-
* @returns This container.
|
|
1299
|
-
* @remarks Time O(n log n), Space O(n) (materializes to array temporarily)
|
|
1300
|
-
*/
|
|
1301
|
-
sort(compareFn) {
|
|
1302
|
-
const arr = this.toArray();
|
|
1303
|
-
arr.sort(compareFn);
|
|
1304
|
-
this.clear();
|
|
1305
|
-
for (const item of arr) this.push(item);
|
|
1306
|
-
return this;
|
|
1307
|
-
}
|
|
1308
|
-
/**
|
|
1309
|
-
* Remove and/or insert elements at a position (array-compatible).
|
|
1310
|
-
* @param start - Start index (supports negative index).
|
|
1311
|
-
* @param deleteCount - How many to remove.
|
|
1312
|
-
* @param items - Elements to insert.
|
|
1313
|
-
* @returns Removed elements as a new list (`this` type).
|
|
1314
|
-
* @remarks Time O(n + m), Space O(min(n, m)) where `m = items.length`
|
|
1315
|
-
*/
|
|
1316
|
-
splice(start, deleteCount = 0, ...items) {
|
|
1317
|
-
const removedList = this._createInstance();
|
|
1318
|
-
start = start < 0 ? this.length + start : start;
|
|
1319
|
-
start = Math.max(0, Math.min(start, this.length));
|
|
1320
|
-
deleteCount = Math.max(0, Math.min(deleteCount, this.length - start));
|
|
1321
|
-
for (let i = 0; i < deleteCount; i++) {
|
|
1322
|
-
const removed = this.deleteAt(start);
|
|
1323
|
-
if (removed !== void 0) {
|
|
1324
|
-
removedList.push(removed);
|
|
1325
|
-
}
|
|
1326
|
-
}
|
|
1327
|
-
for (let i = 0; i < items.length; i++) {
|
|
1328
|
-
this.addAt(start + i, items[i]);
|
|
1329
|
-
}
|
|
1330
|
-
return removedList;
|
|
1331
|
-
}
|
|
1332
|
-
/**
|
|
1333
|
-
* Join all elements into a string.
|
|
1334
|
-
* @param separator - Separator string.
|
|
1335
|
-
* @returns Concatenated string.
|
|
1336
|
-
* @remarks Time O(n), Space O(n)
|
|
1337
|
-
*/
|
|
1338
|
-
join(separator = ",") {
|
|
1339
|
-
return this.toArray().join(separator);
|
|
1340
|
-
}
|
|
1341
|
-
/**
|
|
1342
|
-
* Snapshot elements into a reversed array.
|
|
1343
|
-
* @returns New reversed array.
|
|
1344
|
-
* @remarks Time O(n), Space O(n)
|
|
1345
|
-
*/
|
|
1346
|
-
toReversedArray() {
|
|
1347
|
-
const array = [];
|
|
1348
|
-
for (let i = this.length - 1; i >= 0; i--) {
|
|
1349
|
-
array.push(this.at(i));
|
|
1350
|
-
}
|
|
1351
|
-
return array;
|
|
1352
|
-
}
|
|
1353
|
-
reduceRight(callbackfn, initialValue) {
|
|
1354
|
-
let accumulator = initialValue != null ? initialValue : 0;
|
|
1355
|
-
for (let i = this.length - 1; i >= 0; i--) {
|
|
1356
|
-
accumulator = callbackfn(accumulator, this.at(i), i, this);
|
|
1357
|
-
}
|
|
1358
|
-
return accumulator;
|
|
1359
|
-
}
|
|
1360
|
-
/**
|
|
1361
|
-
* Create a shallow copy of a subrange.
|
|
1362
|
-
* @param start - Inclusive start (supports negative index).
|
|
1363
|
-
* @param end - Exclusive end (supports negative index).
|
|
1364
|
-
* @returns New list with the range (`this` type).
|
|
1365
|
-
* @remarks Time O(n), Space O(n)
|
|
1366
|
-
*/
|
|
1367
|
-
slice(start = 0, end = this.length) {
|
|
1368
|
-
start = start < 0 ? this.length + start : start;
|
|
1369
|
-
end = end < 0 ? this.length + end : end;
|
|
1370
|
-
const newList = this._createInstance();
|
|
1371
|
-
for (let i = start; i < end; i++) {
|
|
1372
|
-
newList.push(this.at(i));
|
|
1373
|
-
}
|
|
1374
|
-
return newList;
|
|
1375
|
-
}
|
|
1376
|
-
/**
|
|
1377
|
-
* Fill a range with a value.
|
|
1378
|
-
* @param value - Value to set.
|
|
1379
|
-
* @param start - Inclusive start.
|
|
1380
|
-
* @param end - Exclusive end.
|
|
1381
|
-
* @returns This list.
|
|
1382
|
-
* @remarks Time O(n), Space O(1)
|
|
1383
|
-
*/
|
|
1384
|
-
fill(value, start = 0, end = this.length) {
|
|
1385
|
-
start = start < 0 ? this.length + start : start;
|
|
1386
|
-
end = end < 0 ? this.length + end : end;
|
|
1387
|
-
if (start < 0) start = 0;
|
|
1388
|
-
if (end > this.length) end = this.length;
|
|
1389
|
-
if (start >= end) return this;
|
|
1390
|
-
for (let i = start; i < end; i++) {
|
|
1391
|
-
this.setAt(i, value);
|
|
1392
|
-
}
|
|
1393
|
-
return this;
|
|
1728
|
+
* @remarks Time O(1), Space O(1)
|
|
1729
|
+
* @template EM
|
|
1730
|
+
* @template RM
|
|
1731
|
+
* @param [options] - Options forwarded to the constructor.
|
|
1732
|
+
* @returns An empty like-kind heap instance.
|
|
1733
|
+
*/
|
|
1734
|
+
_spawnLike(options) {
|
|
1735
|
+
return this._createLike([], options);
|
|
1394
1736
|
}
|
|
1395
1737
|
};
|
|
1396
1738
|
|
|
@@ -1462,6 +1804,30 @@ var undirectedGraphTyped = (() => {
|
|
|
1462
1804
|
|
|
1463
1805
|
|
|
1464
1806
|
|
|
1807
|
+
|
|
1808
|
+
|
|
1809
|
+
|
|
1810
|
+
|
|
1811
|
+
|
|
1812
|
+
|
|
1813
|
+
|
|
1814
|
+
|
|
1815
|
+
|
|
1816
|
+
|
|
1817
|
+
|
|
1818
|
+
|
|
1819
|
+
|
|
1820
|
+
|
|
1821
|
+
|
|
1822
|
+
|
|
1823
|
+
|
|
1824
|
+
|
|
1825
|
+
|
|
1826
|
+
|
|
1827
|
+
|
|
1828
|
+
|
|
1829
|
+
|
|
1830
|
+
|
|
1465
1831
|
* @example
|
|
1466
1832
|
* // Track queue length
|
|
1467
1833
|
* const q = new Queue<number>();
|
|
@@ -1488,6 +1854,30 @@ var undirectedGraphTyped = (() => {
|
|
|
1488
1854
|
|
|
1489
1855
|
|
|
1490
1856
|
|
|
1857
|
+
|
|
1858
|
+
|
|
1859
|
+
|
|
1860
|
+
|
|
1861
|
+
|
|
1862
|
+
|
|
1863
|
+
|
|
1864
|
+
|
|
1865
|
+
|
|
1866
|
+
|
|
1867
|
+
|
|
1868
|
+
|
|
1869
|
+
|
|
1870
|
+
|
|
1871
|
+
|
|
1872
|
+
|
|
1873
|
+
|
|
1874
|
+
|
|
1875
|
+
|
|
1876
|
+
|
|
1877
|
+
|
|
1878
|
+
|
|
1879
|
+
|
|
1880
|
+
|
|
1491
1881
|
* @example
|
|
1492
1882
|
* // View the front element
|
|
1493
1883
|
* const q = new Queue<string>(['first', 'second', 'third']);
|
|
@@ -1530,6 +1920,30 @@ var undirectedGraphTyped = (() => {
|
|
|
1530
1920
|
|
|
1531
1921
|
|
|
1532
1922
|
|
|
1923
|
+
|
|
1924
|
+
|
|
1925
|
+
|
|
1926
|
+
|
|
1927
|
+
|
|
1928
|
+
|
|
1929
|
+
|
|
1930
|
+
|
|
1931
|
+
|
|
1932
|
+
|
|
1933
|
+
|
|
1934
|
+
|
|
1935
|
+
|
|
1936
|
+
|
|
1937
|
+
|
|
1938
|
+
|
|
1939
|
+
|
|
1940
|
+
|
|
1941
|
+
|
|
1942
|
+
|
|
1943
|
+
|
|
1944
|
+
|
|
1945
|
+
|
|
1946
|
+
|
|
1533
1947
|
* @example
|
|
1534
1948
|
* // Queue for...of iteration and isEmpty check
|
|
1535
1949
|
* const queue = new Queue<string>(['A', 'B', 'C', 'D']);
|
|
@@ -1568,6 +1982,30 @@ var undirectedGraphTyped = (() => {
|
|
|
1568
1982
|
|
|
1569
1983
|
|
|
1570
1984
|
|
|
1985
|
+
|
|
1986
|
+
|
|
1987
|
+
|
|
1988
|
+
|
|
1989
|
+
|
|
1990
|
+
|
|
1991
|
+
|
|
1992
|
+
|
|
1993
|
+
|
|
1994
|
+
|
|
1995
|
+
|
|
1996
|
+
|
|
1997
|
+
|
|
1998
|
+
|
|
1999
|
+
|
|
2000
|
+
|
|
2001
|
+
|
|
2002
|
+
|
|
2003
|
+
|
|
2004
|
+
|
|
2005
|
+
|
|
2006
|
+
|
|
2007
|
+
|
|
2008
|
+
|
|
1571
2009
|
* @example
|
|
1572
2010
|
* // basic Queue creation and push operation
|
|
1573
2011
|
* // Create a simple Queue with initial values
|
|
@@ -1613,6 +2051,30 @@ var undirectedGraphTyped = (() => {
|
|
|
1613
2051
|
|
|
1614
2052
|
|
|
1615
2053
|
|
|
2054
|
+
|
|
2055
|
+
|
|
2056
|
+
|
|
2057
|
+
|
|
2058
|
+
|
|
2059
|
+
|
|
2060
|
+
|
|
2061
|
+
|
|
2062
|
+
|
|
2063
|
+
|
|
2064
|
+
|
|
2065
|
+
|
|
2066
|
+
|
|
2067
|
+
|
|
2068
|
+
|
|
2069
|
+
|
|
2070
|
+
|
|
2071
|
+
|
|
2072
|
+
|
|
2073
|
+
|
|
2074
|
+
|
|
2075
|
+
|
|
2076
|
+
|
|
2077
|
+
|
|
1616
2078
|
* @example
|
|
1617
2079
|
* // Queue shift and peek operations
|
|
1618
2080
|
* const queue = new Queue<number>([10, 20, 30, 40]);
|
|
@@ -1648,6 +2110,30 @@ var undirectedGraphTyped = (() => {
|
|
|
1648
2110
|
|
|
1649
2111
|
|
|
1650
2112
|
|
|
2113
|
+
|
|
2114
|
+
|
|
2115
|
+
|
|
2116
|
+
|
|
2117
|
+
|
|
2118
|
+
|
|
2119
|
+
|
|
2120
|
+
|
|
2121
|
+
|
|
2122
|
+
|
|
2123
|
+
|
|
2124
|
+
|
|
2125
|
+
|
|
2126
|
+
|
|
2127
|
+
|
|
2128
|
+
|
|
2129
|
+
|
|
2130
|
+
|
|
2131
|
+
|
|
2132
|
+
|
|
2133
|
+
|
|
2134
|
+
|
|
2135
|
+
|
|
2136
|
+
|
|
1651
2137
|
* @example
|
|
1652
2138
|
* // Remove specific element
|
|
1653
2139
|
* const q = new Queue<number>([1, 2, 3, 2]);
|
|
@@ -1676,6 +2162,30 @@ var undirectedGraphTyped = (() => {
|
|
|
1676
2162
|
|
|
1677
2163
|
|
|
1678
2164
|
|
|
2165
|
+
|
|
2166
|
+
|
|
2167
|
+
|
|
2168
|
+
|
|
2169
|
+
|
|
2170
|
+
|
|
2171
|
+
|
|
2172
|
+
|
|
2173
|
+
|
|
2174
|
+
|
|
2175
|
+
|
|
2176
|
+
|
|
2177
|
+
|
|
2178
|
+
|
|
2179
|
+
|
|
2180
|
+
|
|
2181
|
+
|
|
2182
|
+
|
|
2183
|
+
|
|
2184
|
+
|
|
2185
|
+
|
|
2186
|
+
|
|
2187
|
+
|
|
2188
|
+
|
|
1679
2189
|
* @example
|
|
1680
2190
|
* // Access element by index
|
|
1681
2191
|
* const q = new Queue<string>(['a', 'b', 'c']);
|
|
@@ -1745,6 +2255,30 @@ var undirectedGraphTyped = (() => {
|
|
|
1745
2255
|
|
|
1746
2256
|
|
|
1747
2257
|
|
|
2258
|
+
|
|
2259
|
+
|
|
2260
|
+
|
|
2261
|
+
|
|
2262
|
+
|
|
2263
|
+
|
|
2264
|
+
|
|
2265
|
+
|
|
2266
|
+
|
|
2267
|
+
|
|
2268
|
+
|
|
2269
|
+
|
|
2270
|
+
|
|
2271
|
+
|
|
2272
|
+
|
|
2273
|
+
|
|
2274
|
+
|
|
2275
|
+
|
|
2276
|
+
|
|
2277
|
+
|
|
2278
|
+
|
|
2279
|
+
|
|
2280
|
+
|
|
2281
|
+
|
|
1748
2282
|
* @example
|
|
1749
2283
|
* // Remove all elements
|
|
1750
2284
|
* const q = new Queue<number>([1, 2, 3]);
|
|
@@ -1767,6 +2301,30 @@ var undirectedGraphTyped = (() => {
|
|
|
1767
2301
|
|
|
1768
2302
|
|
|
1769
2303
|
|
|
2304
|
+
|
|
2305
|
+
|
|
2306
|
+
|
|
2307
|
+
|
|
2308
|
+
|
|
2309
|
+
|
|
2310
|
+
|
|
2311
|
+
|
|
2312
|
+
|
|
2313
|
+
|
|
2314
|
+
|
|
2315
|
+
|
|
2316
|
+
|
|
2317
|
+
|
|
2318
|
+
|
|
2319
|
+
|
|
2320
|
+
|
|
2321
|
+
|
|
2322
|
+
|
|
2323
|
+
|
|
2324
|
+
|
|
2325
|
+
|
|
2326
|
+
|
|
2327
|
+
|
|
1770
2328
|
* @example
|
|
1771
2329
|
* // Reclaim unused memory
|
|
1772
2330
|
* const q = new Queue<number>([1, 2, 3, 4, 5]);
|
|
@@ -1812,6 +2370,30 @@ var undirectedGraphTyped = (() => {
|
|
|
1812
2370
|
|
|
1813
2371
|
|
|
1814
2372
|
|
|
2373
|
+
|
|
2374
|
+
|
|
2375
|
+
|
|
2376
|
+
|
|
2377
|
+
|
|
2378
|
+
|
|
2379
|
+
|
|
2380
|
+
|
|
2381
|
+
|
|
2382
|
+
|
|
2383
|
+
|
|
2384
|
+
|
|
2385
|
+
|
|
2386
|
+
|
|
2387
|
+
|
|
2388
|
+
|
|
2389
|
+
|
|
2390
|
+
|
|
2391
|
+
|
|
2392
|
+
|
|
2393
|
+
|
|
2394
|
+
|
|
2395
|
+
|
|
2396
|
+
|
|
1815
2397
|
* @example
|
|
1816
2398
|
* // Create independent copy
|
|
1817
2399
|
* const q = new Queue<number>([1, 2, 3]);
|
|
@@ -1841,6 +2423,30 @@ var undirectedGraphTyped = (() => {
|
|
|
1841
2423
|
|
|
1842
2424
|
|
|
1843
2425
|
|
|
2426
|
+
|
|
2427
|
+
|
|
2428
|
+
|
|
2429
|
+
|
|
2430
|
+
|
|
2431
|
+
|
|
2432
|
+
|
|
2433
|
+
|
|
2434
|
+
|
|
2435
|
+
|
|
2436
|
+
|
|
2437
|
+
|
|
2438
|
+
|
|
2439
|
+
|
|
2440
|
+
|
|
2441
|
+
|
|
2442
|
+
|
|
2443
|
+
|
|
2444
|
+
|
|
2445
|
+
|
|
2446
|
+
|
|
2447
|
+
|
|
2448
|
+
|
|
2449
|
+
|
|
1844
2450
|
* @example
|
|
1845
2451
|
* // Filter elements
|
|
1846
2452
|
* const q = new Queue<number>([1, 2, 3, 4, 5]);
|
|
@@ -1874,6 +2480,30 @@ var undirectedGraphTyped = (() => {
|
|
|
1874
2480
|
|
|
1875
2481
|
|
|
1876
2482
|
|
|
2483
|
+
|
|
2484
|
+
|
|
2485
|
+
|
|
2486
|
+
|
|
2487
|
+
|
|
2488
|
+
|
|
2489
|
+
|
|
2490
|
+
|
|
2491
|
+
|
|
2492
|
+
|
|
2493
|
+
|
|
2494
|
+
|
|
2495
|
+
|
|
2496
|
+
|
|
2497
|
+
|
|
2498
|
+
|
|
2499
|
+
|
|
2500
|
+
|
|
2501
|
+
|
|
2502
|
+
|
|
2503
|
+
|
|
2504
|
+
|
|
2505
|
+
|
|
2506
|
+
|
|
1877
2507
|
* @example
|
|
1878
2508
|
* // Transform elements
|
|
1879
2509
|
* const q = new Queue<number>([1, 2, 3]);
|
|
@@ -2102,7 +2732,7 @@ var undirectedGraphTyped = (() => {
|
|
|
2102
2732
|
const newEdge = this.createEdge(srcOrEdge, dest, weight, value);
|
|
2103
2733
|
return this._addEdge(newEdge);
|
|
2104
2734
|
} else {
|
|
2105
|
-
|
|
2735
|
+
raise(TypeError, ERR.invalidArgument("dest must be a Vertex or vertex key when srcOrEdge is an Edge.", "Graph"));
|
|
2106
2736
|
}
|
|
2107
2737
|
}
|
|
2108
2738
|
}
|
|
@@ -2969,6 +3599,30 @@ var undirectedGraphTyped = (() => {
|
|
|
2969
3599
|
|
|
2970
3600
|
|
|
2971
3601
|
|
|
3602
|
+
|
|
3603
|
+
|
|
3604
|
+
|
|
3605
|
+
|
|
3606
|
+
|
|
3607
|
+
|
|
3608
|
+
|
|
3609
|
+
|
|
3610
|
+
|
|
3611
|
+
|
|
3612
|
+
|
|
3613
|
+
|
|
3614
|
+
|
|
3615
|
+
|
|
3616
|
+
|
|
3617
|
+
|
|
3618
|
+
|
|
3619
|
+
|
|
3620
|
+
|
|
3621
|
+
|
|
3622
|
+
|
|
3623
|
+
|
|
3624
|
+
|
|
3625
|
+
|
|
2972
3626
|
* @example
|
|
2973
3627
|
* // Get edge between vertices
|
|
2974
3628
|
* const g = new UndirectedGraph();
|
|
@@ -3030,6 +3684,30 @@ var undirectedGraphTyped = (() => {
|
|
|
3030
3684
|
|
|
3031
3685
|
|
|
3032
3686
|
|
|
3687
|
+
|
|
3688
|
+
|
|
3689
|
+
|
|
3690
|
+
|
|
3691
|
+
|
|
3692
|
+
|
|
3693
|
+
|
|
3694
|
+
|
|
3695
|
+
|
|
3696
|
+
|
|
3697
|
+
|
|
3698
|
+
|
|
3699
|
+
|
|
3700
|
+
|
|
3701
|
+
|
|
3702
|
+
|
|
3703
|
+
|
|
3704
|
+
|
|
3705
|
+
|
|
3706
|
+
|
|
3707
|
+
|
|
3708
|
+
|
|
3709
|
+
|
|
3710
|
+
|
|
3033
3711
|
* @example
|
|
3034
3712
|
* // UndirectedGraph deleteEdge and vertex operations
|
|
3035
3713
|
* const graph = new UndirectedGraph<string>();
|
|
@@ -3090,6 +3768,30 @@ var undirectedGraphTyped = (() => {
|
|
|
3090
3768
|
|
|
3091
3769
|
|
|
3092
3770
|
|
|
3771
|
+
|
|
3772
|
+
|
|
3773
|
+
|
|
3774
|
+
|
|
3775
|
+
|
|
3776
|
+
|
|
3777
|
+
|
|
3778
|
+
|
|
3779
|
+
|
|
3780
|
+
|
|
3781
|
+
|
|
3782
|
+
|
|
3783
|
+
|
|
3784
|
+
|
|
3785
|
+
|
|
3786
|
+
|
|
3787
|
+
|
|
3788
|
+
|
|
3789
|
+
|
|
3790
|
+
|
|
3791
|
+
|
|
3792
|
+
|
|
3793
|
+
|
|
3794
|
+
|
|
3093
3795
|
* @example
|
|
3094
3796
|
* // Remove vertex and edges
|
|
3095
3797
|
* const g = new UndirectedGraph();
|
|
@@ -3165,6 +3867,30 @@ var undirectedGraphTyped = (() => {
|
|
|
3165
3867
|
|
|
3166
3868
|
|
|
3167
3869
|
|
|
3870
|
+
|
|
3871
|
+
|
|
3872
|
+
|
|
3873
|
+
|
|
3874
|
+
|
|
3875
|
+
|
|
3876
|
+
|
|
3877
|
+
|
|
3878
|
+
|
|
3879
|
+
|
|
3880
|
+
|
|
3881
|
+
|
|
3882
|
+
|
|
3883
|
+
|
|
3884
|
+
|
|
3885
|
+
|
|
3886
|
+
|
|
3887
|
+
|
|
3888
|
+
|
|
3889
|
+
|
|
3890
|
+
|
|
3891
|
+
|
|
3892
|
+
|
|
3893
|
+
|
|
3168
3894
|
* @example
|
|
3169
3895
|
* // Get all edges
|
|
3170
3896
|
* const g = new UndirectedGraph();
|
|
@@ -3195,6 +3921,30 @@ var undirectedGraphTyped = (() => {
|
|
|
3195
3921
|
|
|
3196
3922
|
|
|
3197
3923
|
|
|
3924
|
+
|
|
3925
|
+
|
|
3926
|
+
|
|
3927
|
+
|
|
3928
|
+
|
|
3929
|
+
|
|
3930
|
+
|
|
3931
|
+
|
|
3932
|
+
|
|
3933
|
+
|
|
3934
|
+
|
|
3935
|
+
|
|
3936
|
+
|
|
3937
|
+
|
|
3938
|
+
|
|
3939
|
+
|
|
3940
|
+
|
|
3941
|
+
|
|
3942
|
+
|
|
3943
|
+
|
|
3944
|
+
|
|
3945
|
+
|
|
3946
|
+
|
|
3947
|
+
|
|
3198
3948
|
* @example
|
|
3199
3949
|
* // UndirectedGraph connectivity and neighbors
|
|
3200
3950
|
* const graph = new UndirectedGraph<string>();
|
|
@@ -3295,6 +4045,30 @@ var undirectedGraphTyped = (() => {
|
|
|
3295
4045
|
|
|
3296
4046
|
|
|
3297
4047
|
|
|
4048
|
+
|
|
4049
|
+
|
|
4050
|
+
|
|
4051
|
+
|
|
4052
|
+
|
|
4053
|
+
|
|
4054
|
+
|
|
4055
|
+
|
|
4056
|
+
|
|
4057
|
+
|
|
4058
|
+
|
|
4059
|
+
|
|
4060
|
+
|
|
4061
|
+
|
|
4062
|
+
|
|
4063
|
+
|
|
4064
|
+
|
|
4065
|
+
|
|
4066
|
+
|
|
4067
|
+
|
|
4068
|
+
|
|
4069
|
+
|
|
4070
|
+
|
|
4071
|
+
|
|
3298
4072
|
* @example
|
|
3299
4073
|
* // Find articulation points and bridges
|
|
3300
4074
|
* const g = new UndirectedGraph();
|
|
@@ -3417,6 +4191,30 @@ var undirectedGraphTyped = (() => {
|
|
|
3417
4191
|
|
|
3418
4192
|
|
|
3419
4193
|
|
|
4194
|
+
|
|
4195
|
+
|
|
4196
|
+
|
|
4197
|
+
|
|
4198
|
+
|
|
4199
|
+
|
|
4200
|
+
|
|
4201
|
+
|
|
4202
|
+
|
|
4203
|
+
|
|
4204
|
+
|
|
4205
|
+
|
|
4206
|
+
|
|
4207
|
+
|
|
4208
|
+
|
|
4209
|
+
|
|
4210
|
+
|
|
4211
|
+
|
|
4212
|
+
|
|
4213
|
+
|
|
4214
|
+
|
|
4215
|
+
|
|
4216
|
+
|
|
4217
|
+
|
|
3420
4218
|
* @example
|
|
3421
4219
|
* // Detect cycle
|
|
3422
4220
|
* const g = new UndirectedGraph();
|
|
@@ -3461,6 +4259,30 @@ var undirectedGraphTyped = (() => {
|
|
|
3461
4259
|
|
|
3462
4260
|
|
|
3463
4261
|
|
|
4262
|
+
|
|
4263
|
+
|
|
4264
|
+
|
|
4265
|
+
|
|
4266
|
+
|
|
4267
|
+
|
|
4268
|
+
|
|
4269
|
+
|
|
4270
|
+
|
|
4271
|
+
|
|
4272
|
+
|
|
4273
|
+
|
|
4274
|
+
|
|
4275
|
+
|
|
4276
|
+
|
|
4277
|
+
|
|
4278
|
+
|
|
4279
|
+
|
|
4280
|
+
|
|
4281
|
+
|
|
4282
|
+
|
|
4283
|
+
|
|
4284
|
+
|
|
4285
|
+
|
|
3464
4286
|
* @example
|
|
3465
4287
|
* // Find bridge edges
|
|
3466
4288
|
* const g = new UndirectedGraph();
|
|
@@ -3487,6 +4309,30 @@ var undirectedGraphTyped = (() => {
|
|
|
3487
4309
|
|
|
3488
4310
|
|
|
3489
4311
|
|
|
4312
|
+
|
|
4313
|
+
|
|
4314
|
+
|
|
4315
|
+
|
|
4316
|
+
|
|
4317
|
+
|
|
4318
|
+
|
|
4319
|
+
|
|
4320
|
+
|
|
4321
|
+
|
|
4322
|
+
|
|
4323
|
+
|
|
4324
|
+
|
|
4325
|
+
|
|
4326
|
+
|
|
4327
|
+
|
|
4328
|
+
|
|
4329
|
+
|
|
4330
|
+
|
|
4331
|
+
|
|
4332
|
+
|
|
4333
|
+
|
|
4334
|
+
|
|
4335
|
+
|
|
3490
4336
|
* @example
|
|
3491
4337
|
* // Find articulation points
|
|
3492
4338
|
* const g = new UndirectedGraph();
|