directed-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 +970 -214
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs-legacy/index.cjs +972 -216
- package/dist/cjs-legacy/index.cjs.map +1 -1
- package/dist/esm/index.mjs +970 -214
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm-legacy/index.mjs +972 -216
- 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/directed-graph-typed.js +967 -211
- package/dist/umd/directed-graph-typed.js.map +1 -1
- package/dist/umd/directed-graph-typed.min.js +1 -1
- package/dist/umd/directed-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
|
@@ -500,6 +500,196 @@ var directedGraphTyped = (() => {
|
|
|
500
500
|
}
|
|
501
501
|
};
|
|
502
502
|
|
|
503
|
+
// src/data-structures/base/linear-base.ts
|
|
504
|
+
var LinearBase = class _LinearBase extends IterableElementBase {
|
|
505
|
+
/**
|
|
506
|
+
* Construct a linear container with runtime options.
|
|
507
|
+
* @param options - `{ maxLen?, ... }` bounds/behavior options.
|
|
508
|
+
* @remarks Time O(1), Space O(1)
|
|
509
|
+
*/
|
|
510
|
+
constructor(options) {
|
|
511
|
+
super(options);
|
|
512
|
+
__publicField(this, "_maxLen", -1);
|
|
513
|
+
if (options) {
|
|
514
|
+
const { maxLen } = options;
|
|
515
|
+
if (typeof maxLen === "number" && maxLen > 0 && maxLen % 1 === 0) this._maxLen = maxLen;
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
/**
|
|
519
|
+
* Upper bound for length (if positive), or `-1` when unbounded.
|
|
520
|
+
* @returns Maximum allowed length.
|
|
521
|
+
* @remarks Time O(1), Space O(1)
|
|
522
|
+
*/
|
|
523
|
+
get maxLen() {
|
|
524
|
+
return this._maxLen;
|
|
525
|
+
}
|
|
526
|
+
/**
|
|
527
|
+
* First index of a value from the left.
|
|
528
|
+
* @param searchElement - Value to match.
|
|
529
|
+
* @param fromIndex - Start position (supports negative index).
|
|
530
|
+
* @returns Index or `-1` if not found.
|
|
531
|
+
* @remarks Time O(n), Space O(1)
|
|
532
|
+
*/
|
|
533
|
+
indexOf(searchElement, fromIndex = 0) {
|
|
534
|
+
if (this.length === 0) return -1;
|
|
535
|
+
if (fromIndex < 0) fromIndex = this.length + fromIndex;
|
|
536
|
+
if (fromIndex < 0) fromIndex = 0;
|
|
537
|
+
for (let i = fromIndex; i < this.length; i++) {
|
|
538
|
+
const element = this.at(i);
|
|
539
|
+
if (element === searchElement) return i;
|
|
540
|
+
}
|
|
541
|
+
return -1;
|
|
542
|
+
}
|
|
543
|
+
/**
|
|
544
|
+
* Last index of a value from the right.
|
|
545
|
+
* @param searchElement - Value to match.
|
|
546
|
+
* @param fromIndex - Start position (supports negative index).
|
|
547
|
+
* @returns Index or `-1` if not found.
|
|
548
|
+
* @remarks Time O(n), Space O(1)
|
|
549
|
+
*/
|
|
550
|
+
lastIndexOf(searchElement, fromIndex = this.length - 1) {
|
|
551
|
+
if (this.length === 0) return -1;
|
|
552
|
+
if (fromIndex >= this.length) fromIndex = this.length - 1;
|
|
553
|
+
if (fromIndex < 0) fromIndex = this.length + fromIndex;
|
|
554
|
+
for (let i = fromIndex; i >= 0; i--) {
|
|
555
|
+
const element = this.at(i);
|
|
556
|
+
if (element === searchElement) return i;
|
|
557
|
+
}
|
|
558
|
+
return -1;
|
|
559
|
+
}
|
|
560
|
+
/**
|
|
561
|
+
* Find the first index matching a predicate.
|
|
562
|
+
* @param predicate - `(element, index, self) => boolean`.
|
|
563
|
+
* @param thisArg - Optional `this` for callback.
|
|
564
|
+
* @returns Index or `-1`.
|
|
565
|
+
* @remarks Time O(n), Space O(1)
|
|
566
|
+
*/
|
|
567
|
+
findIndex(predicate, thisArg) {
|
|
568
|
+
for (let i = 0; i < this.length; i++) {
|
|
569
|
+
const item = this.at(i);
|
|
570
|
+
if (item !== void 0 && predicate.call(thisArg, item, i, this)) return i;
|
|
571
|
+
}
|
|
572
|
+
return -1;
|
|
573
|
+
}
|
|
574
|
+
/**
|
|
575
|
+
* Concatenate elements and/or containers.
|
|
576
|
+
* @param items - Elements or other containers.
|
|
577
|
+
* @returns New container with combined elements (`this` type).
|
|
578
|
+
* @remarks Time O(sum(length)), Space O(sum(length))
|
|
579
|
+
*/
|
|
580
|
+
concat(...items) {
|
|
581
|
+
const newList = this.clone();
|
|
582
|
+
for (const item of items) {
|
|
583
|
+
if (item instanceof _LinearBase) {
|
|
584
|
+
newList.pushMany(item);
|
|
585
|
+
} else {
|
|
586
|
+
newList.push(item);
|
|
587
|
+
}
|
|
588
|
+
}
|
|
589
|
+
return newList;
|
|
590
|
+
}
|
|
591
|
+
/**
|
|
592
|
+
* In-place stable order via array sort semantics.
|
|
593
|
+
* @param compareFn - Comparator `(a, b) => number`.
|
|
594
|
+
* @returns This container.
|
|
595
|
+
* @remarks Time O(n log n), Space O(n) (materializes to array temporarily)
|
|
596
|
+
*/
|
|
597
|
+
sort(compareFn) {
|
|
598
|
+
const arr = this.toArray();
|
|
599
|
+
arr.sort(compareFn);
|
|
600
|
+
this.clear();
|
|
601
|
+
for (const item of arr) this.push(item);
|
|
602
|
+
return this;
|
|
603
|
+
}
|
|
604
|
+
/**
|
|
605
|
+
* Remove and/or insert elements at a position (array-compatible).
|
|
606
|
+
* @param start - Start index (supports negative index).
|
|
607
|
+
* @param deleteCount - How many to remove.
|
|
608
|
+
* @param items - Elements to insert.
|
|
609
|
+
* @returns Removed elements as a new list (`this` type).
|
|
610
|
+
* @remarks Time O(n + m), Space O(min(n, m)) where `m = items.length`
|
|
611
|
+
*/
|
|
612
|
+
splice(start, deleteCount = 0, ...items) {
|
|
613
|
+
const removedList = this._createInstance();
|
|
614
|
+
start = start < 0 ? this.length + start : start;
|
|
615
|
+
start = Math.max(0, Math.min(start, this.length));
|
|
616
|
+
deleteCount = Math.max(0, Math.min(deleteCount, this.length - start));
|
|
617
|
+
for (let i = 0; i < deleteCount; i++) {
|
|
618
|
+
const removed = this.deleteAt(start);
|
|
619
|
+
if (removed !== void 0) {
|
|
620
|
+
removedList.push(removed);
|
|
621
|
+
}
|
|
622
|
+
}
|
|
623
|
+
for (let i = 0; i < items.length; i++) {
|
|
624
|
+
this.addAt(start + i, items[i]);
|
|
625
|
+
}
|
|
626
|
+
return removedList;
|
|
627
|
+
}
|
|
628
|
+
/**
|
|
629
|
+
* Join all elements into a string.
|
|
630
|
+
* @param separator - Separator string.
|
|
631
|
+
* @returns Concatenated string.
|
|
632
|
+
* @remarks Time O(n), Space O(n)
|
|
633
|
+
*/
|
|
634
|
+
join(separator = ",") {
|
|
635
|
+
return this.toArray().join(separator);
|
|
636
|
+
}
|
|
637
|
+
/**
|
|
638
|
+
* Snapshot elements into a reversed array.
|
|
639
|
+
* @returns New reversed array.
|
|
640
|
+
* @remarks Time O(n), Space O(n)
|
|
641
|
+
*/
|
|
642
|
+
toReversedArray() {
|
|
643
|
+
const array = [];
|
|
644
|
+
for (let i = this.length - 1; i >= 0; i--) {
|
|
645
|
+
array.push(this.at(i));
|
|
646
|
+
}
|
|
647
|
+
return array;
|
|
648
|
+
}
|
|
649
|
+
reduceRight(callbackfn, initialValue) {
|
|
650
|
+
let accumulator = initialValue != null ? initialValue : 0;
|
|
651
|
+
for (let i = this.length - 1; i >= 0; i--) {
|
|
652
|
+
accumulator = callbackfn(accumulator, this.at(i), i, this);
|
|
653
|
+
}
|
|
654
|
+
return accumulator;
|
|
655
|
+
}
|
|
656
|
+
/**
|
|
657
|
+
* Create a shallow copy of a subrange.
|
|
658
|
+
* @param start - Inclusive start (supports negative index).
|
|
659
|
+
* @param end - Exclusive end (supports negative index).
|
|
660
|
+
* @returns New list with the range (`this` type).
|
|
661
|
+
* @remarks Time O(n), Space O(n)
|
|
662
|
+
*/
|
|
663
|
+
slice(start = 0, end = this.length) {
|
|
664
|
+
start = start < 0 ? this.length + start : start;
|
|
665
|
+
end = end < 0 ? this.length + end : end;
|
|
666
|
+
const newList = this._createInstance();
|
|
667
|
+
for (let i = start; i < end; i++) {
|
|
668
|
+
newList.push(this.at(i));
|
|
669
|
+
}
|
|
670
|
+
return newList;
|
|
671
|
+
}
|
|
672
|
+
/**
|
|
673
|
+
* Fill a range with a value.
|
|
674
|
+
* @param value - Value to set.
|
|
675
|
+
* @param start - Inclusive start.
|
|
676
|
+
* @param end - Exclusive end.
|
|
677
|
+
* @returns This list.
|
|
678
|
+
* @remarks Time O(n), Space O(1)
|
|
679
|
+
*/
|
|
680
|
+
fill(value, start = 0, end = this.length) {
|
|
681
|
+
start = start < 0 ? this.length + start : start;
|
|
682
|
+
end = end < 0 ? this.length + end : end;
|
|
683
|
+
if (start < 0) start = 0;
|
|
684
|
+
if (end > this.length) end = this.length;
|
|
685
|
+
if (start >= end) return this;
|
|
686
|
+
for (let i = start; i < end; i++) {
|
|
687
|
+
this.setAt(i, value);
|
|
688
|
+
}
|
|
689
|
+
return this;
|
|
690
|
+
}
|
|
691
|
+
};
|
|
692
|
+
|
|
503
693
|
// src/data-structures/heap/heap.ts
|
|
504
694
|
var Heap = class _Heap extends IterableElementBase {
|
|
505
695
|
/**
|
|
@@ -551,6 +741,27 @@ var directedGraphTyped = (() => {
|
|
|
551
741
|
|
|
552
742
|
|
|
553
743
|
|
|
744
|
+
|
|
745
|
+
|
|
746
|
+
|
|
747
|
+
|
|
748
|
+
|
|
749
|
+
|
|
750
|
+
|
|
751
|
+
|
|
752
|
+
|
|
753
|
+
|
|
754
|
+
|
|
755
|
+
|
|
756
|
+
|
|
757
|
+
|
|
758
|
+
|
|
759
|
+
|
|
760
|
+
|
|
761
|
+
|
|
762
|
+
|
|
763
|
+
|
|
764
|
+
|
|
554
765
|
* @example
|
|
555
766
|
* // Track heap capacity
|
|
556
767
|
* const heap = new Heap<number>();
|
|
@@ -614,6 +825,27 @@ var directedGraphTyped = (() => {
|
|
|
614
825
|
|
|
615
826
|
|
|
616
827
|
|
|
828
|
+
|
|
829
|
+
|
|
830
|
+
|
|
831
|
+
|
|
832
|
+
|
|
833
|
+
|
|
834
|
+
|
|
835
|
+
|
|
836
|
+
|
|
837
|
+
|
|
838
|
+
|
|
839
|
+
|
|
840
|
+
|
|
841
|
+
|
|
842
|
+
|
|
843
|
+
|
|
844
|
+
|
|
845
|
+
|
|
846
|
+
|
|
847
|
+
|
|
848
|
+
|
|
617
849
|
* @example
|
|
618
850
|
* // basic Heap creation and add operation
|
|
619
851
|
* // Create a min heap (default)
|
|
@@ -647,6 +879,27 @@ var directedGraphTyped = (() => {
|
|
|
647
879
|
|
|
648
880
|
|
|
649
881
|
|
|
882
|
+
|
|
883
|
+
|
|
884
|
+
|
|
885
|
+
|
|
886
|
+
|
|
887
|
+
|
|
888
|
+
|
|
889
|
+
|
|
890
|
+
|
|
891
|
+
|
|
892
|
+
|
|
893
|
+
|
|
894
|
+
|
|
895
|
+
|
|
896
|
+
|
|
897
|
+
|
|
898
|
+
|
|
899
|
+
|
|
900
|
+
|
|
901
|
+
|
|
902
|
+
|
|
650
903
|
* @example
|
|
651
904
|
* // Add multiple elements
|
|
652
905
|
* const heap = new Heap<number>([], { comparator: (a, b) => a - b });
|
|
@@ -682,6 +935,27 @@ var directedGraphTyped = (() => {
|
|
|
682
935
|
|
|
683
936
|
|
|
684
937
|
|
|
938
|
+
|
|
939
|
+
|
|
940
|
+
|
|
941
|
+
|
|
942
|
+
|
|
943
|
+
|
|
944
|
+
|
|
945
|
+
|
|
946
|
+
|
|
947
|
+
|
|
948
|
+
|
|
949
|
+
|
|
950
|
+
|
|
951
|
+
|
|
952
|
+
|
|
953
|
+
|
|
954
|
+
|
|
955
|
+
|
|
956
|
+
|
|
957
|
+
|
|
958
|
+
|
|
685
959
|
* @example
|
|
686
960
|
* // Heap with custom comparator (MaxHeap behavior)
|
|
687
961
|
* interface Task {
|
|
@@ -733,6 +1007,27 @@ var directedGraphTyped = (() => {
|
|
|
733
1007
|
|
|
734
1008
|
|
|
735
1009
|
|
|
1010
|
+
|
|
1011
|
+
|
|
1012
|
+
|
|
1013
|
+
|
|
1014
|
+
|
|
1015
|
+
|
|
1016
|
+
|
|
1017
|
+
|
|
1018
|
+
|
|
1019
|
+
|
|
1020
|
+
|
|
1021
|
+
|
|
1022
|
+
|
|
1023
|
+
|
|
1024
|
+
|
|
1025
|
+
|
|
1026
|
+
|
|
1027
|
+
|
|
1028
|
+
|
|
1029
|
+
|
|
1030
|
+
|
|
736
1031
|
* @example
|
|
737
1032
|
* // Heap for event processing with priority
|
|
738
1033
|
* interface Event {
|
|
@@ -809,6 +1104,27 @@ var directedGraphTyped = (() => {
|
|
|
809
1104
|
|
|
810
1105
|
|
|
811
1106
|
|
|
1107
|
+
|
|
1108
|
+
|
|
1109
|
+
|
|
1110
|
+
|
|
1111
|
+
|
|
1112
|
+
|
|
1113
|
+
|
|
1114
|
+
|
|
1115
|
+
|
|
1116
|
+
|
|
1117
|
+
|
|
1118
|
+
|
|
1119
|
+
|
|
1120
|
+
|
|
1121
|
+
|
|
1122
|
+
|
|
1123
|
+
|
|
1124
|
+
|
|
1125
|
+
|
|
1126
|
+
|
|
1127
|
+
|
|
812
1128
|
* @example
|
|
813
1129
|
* // Check if heap is empty
|
|
814
1130
|
* const heap = new Heap<number>([], { comparator: (a, b) => a - b });
|
|
@@ -832,6 +1148,27 @@ var directedGraphTyped = (() => {
|
|
|
832
1148
|
|
|
833
1149
|
|
|
834
1150
|
|
|
1151
|
+
|
|
1152
|
+
|
|
1153
|
+
|
|
1154
|
+
|
|
1155
|
+
|
|
1156
|
+
|
|
1157
|
+
|
|
1158
|
+
|
|
1159
|
+
|
|
1160
|
+
|
|
1161
|
+
|
|
1162
|
+
|
|
1163
|
+
|
|
1164
|
+
|
|
1165
|
+
|
|
1166
|
+
|
|
1167
|
+
|
|
1168
|
+
|
|
1169
|
+
|
|
1170
|
+
|
|
1171
|
+
|
|
835
1172
|
* @example
|
|
836
1173
|
* // Remove all elements
|
|
837
1174
|
* const heap = new Heap<number>([1, 2, 3], { comparator: (a, b) => a - b });
|
|
@@ -858,6 +1195,27 @@ var directedGraphTyped = (() => {
|
|
|
858
1195
|
* @returns True if found.
|
|
859
1196
|
|
|
860
1197
|
|
|
1198
|
+
|
|
1199
|
+
|
|
1200
|
+
|
|
1201
|
+
|
|
1202
|
+
|
|
1203
|
+
|
|
1204
|
+
|
|
1205
|
+
|
|
1206
|
+
|
|
1207
|
+
|
|
1208
|
+
|
|
1209
|
+
|
|
1210
|
+
|
|
1211
|
+
|
|
1212
|
+
|
|
1213
|
+
|
|
1214
|
+
|
|
1215
|
+
|
|
1216
|
+
|
|
1217
|
+
|
|
1218
|
+
|
|
861
1219
|
* @example
|
|
862
1220
|
* // Check element existence
|
|
863
1221
|
* const heap = new Heap<number>([3, 1, 2], { comparator: (a, b) => a - b });
|
|
@@ -881,6 +1239,27 @@ var directedGraphTyped = (() => {
|
|
|
881
1239
|
|
|
882
1240
|
|
|
883
1241
|
|
|
1242
|
+
|
|
1243
|
+
|
|
1244
|
+
|
|
1245
|
+
|
|
1246
|
+
|
|
1247
|
+
|
|
1248
|
+
|
|
1249
|
+
|
|
1250
|
+
|
|
1251
|
+
|
|
1252
|
+
|
|
1253
|
+
|
|
1254
|
+
|
|
1255
|
+
|
|
1256
|
+
|
|
1257
|
+
|
|
1258
|
+
|
|
1259
|
+
|
|
1260
|
+
|
|
1261
|
+
|
|
1262
|
+
|
|
884
1263
|
* @example
|
|
885
1264
|
* // Remove specific element
|
|
886
1265
|
* const heap = new Heap<number>([3, 1, 4, 1, 5], { comparator: (a, b) => a - b });
|
|
@@ -950,6 +1329,27 @@ var directedGraphTyped = (() => {
|
|
|
950
1329
|
* @returns Array of visited elements.
|
|
951
1330
|
|
|
952
1331
|
|
|
1332
|
+
|
|
1333
|
+
|
|
1334
|
+
|
|
1335
|
+
|
|
1336
|
+
|
|
1337
|
+
|
|
1338
|
+
|
|
1339
|
+
|
|
1340
|
+
|
|
1341
|
+
|
|
1342
|
+
|
|
1343
|
+
|
|
1344
|
+
|
|
1345
|
+
|
|
1346
|
+
|
|
1347
|
+
|
|
1348
|
+
|
|
1349
|
+
|
|
1350
|
+
|
|
1351
|
+
|
|
1352
|
+
|
|
953
1353
|
* @example
|
|
954
1354
|
* // Depth-first traversal
|
|
955
1355
|
* const heap = new Heap<number>([3, 1, 2], { comparator: (a, b) => a - b });
|
|
@@ -1006,6 +1406,27 @@ var directedGraphTyped = (() => {
|
|
|
1006
1406
|
|
|
1007
1407
|
|
|
1008
1408
|
|
|
1409
|
+
|
|
1410
|
+
|
|
1411
|
+
|
|
1412
|
+
|
|
1413
|
+
|
|
1414
|
+
|
|
1415
|
+
|
|
1416
|
+
|
|
1417
|
+
|
|
1418
|
+
|
|
1419
|
+
|
|
1420
|
+
|
|
1421
|
+
|
|
1422
|
+
|
|
1423
|
+
|
|
1424
|
+
|
|
1425
|
+
|
|
1426
|
+
|
|
1427
|
+
|
|
1428
|
+
|
|
1429
|
+
|
|
1009
1430
|
* @example
|
|
1010
1431
|
* // Sort elements using heap
|
|
1011
1432
|
* const heap = new Heap<number>([5, 1, 3, 2, 4]);
|
|
@@ -1035,6 +1456,27 @@ var directedGraphTyped = (() => {
|
|
|
1035
1456
|
|
|
1036
1457
|
|
|
1037
1458
|
|
|
1459
|
+
|
|
1460
|
+
|
|
1461
|
+
|
|
1462
|
+
|
|
1463
|
+
|
|
1464
|
+
|
|
1465
|
+
|
|
1466
|
+
|
|
1467
|
+
|
|
1468
|
+
|
|
1469
|
+
|
|
1470
|
+
|
|
1471
|
+
|
|
1472
|
+
|
|
1473
|
+
|
|
1474
|
+
|
|
1475
|
+
|
|
1476
|
+
|
|
1477
|
+
|
|
1478
|
+
|
|
1479
|
+
|
|
1038
1480
|
* @example
|
|
1039
1481
|
* // Create independent copy
|
|
1040
1482
|
* const heap = new Heap<number>([3, 1, 4], { comparator: (a, b) => a - b });
|
|
@@ -1063,6 +1505,27 @@ var directedGraphTyped = (() => {
|
|
|
1063
1505
|
|
|
1064
1506
|
|
|
1065
1507
|
|
|
1508
|
+
|
|
1509
|
+
|
|
1510
|
+
|
|
1511
|
+
|
|
1512
|
+
|
|
1513
|
+
|
|
1514
|
+
|
|
1515
|
+
|
|
1516
|
+
|
|
1517
|
+
|
|
1518
|
+
|
|
1519
|
+
|
|
1520
|
+
|
|
1521
|
+
|
|
1522
|
+
|
|
1523
|
+
|
|
1524
|
+
|
|
1525
|
+
|
|
1526
|
+
|
|
1527
|
+
|
|
1528
|
+
|
|
1066
1529
|
* @example
|
|
1067
1530
|
* // Filter elements
|
|
1068
1531
|
* const heap = new Heap<number>([1, 2, 3, 4, 5], { comparator: (a, b) => a - b });
|
|
@@ -1098,6 +1561,27 @@ var directedGraphTyped = (() => {
|
|
|
1098
1561
|
|
|
1099
1562
|
|
|
1100
1563
|
|
|
1564
|
+
|
|
1565
|
+
|
|
1566
|
+
|
|
1567
|
+
|
|
1568
|
+
|
|
1569
|
+
|
|
1570
|
+
|
|
1571
|
+
|
|
1572
|
+
|
|
1573
|
+
|
|
1574
|
+
|
|
1575
|
+
|
|
1576
|
+
|
|
1577
|
+
|
|
1578
|
+
|
|
1579
|
+
|
|
1580
|
+
|
|
1581
|
+
|
|
1582
|
+
|
|
1583
|
+
|
|
1584
|
+
|
|
1101
1585
|
* @example
|
|
1102
1586
|
* // Transform elements
|
|
1103
1587
|
* const heap = new Heap<number>([1, 2, 3], { comparator: (a, b) => a - b });
|
|
@@ -1177,223 +1661,33 @@ var directedGraphTyped = (() => {
|
|
|
1177
1661
|
* @param [options] - Options to override comparator or toElementFn.
|
|
1178
1662
|
* @returns A like-kind empty heap instance.
|
|
1179
1663
|
*/
|
|
1180
|
-
_createInstance(options) {
|
|
1181
|
-
const Ctor = this.constructor;
|
|
1182
|
-
return new Ctor([], { comparator: this.comparator, toElementFn: this.toElementFn, ...options != null ? options : {} });
|
|
1183
|
-
}
|
|
1184
|
-
/**
|
|
1185
|
-
* (Protected) Create a like-kind instance seeded by elements.
|
|
1186
|
-
* @remarks Time O(N log N), Space O(N)
|
|
1187
|
-
* @template EM
|
|
1188
|
-
* @template RM
|
|
1189
|
-
* @param [elements] - Iterable of elements or raw values to seed.
|
|
1190
|
-
* @param [options] - Options forwarded to the constructor.
|
|
1191
|
-
* @returns A like-kind heap instance.
|
|
1192
|
-
*/
|
|
1193
|
-
_createLike(elements = [], options) {
|
|
1194
|
-
const Ctor = this.constructor;
|
|
1195
|
-
return new Ctor(elements, options);
|
|
1196
|
-
}
|
|
1197
|
-
/**
|
|
1198
|
-
* (Protected) Spawn an empty like-kind heap instance.
|
|
1199
|
-
* @remarks Time O(1), Space O(1)
|
|
1200
|
-
* @template EM
|
|
1201
|
-
* @template RM
|
|
1202
|
-
* @param [options] - Options forwarded to the constructor.
|
|
1203
|
-
* @returns An empty like-kind heap instance.
|
|
1204
|
-
*/
|
|
1205
|
-
_spawnLike(options) {
|
|
1206
|
-
return this._createLike([], options);
|
|
1207
|
-
}
|
|
1208
|
-
};
|
|
1209
|
-
|
|
1210
|
-
// src/data-structures/base/linear-base.ts
|
|
1211
|
-
var LinearBase = class _LinearBase extends IterableElementBase {
|
|
1212
|
-
/**
|
|
1213
|
-
* Construct a linear container with runtime options.
|
|
1214
|
-
* @param options - `{ maxLen?, ... }` bounds/behavior options.
|
|
1215
|
-
* @remarks Time O(1), Space O(1)
|
|
1216
|
-
*/
|
|
1217
|
-
constructor(options) {
|
|
1218
|
-
super(options);
|
|
1219
|
-
__publicField(this, "_maxLen", -1);
|
|
1220
|
-
if (options) {
|
|
1221
|
-
const { maxLen } = options;
|
|
1222
|
-
if (typeof maxLen === "number" && maxLen > 0 && maxLen % 1 === 0) this._maxLen = maxLen;
|
|
1223
|
-
}
|
|
1224
|
-
}
|
|
1225
|
-
/**
|
|
1226
|
-
* Upper bound for length (if positive), or `-1` when unbounded.
|
|
1227
|
-
* @returns Maximum allowed length.
|
|
1228
|
-
* @remarks Time O(1), Space O(1)
|
|
1229
|
-
*/
|
|
1230
|
-
get maxLen() {
|
|
1231
|
-
return this._maxLen;
|
|
1232
|
-
}
|
|
1233
|
-
/**
|
|
1234
|
-
* First index of a value from the left.
|
|
1235
|
-
* @param searchElement - Value to match.
|
|
1236
|
-
* @param fromIndex - Start position (supports negative index).
|
|
1237
|
-
* @returns Index or `-1` if not found.
|
|
1238
|
-
* @remarks Time O(n), Space O(1)
|
|
1239
|
-
*/
|
|
1240
|
-
indexOf(searchElement, fromIndex = 0) {
|
|
1241
|
-
if (this.length === 0) return -1;
|
|
1242
|
-
if (fromIndex < 0) fromIndex = this.length + fromIndex;
|
|
1243
|
-
if (fromIndex < 0) fromIndex = 0;
|
|
1244
|
-
for (let i = fromIndex; i < this.length; i++) {
|
|
1245
|
-
const element = this.at(i);
|
|
1246
|
-
if (element === searchElement) return i;
|
|
1247
|
-
}
|
|
1248
|
-
return -1;
|
|
1249
|
-
}
|
|
1250
|
-
/**
|
|
1251
|
-
* Last index of a value from the right.
|
|
1252
|
-
* @param searchElement - Value to match.
|
|
1253
|
-
* @param fromIndex - Start position (supports negative index).
|
|
1254
|
-
* @returns Index or `-1` if not found.
|
|
1255
|
-
* @remarks Time O(n), Space O(1)
|
|
1256
|
-
*/
|
|
1257
|
-
lastIndexOf(searchElement, fromIndex = this.length - 1) {
|
|
1258
|
-
if (this.length === 0) return -1;
|
|
1259
|
-
if (fromIndex >= this.length) fromIndex = this.length - 1;
|
|
1260
|
-
if (fromIndex < 0) fromIndex = this.length + fromIndex;
|
|
1261
|
-
for (let i = fromIndex; i >= 0; i--) {
|
|
1262
|
-
const element = this.at(i);
|
|
1263
|
-
if (element === searchElement) return i;
|
|
1264
|
-
}
|
|
1265
|
-
return -1;
|
|
1266
|
-
}
|
|
1267
|
-
/**
|
|
1268
|
-
* Find the first index matching a predicate.
|
|
1269
|
-
* @param predicate - `(element, index, self) => boolean`.
|
|
1270
|
-
* @param thisArg - Optional `this` for callback.
|
|
1271
|
-
* @returns Index or `-1`.
|
|
1272
|
-
* @remarks Time O(n), Space O(1)
|
|
1273
|
-
*/
|
|
1274
|
-
findIndex(predicate, thisArg) {
|
|
1275
|
-
for (let i = 0; i < this.length; i++) {
|
|
1276
|
-
const item = this.at(i);
|
|
1277
|
-
if (item !== void 0 && predicate.call(thisArg, item, i, this)) return i;
|
|
1278
|
-
}
|
|
1279
|
-
return -1;
|
|
1280
|
-
}
|
|
1281
|
-
/**
|
|
1282
|
-
* Concatenate elements and/or containers.
|
|
1283
|
-
* @param items - Elements or other containers.
|
|
1284
|
-
* @returns New container with combined elements (`this` type).
|
|
1285
|
-
* @remarks Time O(sum(length)), Space O(sum(length))
|
|
1286
|
-
*/
|
|
1287
|
-
concat(...items) {
|
|
1288
|
-
const newList = this.clone();
|
|
1289
|
-
for (const item of items) {
|
|
1290
|
-
if (item instanceof _LinearBase) {
|
|
1291
|
-
newList.pushMany(item);
|
|
1292
|
-
} else {
|
|
1293
|
-
newList.push(item);
|
|
1294
|
-
}
|
|
1295
|
-
}
|
|
1296
|
-
return newList;
|
|
1297
|
-
}
|
|
1298
|
-
/**
|
|
1299
|
-
* In-place stable order via array sort semantics.
|
|
1300
|
-
* @param compareFn - Comparator `(a, b) => number`.
|
|
1301
|
-
* @returns This container.
|
|
1302
|
-
* @remarks Time O(n log n), Space O(n) (materializes to array temporarily)
|
|
1303
|
-
*/
|
|
1304
|
-
sort(compareFn) {
|
|
1305
|
-
const arr = this.toArray();
|
|
1306
|
-
arr.sort(compareFn);
|
|
1307
|
-
this.clear();
|
|
1308
|
-
for (const item of arr) this.push(item);
|
|
1309
|
-
return this;
|
|
1310
|
-
}
|
|
1311
|
-
/**
|
|
1312
|
-
* Remove and/or insert elements at a position (array-compatible).
|
|
1313
|
-
* @param start - Start index (supports negative index).
|
|
1314
|
-
* @param deleteCount - How many to remove.
|
|
1315
|
-
* @param items - Elements to insert.
|
|
1316
|
-
* @returns Removed elements as a new list (`this` type).
|
|
1317
|
-
* @remarks Time O(n + m), Space O(min(n, m)) where `m = items.length`
|
|
1318
|
-
*/
|
|
1319
|
-
splice(start, deleteCount = 0, ...items) {
|
|
1320
|
-
const removedList = this._createInstance();
|
|
1321
|
-
start = start < 0 ? this.length + start : start;
|
|
1322
|
-
start = Math.max(0, Math.min(start, this.length));
|
|
1323
|
-
deleteCount = Math.max(0, Math.min(deleteCount, this.length - start));
|
|
1324
|
-
for (let i = 0; i < deleteCount; i++) {
|
|
1325
|
-
const removed = this.deleteAt(start);
|
|
1326
|
-
if (removed !== void 0) {
|
|
1327
|
-
removedList.push(removed);
|
|
1328
|
-
}
|
|
1329
|
-
}
|
|
1330
|
-
for (let i = 0; i < items.length; i++) {
|
|
1331
|
-
this.addAt(start + i, items[i]);
|
|
1332
|
-
}
|
|
1333
|
-
return removedList;
|
|
1334
|
-
}
|
|
1335
|
-
/**
|
|
1336
|
-
* Join all elements into a string.
|
|
1337
|
-
* @param separator - Separator string.
|
|
1338
|
-
* @returns Concatenated string.
|
|
1339
|
-
* @remarks Time O(n), Space O(n)
|
|
1340
|
-
*/
|
|
1341
|
-
join(separator = ",") {
|
|
1342
|
-
return this.toArray().join(separator);
|
|
1343
|
-
}
|
|
1344
|
-
/**
|
|
1345
|
-
* Snapshot elements into a reversed array.
|
|
1346
|
-
* @returns New reversed array.
|
|
1347
|
-
* @remarks Time O(n), Space O(n)
|
|
1348
|
-
*/
|
|
1349
|
-
toReversedArray() {
|
|
1350
|
-
const array = [];
|
|
1351
|
-
for (let i = this.length - 1; i >= 0; i--) {
|
|
1352
|
-
array.push(this.at(i));
|
|
1353
|
-
}
|
|
1354
|
-
return array;
|
|
1355
|
-
}
|
|
1356
|
-
reduceRight(callbackfn, initialValue) {
|
|
1357
|
-
let accumulator = initialValue != null ? initialValue : 0;
|
|
1358
|
-
for (let i = this.length - 1; i >= 0; i--) {
|
|
1359
|
-
accumulator = callbackfn(accumulator, this.at(i), i, this);
|
|
1360
|
-
}
|
|
1361
|
-
return accumulator;
|
|
1664
|
+
_createInstance(options) {
|
|
1665
|
+
const Ctor = this.constructor;
|
|
1666
|
+
return new Ctor([], { comparator: this.comparator, toElementFn: this.toElementFn, ...options != null ? options : {} });
|
|
1362
1667
|
}
|
|
1363
1668
|
/**
|
|
1364
|
-
* Create a
|
|
1365
|
-
* @
|
|
1366
|
-
* @
|
|
1367
|
-
* @
|
|
1368
|
-
* @
|
|
1669
|
+
* (Protected) Create a like-kind instance seeded by elements.
|
|
1670
|
+
* @remarks Time O(N log N), Space O(N)
|
|
1671
|
+
* @template EM
|
|
1672
|
+
* @template RM
|
|
1673
|
+
* @param [elements] - Iterable of elements or raw values to seed.
|
|
1674
|
+
* @param [options] - Options forwarded to the constructor.
|
|
1675
|
+
* @returns A like-kind heap instance.
|
|
1369
1676
|
*/
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
const newList = this._createInstance();
|
|
1374
|
-
for (let i = start; i < end; i++) {
|
|
1375
|
-
newList.push(this.at(i));
|
|
1376
|
-
}
|
|
1377
|
-
return newList;
|
|
1677
|
+
_createLike(elements = [], options) {
|
|
1678
|
+
const Ctor = this.constructor;
|
|
1679
|
+
return new Ctor(elements, options);
|
|
1378
1680
|
}
|
|
1379
1681
|
/**
|
|
1380
|
-
*
|
|
1381
|
-
* @
|
|
1382
|
-
* @
|
|
1383
|
-
* @
|
|
1384
|
-
* @
|
|
1385
|
-
* @
|
|
1682
|
+
* (Protected) Spawn an empty like-kind heap instance.
|
|
1683
|
+
* @remarks Time O(1), Space O(1)
|
|
1684
|
+
* @template EM
|
|
1685
|
+
* @template RM
|
|
1686
|
+
* @param [options] - Options forwarded to the constructor.
|
|
1687
|
+
* @returns An empty like-kind heap instance.
|
|
1386
1688
|
*/
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
end = end < 0 ? this.length + end : end;
|
|
1390
|
-
if (start < 0) start = 0;
|
|
1391
|
-
if (end > this.length) end = this.length;
|
|
1392
|
-
if (start >= end) return this;
|
|
1393
|
-
for (let i = start; i < end; i++) {
|
|
1394
|
-
this.setAt(i, value);
|
|
1395
|
-
}
|
|
1396
|
-
return this;
|
|
1689
|
+
_spawnLike(options) {
|
|
1690
|
+
return this._createLike([], options);
|
|
1397
1691
|
}
|
|
1398
1692
|
};
|
|
1399
1693
|
|
|
@@ -1465,6 +1759,27 @@ var directedGraphTyped = (() => {
|
|
|
1465
1759
|
|
|
1466
1760
|
|
|
1467
1761
|
|
|
1762
|
+
|
|
1763
|
+
|
|
1764
|
+
|
|
1765
|
+
|
|
1766
|
+
|
|
1767
|
+
|
|
1768
|
+
|
|
1769
|
+
|
|
1770
|
+
|
|
1771
|
+
|
|
1772
|
+
|
|
1773
|
+
|
|
1774
|
+
|
|
1775
|
+
|
|
1776
|
+
|
|
1777
|
+
|
|
1778
|
+
|
|
1779
|
+
|
|
1780
|
+
|
|
1781
|
+
|
|
1782
|
+
|
|
1468
1783
|
* @example
|
|
1469
1784
|
* // Track queue length
|
|
1470
1785
|
* const q = new Queue<number>();
|
|
@@ -1491,6 +1806,27 @@ var directedGraphTyped = (() => {
|
|
|
1491
1806
|
|
|
1492
1807
|
|
|
1493
1808
|
|
|
1809
|
+
|
|
1810
|
+
|
|
1811
|
+
|
|
1812
|
+
|
|
1813
|
+
|
|
1814
|
+
|
|
1815
|
+
|
|
1816
|
+
|
|
1817
|
+
|
|
1818
|
+
|
|
1819
|
+
|
|
1820
|
+
|
|
1821
|
+
|
|
1822
|
+
|
|
1823
|
+
|
|
1824
|
+
|
|
1825
|
+
|
|
1826
|
+
|
|
1827
|
+
|
|
1828
|
+
|
|
1829
|
+
|
|
1494
1830
|
* @example
|
|
1495
1831
|
* // View the front element
|
|
1496
1832
|
* const q = new Queue<string>(['first', 'second', 'third']);
|
|
@@ -1533,6 +1869,27 @@ var directedGraphTyped = (() => {
|
|
|
1533
1869
|
|
|
1534
1870
|
|
|
1535
1871
|
|
|
1872
|
+
|
|
1873
|
+
|
|
1874
|
+
|
|
1875
|
+
|
|
1876
|
+
|
|
1877
|
+
|
|
1878
|
+
|
|
1879
|
+
|
|
1880
|
+
|
|
1881
|
+
|
|
1882
|
+
|
|
1883
|
+
|
|
1884
|
+
|
|
1885
|
+
|
|
1886
|
+
|
|
1887
|
+
|
|
1888
|
+
|
|
1889
|
+
|
|
1890
|
+
|
|
1891
|
+
|
|
1892
|
+
|
|
1536
1893
|
* @example
|
|
1537
1894
|
* // Queue for...of iteration and isEmpty check
|
|
1538
1895
|
* const queue = new Queue<string>(['A', 'B', 'C', 'D']);
|
|
@@ -1571,6 +1928,27 @@ var directedGraphTyped = (() => {
|
|
|
1571
1928
|
|
|
1572
1929
|
|
|
1573
1930
|
|
|
1931
|
+
|
|
1932
|
+
|
|
1933
|
+
|
|
1934
|
+
|
|
1935
|
+
|
|
1936
|
+
|
|
1937
|
+
|
|
1938
|
+
|
|
1939
|
+
|
|
1940
|
+
|
|
1941
|
+
|
|
1942
|
+
|
|
1943
|
+
|
|
1944
|
+
|
|
1945
|
+
|
|
1946
|
+
|
|
1947
|
+
|
|
1948
|
+
|
|
1949
|
+
|
|
1950
|
+
|
|
1951
|
+
|
|
1574
1952
|
* @example
|
|
1575
1953
|
* // basic Queue creation and push operation
|
|
1576
1954
|
* // Create a simple Queue with initial values
|
|
@@ -1616,6 +1994,27 @@ var directedGraphTyped = (() => {
|
|
|
1616
1994
|
|
|
1617
1995
|
|
|
1618
1996
|
|
|
1997
|
+
|
|
1998
|
+
|
|
1999
|
+
|
|
2000
|
+
|
|
2001
|
+
|
|
2002
|
+
|
|
2003
|
+
|
|
2004
|
+
|
|
2005
|
+
|
|
2006
|
+
|
|
2007
|
+
|
|
2008
|
+
|
|
2009
|
+
|
|
2010
|
+
|
|
2011
|
+
|
|
2012
|
+
|
|
2013
|
+
|
|
2014
|
+
|
|
2015
|
+
|
|
2016
|
+
|
|
2017
|
+
|
|
1619
2018
|
* @example
|
|
1620
2019
|
* // Queue shift and peek operations
|
|
1621
2020
|
* const queue = new Queue<number>([10, 20, 30, 40]);
|
|
@@ -1651,6 +2050,27 @@ var directedGraphTyped = (() => {
|
|
|
1651
2050
|
|
|
1652
2051
|
|
|
1653
2052
|
|
|
2053
|
+
|
|
2054
|
+
|
|
2055
|
+
|
|
2056
|
+
|
|
2057
|
+
|
|
2058
|
+
|
|
2059
|
+
|
|
2060
|
+
|
|
2061
|
+
|
|
2062
|
+
|
|
2063
|
+
|
|
2064
|
+
|
|
2065
|
+
|
|
2066
|
+
|
|
2067
|
+
|
|
2068
|
+
|
|
2069
|
+
|
|
2070
|
+
|
|
2071
|
+
|
|
2072
|
+
|
|
2073
|
+
|
|
1654
2074
|
* @example
|
|
1655
2075
|
* // Remove specific element
|
|
1656
2076
|
* const q = new Queue<number>([1, 2, 3, 2]);
|
|
@@ -1679,6 +2099,27 @@ var directedGraphTyped = (() => {
|
|
|
1679
2099
|
|
|
1680
2100
|
|
|
1681
2101
|
|
|
2102
|
+
|
|
2103
|
+
|
|
2104
|
+
|
|
2105
|
+
|
|
2106
|
+
|
|
2107
|
+
|
|
2108
|
+
|
|
2109
|
+
|
|
2110
|
+
|
|
2111
|
+
|
|
2112
|
+
|
|
2113
|
+
|
|
2114
|
+
|
|
2115
|
+
|
|
2116
|
+
|
|
2117
|
+
|
|
2118
|
+
|
|
2119
|
+
|
|
2120
|
+
|
|
2121
|
+
|
|
2122
|
+
|
|
1682
2123
|
* @example
|
|
1683
2124
|
* // Access element by index
|
|
1684
2125
|
* const q = new Queue<string>(['a', 'b', 'c']);
|
|
@@ -1748,6 +2189,27 @@ var directedGraphTyped = (() => {
|
|
|
1748
2189
|
|
|
1749
2190
|
|
|
1750
2191
|
|
|
2192
|
+
|
|
2193
|
+
|
|
2194
|
+
|
|
2195
|
+
|
|
2196
|
+
|
|
2197
|
+
|
|
2198
|
+
|
|
2199
|
+
|
|
2200
|
+
|
|
2201
|
+
|
|
2202
|
+
|
|
2203
|
+
|
|
2204
|
+
|
|
2205
|
+
|
|
2206
|
+
|
|
2207
|
+
|
|
2208
|
+
|
|
2209
|
+
|
|
2210
|
+
|
|
2211
|
+
|
|
2212
|
+
|
|
1751
2213
|
* @example
|
|
1752
2214
|
* // Remove all elements
|
|
1753
2215
|
* const q = new Queue<number>([1, 2, 3]);
|
|
@@ -1770,6 +2232,27 @@ var directedGraphTyped = (() => {
|
|
|
1770
2232
|
|
|
1771
2233
|
|
|
1772
2234
|
|
|
2235
|
+
|
|
2236
|
+
|
|
2237
|
+
|
|
2238
|
+
|
|
2239
|
+
|
|
2240
|
+
|
|
2241
|
+
|
|
2242
|
+
|
|
2243
|
+
|
|
2244
|
+
|
|
2245
|
+
|
|
2246
|
+
|
|
2247
|
+
|
|
2248
|
+
|
|
2249
|
+
|
|
2250
|
+
|
|
2251
|
+
|
|
2252
|
+
|
|
2253
|
+
|
|
2254
|
+
|
|
2255
|
+
|
|
1773
2256
|
* @example
|
|
1774
2257
|
* // Reclaim unused memory
|
|
1775
2258
|
* const q = new Queue<number>([1, 2, 3, 4, 5]);
|
|
@@ -1815,6 +2298,27 @@ var directedGraphTyped = (() => {
|
|
|
1815
2298
|
|
|
1816
2299
|
|
|
1817
2300
|
|
|
2301
|
+
|
|
2302
|
+
|
|
2303
|
+
|
|
2304
|
+
|
|
2305
|
+
|
|
2306
|
+
|
|
2307
|
+
|
|
2308
|
+
|
|
2309
|
+
|
|
2310
|
+
|
|
2311
|
+
|
|
2312
|
+
|
|
2313
|
+
|
|
2314
|
+
|
|
2315
|
+
|
|
2316
|
+
|
|
2317
|
+
|
|
2318
|
+
|
|
2319
|
+
|
|
2320
|
+
|
|
2321
|
+
|
|
1818
2322
|
* @example
|
|
1819
2323
|
* // Create independent copy
|
|
1820
2324
|
* const q = new Queue<number>([1, 2, 3]);
|
|
@@ -1844,6 +2348,27 @@ var directedGraphTyped = (() => {
|
|
|
1844
2348
|
|
|
1845
2349
|
|
|
1846
2350
|
|
|
2351
|
+
|
|
2352
|
+
|
|
2353
|
+
|
|
2354
|
+
|
|
2355
|
+
|
|
2356
|
+
|
|
2357
|
+
|
|
2358
|
+
|
|
2359
|
+
|
|
2360
|
+
|
|
2361
|
+
|
|
2362
|
+
|
|
2363
|
+
|
|
2364
|
+
|
|
2365
|
+
|
|
2366
|
+
|
|
2367
|
+
|
|
2368
|
+
|
|
2369
|
+
|
|
2370
|
+
|
|
2371
|
+
|
|
1847
2372
|
* @example
|
|
1848
2373
|
* // Filter elements
|
|
1849
2374
|
* const q = new Queue<number>([1, 2, 3, 4, 5]);
|
|
@@ -1877,6 +2402,27 @@ var directedGraphTyped = (() => {
|
|
|
1877
2402
|
|
|
1878
2403
|
|
|
1879
2404
|
|
|
2405
|
+
|
|
2406
|
+
|
|
2407
|
+
|
|
2408
|
+
|
|
2409
|
+
|
|
2410
|
+
|
|
2411
|
+
|
|
2412
|
+
|
|
2413
|
+
|
|
2414
|
+
|
|
2415
|
+
|
|
2416
|
+
|
|
2417
|
+
|
|
2418
|
+
|
|
2419
|
+
|
|
2420
|
+
|
|
2421
|
+
|
|
2422
|
+
|
|
2423
|
+
|
|
2424
|
+
|
|
2425
|
+
|
|
1880
2426
|
* @example
|
|
1881
2427
|
* // Transform elements
|
|
1882
2428
|
* const q = new Queue<number>([1, 2, 3]);
|
|
@@ -2983,6 +3529,27 @@ var directedGraphTyped = (() => {
|
|
|
2983
3529
|
|
|
2984
3530
|
|
|
2985
3531
|
|
|
3532
|
+
|
|
3533
|
+
|
|
3534
|
+
|
|
3535
|
+
|
|
3536
|
+
|
|
3537
|
+
|
|
3538
|
+
|
|
3539
|
+
|
|
3540
|
+
|
|
3541
|
+
|
|
3542
|
+
|
|
3543
|
+
|
|
3544
|
+
|
|
3545
|
+
|
|
3546
|
+
|
|
3547
|
+
|
|
3548
|
+
|
|
3549
|
+
|
|
3550
|
+
|
|
3551
|
+
|
|
3552
|
+
|
|
2986
3553
|
* @example
|
|
2987
3554
|
* // Get edge between vertices
|
|
2988
3555
|
* const g = new DirectedGraph();
|
|
@@ -3047,6 +3614,27 @@ var directedGraphTyped = (() => {
|
|
|
3047
3614
|
|
|
3048
3615
|
|
|
3049
3616
|
|
|
3617
|
+
|
|
3618
|
+
|
|
3619
|
+
|
|
3620
|
+
|
|
3621
|
+
|
|
3622
|
+
|
|
3623
|
+
|
|
3624
|
+
|
|
3625
|
+
|
|
3626
|
+
|
|
3627
|
+
|
|
3628
|
+
|
|
3629
|
+
|
|
3630
|
+
|
|
3631
|
+
|
|
3632
|
+
|
|
3633
|
+
|
|
3634
|
+
|
|
3635
|
+
|
|
3636
|
+
|
|
3637
|
+
|
|
3050
3638
|
* @example
|
|
3051
3639
|
* // DirectedGraph deleteEdge and vertex operations
|
|
3052
3640
|
* const graph = new DirectedGraph<string>();
|
|
@@ -3109,6 +3697,27 @@ var directedGraphTyped = (() => {
|
|
|
3109
3697
|
|
|
3110
3698
|
|
|
3111
3699
|
|
|
3700
|
+
|
|
3701
|
+
|
|
3702
|
+
|
|
3703
|
+
|
|
3704
|
+
|
|
3705
|
+
|
|
3706
|
+
|
|
3707
|
+
|
|
3708
|
+
|
|
3709
|
+
|
|
3710
|
+
|
|
3711
|
+
|
|
3712
|
+
|
|
3713
|
+
|
|
3714
|
+
|
|
3715
|
+
|
|
3716
|
+
|
|
3717
|
+
|
|
3718
|
+
|
|
3719
|
+
|
|
3720
|
+
|
|
3112
3721
|
* @example
|
|
3113
3722
|
* // Remove a vertex
|
|
3114
3723
|
* const g = new DirectedGraph();
|
|
@@ -3162,6 +3771,27 @@ var directedGraphTyped = (() => {
|
|
|
3162
3771
|
|
|
3163
3772
|
|
|
3164
3773
|
|
|
3774
|
+
|
|
3775
|
+
|
|
3776
|
+
|
|
3777
|
+
|
|
3778
|
+
|
|
3779
|
+
|
|
3780
|
+
|
|
3781
|
+
|
|
3782
|
+
|
|
3783
|
+
|
|
3784
|
+
|
|
3785
|
+
|
|
3786
|
+
|
|
3787
|
+
|
|
3788
|
+
|
|
3789
|
+
|
|
3790
|
+
|
|
3791
|
+
|
|
3792
|
+
|
|
3793
|
+
|
|
3794
|
+
|
|
3165
3795
|
* @example
|
|
3166
3796
|
* // Get incoming edges
|
|
3167
3797
|
* const g = new DirectedGraph();
|
|
@@ -3192,6 +3822,27 @@ var directedGraphTyped = (() => {
|
|
|
3192
3822
|
|
|
3193
3823
|
|
|
3194
3824
|
|
|
3825
|
+
|
|
3826
|
+
|
|
3827
|
+
|
|
3828
|
+
|
|
3829
|
+
|
|
3830
|
+
|
|
3831
|
+
|
|
3832
|
+
|
|
3833
|
+
|
|
3834
|
+
|
|
3835
|
+
|
|
3836
|
+
|
|
3837
|
+
|
|
3838
|
+
|
|
3839
|
+
|
|
3840
|
+
|
|
3841
|
+
|
|
3842
|
+
|
|
3843
|
+
|
|
3844
|
+
|
|
3845
|
+
|
|
3195
3846
|
* @example
|
|
3196
3847
|
* // Get outgoing edges
|
|
3197
3848
|
* const g = new DirectedGraph();
|
|
@@ -3275,6 +3926,27 @@ var directedGraphTyped = (() => {
|
|
|
3275
3926
|
|
|
3276
3927
|
|
|
3277
3928
|
|
|
3929
|
+
|
|
3930
|
+
|
|
3931
|
+
|
|
3932
|
+
|
|
3933
|
+
|
|
3934
|
+
|
|
3935
|
+
|
|
3936
|
+
|
|
3937
|
+
|
|
3938
|
+
|
|
3939
|
+
|
|
3940
|
+
|
|
3941
|
+
|
|
3942
|
+
|
|
3943
|
+
|
|
3944
|
+
|
|
3945
|
+
|
|
3946
|
+
|
|
3947
|
+
|
|
3948
|
+
|
|
3949
|
+
|
|
3278
3950
|
* @example
|
|
3279
3951
|
* // DirectedGraph topologicalSort for task scheduling
|
|
3280
3952
|
* const graph = new DirectedGraph<string>();
|
|
@@ -3339,6 +4011,27 @@ var directedGraphTyped = (() => {
|
|
|
3339
4011
|
|
|
3340
4012
|
|
|
3341
4013
|
|
|
4014
|
+
|
|
4015
|
+
|
|
4016
|
+
|
|
4017
|
+
|
|
4018
|
+
|
|
4019
|
+
|
|
4020
|
+
|
|
4021
|
+
|
|
4022
|
+
|
|
4023
|
+
|
|
4024
|
+
|
|
4025
|
+
|
|
4026
|
+
|
|
4027
|
+
|
|
4028
|
+
|
|
4029
|
+
|
|
4030
|
+
|
|
4031
|
+
|
|
4032
|
+
|
|
4033
|
+
|
|
4034
|
+
|
|
3342
4035
|
* @example
|
|
3343
4036
|
* // Get all edges
|
|
3344
4037
|
* const g = new DirectedGraph();
|
|
@@ -3365,6 +4058,27 @@ var directedGraphTyped = (() => {
|
|
|
3365
4058
|
|
|
3366
4059
|
|
|
3367
4060
|
|
|
4061
|
+
|
|
4062
|
+
|
|
4063
|
+
|
|
4064
|
+
|
|
4065
|
+
|
|
4066
|
+
|
|
4067
|
+
|
|
4068
|
+
|
|
4069
|
+
|
|
4070
|
+
|
|
4071
|
+
|
|
4072
|
+
|
|
4073
|
+
|
|
4074
|
+
|
|
4075
|
+
|
|
4076
|
+
|
|
4077
|
+
|
|
4078
|
+
|
|
4079
|
+
|
|
4080
|
+
|
|
4081
|
+
|
|
3368
4082
|
* @example
|
|
3369
4083
|
* // Get outgoing neighbors
|
|
3370
4084
|
* const g = new DirectedGraph();
|
|
@@ -3444,6 +4158,27 @@ var directedGraphTyped = (() => {
|
|
|
3444
4158
|
|
|
3445
4159
|
|
|
3446
4160
|
|
|
4161
|
+
|
|
4162
|
+
|
|
4163
|
+
|
|
4164
|
+
|
|
4165
|
+
|
|
4166
|
+
|
|
4167
|
+
|
|
4168
|
+
|
|
4169
|
+
|
|
4170
|
+
|
|
4171
|
+
|
|
4172
|
+
|
|
4173
|
+
|
|
4174
|
+
|
|
4175
|
+
|
|
4176
|
+
|
|
4177
|
+
|
|
4178
|
+
|
|
4179
|
+
|
|
4180
|
+
|
|
4181
|
+
|
|
3447
4182
|
* @example
|
|
3448
4183
|
* // Find strongly connected components
|
|
3449
4184
|
* const g = new DirectedGraph();
|
|
@@ -3526,6 +4261,27 @@ var directedGraphTyped = (() => {
|
|
|
3526
4261
|
|
|
3527
4262
|
|
|
3528
4263
|
|
|
4264
|
+
|
|
4265
|
+
|
|
4266
|
+
|
|
4267
|
+
|
|
4268
|
+
|
|
4269
|
+
|
|
4270
|
+
|
|
4271
|
+
|
|
4272
|
+
|
|
4273
|
+
|
|
4274
|
+
|
|
4275
|
+
|
|
4276
|
+
|
|
4277
|
+
|
|
4278
|
+
|
|
4279
|
+
|
|
4280
|
+
|
|
4281
|
+
|
|
4282
|
+
|
|
4283
|
+
|
|
4284
|
+
|
|
3529
4285
|
* @example
|
|
3530
4286
|
* // Get strongly connected components
|
|
3531
4287
|
* const g = new DirectedGraph();
|