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
package/dist/cjs/index.cjs
CHANGED
|
@@ -478,6 +478,199 @@ var IterableElementBase = class {
|
|
|
478
478
|
}
|
|
479
479
|
};
|
|
480
480
|
|
|
481
|
+
// src/data-structures/base/linear-base.ts
|
|
482
|
+
var LinearBase = class _LinearBase extends IterableElementBase {
|
|
483
|
+
static {
|
|
484
|
+
__name(this, "LinearBase");
|
|
485
|
+
}
|
|
486
|
+
/**
|
|
487
|
+
* Construct a linear container with runtime options.
|
|
488
|
+
* @param options - `{ maxLen?, ... }` bounds/behavior options.
|
|
489
|
+
* @remarks Time O(1), Space O(1)
|
|
490
|
+
*/
|
|
491
|
+
constructor(options) {
|
|
492
|
+
super(options);
|
|
493
|
+
if (options) {
|
|
494
|
+
const { maxLen } = options;
|
|
495
|
+
if (typeof maxLen === "number" && maxLen > 0 && maxLen % 1 === 0) this._maxLen = maxLen;
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
_maxLen = -1;
|
|
499
|
+
/**
|
|
500
|
+
* Upper bound for length (if positive), or `-1` when unbounded.
|
|
501
|
+
* @returns Maximum allowed length.
|
|
502
|
+
* @remarks Time O(1), Space O(1)
|
|
503
|
+
*/
|
|
504
|
+
get maxLen() {
|
|
505
|
+
return this._maxLen;
|
|
506
|
+
}
|
|
507
|
+
/**
|
|
508
|
+
* First index of a value from the left.
|
|
509
|
+
* @param searchElement - Value to match.
|
|
510
|
+
* @param fromIndex - Start position (supports negative index).
|
|
511
|
+
* @returns Index or `-1` if not found.
|
|
512
|
+
* @remarks Time O(n), Space O(1)
|
|
513
|
+
*/
|
|
514
|
+
indexOf(searchElement, fromIndex = 0) {
|
|
515
|
+
if (this.length === 0) return -1;
|
|
516
|
+
if (fromIndex < 0) fromIndex = this.length + fromIndex;
|
|
517
|
+
if (fromIndex < 0) fromIndex = 0;
|
|
518
|
+
for (let i = fromIndex; i < this.length; i++) {
|
|
519
|
+
const element = this.at(i);
|
|
520
|
+
if (element === searchElement) return i;
|
|
521
|
+
}
|
|
522
|
+
return -1;
|
|
523
|
+
}
|
|
524
|
+
/**
|
|
525
|
+
* Last index of a value from the right.
|
|
526
|
+
* @param searchElement - Value to match.
|
|
527
|
+
* @param fromIndex - Start position (supports negative index).
|
|
528
|
+
* @returns Index or `-1` if not found.
|
|
529
|
+
* @remarks Time O(n), Space O(1)
|
|
530
|
+
*/
|
|
531
|
+
lastIndexOf(searchElement, fromIndex = this.length - 1) {
|
|
532
|
+
if (this.length === 0) return -1;
|
|
533
|
+
if (fromIndex >= this.length) fromIndex = this.length - 1;
|
|
534
|
+
if (fromIndex < 0) fromIndex = this.length + fromIndex;
|
|
535
|
+
for (let i = fromIndex; i >= 0; i--) {
|
|
536
|
+
const element = this.at(i);
|
|
537
|
+
if (element === searchElement) return i;
|
|
538
|
+
}
|
|
539
|
+
return -1;
|
|
540
|
+
}
|
|
541
|
+
/**
|
|
542
|
+
* Find the first index matching a predicate.
|
|
543
|
+
* @param predicate - `(element, index, self) => boolean`.
|
|
544
|
+
* @param thisArg - Optional `this` for callback.
|
|
545
|
+
* @returns Index or `-1`.
|
|
546
|
+
* @remarks Time O(n), Space O(1)
|
|
547
|
+
*/
|
|
548
|
+
findIndex(predicate, thisArg) {
|
|
549
|
+
for (let i = 0; i < this.length; i++) {
|
|
550
|
+
const item = this.at(i);
|
|
551
|
+
if (item !== void 0 && predicate.call(thisArg, item, i, this)) return i;
|
|
552
|
+
}
|
|
553
|
+
return -1;
|
|
554
|
+
}
|
|
555
|
+
/**
|
|
556
|
+
* Concatenate elements and/or containers.
|
|
557
|
+
* @param items - Elements or other containers.
|
|
558
|
+
* @returns New container with combined elements (`this` type).
|
|
559
|
+
* @remarks Time O(sum(length)), Space O(sum(length))
|
|
560
|
+
*/
|
|
561
|
+
concat(...items) {
|
|
562
|
+
const newList = this.clone();
|
|
563
|
+
for (const item of items) {
|
|
564
|
+
if (item instanceof _LinearBase) {
|
|
565
|
+
newList.pushMany(item);
|
|
566
|
+
} else {
|
|
567
|
+
newList.push(item);
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
return newList;
|
|
571
|
+
}
|
|
572
|
+
/**
|
|
573
|
+
* In-place stable order via array sort semantics.
|
|
574
|
+
* @param compareFn - Comparator `(a, b) => number`.
|
|
575
|
+
* @returns This container.
|
|
576
|
+
* @remarks Time O(n log n), Space O(n) (materializes to array temporarily)
|
|
577
|
+
*/
|
|
578
|
+
sort(compareFn) {
|
|
579
|
+
const arr = this.toArray();
|
|
580
|
+
arr.sort(compareFn);
|
|
581
|
+
this.clear();
|
|
582
|
+
for (const item of arr) this.push(item);
|
|
583
|
+
return this;
|
|
584
|
+
}
|
|
585
|
+
/**
|
|
586
|
+
* Remove and/or insert elements at a position (array-compatible).
|
|
587
|
+
* @param start - Start index (supports negative index).
|
|
588
|
+
* @param deleteCount - How many to remove.
|
|
589
|
+
* @param items - Elements to insert.
|
|
590
|
+
* @returns Removed elements as a new list (`this` type).
|
|
591
|
+
* @remarks Time O(n + m), Space O(min(n, m)) where `m = items.length`
|
|
592
|
+
*/
|
|
593
|
+
splice(start, deleteCount = 0, ...items) {
|
|
594
|
+
const removedList = this._createInstance();
|
|
595
|
+
start = start < 0 ? this.length + start : start;
|
|
596
|
+
start = Math.max(0, Math.min(start, this.length));
|
|
597
|
+
deleteCount = Math.max(0, Math.min(deleteCount, this.length - start));
|
|
598
|
+
for (let i = 0; i < deleteCount; i++) {
|
|
599
|
+
const removed = this.deleteAt(start);
|
|
600
|
+
if (removed !== void 0) {
|
|
601
|
+
removedList.push(removed);
|
|
602
|
+
}
|
|
603
|
+
}
|
|
604
|
+
for (let i = 0; i < items.length; i++) {
|
|
605
|
+
this.addAt(start + i, items[i]);
|
|
606
|
+
}
|
|
607
|
+
return removedList;
|
|
608
|
+
}
|
|
609
|
+
/**
|
|
610
|
+
* Join all elements into a string.
|
|
611
|
+
* @param separator - Separator string.
|
|
612
|
+
* @returns Concatenated string.
|
|
613
|
+
* @remarks Time O(n), Space O(n)
|
|
614
|
+
*/
|
|
615
|
+
join(separator = ",") {
|
|
616
|
+
return this.toArray().join(separator);
|
|
617
|
+
}
|
|
618
|
+
/**
|
|
619
|
+
* Snapshot elements into a reversed array.
|
|
620
|
+
* @returns New reversed array.
|
|
621
|
+
* @remarks Time O(n), Space O(n)
|
|
622
|
+
*/
|
|
623
|
+
toReversedArray() {
|
|
624
|
+
const array = [];
|
|
625
|
+
for (let i = this.length - 1; i >= 0; i--) {
|
|
626
|
+
array.push(this.at(i));
|
|
627
|
+
}
|
|
628
|
+
return array;
|
|
629
|
+
}
|
|
630
|
+
reduceRight(callbackfn, initialValue) {
|
|
631
|
+
let accumulator = initialValue ?? 0;
|
|
632
|
+
for (let i = this.length - 1; i >= 0; i--) {
|
|
633
|
+
accumulator = callbackfn(accumulator, this.at(i), i, this);
|
|
634
|
+
}
|
|
635
|
+
return accumulator;
|
|
636
|
+
}
|
|
637
|
+
/**
|
|
638
|
+
* Create a shallow copy of a subrange.
|
|
639
|
+
* @param start - Inclusive start (supports negative index).
|
|
640
|
+
* @param end - Exclusive end (supports negative index).
|
|
641
|
+
* @returns New list with the range (`this` type).
|
|
642
|
+
* @remarks Time O(n), Space O(n)
|
|
643
|
+
*/
|
|
644
|
+
slice(start = 0, end = this.length) {
|
|
645
|
+
start = start < 0 ? this.length + start : start;
|
|
646
|
+
end = end < 0 ? this.length + end : end;
|
|
647
|
+
const newList = this._createInstance();
|
|
648
|
+
for (let i = start; i < end; i++) {
|
|
649
|
+
newList.push(this.at(i));
|
|
650
|
+
}
|
|
651
|
+
return newList;
|
|
652
|
+
}
|
|
653
|
+
/**
|
|
654
|
+
* Fill a range with a value.
|
|
655
|
+
* @param value - Value to set.
|
|
656
|
+
* @param start - Inclusive start.
|
|
657
|
+
* @param end - Exclusive end.
|
|
658
|
+
* @returns This list.
|
|
659
|
+
* @remarks Time O(n), Space O(1)
|
|
660
|
+
*/
|
|
661
|
+
fill(value, start = 0, end = this.length) {
|
|
662
|
+
start = start < 0 ? this.length + start : start;
|
|
663
|
+
end = end < 0 ? this.length + end : end;
|
|
664
|
+
if (start < 0) start = 0;
|
|
665
|
+
if (end > this.length) end = this.length;
|
|
666
|
+
if (start >= end) return this;
|
|
667
|
+
for (let i = start; i < end; i++) {
|
|
668
|
+
this.setAt(i, value);
|
|
669
|
+
}
|
|
670
|
+
return this;
|
|
671
|
+
}
|
|
672
|
+
};
|
|
673
|
+
|
|
481
674
|
// src/data-structures/heap/heap.ts
|
|
482
675
|
var Heap = class _Heap extends IterableElementBase {
|
|
483
676
|
static {
|
|
@@ -523,6 +716,27 @@ var Heap = class _Heap extends IterableElementBase {
|
|
|
523
716
|
|
|
524
717
|
|
|
525
718
|
|
|
719
|
+
|
|
720
|
+
|
|
721
|
+
|
|
722
|
+
|
|
723
|
+
|
|
724
|
+
|
|
725
|
+
|
|
726
|
+
|
|
727
|
+
|
|
728
|
+
|
|
729
|
+
|
|
730
|
+
|
|
731
|
+
|
|
732
|
+
|
|
733
|
+
|
|
734
|
+
|
|
735
|
+
|
|
736
|
+
|
|
737
|
+
|
|
738
|
+
|
|
739
|
+
|
|
526
740
|
* @example
|
|
527
741
|
* // Track heap capacity
|
|
528
742
|
* const heap = new Heap<number>();
|
|
@@ -585,6 +799,27 @@ var Heap = class _Heap extends IterableElementBase {
|
|
|
585
799
|
|
|
586
800
|
|
|
587
801
|
|
|
802
|
+
|
|
803
|
+
|
|
804
|
+
|
|
805
|
+
|
|
806
|
+
|
|
807
|
+
|
|
808
|
+
|
|
809
|
+
|
|
810
|
+
|
|
811
|
+
|
|
812
|
+
|
|
813
|
+
|
|
814
|
+
|
|
815
|
+
|
|
816
|
+
|
|
817
|
+
|
|
818
|
+
|
|
819
|
+
|
|
820
|
+
|
|
821
|
+
|
|
822
|
+
|
|
588
823
|
* @example
|
|
589
824
|
* // basic Heap creation and add operation
|
|
590
825
|
* // Create a min heap (default)
|
|
@@ -618,6 +853,27 @@ var Heap = class _Heap extends IterableElementBase {
|
|
|
618
853
|
|
|
619
854
|
|
|
620
855
|
|
|
856
|
+
|
|
857
|
+
|
|
858
|
+
|
|
859
|
+
|
|
860
|
+
|
|
861
|
+
|
|
862
|
+
|
|
863
|
+
|
|
864
|
+
|
|
865
|
+
|
|
866
|
+
|
|
867
|
+
|
|
868
|
+
|
|
869
|
+
|
|
870
|
+
|
|
871
|
+
|
|
872
|
+
|
|
873
|
+
|
|
874
|
+
|
|
875
|
+
|
|
876
|
+
|
|
621
877
|
* @example
|
|
622
878
|
* // Add multiple elements
|
|
623
879
|
* const heap = new Heap<number>([], { comparator: (a, b) => a - b });
|
|
@@ -653,6 +909,27 @@ var Heap = class _Heap extends IterableElementBase {
|
|
|
653
909
|
|
|
654
910
|
|
|
655
911
|
|
|
912
|
+
|
|
913
|
+
|
|
914
|
+
|
|
915
|
+
|
|
916
|
+
|
|
917
|
+
|
|
918
|
+
|
|
919
|
+
|
|
920
|
+
|
|
921
|
+
|
|
922
|
+
|
|
923
|
+
|
|
924
|
+
|
|
925
|
+
|
|
926
|
+
|
|
927
|
+
|
|
928
|
+
|
|
929
|
+
|
|
930
|
+
|
|
931
|
+
|
|
932
|
+
|
|
656
933
|
* @example
|
|
657
934
|
* // Heap with custom comparator (MaxHeap behavior)
|
|
658
935
|
* interface Task {
|
|
@@ -704,6 +981,27 @@ var Heap = class _Heap extends IterableElementBase {
|
|
|
704
981
|
|
|
705
982
|
|
|
706
983
|
|
|
984
|
+
|
|
985
|
+
|
|
986
|
+
|
|
987
|
+
|
|
988
|
+
|
|
989
|
+
|
|
990
|
+
|
|
991
|
+
|
|
992
|
+
|
|
993
|
+
|
|
994
|
+
|
|
995
|
+
|
|
996
|
+
|
|
997
|
+
|
|
998
|
+
|
|
999
|
+
|
|
1000
|
+
|
|
1001
|
+
|
|
1002
|
+
|
|
1003
|
+
|
|
1004
|
+
|
|
707
1005
|
* @example
|
|
708
1006
|
* // Heap for event processing with priority
|
|
709
1007
|
* interface Event {
|
|
@@ -780,6 +1078,27 @@ var Heap = class _Heap extends IterableElementBase {
|
|
|
780
1078
|
|
|
781
1079
|
|
|
782
1080
|
|
|
1081
|
+
|
|
1082
|
+
|
|
1083
|
+
|
|
1084
|
+
|
|
1085
|
+
|
|
1086
|
+
|
|
1087
|
+
|
|
1088
|
+
|
|
1089
|
+
|
|
1090
|
+
|
|
1091
|
+
|
|
1092
|
+
|
|
1093
|
+
|
|
1094
|
+
|
|
1095
|
+
|
|
1096
|
+
|
|
1097
|
+
|
|
1098
|
+
|
|
1099
|
+
|
|
1100
|
+
|
|
1101
|
+
|
|
783
1102
|
* @example
|
|
784
1103
|
* // Check if heap is empty
|
|
785
1104
|
* const heap = new Heap<number>([], { comparator: (a, b) => a - b });
|
|
@@ -803,6 +1122,27 @@ var Heap = class _Heap extends IterableElementBase {
|
|
|
803
1122
|
|
|
804
1123
|
|
|
805
1124
|
|
|
1125
|
+
|
|
1126
|
+
|
|
1127
|
+
|
|
1128
|
+
|
|
1129
|
+
|
|
1130
|
+
|
|
1131
|
+
|
|
1132
|
+
|
|
1133
|
+
|
|
1134
|
+
|
|
1135
|
+
|
|
1136
|
+
|
|
1137
|
+
|
|
1138
|
+
|
|
1139
|
+
|
|
1140
|
+
|
|
1141
|
+
|
|
1142
|
+
|
|
1143
|
+
|
|
1144
|
+
|
|
1145
|
+
|
|
806
1146
|
* @example
|
|
807
1147
|
* // Remove all elements
|
|
808
1148
|
* const heap = new Heap<number>([1, 2, 3], { comparator: (a, b) => a - b });
|
|
@@ -829,6 +1169,27 @@ var Heap = class _Heap extends IterableElementBase {
|
|
|
829
1169
|
* @returns True if found.
|
|
830
1170
|
|
|
831
1171
|
|
|
1172
|
+
|
|
1173
|
+
|
|
1174
|
+
|
|
1175
|
+
|
|
1176
|
+
|
|
1177
|
+
|
|
1178
|
+
|
|
1179
|
+
|
|
1180
|
+
|
|
1181
|
+
|
|
1182
|
+
|
|
1183
|
+
|
|
1184
|
+
|
|
1185
|
+
|
|
1186
|
+
|
|
1187
|
+
|
|
1188
|
+
|
|
1189
|
+
|
|
1190
|
+
|
|
1191
|
+
|
|
1192
|
+
|
|
832
1193
|
* @example
|
|
833
1194
|
* // Check element existence
|
|
834
1195
|
* const heap = new Heap<number>([3, 1, 2], { comparator: (a, b) => a - b });
|
|
@@ -852,6 +1213,27 @@ var Heap = class _Heap extends IterableElementBase {
|
|
|
852
1213
|
|
|
853
1214
|
|
|
854
1215
|
|
|
1216
|
+
|
|
1217
|
+
|
|
1218
|
+
|
|
1219
|
+
|
|
1220
|
+
|
|
1221
|
+
|
|
1222
|
+
|
|
1223
|
+
|
|
1224
|
+
|
|
1225
|
+
|
|
1226
|
+
|
|
1227
|
+
|
|
1228
|
+
|
|
1229
|
+
|
|
1230
|
+
|
|
1231
|
+
|
|
1232
|
+
|
|
1233
|
+
|
|
1234
|
+
|
|
1235
|
+
|
|
1236
|
+
|
|
855
1237
|
* @example
|
|
856
1238
|
* // Remove specific element
|
|
857
1239
|
* const heap = new Heap<number>([3, 1, 4, 1, 5], { comparator: (a, b) => a - b });
|
|
@@ -921,6 +1303,27 @@ var Heap = class _Heap extends IterableElementBase {
|
|
|
921
1303
|
* @returns Array of visited elements.
|
|
922
1304
|
|
|
923
1305
|
|
|
1306
|
+
|
|
1307
|
+
|
|
1308
|
+
|
|
1309
|
+
|
|
1310
|
+
|
|
1311
|
+
|
|
1312
|
+
|
|
1313
|
+
|
|
1314
|
+
|
|
1315
|
+
|
|
1316
|
+
|
|
1317
|
+
|
|
1318
|
+
|
|
1319
|
+
|
|
1320
|
+
|
|
1321
|
+
|
|
1322
|
+
|
|
1323
|
+
|
|
1324
|
+
|
|
1325
|
+
|
|
1326
|
+
|
|
924
1327
|
* @example
|
|
925
1328
|
* // Depth-first traversal
|
|
926
1329
|
* const heap = new Heap<number>([3, 1, 2], { comparator: (a, b) => a - b });
|
|
@@ -977,6 +1380,27 @@ var Heap = class _Heap extends IterableElementBase {
|
|
|
977
1380
|
|
|
978
1381
|
|
|
979
1382
|
|
|
1383
|
+
|
|
1384
|
+
|
|
1385
|
+
|
|
1386
|
+
|
|
1387
|
+
|
|
1388
|
+
|
|
1389
|
+
|
|
1390
|
+
|
|
1391
|
+
|
|
1392
|
+
|
|
1393
|
+
|
|
1394
|
+
|
|
1395
|
+
|
|
1396
|
+
|
|
1397
|
+
|
|
1398
|
+
|
|
1399
|
+
|
|
1400
|
+
|
|
1401
|
+
|
|
1402
|
+
|
|
1403
|
+
|
|
980
1404
|
* @example
|
|
981
1405
|
* // Sort elements using heap
|
|
982
1406
|
* const heap = new Heap<number>([5, 1, 3, 2, 4]);
|
|
@@ -1006,6 +1430,27 @@ var Heap = class _Heap extends IterableElementBase {
|
|
|
1006
1430
|
|
|
1007
1431
|
|
|
1008
1432
|
|
|
1433
|
+
|
|
1434
|
+
|
|
1435
|
+
|
|
1436
|
+
|
|
1437
|
+
|
|
1438
|
+
|
|
1439
|
+
|
|
1440
|
+
|
|
1441
|
+
|
|
1442
|
+
|
|
1443
|
+
|
|
1444
|
+
|
|
1445
|
+
|
|
1446
|
+
|
|
1447
|
+
|
|
1448
|
+
|
|
1449
|
+
|
|
1450
|
+
|
|
1451
|
+
|
|
1452
|
+
|
|
1453
|
+
|
|
1009
1454
|
* @example
|
|
1010
1455
|
* // Create independent copy
|
|
1011
1456
|
* const heap = new Heap<number>([3, 1, 4], { comparator: (a, b) => a - b });
|
|
@@ -1034,6 +1479,27 @@ var Heap = class _Heap extends IterableElementBase {
|
|
|
1034
1479
|
|
|
1035
1480
|
|
|
1036
1481
|
|
|
1482
|
+
|
|
1483
|
+
|
|
1484
|
+
|
|
1485
|
+
|
|
1486
|
+
|
|
1487
|
+
|
|
1488
|
+
|
|
1489
|
+
|
|
1490
|
+
|
|
1491
|
+
|
|
1492
|
+
|
|
1493
|
+
|
|
1494
|
+
|
|
1495
|
+
|
|
1496
|
+
|
|
1497
|
+
|
|
1498
|
+
|
|
1499
|
+
|
|
1500
|
+
|
|
1501
|
+
|
|
1502
|
+
|
|
1037
1503
|
* @example
|
|
1038
1504
|
* // Filter elements
|
|
1039
1505
|
* const heap = new Heap<number>([1, 2, 3, 4, 5], { comparator: (a, b) => a - b });
|
|
@@ -1069,6 +1535,27 @@ var Heap = class _Heap extends IterableElementBase {
|
|
|
1069
1535
|
|
|
1070
1536
|
|
|
1071
1537
|
|
|
1538
|
+
|
|
1539
|
+
|
|
1540
|
+
|
|
1541
|
+
|
|
1542
|
+
|
|
1543
|
+
|
|
1544
|
+
|
|
1545
|
+
|
|
1546
|
+
|
|
1547
|
+
|
|
1548
|
+
|
|
1549
|
+
|
|
1550
|
+
|
|
1551
|
+
|
|
1552
|
+
|
|
1553
|
+
|
|
1554
|
+
|
|
1555
|
+
|
|
1556
|
+
|
|
1557
|
+
|
|
1558
|
+
|
|
1072
1559
|
* @example
|
|
1073
1560
|
* // Transform elements
|
|
1074
1561
|
* const heap = new Heap<number>([1, 2, 3], { comparator: (a, b) => a - b });
|
|
@@ -1157,226 +1644,33 @@ var Heap = class _Heap extends IterableElementBase {
|
|
|
1157
1644
|
* @param [options] - Options to override comparator or toElementFn.
|
|
1158
1645
|
* @returns A like-kind empty heap instance.
|
|
1159
1646
|
*/
|
|
1160
|
-
_createInstance(options) {
|
|
1161
|
-
const Ctor = this.constructor;
|
|
1162
|
-
return new Ctor([], { comparator: this.comparator, toElementFn: this.toElementFn, ...options ?? {} });
|
|
1163
|
-
}
|
|
1164
|
-
/**
|
|
1165
|
-
* (Protected) Create a like-kind instance seeded by elements.
|
|
1166
|
-
* @remarks Time O(N log N), Space O(N)
|
|
1167
|
-
* @template EM
|
|
1168
|
-
* @template RM
|
|
1169
|
-
* @param [elements] - Iterable of elements or raw values to seed.
|
|
1170
|
-
* @param [options] - Options forwarded to the constructor.
|
|
1171
|
-
* @returns A like-kind heap instance.
|
|
1172
|
-
*/
|
|
1173
|
-
_createLike(elements = [], options) {
|
|
1174
|
-
const Ctor = this.constructor;
|
|
1175
|
-
return new Ctor(elements, options);
|
|
1176
|
-
}
|
|
1177
|
-
/**
|
|
1178
|
-
* (Protected) Spawn an empty like-kind heap instance.
|
|
1179
|
-
* @remarks Time O(1), Space O(1)
|
|
1180
|
-
* @template EM
|
|
1181
|
-
* @template RM
|
|
1182
|
-
* @param [options] - Options forwarded to the constructor.
|
|
1183
|
-
* @returns An empty like-kind heap instance.
|
|
1184
|
-
*/
|
|
1185
|
-
_spawnLike(options) {
|
|
1186
|
-
return this._createLike([], options);
|
|
1187
|
-
}
|
|
1188
|
-
};
|
|
1189
|
-
|
|
1190
|
-
// src/data-structures/base/linear-base.ts
|
|
1191
|
-
var LinearBase = class _LinearBase extends IterableElementBase {
|
|
1192
|
-
static {
|
|
1193
|
-
__name(this, "LinearBase");
|
|
1194
|
-
}
|
|
1195
|
-
/**
|
|
1196
|
-
* Construct a linear container with runtime options.
|
|
1197
|
-
* @param options - `{ maxLen?, ... }` bounds/behavior options.
|
|
1198
|
-
* @remarks Time O(1), Space O(1)
|
|
1199
|
-
*/
|
|
1200
|
-
constructor(options) {
|
|
1201
|
-
super(options);
|
|
1202
|
-
if (options) {
|
|
1203
|
-
const { maxLen } = options;
|
|
1204
|
-
if (typeof maxLen === "number" && maxLen > 0 && maxLen % 1 === 0) this._maxLen = maxLen;
|
|
1205
|
-
}
|
|
1206
|
-
}
|
|
1207
|
-
_maxLen = -1;
|
|
1208
|
-
/**
|
|
1209
|
-
* Upper bound for length (if positive), or `-1` when unbounded.
|
|
1210
|
-
* @returns Maximum allowed length.
|
|
1211
|
-
* @remarks Time O(1), Space O(1)
|
|
1212
|
-
*/
|
|
1213
|
-
get maxLen() {
|
|
1214
|
-
return this._maxLen;
|
|
1215
|
-
}
|
|
1216
|
-
/**
|
|
1217
|
-
* First index of a value from the left.
|
|
1218
|
-
* @param searchElement - Value to match.
|
|
1219
|
-
* @param fromIndex - Start position (supports negative index).
|
|
1220
|
-
* @returns Index or `-1` if not found.
|
|
1221
|
-
* @remarks Time O(n), Space O(1)
|
|
1222
|
-
*/
|
|
1223
|
-
indexOf(searchElement, fromIndex = 0) {
|
|
1224
|
-
if (this.length === 0) return -1;
|
|
1225
|
-
if (fromIndex < 0) fromIndex = this.length + fromIndex;
|
|
1226
|
-
if (fromIndex < 0) fromIndex = 0;
|
|
1227
|
-
for (let i = fromIndex; i < this.length; i++) {
|
|
1228
|
-
const element = this.at(i);
|
|
1229
|
-
if (element === searchElement) return i;
|
|
1230
|
-
}
|
|
1231
|
-
return -1;
|
|
1232
|
-
}
|
|
1233
|
-
/**
|
|
1234
|
-
* Last index of a value from the right.
|
|
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
|
-
lastIndexOf(searchElement, fromIndex = this.length - 1) {
|
|
1241
|
-
if (this.length === 0) return -1;
|
|
1242
|
-
if (fromIndex >= this.length) fromIndex = this.length - 1;
|
|
1243
|
-
if (fromIndex < 0) fromIndex = this.length + fromIndex;
|
|
1244
|
-
for (let i = fromIndex; i >= 0; i--) {
|
|
1245
|
-
const element = this.at(i);
|
|
1246
|
-
if (element === searchElement) return i;
|
|
1247
|
-
}
|
|
1248
|
-
return -1;
|
|
1249
|
-
}
|
|
1250
|
-
/**
|
|
1251
|
-
* Find the first index matching a predicate.
|
|
1252
|
-
* @param predicate - `(element, index, self) => boolean`.
|
|
1253
|
-
* @param thisArg - Optional `this` for callback.
|
|
1254
|
-
* @returns Index or `-1`.
|
|
1255
|
-
* @remarks Time O(n), Space O(1)
|
|
1256
|
-
*/
|
|
1257
|
-
findIndex(predicate, thisArg) {
|
|
1258
|
-
for (let i = 0; i < this.length; i++) {
|
|
1259
|
-
const item = this.at(i);
|
|
1260
|
-
if (item !== void 0 && predicate.call(thisArg, item, i, this)) return i;
|
|
1261
|
-
}
|
|
1262
|
-
return -1;
|
|
1263
|
-
}
|
|
1264
|
-
/**
|
|
1265
|
-
* Concatenate elements and/or containers.
|
|
1266
|
-
* @param items - Elements or other containers.
|
|
1267
|
-
* @returns New container with combined elements (`this` type).
|
|
1268
|
-
* @remarks Time O(sum(length)), Space O(sum(length))
|
|
1269
|
-
*/
|
|
1270
|
-
concat(...items) {
|
|
1271
|
-
const newList = this.clone();
|
|
1272
|
-
for (const item of items) {
|
|
1273
|
-
if (item instanceof _LinearBase) {
|
|
1274
|
-
newList.pushMany(item);
|
|
1275
|
-
} else {
|
|
1276
|
-
newList.push(item);
|
|
1277
|
-
}
|
|
1278
|
-
}
|
|
1279
|
-
return newList;
|
|
1280
|
-
}
|
|
1281
|
-
/**
|
|
1282
|
-
* In-place stable order via array sort semantics.
|
|
1283
|
-
* @param compareFn - Comparator `(a, b) => number`.
|
|
1284
|
-
* @returns This container.
|
|
1285
|
-
* @remarks Time O(n log n), Space O(n) (materializes to array temporarily)
|
|
1286
|
-
*/
|
|
1287
|
-
sort(compareFn) {
|
|
1288
|
-
const arr = this.toArray();
|
|
1289
|
-
arr.sort(compareFn);
|
|
1290
|
-
this.clear();
|
|
1291
|
-
for (const item of arr) this.push(item);
|
|
1292
|
-
return this;
|
|
1293
|
-
}
|
|
1294
|
-
/**
|
|
1295
|
-
* Remove and/or insert elements at a position (array-compatible).
|
|
1296
|
-
* @param start - Start index (supports negative index).
|
|
1297
|
-
* @param deleteCount - How many to remove.
|
|
1298
|
-
* @param items - Elements to insert.
|
|
1299
|
-
* @returns Removed elements as a new list (`this` type).
|
|
1300
|
-
* @remarks Time O(n + m), Space O(min(n, m)) where `m = items.length`
|
|
1301
|
-
*/
|
|
1302
|
-
splice(start, deleteCount = 0, ...items) {
|
|
1303
|
-
const removedList = this._createInstance();
|
|
1304
|
-
start = start < 0 ? this.length + start : start;
|
|
1305
|
-
start = Math.max(0, Math.min(start, this.length));
|
|
1306
|
-
deleteCount = Math.max(0, Math.min(deleteCount, this.length - start));
|
|
1307
|
-
for (let i = 0; i < deleteCount; i++) {
|
|
1308
|
-
const removed = this.deleteAt(start);
|
|
1309
|
-
if (removed !== void 0) {
|
|
1310
|
-
removedList.push(removed);
|
|
1311
|
-
}
|
|
1312
|
-
}
|
|
1313
|
-
for (let i = 0; i < items.length; i++) {
|
|
1314
|
-
this.addAt(start + i, items[i]);
|
|
1315
|
-
}
|
|
1316
|
-
return removedList;
|
|
1317
|
-
}
|
|
1318
|
-
/**
|
|
1319
|
-
* Join all elements into a string.
|
|
1320
|
-
* @param separator - Separator string.
|
|
1321
|
-
* @returns Concatenated string.
|
|
1322
|
-
* @remarks Time O(n), Space O(n)
|
|
1323
|
-
*/
|
|
1324
|
-
join(separator = ",") {
|
|
1325
|
-
return this.toArray().join(separator);
|
|
1326
|
-
}
|
|
1327
|
-
/**
|
|
1328
|
-
* Snapshot elements into a reversed array.
|
|
1329
|
-
* @returns New reversed array.
|
|
1330
|
-
* @remarks Time O(n), Space O(n)
|
|
1331
|
-
*/
|
|
1332
|
-
toReversedArray() {
|
|
1333
|
-
const array = [];
|
|
1334
|
-
for (let i = this.length - 1; i >= 0; i--) {
|
|
1335
|
-
array.push(this.at(i));
|
|
1336
|
-
}
|
|
1337
|
-
return array;
|
|
1338
|
-
}
|
|
1339
|
-
reduceRight(callbackfn, initialValue) {
|
|
1340
|
-
let accumulator = initialValue ?? 0;
|
|
1341
|
-
for (let i = this.length - 1; i >= 0; i--) {
|
|
1342
|
-
accumulator = callbackfn(accumulator, this.at(i), i, this);
|
|
1343
|
-
}
|
|
1344
|
-
return accumulator;
|
|
1647
|
+
_createInstance(options) {
|
|
1648
|
+
const Ctor = this.constructor;
|
|
1649
|
+
return new Ctor([], { comparator: this.comparator, toElementFn: this.toElementFn, ...options ?? {} });
|
|
1345
1650
|
}
|
|
1346
1651
|
/**
|
|
1347
|
-
* Create a
|
|
1348
|
-
* @
|
|
1349
|
-
* @
|
|
1350
|
-
* @
|
|
1351
|
-
* @
|
|
1652
|
+
* (Protected) Create a like-kind instance seeded by elements.
|
|
1653
|
+
* @remarks Time O(N log N), Space O(N)
|
|
1654
|
+
* @template EM
|
|
1655
|
+
* @template RM
|
|
1656
|
+
* @param [elements] - Iterable of elements or raw values to seed.
|
|
1657
|
+
* @param [options] - Options forwarded to the constructor.
|
|
1658
|
+
* @returns A like-kind heap instance.
|
|
1352
1659
|
*/
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
const newList = this._createInstance();
|
|
1357
|
-
for (let i = start; i < end; i++) {
|
|
1358
|
-
newList.push(this.at(i));
|
|
1359
|
-
}
|
|
1360
|
-
return newList;
|
|
1660
|
+
_createLike(elements = [], options) {
|
|
1661
|
+
const Ctor = this.constructor;
|
|
1662
|
+
return new Ctor(elements, options);
|
|
1361
1663
|
}
|
|
1362
1664
|
/**
|
|
1363
|
-
*
|
|
1364
|
-
* @
|
|
1365
|
-
* @
|
|
1366
|
-
* @
|
|
1367
|
-
* @
|
|
1368
|
-
* @
|
|
1665
|
+
* (Protected) Spawn an empty like-kind heap instance.
|
|
1666
|
+
* @remarks Time O(1), Space O(1)
|
|
1667
|
+
* @template EM
|
|
1668
|
+
* @template RM
|
|
1669
|
+
* @param [options] - Options forwarded to the constructor.
|
|
1670
|
+
* @returns An empty like-kind heap instance.
|
|
1369
1671
|
*/
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
end = end < 0 ? this.length + end : end;
|
|
1373
|
-
if (start < 0) start = 0;
|
|
1374
|
-
if (end > this.length) end = this.length;
|
|
1375
|
-
if (start >= end) return this;
|
|
1376
|
-
for (let i = start; i < end; i++) {
|
|
1377
|
-
this.setAt(i, value);
|
|
1378
|
-
}
|
|
1379
|
-
return this;
|
|
1672
|
+
_spawnLike(options) {
|
|
1673
|
+
return this._createLike([], options);
|
|
1380
1674
|
}
|
|
1381
1675
|
};
|
|
1382
1676
|
|
|
@@ -1451,6 +1745,27 @@ var Queue = class _Queue extends LinearBase {
|
|
|
1451
1745
|
|
|
1452
1746
|
|
|
1453
1747
|
|
|
1748
|
+
|
|
1749
|
+
|
|
1750
|
+
|
|
1751
|
+
|
|
1752
|
+
|
|
1753
|
+
|
|
1754
|
+
|
|
1755
|
+
|
|
1756
|
+
|
|
1757
|
+
|
|
1758
|
+
|
|
1759
|
+
|
|
1760
|
+
|
|
1761
|
+
|
|
1762
|
+
|
|
1763
|
+
|
|
1764
|
+
|
|
1765
|
+
|
|
1766
|
+
|
|
1767
|
+
|
|
1768
|
+
|
|
1454
1769
|
* @example
|
|
1455
1770
|
* // Track queue length
|
|
1456
1771
|
* const q = new Queue<number>();
|
|
@@ -1477,6 +1792,27 @@ var Queue = class _Queue extends LinearBase {
|
|
|
1477
1792
|
|
|
1478
1793
|
|
|
1479
1794
|
|
|
1795
|
+
|
|
1796
|
+
|
|
1797
|
+
|
|
1798
|
+
|
|
1799
|
+
|
|
1800
|
+
|
|
1801
|
+
|
|
1802
|
+
|
|
1803
|
+
|
|
1804
|
+
|
|
1805
|
+
|
|
1806
|
+
|
|
1807
|
+
|
|
1808
|
+
|
|
1809
|
+
|
|
1810
|
+
|
|
1811
|
+
|
|
1812
|
+
|
|
1813
|
+
|
|
1814
|
+
|
|
1815
|
+
|
|
1480
1816
|
* @example
|
|
1481
1817
|
* // View the front element
|
|
1482
1818
|
* const q = new Queue<string>(['first', 'second', 'third']);
|
|
@@ -1519,6 +1855,27 @@ var Queue = class _Queue extends LinearBase {
|
|
|
1519
1855
|
|
|
1520
1856
|
|
|
1521
1857
|
|
|
1858
|
+
|
|
1859
|
+
|
|
1860
|
+
|
|
1861
|
+
|
|
1862
|
+
|
|
1863
|
+
|
|
1864
|
+
|
|
1865
|
+
|
|
1866
|
+
|
|
1867
|
+
|
|
1868
|
+
|
|
1869
|
+
|
|
1870
|
+
|
|
1871
|
+
|
|
1872
|
+
|
|
1873
|
+
|
|
1874
|
+
|
|
1875
|
+
|
|
1876
|
+
|
|
1877
|
+
|
|
1878
|
+
|
|
1522
1879
|
* @example
|
|
1523
1880
|
* // Queue for...of iteration and isEmpty check
|
|
1524
1881
|
* const queue = new Queue<string>(['A', 'B', 'C', 'D']);
|
|
@@ -1557,6 +1914,27 @@ var Queue = class _Queue extends LinearBase {
|
|
|
1557
1914
|
|
|
1558
1915
|
|
|
1559
1916
|
|
|
1917
|
+
|
|
1918
|
+
|
|
1919
|
+
|
|
1920
|
+
|
|
1921
|
+
|
|
1922
|
+
|
|
1923
|
+
|
|
1924
|
+
|
|
1925
|
+
|
|
1926
|
+
|
|
1927
|
+
|
|
1928
|
+
|
|
1929
|
+
|
|
1930
|
+
|
|
1931
|
+
|
|
1932
|
+
|
|
1933
|
+
|
|
1934
|
+
|
|
1935
|
+
|
|
1936
|
+
|
|
1937
|
+
|
|
1560
1938
|
* @example
|
|
1561
1939
|
* // basic Queue creation and push operation
|
|
1562
1940
|
* // Create a simple Queue with initial values
|
|
@@ -1602,6 +1980,27 @@ var Queue = class _Queue extends LinearBase {
|
|
|
1602
1980
|
|
|
1603
1981
|
|
|
1604
1982
|
|
|
1983
|
+
|
|
1984
|
+
|
|
1985
|
+
|
|
1986
|
+
|
|
1987
|
+
|
|
1988
|
+
|
|
1989
|
+
|
|
1990
|
+
|
|
1991
|
+
|
|
1992
|
+
|
|
1993
|
+
|
|
1994
|
+
|
|
1995
|
+
|
|
1996
|
+
|
|
1997
|
+
|
|
1998
|
+
|
|
1999
|
+
|
|
2000
|
+
|
|
2001
|
+
|
|
2002
|
+
|
|
2003
|
+
|
|
1605
2004
|
* @example
|
|
1606
2005
|
* // Queue shift and peek operations
|
|
1607
2006
|
* const queue = new Queue<number>([10, 20, 30, 40]);
|
|
@@ -1637,6 +2036,27 @@ var Queue = class _Queue extends LinearBase {
|
|
|
1637
2036
|
|
|
1638
2037
|
|
|
1639
2038
|
|
|
2039
|
+
|
|
2040
|
+
|
|
2041
|
+
|
|
2042
|
+
|
|
2043
|
+
|
|
2044
|
+
|
|
2045
|
+
|
|
2046
|
+
|
|
2047
|
+
|
|
2048
|
+
|
|
2049
|
+
|
|
2050
|
+
|
|
2051
|
+
|
|
2052
|
+
|
|
2053
|
+
|
|
2054
|
+
|
|
2055
|
+
|
|
2056
|
+
|
|
2057
|
+
|
|
2058
|
+
|
|
2059
|
+
|
|
1640
2060
|
* @example
|
|
1641
2061
|
* // Remove specific element
|
|
1642
2062
|
* const q = new Queue<number>([1, 2, 3, 2]);
|
|
@@ -1665,6 +2085,27 @@ var Queue = class _Queue extends LinearBase {
|
|
|
1665
2085
|
|
|
1666
2086
|
|
|
1667
2087
|
|
|
2088
|
+
|
|
2089
|
+
|
|
2090
|
+
|
|
2091
|
+
|
|
2092
|
+
|
|
2093
|
+
|
|
2094
|
+
|
|
2095
|
+
|
|
2096
|
+
|
|
2097
|
+
|
|
2098
|
+
|
|
2099
|
+
|
|
2100
|
+
|
|
2101
|
+
|
|
2102
|
+
|
|
2103
|
+
|
|
2104
|
+
|
|
2105
|
+
|
|
2106
|
+
|
|
2107
|
+
|
|
2108
|
+
|
|
1668
2109
|
* @example
|
|
1669
2110
|
* // Access element by index
|
|
1670
2111
|
* const q = new Queue<string>(['a', 'b', 'c']);
|
|
@@ -1734,6 +2175,27 @@ var Queue = class _Queue extends LinearBase {
|
|
|
1734
2175
|
|
|
1735
2176
|
|
|
1736
2177
|
|
|
2178
|
+
|
|
2179
|
+
|
|
2180
|
+
|
|
2181
|
+
|
|
2182
|
+
|
|
2183
|
+
|
|
2184
|
+
|
|
2185
|
+
|
|
2186
|
+
|
|
2187
|
+
|
|
2188
|
+
|
|
2189
|
+
|
|
2190
|
+
|
|
2191
|
+
|
|
2192
|
+
|
|
2193
|
+
|
|
2194
|
+
|
|
2195
|
+
|
|
2196
|
+
|
|
2197
|
+
|
|
2198
|
+
|
|
1737
2199
|
* @example
|
|
1738
2200
|
* // Remove all elements
|
|
1739
2201
|
* const q = new Queue<number>([1, 2, 3]);
|
|
@@ -1756,6 +2218,27 @@ var Queue = class _Queue extends LinearBase {
|
|
|
1756
2218
|
|
|
1757
2219
|
|
|
1758
2220
|
|
|
2221
|
+
|
|
2222
|
+
|
|
2223
|
+
|
|
2224
|
+
|
|
2225
|
+
|
|
2226
|
+
|
|
2227
|
+
|
|
2228
|
+
|
|
2229
|
+
|
|
2230
|
+
|
|
2231
|
+
|
|
2232
|
+
|
|
2233
|
+
|
|
2234
|
+
|
|
2235
|
+
|
|
2236
|
+
|
|
2237
|
+
|
|
2238
|
+
|
|
2239
|
+
|
|
2240
|
+
|
|
2241
|
+
|
|
1759
2242
|
* @example
|
|
1760
2243
|
* // Reclaim unused memory
|
|
1761
2244
|
* const q = new Queue<number>([1, 2, 3, 4, 5]);
|
|
@@ -1801,6 +2284,27 @@ var Queue = class _Queue extends LinearBase {
|
|
|
1801
2284
|
|
|
1802
2285
|
|
|
1803
2286
|
|
|
2287
|
+
|
|
2288
|
+
|
|
2289
|
+
|
|
2290
|
+
|
|
2291
|
+
|
|
2292
|
+
|
|
2293
|
+
|
|
2294
|
+
|
|
2295
|
+
|
|
2296
|
+
|
|
2297
|
+
|
|
2298
|
+
|
|
2299
|
+
|
|
2300
|
+
|
|
2301
|
+
|
|
2302
|
+
|
|
2303
|
+
|
|
2304
|
+
|
|
2305
|
+
|
|
2306
|
+
|
|
2307
|
+
|
|
1804
2308
|
* @example
|
|
1805
2309
|
* // Create independent copy
|
|
1806
2310
|
* const q = new Queue<number>([1, 2, 3]);
|
|
@@ -1830,6 +2334,27 @@ var Queue = class _Queue extends LinearBase {
|
|
|
1830
2334
|
|
|
1831
2335
|
|
|
1832
2336
|
|
|
2337
|
+
|
|
2338
|
+
|
|
2339
|
+
|
|
2340
|
+
|
|
2341
|
+
|
|
2342
|
+
|
|
2343
|
+
|
|
2344
|
+
|
|
2345
|
+
|
|
2346
|
+
|
|
2347
|
+
|
|
2348
|
+
|
|
2349
|
+
|
|
2350
|
+
|
|
2351
|
+
|
|
2352
|
+
|
|
2353
|
+
|
|
2354
|
+
|
|
2355
|
+
|
|
2356
|
+
|
|
2357
|
+
|
|
1833
2358
|
* @example
|
|
1834
2359
|
* // Filter elements
|
|
1835
2360
|
* const q = new Queue<number>([1, 2, 3, 4, 5]);
|
|
@@ -1863,6 +2388,27 @@ var Queue = class _Queue extends LinearBase {
|
|
|
1863
2388
|
|
|
1864
2389
|
|
|
1865
2390
|
|
|
2391
|
+
|
|
2392
|
+
|
|
2393
|
+
|
|
2394
|
+
|
|
2395
|
+
|
|
2396
|
+
|
|
2397
|
+
|
|
2398
|
+
|
|
2399
|
+
|
|
2400
|
+
|
|
2401
|
+
|
|
2402
|
+
|
|
2403
|
+
|
|
2404
|
+
|
|
2405
|
+
|
|
2406
|
+
|
|
2407
|
+
|
|
2408
|
+
|
|
2409
|
+
|
|
2410
|
+
|
|
2411
|
+
|
|
1866
2412
|
* @example
|
|
1867
2413
|
* // Transform elements
|
|
1868
2414
|
* const q = new Queue<number>([1, 2, 3]);
|
|
@@ -2978,6 +3524,27 @@ var DirectedGraph = class _DirectedGraph extends AbstractGraph {
|
|
|
2978
3524
|
|
|
2979
3525
|
|
|
2980
3526
|
|
|
3527
|
+
|
|
3528
|
+
|
|
3529
|
+
|
|
3530
|
+
|
|
3531
|
+
|
|
3532
|
+
|
|
3533
|
+
|
|
3534
|
+
|
|
3535
|
+
|
|
3536
|
+
|
|
3537
|
+
|
|
3538
|
+
|
|
3539
|
+
|
|
3540
|
+
|
|
3541
|
+
|
|
3542
|
+
|
|
3543
|
+
|
|
3544
|
+
|
|
3545
|
+
|
|
3546
|
+
|
|
3547
|
+
|
|
2981
3548
|
* @example
|
|
2982
3549
|
* // Get edge between vertices
|
|
2983
3550
|
* const g = new DirectedGraph();
|
|
@@ -3042,6 +3609,27 @@ var DirectedGraph = class _DirectedGraph extends AbstractGraph {
|
|
|
3042
3609
|
|
|
3043
3610
|
|
|
3044
3611
|
|
|
3612
|
+
|
|
3613
|
+
|
|
3614
|
+
|
|
3615
|
+
|
|
3616
|
+
|
|
3617
|
+
|
|
3618
|
+
|
|
3619
|
+
|
|
3620
|
+
|
|
3621
|
+
|
|
3622
|
+
|
|
3623
|
+
|
|
3624
|
+
|
|
3625
|
+
|
|
3626
|
+
|
|
3627
|
+
|
|
3628
|
+
|
|
3629
|
+
|
|
3630
|
+
|
|
3631
|
+
|
|
3632
|
+
|
|
3045
3633
|
* @example
|
|
3046
3634
|
* // DirectedGraph deleteEdge and vertex operations
|
|
3047
3635
|
* const graph = new DirectedGraph<string>();
|
|
@@ -3104,6 +3692,27 @@ var DirectedGraph = class _DirectedGraph extends AbstractGraph {
|
|
|
3104
3692
|
|
|
3105
3693
|
|
|
3106
3694
|
|
|
3695
|
+
|
|
3696
|
+
|
|
3697
|
+
|
|
3698
|
+
|
|
3699
|
+
|
|
3700
|
+
|
|
3701
|
+
|
|
3702
|
+
|
|
3703
|
+
|
|
3704
|
+
|
|
3705
|
+
|
|
3706
|
+
|
|
3707
|
+
|
|
3708
|
+
|
|
3709
|
+
|
|
3710
|
+
|
|
3711
|
+
|
|
3712
|
+
|
|
3713
|
+
|
|
3714
|
+
|
|
3715
|
+
|
|
3107
3716
|
* @example
|
|
3108
3717
|
* // Remove a vertex
|
|
3109
3718
|
* const g = new DirectedGraph();
|
|
@@ -3157,6 +3766,27 @@ var DirectedGraph = class _DirectedGraph extends AbstractGraph {
|
|
|
3157
3766
|
|
|
3158
3767
|
|
|
3159
3768
|
|
|
3769
|
+
|
|
3770
|
+
|
|
3771
|
+
|
|
3772
|
+
|
|
3773
|
+
|
|
3774
|
+
|
|
3775
|
+
|
|
3776
|
+
|
|
3777
|
+
|
|
3778
|
+
|
|
3779
|
+
|
|
3780
|
+
|
|
3781
|
+
|
|
3782
|
+
|
|
3783
|
+
|
|
3784
|
+
|
|
3785
|
+
|
|
3786
|
+
|
|
3787
|
+
|
|
3788
|
+
|
|
3789
|
+
|
|
3160
3790
|
* @example
|
|
3161
3791
|
* // Get incoming edges
|
|
3162
3792
|
* const g = new DirectedGraph();
|
|
@@ -3187,6 +3817,27 @@ var DirectedGraph = class _DirectedGraph extends AbstractGraph {
|
|
|
3187
3817
|
|
|
3188
3818
|
|
|
3189
3819
|
|
|
3820
|
+
|
|
3821
|
+
|
|
3822
|
+
|
|
3823
|
+
|
|
3824
|
+
|
|
3825
|
+
|
|
3826
|
+
|
|
3827
|
+
|
|
3828
|
+
|
|
3829
|
+
|
|
3830
|
+
|
|
3831
|
+
|
|
3832
|
+
|
|
3833
|
+
|
|
3834
|
+
|
|
3835
|
+
|
|
3836
|
+
|
|
3837
|
+
|
|
3838
|
+
|
|
3839
|
+
|
|
3840
|
+
|
|
3190
3841
|
* @example
|
|
3191
3842
|
* // Get outgoing edges
|
|
3192
3843
|
* const g = new DirectedGraph();
|
|
@@ -3270,6 +3921,27 @@ var DirectedGraph = class _DirectedGraph extends AbstractGraph {
|
|
|
3270
3921
|
|
|
3271
3922
|
|
|
3272
3923
|
|
|
3924
|
+
|
|
3925
|
+
|
|
3926
|
+
|
|
3927
|
+
|
|
3928
|
+
|
|
3929
|
+
|
|
3930
|
+
|
|
3931
|
+
|
|
3932
|
+
|
|
3933
|
+
|
|
3934
|
+
|
|
3935
|
+
|
|
3936
|
+
|
|
3937
|
+
|
|
3938
|
+
|
|
3939
|
+
|
|
3940
|
+
|
|
3941
|
+
|
|
3942
|
+
|
|
3943
|
+
|
|
3944
|
+
|
|
3273
3945
|
* @example
|
|
3274
3946
|
* // DirectedGraph topologicalSort for task scheduling
|
|
3275
3947
|
* const graph = new DirectedGraph<string>();
|
|
@@ -3334,6 +4006,27 @@ var DirectedGraph = class _DirectedGraph extends AbstractGraph {
|
|
|
3334
4006
|
|
|
3335
4007
|
|
|
3336
4008
|
|
|
4009
|
+
|
|
4010
|
+
|
|
4011
|
+
|
|
4012
|
+
|
|
4013
|
+
|
|
4014
|
+
|
|
4015
|
+
|
|
4016
|
+
|
|
4017
|
+
|
|
4018
|
+
|
|
4019
|
+
|
|
4020
|
+
|
|
4021
|
+
|
|
4022
|
+
|
|
4023
|
+
|
|
4024
|
+
|
|
4025
|
+
|
|
4026
|
+
|
|
4027
|
+
|
|
4028
|
+
|
|
4029
|
+
|
|
3337
4030
|
* @example
|
|
3338
4031
|
* // Get all edges
|
|
3339
4032
|
* const g = new DirectedGraph();
|
|
@@ -3360,6 +4053,27 @@ var DirectedGraph = class _DirectedGraph extends AbstractGraph {
|
|
|
3360
4053
|
|
|
3361
4054
|
|
|
3362
4055
|
|
|
4056
|
+
|
|
4057
|
+
|
|
4058
|
+
|
|
4059
|
+
|
|
4060
|
+
|
|
4061
|
+
|
|
4062
|
+
|
|
4063
|
+
|
|
4064
|
+
|
|
4065
|
+
|
|
4066
|
+
|
|
4067
|
+
|
|
4068
|
+
|
|
4069
|
+
|
|
4070
|
+
|
|
4071
|
+
|
|
4072
|
+
|
|
4073
|
+
|
|
4074
|
+
|
|
4075
|
+
|
|
4076
|
+
|
|
3363
4077
|
* @example
|
|
3364
4078
|
* // Get outgoing neighbors
|
|
3365
4079
|
* const g = new DirectedGraph();
|
|
@@ -3439,6 +4153,27 @@ var DirectedGraph = class _DirectedGraph extends AbstractGraph {
|
|
|
3439
4153
|
|
|
3440
4154
|
|
|
3441
4155
|
|
|
4156
|
+
|
|
4157
|
+
|
|
4158
|
+
|
|
4159
|
+
|
|
4160
|
+
|
|
4161
|
+
|
|
4162
|
+
|
|
4163
|
+
|
|
4164
|
+
|
|
4165
|
+
|
|
4166
|
+
|
|
4167
|
+
|
|
4168
|
+
|
|
4169
|
+
|
|
4170
|
+
|
|
4171
|
+
|
|
4172
|
+
|
|
4173
|
+
|
|
4174
|
+
|
|
4175
|
+
|
|
4176
|
+
|
|
3442
4177
|
* @example
|
|
3443
4178
|
* // Find strongly connected components
|
|
3444
4179
|
* const g = new DirectedGraph();
|
|
@@ -3521,6 +4256,27 @@ var DirectedGraph = class _DirectedGraph extends AbstractGraph {
|
|
|
3521
4256
|
|
|
3522
4257
|
|
|
3523
4258
|
|
|
4259
|
+
|
|
4260
|
+
|
|
4261
|
+
|
|
4262
|
+
|
|
4263
|
+
|
|
4264
|
+
|
|
4265
|
+
|
|
4266
|
+
|
|
4267
|
+
|
|
4268
|
+
|
|
4269
|
+
|
|
4270
|
+
|
|
4271
|
+
|
|
4272
|
+
|
|
4273
|
+
|
|
4274
|
+
|
|
4275
|
+
|
|
4276
|
+
|
|
4277
|
+
|
|
4278
|
+
|
|
4279
|
+
|
|
3524
4280
|
* @example
|
|
3525
4281
|
* // Get strongly connected components
|
|
3526
4282
|
* const g = new DirectedGraph();
|