graph-typed 2.5.0 → 2.5.1
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 +1213 -268
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs-legacy/index.cjs +1202 -257
- package/dist/cjs-legacy/index.cjs.map +1 -1
- package/dist/esm/index.mjs +1213 -268
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm-legacy/index.mjs +1202 -257
- package/dist/esm-legacy/index.mjs.map +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 +252 -0
- package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +294 -0
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +527 -2
- package/dist/types/data-structures/binary-tree/bst.d.ts +505 -1
- package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +399 -0
- package/dist/types/data-structures/binary-tree/segment-tree.d.ts +126 -1
- package/dist/types/data-structures/binary-tree/tree-map.d.ts +2881 -382
- package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +2867 -347
- package/dist/types/data-structures/binary-tree/tree-multi-set.d.ts +2328 -312
- package/dist/types/data-structures/binary-tree/tree-set.d.ts +2671 -277
- package/dist/types/data-structures/graph/abstract-graph.d.ts +4 -4
- package/dist/types/data-structures/graph/directed-graph.d.ts +210 -0
- package/dist/types/data-structures/graph/undirected-graph.d.ts +189 -0
- package/dist/types/data-structures/hash/hash-map.d.ts +241 -10
- package/dist/types/data-structures/heap/heap.d.ts +294 -0
- package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +360 -3
- package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +318 -3
- package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +380 -2
- package/dist/types/data-structures/matrix/matrix.d.ts +168 -0
- package/dist/types/data-structures/queue/deque.d.ts +319 -4
- package/dist/types/data-structures/queue/queue.d.ts +252 -0
- package/dist/types/data-structures/stack/stack.d.ts +210 -0
- package/dist/types/data-structures/trie/trie.d.ts +256 -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/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 +1204 -259
- 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/data-structures/base/index.ts +1 -0
- 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 +252 -0
- package/src/data-structures/binary-tree/binary-indexed-tree.ts +295 -1
- package/src/data-structures/binary-tree/binary-tree.ts +527 -2
- package/src/data-structures/binary-tree/bst.ts +505 -1
- package/src/data-structures/binary-tree/red-black-tree.ts +399 -0
- package/src/data-structures/binary-tree/segment-tree.ts +127 -2
- package/src/data-structures/binary-tree/tree-map.ts +2958 -459
- package/src/data-structures/binary-tree/tree-multi-map.ts +3069 -549
- package/src/data-structures/binary-tree/tree-multi-set.ts +2476 -460
- package/src/data-structures/binary-tree/tree-set.ts +2816 -422
- package/src/data-structures/graph/abstract-graph.ts +4 -4
- package/src/data-structures/graph/directed-graph.ts +210 -0
- package/src/data-structures/graph/undirected-graph.ts +189 -0
- package/src/data-structures/hash/hash-map.ts +246 -15
- package/src/data-structures/heap/heap.ts +294 -0
- package/src/data-structures/linked-list/doubly-linked-list.ts +360 -3
- package/src/data-structures/linked-list/singly-linked-list.ts +318 -3
- package/src/data-structures/linked-list/skip-linked-list.ts +380 -2
- package/src/data-structures/matrix/matrix.ts +169 -1
- package/src/data-structures/queue/deque.ts +320 -5
- package/src/data-structures/queue/queue.ts +252 -0
- package/src/data-structures/stack/stack.ts +210 -0
- package/src/data-structures/trie/trie.ts +257 -5
- package/src/interfaces/graph.ts +1 -1
- package/src/types/common.ts +2 -2
- 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
|
@@ -476,6 +476,199 @@ var IterableElementBase = class {
|
|
|
476
476
|
}
|
|
477
477
|
};
|
|
478
478
|
|
|
479
|
+
// src/data-structures/base/linear-base.ts
|
|
480
|
+
var LinearBase = class _LinearBase extends IterableElementBase {
|
|
481
|
+
static {
|
|
482
|
+
__name(this, "LinearBase");
|
|
483
|
+
}
|
|
484
|
+
/**
|
|
485
|
+
* Construct a linear container with runtime options.
|
|
486
|
+
* @param options - `{ maxLen?, ... }` bounds/behavior options.
|
|
487
|
+
* @remarks Time O(1), Space O(1)
|
|
488
|
+
*/
|
|
489
|
+
constructor(options) {
|
|
490
|
+
super(options);
|
|
491
|
+
if (options) {
|
|
492
|
+
const { maxLen } = options;
|
|
493
|
+
if (typeof maxLen === "number" && maxLen > 0 && maxLen % 1 === 0) this._maxLen = maxLen;
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
_maxLen = -1;
|
|
497
|
+
/**
|
|
498
|
+
* Upper bound for length (if positive), or `-1` when unbounded.
|
|
499
|
+
* @returns Maximum allowed length.
|
|
500
|
+
* @remarks Time O(1), Space O(1)
|
|
501
|
+
*/
|
|
502
|
+
get maxLen() {
|
|
503
|
+
return this._maxLen;
|
|
504
|
+
}
|
|
505
|
+
/**
|
|
506
|
+
* First index of a value from the left.
|
|
507
|
+
* @param searchElement - Value to match.
|
|
508
|
+
* @param fromIndex - Start position (supports negative index).
|
|
509
|
+
* @returns Index or `-1` if not found.
|
|
510
|
+
* @remarks Time O(n), Space O(1)
|
|
511
|
+
*/
|
|
512
|
+
indexOf(searchElement, fromIndex = 0) {
|
|
513
|
+
if (this.length === 0) return -1;
|
|
514
|
+
if (fromIndex < 0) fromIndex = this.length + fromIndex;
|
|
515
|
+
if (fromIndex < 0) fromIndex = 0;
|
|
516
|
+
for (let i = fromIndex; i < this.length; i++) {
|
|
517
|
+
const element = this.at(i);
|
|
518
|
+
if (element === searchElement) return i;
|
|
519
|
+
}
|
|
520
|
+
return -1;
|
|
521
|
+
}
|
|
522
|
+
/**
|
|
523
|
+
* Last index of a value from the right.
|
|
524
|
+
* @param searchElement - Value to match.
|
|
525
|
+
* @param fromIndex - Start position (supports negative index).
|
|
526
|
+
* @returns Index or `-1` if not found.
|
|
527
|
+
* @remarks Time O(n), Space O(1)
|
|
528
|
+
*/
|
|
529
|
+
lastIndexOf(searchElement, fromIndex = this.length - 1) {
|
|
530
|
+
if (this.length === 0) return -1;
|
|
531
|
+
if (fromIndex >= this.length) fromIndex = this.length - 1;
|
|
532
|
+
if (fromIndex < 0) fromIndex = this.length + fromIndex;
|
|
533
|
+
for (let i = fromIndex; i >= 0; i--) {
|
|
534
|
+
const element = this.at(i);
|
|
535
|
+
if (element === searchElement) return i;
|
|
536
|
+
}
|
|
537
|
+
return -1;
|
|
538
|
+
}
|
|
539
|
+
/**
|
|
540
|
+
* Find the first index matching a predicate.
|
|
541
|
+
* @param predicate - `(element, index, self) => boolean`.
|
|
542
|
+
* @param thisArg - Optional `this` for callback.
|
|
543
|
+
* @returns Index or `-1`.
|
|
544
|
+
* @remarks Time O(n), Space O(1)
|
|
545
|
+
*/
|
|
546
|
+
findIndex(predicate, thisArg) {
|
|
547
|
+
for (let i = 0; i < this.length; i++) {
|
|
548
|
+
const item = this.at(i);
|
|
549
|
+
if (item !== void 0 && predicate.call(thisArg, item, i, this)) return i;
|
|
550
|
+
}
|
|
551
|
+
return -1;
|
|
552
|
+
}
|
|
553
|
+
/**
|
|
554
|
+
* Concatenate elements and/or containers.
|
|
555
|
+
* @param items - Elements or other containers.
|
|
556
|
+
* @returns New container with combined elements (`this` type).
|
|
557
|
+
* @remarks Time O(sum(length)), Space O(sum(length))
|
|
558
|
+
*/
|
|
559
|
+
concat(...items) {
|
|
560
|
+
const newList = this.clone();
|
|
561
|
+
for (const item of items) {
|
|
562
|
+
if (item instanceof _LinearBase) {
|
|
563
|
+
newList.pushMany(item);
|
|
564
|
+
} else {
|
|
565
|
+
newList.push(item);
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
return newList;
|
|
569
|
+
}
|
|
570
|
+
/**
|
|
571
|
+
* In-place stable order via array sort semantics.
|
|
572
|
+
* @param compareFn - Comparator `(a, b) => number`.
|
|
573
|
+
* @returns This container.
|
|
574
|
+
* @remarks Time O(n log n), Space O(n) (materializes to array temporarily)
|
|
575
|
+
*/
|
|
576
|
+
sort(compareFn) {
|
|
577
|
+
const arr = this.toArray();
|
|
578
|
+
arr.sort(compareFn);
|
|
579
|
+
this.clear();
|
|
580
|
+
for (const item of arr) this.push(item);
|
|
581
|
+
return this;
|
|
582
|
+
}
|
|
583
|
+
/**
|
|
584
|
+
* Remove and/or insert elements at a position (array-compatible).
|
|
585
|
+
* @param start - Start index (supports negative index).
|
|
586
|
+
* @param deleteCount - How many to remove.
|
|
587
|
+
* @param items - Elements to insert.
|
|
588
|
+
* @returns Removed elements as a new list (`this` type).
|
|
589
|
+
* @remarks Time O(n + m), Space O(min(n, m)) where `m = items.length`
|
|
590
|
+
*/
|
|
591
|
+
splice(start, deleteCount = 0, ...items) {
|
|
592
|
+
const removedList = this._createInstance();
|
|
593
|
+
start = start < 0 ? this.length + start : start;
|
|
594
|
+
start = Math.max(0, Math.min(start, this.length));
|
|
595
|
+
deleteCount = Math.max(0, Math.min(deleteCount, this.length - start));
|
|
596
|
+
for (let i = 0; i < deleteCount; i++) {
|
|
597
|
+
const removed = this.deleteAt(start);
|
|
598
|
+
if (removed !== void 0) {
|
|
599
|
+
removedList.push(removed);
|
|
600
|
+
}
|
|
601
|
+
}
|
|
602
|
+
for (let i = 0; i < items.length; i++) {
|
|
603
|
+
this.addAt(start + i, items[i]);
|
|
604
|
+
}
|
|
605
|
+
return removedList;
|
|
606
|
+
}
|
|
607
|
+
/**
|
|
608
|
+
* Join all elements into a string.
|
|
609
|
+
* @param separator - Separator string.
|
|
610
|
+
* @returns Concatenated string.
|
|
611
|
+
* @remarks Time O(n), Space O(n)
|
|
612
|
+
*/
|
|
613
|
+
join(separator = ",") {
|
|
614
|
+
return this.toArray().join(separator);
|
|
615
|
+
}
|
|
616
|
+
/**
|
|
617
|
+
* Snapshot elements into a reversed array.
|
|
618
|
+
* @returns New reversed array.
|
|
619
|
+
* @remarks Time O(n), Space O(n)
|
|
620
|
+
*/
|
|
621
|
+
toReversedArray() {
|
|
622
|
+
const array = [];
|
|
623
|
+
for (let i = this.length - 1; i >= 0; i--) {
|
|
624
|
+
array.push(this.at(i));
|
|
625
|
+
}
|
|
626
|
+
return array;
|
|
627
|
+
}
|
|
628
|
+
reduceRight(callbackfn, initialValue) {
|
|
629
|
+
let accumulator = initialValue ?? 0;
|
|
630
|
+
for (let i = this.length - 1; i >= 0; i--) {
|
|
631
|
+
accumulator = callbackfn(accumulator, this.at(i), i, this);
|
|
632
|
+
}
|
|
633
|
+
return accumulator;
|
|
634
|
+
}
|
|
635
|
+
/**
|
|
636
|
+
* Create a shallow copy of a subrange.
|
|
637
|
+
* @param start - Inclusive start (supports negative index).
|
|
638
|
+
* @param end - Exclusive end (supports negative index).
|
|
639
|
+
* @returns New list with the range (`this` type).
|
|
640
|
+
* @remarks Time O(n), Space O(n)
|
|
641
|
+
*/
|
|
642
|
+
slice(start = 0, end = this.length) {
|
|
643
|
+
start = start < 0 ? this.length + start : start;
|
|
644
|
+
end = end < 0 ? this.length + end : end;
|
|
645
|
+
const newList = this._createInstance();
|
|
646
|
+
for (let i = start; i < end; i++) {
|
|
647
|
+
newList.push(this.at(i));
|
|
648
|
+
}
|
|
649
|
+
return newList;
|
|
650
|
+
}
|
|
651
|
+
/**
|
|
652
|
+
* Fill a range with a value.
|
|
653
|
+
* @param value - Value to set.
|
|
654
|
+
* @param start - Inclusive start.
|
|
655
|
+
* @param end - Exclusive end.
|
|
656
|
+
* @returns This list.
|
|
657
|
+
* @remarks Time O(n), Space O(1)
|
|
658
|
+
*/
|
|
659
|
+
fill(value, start = 0, end = this.length) {
|
|
660
|
+
start = start < 0 ? this.length + start : start;
|
|
661
|
+
end = end < 0 ? this.length + end : end;
|
|
662
|
+
if (start < 0) start = 0;
|
|
663
|
+
if (end > this.length) end = this.length;
|
|
664
|
+
if (start >= end) return this;
|
|
665
|
+
for (let i = start; i < end; i++) {
|
|
666
|
+
this.setAt(i, value);
|
|
667
|
+
}
|
|
668
|
+
return this;
|
|
669
|
+
}
|
|
670
|
+
};
|
|
671
|
+
|
|
479
672
|
// src/data-structures/heap/heap.ts
|
|
480
673
|
var Heap = class _Heap extends IterableElementBase {
|
|
481
674
|
static {
|
|
@@ -521,6 +714,27 @@ var Heap = class _Heap extends IterableElementBase {
|
|
|
521
714
|
|
|
522
715
|
|
|
523
716
|
|
|
717
|
+
|
|
718
|
+
|
|
719
|
+
|
|
720
|
+
|
|
721
|
+
|
|
722
|
+
|
|
723
|
+
|
|
724
|
+
|
|
725
|
+
|
|
726
|
+
|
|
727
|
+
|
|
728
|
+
|
|
729
|
+
|
|
730
|
+
|
|
731
|
+
|
|
732
|
+
|
|
733
|
+
|
|
734
|
+
|
|
735
|
+
|
|
736
|
+
|
|
737
|
+
|
|
524
738
|
* @example
|
|
525
739
|
* // Track heap capacity
|
|
526
740
|
* const heap = new Heap<number>();
|
|
@@ -583,6 +797,27 @@ var Heap = class _Heap extends IterableElementBase {
|
|
|
583
797
|
|
|
584
798
|
|
|
585
799
|
|
|
800
|
+
|
|
801
|
+
|
|
802
|
+
|
|
803
|
+
|
|
804
|
+
|
|
805
|
+
|
|
806
|
+
|
|
807
|
+
|
|
808
|
+
|
|
809
|
+
|
|
810
|
+
|
|
811
|
+
|
|
812
|
+
|
|
813
|
+
|
|
814
|
+
|
|
815
|
+
|
|
816
|
+
|
|
817
|
+
|
|
818
|
+
|
|
819
|
+
|
|
820
|
+
|
|
586
821
|
* @example
|
|
587
822
|
* // basic Heap creation and add operation
|
|
588
823
|
* // Create a min heap (default)
|
|
@@ -616,6 +851,27 @@ var Heap = class _Heap extends IterableElementBase {
|
|
|
616
851
|
|
|
617
852
|
|
|
618
853
|
|
|
854
|
+
|
|
855
|
+
|
|
856
|
+
|
|
857
|
+
|
|
858
|
+
|
|
859
|
+
|
|
860
|
+
|
|
861
|
+
|
|
862
|
+
|
|
863
|
+
|
|
864
|
+
|
|
865
|
+
|
|
866
|
+
|
|
867
|
+
|
|
868
|
+
|
|
869
|
+
|
|
870
|
+
|
|
871
|
+
|
|
872
|
+
|
|
873
|
+
|
|
874
|
+
|
|
619
875
|
* @example
|
|
620
876
|
* // Add multiple elements
|
|
621
877
|
* const heap = new Heap<number>([], { comparator: (a, b) => a - b });
|
|
@@ -651,6 +907,27 @@ var Heap = class _Heap extends IterableElementBase {
|
|
|
651
907
|
|
|
652
908
|
|
|
653
909
|
|
|
910
|
+
|
|
911
|
+
|
|
912
|
+
|
|
913
|
+
|
|
914
|
+
|
|
915
|
+
|
|
916
|
+
|
|
917
|
+
|
|
918
|
+
|
|
919
|
+
|
|
920
|
+
|
|
921
|
+
|
|
922
|
+
|
|
923
|
+
|
|
924
|
+
|
|
925
|
+
|
|
926
|
+
|
|
927
|
+
|
|
928
|
+
|
|
929
|
+
|
|
930
|
+
|
|
654
931
|
* @example
|
|
655
932
|
* // Heap with custom comparator (MaxHeap behavior)
|
|
656
933
|
* interface Task {
|
|
@@ -702,6 +979,27 @@ var Heap = class _Heap extends IterableElementBase {
|
|
|
702
979
|
|
|
703
980
|
|
|
704
981
|
|
|
982
|
+
|
|
983
|
+
|
|
984
|
+
|
|
985
|
+
|
|
986
|
+
|
|
987
|
+
|
|
988
|
+
|
|
989
|
+
|
|
990
|
+
|
|
991
|
+
|
|
992
|
+
|
|
993
|
+
|
|
994
|
+
|
|
995
|
+
|
|
996
|
+
|
|
997
|
+
|
|
998
|
+
|
|
999
|
+
|
|
1000
|
+
|
|
1001
|
+
|
|
1002
|
+
|
|
705
1003
|
* @example
|
|
706
1004
|
* // Heap for event processing with priority
|
|
707
1005
|
* interface Event {
|
|
@@ -778,6 +1076,27 @@ var Heap = class _Heap extends IterableElementBase {
|
|
|
778
1076
|
|
|
779
1077
|
|
|
780
1078
|
|
|
1079
|
+
|
|
1080
|
+
|
|
1081
|
+
|
|
1082
|
+
|
|
1083
|
+
|
|
1084
|
+
|
|
1085
|
+
|
|
1086
|
+
|
|
1087
|
+
|
|
1088
|
+
|
|
1089
|
+
|
|
1090
|
+
|
|
1091
|
+
|
|
1092
|
+
|
|
1093
|
+
|
|
1094
|
+
|
|
1095
|
+
|
|
1096
|
+
|
|
1097
|
+
|
|
1098
|
+
|
|
1099
|
+
|
|
781
1100
|
* @example
|
|
782
1101
|
* // Check if heap is empty
|
|
783
1102
|
* const heap = new Heap<number>([], { comparator: (a, b) => a - b });
|
|
@@ -801,6 +1120,27 @@ var Heap = class _Heap extends IterableElementBase {
|
|
|
801
1120
|
|
|
802
1121
|
|
|
803
1122
|
|
|
1123
|
+
|
|
1124
|
+
|
|
1125
|
+
|
|
1126
|
+
|
|
1127
|
+
|
|
1128
|
+
|
|
1129
|
+
|
|
1130
|
+
|
|
1131
|
+
|
|
1132
|
+
|
|
1133
|
+
|
|
1134
|
+
|
|
1135
|
+
|
|
1136
|
+
|
|
1137
|
+
|
|
1138
|
+
|
|
1139
|
+
|
|
1140
|
+
|
|
1141
|
+
|
|
1142
|
+
|
|
1143
|
+
|
|
804
1144
|
* @example
|
|
805
1145
|
* // Remove all elements
|
|
806
1146
|
* const heap = new Heap<number>([1, 2, 3], { comparator: (a, b) => a - b });
|
|
@@ -827,6 +1167,27 @@ var Heap = class _Heap extends IterableElementBase {
|
|
|
827
1167
|
* @returns True if found.
|
|
828
1168
|
|
|
829
1169
|
|
|
1170
|
+
|
|
1171
|
+
|
|
1172
|
+
|
|
1173
|
+
|
|
1174
|
+
|
|
1175
|
+
|
|
1176
|
+
|
|
1177
|
+
|
|
1178
|
+
|
|
1179
|
+
|
|
1180
|
+
|
|
1181
|
+
|
|
1182
|
+
|
|
1183
|
+
|
|
1184
|
+
|
|
1185
|
+
|
|
1186
|
+
|
|
1187
|
+
|
|
1188
|
+
|
|
1189
|
+
|
|
1190
|
+
|
|
830
1191
|
* @example
|
|
831
1192
|
* // Check element existence
|
|
832
1193
|
* const heap = new Heap<number>([3, 1, 2], { comparator: (a, b) => a - b });
|
|
@@ -850,6 +1211,27 @@ var Heap = class _Heap extends IterableElementBase {
|
|
|
850
1211
|
|
|
851
1212
|
|
|
852
1213
|
|
|
1214
|
+
|
|
1215
|
+
|
|
1216
|
+
|
|
1217
|
+
|
|
1218
|
+
|
|
1219
|
+
|
|
1220
|
+
|
|
1221
|
+
|
|
1222
|
+
|
|
1223
|
+
|
|
1224
|
+
|
|
1225
|
+
|
|
1226
|
+
|
|
1227
|
+
|
|
1228
|
+
|
|
1229
|
+
|
|
1230
|
+
|
|
1231
|
+
|
|
1232
|
+
|
|
1233
|
+
|
|
1234
|
+
|
|
853
1235
|
* @example
|
|
854
1236
|
* // Remove specific element
|
|
855
1237
|
* const heap = new Heap<number>([3, 1, 4, 1, 5], { comparator: (a, b) => a - b });
|
|
@@ -919,6 +1301,27 @@ var Heap = class _Heap extends IterableElementBase {
|
|
|
919
1301
|
* @returns Array of visited elements.
|
|
920
1302
|
|
|
921
1303
|
|
|
1304
|
+
|
|
1305
|
+
|
|
1306
|
+
|
|
1307
|
+
|
|
1308
|
+
|
|
1309
|
+
|
|
1310
|
+
|
|
1311
|
+
|
|
1312
|
+
|
|
1313
|
+
|
|
1314
|
+
|
|
1315
|
+
|
|
1316
|
+
|
|
1317
|
+
|
|
1318
|
+
|
|
1319
|
+
|
|
1320
|
+
|
|
1321
|
+
|
|
1322
|
+
|
|
1323
|
+
|
|
1324
|
+
|
|
922
1325
|
* @example
|
|
923
1326
|
* // Depth-first traversal
|
|
924
1327
|
* const heap = new Heap<number>([3, 1, 2], { comparator: (a, b) => a - b });
|
|
@@ -975,6 +1378,27 @@ var Heap = class _Heap extends IterableElementBase {
|
|
|
975
1378
|
|
|
976
1379
|
|
|
977
1380
|
|
|
1381
|
+
|
|
1382
|
+
|
|
1383
|
+
|
|
1384
|
+
|
|
1385
|
+
|
|
1386
|
+
|
|
1387
|
+
|
|
1388
|
+
|
|
1389
|
+
|
|
1390
|
+
|
|
1391
|
+
|
|
1392
|
+
|
|
1393
|
+
|
|
1394
|
+
|
|
1395
|
+
|
|
1396
|
+
|
|
1397
|
+
|
|
1398
|
+
|
|
1399
|
+
|
|
1400
|
+
|
|
1401
|
+
|
|
978
1402
|
* @example
|
|
979
1403
|
* // Sort elements using heap
|
|
980
1404
|
* const heap = new Heap<number>([5, 1, 3, 2, 4]);
|
|
@@ -1004,6 +1428,27 @@ var Heap = class _Heap extends IterableElementBase {
|
|
|
1004
1428
|
|
|
1005
1429
|
|
|
1006
1430
|
|
|
1431
|
+
|
|
1432
|
+
|
|
1433
|
+
|
|
1434
|
+
|
|
1435
|
+
|
|
1436
|
+
|
|
1437
|
+
|
|
1438
|
+
|
|
1439
|
+
|
|
1440
|
+
|
|
1441
|
+
|
|
1442
|
+
|
|
1443
|
+
|
|
1444
|
+
|
|
1445
|
+
|
|
1446
|
+
|
|
1447
|
+
|
|
1448
|
+
|
|
1449
|
+
|
|
1450
|
+
|
|
1451
|
+
|
|
1007
1452
|
* @example
|
|
1008
1453
|
* // Create independent copy
|
|
1009
1454
|
* const heap = new Heap<number>([3, 1, 4], { comparator: (a, b) => a - b });
|
|
@@ -1032,6 +1477,27 @@ var Heap = class _Heap extends IterableElementBase {
|
|
|
1032
1477
|
|
|
1033
1478
|
|
|
1034
1479
|
|
|
1480
|
+
|
|
1481
|
+
|
|
1482
|
+
|
|
1483
|
+
|
|
1484
|
+
|
|
1485
|
+
|
|
1486
|
+
|
|
1487
|
+
|
|
1488
|
+
|
|
1489
|
+
|
|
1490
|
+
|
|
1491
|
+
|
|
1492
|
+
|
|
1493
|
+
|
|
1494
|
+
|
|
1495
|
+
|
|
1496
|
+
|
|
1497
|
+
|
|
1498
|
+
|
|
1499
|
+
|
|
1500
|
+
|
|
1035
1501
|
* @example
|
|
1036
1502
|
* // Filter elements
|
|
1037
1503
|
* const heap = new Heap<number>([1, 2, 3, 4, 5], { comparator: (a, b) => a - b });
|
|
@@ -1067,6 +1533,27 @@ var Heap = class _Heap extends IterableElementBase {
|
|
|
1067
1533
|
|
|
1068
1534
|
|
|
1069
1535
|
|
|
1536
|
+
|
|
1537
|
+
|
|
1538
|
+
|
|
1539
|
+
|
|
1540
|
+
|
|
1541
|
+
|
|
1542
|
+
|
|
1543
|
+
|
|
1544
|
+
|
|
1545
|
+
|
|
1546
|
+
|
|
1547
|
+
|
|
1548
|
+
|
|
1549
|
+
|
|
1550
|
+
|
|
1551
|
+
|
|
1552
|
+
|
|
1553
|
+
|
|
1554
|
+
|
|
1555
|
+
|
|
1556
|
+
|
|
1070
1557
|
* @example
|
|
1071
1558
|
* // Transform elements
|
|
1072
1559
|
* const heap = new Heap<number>([1, 2, 3], { comparator: (a, b) => a - b });
|
|
@@ -1095,286 +1582,93 @@ var Heap = class _Heap extends IterableElementBase {
|
|
|
1095
1582
|
const out = this._createInstance();
|
|
1096
1583
|
let i = 0;
|
|
1097
1584
|
for (const x of this) {
|
|
1098
|
-
const v = thisArg === void 0 ? callback(x, i++, this) : callback.call(thisArg, x, i++, this);
|
|
1099
|
-
out.add(v);
|
|
1100
|
-
}
|
|
1101
|
-
return out;
|
|
1102
|
-
}
|
|
1103
|
-
_DEFAULT_COMPARATOR = /* @__PURE__ */ __name((a, b) => {
|
|
1104
|
-
if (typeof a === "object" || typeof b === "object") {
|
|
1105
|
-
throw new TypeError(ERR.comparatorRequired("Heap"));
|
|
1106
|
-
}
|
|
1107
|
-
if (a > b) return 1;
|
|
1108
|
-
if (a < b) return -1;
|
|
1109
|
-
return 0;
|
|
1110
|
-
}, "_DEFAULT_COMPARATOR");
|
|
1111
|
-
_comparator = this._DEFAULT_COMPARATOR;
|
|
1112
|
-
/**
|
|
1113
|
-
* Get the comparator used to order elements.
|
|
1114
|
-
* @remarks Time O(1), Space O(1)
|
|
1115
|
-
* @returns Comparator function.
|
|
1116
|
-
*/
|
|
1117
|
-
get comparator() {
|
|
1118
|
-
return this._comparator;
|
|
1119
|
-
}
|
|
1120
|
-
*_getIterator() {
|
|
1121
|
-
for (const element of this.elements) yield element;
|
|
1122
|
-
}
|
|
1123
|
-
_bubbleUp(index) {
|
|
1124
|
-
const element = this.elements[index];
|
|
1125
|
-
while (index > 0) {
|
|
1126
|
-
const parent = index - 1 >> 1;
|
|
1127
|
-
const parentItem = this.elements[parent];
|
|
1128
|
-
if (this.comparator(parentItem, element) <= 0) break;
|
|
1129
|
-
this.elements[index] = parentItem;
|
|
1130
|
-
index = parent;
|
|
1131
|
-
}
|
|
1132
|
-
this.elements[index] = element;
|
|
1133
|
-
return true;
|
|
1134
|
-
}
|
|
1135
|
-
_sinkDown(index, halfLength) {
|
|
1136
|
-
const element = this.elements[index];
|
|
1137
|
-
while (index < halfLength) {
|
|
1138
|
-
let left = index << 1 | 1;
|
|
1139
|
-
const right = left + 1;
|
|
1140
|
-
let minItem = this.elements[left];
|
|
1141
|
-
if (right < this.elements.length && this.comparator(minItem, this.elements[right]) > 0) {
|
|
1142
|
-
left = right;
|
|
1143
|
-
minItem = this.elements[right];
|
|
1144
|
-
}
|
|
1145
|
-
if (this.comparator(minItem, element) >= 0) break;
|
|
1146
|
-
this.elements[index] = minItem;
|
|
1147
|
-
index = left;
|
|
1148
|
-
}
|
|
1149
|
-
this.elements[index] = element;
|
|
1150
|
-
return true;
|
|
1151
|
-
}
|
|
1152
|
-
/**
|
|
1153
|
-
* (Protected) Create an empty instance of the same concrete class.
|
|
1154
|
-
* @remarks Time O(1), Space O(1)
|
|
1155
|
-
* @param [options] - Options to override comparator or toElementFn.
|
|
1156
|
-
* @returns A like-kind empty heap instance.
|
|
1157
|
-
*/
|
|
1158
|
-
_createInstance(options) {
|
|
1159
|
-
const Ctor = this.constructor;
|
|
1160
|
-
return new Ctor([], { comparator: this.comparator, toElementFn: this.toElementFn, ...options ?? {} });
|
|
1161
|
-
}
|
|
1162
|
-
/**
|
|
1163
|
-
* (Protected) Create a like-kind instance seeded by elements.
|
|
1164
|
-
* @remarks Time O(N log N), Space O(N)
|
|
1165
|
-
* @template EM
|
|
1166
|
-
* @template RM
|
|
1167
|
-
* @param [elements] - Iterable of elements or raw values to seed.
|
|
1168
|
-
* @param [options] - Options forwarded to the constructor.
|
|
1169
|
-
* @returns A like-kind heap instance.
|
|
1170
|
-
*/
|
|
1171
|
-
_createLike(elements = [], options) {
|
|
1172
|
-
const Ctor = this.constructor;
|
|
1173
|
-
return new Ctor(elements, options);
|
|
1174
|
-
}
|
|
1175
|
-
/**
|
|
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);
|
|
1585
|
+
const v = thisArg === void 0 ? callback(x, i++, this) : callback.call(thisArg, x, i++, this);
|
|
1586
|
+
out.add(v);
|
|
1587
|
+
}
|
|
1588
|
+
return out;
|
|
1324
1589
|
}
|
|
1590
|
+
_DEFAULT_COMPARATOR = /* @__PURE__ */ __name((a, b) => {
|
|
1591
|
+
if (typeof a === "object" || typeof b === "object") {
|
|
1592
|
+
throw new TypeError(ERR.comparatorRequired("Heap"));
|
|
1593
|
+
}
|
|
1594
|
+
if (a > b) return 1;
|
|
1595
|
+
if (a < b) return -1;
|
|
1596
|
+
return 0;
|
|
1597
|
+
}, "_DEFAULT_COMPARATOR");
|
|
1598
|
+
_comparator = this._DEFAULT_COMPARATOR;
|
|
1325
1599
|
/**
|
|
1326
|
-
*
|
|
1327
|
-
* @
|
|
1328
|
-
* @
|
|
1600
|
+
* Get the comparator used to order elements.
|
|
1601
|
+
* @remarks Time O(1), Space O(1)
|
|
1602
|
+
* @returns Comparator function.
|
|
1329
1603
|
*/
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1604
|
+
get comparator() {
|
|
1605
|
+
return this._comparator;
|
|
1606
|
+
}
|
|
1607
|
+
*_getIterator() {
|
|
1608
|
+
for (const element of this.elements) yield element;
|
|
1609
|
+
}
|
|
1610
|
+
_bubbleUp(index) {
|
|
1611
|
+
const element = this.elements[index];
|
|
1612
|
+
while (index > 0) {
|
|
1613
|
+
const parent = index - 1 >> 1;
|
|
1614
|
+
const parentItem = this.elements[parent];
|
|
1615
|
+
if (this.comparator(parentItem, element) <= 0) break;
|
|
1616
|
+
this.elements[index] = parentItem;
|
|
1617
|
+
index = parent;
|
|
1334
1618
|
}
|
|
1335
|
-
|
|
1619
|
+
this.elements[index] = element;
|
|
1620
|
+
return true;
|
|
1336
1621
|
}
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1622
|
+
_sinkDown(index, halfLength) {
|
|
1623
|
+
const element = this.elements[index];
|
|
1624
|
+
while (index < halfLength) {
|
|
1625
|
+
let left = index << 1 | 1;
|
|
1626
|
+
const right = left + 1;
|
|
1627
|
+
let minItem = this.elements[left];
|
|
1628
|
+
if (right < this.elements.length && this.comparator(minItem, this.elements[right]) > 0) {
|
|
1629
|
+
left = right;
|
|
1630
|
+
minItem = this.elements[right];
|
|
1631
|
+
}
|
|
1632
|
+
if (this.comparator(minItem, element) >= 0) break;
|
|
1633
|
+
this.elements[index] = minItem;
|
|
1634
|
+
index = left;
|
|
1341
1635
|
}
|
|
1342
|
-
|
|
1636
|
+
this.elements[index] = element;
|
|
1637
|
+
return true;
|
|
1343
1638
|
}
|
|
1344
1639
|
/**
|
|
1345
|
-
* Create
|
|
1346
|
-
* @
|
|
1347
|
-
* @param
|
|
1348
|
-
* @returns
|
|
1349
|
-
* @remarks Time O(n), Space O(n)
|
|
1640
|
+
* (Protected) Create an empty instance of the same concrete class.
|
|
1641
|
+
* @remarks Time O(1), Space O(1)
|
|
1642
|
+
* @param [options] - Options to override comparator or toElementFn.
|
|
1643
|
+
* @returns A like-kind empty heap instance.
|
|
1350
1644
|
*/
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
const newList = this._createInstance();
|
|
1355
|
-
for (let i = start; i < end; i++) {
|
|
1356
|
-
newList.push(this.at(i));
|
|
1357
|
-
}
|
|
1358
|
-
return newList;
|
|
1645
|
+
_createInstance(options) {
|
|
1646
|
+
const Ctor = this.constructor;
|
|
1647
|
+
return new Ctor([], { comparator: this.comparator, toElementFn: this.toElementFn, ...options ?? {} });
|
|
1359
1648
|
}
|
|
1360
1649
|
/**
|
|
1361
|
-
*
|
|
1362
|
-
* @
|
|
1363
|
-
* @
|
|
1364
|
-
* @
|
|
1365
|
-
* @
|
|
1366
|
-
* @
|
|
1650
|
+
* (Protected) Create a like-kind instance seeded by elements.
|
|
1651
|
+
* @remarks Time O(N log N), Space O(N)
|
|
1652
|
+
* @template EM
|
|
1653
|
+
* @template RM
|
|
1654
|
+
* @param [elements] - Iterable of elements or raw values to seed.
|
|
1655
|
+
* @param [options] - Options forwarded to the constructor.
|
|
1656
|
+
* @returns A like-kind heap instance.
|
|
1367
1657
|
*/
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1658
|
+
_createLike(elements = [], options) {
|
|
1659
|
+
const Ctor = this.constructor;
|
|
1660
|
+
return new Ctor(elements, options);
|
|
1661
|
+
}
|
|
1662
|
+
/**
|
|
1663
|
+
* (Protected) Spawn an empty like-kind heap instance.
|
|
1664
|
+
* @remarks Time O(1), Space O(1)
|
|
1665
|
+
* @template EM
|
|
1666
|
+
* @template RM
|
|
1667
|
+
* @param [options] - Options forwarded to the constructor.
|
|
1668
|
+
* @returns An empty like-kind heap instance.
|
|
1669
|
+
*/
|
|
1670
|
+
_spawnLike(options) {
|
|
1671
|
+
return this._createLike([], options);
|
|
1378
1672
|
}
|
|
1379
1673
|
};
|
|
1380
1674
|
|
|
@@ -1449,6 +1743,27 @@ var Queue = class _Queue extends LinearBase {
|
|
|
1449
1743
|
|
|
1450
1744
|
|
|
1451
1745
|
|
|
1746
|
+
|
|
1747
|
+
|
|
1748
|
+
|
|
1749
|
+
|
|
1750
|
+
|
|
1751
|
+
|
|
1752
|
+
|
|
1753
|
+
|
|
1754
|
+
|
|
1755
|
+
|
|
1756
|
+
|
|
1757
|
+
|
|
1758
|
+
|
|
1759
|
+
|
|
1760
|
+
|
|
1761
|
+
|
|
1762
|
+
|
|
1763
|
+
|
|
1764
|
+
|
|
1765
|
+
|
|
1766
|
+
|
|
1452
1767
|
* @example
|
|
1453
1768
|
* // Track queue length
|
|
1454
1769
|
* const q = new Queue<number>();
|
|
@@ -1475,6 +1790,27 @@ var Queue = class _Queue extends LinearBase {
|
|
|
1475
1790
|
|
|
1476
1791
|
|
|
1477
1792
|
|
|
1793
|
+
|
|
1794
|
+
|
|
1795
|
+
|
|
1796
|
+
|
|
1797
|
+
|
|
1798
|
+
|
|
1799
|
+
|
|
1800
|
+
|
|
1801
|
+
|
|
1802
|
+
|
|
1803
|
+
|
|
1804
|
+
|
|
1805
|
+
|
|
1806
|
+
|
|
1807
|
+
|
|
1808
|
+
|
|
1809
|
+
|
|
1810
|
+
|
|
1811
|
+
|
|
1812
|
+
|
|
1813
|
+
|
|
1478
1814
|
* @example
|
|
1479
1815
|
* // View the front element
|
|
1480
1816
|
* const q = new Queue<string>(['first', 'second', 'third']);
|
|
@@ -1517,6 +1853,27 @@ var Queue = class _Queue extends LinearBase {
|
|
|
1517
1853
|
|
|
1518
1854
|
|
|
1519
1855
|
|
|
1856
|
+
|
|
1857
|
+
|
|
1858
|
+
|
|
1859
|
+
|
|
1860
|
+
|
|
1861
|
+
|
|
1862
|
+
|
|
1863
|
+
|
|
1864
|
+
|
|
1865
|
+
|
|
1866
|
+
|
|
1867
|
+
|
|
1868
|
+
|
|
1869
|
+
|
|
1870
|
+
|
|
1871
|
+
|
|
1872
|
+
|
|
1873
|
+
|
|
1874
|
+
|
|
1875
|
+
|
|
1876
|
+
|
|
1520
1877
|
* @example
|
|
1521
1878
|
* // Queue for...of iteration and isEmpty check
|
|
1522
1879
|
* const queue = new Queue<string>(['A', 'B', 'C', 'D']);
|
|
@@ -1555,6 +1912,27 @@ var Queue = class _Queue extends LinearBase {
|
|
|
1555
1912
|
|
|
1556
1913
|
|
|
1557
1914
|
|
|
1915
|
+
|
|
1916
|
+
|
|
1917
|
+
|
|
1918
|
+
|
|
1919
|
+
|
|
1920
|
+
|
|
1921
|
+
|
|
1922
|
+
|
|
1923
|
+
|
|
1924
|
+
|
|
1925
|
+
|
|
1926
|
+
|
|
1927
|
+
|
|
1928
|
+
|
|
1929
|
+
|
|
1930
|
+
|
|
1931
|
+
|
|
1932
|
+
|
|
1933
|
+
|
|
1934
|
+
|
|
1935
|
+
|
|
1558
1936
|
* @example
|
|
1559
1937
|
* // basic Queue creation and push operation
|
|
1560
1938
|
* // Create a simple Queue with initial values
|
|
@@ -1600,6 +1978,27 @@ var Queue = class _Queue extends LinearBase {
|
|
|
1600
1978
|
|
|
1601
1979
|
|
|
1602
1980
|
|
|
1981
|
+
|
|
1982
|
+
|
|
1983
|
+
|
|
1984
|
+
|
|
1985
|
+
|
|
1986
|
+
|
|
1987
|
+
|
|
1988
|
+
|
|
1989
|
+
|
|
1990
|
+
|
|
1991
|
+
|
|
1992
|
+
|
|
1993
|
+
|
|
1994
|
+
|
|
1995
|
+
|
|
1996
|
+
|
|
1997
|
+
|
|
1998
|
+
|
|
1999
|
+
|
|
2000
|
+
|
|
2001
|
+
|
|
1603
2002
|
* @example
|
|
1604
2003
|
* // Queue shift and peek operations
|
|
1605
2004
|
* const queue = new Queue<number>([10, 20, 30, 40]);
|
|
@@ -1635,6 +2034,27 @@ var Queue = class _Queue extends LinearBase {
|
|
|
1635
2034
|
|
|
1636
2035
|
|
|
1637
2036
|
|
|
2037
|
+
|
|
2038
|
+
|
|
2039
|
+
|
|
2040
|
+
|
|
2041
|
+
|
|
2042
|
+
|
|
2043
|
+
|
|
2044
|
+
|
|
2045
|
+
|
|
2046
|
+
|
|
2047
|
+
|
|
2048
|
+
|
|
2049
|
+
|
|
2050
|
+
|
|
2051
|
+
|
|
2052
|
+
|
|
2053
|
+
|
|
2054
|
+
|
|
2055
|
+
|
|
2056
|
+
|
|
2057
|
+
|
|
1638
2058
|
* @example
|
|
1639
2059
|
* // Remove specific element
|
|
1640
2060
|
* const q = new Queue<number>([1, 2, 3, 2]);
|
|
@@ -1663,6 +2083,27 @@ var Queue = class _Queue extends LinearBase {
|
|
|
1663
2083
|
|
|
1664
2084
|
|
|
1665
2085
|
|
|
2086
|
+
|
|
2087
|
+
|
|
2088
|
+
|
|
2089
|
+
|
|
2090
|
+
|
|
2091
|
+
|
|
2092
|
+
|
|
2093
|
+
|
|
2094
|
+
|
|
2095
|
+
|
|
2096
|
+
|
|
2097
|
+
|
|
2098
|
+
|
|
2099
|
+
|
|
2100
|
+
|
|
2101
|
+
|
|
2102
|
+
|
|
2103
|
+
|
|
2104
|
+
|
|
2105
|
+
|
|
2106
|
+
|
|
1666
2107
|
* @example
|
|
1667
2108
|
* // Access element by index
|
|
1668
2109
|
* const q = new Queue<string>(['a', 'b', 'c']);
|
|
@@ -1732,6 +2173,27 @@ var Queue = class _Queue extends LinearBase {
|
|
|
1732
2173
|
|
|
1733
2174
|
|
|
1734
2175
|
|
|
2176
|
+
|
|
2177
|
+
|
|
2178
|
+
|
|
2179
|
+
|
|
2180
|
+
|
|
2181
|
+
|
|
2182
|
+
|
|
2183
|
+
|
|
2184
|
+
|
|
2185
|
+
|
|
2186
|
+
|
|
2187
|
+
|
|
2188
|
+
|
|
2189
|
+
|
|
2190
|
+
|
|
2191
|
+
|
|
2192
|
+
|
|
2193
|
+
|
|
2194
|
+
|
|
2195
|
+
|
|
2196
|
+
|
|
1735
2197
|
* @example
|
|
1736
2198
|
* // Remove all elements
|
|
1737
2199
|
* const q = new Queue<number>([1, 2, 3]);
|
|
@@ -1754,6 +2216,27 @@ var Queue = class _Queue extends LinearBase {
|
|
|
1754
2216
|
|
|
1755
2217
|
|
|
1756
2218
|
|
|
2219
|
+
|
|
2220
|
+
|
|
2221
|
+
|
|
2222
|
+
|
|
2223
|
+
|
|
2224
|
+
|
|
2225
|
+
|
|
2226
|
+
|
|
2227
|
+
|
|
2228
|
+
|
|
2229
|
+
|
|
2230
|
+
|
|
2231
|
+
|
|
2232
|
+
|
|
2233
|
+
|
|
2234
|
+
|
|
2235
|
+
|
|
2236
|
+
|
|
2237
|
+
|
|
2238
|
+
|
|
2239
|
+
|
|
1757
2240
|
* @example
|
|
1758
2241
|
* // Reclaim unused memory
|
|
1759
2242
|
* const q = new Queue<number>([1, 2, 3, 4, 5]);
|
|
@@ -1799,6 +2282,27 @@ var Queue = class _Queue extends LinearBase {
|
|
|
1799
2282
|
|
|
1800
2283
|
|
|
1801
2284
|
|
|
2285
|
+
|
|
2286
|
+
|
|
2287
|
+
|
|
2288
|
+
|
|
2289
|
+
|
|
2290
|
+
|
|
2291
|
+
|
|
2292
|
+
|
|
2293
|
+
|
|
2294
|
+
|
|
2295
|
+
|
|
2296
|
+
|
|
2297
|
+
|
|
2298
|
+
|
|
2299
|
+
|
|
2300
|
+
|
|
2301
|
+
|
|
2302
|
+
|
|
2303
|
+
|
|
2304
|
+
|
|
2305
|
+
|
|
1802
2306
|
* @example
|
|
1803
2307
|
* // Create independent copy
|
|
1804
2308
|
* const q = new Queue<number>([1, 2, 3]);
|
|
@@ -1828,6 +2332,27 @@ var Queue = class _Queue extends LinearBase {
|
|
|
1828
2332
|
|
|
1829
2333
|
|
|
1830
2334
|
|
|
2335
|
+
|
|
2336
|
+
|
|
2337
|
+
|
|
2338
|
+
|
|
2339
|
+
|
|
2340
|
+
|
|
2341
|
+
|
|
2342
|
+
|
|
2343
|
+
|
|
2344
|
+
|
|
2345
|
+
|
|
2346
|
+
|
|
2347
|
+
|
|
2348
|
+
|
|
2349
|
+
|
|
2350
|
+
|
|
2351
|
+
|
|
2352
|
+
|
|
2353
|
+
|
|
2354
|
+
|
|
2355
|
+
|
|
1831
2356
|
* @example
|
|
1832
2357
|
* // Filter elements
|
|
1833
2358
|
* const q = new Queue<number>([1, 2, 3, 4, 5]);
|
|
@@ -1861,6 +2386,27 @@ var Queue = class _Queue extends LinearBase {
|
|
|
1861
2386
|
|
|
1862
2387
|
|
|
1863
2388
|
|
|
2389
|
+
|
|
2390
|
+
|
|
2391
|
+
|
|
2392
|
+
|
|
2393
|
+
|
|
2394
|
+
|
|
2395
|
+
|
|
2396
|
+
|
|
2397
|
+
|
|
2398
|
+
|
|
2399
|
+
|
|
2400
|
+
|
|
2401
|
+
|
|
2402
|
+
|
|
2403
|
+
|
|
2404
|
+
|
|
2405
|
+
|
|
2406
|
+
|
|
2407
|
+
|
|
2408
|
+
|
|
2409
|
+
|
|
1864
2410
|
* @example
|
|
1865
2411
|
* // Transform elements
|
|
1866
2412
|
* const q = new Queue<number>([1, 2, 3]);
|
|
@@ -2976,6 +3522,27 @@ var DirectedGraph = class _DirectedGraph extends AbstractGraph {
|
|
|
2976
3522
|
|
|
2977
3523
|
|
|
2978
3524
|
|
|
3525
|
+
|
|
3526
|
+
|
|
3527
|
+
|
|
3528
|
+
|
|
3529
|
+
|
|
3530
|
+
|
|
3531
|
+
|
|
3532
|
+
|
|
3533
|
+
|
|
3534
|
+
|
|
3535
|
+
|
|
3536
|
+
|
|
3537
|
+
|
|
3538
|
+
|
|
3539
|
+
|
|
3540
|
+
|
|
3541
|
+
|
|
3542
|
+
|
|
3543
|
+
|
|
3544
|
+
|
|
3545
|
+
|
|
2979
3546
|
* @example
|
|
2980
3547
|
* // Get edge between vertices
|
|
2981
3548
|
* const g = new DirectedGraph();
|
|
@@ -3040,6 +3607,27 @@ var DirectedGraph = class _DirectedGraph extends AbstractGraph {
|
|
|
3040
3607
|
|
|
3041
3608
|
|
|
3042
3609
|
|
|
3610
|
+
|
|
3611
|
+
|
|
3612
|
+
|
|
3613
|
+
|
|
3614
|
+
|
|
3615
|
+
|
|
3616
|
+
|
|
3617
|
+
|
|
3618
|
+
|
|
3619
|
+
|
|
3620
|
+
|
|
3621
|
+
|
|
3622
|
+
|
|
3623
|
+
|
|
3624
|
+
|
|
3625
|
+
|
|
3626
|
+
|
|
3627
|
+
|
|
3628
|
+
|
|
3629
|
+
|
|
3630
|
+
|
|
3043
3631
|
* @example
|
|
3044
3632
|
* // DirectedGraph deleteEdge and vertex operations
|
|
3045
3633
|
* const graph = new DirectedGraph<string>();
|
|
@@ -3102,6 +3690,27 @@ var DirectedGraph = class _DirectedGraph extends AbstractGraph {
|
|
|
3102
3690
|
|
|
3103
3691
|
|
|
3104
3692
|
|
|
3693
|
+
|
|
3694
|
+
|
|
3695
|
+
|
|
3696
|
+
|
|
3697
|
+
|
|
3698
|
+
|
|
3699
|
+
|
|
3700
|
+
|
|
3701
|
+
|
|
3702
|
+
|
|
3703
|
+
|
|
3704
|
+
|
|
3705
|
+
|
|
3706
|
+
|
|
3707
|
+
|
|
3708
|
+
|
|
3709
|
+
|
|
3710
|
+
|
|
3711
|
+
|
|
3712
|
+
|
|
3713
|
+
|
|
3105
3714
|
* @example
|
|
3106
3715
|
* // Remove a vertex
|
|
3107
3716
|
* const g = new DirectedGraph();
|
|
@@ -3155,6 +3764,27 @@ var DirectedGraph = class _DirectedGraph extends AbstractGraph {
|
|
|
3155
3764
|
|
|
3156
3765
|
|
|
3157
3766
|
|
|
3767
|
+
|
|
3768
|
+
|
|
3769
|
+
|
|
3770
|
+
|
|
3771
|
+
|
|
3772
|
+
|
|
3773
|
+
|
|
3774
|
+
|
|
3775
|
+
|
|
3776
|
+
|
|
3777
|
+
|
|
3778
|
+
|
|
3779
|
+
|
|
3780
|
+
|
|
3781
|
+
|
|
3782
|
+
|
|
3783
|
+
|
|
3784
|
+
|
|
3785
|
+
|
|
3786
|
+
|
|
3787
|
+
|
|
3158
3788
|
* @example
|
|
3159
3789
|
* // Get incoming edges
|
|
3160
3790
|
* const g = new DirectedGraph();
|
|
@@ -3185,6 +3815,27 @@ var DirectedGraph = class _DirectedGraph extends AbstractGraph {
|
|
|
3185
3815
|
|
|
3186
3816
|
|
|
3187
3817
|
|
|
3818
|
+
|
|
3819
|
+
|
|
3820
|
+
|
|
3821
|
+
|
|
3822
|
+
|
|
3823
|
+
|
|
3824
|
+
|
|
3825
|
+
|
|
3826
|
+
|
|
3827
|
+
|
|
3828
|
+
|
|
3829
|
+
|
|
3830
|
+
|
|
3831
|
+
|
|
3832
|
+
|
|
3833
|
+
|
|
3834
|
+
|
|
3835
|
+
|
|
3836
|
+
|
|
3837
|
+
|
|
3838
|
+
|
|
3188
3839
|
* @example
|
|
3189
3840
|
* // Get outgoing edges
|
|
3190
3841
|
* const g = new DirectedGraph();
|
|
@@ -3268,6 +3919,27 @@ var DirectedGraph = class _DirectedGraph extends AbstractGraph {
|
|
|
3268
3919
|
|
|
3269
3920
|
|
|
3270
3921
|
|
|
3922
|
+
|
|
3923
|
+
|
|
3924
|
+
|
|
3925
|
+
|
|
3926
|
+
|
|
3927
|
+
|
|
3928
|
+
|
|
3929
|
+
|
|
3930
|
+
|
|
3931
|
+
|
|
3932
|
+
|
|
3933
|
+
|
|
3934
|
+
|
|
3935
|
+
|
|
3936
|
+
|
|
3937
|
+
|
|
3938
|
+
|
|
3939
|
+
|
|
3940
|
+
|
|
3941
|
+
|
|
3942
|
+
|
|
3271
3943
|
* @example
|
|
3272
3944
|
* // DirectedGraph topologicalSort for task scheduling
|
|
3273
3945
|
* const graph = new DirectedGraph<string>();
|
|
@@ -3332,6 +4004,27 @@ var DirectedGraph = class _DirectedGraph extends AbstractGraph {
|
|
|
3332
4004
|
|
|
3333
4005
|
|
|
3334
4006
|
|
|
4007
|
+
|
|
4008
|
+
|
|
4009
|
+
|
|
4010
|
+
|
|
4011
|
+
|
|
4012
|
+
|
|
4013
|
+
|
|
4014
|
+
|
|
4015
|
+
|
|
4016
|
+
|
|
4017
|
+
|
|
4018
|
+
|
|
4019
|
+
|
|
4020
|
+
|
|
4021
|
+
|
|
4022
|
+
|
|
4023
|
+
|
|
4024
|
+
|
|
4025
|
+
|
|
4026
|
+
|
|
4027
|
+
|
|
3335
4028
|
* @example
|
|
3336
4029
|
* // Get all edges
|
|
3337
4030
|
* const g = new DirectedGraph();
|
|
@@ -3358,6 +4051,27 @@ var DirectedGraph = class _DirectedGraph extends AbstractGraph {
|
|
|
3358
4051
|
|
|
3359
4052
|
|
|
3360
4053
|
|
|
4054
|
+
|
|
4055
|
+
|
|
4056
|
+
|
|
4057
|
+
|
|
4058
|
+
|
|
4059
|
+
|
|
4060
|
+
|
|
4061
|
+
|
|
4062
|
+
|
|
4063
|
+
|
|
4064
|
+
|
|
4065
|
+
|
|
4066
|
+
|
|
4067
|
+
|
|
4068
|
+
|
|
4069
|
+
|
|
4070
|
+
|
|
4071
|
+
|
|
4072
|
+
|
|
4073
|
+
|
|
4074
|
+
|
|
3361
4075
|
* @example
|
|
3362
4076
|
* // Get outgoing neighbors
|
|
3363
4077
|
* const g = new DirectedGraph();
|
|
@@ -3437,6 +4151,27 @@ var DirectedGraph = class _DirectedGraph extends AbstractGraph {
|
|
|
3437
4151
|
|
|
3438
4152
|
|
|
3439
4153
|
|
|
4154
|
+
|
|
4155
|
+
|
|
4156
|
+
|
|
4157
|
+
|
|
4158
|
+
|
|
4159
|
+
|
|
4160
|
+
|
|
4161
|
+
|
|
4162
|
+
|
|
4163
|
+
|
|
4164
|
+
|
|
4165
|
+
|
|
4166
|
+
|
|
4167
|
+
|
|
4168
|
+
|
|
4169
|
+
|
|
4170
|
+
|
|
4171
|
+
|
|
4172
|
+
|
|
4173
|
+
|
|
4174
|
+
|
|
3440
4175
|
* @example
|
|
3441
4176
|
* // Find strongly connected components
|
|
3442
4177
|
* const g = new DirectedGraph();
|
|
@@ -3519,6 +4254,27 @@ var DirectedGraph = class _DirectedGraph extends AbstractGraph {
|
|
|
3519
4254
|
|
|
3520
4255
|
|
|
3521
4256
|
|
|
4257
|
+
|
|
4258
|
+
|
|
4259
|
+
|
|
4260
|
+
|
|
4261
|
+
|
|
4262
|
+
|
|
4263
|
+
|
|
4264
|
+
|
|
4265
|
+
|
|
4266
|
+
|
|
4267
|
+
|
|
4268
|
+
|
|
4269
|
+
|
|
4270
|
+
|
|
4271
|
+
|
|
4272
|
+
|
|
4273
|
+
|
|
4274
|
+
|
|
4275
|
+
|
|
4276
|
+
|
|
4277
|
+
|
|
3522
4278
|
* @example
|
|
3523
4279
|
* // Get strongly connected components
|
|
3524
4280
|
* const g = new DirectedGraph();
|
|
@@ -3667,6 +4423,27 @@ var UndirectedGraph = class _UndirectedGraph extends AbstractGraph {
|
|
|
3667
4423
|
|
|
3668
4424
|
|
|
3669
4425
|
|
|
4426
|
+
|
|
4427
|
+
|
|
4428
|
+
|
|
4429
|
+
|
|
4430
|
+
|
|
4431
|
+
|
|
4432
|
+
|
|
4433
|
+
|
|
4434
|
+
|
|
4435
|
+
|
|
4436
|
+
|
|
4437
|
+
|
|
4438
|
+
|
|
4439
|
+
|
|
4440
|
+
|
|
4441
|
+
|
|
4442
|
+
|
|
4443
|
+
|
|
4444
|
+
|
|
4445
|
+
|
|
4446
|
+
|
|
3670
4447
|
* @example
|
|
3671
4448
|
* // Get edge between vertices
|
|
3672
4449
|
* const g = new UndirectedGraph();
|
|
@@ -3727,6 +4504,27 @@ var UndirectedGraph = class _UndirectedGraph extends AbstractGraph {
|
|
|
3727
4504
|
|
|
3728
4505
|
|
|
3729
4506
|
|
|
4507
|
+
|
|
4508
|
+
|
|
4509
|
+
|
|
4510
|
+
|
|
4511
|
+
|
|
4512
|
+
|
|
4513
|
+
|
|
4514
|
+
|
|
4515
|
+
|
|
4516
|
+
|
|
4517
|
+
|
|
4518
|
+
|
|
4519
|
+
|
|
4520
|
+
|
|
4521
|
+
|
|
4522
|
+
|
|
4523
|
+
|
|
4524
|
+
|
|
4525
|
+
|
|
4526
|
+
|
|
4527
|
+
|
|
3730
4528
|
* @example
|
|
3731
4529
|
* // UndirectedGraph deleteEdge and vertex operations
|
|
3732
4530
|
* const graph = new UndirectedGraph<string>();
|
|
@@ -3787,6 +4585,27 @@ var UndirectedGraph = class _UndirectedGraph extends AbstractGraph {
|
|
|
3787
4585
|
|
|
3788
4586
|
|
|
3789
4587
|
|
|
4588
|
+
|
|
4589
|
+
|
|
4590
|
+
|
|
4591
|
+
|
|
4592
|
+
|
|
4593
|
+
|
|
4594
|
+
|
|
4595
|
+
|
|
4596
|
+
|
|
4597
|
+
|
|
4598
|
+
|
|
4599
|
+
|
|
4600
|
+
|
|
4601
|
+
|
|
4602
|
+
|
|
4603
|
+
|
|
4604
|
+
|
|
4605
|
+
|
|
4606
|
+
|
|
4607
|
+
|
|
4608
|
+
|
|
3790
4609
|
* @example
|
|
3791
4610
|
* // Remove vertex and edges
|
|
3792
4611
|
* const g = new UndirectedGraph();
|
|
@@ -3861,6 +4680,27 @@ var UndirectedGraph = class _UndirectedGraph extends AbstractGraph {
|
|
|
3861
4680
|
|
|
3862
4681
|
|
|
3863
4682
|
|
|
4683
|
+
|
|
4684
|
+
|
|
4685
|
+
|
|
4686
|
+
|
|
4687
|
+
|
|
4688
|
+
|
|
4689
|
+
|
|
4690
|
+
|
|
4691
|
+
|
|
4692
|
+
|
|
4693
|
+
|
|
4694
|
+
|
|
4695
|
+
|
|
4696
|
+
|
|
4697
|
+
|
|
4698
|
+
|
|
4699
|
+
|
|
4700
|
+
|
|
4701
|
+
|
|
4702
|
+
|
|
4703
|
+
|
|
3864
4704
|
* @example
|
|
3865
4705
|
* // Get all edges
|
|
3866
4706
|
* const g = new UndirectedGraph();
|
|
@@ -3891,6 +4731,27 @@ var UndirectedGraph = class _UndirectedGraph extends AbstractGraph {
|
|
|
3891
4731
|
|
|
3892
4732
|
|
|
3893
4733
|
|
|
4734
|
+
|
|
4735
|
+
|
|
4736
|
+
|
|
4737
|
+
|
|
4738
|
+
|
|
4739
|
+
|
|
4740
|
+
|
|
4741
|
+
|
|
4742
|
+
|
|
4743
|
+
|
|
4744
|
+
|
|
4745
|
+
|
|
4746
|
+
|
|
4747
|
+
|
|
4748
|
+
|
|
4749
|
+
|
|
4750
|
+
|
|
4751
|
+
|
|
4752
|
+
|
|
4753
|
+
|
|
4754
|
+
|
|
3894
4755
|
* @example
|
|
3895
4756
|
* // UndirectedGraph connectivity and neighbors
|
|
3896
4757
|
* const graph = new UndirectedGraph<string>();
|
|
@@ -3991,6 +4852,27 @@ var UndirectedGraph = class _UndirectedGraph extends AbstractGraph {
|
|
|
3991
4852
|
|
|
3992
4853
|
|
|
3993
4854
|
|
|
4855
|
+
|
|
4856
|
+
|
|
4857
|
+
|
|
4858
|
+
|
|
4859
|
+
|
|
4860
|
+
|
|
4861
|
+
|
|
4862
|
+
|
|
4863
|
+
|
|
4864
|
+
|
|
4865
|
+
|
|
4866
|
+
|
|
4867
|
+
|
|
4868
|
+
|
|
4869
|
+
|
|
4870
|
+
|
|
4871
|
+
|
|
4872
|
+
|
|
4873
|
+
|
|
4874
|
+
|
|
4875
|
+
|
|
3994
4876
|
* @example
|
|
3995
4877
|
* // Find articulation points and bridges
|
|
3996
4878
|
* const g = new UndirectedGraph();
|
|
@@ -4113,6 +4995,27 @@ var UndirectedGraph = class _UndirectedGraph extends AbstractGraph {
|
|
|
4113
4995
|
|
|
4114
4996
|
|
|
4115
4997
|
|
|
4998
|
+
|
|
4999
|
+
|
|
5000
|
+
|
|
5001
|
+
|
|
5002
|
+
|
|
5003
|
+
|
|
5004
|
+
|
|
5005
|
+
|
|
5006
|
+
|
|
5007
|
+
|
|
5008
|
+
|
|
5009
|
+
|
|
5010
|
+
|
|
5011
|
+
|
|
5012
|
+
|
|
5013
|
+
|
|
5014
|
+
|
|
5015
|
+
|
|
5016
|
+
|
|
5017
|
+
|
|
5018
|
+
|
|
4116
5019
|
* @example
|
|
4117
5020
|
* // Detect cycle
|
|
4118
5021
|
* const g = new UndirectedGraph();
|
|
@@ -4157,6 +5060,27 @@ var UndirectedGraph = class _UndirectedGraph extends AbstractGraph {
|
|
|
4157
5060
|
|
|
4158
5061
|
|
|
4159
5062
|
|
|
5063
|
+
|
|
5064
|
+
|
|
5065
|
+
|
|
5066
|
+
|
|
5067
|
+
|
|
5068
|
+
|
|
5069
|
+
|
|
5070
|
+
|
|
5071
|
+
|
|
5072
|
+
|
|
5073
|
+
|
|
5074
|
+
|
|
5075
|
+
|
|
5076
|
+
|
|
5077
|
+
|
|
5078
|
+
|
|
5079
|
+
|
|
5080
|
+
|
|
5081
|
+
|
|
5082
|
+
|
|
5083
|
+
|
|
4160
5084
|
* @example
|
|
4161
5085
|
* // Find bridge edges
|
|
4162
5086
|
* const g = new UndirectedGraph();
|
|
@@ -4183,6 +5107,27 @@ var UndirectedGraph = class _UndirectedGraph extends AbstractGraph {
|
|
|
4183
5107
|
|
|
4184
5108
|
|
|
4185
5109
|
|
|
5110
|
+
|
|
5111
|
+
|
|
5112
|
+
|
|
5113
|
+
|
|
5114
|
+
|
|
5115
|
+
|
|
5116
|
+
|
|
5117
|
+
|
|
5118
|
+
|
|
5119
|
+
|
|
5120
|
+
|
|
5121
|
+
|
|
5122
|
+
|
|
5123
|
+
|
|
5124
|
+
|
|
5125
|
+
|
|
5126
|
+
|
|
5127
|
+
|
|
5128
|
+
|
|
5129
|
+
|
|
5130
|
+
|
|
4186
5131
|
* @example
|
|
4187
5132
|
* // Find articulation points
|
|
4188
5133
|
* const g = new UndirectedGraph();
|