undirected-graph-typed 2.5.0 → 2.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.cjs +1054 -207
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs-legacy/index.cjs +1051 -204
- package/dist/cjs-legacy/index.cjs.map +1 -1
- package/dist/esm/index.mjs +1054 -208
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm-legacy/index.mjs +1051 -205
- package/dist/esm-legacy/index.mjs.map +1 -1
- package/dist/types/common/error.d.ts +9 -0
- package/dist/types/common/index.d.ts +1 -1
- package/dist/types/data-structures/base/index.d.ts +1 -0
- package/dist/types/data-structures/base/iterable-entry-base.d.ts +8 -8
- package/dist/types/data-structures/base/linear-base.d.ts +3 -3
- package/dist/types/data-structures/binary-tree/avl-tree.d.ts +288 -0
- package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +336 -0
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +618 -18
- package/dist/types/data-structures/binary-tree/bst.d.ts +676 -1
- package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +456 -0
- package/dist/types/data-structures/binary-tree/segment-tree.d.ts +144 -1
- package/dist/types/data-structures/binary-tree/tree-map.d.ts +3307 -399
- package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +3285 -360
- package/dist/types/data-structures/binary-tree/tree-multi-set.d.ts +2674 -325
- package/dist/types/data-structures/binary-tree/tree-set.d.ts +3072 -287
- package/dist/types/data-structures/graph/abstract-graph.d.ts +4 -4
- package/dist/types/data-structures/graph/directed-graph.d.ts +240 -0
- package/dist/types/data-structures/graph/undirected-graph.d.ts +216 -0
- package/dist/types/data-structures/hash/hash-map.d.ts +274 -10
- package/dist/types/data-structures/heap/heap.d.ts +336 -0
- package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +411 -3
- package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +363 -3
- package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +434 -2
- package/dist/types/data-structures/matrix/matrix.d.ts +192 -0
- package/dist/types/data-structures/queue/deque.d.ts +364 -4
- package/dist/types/data-structures/queue/queue.d.ts +288 -0
- package/dist/types/data-structures/stack/stack.d.ts +240 -0
- package/dist/types/data-structures/trie/trie.d.ts +292 -4
- package/dist/types/interfaces/graph.d.ts +1 -1
- package/dist/types/types/common.d.ts +2 -2
- package/dist/types/types/data-structures/binary-tree/bst.d.ts +1 -0
- package/dist/types/types/data-structures/binary-tree/tree-map.d.ts +5 -0
- package/dist/types/types/data-structures/binary-tree/tree-multi-set.d.ts +4 -0
- package/dist/types/types/data-structures/binary-tree/tree-set.d.ts +4 -0
- package/dist/types/types/data-structures/heap/heap.d.ts +1 -0
- package/dist/types/types/data-structures/priority-queue/priority-queue.d.ts +1 -0
- package/dist/types/types/utils/validate-type.d.ts +4 -4
- package/dist/umd/undirected-graph-typed.js +1051 -205
- package/dist/umd/undirected-graph-typed.js.map +1 -1
- package/dist/umd/undirected-graph-typed.min.js +3 -3
- package/dist/umd/undirected-graph-typed.min.js.map +1 -1
- package/package.json +2 -2
- package/src/common/error.ts +19 -1
- package/src/common/index.ts +1 -1
- package/src/data-structures/base/index.ts +1 -0
- package/src/data-structures/base/iterable-element-base.ts +3 -2
- package/src/data-structures/base/iterable-entry-base.ts +8 -8
- package/src/data-structures/base/linear-base.ts +3 -3
- package/src/data-structures/binary-tree/avl-tree.ts +299 -0
- package/src/data-structures/binary-tree/binary-indexed-tree.ts +341 -5
- package/src/data-structures/binary-tree/binary-tree.ts +606 -6
- package/src/data-structures/binary-tree/bst.ts +946 -7
- package/src/data-structures/binary-tree/red-black-tree.ts +472 -0
- package/src/data-structures/binary-tree/segment-tree.ts +145 -2
- package/src/data-structures/binary-tree/tree-map.ts +3423 -499
- package/src/data-structures/binary-tree/tree-multi-map.ts +3537 -596
- package/src/data-structures/binary-tree/tree-multi-set.ts +2855 -495
- package/src/data-structures/binary-tree/tree-set.ts +3209 -413
- package/src/data-structures/graph/abstract-graph.ts +6 -6
- package/src/data-structures/graph/directed-graph.ts +240 -0
- package/src/data-structures/graph/undirected-graph.ts +216 -0
- package/src/data-structures/hash/hash-map.ts +281 -19
- package/src/data-structures/heap/heap.ts +340 -4
- package/src/data-structures/heap/max-heap.ts +2 -2
- package/src/data-structures/linked-list/doubly-linked-list.ts +411 -3
- package/src/data-structures/linked-list/singly-linked-list.ts +363 -3
- package/src/data-structures/linked-list/skip-linked-list.ts +439 -7
- package/src/data-structures/matrix/matrix.ts +202 -10
- package/src/data-structures/priority-queue/max-priority-queue.ts +2 -2
- package/src/data-structures/queue/deque.ts +365 -5
- package/src/data-structures/queue/queue.ts +288 -0
- package/src/data-structures/stack/stack.ts +240 -0
- package/src/data-structures/trie/trie.ts +295 -7
- package/src/interfaces/graph.ts +1 -1
- package/src/types/common.ts +2 -2
- package/src/types/data-structures/binary-tree/bst.ts +1 -0
- package/src/types/data-structures/binary-tree/tree-map.ts +6 -0
- package/src/types/data-structures/binary-tree/tree-multi-set.ts +5 -0
- package/src/types/data-structures/binary-tree/tree-set.ts +5 -0
- package/src/types/data-structures/heap/heap.ts +1 -0
- package/src/types/data-structures/priority-queue/priority-queue.ts +1 -0
- package/src/types/utils/validate-type.ts +4 -4
|
@@ -27,6 +27,10 @@ var arrayRemove = /* @__PURE__ */ __name(function(array, predicate) {
|
|
|
27
27
|
}, "arrayRemove");
|
|
28
28
|
|
|
29
29
|
// src/common/error.ts
|
|
30
|
+
function raise(ErrorClass, message) {
|
|
31
|
+
throw new ErrorClass(message);
|
|
32
|
+
}
|
|
33
|
+
__name(raise, "raise");
|
|
30
34
|
var ERR = {
|
|
31
35
|
// Range / index
|
|
32
36
|
indexOutOfRange: /* @__PURE__ */ __name((index, min, max, ctx) => `${ctx ? ctx + ": " : ""}Index ${index} is out of range [${min}, ${max}].`, "indexOutOfRange"),
|
|
@@ -48,7 +52,9 @@ var ERR = {
|
|
|
48
52
|
matrixSingular: /* @__PURE__ */ __name(() => "Matrix: Singular matrix, inverse does not exist.", "matrixSingular"),
|
|
49
53
|
matrixNotSquare: /* @__PURE__ */ __name(() => "Matrix: Must be square for inversion.", "matrixNotSquare"),
|
|
50
54
|
matrixNotRectangular: /* @__PURE__ */ __name(() => "Matrix: Must be rectangular for transposition.", "matrixNotRectangular"),
|
|
51
|
-
matrixRowMismatch: /* @__PURE__ */ __name((expected, got) => `Matrix: Expected row length ${expected}, but got ${got}.`, "matrixRowMismatch")
|
|
55
|
+
matrixRowMismatch: /* @__PURE__ */ __name((expected, got) => `Matrix: Expected row length ${expected}, but got ${got}.`, "matrixRowMismatch"),
|
|
56
|
+
// Order statistic
|
|
57
|
+
orderStatisticNotEnabled: /* @__PURE__ */ __name((method, ctx) => `${ctx ? ctx + ": " : ""}${method}() requires enableOrderStatistic: true.`, "orderStatisticNotEnabled")
|
|
52
58
|
};
|
|
53
59
|
|
|
54
60
|
// src/common/index.ts
|
|
@@ -277,7 +283,7 @@ var _IterableElementBase = class _IterableElementBase {
|
|
|
277
283
|
if (options) {
|
|
278
284
|
const { toElementFn } = options;
|
|
279
285
|
if (typeof toElementFn === "function") this._toElementFn = toElementFn;
|
|
280
|
-
else if (toElementFn)
|
|
286
|
+
else if (toElementFn) raise(TypeError, "toElementFn must be a function type");
|
|
281
287
|
}
|
|
282
288
|
}
|
|
283
289
|
/**
|
|
@@ -433,7 +439,7 @@ var _IterableElementBase = class _IterableElementBase {
|
|
|
433
439
|
acc = initialValue;
|
|
434
440
|
} else {
|
|
435
441
|
const first = iter.next();
|
|
436
|
-
if (first.done)
|
|
442
|
+
if (first.done) raise(TypeError, "Reduce of empty structure with no initial value");
|
|
437
443
|
acc = first.value;
|
|
438
444
|
index = 1;
|
|
439
445
|
}
|
|
@@ -477,6 +483,198 @@ var _IterableElementBase = class _IterableElementBase {
|
|
|
477
483
|
__name(_IterableElementBase, "IterableElementBase");
|
|
478
484
|
var IterableElementBase = _IterableElementBase;
|
|
479
485
|
|
|
486
|
+
// src/data-structures/base/linear-base.ts
|
|
487
|
+
var _LinearBase = class _LinearBase extends IterableElementBase {
|
|
488
|
+
/**
|
|
489
|
+
* Construct a linear container with runtime options.
|
|
490
|
+
* @param options - `{ maxLen?, ... }` bounds/behavior options.
|
|
491
|
+
* @remarks Time O(1), Space O(1)
|
|
492
|
+
*/
|
|
493
|
+
constructor(options) {
|
|
494
|
+
super(options);
|
|
495
|
+
__publicField(this, "_maxLen", -1);
|
|
496
|
+
if (options) {
|
|
497
|
+
const { maxLen } = options;
|
|
498
|
+
if (typeof maxLen === "number" && maxLen > 0 && maxLen % 1 === 0) this._maxLen = maxLen;
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
/**
|
|
502
|
+
* Upper bound for length (if positive), or `-1` when unbounded.
|
|
503
|
+
* @returns Maximum allowed length.
|
|
504
|
+
* @remarks Time O(1), Space O(1)
|
|
505
|
+
*/
|
|
506
|
+
get maxLen() {
|
|
507
|
+
return this._maxLen;
|
|
508
|
+
}
|
|
509
|
+
/**
|
|
510
|
+
* First index of a value from the left.
|
|
511
|
+
* @param searchElement - Value to match.
|
|
512
|
+
* @param fromIndex - Start position (supports negative index).
|
|
513
|
+
* @returns Index or `-1` if not found.
|
|
514
|
+
* @remarks Time O(n), Space O(1)
|
|
515
|
+
*/
|
|
516
|
+
indexOf(searchElement, fromIndex = 0) {
|
|
517
|
+
if (this.length === 0) return -1;
|
|
518
|
+
if (fromIndex < 0) fromIndex = this.length + fromIndex;
|
|
519
|
+
if (fromIndex < 0) fromIndex = 0;
|
|
520
|
+
for (let i = fromIndex; i < this.length; i++) {
|
|
521
|
+
const element = this.at(i);
|
|
522
|
+
if (element === searchElement) return i;
|
|
523
|
+
}
|
|
524
|
+
return -1;
|
|
525
|
+
}
|
|
526
|
+
/**
|
|
527
|
+
* Last index of a value from the right.
|
|
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
|
+
lastIndexOf(searchElement, fromIndex = this.length - 1) {
|
|
534
|
+
if (this.length === 0) return -1;
|
|
535
|
+
if (fromIndex >= this.length) fromIndex = this.length - 1;
|
|
536
|
+
if (fromIndex < 0) fromIndex = this.length + fromIndex;
|
|
537
|
+
for (let i = fromIndex; i >= 0; i--) {
|
|
538
|
+
const element = this.at(i);
|
|
539
|
+
if (element === searchElement) return i;
|
|
540
|
+
}
|
|
541
|
+
return -1;
|
|
542
|
+
}
|
|
543
|
+
/**
|
|
544
|
+
* Find the first index matching a predicate.
|
|
545
|
+
* @param predicate - `(element, index, self) => boolean`.
|
|
546
|
+
* @param thisArg - Optional `this` for callback.
|
|
547
|
+
* @returns Index or `-1`.
|
|
548
|
+
* @remarks Time O(n), Space O(1)
|
|
549
|
+
*/
|
|
550
|
+
findIndex(predicate, thisArg) {
|
|
551
|
+
for (let i = 0; i < this.length; i++) {
|
|
552
|
+
const item = this.at(i);
|
|
553
|
+
if (item !== void 0 && predicate.call(thisArg, item, i, this)) return i;
|
|
554
|
+
}
|
|
555
|
+
return -1;
|
|
556
|
+
}
|
|
557
|
+
/**
|
|
558
|
+
* Concatenate elements and/or containers.
|
|
559
|
+
* @param items - Elements or other containers.
|
|
560
|
+
* @returns New container with combined elements (`this` type).
|
|
561
|
+
* @remarks Time O(sum(length)), Space O(sum(length))
|
|
562
|
+
*/
|
|
563
|
+
concat(...items) {
|
|
564
|
+
const newList = this.clone();
|
|
565
|
+
for (const item of items) {
|
|
566
|
+
if (item instanceof _LinearBase) {
|
|
567
|
+
newList.pushMany(item);
|
|
568
|
+
} else {
|
|
569
|
+
newList.push(item);
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
return newList;
|
|
573
|
+
}
|
|
574
|
+
/**
|
|
575
|
+
* In-place stable order via array sort semantics.
|
|
576
|
+
* @param compareFn - Comparator `(a, b) => number`.
|
|
577
|
+
* @returns This container.
|
|
578
|
+
* @remarks Time O(n log n), Space O(n) (materializes to array temporarily)
|
|
579
|
+
*/
|
|
580
|
+
sort(compareFn) {
|
|
581
|
+
const arr = this.toArray();
|
|
582
|
+
arr.sort(compareFn);
|
|
583
|
+
this.clear();
|
|
584
|
+
for (const item of arr) this.push(item);
|
|
585
|
+
return this;
|
|
586
|
+
}
|
|
587
|
+
/**
|
|
588
|
+
* Remove and/or insert elements at a position (array-compatible).
|
|
589
|
+
* @param start - Start index (supports negative index).
|
|
590
|
+
* @param deleteCount - How many to remove.
|
|
591
|
+
* @param items - Elements to insert.
|
|
592
|
+
* @returns Removed elements as a new list (`this` type).
|
|
593
|
+
* @remarks Time O(n + m), Space O(min(n, m)) where `m = items.length`
|
|
594
|
+
*/
|
|
595
|
+
splice(start, deleteCount = 0, ...items) {
|
|
596
|
+
const removedList = this._createInstance();
|
|
597
|
+
start = start < 0 ? this.length + start : start;
|
|
598
|
+
start = Math.max(0, Math.min(start, this.length));
|
|
599
|
+
deleteCount = Math.max(0, Math.min(deleteCount, this.length - start));
|
|
600
|
+
for (let i = 0; i < deleteCount; i++) {
|
|
601
|
+
const removed = this.deleteAt(start);
|
|
602
|
+
if (removed !== void 0) {
|
|
603
|
+
removedList.push(removed);
|
|
604
|
+
}
|
|
605
|
+
}
|
|
606
|
+
for (let i = 0; i < items.length; i++) {
|
|
607
|
+
this.addAt(start + i, items[i]);
|
|
608
|
+
}
|
|
609
|
+
return removedList;
|
|
610
|
+
}
|
|
611
|
+
/**
|
|
612
|
+
* Join all elements into a string.
|
|
613
|
+
* @param separator - Separator string.
|
|
614
|
+
* @returns Concatenated string.
|
|
615
|
+
* @remarks Time O(n), Space O(n)
|
|
616
|
+
*/
|
|
617
|
+
join(separator = ",") {
|
|
618
|
+
return this.toArray().join(separator);
|
|
619
|
+
}
|
|
620
|
+
/**
|
|
621
|
+
* Snapshot elements into a reversed array.
|
|
622
|
+
* @returns New reversed array.
|
|
623
|
+
* @remarks Time O(n), Space O(n)
|
|
624
|
+
*/
|
|
625
|
+
toReversedArray() {
|
|
626
|
+
const array = [];
|
|
627
|
+
for (let i = this.length - 1; i >= 0; i--) {
|
|
628
|
+
array.push(this.at(i));
|
|
629
|
+
}
|
|
630
|
+
return array;
|
|
631
|
+
}
|
|
632
|
+
reduceRight(callbackfn, initialValue) {
|
|
633
|
+
let accumulator = initialValue != null ? initialValue : 0;
|
|
634
|
+
for (let i = this.length - 1; i >= 0; i--) {
|
|
635
|
+
accumulator = callbackfn(accumulator, this.at(i), i, this);
|
|
636
|
+
}
|
|
637
|
+
return accumulator;
|
|
638
|
+
}
|
|
639
|
+
/**
|
|
640
|
+
* Create a shallow copy of a subrange.
|
|
641
|
+
* @param start - Inclusive start (supports negative index).
|
|
642
|
+
* @param end - Exclusive end (supports negative index).
|
|
643
|
+
* @returns New list with the range (`this` type).
|
|
644
|
+
* @remarks Time O(n), Space O(n)
|
|
645
|
+
*/
|
|
646
|
+
slice(start = 0, end = this.length) {
|
|
647
|
+
start = start < 0 ? this.length + start : start;
|
|
648
|
+
end = end < 0 ? this.length + end : end;
|
|
649
|
+
const newList = this._createInstance();
|
|
650
|
+
for (let i = start; i < end; i++) {
|
|
651
|
+
newList.push(this.at(i));
|
|
652
|
+
}
|
|
653
|
+
return newList;
|
|
654
|
+
}
|
|
655
|
+
/**
|
|
656
|
+
* Fill a range with a value.
|
|
657
|
+
* @param value - Value to set.
|
|
658
|
+
* @param start - Inclusive start.
|
|
659
|
+
* @param end - Exclusive end.
|
|
660
|
+
* @returns This list.
|
|
661
|
+
* @remarks Time O(n), Space O(1)
|
|
662
|
+
*/
|
|
663
|
+
fill(value, start = 0, end = this.length) {
|
|
664
|
+
start = start < 0 ? this.length + start : start;
|
|
665
|
+
end = end < 0 ? this.length + end : end;
|
|
666
|
+
if (start < 0) start = 0;
|
|
667
|
+
if (end > this.length) end = this.length;
|
|
668
|
+
if (start >= end) return this;
|
|
669
|
+
for (let i = start; i < end; i++) {
|
|
670
|
+
this.setAt(i, value);
|
|
671
|
+
}
|
|
672
|
+
return this;
|
|
673
|
+
}
|
|
674
|
+
};
|
|
675
|
+
__name(_LinearBase, "LinearBase");
|
|
676
|
+
var LinearBase = _LinearBase;
|
|
677
|
+
|
|
480
678
|
// src/data-structures/heap/heap.ts
|
|
481
679
|
var _Heap = class _Heap extends IterableElementBase {
|
|
482
680
|
/**
|
|
@@ -492,7 +690,7 @@ var _Heap = class _Heap extends IterableElementBase {
|
|
|
492
690
|
__publicField(this, "_elements", []);
|
|
493
691
|
__publicField(this, "_DEFAULT_COMPARATOR", /* @__PURE__ */ __name((a, b) => {
|
|
494
692
|
if (typeof a === "object" || typeof b === "object") {
|
|
495
|
-
|
|
693
|
+
raise(TypeError, ERR.comparatorRequired("Heap"));
|
|
496
694
|
}
|
|
497
695
|
if (a > b) return 1;
|
|
498
696
|
if (a < b) return -1;
|
|
@@ -528,6 +726,30 @@ var _Heap = class _Heap extends IterableElementBase {
|
|
|
528
726
|
|
|
529
727
|
|
|
530
728
|
|
|
729
|
+
|
|
730
|
+
|
|
731
|
+
|
|
732
|
+
|
|
733
|
+
|
|
734
|
+
|
|
735
|
+
|
|
736
|
+
|
|
737
|
+
|
|
738
|
+
|
|
739
|
+
|
|
740
|
+
|
|
741
|
+
|
|
742
|
+
|
|
743
|
+
|
|
744
|
+
|
|
745
|
+
|
|
746
|
+
|
|
747
|
+
|
|
748
|
+
|
|
749
|
+
|
|
750
|
+
|
|
751
|
+
|
|
752
|
+
|
|
531
753
|
* @example
|
|
532
754
|
* // Track heap capacity
|
|
533
755
|
* const heap = new Heap<number>();
|
|
@@ -591,6 +813,30 @@ var _Heap = class _Heap extends IterableElementBase {
|
|
|
591
813
|
|
|
592
814
|
|
|
593
815
|
|
|
816
|
+
|
|
817
|
+
|
|
818
|
+
|
|
819
|
+
|
|
820
|
+
|
|
821
|
+
|
|
822
|
+
|
|
823
|
+
|
|
824
|
+
|
|
825
|
+
|
|
826
|
+
|
|
827
|
+
|
|
828
|
+
|
|
829
|
+
|
|
830
|
+
|
|
831
|
+
|
|
832
|
+
|
|
833
|
+
|
|
834
|
+
|
|
835
|
+
|
|
836
|
+
|
|
837
|
+
|
|
838
|
+
|
|
839
|
+
|
|
594
840
|
* @example
|
|
595
841
|
* // basic Heap creation and add operation
|
|
596
842
|
* // Create a min heap (default)
|
|
@@ -624,6 +870,30 @@ var _Heap = class _Heap extends IterableElementBase {
|
|
|
624
870
|
|
|
625
871
|
|
|
626
872
|
|
|
873
|
+
|
|
874
|
+
|
|
875
|
+
|
|
876
|
+
|
|
877
|
+
|
|
878
|
+
|
|
879
|
+
|
|
880
|
+
|
|
881
|
+
|
|
882
|
+
|
|
883
|
+
|
|
884
|
+
|
|
885
|
+
|
|
886
|
+
|
|
887
|
+
|
|
888
|
+
|
|
889
|
+
|
|
890
|
+
|
|
891
|
+
|
|
892
|
+
|
|
893
|
+
|
|
894
|
+
|
|
895
|
+
|
|
896
|
+
|
|
627
897
|
* @example
|
|
628
898
|
* // Add multiple elements
|
|
629
899
|
* const heap = new Heap<number>([], { comparator: (a, b) => a - b });
|
|
@@ -659,6 +929,30 @@ var _Heap = class _Heap extends IterableElementBase {
|
|
|
659
929
|
|
|
660
930
|
|
|
661
931
|
|
|
932
|
+
|
|
933
|
+
|
|
934
|
+
|
|
935
|
+
|
|
936
|
+
|
|
937
|
+
|
|
938
|
+
|
|
939
|
+
|
|
940
|
+
|
|
941
|
+
|
|
942
|
+
|
|
943
|
+
|
|
944
|
+
|
|
945
|
+
|
|
946
|
+
|
|
947
|
+
|
|
948
|
+
|
|
949
|
+
|
|
950
|
+
|
|
951
|
+
|
|
952
|
+
|
|
953
|
+
|
|
954
|
+
|
|
955
|
+
|
|
662
956
|
* @example
|
|
663
957
|
* // Heap with custom comparator (MaxHeap behavior)
|
|
664
958
|
* interface Task {
|
|
@@ -710,6 +1004,30 @@ var _Heap = class _Heap extends IterableElementBase {
|
|
|
710
1004
|
|
|
711
1005
|
|
|
712
1006
|
|
|
1007
|
+
|
|
1008
|
+
|
|
1009
|
+
|
|
1010
|
+
|
|
1011
|
+
|
|
1012
|
+
|
|
1013
|
+
|
|
1014
|
+
|
|
1015
|
+
|
|
1016
|
+
|
|
1017
|
+
|
|
1018
|
+
|
|
1019
|
+
|
|
1020
|
+
|
|
1021
|
+
|
|
1022
|
+
|
|
1023
|
+
|
|
1024
|
+
|
|
1025
|
+
|
|
1026
|
+
|
|
1027
|
+
|
|
1028
|
+
|
|
1029
|
+
|
|
1030
|
+
|
|
713
1031
|
* @example
|
|
714
1032
|
* // Heap for event processing with priority
|
|
715
1033
|
* interface Event {
|
|
@@ -786,6 +1104,30 @@ var _Heap = class _Heap extends IterableElementBase {
|
|
|
786
1104
|
|
|
787
1105
|
|
|
788
1106
|
|
|
1107
|
+
|
|
1108
|
+
|
|
1109
|
+
|
|
1110
|
+
|
|
1111
|
+
|
|
1112
|
+
|
|
1113
|
+
|
|
1114
|
+
|
|
1115
|
+
|
|
1116
|
+
|
|
1117
|
+
|
|
1118
|
+
|
|
1119
|
+
|
|
1120
|
+
|
|
1121
|
+
|
|
1122
|
+
|
|
1123
|
+
|
|
1124
|
+
|
|
1125
|
+
|
|
1126
|
+
|
|
1127
|
+
|
|
1128
|
+
|
|
1129
|
+
|
|
1130
|
+
|
|
789
1131
|
* @example
|
|
790
1132
|
* // Check if heap is empty
|
|
791
1133
|
* const heap = new Heap<number>([], { comparator: (a, b) => a - b });
|
|
@@ -809,6 +1151,30 @@ var _Heap = class _Heap extends IterableElementBase {
|
|
|
809
1151
|
|
|
810
1152
|
|
|
811
1153
|
|
|
1154
|
+
|
|
1155
|
+
|
|
1156
|
+
|
|
1157
|
+
|
|
1158
|
+
|
|
1159
|
+
|
|
1160
|
+
|
|
1161
|
+
|
|
1162
|
+
|
|
1163
|
+
|
|
1164
|
+
|
|
1165
|
+
|
|
1166
|
+
|
|
1167
|
+
|
|
1168
|
+
|
|
1169
|
+
|
|
1170
|
+
|
|
1171
|
+
|
|
1172
|
+
|
|
1173
|
+
|
|
1174
|
+
|
|
1175
|
+
|
|
1176
|
+
|
|
1177
|
+
|
|
812
1178
|
* @example
|
|
813
1179
|
* // Remove all elements
|
|
814
1180
|
* const heap = new Heap<number>([1, 2, 3], { comparator: (a, b) => a - b });
|
|
@@ -835,6 +1201,30 @@ var _Heap = class _Heap extends IterableElementBase {
|
|
|
835
1201
|
* @returns True if found.
|
|
836
1202
|
|
|
837
1203
|
|
|
1204
|
+
|
|
1205
|
+
|
|
1206
|
+
|
|
1207
|
+
|
|
1208
|
+
|
|
1209
|
+
|
|
1210
|
+
|
|
1211
|
+
|
|
1212
|
+
|
|
1213
|
+
|
|
1214
|
+
|
|
1215
|
+
|
|
1216
|
+
|
|
1217
|
+
|
|
1218
|
+
|
|
1219
|
+
|
|
1220
|
+
|
|
1221
|
+
|
|
1222
|
+
|
|
1223
|
+
|
|
1224
|
+
|
|
1225
|
+
|
|
1226
|
+
|
|
1227
|
+
|
|
838
1228
|
* @example
|
|
839
1229
|
* // Check element existence
|
|
840
1230
|
* const heap = new Heap<number>([3, 1, 2], { comparator: (a, b) => a - b });
|
|
@@ -858,6 +1248,30 @@ var _Heap = class _Heap extends IterableElementBase {
|
|
|
858
1248
|
|
|
859
1249
|
|
|
860
1250
|
|
|
1251
|
+
|
|
1252
|
+
|
|
1253
|
+
|
|
1254
|
+
|
|
1255
|
+
|
|
1256
|
+
|
|
1257
|
+
|
|
1258
|
+
|
|
1259
|
+
|
|
1260
|
+
|
|
1261
|
+
|
|
1262
|
+
|
|
1263
|
+
|
|
1264
|
+
|
|
1265
|
+
|
|
1266
|
+
|
|
1267
|
+
|
|
1268
|
+
|
|
1269
|
+
|
|
1270
|
+
|
|
1271
|
+
|
|
1272
|
+
|
|
1273
|
+
|
|
1274
|
+
|
|
861
1275
|
* @example
|
|
862
1276
|
* // Remove specific element
|
|
863
1277
|
* const heap = new Heap<number>([3, 1, 4, 1, 5], { comparator: (a, b) => a - b });
|
|
@@ -927,6 +1341,30 @@ var _Heap = class _Heap extends IterableElementBase {
|
|
|
927
1341
|
* @returns Array of visited elements.
|
|
928
1342
|
|
|
929
1343
|
|
|
1344
|
+
|
|
1345
|
+
|
|
1346
|
+
|
|
1347
|
+
|
|
1348
|
+
|
|
1349
|
+
|
|
1350
|
+
|
|
1351
|
+
|
|
1352
|
+
|
|
1353
|
+
|
|
1354
|
+
|
|
1355
|
+
|
|
1356
|
+
|
|
1357
|
+
|
|
1358
|
+
|
|
1359
|
+
|
|
1360
|
+
|
|
1361
|
+
|
|
1362
|
+
|
|
1363
|
+
|
|
1364
|
+
|
|
1365
|
+
|
|
1366
|
+
|
|
1367
|
+
|
|
930
1368
|
* @example
|
|
931
1369
|
* // Depth-first traversal
|
|
932
1370
|
* const heap = new Heap<number>([3, 1, 2], { comparator: (a, b) => a - b });
|
|
@@ -983,6 +1421,30 @@ var _Heap = class _Heap extends IterableElementBase {
|
|
|
983
1421
|
|
|
984
1422
|
|
|
985
1423
|
|
|
1424
|
+
|
|
1425
|
+
|
|
1426
|
+
|
|
1427
|
+
|
|
1428
|
+
|
|
1429
|
+
|
|
1430
|
+
|
|
1431
|
+
|
|
1432
|
+
|
|
1433
|
+
|
|
1434
|
+
|
|
1435
|
+
|
|
1436
|
+
|
|
1437
|
+
|
|
1438
|
+
|
|
1439
|
+
|
|
1440
|
+
|
|
1441
|
+
|
|
1442
|
+
|
|
1443
|
+
|
|
1444
|
+
|
|
1445
|
+
|
|
1446
|
+
|
|
1447
|
+
|
|
986
1448
|
* @example
|
|
987
1449
|
* // Sort elements using heap
|
|
988
1450
|
* const heap = new Heap<number>([5, 1, 3, 2, 4]);
|
|
@@ -1012,6 +1474,30 @@ var _Heap = class _Heap extends IterableElementBase {
|
|
|
1012
1474
|
|
|
1013
1475
|
|
|
1014
1476
|
|
|
1477
|
+
|
|
1478
|
+
|
|
1479
|
+
|
|
1480
|
+
|
|
1481
|
+
|
|
1482
|
+
|
|
1483
|
+
|
|
1484
|
+
|
|
1485
|
+
|
|
1486
|
+
|
|
1487
|
+
|
|
1488
|
+
|
|
1489
|
+
|
|
1490
|
+
|
|
1491
|
+
|
|
1492
|
+
|
|
1493
|
+
|
|
1494
|
+
|
|
1495
|
+
|
|
1496
|
+
|
|
1497
|
+
|
|
1498
|
+
|
|
1499
|
+
|
|
1500
|
+
|
|
1015
1501
|
* @example
|
|
1016
1502
|
* // Create independent copy
|
|
1017
1503
|
* const heap = new Heap<number>([3, 1, 4], { comparator: (a, b) => a - b });
|
|
@@ -1040,6 +1526,30 @@ var _Heap = class _Heap extends IterableElementBase {
|
|
|
1040
1526
|
|
|
1041
1527
|
|
|
1042
1528
|
|
|
1529
|
+
|
|
1530
|
+
|
|
1531
|
+
|
|
1532
|
+
|
|
1533
|
+
|
|
1534
|
+
|
|
1535
|
+
|
|
1536
|
+
|
|
1537
|
+
|
|
1538
|
+
|
|
1539
|
+
|
|
1540
|
+
|
|
1541
|
+
|
|
1542
|
+
|
|
1543
|
+
|
|
1544
|
+
|
|
1545
|
+
|
|
1546
|
+
|
|
1547
|
+
|
|
1548
|
+
|
|
1549
|
+
|
|
1550
|
+
|
|
1551
|
+
|
|
1552
|
+
|
|
1043
1553
|
* @example
|
|
1044
1554
|
* // Filter elements
|
|
1045
1555
|
* const heap = new Heap<number>([1, 2, 3, 4, 5], { comparator: (a, b) => a - b });
|
|
@@ -1075,6 +1585,30 @@ var _Heap = class _Heap extends IterableElementBase {
|
|
|
1075
1585
|
|
|
1076
1586
|
|
|
1077
1587
|
|
|
1588
|
+
|
|
1589
|
+
|
|
1590
|
+
|
|
1591
|
+
|
|
1592
|
+
|
|
1593
|
+
|
|
1594
|
+
|
|
1595
|
+
|
|
1596
|
+
|
|
1597
|
+
|
|
1598
|
+
|
|
1599
|
+
|
|
1600
|
+
|
|
1601
|
+
|
|
1602
|
+
|
|
1603
|
+
|
|
1604
|
+
|
|
1605
|
+
|
|
1606
|
+
|
|
1607
|
+
|
|
1608
|
+
|
|
1609
|
+
|
|
1610
|
+
|
|
1611
|
+
|
|
1078
1612
|
* @example
|
|
1079
1613
|
* // Transform elements
|
|
1080
1614
|
* const heap = new Heap<number>([1, 2, 3], { comparator: (a, b) => a - b });
|
|
@@ -1083,7 +1617,7 @@ var _Heap = class _Heap extends IterableElementBase {
|
|
|
1083
1617
|
*/
|
|
1084
1618
|
map(callback, options, thisArg) {
|
|
1085
1619
|
const { comparator, toElementFn, ...rest } = options != null ? options : {};
|
|
1086
|
-
if (!comparator)
|
|
1620
|
+
if (!comparator) raise(TypeError, ERR.comparatorRequired("Heap.map"));
|
|
1087
1621
|
const out = this._createLike([], { ...rest, comparator, toElementFn });
|
|
1088
1622
|
let i = 0;
|
|
1089
1623
|
for (const x of this) {
|
|
@@ -1177,206 +1711,14 @@ var _Heap = class _Heap extends IterableElementBase {
|
|
|
1177
1711
|
* @template EM
|
|
1178
1712
|
* @template RM
|
|
1179
1713
|
* @param [options] - Options forwarded to the constructor.
|
|
1180
|
-
* @returns An empty like-kind heap instance.
|
|
1181
|
-
*/
|
|
1182
|
-
_spawnLike(options) {
|
|
1183
|
-
return this._createLike([], options);
|
|
1184
|
-
}
|
|
1185
|
-
};
|
|
1186
|
-
__name(_Heap, "Heap");
|
|
1187
|
-
var Heap = _Heap;
|
|
1188
|
-
|
|
1189
|
-
// src/data-structures/base/linear-base.ts
|
|
1190
|
-
var _LinearBase = class _LinearBase extends IterableElementBase {
|
|
1191
|
-
/**
|
|
1192
|
-
* Construct a linear container with runtime options.
|
|
1193
|
-
* @param options - `{ maxLen?, ... }` bounds/behavior options.
|
|
1194
|
-
* @remarks Time O(1), Space O(1)
|
|
1195
|
-
*/
|
|
1196
|
-
constructor(options) {
|
|
1197
|
-
super(options);
|
|
1198
|
-
__publicField(this, "_maxLen", -1);
|
|
1199
|
-
if (options) {
|
|
1200
|
-
const { maxLen } = options;
|
|
1201
|
-
if (typeof maxLen === "number" && maxLen > 0 && maxLen % 1 === 0) this._maxLen = maxLen;
|
|
1202
|
-
}
|
|
1203
|
-
}
|
|
1204
|
-
/**
|
|
1205
|
-
* Upper bound for length (if positive), or `-1` when unbounded.
|
|
1206
|
-
* @returns Maximum allowed length.
|
|
1207
|
-
* @remarks Time O(1), Space O(1)
|
|
1208
|
-
*/
|
|
1209
|
-
get maxLen() {
|
|
1210
|
-
return this._maxLen;
|
|
1211
|
-
}
|
|
1212
|
-
/**
|
|
1213
|
-
* First index of a value from the left.
|
|
1214
|
-
* @param searchElement - Value to match.
|
|
1215
|
-
* @param fromIndex - Start position (supports negative index).
|
|
1216
|
-
* @returns Index or `-1` if not found.
|
|
1217
|
-
* @remarks Time O(n), Space O(1)
|
|
1218
|
-
*/
|
|
1219
|
-
indexOf(searchElement, fromIndex = 0) {
|
|
1220
|
-
if (this.length === 0) return -1;
|
|
1221
|
-
if (fromIndex < 0) fromIndex = this.length + fromIndex;
|
|
1222
|
-
if (fromIndex < 0) fromIndex = 0;
|
|
1223
|
-
for (let i = fromIndex; i < this.length; i++) {
|
|
1224
|
-
const element = this.at(i);
|
|
1225
|
-
if (element === searchElement) return i;
|
|
1226
|
-
}
|
|
1227
|
-
return -1;
|
|
1228
|
-
}
|
|
1229
|
-
/**
|
|
1230
|
-
* Last index of a value from the right.
|
|
1231
|
-
* @param searchElement - Value to match.
|
|
1232
|
-
* @param fromIndex - Start position (supports negative index).
|
|
1233
|
-
* @returns Index or `-1` if not found.
|
|
1234
|
-
* @remarks Time O(n), Space O(1)
|
|
1235
|
-
*/
|
|
1236
|
-
lastIndexOf(searchElement, fromIndex = this.length - 1) {
|
|
1237
|
-
if (this.length === 0) return -1;
|
|
1238
|
-
if (fromIndex >= this.length) fromIndex = this.length - 1;
|
|
1239
|
-
if (fromIndex < 0) fromIndex = this.length + fromIndex;
|
|
1240
|
-
for (let i = fromIndex; i >= 0; i--) {
|
|
1241
|
-
const element = this.at(i);
|
|
1242
|
-
if (element === searchElement) return i;
|
|
1243
|
-
}
|
|
1244
|
-
return -1;
|
|
1245
|
-
}
|
|
1246
|
-
/**
|
|
1247
|
-
* Find the first index matching a predicate.
|
|
1248
|
-
* @param predicate - `(element, index, self) => boolean`.
|
|
1249
|
-
* @param thisArg - Optional `this` for callback.
|
|
1250
|
-
* @returns Index or `-1`.
|
|
1251
|
-
* @remarks Time O(n), Space O(1)
|
|
1252
|
-
*/
|
|
1253
|
-
findIndex(predicate, thisArg) {
|
|
1254
|
-
for (let i = 0; i < this.length; i++) {
|
|
1255
|
-
const item = this.at(i);
|
|
1256
|
-
if (item !== void 0 && predicate.call(thisArg, item, i, this)) return i;
|
|
1257
|
-
}
|
|
1258
|
-
return -1;
|
|
1259
|
-
}
|
|
1260
|
-
/**
|
|
1261
|
-
* Concatenate elements and/or containers.
|
|
1262
|
-
* @param items - Elements or other containers.
|
|
1263
|
-
* @returns New container with combined elements (`this` type).
|
|
1264
|
-
* @remarks Time O(sum(length)), Space O(sum(length))
|
|
1265
|
-
*/
|
|
1266
|
-
concat(...items) {
|
|
1267
|
-
const newList = this.clone();
|
|
1268
|
-
for (const item of items) {
|
|
1269
|
-
if (item instanceof _LinearBase) {
|
|
1270
|
-
newList.pushMany(item);
|
|
1271
|
-
} else {
|
|
1272
|
-
newList.push(item);
|
|
1273
|
-
}
|
|
1274
|
-
}
|
|
1275
|
-
return newList;
|
|
1276
|
-
}
|
|
1277
|
-
/**
|
|
1278
|
-
* In-place stable order via array sort semantics.
|
|
1279
|
-
* @param compareFn - Comparator `(a, b) => number`.
|
|
1280
|
-
* @returns This container.
|
|
1281
|
-
* @remarks Time O(n log n), Space O(n) (materializes to array temporarily)
|
|
1282
|
-
*/
|
|
1283
|
-
sort(compareFn) {
|
|
1284
|
-
const arr = this.toArray();
|
|
1285
|
-
arr.sort(compareFn);
|
|
1286
|
-
this.clear();
|
|
1287
|
-
for (const item of arr) this.push(item);
|
|
1288
|
-
return this;
|
|
1289
|
-
}
|
|
1290
|
-
/**
|
|
1291
|
-
* Remove and/or insert elements at a position (array-compatible).
|
|
1292
|
-
* @param start - Start index (supports negative index).
|
|
1293
|
-
* @param deleteCount - How many to remove.
|
|
1294
|
-
* @param items - Elements to insert.
|
|
1295
|
-
* @returns Removed elements as a new list (`this` type).
|
|
1296
|
-
* @remarks Time O(n + m), Space O(min(n, m)) where `m = items.length`
|
|
1297
|
-
*/
|
|
1298
|
-
splice(start, deleteCount = 0, ...items) {
|
|
1299
|
-
const removedList = this._createInstance();
|
|
1300
|
-
start = start < 0 ? this.length + start : start;
|
|
1301
|
-
start = Math.max(0, Math.min(start, this.length));
|
|
1302
|
-
deleteCount = Math.max(0, Math.min(deleteCount, this.length - start));
|
|
1303
|
-
for (let i = 0; i < deleteCount; i++) {
|
|
1304
|
-
const removed = this.deleteAt(start);
|
|
1305
|
-
if (removed !== void 0) {
|
|
1306
|
-
removedList.push(removed);
|
|
1307
|
-
}
|
|
1308
|
-
}
|
|
1309
|
-
for (let i = 0; i < items.length; i++) {
|
|
1310
|
-
this.addAt(start + i, items[i]);
|
|
1311
|
-
}
|
|
1312
|
-
return removedList;
|
|
1313
|
-
}
|
|
1314
|
-
/**
|
|
1315
|
-
* Join all elements into a string.
|
|
1316
|
-
* @param separator - Separator string.
|
|
1317
|
-
* @returns Concatenated string.
|
|
1318
|
-
* @remarks Time O(n), Space O(n)
|
|
1319
|
-
*/
|
|
1320
|
-
join(separator = ",") {
|
|
1321
|
-
return this.toArray().join(separator);
|
|
1322
|
-
}
|
|
1323
|
-
/**
|
|
1324
|
-
* Snapshot elements into a reversed array.
|
|
1325
|
-
* @returns New reversed array.
|
|
1326
|
-
* @remarks Time O(n), Space O(n)
|
|
1327
|
-
*/
|
|
1328
|
-
toReversedArray() {
|
|
1329
|
-
const array = [];
|
|
1330
|
-
for (let i = this.length - 1; i >= 0; i--) {
|
|
1331
|
-
array.push(this.at(i));
|
|
1332
|
-
}
|
|
1333
|
-
return array;
|
|
1334
|
-
}
|
|
1335
|
-
reduceRight(callbackfn, initialValue) {
|
|
1336
|
-
let accumulator = initialValue != null ? initialValue : 0;
|
|
1337
|
-
for (let i = this.length - 1; i >= 0; i--) {
|
|
1338
|
-
accumulator = callbackfn(accumulator, this.at(i), i, this);
|
|
1339
|
-
}
|
|
1340
|
-
return accumulator;
|
|
1341
|
-
}
|
|
1342
|
-
/**
|
|
1343
|
-
* Create a shallow copy of a subrange.
|
|
1344
|
-
* @param start - Inclusive start (supports negative index).
|
|
1345
|
-
* @param end - Exclusive end (supports negative index).
|
|
1346
|
-
* @returns New list with the range (`this` type).
|
|
1347
|
-
* @remarks Time O(n), Space O(n)
|
|
1348
|
-
*/
|
|
1349
|
-
slice(start = 0, end = this.length) {
|
|
1350
|
-
start = start < 0 ? this.length + start : start;
|
|
1351
|
-
end = end < 0 ? this.length + end : end;
|
|
1352
|
-
const newList = this._createInstance();
|
|
1353
|
-
for (let i = start; i < end; i++) {
|
|
1354
|
-
newList.push(this.at(i));
|
|
1355
|
-
}
|
|
1356
|
-
return newList;
|
|
1357
|
-
}
|
|
1358
|
-
/**
|
|
1359
|
-
* Fill a range with a value.
|
|
1360
|
-
* @param value - Value to set.
|
|
1361
|
-
* @param start - Inclusive start.
|
|
1362
|
-
* @param end - Exclusive end.
|
|
1363
|
-
* @returns This list.
|
|
1364
|
-
* @remarks Time O(n), Space O(1)
|
|
1365
|
-
*/
|
|
1366
|
-
fill(value, start = 0, end = this.length) {
|
|
1367
|
-
start = start < 0 ? this.length + start : start;
|
|
1368
|
-
end = end < 0 ? this.length + end : end;
|
|
1369
|
-
if (start < 0) start = 0;
|
|
1370
|
-
if (end > this.length) end = this.length;
|
|
1371
|
-
if (start >= end) return this;
|
|
1372
|
-
for (let i = start; i < end; i++) {
|
|
1373
|
-
this.setAt(i, value);
|
|
1374
|
-
}
|
|
1375
|
-
return this;
|
|
1714
|
+
* @returns An empty like-kind heap instance.
|
|
1715
|
+
*/
|
|
1716
|
+
_spawnLike(options) {
|
|
1717
|
+
return this._createLike([], options);
|
|
1376
1718
|
}
|
|
1377
1719
|
};
|
|
1378
|
-
__name(
|
|
1379
|
-
var
|
|
1720
|
+
__name(_Heap, "Heap");
|
|
1721
|
+
var Heap = _Heap;
|
|
1380
1722
|
|
|
1381
1723
|
// src/data-structures/queue/queue.ts
|
|
1382
1724
|
var _Queue = class _Queue extends LinearBase {
|
|
@@ -1446,6 +1788,30 @@ var _Queue = class _Queue extends LinearBase {
|
|
|
1446
1788
|
|
|
1447
1789
|
|
|
1448
1790
|
|
|
1791
|
+
|
|
1792
|
+
|
|
1793
|
+
|
|
1794
|
+
|
|
1795
|
+
|
|
1796
|
+
|
|
1797
|
+
|
|
1798
|
+
|
|
1799
|
+
|
|
1800
|
+
|
|
1801
|
+
|
|
1802
|
+
|
|
1803
|
+
|
|
1804
|
+
|
|
1805
|
+
|
|
1806
|
+
|
|
1807
|
+
|
|
1808
|
+
|
|
1809
|
+
|
|
1810
|
+
|
|
1811
|
+
|
|
1812
|
+
|
|
1813
|
+
|
|
1814
|
+
|
|
1449
1815
|
* @example
|
|
1450
1816
|
* // Track queue length
|
|
1451
1817
|
* const q = new Queue<number>();
|
|
@@ -1472,6 +1838,30 @@ var _Queue = class _Queue extends LinearBase {
|
|
|
1472
1838
|
|
|
1473
1839
|
|
|
1474
1840
|
|
|
1841
|
+
|
|
1842
|
+
|
|
1843
|
+
|
|
1844
|
+
|
|
1845
|
+
|
|
1846
|
+
|
|
1847
|
+
|
|
1848
|
+
|
|
1849
|
+
|
|
1850
|
+
|
|
1851
|
+
|
|
1852
|
+
|
|
1853
|
+
|
|
1854
|
+
|
|
1855
|
+
|
|
1856
|
+
|
|
1857
|
+
|
|
1858
|
+
|
|
1859
|
+
|
|
1860
|
+
|
|
1861
|
+
|
|
1862
|
+
|
|
1863
|
+
|
|
1864
|
+
|
|
1475
1865
|
* @example
|
|
1476
1866
|
* // View the front element
|
|
1477
1867
|
* const q = new Queue<string>(['first', 'second', 'third']);
|
|
@@ -1514,6 +1904,30 @@ var _Queue = class _Queue extends LinearBase {
|
|
|
1514
1904
|
|
|
1515
1905
|
|
|
1516
1906
|
|
|
1907
|
+
|
|
1908
|
+
|
|
1909
|
+
|
|
1910
|
+
|
|
1911
|
+
|
|
1912
|
+
|
|
1913
|
+
|
|
1914
|
+
|
|
1915
|
+
|
|
1916
|
+
|
|
1917
|
+
|
|
1918
|
+
|
|
1919
|
+
|
|
1920
|
+
|
|
1921
|
+
|
|
1922
|
+
|
|
1923
|
+
|
|
1924
|
+
|
|
1925
|
+
|
|
1926
|
+
|
|
1927
|
+
|
|
1928
|
+
|
|
1929
|
+
|
|
1930
|
+
|
|
1517
1931
|
* @example
|
|
1518
1932
|
* // Queue for...of iteration and isEmpty check
|
|
1519
1933
|
* const queue = new Queue<string>(['A', 'B', 'C', 'D']);
|
|
@@ -1552,6 +1966,30 @@ var _Queue = class _Queue extends LinearBase {
|
|
|
1552
1966
|
|
|
1553
1967
|
|
|
1554
1968
|
|
|
1969
|
+
|
|
1970
|
+
|
|
1971
|
+
|
|
1972
|
+
|
|
1973
|
+
|
|
1974
|
+
|
|
1975
|
+
|
|
1976
|
+
|
|
1977
|
+
|
|
1978
|
+
|
|
1979
|
+
|
|
1980
|
+
|
|
1981
|
+
|
|
1982
|
+
|
|
1983
|
+
|
|
1984
|
+
|
|
1985
|
+
|
|
1986
|
+
|
|
1987
|
+
|
|
1988
|
+
|
|
1989
|
+
|
|
1990
|
+
|
|
1991
|
+
|
|
1992
|
+
|
|
1555
1993
|
* @example
|
|
1556
1994
|
* // basic Queue creation and push operation
|
|
1557
1995
|
* // Create a simple Queue with initial values
|
|
@@ -1597,6 +2035,30 @@ var _Queue = class _Queue extends LinearBase {
|
|
|
1597
2035
|
|
|
1598
2036
|
|
|
1599
2037
|
|
|
2038
|
+
|
|
2039
|
+
|
|
2040
|
+
|
|
2041
|
+
|
|
2042
|
+
|
|
2043
|
+
|
|
2044
|
+
|
|
2045
|
+
|
|
2046
|
+
|
|
2047
|
+
|
|
2048
|
+
|
|
2049
|
+
|
|
2050
|
+
|
|
2051
|
+
|
|
2052
|
+
|
|
2053
|
+
|
|
2054
|
+
|
|
2055
|
+
|
|
2056
|
+
|
|
2057
|
+
|
|
2058
|
+
|
|
2059
|
+
|
|
2060
|
+
|
|
2061
|
+
|
|
1600
2062
|
* @example
|
|
1601
2063
|
* // Queue shift and peek operations
|
|
1602
2064
|
* const queue = new Queue<number>([10, 20, 30, 40]);
|
|
@@ -1632,6 +2094,30 @@ var _Queue = class _Queue extends LinearBase {
|
|
|
1632
2094
|
|
|
1633
2095
|
|
|
1634
2096
|
|
|
2097
|
+
|
|
2098
|
+
|
|
2099
|
+
|
|
2100
|
+
|
|
2101
|
+
|
|
2102
|
+
|
|
2103
|
+
|
|
2104
|
+
|
|
2105
|
+
|
|
2106
|
+
|
|
2107
|
+
|
|
2108
|
+
|
|
2109
|
+
|
|
2110
|
+
|
|
2111
|
+
|
|
2112
|
+
|
|
2113
|
+
|
|
2114
|
+
|
|
2115
|
+
|
|
2116
|
+
|
|
2117
|
+
|
|
2118
|
+
|
|
2119
|
+
|
|
2120
|
+
|
|
1635
2121
|
* @example
|
|
1636
2122
|
* // Remove specific element
|
|
1637
2123
|
* const q = new Queue<number>([1, 2, 3, 2]);
|
|
@@ -1660,6 +2146,30 @@ var _Queue = class _Queue extends LinearBase {
|
|
|
1660
2146
|
|
|
1661
2147
|
|
|
1662
2148
|
|
|
2149
|
+
|
|
2150
|
+
|
|
2151
|
+
|
|
2152
|
+
|
|
2153
|
+
|
|
2154
|
+
|
|
2155
|
+
|
|
2156
|
+
|
|
2157
|
+
|
|
2158
|
+
|
|
2159
|
+
|
|
2160
|
+
|
|
2161
|
+
|
|
2162
|
+
|
|
2163
|
+
|
|
2164
|
+
|
|
2165
|
+
|
|
2166
|
+
|
|
2167
|
+
|
|
2168
|
+
|
|
2169
|
+
|
|
2170
|
+
|
|
2171
|
+
|
|
2172
|
+
|
|
1663
2173
|
* @example
|
|
1664
2174
|
* // Access element by index
|
|
1665
2175
|
* const q = new Queue<string>(['a', 'b', 'c']);
|
|
@@ -1729,6 +2239,30 @@ var _Queue = class _Queue extends LinearBase {
|
|
|
1729
2239
|
|
|
1730
2240
|
|
|
1731
2241
|
|
|
2242
|
+
|
|
2243
|
+
|
|
2244
|
+
|
|
2245
|
+
|
|
2246
|
+
|
|
2247
|
+
|
|
2248
|
+
|
|
2249
|
+
|
|
2250
|
+
|
|
2251
|
+
|
|
2252
|
+
|
|
2253
|
+
|
|
2254
|
+
|
|
2255
|
+
|
|
2256
|
+
|
|
2257
|
+
|
|
2258
|
+
|
|
2259
|
+
|
|
2260
|
+
|
|
2261
|
+
|
|
2262
|
+
|
|
2263
|
+
|
|
2264
|
+
|
|
2265
|
+
|
|
1732
2266
|
* @example
|
|
1733
2267
|
* // Remove all elements
|
|
1734
2268
|
* const q = new Queue<number>([1, 2, 3]);
|
|
@@ -1751,6 +2285,30 @@ var _Queue = class _Queue extends LinearBase {
|
|
|
1751
2285
|
|
|
1752
2286
|
|
|
1753
2287
|
|
|
2288
|
+
|
|
2289
|
+
|
|
2290
|
+
|
|
2291
|
+
|
|
2292
|
+
|
|
2293
|
+
|
|
2294
|
+
|
|
2295
|
+
|
|
2296
|
+
|
|
2297
|
+
|
|
2298
|
+
|
|
2299
|
+
|
|
2300
|
+
|
|
2301
|
+
|
|
2302
|
+
|
|
2303
|
+
|
|
2304
|
+
|
|
2305
|
+
|
|
2306
|
+
|
|
2307
|
+
|
|
2308
|
+
|
|
2309
|
+
|
|
2310
|
+
|
|
2311
|
+
|
|
1754
2312
|
* @example
|
|
1755
2313
|
* // Reclaim unused memory
|
|
1756
2314
|
* const q = new Queue<number>([1, 2, 3, 4, 5]);
|
|
@@ -1796,6 +2354,30 @@ var _Queue = class _Queue extends LinearBase {
|
|
|
1796
2354
|
|
|
1797
2355
|
|
|
1798
2356
|
|
|
2357
|
+
|
|
2358
|
+
|
|
2359
|
+
|
|
2360
|
+
|
|
2361
|
+
|
|
2362
|
+
|
|
2363
|
+
|
|
2364
|
+
|
|
2365
|
+
|
|
2366
|
+
|
|
2367
|
+
|
|
2368
|
+
|
|
2369
|
+
|
|
2370
|
+
|
|
2371
|
+
|
|
2372
|
+
|
|
2373
|
+
|
|
2374
|
+
|
|
2375
|
+
|
|
2376
|
+
|
|
2377
|
+
|
|
2378
|
+
|
|
2379
|
+
|
|
2380
|
+
|
|
1799
2381
|
* @example
|
|
1800
2382
|
* // Create independent copy
|
|
1801
2383
|
* const q = new Queue<number>([1, 2, 3]);
|
|
@@ -1825,6 +2407,30 @@ var _Queue = class _Queue extends LinearBase {
|
|
|
1825
2407
|
|
|
1826
2408
|
|
|
1827
2409
|
|
|
2410
|
+
|
|
2411
|
+
|
|
2412
|
+
|
|
2413
|
+
|
|
2414
|
+
|
|
2415
|
+
|
|
2416
|
+
|
|
2417
|
+
|
|
2418
|
+
|
|
2419
|
+
|
|
2420
|
+
|
|
2421
|
+
|
|
2422
|
+
|
|
2423
|
+
|
|
2424
|
+
|
|
2425
|
+
|
|
2426
|
+
|
|
2427
|
+
|
|
2428
|
+
|
|
2429
|
+
|
|
2430
|
+
|
|
2431
|
+
|
|
2432
|
+
|
|
2433
|
+
|
|
1828
2434
|
* @example
|
|
1829
2435
|
* // Filter elements
|
|
1830
2436
|
* const q = new Queue<number>([1, 2, 3, 4, 5]);
|
|
@@ -1858,6 +2464,30 @@ var _Queue = class _Queue extends LinearBase {
|
|
|
1858
2464
|
|
|
1859
2465
|
|
|
1860
2466
|
|
|
2467
|
+
|
|
2468
|
+
|
|
2469
|
+
|
|
2470
|
+
|
|
2471
|
+
|
|
2472
|
+
|
|
2473
|
+
|
|
2474
|
+
|
|
2475
|
+
|
|
2476
|
+
|
|
2477
|
+
|
|
2478
|
+
|
|
2479
|
+
|
|
2480
|
+
|
|
2481
|
+
|
|
2482
|
+
|
|
2483
|
+
|
|
2484
|
+
|
|
2485
|
+
|
|
2486
|
+
|
|
2487
|
+
|
|
2488
|
+
|
|
2489
|
+
|
|
2490
|
+
|
|
1861
2491
|
* @example
|
|
1862
2492
|
* // Transform elements
|
|
1863
2493
|
* const q = new Queue<number>([1, 2, 3]);
|
|
@@ -2092,7 +2722,7 @@ var _AbstractGraph = class _AbstractGraph extends IterableEntryBase {
|
|
|
2092
2722
|
const newEdge = this.createEdge(srcOrEdge, dest, weight, value);
|
|
2093
2723
|
return this._addEdge(newEdge);
|
|
2094
2724
|
} else {
|
|
2095
|
-
|
|
2725
|
+
raise(TypeError, ERR.invalidArgument("dest must be a Vertex or vertex key when srcOrEdge is an Edge.", "Graph"));
|
|
2096
2726
|
}
|
|
2097
2727
|
}
|
|
2098
2728
|
}
|
|
@@ -2965,6 +3595,30 @@ var _UndirectedGraph = class _UndirectedGraph extends AbstractGraph {
|
|
|
2965
3595
|
|
|
2966
3596
|
|
|
2967
3597
|
|
|
3598
|
+
|
|
3599
|
+
|
|
3600
|
+
|
|
3601
|
+
|
|
3602
|
+
|
|
3603
|
+
|
|
3604
|
+
|
|
3605
|
+
|
|
3606
|
+
|
|
3607
|
+
|
|
3608
|
+
|
|
3609
|
+
|
|
3610
|
+
|
|
3611
|
+
|
|
3612
|
+
|
|
3613
|
+
|
|
3614
|
+
|
|
3615
|
+
|
|
3616
|
+
|
|
3617
|
+
|
|
3618
|
+
|
|
3619
|
+
|
|
3620
|
+
|
|
3621
|
+
|
|
2968
3622
|
* @example
|
|
2969
3623
|
* // Get edge between vertices
|
|
2970
3624
|
* const g = new UndirectedGraph();
|
|
@@ -3026,6 +3680,30 @@ var _UndirectedGraph = class _UndirectedGraph extends AbstractGraph {
|
|
|
3026
3680
|
|
|
3027
3681
|
|
|
3028
3682
|
|
|
3683
|
+
|
|
3684
|
+
|
|
3685
|
+
|
|
3686
|
+
|
|
3687
|
+
|
|
3688
|
+
|
|
3689
|
+
|
|
3690
|
+
|
|
3691
|
+
|
|
3692
|
+
|
|
3693
|
+
|
|
3694
|
+
|
|
3695
|
+
|
|
3696
|
+
|
|
3697
|
+
|
|
3698
|
+
|
|
3699
|
+
|
|
3700
|
+
|
|
3701
|
+
|
|
3702
|
+
|
|
3703
|
+
|
|
3704
|
+
|
|
3705
|
+
|
|
3706
|
+
|
|
3029
3707
|
* @example
|
|
3030
3708
|
* // UndirectedGraph deleteEdge and vertex operations
|
|
3031
3709
|
* const graph = new UndirectedGraph<string>();
|
|
@@ -3086,6 +3764,30 @@ var _UndirectedGraph = class _UndirectedGraph extends AbstractGraph {
|
|
|
3086
3764
|
|
|
3087
3765
|
|
|
3088
3766
|
|
|
3767
|
+
|
|
3768
|
+
|
|
3769
|
+
|
|
3770
|
+
|
|
3771
|
+
|
|
3772
|
+
|
|
3773
|
+
|
|
3774
|
+
|
|
3775
|
+
|
|
3776
|
+
|
|
3777
|
+
|
|
3778
|
+
|
|
3779
|
+
|
|
3780
|
+
|
|
3781
|
+
|
|
3782
|
+
|
|
3783
|
+
|
|
3784
|
+
|
|
3785
|
+
|
|
3786
|
+
|
|
3787
|
+
|
|
3788
|
+
|
|
3789
|
+
|
|
3790
|
+
|
|
3089
3791
|
* @example
|
|
3090
3792
|
* // Remove vertex and edges
|
|
3091
3793
|
* const g = new UndirectedGraph();
|
|
@@ -3161,6 +3863,30 @@ var _UndirectedGraph = class _UndirectedGraph extends AbstractGraph {
|
|
|
3161
3863
|
|
|
3162
3864
|
|
|
3163
3865
|
|
|
3866
|
+
|
|
3867
|
+
|
|
3868
|
+
|
|
3869
|
+
|
|
3870
|
+
|
|
3871
|
+
|
|
3872
|
+
|
|
3873
|
+
|
|
3874
|
+
|
|
3875
|
+
|
|
3876
|
+
|
|
3877
|
+
|
|
3878
|
+
|
|
3879
|
+
|
|
3880
|
+
|
|
3881
|
+
|
|
3882
|
+
|
|
3883
|
+
|
|
3884
|
+
|
|
3885
|
+
|
|
3886
|
+
|
|
3887
|
+
|
|
3888
|
+
|
|
3889
|
+
|
|
3164
3890
|
* @example
|
|
3165
3891
|
* // Get all edges
|
|
3166
3892
|
* const g = new UndirectedGraph();
|
|
@@ -3191,6 +3917,30 @@ var _UndirectedGraph = class _UndirectedGraph extends AbstractGraph {
|
|
|
3191
3917
|
|
|
3192
3918
|
|
|
3193
3919
|
|
|
3920
|
+
|
|
3921
|
+
|
|
3922
|
+
|
|
3923
|
+
|
|
3924
|
+
|
|
3925
|
+
|
|
3926
|
+
|
|
3927
|
+
|
|
3928
|
+
|
|
3929
|
+
|
|
3930
|
+
|
|
3931
|
+
|
|
3932
|
+
|
|
3933
|
+
|
|
3934
|
+
|
|
3935
|
+
|
|
3936
|
+
|
|
3937
|
+
|
|
3938
|
+
|
|
3939
|
+
|
|
3940
|
+
|
|
3941
|
+
|
|
3942
|
+
|
|
3943
|
+
|
|
3194
3944
|
* @example
|
|
3195
3945
|
* // UndirectedGraph connectivity and neighbors
|
|
3196
3946
|
* const graph = new UndirectedGraph<string>();
|
|
@@ -3291,6 +4041,30 @@ var _UndirectedGraph = class _UndirectedGraph extends AbstractGraph {
|
|
|
3291
4041
|
|
|
3292
4042
|
|
|
3293
4043
|
|
|
4044
|
+
|
|
4045
|
+
|
|
4046
|
+
|
|
4047
|
+
|
|
4048
|
+
|
|
4049
|
+
|
|
4050
|
+
|
|
4051
|
+
|
|
4052
|
+
|
|
4053
|
+
|
|
4054
|
+
|
|
4055
|
+
|
|
4056
|
+
|
|
4057
|
+
|
|
4058
|
+
|
|
4059
|
+
|
|
4060
|
+
|
|
4061
|
+
|
|
4062
|
+
|
|
4063
|
+
|
|
4064
|
+
|
|
4065
|
+
|
|
4066
|
+
|
|
4067
|
+
|
|
3294
4068
|
* @example
|
|
3295
4069
|
* // Find articulation points and bridges
|
|
3296
4070
|
* const g = new UndirectedGraph();
|
|
@@ -3413,6 +4187,30 @@ var _UndirectedGraph = class _UndirectedGraph extends AbstractGraph {
|
|
|
3413
4187
|
|
|
3414
4188
|
|
|
3415
4189
|
|
|
4190
|
+
|
|
4191
|
+
|
|
4192
|
+
|
|
4193
|
+
|
|
4194
|
+
|
|
4195
|
+
|
|
4196
|
+
|
|
4197
|
+
|
|
4198
|
+
|
|
4199
|
+
|
|
4200
|
+
|
|
4201
|
+
|
|
4202
|
+
|
|
4203
|
+
|
|
4204
|
+
|
|
4205
|
+
|
|
4206
|
+
|
|
4207
|
+
|
|
4208
|
+
|
|
4209
|
+
|
|
4210
|
+
|
|
4211
|
+
|
|
4212
|
+
|
|
4213
|
+
|
|
3416
4214
|
* @example
|
|
3417
4215
|
* // Detect cycle
|
|
3418
4216
|
* const g = new UndirectedGraph();
|
|
@@ -3457,6 +4255,30 @@ var _UndirectedGraph = class _UndirectedGraph extends AbstractGraph {
|
|
|
3457
4255
|
|
|
3458
4256
|
|
|
3459
4257
|
|
|
4258
|
+
|
|
4259
|
+
|
|
4260
|
+
|
|
4261
|
+
|
|
4262
|
+
|
|
4263
|
+
|
|
4264
|
+
|
|
4265
|
+
|
|
4266
|
+
|
|
4267
|
+
|
|
4268
|
+
|
|
4269
|
+
|
|
4270
|
+
|
|
4271
|
+
|
|
4272
|
+
|
|
4273
|
+
|
|
4274
|
+
|
|
4275
|
+
|
|
4276
|
+
|
|
4277
|
+
|
|
4278
|
+
|
|
4279
|
+
|
|
4280
|
+
|
|
4281
|
+
|
|
3460
4282
|
* @example
|
|
3461
4283
|
* // Find bridge edges
|
|
3462
4284
|
* const g = new UndirectedGraph();
|
|
@@ -3483,6 +4305,30 @@ var _UndirectedGraph = class _UndirectedGraph extends AbstractGraph {
|
|
|
3483
4305
|
|
|
3484
4306
|
|
|
3485
4307
|
|
|
4308
|
+
|
|
4309
|
+
|
|
4310
|
+
|
|
4311
|
+
|
|
4312
|
+
|
|
4313
|
+
|
|
4314
|
+
|
|
4315
|
+
|
|
4316
|
+
|
|
4317
|
+
|
|
4318
|
+
|
|
4319
|
+
|
|
4320
|
+
|
|
4321
|
+
|
|
4322
|
+
|
|
4323
|
+
|
|
4324
|
+
|
|
4325
|
+
|
|
4326
|
+
|
|
4327
|
+
|
|
4328
|
+
|
|
4329
|
+
|
|
4330
|
+
|
|
4331
|
+
|
|
3486
4332
|
* @example
|
|
3487
4333
|
* // Find articulation points
|
|
3488
4334
|
* const g = new UndirectedGraph();
|
|
@@ -3552,5 +4398,6 @@ exports.Range = Range;
|
|
|
3552
4398
|
exports.UndirectedEdge = UndirectedEdge;
|
|
3553
4399
|
exports.UndirectedGraph = UndirectedGraph;
|
|
3554
4400
|
exports.UndirectedVertex = UndirectedVertex;
|
|
4401
|
+
exports.raise = raise;
|
|
3555
4402
|
//# sourceMappingURL=index.cjs.map
|
|
3556
4403
|
//# sourceMappingURL=index.cjs.map
|