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 +1314 -227
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs-legacy/index.cjs +1297 -210
- package/dist/cjs-legacy/index.cjs.map +1 -1
- package/dist/esm/index.mjs +1314 -228
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm-legacy/index.mjs +1297 -211
- 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/graph-typed.js +1291 -205
- package/dist/umd/graph-typed.js.map +1 -1
- package/dist/umd/graph-typed.min.js +3 -3
- package/dist/umd/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
package/dist/esm/index.mjs
CHANGED
|
@@ -23,6 +23,10 @@ var arrayRemove = /* @__PURE__ */ __name(function(array, predicate) {
|
|
|
23
23
|
}, "arrayRemove");
|
|
24
24
|
|
|
25
25
|
// src/common/error.ts
|
|
26
|
+
function raise(ErrorClass, message) {
|
|
27
|
+
throw new ErrorClass(message);
|
|
28
|
+
}
|
|
29
|
+
__name(raise, "raise");
|
|
26
30
|
var ERR = {
|
|
27
31
|
// Range / index
|
|
28
32
|
indexOutOfRange: /* @__PURE__ */ __name((index, min, max, ctx) => `${ctx ? ctx + ": " : ""}Index ${index} is out of range [${min}, ${max}].`, "indexOutOfRange"),
|
|
@@ -44,7 +48,9 @@ var ERR = {
|
|
|
44
48
|
matrixSingular: /* @__PURE__ */ __name(() => "Matrix: Singular matrix, inverse does not exist.", "matrixSingular"),
|
|
45
49
|
matrixNotSquare: /* @__PURE__ */ __name(() => "Matrix: Must be square for inversion.", "matrixNotSquare"),
|
|
46
50
|
matrixNotRectangular: /* @__PURE__ */ __name(() => "Matrix: Must be rectangular for transposition.", "matrixNotRectangular"),
|
|
47
|
-
matrixRowMismatch: /* @__PURE__ */ __name((expected, got) => `Matrix: Expected row length ${expected}, but got ${got}.`, "matrixRowMismatch")
|
|
51
|
+
matrixRowMismatch: /* @__PURE__ */ __name((expected, got) => `Matrix: Expected row length ${expected}, but got ${got}.`, "matrixRowMismatch"),
|
|
52
|
+
// Order statistic
|
|
53
|
+
orderStatisticNotEnabled: /* @__PURE__ */ __name((method, ctx) => `${ctx ? ctx + ": " : ""}${method}() requires enableOrderStatistic: true.`, "orderStatisticNotEnabled")
|
|
48
54
|
};
|
|
49
55
|
|
|
50
56
|
// src/common/index.ts
|
|
@@ -271,7 +277,7 @@ var IterableElementBase = class {
|
|
|
271
277
|
if (options) {
|
|
272
278
|
const { toElementFn } = options;
|
|
273
279
|
if (typeof toElementFn === "function") this._toElementFn = toElementFn;
|
|
274
|
-
else if (toElementFn)
|
|
280
|
+
else if (toElementFn) raise(TypeError, "toElementFn must be a function type");
|
|
275
281
|
}
|
|
276
282
|
}
|
|
277
283
|
/**
|
|
@@ -434,7 +440,7 @@ var IterableElementBase = class {
|
|
|
434
440
|
acc = initialValue;
|
|
435
441
|
} else {
|
|
436
442
|
const first = iter.next();
|
|
437
|
-
if (first.done)
|
|
443
|
+
if (first.done) raise(TypeError, "Reduce of empty structure with no initial value");
|
|
438
444
|
acc = first.value;
|
|
439
445
|
index = 1;
|
|
440
446
|
}
|
|
@@ -476,6 +482,199 @@ var IterableElementBase = class {
|
|
|
476
482
|
}
|
|
477
483
|
};
|
|
478
484
|
|
|
485
|
+
// src/data-structures/base/linear-base.ts
|
|
486
|
+
var LinearBase = class _LinearBase extends IterableElementBase {
|
|
487
|
+
static {
|
|
488
|
+
__name(this, "LinearBase");
|
|
489
|
+
}
|
|
490
|
+
/**
|
|
491
|
+
* Construct a linear container with runtime options.
|
|
492
|
+
* @param options - `{ maxLen?, ... }` bounds/behavior options.
|
|
493
|
+
* @remarks Time O(1), Space O(1)
|
|
494
|
+
*/
|
|
495
|
+
constructor(options) {
|
|
496
|
+
super(options);
|
|
497
|
+
if (options) {
|
|
498
|
+
const { maxLen } = options;
|
|
499
|
+
if (typeof maxLen === "number" && maxLen > 0 && maxLen % 1 === 0) this._maxLen = maxLen;
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
_maxLen = -1;
|
|
503
|
+
/**
|
|
504
|
+
* Upper bound for length (if positive), or `-1` when unbounded.
|
|
505
|
+
* @returns Maximum allowed length.
|
|
506
|
+
* @remarks Time O(1), Space O(1)
|
|
507
|
+
*/
|
|
508
|
+
get maxLen() {
|
|
509
|
+
return this._maxLen;
|
|
510
|
+
}
|
|
511
|
+
/**
|
|
512
|
+
* First index of a value from the left.
|
|
513
|
+
* @param searchElement - Value to match.
|
|
514
|
+
* @param fromIndex - Start position (supports negative index).
|
|
515
|
+
* @returns Index or `-1` if not found.
|
|
516
|
+
* @remarks Time O(n), Space O(1)
|
|
517
|
+
*/
|
|
518
|
+
indexOf(searchElement, fromIndex = 0) {
|
|
519
|
+
if (this.length === 0) return -1;
|
|
520
|
+
if (fromIndex < 0) fromIndex = this.length + fromIndex;
|
|
521
|
+
if (fromIndex < 0) fromIndex = 0;
|
|
522
|
+
for (let i = fromIndex; i < this.length; i++) {
|
|
523
|
+
const element = this.at(i);
|
|
524
|
+
if (element === searchElement) return i;
|
|
525
|
+
}
|
|
526
|
+
return -1;
|
|
527
|
+
}
|
|
528
|
+
/**
|
|
529
|
+
* Last index of a value from the right.
|
|
530
|
+
* @param searchElement - Value to match.
|
|
531
|
+
* @param fromIndex - Start position (supports negative index).
|
|
532
|
+
* @returns Index or `-1` if not found.
|
|
533
|
+
* @remarks Time O(n), Space O(1)
|
|
534
|
+
*/
|
|
535
|
+
lastIndexOf(searchElement, fromIndex = this.length - 1) {
|
|
536
|
+
if (this.length === 0) return -1;
|
|
537
|
+
if (fromIndex >= this.length) fromIndex = this.length - 1;
|
|
538
|
+
if (fromIndex < 0) fromIndex = this.length + fromIndex;
|
|
539
|
+
for (let i = fromIndex; i >= 0; i--) {
|
|
540
|
+
const element = this.at(i);
|
|
541
|
+
if (element === searchElement) return i;
|
|
542
|
+
}
|
|
543
|
+
return -1;
|
|
544
|
+
}
|
|
545
|
+
/**
|
|
546
|
+
* Find the first index matching a predicate.
|
|
547
|
+
* @param predicate - `(element, index, self) => boolean`.
|
|
548
|
+
* @param thisArg - Optional `this` for callback.
|
|
549
|
+
* @returns Index or `-1`.
|
|
550
|
+
* @remarks Time O(n), Space O(1)
|
|
551
|
+
*/
|
|
552
|
+
findIndex(predicate, thisArg) {
|
|
553
|
+
for (let i = 0; i < this.length; i++) {
|
|
554
|
+
const item = this.at(i);
|
|
555
|
+
if (item !== void 0 && predicate.call(thisArg, item, i, this)) return i;
|
|
556
|
+
}
|
|
557
|
+
return -1;
|
|
558
|
+
}
|
|
559
|
+
/**
|
|
560
|
+
* Concatenate elements and/or containers.
|
|
561
|
+
* @param items - Elements or other containers.
|
|
562
|
+
* @returns New container with combined elements (`this` type).
|
|
563
|
+
* @remarks Time O(sum(length)), Space O(sum(length))
|
|
564
|
+
*/
|
|
565
|
+
concat(...items) {
|
|
566
|
+
const newList = this.clone();
|
|
567
|
+
for (const item of items) {
|
|
568
|
+
if (item instanceof _LinearBase) {
|
|
569
|
+
newList.pushMany(item);
|
|
570
|
+
} else {
|
|
571
|
+
newList.push(item);
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
return newList;
|
|
575
|
+
}
|
|
576
|
+
/**
|
|
577
|
+
* In-place stable order via array sort semantics.
|
|
578
|
+
* @param compareFn - Comparator `(a, b) => number`.
|
|
579
|
+
* @returns This container.
|
|
580
|
+
* @remarks Time O(n log n), Space O(n) (materializes to array temporarily)
|
|
581
|
+
*/
|
|
582
|
+
sort(compareFn) {
|
|
583
|
+
const arr = this.toArray();
|
|
584
|
+
arr.sort(compareFn);
|
|
585
|
+
this.clear();
|
|
586
|
+
for (const item of arr) this.push(item);
|
|
587
|
+
return this;
|
|
588
|
+
}
|
|
589
|
+
/**
|
|
590
|
+
* Remove and/or insert elements at a position (array-compatible).
|
|
591
|
+
* @param start - Start index (supports negative index).
|
|
592
|
+
* @param deleteCount - How many to remove.
|
|
593
|
+
* @param items - Elements to insert.
|
|
594
|
+
* @returns Removed elements as a new list (`this` type).
|
|
595
|
+
* @remarks Time O(n + m), Space O(min(n, m)) where `m = items.length`
|
|
596
|
+
*/
|
|
597
|
+
splice(start, deleteCount = 0, ...items) {
|
|
598
|
+
const removedList = this._createInstance();
|
|
599
|
+
start = start < 0 ? this.length + start : start;
|
|
600
|
+
start = Math.max(0, Math.min(start, this.length));
|
|
601
|
+
deleteCount = Math.max(0, Math.min(deleteCount, this.length - start));
|
|
602
|
+
for (let i = 0; i < deleteCount; i++) {
|
|
603
|
+
const removed = this.deleteAt(start);
|
|
604
|
+
if (removed !== void 0) {
|
|
605
|
+
removedList.push(removed);
|
|
606
|
+
}
|
|
607
|
+
}
|
|
608
|
+
for (let i = 0; i < items.length; i++) {
|
|
609
|
+
this.addAt(start + i, items[i]);
|
|
610
|
+
}
|
|
611
|
+
return removedList;
|
|
612
|
+
}
|
|
613
|
+
/**
|
|
614
|
+
* Join all elements into a string.
|
|
615
|
+
* @param separator - Separator string.
|
|
616
|
+
* @returns Concatenated string.
|
|
617
|
+
* @remarks Time O(n), Space O(n)
|
|
618
|
+
*/
|
|
619
|
+
join(separator = ",") {
|
|
620
|
+
return this.toArray().join(separator);
|
|
621
|
+
}
|
|
622
|
+
/**
|
|
623
|
+
* Snapshot elements into a reversed array.
|
|
624
|
+
* @returns New reversed array.
|
|
625
|
+
* @remarks Time O(n), Space O(n)
|
|
626
|
+
*/
|
|
627
|
+
toReversedArray() {
|
|
628
|
+
const array = [];
|
|
629
|
+
for (let i = this.length - 1; i >= 0; i--) {
|
|
630
|
+
array.push(this.at(i));
|
|
631
|
+
}
|
|
632
|
+
return array;
|
|
633
|
+
}
|
|
634
|
+
reduceRight(callbackfn, initialValue) {
|
|
635
|
+
let accumulator = initialValue ?? 0;
|
|
636
|
+
for (let i = this.length - 1; i >= 0; i--) {
|
|
637
|
+
accumulator = callbackfn(accumulator, this.at(i), i, this);
|
|
638
|
+
}
|
|
639
|
+
return accumulator;
|
|
640
|
+
}
|
|
641
|
+
/**
|
|
642
|
+
* Create a shallow copy of a subrange.
|
|
643
|
+
* @param start - Inclusive start (supports negative index).
|
|
644
|
+
* @param end - Exclusive end (supports negative index).
|
|
645
|
+
* @returns New list with the range (`this` type).
|
|
646
|
+
* @remarks Time O(n), Space O(n)
|
|
647
|
+
*/
|
|
648
|
+
slice(start = 0, end = this.length) {
|
|
649
|
+
start = start < 0 ? this.length + start : start;
|
|
650
|
+
end = end < 0 ? this.length + end : end;
|
|
651
|
+
const newList = this._createInstance();
|
|
652
|
+
for (let i = start; i < end; i++) {
|
|
653
|
+
newList.push(this.at(i));
|
|
654
|
+
}
|
|
655
|
+
return newList;
|
|
656
|
+
}
|
|
657
|
+
/**
|
|
658
|
+
* Fill a range with a value.
|
|
659
|
+
* @param value - Value to set.
|
|
660
|
+
* @param start - Inclusive start.
|
|
661
|
+
* @param end - Exclusive end.
|
|
662
|
+
* @returns This list.
|
|
663
|
+
* @remarks Time O(n), Space O(1)
|
|
664
|
+
*/
|
|
665
|
+
fill(value, start = 0, end = this.length) {
|
|
666
|
+
start = start < 0 ? this.length + start : start;
|
|
667
|
+
end = end < 0 ? this.length + end : end;
|
|
668
|
+
if (start < 0) start = 0;
|
|
669
|
+
if (end > this.length) end = this.length;
|
|
670
|
+
if (start >= end) return this;
|
|
671
|
+
for (let i = start; i < end; i++) {
|
|
672
|
+
this.setAt(i, value);
|
|
673
|
+
}
|
|
674
|
+
return this;
|
|
675
|
+
}
|
|
676
|
+
};
|
|
677
|
+
|
|
479
678
|
// src/data-structures/heap/heap.ts
|
|
480
679
|
var Heap = class _Heap extends IterableElementBase {
|
|
481
680
|
static {
|
|
@@ -521,6 +720,30 @@ var Heap = class _Heap extends IterableElementBase {
|
|
|
521
720
|
|
|
522
721
|
|
|
523
722
|
|
|
723
|
+
|
|
724
|
+
|
|
725
|
+
|
|
726
|
+
|
|
727
|
+
|
|
728
|
+
|
|
729
|
+
|
|
730
|
+
|
|
731
|
+
|
|
732
|
+
|
|
733
|
+
|
|
734
|
+
|
|
735
|
+
|
|
736
|
+
|
|
737
|
+
|
|
738
|
+
|
|
739
|
+
|
|
740
|
+
|
|
741
|
+
|
|
742
|
+
|
|
743
|
+
|
|
744
|
+
|
|
745
|
+
|
|
746
|
+
|
|
524
747
|
* @example
|
|
525
748
|
* // Track heap capacity
|
|
526
749
|
* const heap = new Heap<number>();
|
|
@@ -583,6 +806,30 @@ var Heap = class _Heap extends IterableElementBase {
|
|
|
583
806
|
|
|
584
807
|
|
|
585
808
|
|
|
809
|
+
|
|
810
|
+
|
|
811
|
+
|
|
812
|
+
|
|
813
|
+
|
|
814
|
+
|
|
815
|
+
|
|
816
|
+
|
|
817
|
+
|
|
818
|
+
|
|
819
|
+
|
|
820
|
+
|
|
821
|
+
|
|
822
|
+
|
|
823
|
+
|
|
824
|
+
|
|
825
|
+
|
|
826
|
+
|
|
827
|
+
|
|
828
|
+
|
|
829
|
+
|
|
830
|
+
|
|
831
|
+
|
|
832
|
+
|
|
586
833
|
* @example
|
|
587
834
|
* // basic Heap creation and add operation
|
|
588
835
|
* // Create a min heap (default)
|
|
@@ -616,6 +863,30 @@ var Heap = class _Heap extends IterableElementBase {
|
|
|
616
863
|
|
|
617
864
|
|
|
618
865
|
|
|
866
|
+
|
|
867
|
+
|
|
868
|
+
|
|
869
|
+
|
|
870
|
+
|
|
871
|
+
|
|
872
|
+
|
|
873
|
+
|
|
874
|
+
|
|
875
|
+
|
|
876
|
+
|
|
877
|
+
|
|
878
|
+
|
|
879
|
+
|
|
880
|
+
|
|
881
|
+
|
|
882
|
+
|
|
883
|
+
|
|
884
|
+
|
|
885
|
+
|
|
886
|
+
|
|
887
|
+
|
|
888
|
+
|
|
889
|
+
|
|
619
890
|
* @example
|
|
620
891
|
* // Add multiple elements
|
|
621
892
|
* const heap = new Heap<number>([], { comparator: (a, b) => a - b });
|
|
@@ -651,6 +922,30 @@ var Heap = class _Heap extends IterableElementBase {
|
|
|
651
922
|
|
|
652
923
|
|
|
653
924
|
|
|
925
|
+
|
|
926
|
+
|
|
927
|
+
|
|
928
|
+
|
|
929
|
+
|
|
930
|
+
|
|
931
|
+
|
|
932
|
+
|
|
933
|
+
|
|
934
|
+
|
|
935
|
+
|
|
936
|
+
|
|
937
|
+
|
|
938
|
+
|
|
939
|
+
|
|
940
|
+
|
|
941
|
+
|
|
942
|
+
|
|
943
|
+
|
|
944
|
+
|
|
945
|
+
|
|
946
|
+
|
|
947
|
+
|
|
948
|
+
|
|
654
949
|
* @example
|
|
655
950
|
* // Heap with custom comparator (MaxHeap behavior)
|
|
656
951
|
* interface Task {
|
|
@@ -702,6 +997,30 @@ var Heap = class _Heap extends IterableElementBase {
|
|
|
702
997
|
|
|
703
998
|
|
|
704
999
|
|
|
1000
|
+
|
|
1001
|
+
|
|
1002
|
+
|
|
1003
|
+
|
|
1004
|
+
|
|
1005
|
+
|
|
1006
|
+
|
|
1007
|
+
|
|
1008
|
+
|
|
1009
|
+
|
|
1010
|
+
|
|
1011
|
+
|
|
1012
|
+
|
|
1013
|
+
|
|
1014
|
+
|
|
1015
|
+
|
|
1016
|
+
|
|
1017
|
+
|
|
1018
|
+
|
|
1019
|
+
|
|
1020
|
+
|
|
1021
|
+
|
|
1022
|
+
|
|
1023
|
+
|
|
705
1024
|
* @example
|
|
706
1025
|
* // Heap for event processing with priority
|
|
707
1026
|
* interface Event {
|
|
@@ -778,6 +1097,30 @@ var Heap = class _Heap extends IterableElementBase {
|
|
|
778
1097
|
|
|
779
1098
|
|
|
780
1099
|
|
|
1100
|
+
|
|
1101
|
+
|
|
1102
|
+
|
|
1103
|
+
|
|
1104
|
+
|
|
1105
|
+
|
|
1106
|
+
|
|
1107
|
+
|
|
1108
|
+
|
|
1109
|
+
|
|
1110
|
+
|
|
1111
|
+
|
|
1112
|
+
|
|
1113
|
+
|
|
1114
|
+
|
|
1115
|
+
|
|
1116
|
+
|
|
1117
|
+
|
|
1118
|
+
|
|
1119
|
+
|
|
1120
|
+
|
|
1121
|
+
|
|
1122
|
+
|
|
1123
|
+
|
|
781
1124
|
* @example
|
|
782
1125
|
* // Check if heap is empty
|
|
783
1126
|
* const heap = new Heap<number>([], { comparator: (a, b) => a - b });
|
|
@@ -801,6 +1144,30 @@ var Heap = class _Heap extends IterableElementBase {
|
|
|
801
1144
|
|
|
802
1145
|
|
|
803
1146
|
|
|
1147
|
+
|
|
1148
|
+
|
|
1149
|
+
|
|
1150
|
+
|
|
1151
|
+
|
|
1152
|
+
|
|
1153
|
+
|
|
1154
|
+
|
|
1155
|
+
|
|
1156
|
+
|
|
1157
|
+
|
|
1158
|
+
|
|
1159
|
+
|
|
1160
|
+
|
|
1161
|
+
|
|
1162
|
+
|
|
1163
|
+
|
|
1164
|
+
|
|
1165
|
+
|
|
1166
|
+
|
|
1167
|
+
|
|
1168
|
+
|
|
1169
|
+
|
|
1170
|
+
|
|
804
1171
|
* @example
|
|
805
1172
|
* // Remove all elements
|
|
806
1173
|
* const heap = new Heap<number>([1, 2, 3], { comparator: (a, b) => a - b });
|
|
@@ -827,6 +1194,30 @@ var Heap = class _Heap extends IterableElementBase {
|
|
|
827
1194
|
* @returns True if found.
|
|
828
1195
|
|
|
829
1196
|
|
|
1197
|
+
|
|
1198
|
+
|
|
1199
|
+
|
|
1200
|
+
|
|
1201
|
+
|
|
1202
|
+
|
|
1203
|
+
|
|
1204
|
+
|
|
1205
|
+
|
|
1206
|
+
|
|
1207
|
+
|
|
1208
|
+
|
|
1209
|
+
|
|
1210
|
+
|
|
1211
|
+
|
|
1212
|
+
|
|
1213
|
+
|
|
1214
|
+
|
|
1215
|
+
|
|
1216
|
+
|
|
1217
|
+
|
|
1218
|
+
|
|
1219
|
+
|
|
1220
|
+
|
|
830
1221
|
* @example
|
|
831
1222
|
* // Check element existence
|
|
832
1223
|
* const heap = new Heap<number>([3, 1, 2], { comparator: (a, b) => a - b });
|
|
@@ -850,6 +1241,30 @@ var Heap = class _Heap extends IterableElementBase {
|
|
|
850
1241
|
|
|
851
1242
|
|
|
852
1243
|
|
|
1244
|
+
|
|
1245
|
+
|
|
1246
|
+
|
|
1247
|
+
|
|
1248
|
+
|
|
1249
|
+
|
|
1250
|
+
|
|
1251
|
+
|
|
1252
|
+
|
|
1253
|
+
|
|
1254
|
+
|
|
1255
|
+
|
|
1256
|
+
|
|
1257
|
+
|
|
1258
|
+
|
|
1259
|
+
|
|
1260
|
+
|
|
1261
|
+
|
|
1262
|
+
|
|
1263
|
+
|
|
1264
|
+
|
|
1265
|
+
|
|
1266
|
+
|
|
1267
|
+
|
|
853
1268
|
* @example
|
|
854
1269
|
* // Remove specific element
|
|
855
1270
|
* const heap = new Heap<number>([3, 1, 4, 1, 5], { comparator: (a, b) => a - b });
|
|
@@ -919,6 +1334,30 @@ var Heap = class _Heap extends IterableElementBase {
|
|
|
919
1334
|
* @returns Array of visited elements.
|
|
920
1335
|
|
|
921
1336
|
|
|
1337
|
+
|
|
1338
|
+
|
|
1339
|
+
|
|
1340
|
+
|
|
1341
|
+
|
|
1342
|
+
|
|
1343
|
+
|
|
1344
|
+
|
|
1345
|
+
|
|
1346
|
+
|
|
1347
|
+
|
|
1348
|
+
|
|
1349
|
+
|
|
1350
|
+
|
|
1351
|
+
|
|
1352
|
+
|
|
1353
|
+
|
|
1354
|
+
|
|
1355
|
+
|
|
1356
|
+
|
|
1357
|
+
|
|
1358
|
+
|
|
1359
|
+
|
|
1360
|
+
|
|
922
1361
|
* @example
|
|
923
1362
|
* // Depth-first traversal
|
|
924
1363
|
* const heap = new Heap<number>([3, 1, 2], { comparator: (a, b) => a - b });
|
|
@@ -975,26 +1414,74 @@ var Heap = class _Heap extends IterableElementBase {
|
|
|
975
1414
|
|
|
976
1415
|
|
|
977
1416
|
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
1417
|
+
|
|
1418
|
+
|
|
1419
|
+
|
|
1420
|
+
|
|
1421
|
+
|
|
1422
|
+
|
|
1423
|
+
|
|
1424
|
+
|
|
1425
|
+
|
|
1426
|
+
|
|
1427
|
+
|
|
1428
|
+
|
|
1429
|
+
|
|
1430
|
+
|
|
1431
|
+
|
|
1432
|
+
|
|
1433
|
+
|
|
1434
|
+
|
|
1435
|
+
|
|
1436
|
+
|
|
1437
|
+
|
|
1438
|
+
|
|
1439
|
+
|
|
1440
|
+
|
|
1441
|
+
* @example
|
|
1442
|
+
* // Sort elements using heap
|
|
1443
|
+
* const heap = new Heap<number>([5, 1, 3, 2, 4]);
|
|
1444
|
+
* const sorted = heap.sort();
|
|
1445
|
+
* console.log(sorted); // [1, 2, 3, 4, 5];
|
|
1446
|
+
*/
|
|
1447
|
+
sort() {
|
|
1448
|
+
const visited = [];
|
|
1449
|
+
const cloned = this._createInstance();
|
|
1450
|
+
for (const x of this.elements) cloned.add(x);
|
|
1451
|
+
while (!cloned.isEmpty()) {
|
|
1452
|
+
const top = cloned.poll();
|
|
1453
|
+
if (top !== void 0) visited.push(top);
|
|
1454
|
+
}
|
|
1455
|
+
return visited;
|
|
1456
|
+
}
|
|
1457
|
+
/**
|
|
1458
|
+
* Deep clone this heap.
|
|
1459
|
+
* @remarks Time O(N), Space O(N)
|
|
1460
|
+
* @returns A new heap with the same elements.
|
|
1461
|
+
|
|
1462
|
+
|
|
1463
|
+
|
|
1464
|
+
|
|
1465
|
+
|
|
1466
|
+
|
|
1467
|
+
|
|
1468
|
+
|
|
1469
|
+
|
|
1470
|
+
|
|
1471
|
+
|
|
1472
|
+
|
|
1473
|
+
|
|
1474
|
+
|
|
1475
|
+
|
|
1476
|
+
|
|
1477
|
+
|
|
1478
|
+
|
|
1479
|
+
|
|
1480
|
+
|
|
1481
|
+
|
|
1482
|
+
|
|
1483
|
+
|
|
1484
|
+
|
|
998
1485
|
|
|
999
1486
|
|
|
1000
1487
|
|
|
@@ -1032,6 +1519,30 @@ var Heap = class _Heap extends IterableElementBase {
|
|
|
1032
1519
|
|
|
1033
1520
|
|
|
1034
1521
|
|
|
1522
|
+
|
|
1523
|
+
|
|
1524
|
+
|
|
1525
|
+
|
|
1526
|
+
|
|
1527
|
+
|
|
1528
|
+
|
|
1529
|
+
|
|
1530
|
+
|
|
1531
|
+
|
|
1532
|
+
|
|
1533
|
+
|
|
1534
|
+
|
|
1535
|
+
|
|
1536
|
+
|
|
1537
|
+
|
|
1538
|
+
|
|
1539
|
+
|
|
1540
|
+
|
|
1541
|
+
|
|
1542
|
+
|
|
1543
|
+
|
|
1544
|
+
|
|
1545
|
+
|
|
1035
1546
|
* @example
|
|
1036
1547
|
* // Filter elements
|
|
1037
1548
|
* const heap = new Heap<number>([1, 2, 3, 4, 5], { comparator: (a, b) => a - b });
|
|
@@ -1067,6 +1578,30 @@ var Heap = class _Heap extends IterableElementBase {
|
|
|
1067
1578
|
|
|
1068
1579
|
|
|
1069
1580
|
|
|
1581
|
+
|
|
1582
|
+
|
|
1583
|
+
|
|
1584
|
+
|
|
1585
|
+
|
|
1586
|
+
|
|
1587
|
+
|
|
1588
|
+
|
|
1589
|
+
|
|
1590
|
+
|
|
1591
|
+
|
|
1592
|
+
|
|
1593
|
+
|
|
1594
|
+
|
|
1595
|
+
|
|
1596
|
+
|
|
1597
|
+
|
|
1598
|
+
|
|
1599
|
+
|
|
1600
|
+
|
|
1601
|
+
|
|
1602
|
+
|
|
1603
|
+
|
|
1604
|
+
|
|
1070
1605
|
* @example
|
|
1071
1606
|
* // Transform elements
|
|
1072
1607
|
* const heap = new Heap<number>([1, 2, 3], { comparator: (a, b) => a - b });
|
|
@@ -1075,7 +1610,7 @@ var Heap = class _Heap extends IterableElementBase {
|
|
|
1075
1610
|
*/
|
|
1076
1611
|
map(callback, options, thisArg) {
|
|
1077
1612
|
const { comparator, toElementFn, ...rest } = options ?? {};
|
|
1078
|
-
if (!comparator)
|
|
1613
|
+
if (!comparator) raise(TypeError, ERR.comparatorRequired("Heap.map"));
|
|
1079
1614
|
const out = this._createLike([], { ...rest, comparator, toElementFn });
|
|
1080
1615
|
let i = 0;
|
|
1081
1616
|
for (const x of this) {
|
|
@@ -1102,7 +1637,7 @@ var Heap = class _Heap extends IterableElementBase {
|
|
|
1102
1637
|
}
|
|
1103
1638
|
_DEFAULT_COMPARATOR = /* @__PURE__ */ __name((a, b) => {
|
|
1104
1639
|
if (typeof a === "object" || typeof b === "object") {
|
|
1105
|
-
|
|
1640
|
+
raise(TypeError, ERR.comparatorRequired("Heap"));
|
|
1106
1641
|
}
|
|
1107
1642
|
if (a > b) return 1;
|
|
1108
1643
|
if (a < b) return -1;
|
|
@@ -1173,208 +1708,15 @@ var Heap = class _Heap extends IterableElementBase {
|
|
|
1173
1708
|
return new Ctor(elements, options);
|
|
1174
1709
|
}
|
|
1175
1710
|
/**
|
|
1176
|
-
* (Protected) Spawn an empty like-kind heap instance.
|
|
1177
|
-
* @remarks Time O(1), Space O(1)
|
|
1178
|
-
* @template EM
|
|
1179
|
-
* @template RM
|
|
1180
|
-
* @param [options] - Options forwarded to the constructor.
|
|
1181
|
-
* @returns An empty like-kind heap instance.
|
|
1182
|
-
*/
|
|
1183
|
-
_spawnLike(options) {
|
|
1184
|
-
return this._createLike([], options);
|
|
1185
|
-
}
|
|
1186
|
-
};
|
|
1187
|
-
|
|
1188
|
-
// src/data-structures/base/linear-base.ts
|
|
1189
|
-
var LinearBase = class _LinearBase extends IterableElementBase {
|
|
1190
|
-
static {
|
|
1191
|
-
__name(this, "LinearBase");
|
|
1192
|
-
}
|
|
1193
|
-
/**
|
|
1194
|
-
* Construct a linear container with runtime options.
|
|
1195
|
-
* @param options - `{ maxLen?, ... }` bounds/behavior options.
|
|
1196
|
-
* @remarks Time O(1), Space O(1)
|
|
1197
|
-
*/
|
|
1198
|
-
constructor(options) {
|
|
1199
|
-
super(options);
|
|
1200
|
-
if (options) {
|
|
1201
|
-
const { maxLen } = options;
|
|
1202
|
-
if (typeof maxLen === "number" && maxLen > 0 && maxLen % 1 === 0) this._maxLen = maxLen;
|
|
1203
|
-
}
|
|
1204
|
-
}
|
|
1205
|
-
_maxLen = -1;
|
|
1206
|
-
/**
|
|
1207
|
-
* Upper bound for length (if positive), or `-1` when unbounded.
|
|
1208
|
-
* @returns Maximum allowed length.
|
|
1209
|
-
* @remarks Time O(1), Space O(1)
|
|
1210
|
-
*/
|
|
1211
|
-
get maxLen() {
|
|
1212
|
-
return this._maxLen;
|
|
1213
|
-
}
|
|
1214
|
-
/**
|
|
1215
|
-
* First index of a value from the left.
|
|
1216
|
-
* @param searchElement - Value to match.
|
|
1217
|
-
* @param fromIndex - Start position (supports negative index).
|
|
1218
|
-
* @returns Index or `-1` if not found.
|
|
1219
|
-
* @remarks Time O(n), Space O(1)
|
|
1220
|
-
*/
|
|
1221
|
-
indexOf(searchElement, fromIndex = 0) {
|
|
1222
|
-
if (this.length === 0) return -1;
|
|
1223
|
-
if (fromIndex < 0) fromIndex = this.length + fromIndex;
|
|
1224
|
-
if (fromIndex < 0) fromIndex = 0;
|
|
1225
|
-
for (let i = fromIndex; i < this.length; i++) {
|
|
1226
|
-
const element = this.at(i);
|
|
1227
|
-
if (element === searchElement) return i;
|
|
1228
|
-
}
|
|
1229
|
-
return -1;
|
|
1230
|
-
}
|
|
1231
|
-
/**
|
|
1232
|
-
* Last index of a value from the right.
|
|
1233
|
-
* @param searchElement - Value to match.
|
|
1234
|
-
* @param fromIndex - Start position (supports negative index).
|
|
1235
|
-
* @returns Index or `-1` if not found.
|
|
1236
|
-
* @remarks Time O(n), Space O(1)
|
|
1237
|
-
*/
|
|
1238
|
-
lastIndexOf(searchElement, fromIndex = this.length - 1) {
|
|
1239
|
-
if (this.length === 0) return -1;
|
|
1240
|
-
if (fromIndex >= this.length) fromIndex = this.length - 1;
|
|
1241
|
-
if (fromIndex < 0) fromIndex = this.length + fromIndex;
|
|
1242
|
-
for (let i = fromIndex; i >= 0; i--) {
|
|
1243
|
-
const element = this.at(i);
|
|
1244
|
-
if (element === searchElement) return i;
|
|
1245
|
-
}
|
|
1246
|
-
return -1;
|
|
1247
|
-
}
|
|
1248
|
-
/**
|
|
1249
|
-
* Find the first index matching a predicate.
|
|
1250
|
-
* @param predicate - `(element, index, self) => boolean`.
|
|
1251
|
-
* @param thisArg - Optional `this` for callback.
|
|
1252
|
-
* @returns Index or `-1`.
|
|
1253
|
-
* @remarks Time O(n), Space O(1)
|
|
1254
|
-
*/
|
|
1255
|
-
findIndex(predicate, thisArg) {
|
|
1256
|
-
for (let i = 0; i < this.length; i++) {
|
|
1257
|
-
const item = this.at(i);
|
|
1258
|
-
if (item !== void 0 && predicate.call(thisArg, item, i, this)) return i;
|
|
1259
|
-
}
|
|
1260
|
-
return -1;
|
|
1261
|
-
}
|
|
1262
|
-
/**
|
|
1263
|
-
* Concatenate elements and/or containers.
|
|
1264
|
-
* @param items - Elements or other containers.
|
|
1265
|
-
* @returns New container with combined elements (`this` type).
|
|
1266
|
-
* @remarks Time O(sum(length)), Space O(sum(length))
|
|
1267
|
-
*/
|
|
1268
|
-
concat(...items) {
|
|
1269
|
-
const newList = this.clone();
|
|
1270
|
-
for (const item of items) {
|
|
1271
|
-
if (item instanceof _LinearBase) {
|
|
1272
|
-
newList.pushMany(item);
|
|
1273
|
-
} else {
|
|
1274
|
-
newList.push(item);
|
|
1275
|
-
}
|
|
1276
|
-
}
|
|
1277
|
-
return newList;
|
|
1278
|
-
}
|
|
1279
|
-
/**
|
|
1280
|
-
* In-place stable order via array sort semantics.
|
|
1281
|
-
* @param compareFn - Comparator `(a, b) => number`.
|
|
1282
|
-
* @returns This container.
|
|
1283
|
-
* @remarks Time O(n log n), Space O(n) (materializes to array temporarily)
|
|
1284
|
-
*/
|
|
1285
|
-
sort(compareFn) {
|
|
1286
|
-
const arr = this.toArray();
|
|
1287
|
-
arr.sort(compareFn);
|
|
1288
|
-
this.clear();
|
|
1289
|
-
for (const item of arr) this.push(item);
|
|
1290
|
-
return this;
|
|
1291
|
-
}
|
|
1292
|
-
/**
|
|
1293
|
-
* Remove and/or insert elements at a position (array-compatible).
|
|
1294
|
-
* @param start - Start index (supports negative index).
|
|
1295
|
-
* @param deleteCount - How many to remove.
|
|
1296
|
-
* @param items - Elements to insert.
|
|
1297
|
-
* @returns Removed elements as a new list (`this` type).
|
|
1298
|
-
* @remarks Time O(n + m), Space O(min(n, m)) where `m = items.length`
|
|
1299
|
-
*/
|
|
1300
|
-
splice(start, deleteCount = 0, ...items) {
|
|
1301
|
-
const removedList = this._createInstance();
|
|
1302
|
-
start = start < 0 ? this.length + start : start;
|
|
1303
|
-
start = Math.max(0, Math.min(start, this.length));
|
|
1304
|
-
deleteCount = Math.max(0, Math.min(deleteCount, this.length - start));
|
|
1305
|
-
for (let i = 0; i < deleteCount; i++) {
|
|
1306
|
-
const removed = this.deleteAt(start);
|
|
1307
|
-
if (removed !== void 0) {
|
|
1308
|
-
removedList.push(removed);
|
|
1309
|
-
}
|
|
1310
|
-
}
|
|
1311
|
-
for (let i = 0; i < items.length; i++) {
|
|
1312
|
-
this.addAt(start + i, items[i]);
|
|
1313
|
-
}
|
|
1314
|
-
return removedList;
|
|
1315
|
-
}
|
|
1316
|
-
/**
|
|
1317
|
-
* Join all elements into a string.
|
|
1318
|
-
* @param separator - Separator string.
|
|
1319
|
-
* @returns Concatenated string.
|
|
1320
|
-
* @remarks Time O(n), Space O(n)
|
|
1321
|
-
*/
|
|
1322
|
-
join(separator = ",") {
|
|
1323
|
-
return this.toArray().join(separator);
|
|
1324
|
-
}
|
|
1325
|
-
/**
|
|
1326
|
-
* Snapshot elements into a reversed array.
|
|
1327
|
-
* @returns New reversed array.
|
|
1328
|
-
* @remarks Time O(n), Space O(n)
|
|
1329
|
-
*/
|
|
1330
|
-
toReversedArray() {
|
|
1331
|
-
const array = [];
|
|
1332
|
-
for (let i = this.length - 1; i >= 0; i--) {
|
|
1333
|
-
array.push(this.at(i));
|
|
1334
|
-
}
|
|
1335
|
-
return array;
|
|
1336
|
-
}
|
|
1337
|
-
reduceRight(callbackfn, initialValue) {
|
|
1338
|
-
let accumulator = initialValue ?? 0;
|
|
1339
|
-
for (let i = this.length - 1; i >= 0; i--) {
|
|
1340
|
-
accumulator = callbackfn(accumulator, this.at(i), i, this);
|
|
1341
|
-
}
|
|
1342
|
-
return accumulator;
|
|
1343
|
-
}
|
|
1344
|
-
/**
|
|
1345
|
-
* Create a shallow copy of a subrange.
|
|
1346
|
-
* @param start - Inclusive start (supports negative index).
|
|
1347
|
-
* @param end - Exclusive end (supports negative index).
|
|
1348
|
-
* @returns New list with the range (`this` type).
|
|
1349
|
-
* @remarks Time O(n), Space O(n)
|
|
1350
|
-
*/
|
|
1351
|
-
slice(start = 0, end = this.length) {
|
|
1352
|
-
start = start < 0 ? this.length + start : start;
|
|
1353
|
-
end = end < 0 ? this.length + end : end;
|
|
1354
|
-
const newList = this._createInstance();
|
|
1355
|
-
for (let i = start; i < end; i++) {
|
|
1356
|
-
newList.push(this.at(i));
|
|
1357
|
-
}
|
|
1358
|
-
return newList;
|
|
1359
|
-
}
|
|
1360
|
-
/**
|
|
1361
|
-
* Fill a range with a value.
|
|
1362
|
-
* @param value - Value to set.
|
|
1363
|
-
* @param start - Inclusive start.
|
|
1364
|
-
* @param end - Exclusive end.
|
|
1365
|
-
* @returns This list.
|
|
1366
|
-
* @remarks Time O(n), Space O(1)
|
|
1711
|
+
* (Protected) Spawn an empty like-kind heap instance.
|
|
1712
|
+
* @remarks Time O(1), Space O(1)
|
|
1713
|
+
* @template EM
|
|
1714
|
+
* @template RM
|
|
1715
|
+
* @param [options] - Options forwarded to the constructor.
|
|
1716
|
+
* @returns An empty like-kind heap instance.
|
|
1367
1717
|
*/
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
end = end < 0 ? this.length + end : end;
|
|
1371
|
-
if (start < 0) start = 0;
|
|
1372
|
-
if (end > this.length) end = this.length;
|
|
1373
|
-
if (start >= end) return this;
|
|
1374
|
-
for (let i = start; i < end; i++) {
|
|
1375
|
-
this.setAt(i, value);
|
|
1376
|
-
}
|
|
1377
|
-
return this;
|
|
1718
|
+
_spawnLike(options) {
|
|
1719
|
+
return this._createLike([], options);
|
|
1378
1720
|
}
|
|
1379
1721
|
};
|
|
1380
1722
|
|
|
@@ -1449,6 +1791,30 @@ var Queue = class _Queue extends LinearBase {
|
|
|
1449
1791
|
|
|
1450
1792
|
|
|
1451
1793
|
|
|
1794
|
+
|
|
1795
|
+
|
|
1796
|
+
|
|
1797
|
+
|
|
1798
|
+
|
|
1799
|
+
|
|
1800
|
+
|
|
1801
|
+
|
|
1802
|
+
|
|
1803
|
+
|
|
1804
|
+
|
|
1805
|
+
|
|
1806
|
+
|
|
1807
|
+
|
|
1808
|
+
|
|
1809
|
+
|
|
1810
|
+
|
|
1811
|
+
|
|
1812
|
+
|
|
1813
|
+
|
|
1814
|
+
|
|
1815
|
+
|
|
1816
|
+
|
|
1817
|
+
|
|
1452
1818
|
* @example
|
|
1453
1819
|
* // Track queue length
|
|
1454
1820
|
* const q = new Queue<number>();
|
|
@@ -1475,6 +1841,30 @@ var Queue = class _Queue extends LinearBase {
|
|
|
1475
1841
|
|
|
1476
1842
|
|
|
1477
1843
|
|
|
1844
|
+
|
|
1845
|
+
|
|
1846
|
+
|
|
1847
|
+
|
|
1848
|
+
|
|
1849
|
+
|
|
1850
|
+
|
|
1851
|
+
|
|
1852
|
+
|
|
1853
|
+
|
|
1854
|
+
|
|
1855
|
+
|
|
1856
|
+
|
|
1857
|
+
|
|
1858
|
+
|
|
1859
|
+
|
|
1860
|
+
|
|
1861
|
+
|
|
1862
|
+
|
|
1863
|
+
|
|
1864
|
+
|
|
1865
|
+
|
|
1866
|
+
|
|
1867
|
+
|
|
1478
1868
|
* @example
|
|
1479
1869
|
* // View the front element
|
|
1480
1870
|
* const q = new Queue<string>(['first', 'second', 'third']);
|
|
@@ -1517,6 +1907,30 @@ var Queue = class _Queue extends LinearBase {
|
|
|
1517
1907
|
|
|
1518
1908
|
|
|
1519
1909
|
|
|
1910
|
+
|
|
1911
|
+
|
|
1912
|
+
|
|
1913
|
+
|
|
1914
|
+
|
|
1915
|
+
|
|
1916
|
+
|
|
1917
|
+
|
|
1918
|
+
|
|
1919
|
+
|
|
1920
|
+
|
|
1921
|
+
|
|
1922
|
+
|
|
1923
|
+
|
|
1924
|
+
|
|
1925
|
+
|
|
1926
|
+
|
|
1927
|
+
|
|
1928
|
+
|
|
1929
|
+
|
|
1930
|
+
|
|
1931
|
+
|
|
1932
|
+
|
|
1933
|
+
|
|
1520
1934
|
* @example
|
|
1521
1935
|
* // Queue for...of iteration and isEmpty check
|
|
1522
1936
|
* const queue = new Queue<string>(['A', 'B', 'C', 'D']);
|
|
@@ -1555,6 +1969,30 @@ var Queue = class _Queue extends LinearBase {
|
|
|
1555
1969
|
|
|
1556
1970
|
|
|
1557
1971
|
|
|
1972
|
+
|
|
1973
|
+
|
|
1974
|
+
|
|
1975
|
+
|
|
1976
|
+
|
|
1977
|
+
|
|
1978
|
+
|
|
1979
|
+
|
|
1980
|
+
|
|
1981
|
+
|
|
1982
|
+
|
|
1983
|
+
|
|
1984
|
+
|
|
1985
|
+
|
|
1986
|
+
|
|
1987
|
+
|
|
1988
|
+
|
|
1989
|
+
|
|
1990
|
+
|
|
1991
|
+
|
|
1992
|
+
|
|
1993
|
+
|
|
1994
|
+
|
|
1995
|
+
|
|
1558
1996
|
* @example
|
|
1559
1997
|
* // basic Queue creation and push operation
|
|
1560
1998
|
* // Create a simple Queue with initial values
|
|
@@ -1600,6 +2038,30 @@ var Queue = class _Queue extends LinearBase {
|
|
|
1600
2038
|
|
|
1601
2039
|
|
|
1602
2040
|
|
|
2041
|
+
|
|
2042
|
+
|
|
2043
|
+
|
|
2044
|
+
|
|
2045
|
+
|
|
2046
|
+
|
|
2047
|
+
|
|
2048
|
+
|
|
2049
|
+
|
|
2050
|
+
|
|
2051
|
+
|
|
2052
|
+
|
|
2053
|
+
|
|
2054
|
+
|
|
2055
|
+
|
|
2056
|
+
|
|
2057
|
+
|
|
2058
|
+
|
|
2059
|
+
|
|
2060
|
+
|
|
2061
|
+
|
|
2062
|
+
|
|
2063
|
+
|
|
2064
|
+
|
|
1603
2065
|
* @example
|
|
1604
2066
|
* // Queue shift and peek operations
|
|
1605
2067
|
* const queue = new Queue<number>([10, 20, 30, 40]);
|
|
@@ -1635,6 +2097,30 @@ var Queue = class _Queue extends LinearBase {
|
|
|
1635
2097
|
|
|
1636
2098
|
|
|
1637
2099
|
|
|
2100
|
+
|
|
2101
|
+
|
|
2102
|
+
|
|
2103
|
+
|
|
2104
|
+
|
|
2105
|
+
|
|
2106
|
+
|
|
2107
|
+
|
|
2108
|
+
|
|
2109
|
+
|
|
2110
|
+
|
|
2111
|
+
|
|
2112
|
+
|
|
2113
|
+
|
|
2114
|
+
|
|
2115
|
+
|
|
2116
|
+
|
|
2117
|
+
|
|
2118
|
+
|
|
2119
|
+
|
|
2120
|
+
|
|
2121
|
+
|
|
2122
|
+
|
|
2123
|
+
|
|
1638
2124
|
* @example
|
|
1639
2125
|
* // Remove specific element
|
|
1640
2126
|
* const q = new Queue<number>([1, 2, 3, 2]);
|
|
@@ -1663,6 +2149,30 @@ var Queue = class _Queue extends LinearBase {
|
|
|
1663
2149
|
|
|
1664
2150
|
|
|
1665
2151
|
|
|
2152
|
+
|
|
2153
|
+
|
|
2154
|
+
|
|
2155
|
+
|
|
2156
|
+
|
|
2157
|
+
|
|
2158
|
+
|
|
2159
|
+
|
|
2160
|
+
|
|
2161
|
+
|
|
2162
|
+
|
|
2163
|
+
|
|
2164
|
+
|
|
2165
|
+
|
|
2166
|
+
|
|
2167
|
+
|
|
2168
|
+
|
|
2169
|
+
|
|
2170
|
+
|
|
2171
|
+
|
|
2172
|
+
|
|
2173
|
+
|
|
2174
|
+
|
|
2175
|
+
|
|
1666
2176
|
* @example
|
|
1667
2177
|
* // Access element by index
|
|
1668
2178
|
* const q = new Queue<string>(['a', 'b', 'c']);
|
|
@@ -1732,6 +2242,30 @@ var Queue = class _Queue extends LinearBase {
|
|
|
1732
2242
|
|
|
1733
2243
|
|
|
1734
2244
|
|
|
2245
|
+
|
|
2246
|
+
|
|
2247
|
+
|
|
2248
|
+
|
|
2249
|
+
|
|
2250
|
+
|
|
2251
|
+
|
|
2252
|
+
|
|
2253
|
+
|
|
2254
|
+
|
|
2255
|
+
|
|
2256
|
+
|
|
2257
|
+
|
|
2258
|
+
|
|
2259
|
+
|
|
2260
|
+
|
|
2261
|
+
|
|
2262
|
+
|
|
2263
|
+
|
|
2264
|
+
|
|
2265
|
+
|
|
2266
|
+
|
|
2267
|
+
|
|
2268
|
+
|
|
1735
2269
|
* @example
|
|
1736
2270
|
* // Remove all elements
|
|
1737
2271
|
* const q = new Queue<number>([1, 2, 3]);
|
|
@@ -1754,6 +2288,30 @@ var Queue = class _Queue extends LinearBase {
|
|
|
1754
2288
|
|
|
1755
2289
|
|
|
1756
2290
|
|
|
2291
|
+
|
|
2292
|
+
|
|
2293
|
+
|
|
2294
|
+
|
|
2295
|
+
|
|
2296
|
+
|
|
2297
|
+
|
|
2298
|
+
|
|
2299
|
+
|
|
2300
|
+
|
|
2301
|
+
|
|
2302
|
+
|
|
2303
|
+
|
|
2304
|
+
|
|
2305
|
+
|
|
2306
|
+
|
|
2307
|
+
|
|
2308
|
+
|
|
2309
|
+
|
|
2310
|
+
|
|
2311
|
+
|
|
2312
|
+
|
|
2313
|
+
|
|
2314
|
+
|
|
1757
2315
|
* @example
|
|
1758
2316
|
* // Reclaim unused memory
|
|
1759
2317
|
* const q = new Queue<number>([1, 2, 3, 4, 5]);
|
|
@@ -1799,6 +2357,30 @@ var Queue = class _Queue extends LinearBase {
|
|
|
1799
2357
|
|
|
1800
2358
|
|
|
1801
2359
|
|
|
2360
|
+
|
|
2361
|
+
|
|
2362
|
+
|
|
2363
|
+
|
|
2364
|
+
|
|
2365
|
+
|
|
2366
|
+
|
|
2367
|
+
|
|
2368
|
+
|
|
2369
|
+
|
|
2370
|
+
|
|
2371
|
+
|
|
2372
|
+
|
|
2373
|
+
|
|
2374
|
+
|
|
2375
|
+
|
|
2376
|
+
|
|
2377
|
+
|
|
2378
|
+
|
|
2379
|
+
|
|
2380
|
+
|
|
2381
|
+
|
|
2382
|
+
|
|
2383
|
+
|
|
1802
2384
|
* @example
|
|
1803
2385
|
* // Create independent copy
|
|
1804
2386
|
* const q = new Queue<number>([1, 2, 3]);
|
|
@@ -1828,6 +2410,30 @@ var Queue = class _Queue extends LinearBase {
|
|
|
1828
2410
|
|
|
1829
2411
|
|
|
1830
2412
|
|
|
2413
|
+
|
|
2414
|
+
|
|
2415
|
+
|
|
2416
|
+
|
|
2417
|
+
|
|
2418
|
+
|
|
2419
|
+
|
|
2420
|
+
|
|
2421
|
+
|
|
2422
|
+
|
|
2423
|
+
|
|
2424
|
+
|
|
2425
|
+
|
|
2426
|
+
|
|
2427
|
+
|
|
2428
|
+
|
|
2429
|
+
|
|
2430
|
+
|
|
2431
|
+
|
|
2432
|
+
|
|
2433
|
+
|
|
2434
|
+
|
|
2435
|
+
|
|
2436
|
+
|
|
1831
2437
|
* @example
|
|
1832
2438
|
* // Filter elements
|
|
1833
2439
|
* const q = new Queue<number>([1, 2, 3, 4, 5]);
|
|
@@ -1861,6 +2467,30 @@ var Queue = class _Queue extends LinearBase {
|
|
|
1861
2467
|
|
|
1862
2468
|
|
|
1863
2469
|
|
|
2470
|
+
|
|
2471
|
+
|
|
2472
|
+
|
|
2473
|
+
|
|
2474
|
+
|
|
2475
|
+
|
|
2476
|
+
|
|
2477
|
+
|
|
2478
|
+
|
|
2479
|
+
|
|
2480
|
+
|
|
2481
|
+
|
|
2482
|
+
|
|
2483
|
+
|
|
2484
|
+
|
|
2485
|
+
|
|
2486
|
+
|
|
2487
|
+
|
|
2488
|
+
|
|
2489
|
+
|
|
2490
|
+
|
|
2491
|
+
|
|
2492
|
+
|
|
2493
|
+
|
|
1864
2494
|
* @example
|
|
1865
2495
|
* // Transform elements
|
|
1866
2496
|
* const q = new Queue<number>([1, 2, 3]);
|
|
@@ -2096,7 +2726,7 @@ var AbstractGraph = class extends IterableEntryBase {
|
|
|
2096
2726
|
const newEdge = this.createEdge(srcOrEdge, dest, weight, value);
|
|
2097
2727
|
return this._addEdge(newEdge);
|
|
2098
2728
|
} else {
|
|
2099
|
-
|
|
2729
|
+
raise(TypeError, ERR.invalidArgument("dest must be a Vertex or vertex key when srcOrEdge is an Edge.", "Graph"));
|
|
2100
2730
|
}
|
|
2101
2731
|
}
|
|
2102
2732
|
}
|
|
@@ -2976,6 +3606,30 @@ var DirectedGraph = class _DirectedGraph extends AbstractGraph {
|
|
|
2976
3606
|
|
|
2977
3607
|
|
|
2978
3608
|
|
|
3609
|
+
|
|
3610
|
+
|
|
3611
|
+
|
|
3612
|
+
|
|
3613
|
+
|
|
3614
|
+
|
|
3615
|
+
|
|
3616
|
+
|
|
3617
|
+
|
|
3618
|
+
|
|
3619
|
+
|
|
3620
|
+
|
|
3621
|
+
|
|
3622
|
+
|
|
3623
|
+
|
|
3624
|
+
|
|
3625
|
+
|
|
3626
|
+
|
|
3627
|
+
|
|
3628
|
+
|
|
3629
|
+
|
|
3630
|
+
|
|
3631
|
+
|
|
3632
|
+
|
|
2979
3633
|
* @example
|
|
2980
3634
|
* // Get edge between vertices
|
|
2981
3635
|
* const g = new DirectedGraph();
|
|
@@ -3040,6 +3694,30 @@ var DirectedGraph = class _DirectedGraph extends AbstractGraph {
|
|
|
3040
3694
|
|
|
3041
3695
|
|
|
3042
3696
|
|
|
3697
|
+
|
|
3698
|
+
|
|
3699
|
+
|
|
3700
|
+
|
|
3701
|
+
|
|
3702
|
+
|
|
3703
|
+
|
|
3704
|
+
|
|
3705
|
+
|
|
3706
|
+
|
|
3707
|
+
|
|
3708
|
+
|
|
3709
|
+
|
|
3710
|
+
|
|
3711
|
+
|
|
3712
|
+
|
|
3713
|
+
|
|
3714
|
+
|
|
3715
|
+
|
|
3716
|
+
|
|
3717
|
+
|
|
3718
|
+
|
|
3719
|
+
|
|
3720
|
+
|
|
3043
3721
|
* @example
|
|
3044
3722
|
* // DirectedGraph deleteEdge and vertex operations
|
|
3045
3723
|
* const graph = new DirectedGraph<string>();
|
|
@@ -3102,6 +3780,30 @@ var DirectedGraph = class _DirectedGraph extends AbstractGraph {
|
|
|
3102
3780
|
|
|
3103
3781
|
|
|
3104
3782
|
|
|
3783
|
+
|
|
3784
|
+
|
|
3785
|
+
|
|
3786
|
+
|
|
3787
|
+
|
|
3788
|
+
|
|
3789
|
+
|
|
3790
|
+
|
|
3791
|
+
|
|
3792
|
+
|
|
3793
|
+
|
|
3794
|
+
|
|
3795
|
+
|
|
3796
|
+
|
|
3797
|
+
|
|
3798
|
+
|
|
3799
|
+
|
|
3800
|
+
|
|
3801
|
+
|
|
3802
|
+
|
|
3803
|
+
|
|
3804
|
+
|
|
3805
|
+
|
|
3806
|
+
|
|
3105
3807
|
* @example
|
|
3106
3808
|
* // Remove a vertex
|
|
3107
3809
|
* const g = new DirectedGraph();
|
|
@@ -3155,6 +3857,30 @@ var DirectedGraph = class _DirectedGraph extends AbstractGraph {
|
|
|
3155
3857
|
|
|
3156
3858
|
|
|
3157
3859
|
|
|
3860
|
+
|
|
3861
|
+
|
|
3862
|
+
|
|
3863
|
+
|
|
3864
|
+
|
|
3865
|
+
|
|
3866
|
+
|
|
3867
|
+
|
|
3868
|
+
|
|
3869
|
+
|
|
3870
|
+
|
|
3871
|
+
|
|
3872
|
+
|
|
3873
|
+
|
|
3874
|
+
|
|
3875
|
+
|
|
3876
|
+
|
|
3877
|
+
|
|
3878
|
+
|
|
3879
|
+
|
|
3880
|
+
|
|
3881
|
+
|
|
3882
|
+
|
|
3883
|
+
|
|
3158
3884
|
* @example
|
|
3159
3885
|
* // Get incoming edges
|
|
3160
3886
|
* const g = new DirectedGraph();
|
|
@@ -3185,6 +3911,30 @@ var DirectedGraph = class _DirectedGraph extends AbstractGraph {
|
|
|
3185
3911
|
|
|
3186
3912
|
|
|
3187
3913
|
|
|
3914
|
+
|
|
3915
|
+
|
|
3916
|
+
|
|
3917
|
+
|
|
3918
|
+
|
|
3919
|
+
|
|
3920
|
+
|
|
3921
|
+
|
|
3922
|
+
|
|
3923
|
+
|
|
3924
|
+
|
|
3925
|
+
|
|
3926
|
+
|
|
3927
|
+
|
|
3928
|
+
|
|
3929
|
+
|
|
3930
|
+
|
|
3931
|
+
|
|
3932
|
+
|
|
3933
|
+
|
|
3934
|
+
|
|
3935
|
+
|
|
3936
|
+
|
|
3937
|
+
|
|
3188
3938
|
* @example
|
|
3189
3939
|
* // Get outgoing edges
|
|
3190
3940
|
* const g = new DirectedGraph();
|
|
@@ -3268,6 +4018,30 @@ var DirectedGraph = class _DirectedGraph extends AbstractGraph {
|
|
|
3268
4018
|
|
|
3269
4019
|
|
|
3270
4020
|
|
|
4021
|
+
|
|
4022
|
+
|
|
4023
|
+
|
|
4024
|
+
|
|
4025
|
+
|
|
4026
|
+
|
|
4027
|
+
|
|
4028
|
+
|
|
4029
|
+
|
|
4030
|
+
|
|
4031
|
+
|
|
4032
|
+
|
|
4033
|
+
|
|
4034
|
+
|
|
4035
|
+
|
|
4036
|
+
|
|
4037
|
+
|
|
4038
|
+
|
|
4039
|
+
|
|
4040
|
+
|
|
4041
|
+
|
|
4042
|
+
|
|
4043
|
+
|
|
4044
|
+
|
|
3271
4045
|
* @example
|
|
3272
4046
|
* // DirectedGraph topologicalSort for task scheduling
|
|
3273
4047
|
* const graph = new DirectedGraph<string>();
|
|
@@ -3332,6 +4106,30 @@ var DirectedGraph = class _DirectedGraph extends AbstractGraph {
|
|
|
3332
4106
|
|
|
3333
4107
|
|
|
3334
4108
|
|
|
4109
|
+
|
|
4110
|
+
|
|
4111
|
+
|
|
4112
|
+
|
|
4113
|
+
|
|
4114
|
+
|
|
4115
|
+
|
|
4116
|
+
|
|
4117
|
+
|
|
4118
|
+
|
|
4119
|
+
|
|
4120
|
+
|
|
4121
|
+
|
|
4122
|
+
|
|
4123
|
+
|
|
4124
|
+
|
|
4125
|
+
|
|
4126
|
+
|
|
4127
|
+
|
|
4128
|
+
|
|
4129
|
+
|
|
4130
|
+
|
|
4131
|
+
|
|
4132
|
+
|
|
3335
4133
|
* @example
|
|
3336
4134
|
* // Get all edges
|
|
3337
4135
|
* const g = new DirectedGraph();
|
|
@@ -3358,6 +4156,30 @@ var DirectedGraph = class _DirectedGraph extends AbstractGraph {
|
|
|
3358
4156
|
|
|
3359
4157
|
|
|
3360
4158
|
|
|
4159
|
+
|
|
4160
|
+
|
|
4161
|
+
|
|
4162
|
+
|
|
4163
|
+
|
|
4164
|
+
|
|
4165
|
+
|
|
4166
|
+
|
|
4167
|
+
|
|
4168
|
+
|
|
4169
|
+
|
|
4170
|
+
|
|
4171
|
+
|
|
4172
|
+
|
|
4173
|
+
|
|
4174
|
+
|
|
4175
|
+
|
|
4176
|
+
|
|
4177
|
+
|
|
4178
|
+
|
|
4179
|
+
|
|
4180
|
+
|
|
4181
|
+
|
|
4182
|
+
|
|
3361
4183
|
* @example
|
|
3362
4184
|
* // Get outgoing neighbors
|
|
3363
4185
|
* const g = new DirectedGraph();
|
|
@@ -3437,6 +4259,30 @@ var DirectedGraph = class _DirectedGraph extends AbstractGraph {
|
|
|
3437
4259
|
|
|
3438
4260
|
|
|
3439
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
|
+
|
|
3440
4286
|
* @example
|
|
3441
4287
|
* // Find strongly connected components
|
|
3442
4288
|
* const g = new DirectedGraph();
|
|
@@ -3519,6 +4365,30 @@ var DirectedGraph = class _DirectedGraph extends AbstractGraph {
|
|
|
3519
4365
|
|
|
3520
4366
|
|
|
3521
4367
|
|
|
4368
|
+
|
|
4369
|
+
|
|
4370
|
+
|
|
4371
|
+
|
|
4372
|
+
|
|
4373
|
+
|
|
4374
|
+
|
|
4375
|
+
|
|
4376
|
+
|
|
4377
|
+
|
|
4378
|
+
|
|
4379
|
+
|
|
4380
|
+
|
|
4381
|
+
|
|
4382
|
+
|
|
4383
|
+
|
|
4384
|
+
|
|
4385
|
+
|
|
4386
|
+
|
|
4387
|
+
|
|
4388
|
+
|
|
4389
|
+
|
|
4390
|
+
|
|
4391
|
+
|
|
3522
4392
|
* @example
|
|
3523
4393
|
* // Get strongly connected components
|
|
3524
4394
|
* const g = new DirectedGraph();
|
|
@@ -3667,6 +4537,30 @@ var UndirectedGraph = class _UndirectedGraph extends AbstractGraph {
|
|
|
3667
4537
|
|
|
3668
4538
|
|
|
3669
4539
|
|
|
4540
|
+
|
|
4541
|
+
|
|
4542
|
+
|
|
4543
|
+
|
|
4544
|
+
|
|
4545
|
+
|
|
4546
|
+
|
|
4547
|
+
|
|
4548
|
+
|
|
4549
|
+
|
|
4550
|
+
|
|
4551
|
+
|
|
4552
|
+
|
|
4553
|
+
|
|
4554
|
+
|
|
4555
|
+
|
|
4556
|
+
|
|
4557
|
+
|
|
4558
|
+
|
|
4559
|
+
|
|
4560
|
+
|
|
4561
|
+
|
|
4562
|
+
|
|
4563
|
+
|
|
3670
4564
|
* @example
|
|
3671
4565
|
* // Get edge between vertices
|
|
3672
4566
|
* const g = new UndirectedGraph();
|
|
@@ -3727,6 +4621,30 @@ var UndirectedGraph = class _UndirectedGraph extends AbstractGraph {
|
|
|
3727
4621
|
|
|
3728
4622
|
|
|
3729
4623
|
|
|
4624
|
+
|
|
4625
|
+
|
|
4626
|
+
|
|
4627
|
+
|
|
4628
|
+
|
|
4629
|
+
|
|
4630
|
+
|
|
4631
|
+
|
|
4632
|
+
|
|
4633
|
+
|
|
4634
|
+
|
|
4635
|
+
|
|
4636
|
+
|
|
4637
|
+
|
|
4638
|
+
|
|
4639
|
+
|
|
4640
|
+
|
|
4641
|
+
|
|
4642
|
+
|
|
4643
|
+
|
|
4644
|
+
|
|
4645
|
+
|
|
4646
|
+
|
|
4647
|
+
|
|
3730
4648
|
* @example
|
|
3731
4649
|
* // UndirectedGraph deleteEdge and vertex operations
|
|
3732
4650
|
* const graph = new UndirectedGraph<string>();
|
|
@@ -3787,6 +4705,30 @@ var UndirectedGraph = class _UndirectedGraph extends AbstractGraph {
|
|
|
3787
4705
|
|
|
3788
4706
|
|
|
3789
4707
|
|
|
4708
|
+
|
|
4709
|
+
|
|
4710
|
+
|
|
4711
|
+
|
|
4712
|
+
|
|
4713
|
+
|
|
4714
|
+
|
|
4715
|
+
|
|
4716
|
+
|
|
4717
|
+
|
|
4718
|
+
|
|
4719
|
+
|
|
4720
|
+
|
|
4721
|
+
|
|
4722
|
+
|
|
4723
|
+
|
|
4724
|
+
|
|
4725
|
+
|
|
4726
|
+
|
|
4727
|
+
|
|
4728
|
+
|
|
4729
|
+
|
|
4730
|
+
|
|
4731
|
+
|
|
3790
4732
|
* @example
|
|
3791
4733
|
* // Remove vertex and edges
|
|
3792
4734
|
* const g = new UndirectedGraph();
|
|
@@ -3861,6 +4803,30 @@ var UndirectedGraph = class _UndirectedGraph extends AbstractGraph {
|
|
|
3861
4803
|
|
|
3862
4804
|
|
|
3863
4805
|
|
|
4806
|
+
|
|
4807
|
+
|
|
4808
|
+
|
|
4809
|
+
|
|
4810
|
+
|
|
4811
|
+
|
|
4812
|
+
|
|
4813
|
+
|
|
4814
|
+
|
|
4815
|
+
|
|
4816
|
+
|
|
4817
|
+
|
|
4818
|
+
|
|
4819
|
+
|
|
4820
|
+
|
|
4821
|
+
|
|
4822
|
+
|
|
4823
|
+
|
|
4824
|
+
|
|
4825
|
+
|
|
4826
|
+
|
|
4827
|
+
|
|
4828
|
+
|
|
4829
|
+
|
|
3864
4830
|
* @example
|
|
3865
4831
|
* // Get all edges
|
|
3866
4832
|
* const g = new UndirectedGraph();
|
|
@@ -3891,6 +4857,30 @@ var UndirectedGraph = class _UndirectedGraph extends AbstractGraph {
|
|
|
3891
4857
|
|
|
3892
4858
|
|
|
3893
4859
|
|
|
4860
|
+
|
|
4861
|
+
|
|
4862
|
+
|
|
4863
|
+
|
|
4864
|
+
|
|
4865
|
+
|
|
4866
|
+
|
|
4867
|
+
|
|
4868
|
+
|
|
4869
|
+
|
|
4870
|
+
|
|
4871
|
+
|
|
4872
|
+
|
|
4873
|
+
|
|
4874
|
+
|
|
4875
|
+
|
|
4876
|
+
|
|
4877
|
+
|
|
4878
|
+
|
|
4879
|
+
|
|
4880
|
+
|
|
4881
|
+
|
|
4882
|
+
|
|
4883
|
+
|
|
3894
4884
|
* @example
|
|
3895
4885
|
* // UndirectedGraph connectivity and neighbors
|
|
3896
4886
|
* const graph = new UndirectedGraph<string>();
|
|
@@ -3991,6 +4981,30 @@ var UndirectedGraph = class _UndirectedGraph extends AbstractGraph {
|
|
|
3991
4981
|
|
|
3992
4982
|
|
|
3993
4983
|
|
|
4984
|
+
|
|
4985
|
+
|
|
4986
|
+
|
|
4987
|
+
|
|
4988
|
+
|
|
4989
|
+
|
|
4990
|
+
|
|
4991
|
+
|
|
4992
|
+
|
|
4993
|
+
|
|
4994
|
+
|
|
4995
|
+
|
|
4996
|
+
|
|
4997
|
+
|
|
4998
|
+
|
|
4999
|
+
|
|
5000
|
+
|
|
5001
|
+
|
|
5002
|
+
|
|
5003
|
+
|
|
5004
|
+
|
|
5005
|
+
|
|
5006
|
+
|
|
5007
|
+
|
|
3994
5008
|
* @example
|
|
3995
5009
|
* // Find articulation points and bridges
|
|
3996
5010
|
* const g = new UndirectedGraph();
|
|
@@ -4113,6 +5127,30 @@ var UndirectedGraph = class _UndirectedGraph extends AbstractGraph {
|
|
|
4113
5127
|
|
|
4114
5128
|
|
|
4115
5129
|
|
|
5130
|
+
|
|
5131
|
+
|
|
5132
|
+
|
|
5133
|
+
|
|
5134
|
+
|
|
5135
|
+
|
|
5136
|
+
|
|
5137
|
+
|
|
5138
|
+
|
|
5139
|
+
|
|
5140
|
+
|
|
5141
|
+
|
|
5142
|
+
|
|
5143
|
+
|
|
5144
|
+
|
|
5145
|
+
|
|
5146
|
+
|
|
5147
|
+
|
|
5148
|
+
|
|
5149
|
+
|
|
5150
|
+
|
|
5151
|
+
|
|
5152
|
+
|
|
5153
|
+
|
|
4116
5154
|
* @example
|
|
4117
5155
|
* // Detect cycle
|
|
4118
5156
|
* const g = new UndirectedGraph();
|
|
@@ -4157,6 +5195,30 @@ var UndirectedGraph = class _UndirectedGraph extends AbstractGraph {
|
|
|
4157
5195
|
|
|
4158
5196
|
|
|
4159
5197
|
|
|
5198
|
+
|
|
5199
|
+
|
|
5200
|
+
|
|
5201
|
+
|
|
5202
|
+
|
|
5203
|
+
|
|
5204
|
+
|
|
5205
|
+
|
|
5206
|
+
|
|
5207
|
+
|
|
5208
|
+
|
|
5209
|
+
|
|
5210
|
+
|
|
5211
|
+
|
|
5212
|
+
|
|
5213
|
+
|
|
5214
|
+
|
|
5215
|
+
|
|
5216
|
+
|
|
5217
|
+
|
|
5218
|
+
|
|
5219
|
+
|
|
5220
|
+
|
|
5221
|
+
|
|
4160
5222
|
* @example
|
|
4161
5223
|
* // Find bridge edges
|
|
4162
5224
|
* const g = new UndirectedGraph();
|
|
@@ -4183,6 +5245,30 @@ var UndirectedGraph = class _UndirectedGraph extends AbstractGraph {
|
|
|
4183
5245
|
|
|
4184
5246
|
|
|
4185
5247
|
|
|
5248
|
+
|
|
5249
|
+
|
|
5250
|
+
|
|
5251
|
+
|
|
5252
|
+
|
|
5253
|
+
|
|
5254
|
+
|
|
5255
|
+
|
|
5256
|
+
|
|
5257
|
+
|
|
5258
|
+
|
|
5259
|
+
|
|
5260
|
+
|
|
5261
|
+
|
|
5262
|
+
|
|
5263
|
+
|
|
5264
|
+
|
|
5265
|
+
|
|
5266
|
+
|
|
5267
|
+
|
|
5268
|
+
|
|
5269
|
+
|
|
5270
|
+
|
|
5271
|
+
|
|
4186
5272
|
* @example
|
|
4187
5273
|
* // Find articulation points
|
|
4188
5274
|
* const g = new UndirectedGraph();
|
|
@@ -4342,6 +5428,6 @@ var MapGraph = class _MapGraph extends DirectedGraph {
|
|
|
4342
5428
|
* @license MIT License
|
|
4343
5429
|
*/
|
|
4344
5430
|
|
|
4345
|
-
export { AbstractEdge, AbstractGraph, AbstractVertex, DFSOperation, DirectedEdge, DirectedGraph, DirectedVertex, ERR, MapEdge, MapGraph, MapVertex, Range, UndirectedEdge, UndirectedGraph, UndirectedVertex };
|
|
5431
|
+
export { AbstractEdge, AbstractGraph, AbstractVertex, DFSOperation, DirectedEdge, DirectedGraph, DirectedVertex, ERR, MapEdge, MapGraph, MapVertex, Range, UndirectedEdge, UndirectedGraph, UndirectedVertex, raise };
|
|
4346
5432
|
//# sourceMappingURL=index.mjs.map
|
|
4347
5433
|
//# sourceMappingURL=index.mjs.map
|