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
|
@@ -475,6 +475,198 @@ var _IterableElementBase = class _IterableElementBase {
|
|
|
475
475
|
__name(_IterableElementBase, "IterableElementBase");
|
|
476
476
|
var IterableElementBase = _IterableElementBase;
|
|
477
477
|
|
|
478
|
+
// src/data-structures/base/linear-base.ts
|
|
479
|
+
var _LinearBase = class _LinearBase extends IterableElementBase {
|
|
480
|
+
/**
|
|
481
|
+
* Construct a linear container with runtime options.
|
|
482
|
+
* @param options - `{ maxLen?, ... }` bounds/behavior options.
|
|
483
|
+
* @remarks Time O(1), Space O(1)
|
|
484
|
+
*/
|
|
485
|
+
constructor(options) {
|
|
486
|
+
super(options);
|
|
487
|
+
__publicField(this, "_maxLen", -1);
|
|
488
|
+
if (options) {
|
|
489
|
+
const { maxLen } = options;
|
|
490
|
+
if (typeof maxLen === "number" && maxLen > 0 && maxLen % 1 === 0) this._maxLen = maxLen;
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
/**
|
|
494
|
+
* Upper bound for length (if positive), or `-1` when unbounded.
|
|
495
|
+
* @returns Maximum allowed length.
|
|
496
|
+
* @remarks Time O(1), Space O(1)
|
|
497
|
+
*/
|
|
498
|
+
get maxLen() {
|
|
499
|
+
return this._maxLen;
|
|
500
|
+
}
|
|
501
|
+
/**
|
|
502
|
+
* First index of a value from the left.
|
|
503
|
+
* @param searchElement - Value to match.
|
|
504
|
+
* @param fromIndex - Start position (supports negative index).
|
|
505
|
+
* @returns Index or `-1` if not found.
|
|
506
|
+
* @remarks Time O(n), Space O(1)
|
|
507
|
+
*/
|
|
508
|
+
indexOf(searchElement, fromIndex = 0) {
|
|
509
|
+
if (this.length === 0) return -1;
|
|
510
|
+
if (fromIndex < 0) fromIndex = this.length + fromIndex;
|
|
511
|
+
if (fromIndex < 0) fromIndex = 0;
|
|
512
|
+
for (let i = fromIndex; i < this.length; i++) {
|
|
513
|
+
const element = this.at(i);
|
|
514
|
+
if (element === searchElement) return i;
|
|
515
|
+
}
|
|
516
|
+
return -1;
|
|
517
|
+
}
|
|
518
|
+
/**
|
|
519
|
+
* Last index of a value from the right.
|
|
520
|
+
* @param searchElement - Value to match.
|
|
521
|
+
* @param fromIndex - Start position (supports negative index).
|
|
522
|
+
* @returns Index or `-1` if not found.
|
|
523
|
+
* @remarks Time O(n), Space O(1)
|
|
524
|
+
*/
|
|
525
|
+
lastIndexOf(searchElement, fromIndex = this.length - 1) {
|
|
526
|
+
if (this.length === 0) return -1;
|
|
527
|
+
if (fromIndex >= this.length) fromIndex = this.length - 1;
|
|
528
|
+
if (fromIndex < 0) fromIndex = this.length + fromIndex;
|
|
529
|
+
for (let i = fromIndex; i >= 0; i--) {
|
|
530
|
+
const element = this.at(i);
|
|
531
|
+
if (element === searchElement) return i;
|
|
532
|
+
}
|
|
533
|
+
return -1;
|
|
534
|
+
}
|
|
535
|
+
/**
|
|
536
|
+
* Find the first index matching a predicate.
|
|
537
|
+
* @param predicate - `(element, index, self) => boolean`.
|
|
538
|
+
* @param thisArg - Optional `this` for callback.
|
|
539
|
+
* @returns Index or `-1`.
|
|
540
|
+
* @remarks Time O(n), Space O(1)
|
|
541
|
+
*/
|
|
542
|
+
findIndex(predicate, thisArg) {
|
|
543
|
+
for (let i = 0; i < this.length; i++) {
|
|
544
|
+
const item = this.at(i);
|
|
545
|
+
if (item !== void 0 && predicate.call(thisArg, item, i, this)) return i;
|
|
546
|
+
}
|
|
547
|
+
return -1;
|
|
548
|
+
}
|
|
549
|
+
/**
|
|
550
|
+
* Concatenate elements and/or containers.
|
|
551
|
+
* @param items - Elements or other containers.
|
|
552
|
+
* @returns New container with combined elements (`this` type).
|
|
553
|
+
* @remarks Time O(sum(length)), Space O(sum(length))
|
|
554
|
+
*/
|
|
555
|
+
concat(...items) {
|
|
556
|
+
const newList = this.clone();
|
|
557
|
+
for (const item of items) {
|
|
558
|
+
if (item instanceof _LinearBase) {
|
|
559
|
+
newList.pushMany(item);
|
|
560
|
+
} else {
|
|
561
|
+
newList.push(item);
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
return newList;
|
|
565
|
+
}
|
|
566
|
+
/**
|
|
567
|
+
* In-place stable order via array sort semantics.
|
|
568
|
+
* @param compareFn - Comparator `(a, b) => number`.
|
|
569
|
+
* @returns This container.
|
|
570
|
+
* @remarks Time O(n log n), Space O(n) (materializes to array temporarily)
|
|
571
|
+
*/
|
|
572
|
+
sort(compareFn) {
|
|
573
|
+
const arr = this.toArray();
|
|
574
|
+
arr.sort(compareFn);
|
|
575
|
+
this.clear();
|
|
576
|
+
for (const item of arr) this.push(item);
|
|
577
|
+
return this;
|
|
578
|
+
}
|
|
579
|
+
/**
|
|
580
|
+
* Remove and/or insert elements at a position (array-compatible).
|
|
581
|
+
* @param start - Start index (supports negative index).
|
|
582
|
+
* @param deleteCount - How many to remove.
|
|
583
|
+
* @param items - Elements to insert.
|
|
584
|
+
* @returns Removed elements as a new list (`this` type).
|
|
585
|
+
* @remarks Time O(n + m), Space O(min(n, m)) where `m = items.length`
|
|
586
|
+
*/
|
|
587
|
+
splice(start, deleteCount = 0, ...items) {
|
|
588
|
+
const removedList = this._createInstance();
|
|
589
|
+
start = start < 0 ? this.length + start : start;
|
|
590
|
+
start = Math.max(0, Math.min(start, this.length));
|
|
591
|
+
deleteCount = Math.max(0, Math.min(deleteCount, this.length - start));
|
|
592
|
+
for (let i = 0; i < deleteCount; i++) {
|
|
593
|
+
const removed = this.deleteAt(start);
|
|
594
|
+
if (removed !== void 0) {
|
|
595
|
+
removedList.push(removed);
|
|
596
|
+
}
|
|
597
|
+
}
|
|
598
|
+
for (let i = 0; i < items.length; i++) {
|
|
599
|
+
this.addAt(start + i, items[i]);
|
|
600
|
+
}
|
|
601
|
+
return removedList;
|
|
602
|
+
}
|
|
603
|
+
/**
|
|
604
|
+
* Join all elements into a string.
|
|
605
|
+
* @param separator - Separator string.
|
|
606
|
+
* @returns Concatenated string.
|
|
607
|
+
* @remarks Time O(n), Space O(n)
|
|
608
|
+
*/
|
|
609
|
+
join(separator = ",") {
|
|
610
|
+
return this.toArray().join(separator);
|
|
611
|
+
}
|
|
612
|
+
/**
|
|
613
|
+
* Snapshot elements into a reversed array.
|
|
614
|
+
* @returns New reversed array.
|
|
615
|
+
* @remarks Time O(n), Space O(n)
|
|
616
|
+
*/
|
|
617
|
+
toReversedArray() {
|
|
618
|
+
const array = [];
|
|
619
|
+
for (let i = this.length - 1; i >= 0; i--) {
|
|
620
|
+
array.push(this.at(i));
|
|
621
|
+
}
|
|
622
|
+
return array;
|
|
623
|
+
}
|
|
624
|
+
reduceRight(callbackfn, initialValue) {
|
|
625
|
+
let accumulator = initialValue != null ? initialValue : 0;
|
|
626
|
+
for (let i = this.length - 1; i >= 0; i--) {
|
|
627
|
+
accumulator = callbackfn(accumulator, this.at(i), i, this);
|
|
628
|
+
}
|
|
629
|
+
return accumulator;
|
|
630
|
+
}
|
|
631
|
+
/**
|
|
632
|
+
* Create a shallow copy of a subrange.
|
|
633
|
+
* @param start - Inclusive start (supports negative index).
|
|
634
|
+
* @param end - Exclusive end (supports negative index).
|
|
635
|
+
* @returns New list with the range (`this` type).
|
|
636
|
+
* @remarks Time O(n), Space O(n)
|
|
637
|
+
*/
|
|
638
|
+
slice(start = 0, end = this.length) {
|
|
639
|
+
start = start < 0 ? this.length + start : start;
|
|
640
|
+
end = end < 0 ? this.length + end : end;
|
|
641
|
+
const newList = this._createInstance();
|
|
642
|
+
for (let i = start; i < end; i++) {
|
|
643
|
+
newList.push(this.at(i));
|
|
644
|
+
}
|
|
645
|
+
return newList;
|
|
646
|
+
}
|
|
647
|
+
/**
|
|
648
|
+
* Fill a range with a value.
|
|
649
|
+
* @param value - Value to set.
|
|
650
|
+
* @param start - Inclusive start.
|
|
651
|
+
* @param end - Exclusive end.
|
|
652
|
+
* @returns This list.
|
|
653
|
+
* @remarks Time O(n), Space O(1)
|
|
654
|
+
*/
|
|
655
|
+
fill(value, start = 0, end = this.length) {
|
|
656
|
+
start = start < 0 ? this.length + start : start;
|
|
657
|
+
end = end < 0 ? this.length + end : end;
|
|
658
|
+
if (start < 0) start = 0;
|
|
659
|
+
if (end > this.length) end = this.length;
|
|
660
|
+
if (start >= end) return this;
|
|
661
|
+
for (let i = start; i < end; i++) {
|
|
662
|
+
this.setAt(i, value);
|
|
663
|
+
}
|
|
664
|
+
return this;
|
|
665
|
+
}
|
|
666
|
+
};
|
|
667
|
+
__name(_LinearBase, "LinearBase");
|
|
668
|
+
var LinearBase = _LinearBase;
|
|
669
|
+
|
|
478
670
|
// src/data-structures/heap/heap.ts
|
|
479
671
|
var _Heap = class _Heap extends IterableElementBase {
|
|
480
672
|
/**
|
|
@@ -526,6 +718,27 @@ var _Heap = class _Heap extends IterableElementBase {
|
|
|
526
718
|
|
|
527
719
|
|
|
528
720
|
|
|
721
|
+
|
|
722
|
+
|
|
723
|
+
|
|
724
|
+
|
|
725
|
+
|
|
726
|
+
|
|
727
|
+
|
|
728
|
+
|
|
729
|
+
|
|
730
|
+
|
|
731
|
+
|
|
732
|
+
|
|
733
|
+
|
|
734
|
+
|
|
735
|
+
|
|
736
|
+
|
|
737
|
+
|
|
738
|
+
|
|
739
|
+
|
|
740
|
+
|
|
741
|
+
|
|
529
742
|
* @example
|
|
530
743
|
* // Track heap capacity
|
|
531
744
|
* const heap = new Heap<number>();
|
|
@@ -589,6 +802,27 @@ var _Heap = class _Heap extends IterableElementBase {
|
|
|
589
802
|
|
|
590
803
|
|
|
591
804
|
|
|
805
|
+
|
|
806
|
+
|
|
807
|
+
|
|
808
|
+
|
|
809
|
+
|
|
810
|
+
|
|
811
|
+
|
|
812
|
+
|
|
813
|
+
|
|
814
|
+
|
|
815
|
+
|
|
816
|
+
|
|
817
|
+
|
|
818
|
+
|
|
819
|
+
|
|
820
|
+
|
|
821
|
+
|
|
822
|
+
|
|
823
|
+
|
|
824
|
+
|
|
825
|
+
|
|
592
826
|
* @example
|
|
593
827
|
* // basic Heap creation and add operation
|
|
594
828
|
* // Create a min heap (default)
|
|
@@ -622,6 +856,27 @@ var _Heap = class _Heap extends IterableElementBase {
|
|
|
622
856
|
|
|
623
857
|
|
|
624
858
|
|
|
859
|
+
|
|
860
|
+
|
|
861
|
+
|
|
862
|
+
|
|
863
|
+
|
|
864
|
+
|
|
865
|
+
|
|
866
|
+
|
|
867
|
+
|
|
868
|
+
|
|
869
|
+
|
|
870
|
+
|
|
871
|
+
|
|
872
|
+
|
|
873
|
+
|
|
874
|
+
|
|
875
|
+
|
|
876
|
+
|
|
877
|
+
|
|
878
|
+
|
|
879
|
+
|
|
625
880
|
* @example
|
|
626
881
|
* // Add multiple elements
|
|
627
882
|
* const heap = new Heap<number>([], { comparator: (a, b) => a - b });
|
|
@@ -657,6 +912,27 @@ var _Heap = class _Heap extends IterableElementBase {
|
|
|
657
912
|
|
|
658
913
|
|
|
659
914
|
|
|
915
|
+
|
|
916
|
+
|
|
917
|
+
|
|
918
|
+
|
|
919
|
+
|
|
920
|
+
|
|
921
|
+
|
|
922
|
+
|
|
923
|
+
|
|
924
|
+
|
|
925
|
+
|
|
926
|
+
|
|
927
|
+
|
|
928
|
+
|
|
929
|
+
|
|
930
|
+
|
|
931
|
+
|
|
932
|
+
|
|
933
|
+
|
|
934
|
+
|
|
935
|
+
|
|
660
936
|
* @example
|
|
661
937
|
* // Heap with custom comparator (MaxHeap behavior)
|
|
662
938
|
* interface Task {
|
|
@@ -708,6 +984,27 @@ var _Heap = class _Heap extends IterableElementBase {
|
|
|
708
984
|
|
|
709
985
|
|
|
710
986
|
|
|
987
|
+
|
|
988
|
+
|
|
989
|
+
|
|
990
|
+
|
|
991
|
+
|
|
992
|
+
|
|
993
|
+
|
|
994
|
+
|
|
995
|
+
|
|
996
|
+
|
|
997
|
+
|
|
998
|
+
|
|
999
|
+
|
|
1000
|
+
|
|
1001
|
+
|
|
1002
|
+
|
|
1003
|
+
|
|
1004
|
+
|
|
1005
|
+
|
|
1006
|
+
|
|
1007
|
+
|
|
711
1008
|
* @example
|
|
712
1009
|
* // Heap for event processing with priority
|
|
713
1010
|
* interface Event {
|
|
@@ -784,6 +1081,27 @@ var _Heap = class _Heap extends IterableElementBase {
|
|
|
784
1081
|
|
|
785
1082
|
|
|
786
1083
|
|
|
1084
|
+
|
|
1085
|
+
|
|
1086
|
+
|
|
1087
|
+
|
|
1088
|
+
|
|
1089
|
+
|
|
1090
|
+
|
|
1091
|
+
|
|
1092
|
+
|
|
1093
|
+
|
|
1094
|
+
|
|
1095
|
+
|
|
1096
|
+
|
|
1097
|
+
|
|
1098
|
+
|
|
1099
|
+
|
|
1100
|
+
|
|
1101
|
+
|
|
1102
|
+
|
|
1103
|
+
|
|
1104
|
+
|
|
787
1105
|
* @example
|
|
788
1106
|
* // Check if heap is empty
|
|
789
1107
|
* const heap = new Heap<number>([], { comparator: (a, b) => a - b });
|
|
@@ -807,6 +1125,27 @@ var _Heap = class _Heap extends IterableElementBase {
|
|
|
807
1125
|
|
|
808
1126
|
|
|
809
1127
|
|
|
1128
|
+
|
|
1129
|
+
|
|
1130
|
+
|
|
1131
|
+
|
|
1132
|
+
|
|
1133
|
+
|
|
1134
|
+
|
|
1135
|
+
|
|
1136
|
+
|
|
1137
|
+
|
|
1138
|
+
|
|
1139
|
+
|
|
1140
|
+
|
|
1141
|
+
|
|
1142
|
+
|
|
1143
|
+
|
|
1144
|
+
|
|
1145
|
+
|
|
1146
|
+
|
|
1147
|
+
|
|
1148
|
+
|
|
810
1149
|
* @example
|
|
811
1150
|
* // Remove all elements
|
|
812
1151
|
* const heap = new Heap<number>([1, 2, 3], { comparator: (a, b) => a - b });
|
|
@@ -833,6 +1172,27 @@ var _Heap = class _Heap extends IterableElementBase {
|
|
|
833
1172
|
* @returns True if found.
|
|
834
1173
|
|
|
835
1174
|
|
|
1175
|
+
|
|
1176
|
+
|
|
1177
|
+
|
|
1178
|
+
|
|
1179
|
+
|
|
1180
|
+
|
|
1181
|
+
|
|
1182
|
+
|
|
1183
|
+
|
|
1184
|
+
|
|
1185
|
+
|
|
1186
|
+
|
|
1187
|
+
|
|
1188
|
+
|
|
1189
|
+
|
|
1190
|
+
|
|
1191
|
+
|
|
1192
|
+
|
|
1193
|
+
|
|
1194
|
+
|
|
1195
|
+
|
|
836
1196
|
* @example
|
|
837
1197
|
* // Check element existence
|
|
838
1198
|
* const heap = new Heap<number>([3, 1, 2], { comparator: (a, b) => a - b });
|
|
@@ -856,6 +1216,27 @@ var _Heap = class _Heap extends IterableElementBase {
|
|
|
856
1216
|
|
|
857
1217
|
|
|
858
1218
|
|
|
1219
|
+
|
|
1220
|
+
|
|
1221
|
+
|
|
1222
|
+
|
|
1223
|
+
|
|
1224
|
+
|
|
1225
|
+
|
|
1226
|
+
|
|
1227
|
+
|
|
1228
|
+
|
|
1229
|
+
|
|
1230
|
+
|
|
1231
|
+
|
|
1232
|
+
|
|
1233
|
+
|
|
1234
|
+
|
|
1235
|
+
|
|
1236
|
+
|
|
1237
|
+
|
|
1238
|
+
|
|
1239
|
+
|
|
859
1240
|
* @example
|
|
860
1241
|
* // Remove specific element
|
|
861
1242
|
* const heap = new Heap<number>([3, 1, 4, 1, 5], { comparator: (a, b) => a - b });
|
|
@@ -925,6 +1306,27 @@ var _Heap = class _Heap extends IterableElementBase {
|
|
|
925
1306
|
* @returns Array of visited elements.
|
|
926
1307
|
|
|
927
1308
|
|
|
1309
|
+
|
|
1310
|
+
|
|
1311
|
+
|
|
1312
|
+
|
|
1313
|
+
|
|
1314
|
+
|
|
1315
|
+
|
|
1316
|
+
|
|
1317
|
+
|
|
1318
|
+
|
|
1319
|
+
|
|
1320
|
+
|
|
1321
|
+
|
|
1322
|
+
|
|
1323
|
+
|
|
1324
|
+
|
|
1325
|
+
|
|
1326
|
+
|
|
1327
|
+
|
|
1328
|
+
|
|
1329
|
+
|
|
928
1330
|
* @example
|
|
929
1331
|
* // Depth-first traversal
|
|
930
1332
|
* const heap = new Heap<number>([3, 1, 2], { comparator: (a, b) => a - b });
|
|
@@ -981,6 +1383,27 @@ var _Heap = class _Heap extends IterableElementBase {
|
|
|
981
1383
|
|
|
982
1384
|
|
|
983
1385
|
|
|
1386
|
+
|
|
1387
|
+
|
|
1388
|
+
|
|
1389
|
+
|
|
1390
|
+
|
|
1391
|
+
|
|
1392
|
+
|
|
1393
|
+
|
|
1394
|
+
|
|
1395
|
+
|
|
1396
|
+
|
|
1397
|
+
|
|
1398
|
+
|
|
1399
|
+
|
|
1400
|
+
|
|
1401
|
+
|
|
1402
|
+
|
|
1403
|
+
|
|
1404
|
+
|
|
1405
|
+
|
|
1406
|
+
|
|
984
1407
|
* @example
|
|
985
1408
|
* // Sort elements using heap
|
|
986
1409
|
* const heap = new Heap<number>([5, 1, 3, 2, 4]);
|
|
@@ -1010,6 +1433,27 @@ var _Heap = class _Heap extends IterableElementBase {
|
|
|
1010
1433
|
|
|
1011
1434
|
|
|
1012
1435
|
|
|
1436
|
+
|
|
1437
|
+
|
|
1438
|
+
|
|
1439
|
+
|
|
1440
|
+
|
|
1441
|
+
|
|
1442
|
+
|
|
1443
|
+
|
|
1444
|
+
|
|
1445
|
+
|
|
1446
|
+
|
|
1447
|
+
|
|
1448
|
+
|
|
1449
|
+
|
|
1450
|
+
|
|
1451
|
+
|
|
1452
|
+
|
|
1453
|
+
|
|
1454
|
+
|
|
1455
|
+
|
|
1456
|
+
|
|
1013
1457
|
* @example
|
|
1014
1458
|
* // Create independent copy
|
|
1015
1459
|
* const heap = new Heap<number>([3, 1, 4], { comparator: (a, b) => a - b });
|
|
@@ -1038,6 +1482,27 @@ var _Heap = class _Heap extends IterableElementBase {
|
|
|
1038
1482
|
|
|
1039
1483
|
|
|
1040
1484
|
|
|
1485
|
+
|
|
1486
|
+
|
|
1487
|
+
|
|
1488
|
+
|
|
1489
|
+
|
|
1490
|
+
|
|
1491
|
+
|
|
1492
|
+
|
|
1493
|
+
|
|
1494
|
+
|
|
1495
|
+
|
|
1496
|
+
|
|
1497
|
+
|
|
1498
|
+
|
|
1499
|
+
|
|
1500
|
+
|
|
1501
|
+
|
|
1502
|
+
|
|
1503
|
+
|
|
1504
|
+
|
|
1505
|
+
|
|
1041
1506
|
* @example
|
|
1042
1507
|
* // Filter elements
|
|
1043
1508
|
* const heap = new Heap<number>([1, 2, 3, 4, 5], { comparator: (a, b) => a - b });
|
|
@@ -1073,6 +1538,27 @@ var _Heap = class _Heap extends IterableElementBase {
|
|
|
1073
1538
|
|
|
1074
1539
|
|
|
1075
1540
|
|
|
1541
|
+
|
|
1542
|
+
|
|
1543
|
+
|
|
1544
|
+
|
|
1545
|
+
|
|
1546
|
+
|
|
1547
|
+
|
|
1548
|
+
|
|
1549
|
+
|
|
1550
|
+
|
|
1551
|
+
|
|
1552
|
+
|
|
1553
|
+
|
|
1554
|
+
|
|
1555
|
+
|
|
1556
|
+
|
|
1557
|
+
|
|
1558
|
+
|
|
1559
|
+
|
|
1560
|
+
|
|
1561
|
+
|
|
1076
1562
|
* @example
|
|
1077
1563
|
* // Transform elements
|
|
1078
1564
|
* const heap = new Heap<number>([1, 2, 3], { comparator: (a, b) => a - b });
|
|
@@ -1153,228 +1639,36 @@ var _Heap = class _Heap extends IterableElementBase {
|
|
|
1153
1639
|
* @returns A like-kind empty heap instance.
|
|
1154
1640
|
*/
|
|
1155
1641
|
_createInstance(options) {
|
|
1156
|
-
const Ctor = this.constructor;
|
|
1157
|
-
return new Ctor([], { comparator: this.comparator, toElementFn: this.toElementFn, ...options != null ? options : {} });
|
|
1158
|
-
}
|
|
1159
|
-
/**
|
|
1160
|
-
* (Protected) Create a like-kind instance seeded by elements.
|
|
1161
|
-
* @remarks Time O(N log N), Space O(N)
|
|
1162
|
-
* @template EM
|
|
1163
|
-
* @template RM
|
|
1164
|
-
* @param [elements] - Iterable of elements or raw values to seed.
|
|
1165
|
-
* @param [options] - Options forwarded to the constructor.
|
|
1166
|
-
* @returns A like-kind heap instance.
|
|
1167
|
-
*/
|
|
1168
|
-
_createLike(elements = [], options) {
|
|
1169
|
-
const Ctor = this.constructor;
|
|
1170
|
-
return new Ctor(elements, options);
|
|
1171
|
-
}
|
|
1172
|
-
/**
|
|
1173
|
-
* (Protected) Spawn an empty like-kind heap instance.
|
|
1174
|
-
* @remarks Time O(1), Space O(1)
|
|
1175
|
-
* @template EM
|
|
1176
|
-
* @template RM
|
|
1177
|
-
* @param [options] - Options forwarded to the constructor.
|
|
1178
|
-
* @returns An empty like-kind heap instance.
|
|
1179
|
-
*/
|
|
1180
|
-
_spawnLike(options) {
|
|
1181
|
-
return this._createLike([], options);
|
|
1182
|
-
}
|
|
1183
|
-
};
|
|
1184
|
-
__name(_Heap, "Heap");
|
|
1185
|
-
var Heap = _Heap;
|
|
1186
|
-
|
|
1187
|
-
// src/data-structures/base/linear-base.ts
|
|
1188
|
-
var _LinearBase = class _LinearBase extends IterableElementBase {
|
|
1189
|
-
/**
|
|
1190
|
-
* Construct a linear container with runtime options.
|
|
1191
|
-
* @param options - `{ maxLen?, ... }` bounds/behavior options.
|
|
1192
|
-
* @remarks Time O(1), Space O(1)
|
|
1193
|
-
*/
|
|
1194
|
-
constructor(options) {
|
|
1195
|
-
super(options);
|
|
1196
|
-
__publicField(this, "_maxLen", -1);
|
|
1197
|
-
if (options) {
|
|
1198
|
-
const { maxLen } = options;
|
|
1199
|
-
if (typeof maxLen === "number" && maxLen > 0 && maxLen % 1 === 0) this._maxLen = maxLen;
|
|
1200
|
-
}
|
|
1201
|
-
}
|
|
1202
|
-
/**
|
|
1203
|
-
* Upper bound for length (if positive), or `-1` when unbounded.
|
|
1204
|
-
* @returns Maximum allowed length.
|
|
1205
|
-
* @remarks Time O(1), Space O(1)
|
|
1206
|
-
*/
|
|
1207
|
-
get maxLen() {
|
|
1208
|
-
return this._maxLen;
|
|
1209
|
-
}
|
|
1210
|
-
/**
|
|
1211
|
-
* First index of a value from the left.
|
|
1212
|
-
* @param searchElement - Value to match.
|
|
1213
|
-
* @param fromIndex - Start position (supports negative index).
|
|
1214
|
-
* @returns Index or `-1` if not found.
|
|
1215
|
-
* @remarks Time O(n), Space O(1)
|
|
1216
|
-
*/
|
|
1217
|
-
indexOf(searchElement, fromIndex = 0) {
|
|
1218
|
-
if (this.length === 0) return -1;
|
|
1219
|
-
if (fromIndex < 0) fromIndex = this.length + fromIndex;
|
|
1220
|
-
if (fromIndex < 0) fromIndex = 0;
|
|
1221
|
-
for (let i = fromIndex; i < this.length; i++) {
|
|
1222
|
-
const element = this.at(i);
|
|
1223
|
-
if (element === searchElement) return i;
|
|
1224
|
-
}
|
|
1225
|
-
return -1;
|
|
1226
|
-
}
|
|
1227
|
-
/**
|
|
1228
|
-
* Last index of a value from the right.
|
|
1229
|
-
* @param searchElement - Value to match.
|
|
1230
|
-
* @param fromIndex - Start position (supports negative index).
|
|
1231
|
-
* @returns Index or `-1` if not found.
|
|
1232
|
-
* @remarks Time O(n), Space O(1)
|
|
1233
|
-
*/
|
|
1234
|
-
lastIndexOf(searchElement, fromIndex = this.length - 1) {
|
|
1235
|
-
if (this.length === 0) return -1;
|
|
1236
|
-
if (fromIndex >= this.length) fromIndex = this.length - 1;
|
|
1237
|
-
if (fromIndex < 0) fromIndex = this.length + fromIndex;
|
|
1238
|
-
for (let i = fromIndex; i >= 0; i--) {
|
|
1239
|
-
const element = this.at(i);
|
|
1240
|
-
if (element === searchElement) return i;
|
|
1241
|
-
}
|
|
1242
|
-
return -1;
|
|
1243
|
-
}
|
|
1244
|
-
/**
|
|
1245
|
-
* Find the first index matching a predicate.
|
|
1246
|
-
* @param predicate - `(element, index, self) => boolean`.
|
|
1247
|
-
* @param thisArg - Optional `this` for callback.
|
|
1248
|
-
* @returns Index or `-1`.
|
|
1249
|
-
* @remarks Time O(n), Space O(1)
|
|
1250
|
-
*/
|
|
1251
|
-
findIndex(predicate, thisArg) {
|
|
1252
|
-
for (let i = 0; i < this.length; i++) {
|
|
1253
|
-
const item = this.at(i);
|
|
1254
|
-
if (item !== void 0 && predicate.call(thisArg, item, i, this)) return i;
|
|
1255
|
-
}
|
|
1256
|
-
return -1;
|
|
1257
|
-
}
|
|
1258
|
-
/**
|
|
1259
|
-
* Concatenate elements and/or containers.
|
|
1260
|
-
* @param items - Elements or other containers.
|
|
1261
|
-
* @returns New container with combined elements (`this` type).
|
|
1262
|
-
* @remarks Time O(sum(length)), Space O(sum(length))
|
|
1263
|
-
*/
|
|
1264
|
-
concat(...items) {
|
|
1265
|
-
const newList = this.clone();
|
|
1266
|
-
for (const item of items) {
|
|
1267
|
-
if (item instanceof _LinearBase) {
|
|
1268
|
-
newList.pushMany(item);
|
|
1269
|
-
} else {
|
|
1270
|
-
newList.push(item);
|
|
1271
|
-
}
|
|
1272
|
-
}
|
|
1273
|
-
return newList;
|
|
1274
|
-
}
|
|
1275
|
-
/**
|
|
1276
|
-
* In-place stable order via array sort semantics.
|
|
1277
|
-
* @param compareFn - Comparator `(a, b) => number`.
|
|
1278
|
-
* @returns This container.
|
|
1279
|
-
* @remarks Time O(n log n), Space O(n) (materializes to array temporarily)
|
|
1280
|
-
*/
|
|
1281
|
-
sort(compareFn) {
|
|
1282
|
-
const arr = this.toArray();
|
|
1283
|
-
arr.sort(compareFn);
|
|
1284
|
-
this.clear();
|
|
1285
|
-
for (const item of arr) this.push(item);
|
|
1286
|
-
return this;
|
|
1287
|
-
}
|
|
1288
|
-
/**
|
|
1289
|
-
* Remove and/or insert elements at a position (array-compatible).
|
|
1290
|
-
* @param start - Start index (supports negative index).
|
|
1291
|
-
* @param deleteCount - How many to remove.
|
|
1292
|
-
* @param items - Elements to insert.
|
|
1293
|
-
* @returns Removed elements as a new list (`this` type).
|
|
1294
|
-
* @remarks Time O(n + m), Space O(min(n, m)) where `m = items.length`
|
|
1295
|
-
*/
|
|
1296
|
-
splice(start, deleteCount = 0, ...items) {
|
|
1297
|
-
const removedList = this._createInstance();
|
|
1298
|
-
start = start < 0 ? this.length + start : start;
|
|
1299
|
-
start = Math.max(0, Math.min(start, this.length));
|
|
1300
|
-
deleteCount = Math.max(0, Math.min(deleteCount, this.length - start));
|
|
1301
|
-
for (let i = 0; i < deleteCount; i++) {
|
|
1302
|
-
const removed = this.deleteAt(start);
|
|
1303
|
-
if (removed !== void 0) {
|
|
1304
|
-
removedList.push(removed);
|
|
1305
|
-
}
|
|
1306
|
-
}
|
|
1307
|
-
for (let i = 0; i < items.length; i++) {
|
|
1308
|
-
this.addAt(start + i, items[i]);
|
|
1309
|
-
}
|
|
1310
|
-
return removedList;
|
|
1311
|
-
}
|
|
1312
|
-
/**
|
|
1313
|
-
* Join all elements into a string.
|
|
1314
|
-
* @param separator - Separator string.
|
|
1315
|
-
* @returns Concatenated string.
|
|
1316
|
-
* @remarks Time O(n), Space O(n)
|
|
1317
|
-
*/
|
|
1318
|
-
join(separator = ",") {
|
|
1319
|
-
return this.toArray().join(separator);
|
|
1320
|
-
}
|
|
1321
|
-
/**
|
|
1322
|
-
* Snapshot elements into a reversed array.
|
|
1323
|
-
* @returns New reversed array.
|
|
1324
|
-
* @remarks Time O(n), Space O(n)
|
|
1325
|
-
*/
|
|
1326
|
-
toReversedArray() {
|
|
1327
|
-
const array = [];
|
|
1328
|
-
for (let i = this.length - 1; i >= 0; i--) {
|
|
1329
|
-
array.push(this.at(i));
|
|
1330
|
-
}
|
|
1331
|
-
return array;
|
|
1332
|
-
}
|
|
1333
|
-
reduceRight(callbackfn, initialValue) {
|
|
1334
|
-
let accumulator = initialValue != null ? initialValue : 0;
|
|
1335
|
-
for (let i = this.length - 1; i >= 0; i--) {
|
|
1336
|
-
accumulator = callbackfn(accumulator, this.at(i), i, this);
|
|
1337
|
-
}
|
|
1338
|
-
return accumulator;
|
|
1339
|
-
}
|
|
1340
|
-
/**
|
|
1341
|
-
* Create a shallow copy of a subrange.
|
|
1342
|
-
* @param start - Inclusive start (supports negative index).
|
|
1343
|
-
* @param end - Exclusive end (supports negative index).
|
|
1344
|
-
* @returns New list with the range (`this` type).
|
|
1345
|
-
* @remarks Time O(n), Space O(n)
|
|
1642
|
+
const Ctor = this.constructor;
|
|
1643
|
+
return new Ctor([], { comparator: this.comparator, toElementFn: this.toElementFn, ...options != null ? options : {} });
|
|
1644
|
+
}
|
|
1645
|
+
/**
|
|
1646
|
+
* (Protected) Create a like-kind instance seeded by elements.
|
|
1647
|
+
* @remarks Time O(N log N), Space O(N)
|
|
1648
|
+
* @template EM
|
|
1649
|
+
* @template RM
|
|
1650
|
+
* @param [elements] - Iterable of elements or raw values to seed.
|
|
1651
|
+
* @param [options] - Options forwarded to the constructor.
|
|
1652
|
+
* @returns A like-kind heap instance.
|
|
1346
1653
|
*/
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
const newList = this._createInstance();
|
|
1351
|
-
for (let i = start; i < end; i++) {
|
|
1352
|
-
newList.push(this.at(i));
|
|
1353
|
-
}
|
|
1354
|
-
return newList;
|
|
1654
|
+
_createLike(elements = [], options) {
|
|
1655
|
+
const Ctor = this.constructor;
|
|
1656
|
+
return new Ctor(elements, options);
|
|
1355
1657
|
}
|
|
1356
1658
|
/**
|
|
1357
|
-
*
|
|
1358
|
-
* @
|
|
1359
|
-
* @
|
|
1360
|
-
* @
|
|
1361
|
-
* @
|
|
1362
|
-
* @
|
|
1659
|
+
* (Protected) Spawn an empty like-kind heap instance.
|
|
1660
|
+
* @remarks Time O(1), Space O(1)
|
|
1661
|
+
* @template EM
|
|
1662
|
+
* @template RM
|
|
1663
|
+
* @param [options] - Options forwarded to the constructor.
|
|
1664
|
+
* @returns An empty like-kind heap instance.
|
|
1363
1665
|
*/
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
end = end < 0 ? this.length + end : end;
|
|
1367
|
-
if (start < 0) start = 0;
|
|
1368
|
-
if (end > this.length) end = this.length;
|
|
1369
|
-
if (start >= end) return this;
|
|
1370
|
-
for (let i = start; i < end; i++) {
|
|
1371
|
-
this.setAt(i, value);
|
|
1372
|
-
}
|
|
1373
|
-
return this;
|
|
1666
|
+
_spawnLike(options) {
|
|
1667
|
+
return this._createLike([], options);
|
|
1374
1668
|
}
|
|
1375
1669
|
};
|
|
1376
|
-
__name(
|
|
1377
|
-
var
|
|
1670
|
+
__name(_Heap, "Heap");
|
|
1671
|
+
var Heap = _Heap;
|
|
1378
1672
|
|
|
1379
1673
|
// src/data-structures/queue/queue.ts
|
|
1380
1674
|
var _Queue = class _Queue extends LinearBase {
|
|
@@ -1444,6 +1738,27 @@ var _Queue = class _Queue extends LinearBase {
|
|
|
1444
1738
|
|
|
1445
1739
|
|
|
1446
1740
|
|
|
1741
|
+
|
|
1742
|
+
|
|
1743
|
+
|
|
1744
|
+
|
|
1745
|
+
|
|
1746
|
+
|
|
1747
|
+
|
|
1748
|
+
|
|
1749
|
+
|
|
1750
|
+
|
|
1751
|
+
|
|
1752
|
+
|
|
1753
|
+
|
|
1754
|
+
|
|
1755
|
+
|
|
1756
|
+
|
|
1757
|
+
|
|
1758
|
+
|
|
1759
|
+
|
|
1760
|
+
|
|
1761
|
+
|
|
1447
1762
|
* @example
|
|
1448
1763
|
* // Track queue length
|
|
1449
1764
|
* const q = new Queue<number>();
|
|
@@ -1470,6 +1785,27 @@ var _Queue = class _Queue extends LinearBase {
|
|
|
1470
1785
|
|
|
1471
1786
|
|
|
1472
1787
|
|
|
1788
|
+
|
|
1789
|
+
|
|
1790
|
+
|
|
1791
|
+
|
|
1792
|
+
|
|
1793
|
+
|
|
1794
|
+
|
|
1795
|
+
|
|
1796
|
+
|
|
1797
|
+
|
|
1798
|
+
|
|
1799
|
+
|
|
1800
|
+
|
|
1801
|
+
|
|
1802
|
+
|
|
1803
|
+
|
|
1804
|
+
|
|
1805
|
+
|
|
1806
|
+
|
|
1807
|
+
|
|
1808
|
+
|
|
1473
1809
|
* @example
|
|
1474
1810
|
* // View the front element
|
|
1475
1811
|
* const q = new Queue<string>(['first', 'second', 'third']);
|
|
@@ -1512,6 +1848,27 @@ var _Queue = class _Queue extends LinearBase {
|
|
|
1512
1848
|
|
|
1513
1849
|
|
|
1514
1850
|
|
|
1851
|
+
|
|
1852
|
+
|
|
1853
|
+
|
|
1854
|
+
|
|
1855
|
+
|
|
1856
|
+
|
|
1857
|
+
|
|
1858
|
+
|
|
1859
|
+
|
|
1860
|
+
|
|
1861
|
+
|
|
1862
|
+
|
|
1863
|
+
|
|
1864
|
+
|
|
1865
|
+
|
|
1866
|
+
|
|
1867
|
+
|
|
1868
|
+
|
|
1869
|
+
|
|
1870
|
+
|
|
1871
|
+
|
|
1515
1872
|
* @example
|
|
1516
1873
|
* // Queue for...of iteration and isEmpty check
|
|
1517
1874
|
* const queue = new Queue<string>(['A', 'B', 'C', 'D']);
|
|
@@ -1550,6 +1907,27 @@ var _Queue = class _Queue extends LinearBase {
|
|
|
1550
1907
|
|
|
1551
1908
|
|
|
1552
1909
|
|
|
1910
|
+
|
|
1911
|
+
|
|
1912
|
+
|
|
1913
|
+
|
|
1914
|
+
|
|
1915
|
+
|
|
1916
|
+
|
|
1917
|
+
|
|
1918
|
+
|
|
1919
|
+
|
|
1920
|
+
|
|
1921
|
+
|
|
1922
|
+
|
|
1923
|
+
|
|
1924
|
+
|
|
1925
|
+
|
|
1926
|
+
|
|
1927
|
+
|
|
1928
|
+
|
|
1929
|
+
|
|
1930
|
+
|
|
1553
1931
|
* @example
|
|
1554
1932
|
* // basic Queue creation and push operation
|
|
1555
1933
|
* // Create a simple Queue with initial values
|
|
@@ -1595,6 +1973,27 @@ var _Queue = class _Queue extends LinearBase {
|
|
|
1595
1973
|
|
|
1596
1974
|
|
|
1597
1975
|
|
|
1976
|
+
|
|
1977
|
+
|
|
1978
|
+
|
|
1979
|
+
|
|
1980
|
+
|
|
1981
|
+
|
|
1982
|
+
|
|
1983
|
+
|
|
1984
|
+
|
|
1985
|
+
|
|
1986
|
+
|
|
1987
|
+
|
|
1988
|
+
|
|
1989
|
+
|
|
1990
|
+
|
|
1991
|
+
|
|
1992
|
+
|
|
1993
|
+
|
|
1994
|
+
|
|
1995
|
+
|
|
1996
|
+
|
|
1598
1997
|
* @example
|
|
1599
1998
|
* // Queue shift and peek operations
|
|
1600
1999
|
* const queue = new Queue<number>([10, 20, 30, 40]);
|
|
@@ -1630,6 +2029,27 @@ var _Queue = class _Queue extends LinearBase {
|
|
|
1630
2029
|
|
|
1631
2030
|
|
|
1632
2031
|
|
|
2032
|
+
|
|
2033
|
+
|
|
2034
|
+
|
|
2035
|
+
|
|
2036
|
+
|
|
2037
|
+
|
|
2038
|
+
|
|
2039
|
+
|
|
2040
|
+
|
|
2041
|
+
|
|
2042
|
+
|
|
2043
|
+
|
|
2044
|
+
|
|
2045
|
+
|
|
2046
|
+
|
|
2047
|
+
|
|
2048
|
+
|
|
2049
|
+
|
|
2050
|
+
|
|
2051
|
+
|
|
2052
|
+
|
|
1633
2053
|
* @example
|
|
1634
2054
|
* // Remove specific element
|
|
1635
2055
|
* const q = new Queue<number>([1, 2, 3, 2]);
|
|
@@ -1658,6 +2078,27 @@ var _Queue = class _Queue extends LinearBase {
|
|
|
1658
2078
|
|
|
1659
2079
|
|
|
1660
2080
|
|
|
2081
|
+
|
|
2082
|
+
|
|
2083
|
+
|
|
2084
|
+
|
|
2085
|
+
|
|
2086
|
+
|
|
2087
|
+
|
|
2088
|
+
|
|
2089
|
+
|
|
2090
|
+
|
|
2091
|
+
|
|
2092
|
+
|
|
2093
|
+
|
|
2094
|
+
|
|
2095
|
+
|
|
2096
|
+
|
|
2097
|
+
|
|
2098
|
+
|
|
2099
|
+
|
|
2100
|
+
|
|
2101
|
+
|
|
1661
2102
|
* @example
|
|
1662
2103
|
* // Access element by index
|
|
1663
2104
|
* const q = new Queue<string>(['a', 'b', 'c']);
|
|
@@ -1727,6 +2168,27 @@ var _Queue = class _Queue extends LinearBase {
|
|
|
1727
2168
|
|
|
1728
2169
|
|
|
1729
2170
|
|
|
2171
|
+
|
|
2172
|
+
|
|
2173
|
+
|
|
2174
|
+
|
|
2175
|
+
|
|
2176
|
+
|
|
2177
|
+
|
|
2178
|
+
|
|
2179
|
+
|
|
2180
|
+
|
|
2181
|
+
|
|
2182
|
+
|
|
2183
|
+
|
|
2184
|
+
|
|
2185
|
+
|
|
2186
|
+
|
|
2187
|
+
|
|
2188
|
+
|
|
2189
|
+
|
|
2190
|
+
|
|
2191
|
+
|
|
1730
2192
|
* @example
|
|
1731
2193
|
* // Remove all elements
|
|
1732
2194
|
* const q = new Queue<number>([1, 2, 3]);
|
|
@@ -1749,6 +2211,27 @@ var _Queue = class _Queue extends LinearBase {
|
|
|
1749
2211
|
|
|
1750
2212
|
|
|
1751
2213
|
|
|
2214
|
+
|
|
2215
|
+
|
|
2216
|
+
|
|
2217
|
+
|
|
2218
|
+
|
|
2219
|
+
|
|
2220
|
+
|
|
2221
|
+
|
|
2222
|
+
|
|
2223
|
+
|
|
2224
|
+
|
|
2225
|
+
|
|
2226
|
+
|
|
2227
|
+
|
|
2228
|
+
|
|
2229
|
+
|
|
2230
|
+
|
|
2231
|
+
|
|
2232
|
+
|
|
2233
|
+
|
|
2234
|
+
|
|
1752
2235
|
* @example
|
|
1753
2236
|
* // Reclaim unused memory
|
|
1754
2237
|
* const q = new Queue<number>([1, 2, 3, 4, 5]);
|
|
@@ -1794,6 +2277,27 @@ var _Queue = class _Queue extends LinearBase {
|
|
|
1794
2277
|
|
|
1795
2278
|
|
|
1796
2279
|
|
|
2280
|
+
|
|
2281
|
+
|
|
2282
|
+
|
|
2283
|
+
|
|
2284
|
+
|
|
2285
|
+
|
|
2286
|
+
|
|
2287
|
+
|
|
2288
|
+
|
|
2289
|
+
|
|
2290
|
+
|
|
2291
|
+
|
|
2292
|
+
|
|
2293
|
+
|
|
2294
|
+
|
|
2295
|
+
|
|
2296
|
+
|
|
2297
|
+
|
|
2298
|
+
|
|
2299
|
+
|
|
2300
|
+
|
|
1797
2301
|
* @example
|
|
1798
2302
|
* // Create independent copy
|
|
1799
2303
|
* const q = new Queue<number>([1, 2, 3]);
|
|
@@ -1823,6 +2327,27 @@ var _Queue = class _Queue extends LinearBase {
|
|
|
1823
2327
|
|
|
1824
2328
|
|
|
1825
2329
|
|
|
2330
|
+
|
|
2331
|
+
|
|
2332
|
+
|
|
2333
|
+
|
|
2334
|
+
|
|
2335
|
+
|
|
2336
|
+
|
|
2337
|
+
|
|
2338
|
+
|
|
2339
|
+
|
|
2340
|
+
|
|
2341
|
+
|
|
2342
|
+
|
|
2343
|
+
|
|
2344
|
+
|
|
2345
|
+
|
|
2346
|
+
|
|
2347
|
+
|
|
2348
|
+
|
|
2349
|
+
|
|
2350
|
+
|
|
1826
2351
|
* @example
|
|
1827
2352
|
* // Filter elements
|
|
1828
2353
|
* const q = new Queue<number>([1, 2, 3, 4, 5]);
|
|
@@ -1856,6 +2381,27 @@ var _Queue = class _Queue extends LinearBase {
|
|
|
1856
2381
|
|
|
1857
2382
|
|
|
1858
2383
|
|
|
2384
|
+
|
|
2385
|
+
|
|
2386
|
+
|
|
2387
|
+
|
|
2388
|
+
|
|
2389
|
+
|
|
2390
|
+
|
|
2391
|
+
|
|
2392
|
+
|
|
2393
|
+
|
|
2394
|
+
|
|
2395
|
+
|
|
2396
|
+
|
|
2397
|
+
|
|
2398
|
+
|
|
2399
|
+
|
|
2400
|
+
|
|
2401
|
+
|
|
2402
|
+
|
|
2403
|
+
|
|
2404
|
+
|
|
1859
2405
|
* @example
|
|
1860
2406
|
* // Transform elements
|
|
1861
2407
|
* const q = new Queue<number>([1, 2, 3]);
|
|
@@ -2974,6 +3520,27 @@ var _DirectedGraph = class _DirectedGraph extends AbstractGraph {
|
|
|
2974
3520
|
|
|
2975
3521
|
|
|
2976
3522
|
|
|
3523
|
+
|
|
3524
|
+
|
|
3525
|
+
|
|
3526
|
+
|
|
3527
|
+
|
|
3528
|
+
|
|
3529
|
+
|
|
3530
|
+
|
|
3531
|
+
|
|
3532
|
+
|
|
3533
|
+
|
|
3534
|
+
|
|
3535
|
+
|
|
3536
|
+
|
|
3537
|
+
|
|
3538
|
+
|
|
3539
|
+
|
|
3540
|
+
|
|
3541
|
+
|
|
3542
|
+
|
|
3543
|
+
|
|
2977
3544
|
* @example
|
|
2978
3545
|
* // Get edge between vertices
|
|
2979
3546
|
* const g = new DirectedGraph();
|
|
@@ -3038,6 +3605,27 @@ var _DirectedGraph = class _DirectedGraph extends AbstractGraph {
|
|
|
3038
3605
|
|
|
3039
3606
|
|
|
3040
3607
|
|
|
3608
|
+
|
|
3609
|
+
|
|
3610
|
+
|
|
3611
|
+
|
|
3612
|
+
|
|
3613
|
+
|
|
3614
|
+
|
|
3615
|
+
|
|
3616
|
+
|
|
3617
|
+
|
|
3618
|
+
|
|
3619
|
+
|
|
3620
|
+
|
|
3621
|
+
|
|
3622
|
+
|
|
3623
|
+
|
|
3624
|
+
|
|
3625
|
+
|
|
3626
|
+
|
|
3627
|
+
|
|
3628
|
+
|
|
3041
3629
|
* @example
|
|
3042
3630
|
* // DirectedGraph deleteEdge and vertex operations
|
|
3043
3631
|
* const graph = new DirectedGraph<string>();
|
|
@@ -3100,6 +3688,27 @@ var _DirectedGraph = class _DirectedGraph extends AbstractGraph {
|
|
|
3100
3688
|
|
|
3101
3689
|
|
|
3102
3690
|
|
|
3691
|
+
|
|
3692
|
+
|
|
3693
|
+
|
|
3694
|
+
|
|
3695
|
+
|
|
3696
|
+
|
|
3697
|
+
|
|
3698
|
+
|
|
3699
|
+
|
|
3700
|
+
|
|
3701
|
+
|
|
3702
|
+
|
|
3703
|
+
|
|
3704
|
+
|
|
3705
|
+
|
|
3706
|
+
|
|
3707
|
+
|
|
3708
|
+
|
|
3709
|
+
|
|
3710
|
+
|
|
3711
|
+
|
|
3103
3712
|
* @example
|
|
3104
3713
|
* // Remove a vertex
|
|
3105
3714
|
* const g = new DirectedGraph();
|
|
@@ -3153,6 +3762,27 @@ var _DirectedGraph = class _DirectedGraph extends AbstractGraph {
|
|
|
3153
3762
|
|
|
3154
3763
|
|
|
3155
3764
|
|
|
3765
|
+
|
|
3766
|
+
|
|
3767
|
+
|
|
3768
|
+
|
|
3769
|
+
|
|
3770
|
+
|
|
3771
|
+
|
|
3772
|
+
|
|
3773
|
+
|
|
3774
|
+
|
|
3775
|
+
|
|
3776
|
+
|
|
3777
|
+
|
|
3778
|
+
|
|
3779
|
+
|
|
3780
|
+
|
|
3781
|
+
|
|
3782
|
+
|
|
3783
|
+
|
|
3784
|
+
|
|
3785
|
+
|
|
3156
3786
|
* @example
|
|
3157
3787
|
* // Get incoming edges
|
|
3158
3788
|
* const g = new DirectedGraph();
|
|
@@ -3183,6 +3813,27 @@ var _DirectedGraph = class _DirectedGraph extends AbstractGraph {
|
|
|
3183
3813
|
|
|
3184
3814
|
|
|
3185
3815
|
|
|
3816
|
+
|
|
3817
|
+
|
|
3818
|
+
|
|
3819
|
+
|
|
3820
|
+
|
|
3821
|
+
|
|
3822
|
+
|
|
3823
|
+
|
|
3824
|
+
|
|
3825
|
+
|
|
3826
|
+
|
|
3827
|
+
|
|
3828
|
+
|
|
3829
|
+
|
|
3830
|
+
|
|
3831
|
+
|
|
3832
|
+
|
|
3833
|
+
|
|
3834
|
+
|
|
3835
|
+
|
|
3836
|
+
|
|
3186
3837
|
* @example
|
|
3187
3838
|
* // Get outgoing edges
|
|
3188
3839
|
* const g = new DirectedGraph();
|
|
@@ -3266,6 +3917,27 @@ var _DirectedGraph = class _DirectedGraph extends AbstractGraph {
|
|
|
3266
3917
|
|
|
3267
3918
|
|
|
3268
3919
|
|
|
3920
|
+
|
|
3921
|
+
|
|
3922
|
+
|
|
3923
|
+
|
|
3924
|
+
|
|
3925
|
+
|
|
3926
|
+
|
|
3927
|
+
|
|
3928
|
+
|
|
3929
|
+
|
|
3930
|
+
|
|
3931
|
+
|
|
3932
|
+
|
|
3933
|
+
|
|
3934
|
+
|
|
3935
|
+
|
|
3936
|
+
|
|
3937
|
+
|
|
3938
|
+
|
|
3939
|
+
|
|
3940
|
+
|
|
3269
3941
|
* @example
|
|
3270
3942
|
* // DirectedGraph topologicalSort for task scheduling
|
|
3271
3943
|
* const graph = new DirectedGraph<string>();
|
|
@@ -3330,6 +4002,27 @@ var _DirectedGraph = class _DirectedGraph extends AbstractGraph {
|
|
|
3330
4002
|
|
|
3331
4003
|
|
|
3332
4004
|
|
|
4005
|
+
|
|
4006
|
+
|
|
4007
|
+
|
|
4008
|
+
|
|
4009
|
+
|
|
4010
|
+
|
|
4011
|
+
|
|
4012
|
+
|
|
4013
|
+
|
|
4014
|
+
|
|
4015
|
+
|
|
4016
|
+
|
|
4017
|
+
|
|
4018
|
+
|
|
4019
|
+
|
|
4020
|
+
|
|
4021
|
+
|
|
4022
|
+
|
|
4023
|
+
|
|
4024
|
+
|
|
4025
|
+
|
|
3333
4026
|
* @example
|
|
3334
4027
|
* // Get all edges
|
|
3335
4028
|
* const g = new DirectedGraph();
|
|
@@ -3356,6 +4049,27 @@ var _DirectedGraph = class _DirectedGraph extends AbstractGraph {
|
|
|
3356
4049
|
|
|
3357
4050
|
|
|
3358
4051
|
|
|
4052
|
+
|
|
4053
|
+
|
|
4054
|
+
|
|
4055
|
+
|
|
4056
|
+
|
|
4057
|
+
|
|
4058
|
+
|
|
4059
|
+
|
|
4060
|
+
|
|
4061
|
+
|
|
4062
|
+
|
|
4063
|
+
|
|
4064
|
+
|
|
4065
|
+
|
|
4066
|
+
|
|
4067
|
+
|
|
4068
|
+
|
|
4069
|
+
|
|
4070
|
+
|
|
4071
|
+
|
|
4072
|
+
|
|
3359
4073
|
* @example
|
|
3360
4074
|
* // Get outgoing neighbors
|
|
3361
4075
|
* const g = new DirectedGraph();
|
|
@@ -3435,6 +4149,27 @@ var _DirectedGraph = class _DirectedGraph extends AbstractGraph {
|
|
|
3435
4149
|
|
|
3436
4150
|
|
|
3437
4151
|
|
|
4152
|
+
|
|
4153
|
+
|
|
4154
|
+
|
|
4155
|
+
|
|
4156
|
+
|
|
4157
|
+
|
|
4158
|
+
|
|
4159
|
+
|
|
4160
|
+
|
|
4161
|
+
|
|
4162
|
+
|
|
4163
|
+
|
|
4164
|
+
|
|
4165
|
+
|
|
4166
|
+
|
|
4167
|
+
|
|
4168
|
+
|
|
4169
|
+
|
|
4170
|
+
|
|
4171
|
+
|
|
4172
|
+
|
|
3438
4173
|
* @example
|
|
3439
4174
|
* // Find strongly connected components
|
|
3440
4175
|
* const g = new DirectedGraph();
|
|
@@ -3517,6 +4252,27 @@ var _DirectedGraph = class _DirectedGraph extends AbstractGraph {
|
|
|
3517
4252
|
|
|
3518
4253
|
|
|
3519
4254
|
|
|
4255
|
+
|
|
4256
|
+
|
|
4257
|
+
|
|
4258
|
+
|
|
4259
|
+
|
|
4260
|
+
|
|
4261
|
+
|
|
4262
|
+
|
|
4263
|
+
|
|
4264
|
+
|
|
4265
|
+
|
|
4266
|
+
|
|
4267
|
+
|
|
4268
|
+
|
|
4269
|
+
|
|
4270
|
+
|
|
4271
|
+
|
|
4272
|
+
|
|
4273
|
+
|
|
4274
|
+
|
|
4275
|
+
|
|
3520
4276
|
* @example
|
|
3521
4277
|
* // Get strongly connected components
|
|
3522
4278
|
* const g = new DirectedGraph();
|