data-structure-typed 1.49.0 → 1.49.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/CHANGELOG.md +1 -1
- package/README.md +16 -16
- package/README_zh-CN.md +2 -2
- package/benchmark/report.html +46 -1
- package/benchmark/report.json +457 -22
- package/dist/cjs/data-structures/base/iterable-base.d.ts +11 -0
- package/dist/cjs/data-structures/base/iterable-base.js +21 -0
- package/dist/cjs/data-structures/base/iterable-base.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/avl-tree.d.ts +10 -12
- package/dist/cjs/data-structures/binary-tree/avl-tree.js +3 -4
- package/dist/cjs/data-structures/binary-tree/avl-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/binary-tree.d.ts +58 -58
- package/dist/cjs/data-structures/binary-tree/binary-tree.js +6 -6
- package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/bst.d.ts +15 -15
- package/dist/cjs/data-structures/binary-tree/bst.js +3 -3
- package/dist/cjs/data-structures/binary-tree/bst.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/rb-tree.d.ts +11 -11
- package/dist/cjs/data-structures/binary-tree/rb-tree.js +5 -6
- package/dist/cjs/data-structures/binary-tree/rb-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/tree-multimap.d.ts +14 -14
- package/dist/cjs/data-structures/binary-tree/tree-multimap.js +3 -3
- package/dist/cjs/data-structures/binary-tree/tree-multimap.js.map +1 -1
- package/dist/cjs/data-structures/graph/abstract-graph.d.ts +9 -3
- package/dist/cjs/data-structures/graph/abstract-graph.js +27 -31
- package/dist/cjs/data-structures/graph/abstract-graph.js.map +1 -1
- package/dist/cjs/data-structures/graph/directed-graph.d.ts +8 -1
- package/dist/cjs/data-structures/graph/directed-graph.js +1 -8
- package/dist/cjs/data-structures/graph/directed-graph.js.map +1 -1
- package/dist/cjs/data-structures/graph/map-graph.d.ts +1 -1
- package/dist/cjs/data-structures/graph/undirected-graph.d.ts +8 -1
- package/dist/cjs/data-structures/graph/undirected-graph.js +1 -8
- package/dist/cjs/data-structures/graph/undirected-graph.js.map +1 -1
- package/dist/cjs/data-structures/hash/hash-map.d.ts +22 -10
- package/dist/cjs/data-structures/hash/hash-map.js +28 -16
- package/dist/cjs/data-structures/hash/hash-map.js.map +1 -1
- package/dist/cjs/data-structures/hash/hash-table.d.ts +2 -2
- package/dist/cjs/data-structures/hash/hash-table.js.map +1 -1
- package/dist/cjs/data-structures/heap/heap.d.ts +20 -38
- package/dist/cjs/data-structures/heap/heap.js +22 -42
- package/dist/cjs/data-structures/heap/heap.js.map +1 -1
- package/dist/cjs/data-structures/heap/max-heap.d.ts +11 -1
- package/dist/cjs/data-structures/heap/max-heap.js +10 -7
- package/dist/cjs/data-structures/heap/max-heap.js.map +1 -1
- package/dist/cjs/data-structures/heap/min-heap.d.ts +11 -1
- package/dist/cjs/data-structures/heap/min-heap.js +10 -7
- package/dist/cjs/data-structures/heap/min-heap.js.map +1 -1
- package/dist/cjs/data-structures/linked-list/doubly-linked-list.d.ts +95 -95
- package/dist/cjs/data-structures/linked-list/doubly-linked-list.js +132 -136
- package/dist/cjs/data-structures/linked-list/doubly-linked-list.js.map +1 -1
- package/dist/cjs/data-structures/linked-list/singly-linked-list.d.ts +18 -23
- package/dist/cjs/data-structures/linked-list/singly-linked-list.js +42 -49
- package/dist/cjs/data-structures/linked-list/singly-linked-list.js.map +1 -1
- package/dist/cjs/data-structures/linked-list/skip-linked-list.d.ts +2 -2
- package/dist/cjs/data-structures/linked-list/skip-linked-list.js +2 -2
- package/dist/cjs/data-structures/linked-list/skip-linked-list.js.map +1 -1
- package/dist/cjs/data-structures/priority-queue/max-priority-queue.d.ts +1 -1
- package/dist/cjs/data-structures/priority-queue/max-priority-queue.js +0 -7
- package/dist/cjs/data-structures/priority-queue/max-priority-queue.js.map +1 -1
- package/dist/cjs/data-structures/priority-queue/min-priority-queue.d.ts +1 -1
- package/dist/cjs/data-structures/priority-queue/min-priority-queue.js +0 -7
- package/dist/cjs/data-structures/priority-queue/min-priority-queue.js.map +1 -1
- package/dist/cjs/data-structures/priority-queue/priority-queue.d.ts +9 -1
- package/dist/cjs/data-structures/priority-queue/priority-queue.js +8 -7
- package/dist/cjs/data-structures/priority-queue/priority-queue.js.map +1 -1
- package/dist/cjs/data-structures/queue/deque.d.ts +76 -80
- package/dist/cjs/data-structures/queue/deque.js +106 -122
- package/dist/cjs/data-structures/queue/deque.js.map +1 -1
- package/dist/cjs/data-structures/queue/queue.d.ts +30 -16
- package/dist/cjs/data-structures/queue/queue.js +31 -24
- package/dist/cjs/data-structures/queue/queue.js.map +1 -1
- package/dist/cjs/data-structures/stack/stack.d.ts +17 -8
- package/dist/cjs/data-structures/stack/stack.js +9 -9
- package/dist/cjs/data-structures/stack/stack.js.map +1 -1
- package/dist/cjs/data-structures/trie/trie.d.ts +14 -5
- package/dist/cjs/data-structures/trie/trie.js +13 -13
- package/dist/cjs/data-structures/trie/trie.js.map +1 -1
- package/dist/cjs/interfaces/binary-tree.d.ts +4 -4
- package/dist/cjs/types/common.d.ts +32 -8
- package/dist/cjs/types/common.js +22 -1
- package/dist/cjs/types/common.js.map +1 -1
- package/dist/cjs/types/data-structures/binary-tree/binary-tree.d.ts +1 -24
- package/dist/cjs/types/data-structures/binary-tree/binary-tree.js +0 -22
- package/dist/cjs/types/data-structures/binary-tree/binary-tree.js.map +1 -1
- package/dist/cjs/types/data-structures/binary-tree/rb-tree.d.ts +1 -1
- package/dist/cjs/types/data-structures/binary-tree/tree-multimap.d.ts +1 -1
- package/dist/mjs/data-structures/base/iterable-base.d.ts +11 -0
- package/dist/mjs/data-structures/base/iterable-base.js +21 -0
- package/dist/mjs/data-structures/binary-tree/avl-tree.d.ts +10 -12
- package/dist/mjs/data-structures/binary-tree/avl-tree.js +3 -4
- package/dist/mjs/data-structures/binary-tree/binary-tree.d.ts +58 -58
- package/dist/mjs/data-structures/binary-tree/binary-tree.js +6 -6
- package/dist/mjs/data-structures/binary-tree/bst.d.ts +15 -15
- package/dist/mjs/data-structures/binary-tree/bst.js +3 -3
- package/dist/mjs/data-structures/binary-tree/rb-tree.d.ts +11 -11
- package/dist/mjs/data-structures/binary-tree/rb-tree.js +5 -6
- package/dist/mjs/data-structures/binary-tree/tree-multimap.d.ts +14 -14
- package/dist/mjs/data-structures/binary-tree/tree-multimap.js +3 -3
- package/dist/mjs/data-structures/graph/abstract-graph.d.ts +9 -3
- package/dist/mjs/data-structures/graph/abstract-graph.js +27 -31
- package/dist/mjs/data-structures/graph/directed-graph.d.ts +8 -1
- package/dist/mjs/data-structures/graph/directed-graph.js +1 -8
- package/dist/mjs/data-structures/graph/map-graph.d.ts +1 -1
- package/dist/mjs/data-structures/graph/undirected-graph.d.ts +8 -1
- package/dist/mjs/data-structures/graph/undirected-graph.js +1 -8
- package/dist/mjs/data-structures/hash/hash-map.d.ts +22 -10
- package/dist/mjs/data-structures/hash/hash-map.js +27 -15
- package/dist/mjs/data-structures/hash/hash-table.d.ts +2 -2
- package/dist/mjs/data-structures/heap/heap.d.ts +20 -38
- package/dist/mjs/data-structures/heap/heap.js +23 -43
- package/dist/mjs/data-structures/heap/max-heap.d.ts +11 -1
- package/dist/mjs/data-structures/heap/max-heap.js +9 -6
- package/dist/mjs/data-structures/heap/min-heap.d.ts +11 -1
- package/dist/mjs/data-structures/heap/min-heap.js +9 -6
- package/dist/mjs/data-structures/linked-list/doubly-linked-list.d.ts +95 -95
- package/dist/mjs/data-structures/linked-list/doubly-linked-list.js +132 -136
- package/dist/mjs/data-structures/linked-list/singly-linked-list.d.ts +18 -23
- package/dist/mjs/data-structures/linked-list/singly-linked-list.js +43 -50
- package/dist/mjs/data-structures/linked-list/skip-linked-list.d.ts +2 -2
- package/dist/mjs/data-structures/linked-list/skip-linked-list.js +2 -2
- package/dist/mjs/data-structures/priority-queue/max-priority-queue.d.ts +1 -1
- package/dist/mjs/data-structures/priority-queue/max-priority-queue.js +0 -7
- package/dist/mjs/data-structures/priority-queue/min-priority-queue.d.ts +1 -1
- package/dist/mjs/data-structures/priority-queue/min-priority-queue.js +0 -7
- package/dist/mjs/data-structures/priority-queue/priority-queue.d.ts +9 -1
- package/dist/mjs/data-structures/priority-queue/priority-queue.js +7 -6
- package/dist/mjs/data-structures/queue/deque.d.ts +76 -80
- package/dist/mjs/data-structures/queue/deque.js +106 -122
- package/dist/mjs/data-structures/queue/queue.d.ts +30 -16
- package/dist/mjs/data-structures/queue/queue.js +31 -24
- package/dist/mjs/data-structures/stack/stack.d.ts +17 -8
- package/dist/mjs/data-structures/stack/stack.js +10 -10
- package/dist/mjs/data-structures/trie/trie.d.ts +14 -5
- package/dist/mjs/data-structures/trie/trie.js +14 -14
- package/dist/mjs/interfaces/binary-tree.d.ts +4 -4
- package/dist/mjs/types/common.d.ts +32 -8
- package/dist/mjs/types/common.js +21 -0
- package/dist/mjs/types/data-structures/binary-tree/binary-tree.d.ts +1 -24
- package/dist/mjs/types/data-structures/binary-tree/binary-tree.js +1 -21
- package/dist/mjs/types/data-structures/binary-tree/rb-tree.d.ts +1 -1
- package/dist/mjs/types/data-structures/binary-tree/tree-multimap.d.ts +1 -1
- package/dist/umd/data-structure-typed.js +533 -558
- package/dist/umd/data-structure-typed.min.js +2 -2
- package/dist/umd/data-structure-typed.min.js.map +1 -1
- package/package.json +1 -1
- package/src/data-structures/base/iterable-base.ts +24 -0
- package/src/data-structures/binary-tree/avl-tree.ts +14 -14
- package/src/data-structures/binary-tree/binary-tree.ts +74 -77
- package/src/data-structures/binary-tree/bst.ts +18 -17
- package/src/data-structures/binary-tree/rb-tree.ts +17 -18
- package/src/data-structures/binary-tree/tree-multimap.ts +22 -20
- package/src/data-structures/graph/abstract-graph.ts +35 -25
- package/src/data-structures/graph/directed-graph.ts +2 -2
- package/src/data-structures/graph/map-graph.ts +1 -1
- package/src/data-structures/graph/undirected-graph.ts +2 -2
- package/src/data-structures/hash/hash-map.ts +40 -24
- package/src/data-structures/hash/hash-table.ts +3 -3
- package/src/data-structures/heap/heap.ts +33 -60
- package/src/data-structures/heap/max-heap.ts +11 -2
- package/src/data-structures/heap/min-heap.ts +11 -2
- package/src/data-structures/linked-list/doubly-linked-list.ts +147 -145
- package/src/data-structures/linked-list/singly-linked-list.ts +52 -52
- package/src/data-structures/linked-list/skip-linked-list.ts +2 -2
- package/src/data-structures/priority-queue/max-priority-queue.ts +1 -1
- package/src/data-structures/priority-queue/min-priority-queue.ts +1 -1
- package/src/data-structures/priority-queue/priority-queue.ts +9 -2
- package/src/data-structures/queue/deque.ts +129 -144
- package/src/data-structures/queue/queue.ts +37 -26
- package/src/data-structures/stack/stack.ts +20 -14
- package/src/data-structures/trie/trie.ts +18 -13
- package/src/interfaces/binary-tree.ts +5 -5
- package/src/types/common.ts +37 -12
- package/src/types/data-structures/binary-tree/avl-tree.ts +0 -1
- package/src/types/data-structures/binary-tree/binary-tree.ts +1 -26
- package/src/types/data-structures/binary-tree/bst.ts +0 -1
- package/src/types/data-structures/binary-tree/rb-tree.ts +1 -1
- package/src/types/data-structures/binary-tree/tree-multimap.ts +1 -1
- package/test/performance/data-structures/comparison/comparison.test.ts +6 -6
- package/test/performance/data-structures/heap/heap.test.ts +2 -2
- package/test/performance/data-structures/linked-list/doubly-linked-list.test.ts +2 -2
- package/test/performance/data-structures/linked-list/singly-linked-list.test.ts +2 -2
- package/test/performance/data-structures/priority-queue/priority-queue.test.ts +2 -2
- package/test/unit/data-structures/binary-tree/binary-tree.test.ts +2 -2
- package/test/unit/data-structures/graph/directed-graph.test.ts +21 -1
- package/test/unit/data-structures/graph/undirected-graph.test.ts +39 -1
- package/test/unit/data-structures/hash/hash-map.test.ts +2 -2
- package/test/unit/data-structures/heap/heap.test.ts +1 -1
- package/test/unit/data-structures/heap/min-heap.test.ts +1 -1
- package/test/unit/data-structures/linked-list/doubly-linked-list.test.ts +30 -30
- package/test/unit/data-structures/linked-list/linked-list.test.ts +1 -1
- package/test/unit/data-structures/linked-list/singly-linked-list.test.ts +21 -21
- package/test/unit/data-structures/linked-list/skip-list.test.ts +2 -2
- package/test/unit/data-structures/queue/deque.test.ts +5 -5
- package/test/unit/data-structures/queue/queue.test.ts +4 -4
- package/test/unit/data-structures/trie/trie.test.ts +1 -1
|
@@ -444,80 +444,6 @@ var dataStructureTyped = (() => {
|
|
|
444
444
|
__publicField(_HashTable, "LOAD_FACTOR", 0.75);
|
|
445
445
|
var HashTable = _HashTable;
|
|
446
446
|
|
|
447
|
-
// src/utils/utils.ts
|
|
448
|
-
var uuidV4 = function() {
|
|
449
|
-
return "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx".replace(/[x]/g, function(c) {
|
|
450
|
-
const r = Math.random() * 16 | 0, v = c == "x" ? r : r & 3 | 8;
|
|
451
|
-
return v.toString(16);
|
|
452
|
-
});
|
|
453
|
-
};
|
|
454
|
-
var arrayRemove = function(array, predicate) {
|
|
455
|
-
let i = -1, len = array ? array.length : 0;
|
|
456
|
-
const result = [];
|
|
457
|
-
while (++i < len) {
|
|
458
|
-
const value = array[i];
|
|
459
|
-
if (predicate(value, i, array)) {
|
|
460
|
-
result.push(value);
|
|
461
|
-
Array.prototype.splice.call(array, i--, 1);
|
|
462
|
-
len--;
|
|
463
|
-
}
|
|
464
|
-
}
|
|
465
|
-
return result;
|
|
466
|
-
};
|
|
467
|
-
var THUNK_SYMBOL = Symbol("thunk");
|
|
468
|
-
var isThunk = (fnOrValue) => {
|
|
469
|
-
return typeof fnOrValue === "function" && fnOrValue.__THUNK__ === THUNK_SYMBOL;
|
|
470
|
-
};
|
|
471
|
-
var toThunk = (fn) => {
|
|
472
|
-
const thunk = () => fn();
|
|
473
|
-
thunk.__THUNK__ = THUNK_SYMBOL;
|
|
474
|
-
return thunk;
|
|
475
|
-
};
|
|
476
|
-
var trampoline = (fn) => {
|
|
477
|
-
const cont = (...args) => toThunk(() => fn(...args));
|
|
478
|
-
return Object.assign(
|
|
479
|
-
(...args) => {
|
|
480
|
-
let result = fn(...args);
|
|
481
|
-
while (isThunk(result) && typeof result === "function") {
|
|
482
|
-
result = result();
|
|
483
|
-
}
|
|
484
|
-
return result;
|
|
485
|
-
},
|
|
486
|
-
{ cont }
|
|
487
|
-
);
|
|
488
|
-
};
|
|
489
|
-
var trampolineAsync = (fn) => {
|
|
490
|
-
const cont = (...args) => toThunk(() => fn(...args));
|
|
491
|
-
return Object.assign(
|
|
492
|
-
(...args) => __async(void 0, null, function* () {
|
|
493
|
-
let result = yield fn(...args);
|
|
494
|
-
while (isThunk(result) && typeof result === "function") {
|
|
495
|
-
result = yield result();
|
|
496
|
-
}
|
|
497
|
-
return result;
|
|
498
|
-
}),
|
|
499
|
-
{ cont }
|
|
500
|
-
);
|
|
501
|
-
};
|
|
502
|
-
var getMSB = (value) => {
|
|
503
|
-
if (value <= 0) {
|
|
504
|
-
return 0;
|
|
505
|
-
}
|
|
506
|
-
return 1 << 31 - Math.clz32(value);
|
|
507
|
-
};
|
|
508
|
-
var rangeCheck = (index, min, max, message = "Index out of bounds.") => {
|
|
509
|
-
if (index < min || index > max)
|
|
510
|
-
throw new RangeError(message);
|
|
511
|
-
};
|
|
512
|
-
var throwRangeError = (message = "The value is off-limits.") => {
|
|
513
|
-
throw new RangeError(message);
|
|
514
|
-
};
|
|
515
|
-
var isWeakKey = (input) => {
|
|
516
|
-
const inputType = typeof input;
|
|
517
|
-
return inputType === "object" && input !== null || inputType === "function";
|
|
518
|
-
};
|
|
519
|
-
var calcMinUnitsRequired = (totalQuantity, unitSize) => Math.floor((totalQuantity + unitSize - 1) / unitSize);
|
|
520
|
-
|
|
521
447
|
// src/data-structures/base/iterable-base.ts
|
|
522
448
|
var IterableEntryBase = class {
|
|
523
449
|
/**
|
|
@@ -690,6 +616,20 @@ var dataStructureTyped = (() => {
|
|
|
690
616
|
}
|
|
691
617
|
return accumulator;
|
|
692
618
|
}
|
|
619
|
+
hasValue(value) {
|
|
620
|
+
for (const [, elementValue] of this) {
|
|
621
|
+
if (elementValue === value)
|
|
622
|
+
return true;
|
|
623
|
+
}
|
|
624
|
+
return false;
|
|
625
|
+
}
|
|
626
|
+
/**
|
|
627
|
+
* Time Complexity: O(n)
|
|
628
|
+
* Space Complexity: O(n)
|
|
629
|
+
*/
|
|
630
|
+
print() {
|
|
631
|
+
console.log([...this]);
|
|
632
|
+
}
|
|
693
633
|
};
|
|
694
634
|
var IterableElementBase = class {
|
|
695
635
|
/**
|
|
@@ -825,7 +765,88 @@ var dataStructureTyped = (() => {
|
|
|
825
765
|
}
|
|
826
766
|
return accumulator;
|
|
827
767
|
}
|
|
768
|
+
/**
|
|
769
|
+
* Time Complexity: O(n)
|
|
770
|
+
* Space Complexity: O(n)
|
|
771
|
+
*/
|
|
772
|
+
print() {
|
|
773
|
+
console.log([...this]);
|
|
774
|
+
}
|
|
775
|
+
};
|
|
776
|
+
|
|
777
|
+
// src/utils/utils.ts
|
|
778
|
+
var uuidV4 = function() {
|
|
779
|
+
return "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx".replace(/[x]/g, function(c) {
|
|
780
|
+
const r = Math.random() * 16 | 0, v = c == "x" ? r : r & 3 | 8;
|
|
781
|
+
return v.toString(16);
|
|
782
|
+
});
|
|
783
|
+
};
|
|
784
|
+
var arrayRemove = function(array, predicate) {
|
|
785
|
+
let i = -1, len = array ? array.length : 0;
|
|
786
|
+
const result = [];
|
|
787
|
+
while (++i < len) {
|
|
788
|
+
const value = array[i];
|
|
789
|
+
if (predicate(value, i, array)) {
|
|
790
|
+
result.push(value);
|
|
791
|
+
Array.prototype.splice.call(array, i--, 1);
|
|
792
|
+
len--;
|
|
793
|
+
}
|
|
794
|
+
}
|
|
795
|
+
return result;
|
|
796
|
+
};
|
|
797
|
+
var THUNK_SYMBOL = Symbol("thunk");
|
|
798
|
+
var isThunk = (fnOrValue) => {
|
|
799
|
+
return typeof fnOrValue === "function" && fnOrValue.__THUNK__ === THUNK_SYMBOL;
|
|
800
|
+
};
|
|
801
|
+
var toThunk = (fn) => {
|
|
802
|
+
const thunk = () => fn();
|
|
803
|
+
thunk.__THUNK__ = THUNK_SYMBOL;
|
|
804
|
+
return thunk;
|
|
805
|
+
};
|
|
806
|
+
var trampoline = (fn) => {
|
|
807
|
+
const cont = (...args) => toThunk(() => fn(...args));
|
|
808
|
+
return Object.assign(
|
|
809
|
+
(...args) => {
|
|
810
|
+
let result = fn(...args);
|
|
811
|
+
while (isThunk(result) && typeof result === "function") {
|
|
812
|
+
result = result();
|
|
813
|
+
}
|
|
814
|
+
return result;
|
|
815
|
+
},
|
|
816
|
+
{ cont }
|
|
817
|
+
);
|
|
818
|
+
};
|
|
819
|
+
var trampolineAsync = (fn) => {
|
|
820
|
+
const cont = (...args) => toThunk(() => fn(...args));
|
|
821
|
+
return Object.assign(
|
|
822
|
+
(...args) => __async(void 0, null, function* () {
|
|
823
|
+
let result = yield fn(...args);
|
|
824
|
+
while (isThunk(result) && typeof result === "function") {
|
|
825
|
+
result = yield result();
|
|
826
|
+
}
|
|
827
|
+
return result;
|
|
828
|
+
}),
|
|
829
|
+
{ cont }
|
|
830
|
+
);
|
|
831
|
+
};
|
|
832
|
+
var getMSB = (value) => {
|
|
833
|
+
if (value <= 0) {
|
|
834
|
+
return 0;
|
|
835
|
+
}
|
|
836
|
+
return 1 << 31 - Math.clz32(value);
|
|
837
|
+
};
|
|
838
|
+
var rangeCheck = (index, min, max, message = "Index out of bounds.") => {
|
|
839
|
+
if (index < min || index > max)
|
|
840
|
+
throw new RangeError(message);
|
|
841
|
+
};
|
|
842
|
+
var throwRangeError = (message = "The value is off-limits.") => {
|
|
843
|
+
throw new RangeError(message);
|
|
844
|
+
};
|
|
845
|
+
var isWeakKey = (input) => {
|
|
846
|
+
const inputType = typeof input;
|
|
847
|
+
return inputType === "object" && input !== null || inputType === "function";
|
|
828
848
|
};
|
|
849
|
+
var calcMinUnitsRequired = (totalQuantity, unitSize) => Math.floor((totalQuantity + unitSize - 1) / unitSize);
|
|
829
850
|
|
|
830
851
|
// src/data-structures/hash/hash-map.ts
|
|
831
852
|
var HashMap = class _HashMap extends IterableEntryBase {
|
|
@@ -886,6 +907,7 @@ var dataStructureTyped = (() => {
|
|
|
886
907
|
}
|
|
887
908
|
this._store[strKey] = { key, value };
|
|
888
909
|
}
|
|
910
|
+
return true;
|
|
889
911
|
}
|
|
890
912
|
/**
|
|
891
913
|
* The function "setMany" sets multiple key-value pairs in a map.
|
|
@@ -893,8 +915,10 @@ var dataStructureTyped = (() => {
|
|
|
893
915
|
* key-value pair is represented as an array with two elements: the key and the value.
|
|
894
916
|
*/
|
|
895
917
|
setMany(elements) {
|
|
918
|
+
const results = [];
|
|
896
919
|
for (const [key, value] of elements)
|
|
897
|
-
this.set(key, value);
|
|
920
|
+
results.push(this.set(key, value));
|
|
921
|
+
return results;
|
|
898
922
|
}
|
|
899
923
|
/**
|
|
900
924
|
* The `get` function retrieves a value from a map based on a given key, either from an object map or
|
|
@@ -1009,6 +1033,9 @@ var dataStructureTyped = (() => {
|
|
|
1009
1033
|
print() {
|
|
1010
1034
|
console.log([...this.entries()]);
|
|
1011
1035
|
}
|
|
1036
|
+
put(key, value) {
|
|
1037
|
+
return this.set(key, value);
|
|
1038
|
+
}
|
|
1012
1039
|
/**
|
|
1013
1040
|
* The function returns an iterator that yields key-value pairs from both an object store and an
|
|
1014
1041
|
* object map.
|
|
@@ -1160,7 +1187,7 @@ var dataStructureTyped = (() => {
|
|
|
1160
1187
|
this._sentinel.prev = node;
|
|
1161
1188
|
this._size++;
|
|
1162
1189
|
}
|
|
1163
|
-
return
|
|
1190
|
+
return true;
|
|
1164
1191
|
}
|
|
1165
1192
|
has(key) {
|
|
1166
1193
|
if (isWeakKey(key)) {
|
|
@@ -1172,10 +1199,12 @@ var dataStructureTyped = (() => {
|
|
|
1172
1199
|
}
|
|
1173
1200
|
}
|
|
1174
1201
|
setMany(entries) {
|
|
1202
|
+
const results = [];
|
|
1175
1203
|
for (const entry of entries) {
|
|
1176
1204
|
const [key, value] = entry;
|
|
1177
|
-
this.set(key, value);
|
|
1205
|
+
results.push(this.set(key, value));
|
|
1178
1206
|
}
|
|
1207
|
+
return results;
|
|
1179
1208
|
}
|
|
1180
1209
|
/**
|
|
1181
1210
|
* Time Complexity: O(1)
|
|
@@ -1218,7 +1247,7 @@ var dataStructureTyped = (() => {
|
|
|
1218
1247
|
while (index--) {
|
|
1219
1248
|
node = node.next;
|
|
1220
1249
|
}
|
|
1221
|
-
return
|
|
1250
|
+
return node.value;
|
|
1222
1251
|
}
|
|
1223
1252
|
/**
|
|
1224
1253
|
* Time Complexity: O(1)
|
|
@@ -1265,8 +1294,7 @@ var dataStructureTyped = (() => {
|
|
|
1265
1294
|
while (index--) {
|
|
1266
1295
|
node = node.next;
|
|
1267
1296
|
}
|
|
1268
|
-
this._deleteNode(node);
|
|
1269
|
-
return this._size;
|
|
1297
|
+
return this._deleteNode(node);
|
|
1270
1298
|
}
|
|
1271
1299
|
/**
|
|
1272
1300
|
* Time Complexity: O(1)
|
|
@@ -1359,8 +1387,8 @@ var dataStructureTyped = (() => {
|
|
|
1359
1387
|
}
|
|
1360
1388
|
return mappedMap;
|
|
1361
1389
|
}
|
|
1362
|
-
|
|
1363
|
-
|
|
1390
|
+
put(key, value) {
|
|
1391
|
+
return this.set(key, value);
|
|
1364
1392
|
}
|
|
1365
1393
|
/**
|
|
1366
1394
|
* Time Complexity: O(n), where n is the number of elements in the LinkedHashMap.
|
|
@@ -1396,6 +1424,7 @@ var dataStructureTyped = (() => {
|
|
|
1396
1424
|
this._tail = prev;
|
|
1397
1425
|
}
|
|
1398
1426
|
this._size -= 1;
|
|
1427
|
+
return true;
|
|
1399
1428
|
}
|
|
1400
1429
|
};
|
|
1401
1430
|
|
|
@@ -1421,10 +1450,10 @@ var dataStructureTyped = (() => {
|
|
|
1421
1450
|
super();
|
|
1422
1451
|
__publicField(this, "_head");
|
|
1423
1452
|
__publicField(this, "_tail");
|
|
1424
|
-
__publicField(this, "
|
|
1453
|
+
__publicField(this, "_size");
|
|
1425
1454
|
this._head = void 0;
|
|
1426
1455
|
this._tail = void 0;
|
|
1427
|
-
this.
|
|
1456
|
+
this._size = 0;
|
|
1428
1457
|
if (elements) {
|
|
1429
1458
|
for (const el of elements)
|
|
1430
1459
|
this.push(el);
|
|
@@ -1436,8 +1465,8 @@ var dataStructureTyped = (() => {
|
|
|
1436
1465
|
get tail() {
|
|
1437
1466
|
return this._tail;
|
|
1438
1467
|
}
|
|
1439
|
-
get
|
|
1440
|
-
return this.
|
|
1468
|
+
get size() {
|
|
1469
|
+
return this._size;
|
|
1441
1470
|
}
|
|
1442
1471
|
/**
|
|
1443
1472
|
* Time Complexity: O(n) - Linear time, where n is the length of the input array, as it performs a loop to push each element into the linked list.
|
|
@@ -1480,7 +1509,8 @@ var dataStructureTyped = (() => {
|
|
|
1480
1509
|
this.tail.next = newNode;
|
|
1481
1510
|
this._tail = newNode;
|
|
1482
1511
|
}
|
|
1483
|
-
this.
|
|
1512
|
+
this._size++;
|
|
1513
|
+
return true;
|
|
1484
1514
|
}
|
|
1485
1515
|
/**
|
|
1486
1516
|
* Time Complexity: O(1) - Constant time, as it involves basic pointer adjustments.
|
|
@@ -1495,7 +1525,7 @@ var dataStructureTyped = (() => {
|
|
|
1495
1525
|
* any type (E) as specified in the generic type declaration of the class or function.
|
|
1496
1526
|
*/
|
|
1497
1527
|
addLast(value) {
|
|
1498
|
-
this.push(value);
|
|
1528
|
+
return this.push(value);
|
|
1499
1529
|
}
|
|
1500
1530
|
/**
|
|
1501
1531
|
* Time Complexity: O(n) - Linear time in the worst case, as it may need to traverse the list to find the last element.
|
|
@@ -1517,7 +1547,7 @@ var dataStructureTyped = (() => {
|
|
|
1517
1547
|
const value2 = this.head.value;
|
|
1518
1548
|
this._head = void 0;
|
|
1519
1549
|
this._tail = void 0;
|
|
1520
|
-
this.
|
|
1550
|
+
this._size--;
|
|
1521
1551
|
return value2;
|
|
1522
1552
|
}
|
|
1523
1553
|
let current = this.head;
|
|
@@ -1527,7 +1557,7 @@ var dataStructureTyped = (() => {
|
|
|
1527
1557
|
const value = this.tail.value;
|
|
1528
1558
|
current.next = void 0;
|
|
1529
1559
|
this._tail = current;
|
|
1530
|
-
this.
|
|
1560
|
+
this._size--;
|
|
1531
1561
|
return value;
|
|
1532
1562
|
}
|
|
1533
1563
|
/**
|
|
@@ -1562,7 +1592,7 @@ var dataStructureTyped = (() => {
|
|
|
1562
1592
|
return void 0;
|
|
1563
1593
|
const removedNode = this.head;
|
|
1564
1594
|
this._head = this.head.next;
|
|
1565
|
-
this.
|
|
1595
|
+
this._size--;
|
|
1566
1596
|
return removedNode.value;
|
|
1567
1597
|
}
|
|
1568
1598
|
/**
|
|
@@ -1600,7 +1630,8 @@ var dataStructureTyped = (() => {
|
|
|
1600
1630
|
newNode.next = this.head;
|
|
1601
1631
|
this._head = newNode;
|
|
1602
1632
|
}
|
|
1603
|
-
this.
|
|
1633
|
+
this._size++;
|
|
1634
|
+
return true;
|
|
1604
1635
|
}
|
|
1605
1636
|
/**
|
|
1606
1637
|
* Time Complexity: O(1) - Constant time, as it involves adjusting pointers at the head.
|
|
@@ -1615,7 +1646,7 @@ var dataStructureTyped = (() => {
|
|
|
1615
1646
|
* linked list.
|
|
1616
1647
|
*/
|
|
1617
1648
|
addFirst(value) {
|
|
1618
|
-
this.unshift(value);
|
|
1649
|
+
return this.unshift(value);
|
|
1619
1650
|
}
|
|
1620
1651
|
/**
|
|
1621
1652
|
* Time Complexity: O(n) - Linear time, where n is the index, as it may need to traverse the list to find the desired node.
|
|
@@ -1632,7 +1663,7 @@ var dataStructureTyped = (() => {
|
|
|
1632
1663
|
* `undefined` if the index is out of bounds.
|
|
1633
1664
|
*/
|
|
1634
1665
|
getAt(index) {
|
|
1635
|
-
if (index < 0 || index >= this.
|
|
1666
|
+
if (index < 0 || index >= this.size)
|
|
1636
1667
|
return void 0;
|
|
1637
1668
|
let current = this.head;
|
|
1638
1669
|
for (let i = 0; i < index; i++) {
|
|
@@ -1676,17 +1707,21 @@ var dataStructureTyped = (() => {
|
|
|
1676
1707
|
* bounds.
|
|
1677
1708
|
*/
|
|
1678
1709
|
deleteAt(index) {
|
|
1679
|
-
if (index < 0 || index >= this.
|
|
1680
|
-
return
|
|
1681
|
-
if (index === 0)
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1710
|
+
if (index < 0 || index >= this.size)
|
|
1711
|
+
return false;
|
|
1712
|
+
if (index === 0) {
|
|
1713
|
+
this.shift();
|
|
1714
|
+
return true;
|
|
1715
|
+
}
|
|
1716
|
+
if (index === this.size - 1) {
|
|
1717
|
+
this.pop();
|
|
1718
|
+
return true;
|
|
1719
|
+
}
|
|
1685
1720
|
const prevNode = this.getNodeAt(index - 1);
|
|
1686
1721
|
const removedNode = prevNode.next;
|
|
1687
1722
|
prevNode.next = removedNode.next;
|
|
1688
|
-
this.
|
|
1689
|
-
return
|
|
1723
|
+
this._size--;
|
|
1724
|
+
return true;
|
|
1690
1725
|
}
|
|
1691
1726
|
/**
|
|
1692
1727
|
* Time Complexity: O(n) - Linear time, where n is the index, as it may need to traverse the list to find the desired node.
|
|
@@ -1725,7 +1760,7 @@ var dataStructureTyped = (() => {
|
|
|
1725
1760
|
this._tail = prev;
|
|
1726
1761
|
}
|
|
1727
1762
|
}
|
|
1728
|
-
this.
|
|
1763
|
+
this._size--;
|
|
1729
1764
|
return true;
|
|
1730
1765
|
}
|
|
1731
1766
|
prev = current;
|
|
@@ -1741,7 +1776,7 @@ var dataStructureTyped = (() => {
|
|
|
1741
1776
|
* Time Complexity: O(n) - Linear time, where n is the index, as it may need to traverse the list to find the desired node.
|
|
1742
1777
|
* Space Complexity: O(1) - Constant space.
|
|
1743
1778
|
*
|
|
1744
|
-
* The `
|
|
1779
|
+
* The `addAt` function inserts a value at a specified index in a singly linked list.
|
|
1745
1780
|
* @param {number} index - The index parameter represents the position at which the new value should be inserted in the
|
|
1746
1781
|
* linked list. It is of type number.
|
|
1747
1782
|
* @param {E} value - The `value` parameter represents the value that you want to insert into the linked list at the
|
|
@@ -1749,14 +1784,14 @@ var dataStructureTyped = (() => {
|
|
|
1749
1784
|
* @returns The `insert` method returns a boolean value. It returns `true` if the insertion is successful, and `false`
|
|
1750
1785
|
* if the index is out of bounds.
|
|
1751
1786
|
*/
|
|
1752
|
-
|
|
1753
|
-
if (index < 0 || index > this.
|
|
1787
|
+
addAt(index, value) {
|
|
1788
|
+
if (index < 0 || index > this.size)
|
|
1754
1789
|
return false;
|
|
1755
1790
|
if (index === 0) {
|
|
1756
1791
|
this.unshift(value);
|
|
1757
1792
|
return true;
|
|
1758
1793
|
}
|
|
1759
|
-
if (index === this.
|
|
1794
|
+
if (index === this.size) {
|
|
1760
1795
|
this.push(value);
|
|
1761
1796
|
return true;
|
|
1762
1797
|
}
|
|
@@ -1764,7 +1799,7 @@ var dataStructureTyped = (() => {
|
|
|
1764
1799
|
const prevNode = this.getNodeAt(index - 1);
|
|
1765
1800
|
newNode.next = prevNode.next;
|
|
1766
1801
|
prevNode.next = newNode;
|
|
1767
|
-
this.
|
|
1802
|
+
this._size++;
|
|
1768
1803
|
return true;
|
|
1769
1804
|
}
|
|
1770
1805
|
/**
|
|
@@ -1773,7 +1808,7 @@ var dataStructureTyped = (() => {
|
|
|
1773
1808
|
* @returns A boolean value indicating whether the length of the object is equal to 0.
|
|
1774
1809
|
*/
|
|
1775
1810
|
isEmpty() {
|
|
1776
|
-
return this.
|
|
1811
|
+
return this.size === 0;
|
|
1777
1812
|
}
|
|
1778
1813
|
/**
|
|
1779
1814
|
* The `clear` function resets the linked list by setting the head, tail, and length to undefined and 0 respectively.
|
|
@@ -1781,7 +1816,7 @@ var dataStructureTyped = (() => {
|
|
|
1781
1816
|
clear() {
|
|
1782
1817
|
this._head = void 0;
|
|
1783
1818
|
this._tail = void 0;
|
|
1784
|
-
this.
|
|
1819
|
+
this._size = 0;
|
|
1785
1820
|
}
|
|
1786
1821
|
/**
|
|
1787
1822
|
* Time Complexity: O(n) - Linear time, where n is the length of the list, as it needs to traverse the entire list to convert it to an array.
|
|
@@ -1816,7 +1851,7 @@ var dataStructureTyped = (() => {
|
|
|
1816
1851
|
*/
|
|
1817
1852
|
reverse() {
|
|
1818
1853
|
if (!this.head || this.head === this.tail)
|
|
1819
|
-
return;
|
|
1854
|
+
return this;
|
|
1820
1855
|
let prev = void 0;
|
|
1821
1856
|
let current = this.head;
|
|
1822
1857
|
let next = void 0;
|
|
@@ -1827,6 +1862,7 @@ var dataStructureTyped = (() => {
|
|
|
1827
1862
|
current = next;
|
|
1828
1863
|
}
|
|
1829
1864
|
[this._head, this._tail] = [this.tail, this.head];
|
|
1865
|
+
return this;
|
|
1830
1866
|
}
|
|
1831
1867
|
/**
|
|
1832
1868
|
* Time Complexity: O(n) - Linear time, where n is the length of the list, as it needs to reverse the pointers of each node.
|
|
@@ -1909,14 +1945,14 @@ var dataStructureTyped = (() => {
|
|
|
1909
1945
|
* Time Complexity: O(n) - Linear time, where n is the length of the list, as it needs to reverse the pointers of each node.
|
|
1910
1946
|
* Space Complexity: O(1) - Constant space.
|
|
1911
1947
|
*
|
|
1912
|
-
* The `
|
|
1948
|
+
* The `addBefore` function inserts a new value before an existing value in a singly linked list.
|
|
1913
1949
|
* @param {E | SinglyLinkedListNode<E>} existingValueOrNode - The existing value or node that you want to insert the
|
|
1914
1950
|
* new value before. It can be either the value itself or a node containing the value in the linked list.
|
|
1915
1951
|
* @param {E} newValue - The `newValue` parameter represents the value that you want to insert into the linked list.
|
|
1916
|
-
* @returns The method `
|
|
1952
|
+
* @returns The method `addBefore` returns a boolean value. It returns `true` if the new value was successfully
|
|
1917
1953
|
* inserted before the existing value, and `false` otherwise.
|
|
1918
1954
|
*/
|
|
1919
|
-
|
|
1955
|
+
addBefore(existingValueOrNode, newValue) {
|
|
1920
1956
|
if (!this.head)
|
|
1921
1957
|
return false;
|
|
1922
1958
|
let existingValue;
|
|
@@ -1935,7 +1971,7 @@ var dataStructureTyped = (() => {
|
|
|
1935
1971
|
const newNode = new SinglyLinkedListNode(newValue);
|
|
1936
1972
|
newNode.next = current.next;
|
|
1937
1973
|
current.next = newNode;
|
|
1938
|
-
this.
|
|
1974
|
+
this._size++;
|
|
1939
1975
|
return true;
|
|
1940
1976
|
}
|
|
1941
1977
|
current = current.next;
|
|
@@ -1950,14 +1986,14 @@ var dataStructureTyped = (() => {
|
|
|
1950
1986
|
* Time Complexity: O(n) - Linear time, where n is the length of the list, as it needs to reverse the pointers of each node.
|
|
1951
1987
|
* Space Complexity: O(1) - Constant space.
|
|
1952
1988
|
*
|
|
1953
|
-
* The `
|
|
1989
|
+
* The `addAfter` function inserts a new node with a given value after an existing node in a singly linked list.
|
|
1954
1990
|
* @param {E | SinglyLinkedListNode<E>} existingValueOrNode - The existing value or node in the linked list after which
|
|
1955
1991
|
* the new value will be inserted. It can be either the value of the existing node or the existing node itself.
|
|
1956
1992
|
* @param {E} newValue - The value that you want to insert into the linked list after the existing value or node.
|
|
1957
1993
|
* @returns The method returns a boolean value. It returns true if the new value was successfully inserted after the
|
|
1958
1994
|
* existing value or node, and false if the existing value or node was not found in the linked list.
|
|
1959
1995
|
*/
|
|
1960
|
-
|
|
1996
|
+
addAfter(existingValueOrNode, newValue) {
|
|
1961
1997
|
let existingNode;
|
|
1962
1998
|
if (existingValueOrNode instanceof SinglyLinkedListNode) {
|
|
1963
1999
|
existingNode = existingValueOrNode;
|
|
@@ -1971,7 +2007,7 @@ var dataStructureTyped = (() => {
|
|
|
1971
2007
|
if (existingNode === this.tail) {
|
|
1972
2008
|
this._tail = newNode;
|
|
1973
2009
|
}
|
|
1974
|
-
this.
|
|
2010
|
+
this._size++;
|
|
1975
2011
|
return true;
|
|
1976
2012
|
}
|
|
1977
2013
|
return false;
|
|
@@ -2058,13 +2094,6 @@ var dataStructureTyped = (() => {
|
|
|
2058
2094
|
}
|
|
2059
2095
|
return mappedList;
|
|
2060
2096
|
}
|
|
2061
|
-
/**
|
|
2062
|
-
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
2063
|
-
* Space Complexity: O(n)
|
|
2064
|
-
*/
|
|
2065
|
-
print() {
|
|
2066
|
-
console.log([...this]);
|
|
2067
|
-
}
|
|
2068
2097
|
*_getIterator() {
|
|
2069
2098
|
let current = this.head;
|
|
2070
2099
|
while (current) {
|
|
@@ -2092,16 +2121,16 @@ var dataStructureTyped = (() => {
|
|
|
2092
2121
|
};
|
|
2093
2122
|
var DoublyLinkedList = class _DoublyLinkedList extends IterableElementBase {
|
|
2094
2123
|
/**
|
|
2095
|
-
* The constructor initializes the linked list with an empty head, tail, and
|
|
2124
|
+
* The constructor initializes the linked list with an empty head, tail, and size.
|
|
2096
2125
|
*/
|
|
2097
2126
|
constructor(elements) {
|
|
2098
2127
|
super();
|
|
2099
2128
|
__publicField(this, "_head");
|
|
2100
2129
|
__publicField(this, "_tail");
|
|
2101
|
-
__publicField(this, "
|
|
2130
|
+
__publicField(this, "_size");
|
|
2102
2131
|
this._head = void 0;
|
|
2103
2132
|
this._tail = void 0;
|
|
2104
|
-
this.
|
|
2133
|
+
this._size = 0;
|
|
2105
2134
|
if (elements) {
|
|
2106
2135
|
for (const el of elements) {
|
|
2107
2136
|
this.push(el);
|
|
@@ -2114,18 +2143,15 @@ var dataStructureTyped = (() => {
|
|
|
2114
2143
|
get tail() {
|
|
2115
2144
|
return this._tail;
|
|
2116
2145
|
}
|
|
2117
|
-
get length() {
|
|
2118
|
-
return this._length;
|
|
2119
|
-
}
|
|
2120
2146
|
get size() {
|
|
2121
|
-
return this.
|
|
2147
|
+
return this._size;
|
|
2122
2148
|
}
|
|
2123
2149
|
/**
|
|
2124
|
-
* Time Complexity: O(n), where n is the
|
|
2150
|
+
* Time Complexity: O(n), where n is the size of the input array.
|
|
2125
2151
|
* Space Complexity: O(n)
|
|
2126
2152
|
*/
|
|
2127
2153
|
/**
|
|
2128
|
-
* Time Complexity: O(n), where n is the
|
|
2154
|
+
* Time Complexity: O(n), where n is the size of the input array.
|
|
2129
2155
|
* Space Complexity: O(n)
|
|
2130
2156
|
*
|
|
2131
2157
|
* The `fromArray` function creates a new instance of a DoublyLinkedList and populates it with the elements from the
|
|
@@ -2161,21 +2187,8 @@ var dataStructureTyped = (() => {
|
|
|
2161
2187
|
this.tail.next = newNode;
|
|
2162
2188
|
this._tail = newNode;
|
|
2163
2189
|
}
|
|
2164
|
-
this.
|
|
2165
|
-
|
|
2166
|
-
/**
|
|
2167
|
-
* Time Complexity: O(1)
|
|
2168
|
-
* Space Complexity: O(1)
|
|
2169
|
-
*/
|
|
2170
|
-
/**
|
|
2171
|
-
* Time Complexity: O(1)
|
|
2172
|
-
* Space Complexity: O(1)
|
|
2173
|
-
*
|
|
2174
|
-
* The addLast function adds a new node with the given value to the end of the doubly linked list.
|
|
2175
|
-
* @param {E} value - The value to be added to the linked list.
|
|
2176
|
-
*/
|
|
2177
|
-
addLast(value) {
|
|
2178
|
-
this.push(value);
|
|
2190
|
+
this._size++;
|
|
2191
|
+
return true;
|
|
2179
2192
|
}
|
|
2180
2193
|
/**
|
|
2181
2194
|
* Time Complexity: O(1)
|
|
@@ -2200,24 +2213,9 @@ var dataStructureTyped = (() => {
|
|
|
2200
2213
|
this._tail = removedNode.prev;
|
|
2201
2214
|
this.tail.next = void 0;
|
|
2202
2215
|
}
|
|
2203
|
-
this.
|
|
2216
|
+
this._size--;
|
|
2204
2217
|
return removedNode.value;
|
|
2205
2218
|
}
|
|
2206
|
-
/**
|
|
2207
|
-
* Time Complexity: O(1)
|
|
2208
|
-
* Space Complexity: O(1)
|
|
2209
|
-
*/
|
|
2210
|
-
/**
|
|
2211
|
-
* Time Complexity: O(1)
|
|
2212
|
-
* Space Complexity: O(1)
|
|
2213
|
-
*
|
|
2214
|
-
* The `pollLast()` function removes and returns the value of the last node in a doubly linked list.
|
|
2215
|
-
* @returns The method is returning the value of the removed node (removedNode.value) if the list is not empty. If the
|
|
2216
|
-
* list is empty, it returns undefined.
|
|
2217
|
-
*/
|
|
2218
|
-
pollLast() {
|
|
2219
|
-
return this.pop();
|
|
2220
|
-
}
|
|
2221
2219
|
/**
|
|
2222
2220
|
* Time Complexity: O(1)
|
|
2223
2221
|
* Space Complexity: O(1)
|
|
@@ -2241,24 +2239,9 @@ var dataStructureTyped = (() => {
|
|
|
2241
2239
|
this._head = removedNode.next;
|
|
2242
2240
|
this.head.prev = void 0;
|
|
2243
2241
|
}
|
|
2244
|
-
this.
|
|
2242
|
+
this._size--;
|
|
2245
2243
|
return removedNode.value;
|
|
2246
2244
|
}
|
|
2247
|
-
/**
|
|
2248
|
-
* Time Complexity: O(1)
|
|
2249
|
-
* Space Complexity: O(1)
|
|
2250
|
-
*/
|
|
2251
|
-
/**
|
|
2252
|
-
* Time Complexity: O(1)
|
|
2253
|
-
* Space Complexity: O(1)
|
|
2254
|
-
*
|
|
2255
|
-
* The `pollFirst()` function removes and returns the value of the first node in a doubly linked list.
|
|
2256
|
-
* @returns The method `shift()` returns the value of the node that is removed from the beginning of the doubly linked
|
|
2257
|
-
* list.
|
|
2258
|
-
*/
|
|
2259
|
-
pollFirst() {
|
|
2260
|
-
return this.shift();
|
|
2261
|
-
}
|
|
2262
2245
|
/**
|
|
2263
2246
|
* Time Complexity: O(1)
|
|
2264
2247
|
* Space Complexity: O(1)
|
|
@@ -2281,52 +2264,8 @@ var dataStructureTyped = (() => {
|
|
|
2281
2264
|
this.head.prev = newNode;
|
|
2282
2265
|
this._head = newNode;
|
|
2283
2266
|
}
|
|
2284
|
-
this.
|
|
2285
|
-
|
|
2286
|
-
/**
|
|
2287
|
-
* Time Complexity: O(1)
|
|
2288
|
-
* Space Complexity: O(1)
|
|
2289
|
-
*/
|
|
2290
|
-
/**
|
|
2291
|
-
* Time Complexity: O(1)
|
|
2292
|
-
* Space Complexity: O(1)
|
|
2293
|
-
*
|
|
2294
|
-
* The addFirst function adds a new node with the given value to the beginning of a doubly linked list.
|
|
2295
|
-
* @param {E} value - The `value` parameter represents the value of the new node that will be added to the beginning of the
|
|
2296
|
-
* doubly linked list.
|
|
2297
|
-
*/
|
|
2298
|
-
addFirst(value) {
|
|
2299
|
-
this.unshift(value);
|
|
2300
|
-
}
|
|
2301
|
-
/**
|
|
2302
|
-
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
2303
|
-
* Space Complexity: O(1)
|
|
2304
|
-
*/
|
|
2305
|
-
/**
|
|
2306
|
-
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
2307
|
-
* Space Complexity: O(1)
|
|
2308
|
-
*
|
|
2309
|
-
* The `getFirst` function returns the first node in a doubly linked list, or undefined if the list is empty.
|
|
2310
|
-
* @returns The method `getFirst()` returns the first node of the doubly linked list, or `undefined` if the list is empty.
|
|
2311
|
-
*/
|
|
2312
|
-
getFirst() {
|
|
2313
|
-
var _a;
|
|
2314
|
-
return (_a = this.head) == null ? void 0 : _a.value;
|
|
2315
|
-
}
|
|
2316
|
-
/**
|
|
2317
|
-
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
2318
|
-
* Space Complexity: O(1)
|
|
2319
|
-
*/
|
|
2320
|
-
/**
|
|
2321
|
-
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
2322
|
-
* Space Complexity: O(1)
|
|
2323
|
-
*
|
|
2324
|
-
* The `getLast` function returns the last node in a doubly linked list, or undefined if the list is empty.
|
|
2325
|
-
* @returns The method `getLast()` returns the last node of the doubly linked list, or `undefined` if the list is empty.
|
|
2326
|
-
*/
|
|
2327
|
-
getLast() {
|
|
2328
|
-
var _a;
|
|
2329
|
-
return (_a = this.tail) == null ? void 0 : _a.value;
|
|
2267
|
+
this._size++;
|
|
2268
|
+
return true;
|
|
2330
2269
|
}
|
|
2331
2270
|
/**
|
|
2332
2271
|
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
@@ -2343,7 +2282,7 @@ var dataStructureTyped = (() => {
|
|
|
2343
2282
|
* or the linked list is empty, it will return undefined.
|
|
2344
2283
|
*/
|
|
2345
2284
|
getAt(index) {
|
|
2346
|
-
if (index < 0 || index >= this.
|
|
2285
|
+
if (index < 0 || index >= this.size)
|
|
2347
2286
|
return void 0;
|
|
2348
2287
|
let current = this.head;
|
|
2349
2288
|
for (let i = 0; i < index; i++) {
|
|
@@ -2367,7 +2306,7 @@ var dataStructureTyped = (() => {
|
|
|
2367
2306
|
* valid range of the linked list, otherwise it returns `undefined`.
|
|
2368
2307
|
*/
|
|
2369
2308
|
getNodeAt(index) {
|
|
2370
|
-
if (index < 0 || index >= this.
|
|
2309
|
+
if (index < 0 || index >= this.size)
|
|
2371
2310
|
return void 0;
|
|
2372
2311
|
let current = this.head;
|
|
2373
2312
|
for (let i = 0; i < index; i++) {
|
|
@@ -2415,14 +2354,14 @@ var dataStructureTyped = (() => {
|
|
|
2415
2354
|
* @returns The `insert` method returns a boolean value. It returns `true` if the insertion is successful, and `false`
|
|
2416
2355
|
* if the index is out of bounds.
|
|
2417
2356
|
*/
|
|
2418
|
-
|
|
2419
|
-
if (index < 0 || index > this.
|
|
2357
|
+
addAt(index, value) {
|
|
2358
|
+
if (index < 0 || index > this.size)
|
|
2420
2359
|
return false;
|
|
2421
2360
|
if (index === 0) {
|
|
2422
2361
|
this.unshift(value);
|
|
2423
2362
|
return true;
|
|
2424
2363
|
}
|
|
2425
|
-
if (index === this.
|
|
2364
|
+
if (index === this.size) {
|
|
2426
2365
|
this.push(value);
|
|
2427
2366
|
return true;
|
|
2428
2367
|
}
|
|
@@ -2433,7 +2372,7 @@ var dataStructureTyped = (() => {
|
|
|
2433
2372
|
newNode.next = nextNode;
|
|
2434
2373
|
prevNode.next = newNode;
|
|
2435
2374
|
nextNode.prev = newNode;
|
|
2436
|
-
this.
|
|
2375
|
+
this._size++;
|
|
2437
2376
|
return true;
|
|
2438
2377
|
}
|
|
2439
2378
|
/**
|
|
@@ -2444,7 +2383,7 @@ var dataStructureTyped = (() => {
|
|
|
2444
2383
|
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
2445
2384
|
* Space Complexity: O(1)
|
|
2446
2385
|
*
|
|
2447
|
-
* The `
|
|
2386
|
+
* The `addBefore` function inserts a new value before an existing value or node in a doubly linked list.
|
|
2448
2387
|
* @param {E | DoublyLinkedListNode<E>} existingValueOrNode - The existing value or node in the doubly linked list
|
|
2449
2388
|
* before which the new value will be inserted. It can be either the value of the existing node or the existing node
|
|
2450
2389
|
* itself.
|
|
@@ -2453,7 +2392,7 @@ var dataStructureTyped = (() => {
|
|
|
2453
2392
|
* @returns The method returns a boolean value. It returns `true` if the insertion is successful, and `false` if the
|
|
2454
2393
|
* insertion fails.
|
|
2455
2394
|
*/
|
|
2456
|
-
|
|
2395
|
+
addBefore(existingValueOrNode, newValue) {
|
|
2457
2396
|
let existingNode;
|
|
2458
2397
|
if (existingValueOrNode instanceof DoublyLinkedListNode) {
|
|
2459
2398
|
existingNode = existingValueOrNode;
|
|
@@ -2471,7 +2410,7 @@ var dataStructureTyped = (() => {
|
|
|
2471
2410
|
if (existingNode === this.head) {
|
|
2472
2411
|
this._head = newNode;
|
|
2473
2412
|
}
|
|
2474
|
-
this.
|
|
2413
|
+
this._size++;
|
|
2475
2414
|
return true;
|
|
2476
2415
|
}
|
|
2477
2416
|
return false;
|
|
@@ -2484,7 +2423,7 @@ var dataStructureTyped = (() => {
|
|
|
2484
2423
|
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
2485
2424
|
* Space Complexity: O(1)
|
|
2486
2425
|
*
|
|
2487
|
-
* The `
|
|
2426
|
+
* The `addAfter` function inserts a new node with a given value after an existing node in a doubly linked list.
|
|
2488
2427
|
* @param {E | DoublyLinkedListNode<E>} existingValueOrNode - The existing value or node in the doubly linked list
|
|
2489
2428
|
* after which the new value will be inserted. It can be either the value of the existing node or the existing node
|
|
2490
2429
|
* itself.
|
|
@@ -2492,7 +2431,7 @@ var dataStructureTyped = (() => {
|
|
|
2492
2431
|
* @returns The method returns a boolean value. It returns true if the insertion is successful, and false if the
|
|
2493
2432
|
* existing value or node is not found in the doubly linked list.
|
|
2494
2433
|
*/
|
|
2495
|
-
|
|
2434
|
+
addAfter(existingValueOrNode, newValue) {
|
|
2496
2435
|
let existingNode;
|
|
2497
2436
|
if (existingValueOrNode instanceof DoublyLinkedListNode) {
|
|
2498
2437
|
existingNode = existingValueOrNode;
|
|
@@ -2510,7 +2449,7 @@ var dataStructureTyped = (() => {
|
|
|
2510
2449
|
if (existingNode === this.tail) {
|
|
2511
2450
|
this._tail = newNode;
|
|
2512
2451
|
}
|
|
2513
|
-
this.
|
|
2452
|
+
this._size++;
|
|
2514
2453
|
return true;
|
|
2515
2454
|
}
|
|
2516
2455
|
return false;
|
|
@@ -2530,19 +2469,23 @@ var dataStructureTyped = (() => {
|
|
|
2530
2469
|
* bounds.
|
|
2531
2470
|
*/
|
|
2532
2471
|
deleteAt(index) {
|
|
2533
|
-
if (index < 0 || index >= this.
|
|
2534
|
-
return
|
|
2535
|
-
if (index === 0)
|
|
2536
|
-
|
|
2537
|
-
|
|
2538
|
-
|
|
2472
|
+
if (index < 0 || index >= this.size)
|
|
2473
|
+
return false;
|
|
2474
|
+
if (index === 0) {
|
|
2475
|
+
this.shift();
|
|
2476
|
+
return true;
|
|
2477
|
+
}
|
|
2478
|
+
if (index === this.size - 1) {
|
|
2479
|
+
this.pop();
|
|
2480
|
+
return true;
|
|
2481
|
+
}
|
|
2539
2482
|
const removedNode = this.getNodeAt(index);
|
|
2540
2483
|
const prevNode = removedNode.prev;
|
|
2541
2484
|
const nextNode = removedNode.next;
|
|
2542
2485
|
prevNode.next = nextNode;
|
|
2543
2486
|
nextNode.prev = prevNode;
|
|
2544
|
-
this.
|
|
2545
|
-
return
|
|
2487
|
+
this._size--;
|
|
2488
|
+
return true;
|
|
2546
2489
|
}
|
|
2547
2490
|
/**
|
|
2548
2491
|
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
@@ -2575,26 +2518,26 @@ var dataStructureTyped = (() => {
|
|
|
2575
2518
|
const nextNode = node.next;
|
|
2576
2519
|
prevNode.next = nextNode;
|
|
2577
2520
|
nextNode.prev = prevNode;
|
|
2578
|
-
this.
|
|
2521
|
+
this._size--;
|
|
2579
2522
|
}
|
|
2580
2523
|
return true;
|
|
2581
2524
|
}
|
|
2582
2525
|
return false;
|
|
2583
2526
|
}
|
|
2584
2527
|
/**
|
|
2585
|
-
* The function checks if a variable has a
|
|
2528
|
+
* The function checks if a variable has a size greater than zero and returns a boolean value.
|
|
2586
2529
|
* @returns A boolean value is being returned.
|
|
2587
2530
|
*/
|
|
2588
2531
|
isEmpty() {
|
|
2589
|
-
return this.
|
|
2532
|
+
return this.size === 0;
|
|
2590
2533
|
}
|
|
2591
2534
|
/**
|
|
2592
|
-
* The `clear` function resets the linked list by setting the head, tail, and
|
|
2535
|
+
* The `clear` function resets the linked list by setting the head, tail, and size to undefined and 0 respectively.
|
|
2593
2536
|
*/
|
|
2594
2537
|
clear() {
|
|
2595
2538
|
this._head = void 0;
|
|
2596
2539
|
this._tail = void 0;
|
|
2597
|
-
this.
|
|
2540
|
+
this._size = 0;
|
|
2598
2541
|
}
|
|
2599
2542
|
/**
|
|
2600
2543
|
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
@@ -2689,6 +2632,7 @@ var dataStructureTyped = (() => {
|
|
|
2689
2632
|
[current.prev, current.next] = [current.next, current.prev];
|
|
2690
2633
|
current = next;
|
|
2691
2634
|
}
|
|
2635
|
+
return this;
|
|
2692
2636
|
}
|
|
2693
2637
|
/**
|
|
2694
2638
|
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
@@ -2792,12 +2736,94 @@ var dataStructureTyped = (() => {
|
|
|
2792
2736
|
}
|
|
2793
2737
|
return mappedList;
|
|
2794
2738
|
}
|
|
2739
|
+
/**
|
|
2740
|
+
* Time Complexity: O(1)
|
|
2741
|
+
* Space Complexity: O(1)
|
|
2742
|
+
*/
|
|
2743
|
+
/**
|
|
2744
|
+
* Time Complexity: O(1)
|
|
2745
|
+
* Space Complexity: O(1)
|
|
2746
|
+
*
|
|
2747
|
+
* The addLast function adds a new node with the given value to the end of the doubly linked list.
|
|
2748
|
+
* @param {E} value - The value to be added to the linked list.
|
|
2749
|
+
*/
|
|
2750
|
+
addLast(value) {
|
|
2751
|
+
return this.push(value);
|
|
2752
|
+
}
|
|
2753
|
+
/**
|
|
2754
|
+
* Time Complexity: O(1)
|
|
2755
|
+
* Space Complexity: O(1)
|
|
2756
|
+
*/
|
|
2757
|
+
/**
|
|
2758
|
+
* Time Complexity: O(1)
|
|
2759
|
+
* Space Complexity: O(1)
|
|
2760
|
+
*
|
|
2761
|
+
* The `pollLast()` function removes and returns the value of the last node in a doubly linked list.
|
|
2762
|
+
* @returns The method is returning the value of the removed node (removedNode.value) if the list is not empty. If the
|
|
2763
|
+
* list is empty, it returns undefined.
|
|
2764
|
+
*/
|
|
2765
|
+
pollLast() {
|
|
2766
|
+
return this.pop();
|
|
2767
|
+
}
|
|
2768
|
+
/**
|
|
2769
|
+
* Time Complexity: O(1)
|
|
2770
|
+
* Space Complexity: O(1)
|
|
2771
|
+
*/
|
|
2772
|
+
/**
|
|
2773
|
+
* Time Complexity: O(1)
|
|
2774
|
+
* Space Complexity: O(1)
|
|
2775
|
+
*
|
|
2776
|
+
* The `pollFirst()` function removes and returns the value of the first node in a doubly linked list.
|
|
2777
|
+
* @returns The method `shift()` returns the value of the node that is removed from the beginning of the doubly linked
|
|
2778
|
+
* list.
|
|
2779
|
+
*/
|
|
2780
|
+
pollFirst() {
|
|
2781
|
+
return this.shift();
|
|
2782
|
+
}
|
|
2783
|
+
/**
|
|
2784
|
+
* Time Complexity: O(1)
|
|
2785
|
+
* Space Complexity: O(1)
|
|
2786
|
+
*/
|
|
2787
|
+
/**
|
|
2788
|
+
* Time Complexity: O(1)
|
|
2789
|
+
* Space Complexity: O(1)
|
|
2790
|
+
*
|
|
2791
|
+
* The addFirst function adds a new node with the given value to the beginning of a doubly linked list.
|
|
2792
|
+
* @param {E} value - The `value` parameter represents the value of the new node that will be added to the beginning of the
|
|
2793
|
+
* doubly linked list.
|
|
2794
|
+
*/
|
|
2795
|
+
addFirst(value) {
|
|
2796
|
+
this.unshift(value);
|
|
2797
|
+
}
|
|
2795
2798
|
/**
|
|
2796
2799
|
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
2797
|
-
* Space Complexity: O(
|
|
2800
|
+
* Space Complexity: O(1)
|
|
2798
2801
|
*/
|
|
2799
|
-
|
|
2800
|
-
|
|
2802
|
+
/**
|
|
2803
|
+
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
2804
|
+
* Space Complexity: O(1)
|
|
2805
|
+
*
|
|
2806
|
+
* The `get first` function returns the first node in a doubly linked list, or undefined if the list is empty.
|
|
2807
|
+
* @returns The method `get first()` returns the first node of the doubly linked list, or `undefined` if the list is empty.
|
|
2808
|
+
*/
|
|
2809
|
+
get first() {
|
|
2810
|
+
var _a;
|
|
2811
|
+
return (_a = this.head) == null ? void 0 : _a.value;
|
|
2812
|
+
}
|
|
2813
|
+
/**
|
|
2814
|
+
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
2815
|
+
* Space Complexity: O(1)
|
|
2816
|
+
*/
|
|
2817
|
+
/**
|
|
2818
|
+
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
2819
|
+
* Space Complexity: O(1)
|
|
2820
|
+
*
|
|
2821
|
+
* The `get last` function returns the last node in a doubly linked list, or undefined if the list is empty.
|
|
2822
|
+
* @returns The method `get last()` returns the last node of the doubly linked list, or `undefined` if the list is empty.
|
|
2823
|
+
*/
|
|
2824
|
+
get last() {
|
|
2825
|
+
var _a;
|
|
2826
|
+
return (_a = this.tail) == null ? void 0 : _a.value;
|
|
2801
2827
|
}
|
|
2802
2828
|
/**
|
|
2803
2829
|
* The function returns an iterator that iterates over the values of a linked list.
|
|
@@ -2968,7 +2994,7 @@ var dataStructureTyped = (() => {
|
|
|
2968
2994
|
* Get the value of the first element (the smallest element) in the Skip List.
|
|
2969
2995
|
* @returns The value of the first element, or undefined if the Skip List is empty.
|
|
2970
2996
|
*/
|
|
2971
|
-
|
|
2997
|
+
get first() {
|
|
2972
2998
|
const firstNode = this.head.forward[0];
|
|
2973
2999
|
return firstNode ? firstNode.value : void 0;
|
|
2974
3000
|
}
|
|
@@ -2983,7 +3009,7 @@ var dataStructureTyped = (() => {
|
|
|
2983
3009
|
* Get the value of the last element (the largest element) in the Skip List.
|
|
2984
3010
|
* @returns The value of the last element, or undefined if the Skip List is empty.
|
|
2985
3011
|
*/
|
|
2986
|
-
|
|
3012
|
+
get last() {
|
|
2987
3013
|
let current = this.head;
|
|
2988
3014
|
for (let i = this.level - 1; i >= 0; i--) {
|
|
2989
3015
|
while (current.forward[i]) {
|
|
@@ -3140,7 +3166,7 @@ var dataStructureTyped = (() => {
|
|
|
3140
3166
|
*/
|
|
3141
3167
|
push(element) {
|
|
3142
3168
|
this.elements.push(element);
|
|
3143
|
-
return
|
|
3169
|
+
return true;
|
|
3144
3170
|
}
|
|
3145
3171
|
/**
|
|
3146
3172
|
* Time Complexity: O(1), as it only involves accessing the last element of the array.
|
|
@@ -3156,8 +3182,8 @@ var dataStructureTyped = (() => {
|
|
|
3156
3182
|
*/
|
|
3157
3183
|
pop() {
|
|
3158
3184
|
if (this.isEmpty())
|
|
3159
|
-
return
|
|
3160
|
-
return this.elements.pop()
|
|
3185
|
+
return;
|
|
3186
|
+
return this.elements.pop();
|
|
3161
3187
|
}
|
|
3162
3188
|
/**
|
|
3163
3189
|
* Time Complexity: O(n)
|
|
@@ -3250,9 +3276,6 @@ var dataStructureTyped = (() => {
|
|
|
3250
3276
|
}
|
|
3251
3277
|
return newStack;
|
|
3252
3278
|
}
|
|
3253
|
-
print() {
|
|
3254
|
-
console.log([...this]);
|
|
3255
|
-
}
|
|
3256
3279
|
/**
|
|
3257
3280
|
* Custom iterator for the Stack class.
|
|
3258
3281
|
* @returns An iterator object.
|
|
@@ -3317,7 +3340,7 @@ var dataStructureTyped = (() => {
|
|
|
3317
3340
|
*/
|
|
3318
3341
|
push(element) {
|
|
3319
3342
|
this.nodes.push(element);
|
|
3320
|
-
return
|
|
3343
|
+
return true;
|
|
3321
3344
|
}
|
|
3322
3345
|
/**
|
|
3323
3346
|
* Time Complexity: O(n) - where n is the number of elements in the queue. In the worst case, it may need to shift all elements to update the offset.
|
|
@@ -3334,7 +3357,7 @@ var dataStructureTyped = (() => {
|
|
|
3334
3357
|
shift() {
|
|
3335
3358
|
if (this.size === 0)
|
|
3336
3359
|
return void 0;
|
|
3337
|
-
const first = this.
|
|
3360
|
+
const first = this.first;
|
|
3338
3361
|
this._offset += 1;
|
|
3339
3362
|
if (this.offset * 2 < this.nodes.length)
|
|
3340
3363
|
return first;
|
|
@@ -3350,11 +3373,11 @@ var dataStructureTyped = (() => {
|
|
|
3350
3373
|
* Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
|
|
3351
3374
|
* Space Complexity: O(1) - no additional space is used.
|
|
3352
3375
|
*
|
|
3353
|
-
* The `
|
|
3354
|
-
* @returns The `
|
|
3376
|
+
* The `first` function returns the first element of the array `_nodes` if it exists, otherwise it returns `undefined`.
|
|
3377
|
+
* @returns The `get first()` method returns the first element of the data structure, represented by the `_nodes` array at
|
|
3355
3378
|
* the `_offset` index. If the data structure is empty (size is 0), it returns `undefined`.
|
|
3356
3379
|
*/
|
|
3357
|
-
|
|
3380
|
+
get first() {
|
|
3358
3381
|
return this.size > 0 ? this.nodes[this.offset] : void 0;
|
|
3359
3382
|
}
|
|
3360
3383
|
/**
|
|
@@ -3370,7 +3393,7 @@ var dataStructureTyped = (() => {
|
|
|
3370
3393
|
* the `_offset` index. If the data structure is empty (size is 0), it returns `undefined`.
|
|
3371
3394
|
*/
|
|
3372
3395
|
peek() {
|
|
3373
|
-
return this.
|
|
3396
|
+
return this.first;
|
|
3374
3397
|
}
|
|
3375
3398
|
/**
|
|
3376
3399
|
* Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
|
|
@@ -3380,11 +3403,11 @@ var dataStructureTyped = (() => {
|
|
|
3380
3403
|
* Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
|
|
3381
3404
|
* Space Complexity: O(1) - no additional space is used.
|
|
3382
3405
|
*
|
|
3383
|
-
* The `
|
|
3384
|
-
* @returns The method `
|
|
3406
|
+
* The `last` function returns the last element in an array-like data structure, or undefined if the structure is empty.
|
|
3407
|
+
* @returns The method `get last()` returns the last element of the `_nodes` array if the array is not empty. If the
|
|
3385
3408
|
* array is empty, it returns `undefined`.
|
|
3386
3409
|
*/
|
|
3387
|
-
|
|
3410
|
+
get last() {
|
|
3388
3411
|
return this.size > 0 ? this.nodes[this.nodes.length - 1] : void 0;
|
|
3389
3412
|
}
|
|
3390
3413
|
/**
|
|
@@ -3400,7 +3423,7 @@ var dataStructureTyped = (() => {
|
|
|
3400
3423
|
* array is empty, it returns `undefined`.
|
|
3401
3424
|
*/
|
|
3402
3425
|
peekLast() {
|
|
3403
|
-
return this.
|
|
3426
|
+
return this.last;
|
|
3404
3427
|
}
|
|
3405
3428
|
/**
|
|
3406
3429
|
* Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
|
|
@@ -3414,7 +3437,7 @@ var dataStructureTyped = (() => {
|
|
|
3414
3437
|
* @param {E} value - The value parameter represents the value that you want to add to the queue.
|
|
3415
3438
|
*/
|
|
3416
3439
|
enqueue(value) {
|
|
3417
|
-
this.push(value);
|
|
3440
|
+
return this.push(value);
|
|
3418
3441
|
}
|
|
3419
3442
|
/**
|
|
3420
3443
|
* Time Complexity: O(n) - same as shift().
|
|
@@ -3492,9 +3515,6 @@ var dataStructureTyped = (() => {
|
|
|
3492
3515
|
clone() {
|
|
3493
3516
|
return new _Queue(this.nodes.slice(this.offset));
|
|
3494
3517
|
}
|
|
3495
|
-
print() {
|
|
3496
|
-
console.log([...this]);
|
|
3497
|
-
}
|
|
3498
3518
|
/**
|
|
3499
3519
|
* Time Complexity: O(n)
|
|
3500
3520
|
* Space Complexity: O(n)
|
|
@@ -3569,7 +3589,7 @@ var dataStructureTyped = (() => {
|
|
|
3569
3589
|
* @param {E} value - The value parameter represents the value that you want to add to the queue.
|
|
3570
3590
|
*/
|
|
3571
3591
|
enqueue(value) {
|
|
3572
|
-
this.push(value);
|
|
3592
|
+
return this.push(value);
|
|
3573
3593
|
}
|
|
3574
3594
|
/**
|
|
3575
3595
|
* The `dequeue` function removes and returns the first element from a queue, or returns undefined if the queue is empty.
|
|
@@ -3579,10 +3599,10 @@ var dataStructureTyped = (() => {
|
|
|
3579
3599
|
return this.shift();
|
|
3580
3600
|
}
|
|
3581
3601
|
/**
|
|
3582
|
-
* The `
|
|
3583
|
-
* @returns The `
|
|
3602
|
+
* The `get first` function returns the value of the head node in a linked list, or `undefined` if the list is empty.
|
|
3603
|
+
* @returns The `get first()` method is returning the value of the `head` node if it exists, otherwise it returns `undefined`.
|
|
3584
3604
|
*/
|
|
3585
|
-
|
|
3605
|
+
get first() {
|
|
3586
3606
|
var _a;
|
|
3587
3607
|
return (_a = this.head) == null ? void 0 : _a.value;
|
|
3588
3608
|
}
|
|
@@ -3591,7 +3611,7 @@ var dataStructureTyped = (() => {
|
|
|
3591
3611
|
* @returns The `peek()` method is returning the value of the `head` node if it exists, otherwise it returns `undefined`.
|
|
3592
3612
|
*/
|
|
3593
3613
|
peek() {
|
|
3594
|
-
return this.
|
|
3614
|
+
return this.first;
|
|
3595
3615
|
}
|
|
3596
3616
|
};
|
|
3597
3617
|
|
|
@@ -3661,95 +3681,6 @@ var dataStructureTyped = (() => {
|
|
|
3661
3681
|
return;
|
|
3662
3682
|
return this._buckets[this._bucketLast][this._lastInBucket];
|
|
3663
3683
|
}
|
|
3664
|
-
/**
|
|
3665
|
-
* Time Complexity: O(1) - Removes the last element.
|
|
3666
|
-
* Space Complexity: O(1) - Operates in-place.
|
|
3667
|
-
*/
|
|
3668
|
-
isEmpty() {
|
|
3669
|
-
return this.size === 0;
|
|
3670
|
-
}
|
|
3671
|
-
/**
|
|
3672
|
-
* Time Complexity: Amortized O(1) - Similar to push, resizing leads to O(n).
|
|
3673
|
-
* Space Complexity: O(n) - Due to potential resizing.
|
|
3674
|
-
*/
|
|
3675
|
-
/**
|
|
3676
|
-
* Time Complexity: O(1)
|
|
3677
|
-
* Space Complexity: O(n) - In worst case, resizing doubles the array size.
|
|
3678
|
-
*
|
|
3679
|
-
* The addLast function adds an element to the end of an array.
|
|
3680
|
-
* @param {E} element - The element parameter represents the element that you want to add to the end of the
|
|
3681
|
-
* data structure.
|
|
3682
|
-
*/
|
|
3683
|
-
addLast(element) {
|
|
3684
|
-
this.push(element);
|
|
3685
|
-
}
|
|
3686
|
-
/**
|
|
3687
|
-
* Time Complexity: O(1) - Removes the first element.
|
|
3688
|
-
* Space Complexity: O(1) - In-place operation.
|
|
3689
|
-
*/
|
|
3690
|
-
/**
|
|
3691
|
-
* Time Complexity: O(1) - Removes the last element.
|
|
3692
|
-
* Space Complexity: O(1) - Operates in-place.
|
|
3693
|
-
*
|
|
3694
|
-
* The function "pollLast" removes and returns the last element of an array.
|
|
3695
|
-
* @returns The last element of the array is being returned.
|
|
3696
|
-
*/
|
|
3697
|
-
pollLast() {
|
|
3698
|
-
return this.pop();
|
|
3699
|
-
}
|
|
3700
|
-
/**
|
|
3701
|
-
* Time Complexity: O(1).
|
|
3702
|
-
* Space Complexity: O(n) - Due to potential resizing.
|
|
3703
|
-
*
|
|
3704
|
-
* The "addFirst" function adds an element to the beginning of an array.
|
|
3705
|
-
* @param {E} element - The parameter "element" represents the element that you want to add to the
|
|
3706
|
-
* beginning of the data structure.
|
|
3707
|
-
*/
|
|
3708
|
-
addFirst(element) {
|
|
3709
|
-
this.unshift(element);
|
|
3710
|
-
}
|
|
3711
|
-
/**
|
|
3712
|
-
* Time Complexity: O(1) - Removes the first element.
|
|
3713
|
-
* Space Complexity: O(1) - In-place operation.
|
|
3714
|
-
*
|
|
3715
|
-
* The function "pollFirst" removes and returns the first element of an array.
|
|
3716
|
-
* @returns The method `pollFirst()` is returning the first element of the array after removing it
|
|
3717
|
-
* from the beginning. If the array is empty, it will return `undefined`.
|
|
3718
|
-
*/
|
|
3719
|
-
pollFirst() {
|
|
3720
|
-
return this.shift();
|
|
3721
|
-
}
|
|
3722
|
-
/**
|
|
3723
|
-
* The clear() function resets the state of the object by initializing all variables to their default
|
|
3724
|
-
* values.
|
|
3725
|
-
*/
|
|
3726
|
-
clear() {
|
|
3727
|
-
this._buckets = [new Array(this._bucketSize)];
|
|
3728
|
-
this._bucketCount = 1;
|
|
3729
|
-
this._bucketFirst = this._bucketLast = this._size = 0;
|
|
3730
|
-
this._firstInBucket = this._lastInBucket = this._bucketSize >> 1;
|
|
3731
|
-
}
|
|
3732
|
-
/**
|
|
3733
|
-
* The below function is a generator that yields elements from a collection one by one.
|
|
3734
|
-
*/
|
|
3735
|
-
*begin() {
|
|
3736
|
-
let index = 0;
|
|
3737
|
-
while (index < this.size) {
|
|
3738
|
-
yield this.getAt(index);
|
|
3739
|
-
index++;
|
|
3740
|
-
}
|
|
3741
|
-
}
|
|
3742
|
-
/**
|
|
3743
|
-
* The function `reverseBegin()` is a generator that yields elements in reverse order starting from
|
|
3744
|
-
* the last element.
|
|
3745
|
-
*/
|
|
3746
|
-
*reverseBegin() {
|
|
3747
|
-
let index = this.size - 1;
|
|
3748
|
-
while (index >= 0) {
|
|
3749
|
-
yield this.getAt(index);
|
|
3750
|
-
index--;
|
|
3751
|
-
}
|
|
3752
|
-
}
|
|
3753
3684
|
/**
|
|
3754
3685
|
* Time Complexity - Amortized O(1) (possible reallocation)
|
|
3755
3686
|
* Space Complexity - O(n) (due to potential resizing).
|
|
@@ -3779,7 +3710,7 @@ var dataStructureTyped = (() => {
|
|
|
3779
3710
|
}
|
|
3780
3711
|
this._size += 1;
|
|
3781
3712
|
this._buckets[this._bucketLast][this._lastInBucket] = element;
|
|
3782
|
-
return
|
|
3713
|
+
return true;
|
|
3783
3714
|
}
|
|
3784
3715
|
/**
|
|
3785
3716
|
* Time Complexity: O(1)
|
|
@@ -3841,38 +3772,76 @@ var dataStructureTyped = (() => {
|
|
|
3841
3772
|
}
|
|
3842
3773
|
this._size += 1;
|
|
3843
3774
|
this._buckets[this._bucketFirst][this._firstInBucket] = element;
|
|
3844
|
-
return
|
|
3775
|
+
return true;
|
|
3845
3776
|
}
|
|
3846
3777
|
/**
|
|
3847
3778
|
* Time Complexity: O(1)
|
|
3848
3779
|
* Space Complexity: O(1)
|
|
3849
3780
|
*/
|
|
3850
3781
|
/**
|
|
3851
|
-
* Time Complexity: O(1)
|
|
3852
|
-
* Space Complexity: O(1)
|
|
3853
|
-
*
|
|
3854
|
-
* The `shift()` function removes and returns the first element from a data structure, updating the
|
|
3855
|
-
* internal state variables accordingly.
|
|
3856
|
-
* @returns The element that is being removed from the beginning of the data structure is being
|
|
3857
|
-
* returned.
|
|
3782
|
+
* Time Complexity: O(1)
|
|
3783
|
+
* Space Complexity: O(1)
|
|
3784
|
+
*
|
|
3785
|
+
* The `shift()` function removes and returns the first element from a data structure, updating the
|
|
3786
|
+
* internal state variables accordingly.
|
|
3787
|
+
* @returns The element that is being removed from the beginning of the data structure is being
|
|
3788
|
+
* returned.
|
|
3789
|
+
*/
|
|
3790
|
+
shift() {
|
|
3791
|
+
if (this.size === 0)
|
|
3792
|
+
return;
|
|
3793
|
+
const element = this._buckets[this._bucketFirst][this._firstInBucket];
|
|
3794
|
+
if (this.size !== 1) {
|
|
3795
|
+
if (this._firstInBucket < this._bucketSize - 1) {
|
|
3796
|
+
this._firstInBucket += 1;
|
|
3797
|
+
} else if (this._bucketFirst < this._bucketCount - 1) {
|
|
3798
|
+
this._bucketFirst += 1;
|
|
3799
|
+
this._firstInBucket = 0;
|
|
3800
|
+
} else {
|
|
3801
|
+
this._bucketFirst = 0;
|
|
3802
|
+
this._firstInBucket = 0;
|
|
3803
|
+
}
|
|
3804
|
+
}
|
|
3805
|
+
this._size -= 1;
|
|
3806
|
+
return element;
|
|
3807
|
+
}
|
|
3808
|
+
/**
|
|
3809
|
+
* Time Complexity: O(1) - Removes the last element.
|
|
3810
|
+
* Space Complexity: O(1) - Operates in-place.
|
|
3811
|
+
*/
|
|
3812
|
+
isEmpty() {
|
|
3813
|
+
return this.size === 0;
|
|
3814
|
+
}
|
|
3815
|
+
/**
|
|
3816
|
+
* The clear() function resets the state of the object by initializing all variables to their default
|
|
3817
|
+
* values.
|
|
3818
|
+
*/
|
|
3819
|
+
clear() {
|
|
3820
|
+
this._buckets = [new Array(this._bucketSize)];
|
|
3821
|
+
this._bucketCount = 1;
|
|
3822
|
+
this._bucketFirst = this._bucketLast = this._size = 0;
|
|
3823
|
+
this._firstInBucket = this._lastInBucket = this._bucketSize >> 1;
|
|
3824
|
+
}
|
|
3825
|
+
/**
|
|
3826
|
+
* The below function is a generator that yields elements from a collection one by one.
|
|
3827
|
+
*/
|
|
3828
|
+
*begin() {
|
|
3829
|
+
let index = 0;
|
|
3830
|
+
while (index < this.size) {
|
|
3831
|
+
yield this.getAt(index);
|
|
3832
|
+
index++;
|
|
3833
|
+
}
|
|
3834
|
+
}
|
|
3835
|
+
/**
|
|
3836
|
+
* The function `reverseBegin()` is a generator that yields elements in reverse order starting from
|
|
3837
|
+
* the last element.
|
|
3858
3838
|
*/
|
|
3859
|
-
|
|
3860
|
-
|
|
3861
|
-
|
|
3862
|
-
|
|
3863
|
-
|
|
3864
|
-
if (this._firstInBucket < this._bucketSize - 1) {
|
|
3865
|
-
this._firstInBucket += 1;
|
|
3866
|
-
} else if (this._bucketFirst < this._bucketCount - 1) {
|
|
3867
|
-
this._bucketFirst += 1;
|
|
3868
|
-
this._firstInBucket = 0;
|
|
3869
|
-
} else {
|
|
3870
|
-
this._bucketFirst = 0;
|
|
3871
|
-
this._firstInBucket = 0;
|
|
3872
|
-
}
|
|
3839
|
+
*reverseBegin() {
|
|
3840
|
+
let index = this.size - 1;
|
|
3841
|
+
while (index >= 0) {
|
|
3842
|
+
yield this.getAt(index);
|
|
3843
|
+
index--;
|
|
3873
3844
|
}
|
|
3874
|
-
this._size -= 1;
|
|
3875
|
-
return element;
|
|
3876
3845
|
}
|
|
3877
3846
|
/**
|
|
3878
3847
|
* Time Complexity: O(1)
|
|
@@ -3917,6 +3886,7 @@ var dataStructureTyped = (() => {
|
|
|
3917
3886
|
indexInBucket
|
|
3918
3887
|
} = this._getBucketAndPosition(pos);
|
|
3919
3888
|
this._buckets[bucketIndex][indexInBucket] = element;
|
|
3889
|
+
return true;
|
|
3920
3890
|
}
|
|
3921
3891
|
/**
|
|
3922
3892
|
* Time Complexity: O(n)
|
|
@@ -3926,7 +3896,7 @@ var dataStructureTyped = (() => {
|
|
|
3926
3896
|
* Time Complexity: O(n)
|
|
3927
3897
|
* Space Complexity: O(n)
|
|
3928
3898
|
*
|
|
3929
|
-
* The `
|
|
3899
|
+
* The `addAt` function inserts one or more elements at a specified position in an array-like data
|
|
3930
3900
|
* structure.
|
|
3931
3901
|
* @param {number} pos - The `pos` parameter represents the position at which the element(s) should
|
|
3932
3902
|
* be inserted. It is of type `number`.
|
|
@@ -3937,7 +3907,7 @@ var dataStructureTyped = (() => {
|
|
|
3937
3907
|
* will be inserted once. However, you can provide a different value for `num` if you want
|
|
3938
3908
|
* @returns The size of the array after the insertion is being returned.
|
|
3939
3909
|
*/
|
|
3940
|
-
|
|
3910
|
+
addAt(pos, element, num = 1) {
|
|
3941
3911
|
const length = this.size;
|
|
3942
3912
|
rangeCheck(pos, 0, length);
|
|
3943
3913
|
if (pos === 0) {
|
|
@@ -3957,7 +3927,7 @@ var dataStructureTyped = (() => {
|
|
|
3957
3927
|
for (let i = 0; i < arr.length; ++i)
|
|
3958
3928
|
this.push(arr[i]);
|
|
3959
3929
|
}
|
|
3960
|
-
return
|
|
3930
|
+
return true;
|
|
3961
3931
|
}
|
|
3962
3932
|
/**
|
|
3963
3933
|
* Time Complexity: O(1)
|
|
@@ -4025,7 +3995,7 @@ var dataStructureTyped = (() => {
|
|
|
4025
3995
|
}
|
|
4026
3996
|
this.pop();
|
|
4027
3997
|
}
|
|
4028
|
-
return
|
|
3998
|
+
return true;
|
|
4029
3999
|
}
|
|
4030
4000
|
/**
|
|
4031
4001
|
* Time Complexity: O(n)
|
|
@@ -4044,7 +4014,7 @@ var dataStructureTyped = (() => {
|
|
|
4044
4014
|
delete(element) {
|
|
4045
4015
|
const size = this.size;
|
|
4046
4016
|
if (size === 0)
|
|
4047
|
-
return
|
|
4017
|
+
return false;
|
|
4048
4018
|
let i = 0;
|
|
4049
4019
|
let index = 0;
|
|
4050
4020
|
while (i < size) {
|
|
@@ -4056,7 +4026,7 @@ var dataStructureTyped = (() => {
|
|
|
4056
4026
|
i += 1;
|
|
4057
4027
|
}
|
|
4058
4028
|
this.cut(index - 1);
|
|
4059
|
-
return
|
|
4029
|
+
return true;
|
|
4060
4030
|
}
|
|
4061
4031
|
/**
|
|
4062
4032
|
* Time Complexity: O(n)
|
|
@@ -4096,7 +4066,7 @@ var dataStructureTyped = (() => {
|
|
|
4096
4066
|
*/
|
|
4097
4067
|
unique() {
|
|
4098
4068
|
if (this.size <= 1) {
|
|
4099
|
-
return this
|
|
4069
|
+
return this;
|
|
4100
4070
|
}
|
|
4101
4071
|
let index = 1;
|
|
4102
4072
|
let prev = this.getAt(0);
|
|
@@ -4108,7 +4078,7 @@ var dataStructureTyped = (() => {
|
|
|
4108
4078
|
}
|
|
4109
4079
|
}
|
|
4110
4080
|
this.cut(index - 1);
|
|
4111
|
-
return this
|
|
4081
|
+
return this;
|
|
4112
4082
|
}
|
|
4113
4083
|
/**
|
|
4114
4084
|
* Time Complexity: O(n log n)
|
|
@@ -4122,7 +4092,7 @@ var dataStructureTyped = (() => {
|
|
|
4122
4092
|
* @param [comparator] - The `comparator` parameter is a function that takes in two elements `x` and
|
|
4123
4093
|
* `y` of type `E` and returns a number. The comparator function is used to determine the order of
|
|
4124
4094
|
* the elements in the sorted array.
|
|
4125
|
-
* @returns
|
|
4095
|
+
* @returns Deque<E>
|
|
4126
4096
|
*/
|
|
4127
4097
|
sort(comparator) {
|
|
4128
4098
|
const arr = [];
|
|
@@ -4192,7 +4162,7 @@ var dataStructureTyped = (() => {
|
|
|
4192
4162
|
return element;
|
|
4193
4163
|
}
|
|
4194
4164
|
}
|
|
4195
|
-
return
|
|
4165
|
+
return;
|
|
4196
4166
|
}
|
|
4197
4167
|
/**
|
|
4198
4168
|
* Time Complexity: O(n)
|
|
@@ -4229,11 +4199,7 @@ var dataStructureTyped = (() => {
|
|
|
4229
4199
|
* @returns The `toArray()` method is returning an array of elements of type `E`.
|
|
4230
4200
|
*/
|
|
4231
4201
|
toArray() {
|
|
4232
|
-
|
|
4233
|
-
for (let i = 0; i < this.size; ++i) {
|
|
4234
|
-
arr.push(this.getAt(i));
|
|
4235
|
-
}
|
|
4236
|
-
return arr;
|
|
4202
|
+
return [...this];
|
|
4237
4203
|
}
|
|
4238
4204
|
/**
|
|
4239
4205
|
* Time Complexity: O(n)
|
|
@@ -4293,11 +4259,55 @@ var dataStructureTyped = (() => {
|
|
|
4293
4259
|
return newDeque;
|
|
4294
4260
|
}
|
|
4295
4261
|
/**
|
|
4296
|
-
* Time Complexity: O(n)
|
|
4297
|
-
* Space Complexity: O(n)
|
|
4262
|
+
* Time Complexity: Amortized O(1) - Similar to push, resizing leads to O(n).
|
|
4263
|
+
* Space Complexity: O(n) - Due to potential resizing.
|
|
4298
4264
|
*/
|
|
4299
|
-
|
|
4300
|
-
|
|
4265
|
+
/**
|
|
4266
|
+
* Time Complexity: O(1)
|
|
4267
|
+
* Space Complexity: O(n) - In worst case, resizing doubles the array size.
|
|
4268
|
+
*
|
|
4269
|
+
* The addLast function adds an element to the end of an array.
|
|
4270
|
+
* @param {E} element - The element parameter represents the element that you want to add to the end of the
|
|
4271
|
+
* data structure.
|
|
4272
|
+
*/
|
|
4273
|
+
addLast(element) {
|
|
4274
|
+
return this.push(element);
|
|
4275
|
+
}
|
|
4276
|
+
/**
|
|
4277
|
+
* Time Complexity: O(1) - Removes the first element.
|
|
4278
|
+
* Space Complexity: O(1) - In-place operation.
|
|
4279
|
+
*/
|
|
4280
|
+
/**
|
|
4281
|
+
* Time Complexity: O(1) - Removes the last element.
|
|
4282
|
+
* Space Complexity: O(1) - Operates in-place.
|
|
4283
|
+
*
|
|
4284
|
+
* The function "pollLast" removes and returns the last element of an array.
|
|
4285
|
+
* @returns The last element of the array is being returned.
|
|
4286
|
+
*/
|
|
4287
|
+
pollLast() {
|
|
4288
|
+
return this.pop();
|
|
4289
|
+
}
|
|
4290
|
+
/**
|
|
4291
|
+
* Time Complexity: O(1).
|
|
4292
|
+
* Space Complexity: O(n) - Due to potential resizing.
|
|
4293
|
+
*
|
|
4294
|
+
* The "addFirst" function adds an element to the beginning of an array.
|
|
4295
|
+
* @param {E} element - The parameter "element" represents the element that you want to add to the
|
|
4296
|
+
* beginning of the data structure.
|
|
4297
|
+
*/
|
|
4298
|
+
addFirst(element) {
|
|
4299
|
+
return this.unshift(element);
|
|
4300
|
+
}
|
|
4301
|
+
/**
|
|
4302
|
+
* Time Complexity: O(1) - Removes the first element.
|
|
4303
|
+
* Space Complexity: O(1) - In-place operation.
|
|
4304
|
+
*
|
|
4305
|
+
* The function "pollFirst" removes and returns the first element of an array.
|
|
4306
|
+
* @returns The method `pollFirst()` is returning the first element of the array after removing it
|
|
4307
|
+
* from the beginning. If the array is empty, it will return `undefined`.
|
|
4308
|
+
*/
|
|
4309
|
+
pollFirst() {
|
|
4310
|
+
return this.shift();
|
|
4301
4311
|
}
|
|
4302
4312
|
/**
|
|
4303
4313
|
* Time Complexity: O(n)
|
|
@@ -4396,7 +4406,7 @@ var dataStructureTyped = (() => {
|
|
|
4396
4406
|
}
|
|
4397
4407
|
if (elements) {
|
|
4398
4408
|
for (const el of elements) {
|
|
4399
|
-
this.
|
|
4409
|
+
this.add(el);
|
|
4400
4410
|
}
|
|
4401
4411
|
}
|
|
4402
4412
|
}
|
|
@@ -4438,23 +4448,8 @@ var dataStructureTyped = (() => {
|
|
|
4438
4448
|
* @param element - The element to be inserted.
|
|
4439
4449
|
*/
|
|
4440
4450
|
add(element) {
|
|
4441
|
-
return this.push(element);
|
|
4442
|
-
}
|
|
4443
|
-
/**
|
|
4444
|
-
* Time Complexity: O(log n), where n is the number of elements in the heap.
|
|
4445
|
-
* Space Complexity: O(1)
|
|
4446
|
-
*/
|
|
4447
|
-
/**
|
|
4448
|
-
* Time Complexity: O(log n), where n is the number of elements in the heap.
|
|
4449
|
-
* Space Complexity: O(1)
|
|
4450
|
-
*
|
|
4451
|
-
* Insert an element into the heap and maintain the heap properties.
|
|
4452
|
-
* @param element - The element to be inserted.
|
|
4453
|
-
*/
|
|
4454
|
-
push(element) {
|
|
4455
4451
|
this._elements.push(element);
|
|
4456
|
-
this._bubbleUp(this.elements.length - 1);
|
|
4457
|
-
return this;
|
|
4452
|
+
return this._bubbleUp(this.elements.length - 1);
|
|
4458
4453
|
}
|
|
4459
4454
|
/**
|
|
4460
4455
|
* Time Complexity: O(log n), where n is the number of elements in the heap.
|
|
@@ -4478,20 +4473,6 @@ var dataStructureTyped = (() => {
|
|
|
4478
4473
|
}
|
|
4479
4474
|
return value;
|
|
4480
4475
|
}
|
|
4481
|
-
/**
|
|
4482
|
-
* Time Complexity: O(log n), where n is the number of elements in the heap.
|
|
4483
|
-
* Space Complexity: O(1)
|
|
4484
|
-
*/
|
|
4485
|
-
/**
|
|
4486
|
-
* Time Complexity: O(log n), where n is the number of elements in the heap.
|
|
4487
|
-
* Space Complexity: O(1)
|
|
4488
|
-
*
|
|
4489
|
-
* Remove and return the top element (smallest or largest element) from the heap.
|
|
4490
|
-
* @returns The top element or undefined if the heap is empty.
|
|
4491
|
-
*/
|
|
4492
|
-
pop() {
|
|
4493
|
-
return this.poll();
|
|
4494
|
-
}
|
|
4495
4476
|
/**
|
|
4496
4477
|
* Peek at the top element of the heap without removing it.
|
|
4497
4478
|
* @returns The top element or undefined if the heap is empty.
|
|
@@ -4525,7 +4506,7 @@ var dataStructureTyped = (() => {
|
|
|
4525
4506
|
*/
|
|
4526
4507
|
refill(elements) {
|
|
4527
4508
|
this._elements = elements;
|
|
4528
|
-
this.fix();
|
|
4509
|
+
return this.fix();
|
|
4529
4510
|
}
|
|
4530
4511
|
/**
|
|
4531
4512
|
* Time Complexity: O(n), where n is the number of elements in the heap.
|
|
@@ -4562,7 +4543,7 @@ var dataStructureTyped = (() => {
|
|
|
4562
4543
|
if (index < 0)
|
|
4563
4544
|
return false;
|
|
4564
4545
|
if (index === 0) {
|
|
4565
|
-
this.
|
|
4546
|
+
this.poll();
|
|
4566
4547
|
} else if (index === this.elements.length - 1) {
|
|
4567
4548
|
this.elements.pop();
|
|
4568
4549
|
} else {
|
|
@@ -4669,8 +4650,10 @@ var dataStructureTyped = (() => {
|
|
|
4669
4650
|
* Fix the entire heap to maintain heap properties.
|
|
4670
4651
|
*/
|
|
4671
4652
|
fix() {
|
|
4653
|
+
const results = [];
|
|
4672
4654
|
for (let i = Math.floor(this.size / 2); i >= 0; i--)
|
|
4673
|
-
this._sinkDown(i, this.elements.length >> 1);
|
|
4655
|
+
results.push(this._sinkDown(i, this.elements.length >> 1));
|
|
4656
|
+
return results;
|
|
4674
4657
|
}
|
|
4675
4658
|
/**
|
|
4676
4659
|
* Time Complexity: O(n)
|
|
@@ -4697,7 +4680,7 @@ var dataStructureTyped = (() => {
|
|
|
4697
4680
|
let index = 0;
|
|
4698
4681
|
for (const current of this) {
|
|
4699
4682
|
if (callback.call(thisArg, current, index, this)) {
|
|
4700
|
-
filteredList.
|
|
4683
|
+
filteredList.add(current);
|
|
4701
4684
|
}
|
|
4702
4685
|
index++;
|
|
4703
4686
|
}
|
|
@@ -4736,13 +4719,6 @@ var dataStructureTyped = (() => {
|
|
|
4736
4719
|
}
|
|
4737
4720
|
return mappedHeap;
|
|
4738
4721
|
}
|
|
4739
|
-
/**
|
|
4740
|
-
* Time Complexity: O(log n)
|
|
4741
|
-
* Space Complexity: O(1)
|
|
4742
|
-
*/
|
|
4743
|
-
print() {
|
|
4744
|
-
console.log([...this]);
|
|
4745
|
-
}
|
|
4746
4722
|
*_getIterator() {
|
|
4747
4723
|
for (const element of this.elements) {
|
|
4748
4724
|
yield element;
|
|
@@ -4770,6 +4746,7 @@ var dataStructureTyped = (() => {
|
|
|
4770
4746
|
index = parent;
|
|
4771
4747
|
}
|
|
4772
4748
|
this.elements[index] = element;
|
|
4749
|
+
return true;
|
|
4773
4750
|
}
|
|
4774
4751
|
/**
|
|
4775
4752
|
* Time Complexity: O(log n)
|
|
@@ -4795,6 +4772,7 @@ var dataStructureTyped = (() => {
|
|
|
4795
4772
|
index = left;
|
|
4796
4773
|
}
|
|
4797
4774
|
this.elements[index] = element;
|
|
4775
|
+
return true;
|
|
4798
4776
|
}
|
|
4799
4777
|
};
|
|
4800
4778
|
var FibonacciHeapNode = class {
|
|
@@ -5175,43 +5153,6 @@ var dataStructureTyped = (() => {
|
|
|
5175
5153
|
}
|
|
5176
5154
|
};
|
|
5177
5155
|
|
|
5178
|
-
// src/data-structures/priority-queue/priority-queue.ts
|
|
5179
|
-
var PriorityQueue = class extends Heap {
|
|
5180
|
-
constructor(elements, options) {
|
|
5181
|
-
super(elements, options);
|
|
5182
|
-
}
|
|
5183
|
-
};
|
|
5184
|
-
|
|
5185
|
-
// src/data-structures/priority-queue/min-priority-queue.ts
|
|
5186
|
-
var MinPriorityQueue = class extends PriorityQueue {
|
|
5187
|
-
constructor(elements, options = {
|
|
5188
|
-
comparator: (a, b) => {
|
|
5189
|
-
if (!(typeof a === "number" && typeof b === "number")) {
|
|
5190
|
-
throw new Error("The a, b params of compare function must be number");
|
|
5191
|
-
} else {
|
|
5192
|
-
return a - b;
|
|
5193
|
-
}
|
|
5194
|
-
}
|
|
5195
|
-
}) {
|
|
5196
|
-
super(elements, options);
|
|
5197
|
-
}
|
|
5198
|
-
};
|
|
5199
|
-
|
|
5200
|
-
// src/data-structures/priority-queue/max-priority-queue.ts
|
|
5201
|
-
var MaxPriorityQueue = class extends PriorityQueue {
|
|
5202
|
-
constructor(elements, options = {
|
|
5203
|
-
comparator: (a, b) => {
|
|
5204
|
-
if (!(typeof a === "number" && typeof b === "number")) {
|
|
5205
|
-
throw new Error("The a, b params of compare function must be number");
|
|
5206
|
-
} else {
|
|
5207
|
-
return b - a;
|
|
5208
|
-
}
|
|
5209
|
-
}
|
|
5210
|
-
}) {
|
|
5211
|
-
super(elements, options);
|
|
5212
|
-
}
|
|
5213
|
-
};
|
|
5214
|
-
|
|
5215
5156
|
// src/data-structures/graph/abstract-graph.ts
|
|
5216
5157
|
var AbstractVertex = class {
|
|
5217
5158
|
/**
|
|
@@ -5638,13 +5579,7 @@ var dataStructureTyped = (() => {
|
|
|
5638
5579
|
* shortest paths from the source vertex to all other vertexMap in the graph. If `genPaths
|
|
5639
5580
|
* @returns The function `dijkstraWithoutHeap` returns an object of type `DijkstraResult<VO>`.
|
|
5640
5581
|
*/
|
|
5641
|
-
dijkstraWithoutHeap(src, dest, getMinDist, genPaths) {
|
|
5642
|
-
if (getMinDist === void 0)
|
|
5643
|
-
getMinDist = false;
|
|
5644
|
-
if (genPaths === void 0)
|
|
5645
|
-
genPaths = false;
|
|
5646
|
-
if (dest === void 0)
|
|
5647
|
-
dest = void 0;
|
|
5582
|
+
dijkstraWithoutHeap(src, dest = void 0, getMinDist = false, genPaths = false) {
|
|
5648
5583
|
let minDist = Infinity;
|
|
5649
5584
|
let minDest = void 0;
|
|
5650
5585
|
let minPath = [];
|
|
@@ -5771,14 +5706,8 @@ var dataStructureTyped = (() => {
|
|
|
5771
5706
|
* shortest paths from the source vertex to all other vertexMap in the graph. If `genPaths
|
|
5772
5707
|
* @returns The function `dijkstra` returns an object of type `DijkstraResult<VO>`.
|
|
5773
5708
|
*/
|
|
5774
|
-
dijkstra(src, dest, getMinDist, genPaths) {
|
|
5709
|
+
dijkstra(src, dest = void 0, getMinDist = false, genPaths = false) {
|
|
5775
5710
|
var _a;
|
|
5776
|
-
if (getMinDist === void 0)
|
|
5777
|
-
getMinDist = false;
|
|
5778
|
-
if (genPaths === void 0)
|
|
5779
|
-
genPaths = false;
|
|
5780
|
-
if (dest === void 0)
|
|
5781
|
-
dest = void 0;
|
|
5782
5711
|
let minDist = Infinity;
|
|
5783
5712
|
let minDest = void 0;
|
|
5784
5713
|
let minPath = [];
|
|
@@ -5796,7 +5725,7 @@ var dataStructureTyped = (() => {
|
|
|
5796
5725
|
if (vertexOrKey instanceof AbstractVertex)
|
|
5797
5726
|
distMap.set(vertexOrKey, Infinity);
|
|
5798
5727
|
}
|
|
5799
|
-
const heap = new
|
|
5728
|
+
const heap = new Heap([], { comparator: (a, b) => a.key - b.key });
|
|
5800
5729
|
heap.add({ key: 0, value: srcVertex });
|
|
5801
5730
|
distMap.set(srcVertex, 0);
|
|
5802
5731
|
preMap.set(srcVertex, void 0);
|
|
@@ -6152,13 +6081,27 @@ var dataStructureTyped = (() => {
|
|
|
6152
6081
|
}
|
|
6153
6082
|
const cycles = /* @__PURE__ */ new Map();
|
|
6154
6083
|
if (needCycles) {
|
|
6155
|
-
|
|
6156
|
-
|
|
6157
|
-
|
|
6158
|
-
|
|
6159
|
-
|
|
6160
|
-
|
|
6161
|
-
|
|
6084
|
+
const visitedMap = /* @__PURE__ */ new Map();
|
|
6085
|
+
const stack = [];
|
|
6086
|
+
const findCyclesDFS = (cur, parent) => {
|
|
6087
|
+
visitedMap.set(cur, true);
|
|
6088
|
+
stack.push(cur);
|
|
6089
|
+
const neighbors = this.getNeighbors(cur);
|
|
6090
|
+
for (const neighbor of neighbors) {
|
|
6091
|
+
if (!visitedMap.get(neighbor)) {
|
|
6092
|
+
findCyclesDFS(neighbor, cur);
|
|
6093
|
+
} else if (stack.includes(neighbor) && neighbor !== parent) {
|
|
6094
|
+
const cycleStartIndex = stack.indexOf(neighbor);
|
|
6095
|
+
const cycle = stack.slice(cycleStartIndex);
|
|
6096
|
+
const cycleLow = Math.min(...cycle.map((v) => dfnMap.get(v) || Infinity));
|
|
6097
|
+
cycles.set(cycleLow, cycle);
|
|
6098
|
+
}
|
|
6099
|
+
}
|
|
6100
|
+
stack.pop();
|
|
6101
|
+
};
|
|
6102
|
+
vertexMap.forEach((v) => {
|
|
6103
|
+
if (!visitedMap.get(v)) {
|
|
6104
|
+
findCyclesDFS(v, void 0);
|
|
6162
6105
|
}
|
|
6163
6106
|
});
|
|
6164
6107
|
}
|
|
@@ -7285,23 +7228,6 @@ var dataStructureTyped = (() => {
|
|
|
7285
7228
|
}
|
|
7286
7229
|
};
|
|
7287
7230
|
|
|
7288
|
-
// src/types/data-structures/binary-tree/binary-tree.ts
|
|
7289
|
-
var IterationType = /* @__PURE__ */ ((IterationType3) => {
|
|
7290
|
-
IterationType3["ITERATIVE"] = "ITERATIVE";
|
|
7291
|
-
IterationType3["RECURSIVE"] = "RECURSIVE";
|
|
7292
|
-
return IterationType3;
|
|
7293
|
-
})(IterationType || {});
|
|
7294
|
-
var FamilyPosition = /* @__PURE__ */ ((FamilyPosition2) => {
|
|
7295
|
-
FamilyPosition2["ROOT"] = "ROOT";
|
|
7296
|
-
FamilyPosition2["LEFT"] = "LEFT";
|
|
7297
|
-
FamilyPosition2["RIGHT"] = "RIGHT";
|
|
7298
|
-
FamilyPosition2["ROOT_LEFT"] = "ROOT_LEFT";
|
|
7299
|
-
FamilyPosition2["ROOT_RIGHT"] = "ROOT_RIGHT";
|
|
7300
|
-
FamilyPosition2["ISOLATED"] = "ISOLATED";
|
|
7301
|
-
FamilyPosition2["MAL_NODE"] = "MAL_NODE";
|
|
7302
|
-
return FamilyPosition2;
|
|
7303
|
-
})(FamilyPosition || {});
|
|
7304
|
-
|
|
7305
7231
|
// src/types/data-structures/binary-tree/rb-tree.ts
|
|
7306
7232
|
var RBTNColor = /* @__PURE__ */ ((RBTNColor2) => {
|
|
7307
7233
|
RBTNColor2[RBTNColor2["RED"] = 1] = "RED";
|
|
@@ -7321,6 +7247,21 @@ var dataStructureTyped = (() => {
|
|
|
7321
7247
|
CP2["gt"] = "gt";
|
|
7322
7248
|
return CP2;
|
|
7323
7249
|
})(CP || {});
|
|
7250
|
+
var IterationType = /* @__PURE__ */ ((IterationType3) => {
|
|
7251
|
+
IterationType3["ITERATIVE"] = "ITERATIVE";
|
|
7252
|
+
IterationType3["RECURSIVE"] = "RECURSIVE";
|
|
7253
|
+
return IterationType3;
|
|
7254
|
+
})(IterationType || {});
|
|
7255
|
+
var FamilyPosition = /* @__PURE__ */ ((FamilyPosition2) => {
|
|
7256
|
+
FamilyPosition2["ROOT"] = "ROOT";
|
|
7257
|
+
FamilyPosition2["LEFT"] = "LEFT";
|
|
7258
|
+
FamilyPosition2["RIGHT"] = "RIGHT";
|
|
7259
|
+
FamilyPosition2["ROOT_LEFT"] = "ROOT_LEFT";
|
|
7260
|
+
FamilyPosition2["ROOT_RIGHT"] = "ROOT_RIGHT";
|
|
7261
|
+
FamilyPosition2["ISOLATED"] = "ISOLATED";
|
|
7262
|
+
FamilyPosition2["MAL_NODE"] = "MAL_NODE";
|
|
7263
|
+
return FamilyPosition2;
|
|
7264
|
+
})(FamilyPosition || {});
|
|
7324
7265
|
|
|
7325
7266
|
// src/data-structures/binary-tree/binary-tree.ts
|
|
7326
7267
|
var BinaryTreeNode = class {
|
|
@@ -7371,7 +7312,7 @@ var dataStructureTyped = (() => {
|
|
|
7371
7312
|
var BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
7372
7313
|
/**
|
|
7373
7314
|
* The constructor function initializes a binary tree object with optional elements and options.
|
|
7374
|
-
* @param [elements] - An optional iterable of
|
|
7315
|
+
* @param [elements] - An optional iterable of BTNExemplar objects. These objects represent the
|
|
7375
7316
|
* elements to be added to the binary tree.
|
|
7376
7317
|
* @param [options] - The `options` parameter is an optional object that can contain additional
|
|
7377
7318
|
* configuration options for the binary tree. In this case, it is of type
|
|
@@ -7428,7 +7369,7 @@ var dataStructureTyped = (() => {
|
|
|
7428
7369
|
}
|
|
7429
7370
|
/**
|
|
7430
7371
|
* The function "isNode" checks if an exemplar is an instance of the BinaryTreeNode class.
|
|
7431
|
-
* @param exemplar - The `exemplar` parameter is a variable of type `
|
|
7372
|
+
* @param exemplar - The `exemplar` parameter is a variable of type `BTNExemplar<K, V,N>`.
|
|
7432
7373
|
* @returns a boolean value indicating whether the exemplar is an instance of the class N.
|
|
7433
7374
|
*/
|
|
7434
7375
|
isNode(exemplar) {
|
|
@@ -7436,7 +7377,7 @@ var dataStructureTyped = (() => {
|
|
|
7436
7377
|
}
|
|
7437
7378
|
/**
|
|
7438
7379
|
* The function `exemplarToNode` converts an exemplar object into a node object.
|
|
7439
|
-
* @param exemplar - The `exemplar` parameter is of type `
|
|
7380
|
+
* @param exemplar - The `exemplar` parameter is of type `BTNExemplar<K, V, N>`.
|
|
7440
7381
|
* @param {V} [value] - The `value` parameter is an optional value that can be passed to the
|
|
7441
7382
|
* `exemplarToNode` function. It represents the value associated with the exemplar node. If no value
|
|
7442
7383
|
* is provided, it will be `undefined`.
|
|
@@ -7468,7 +7409,7 @@ var dataStructureTyped = (() => {
|
|
|
7468
7409
|
}
|
|
7469
7410
|
/**
|
|
7470
7411
|
* The function checks if a given value is an entry in a binary tree node.
|
|
7471
|
-
* @param kne -
|
|
7412
|
+
* @param kne - BTNExemplar<K, V,N> - A generic type representing a node in a binary tree. It has
|
|
7472
7413
|
* two type parameters V and N, representing the value and node type respectively.
|
|
7473
7414
|
* @returns a boolean value.
|
|
7474
7415
|
*/
|
|
@@ -7540,7 +7481,7 @@ var dataStructureTyped = (() => {
|
|
|
7540
7481
|
*
|
|
7541
7482
|
* The `addMany` function takes in a collection of nodes and an optional collection of values, and
|
|
7542
7483
|
* adds each node with its corresponding value to the data structure.
|
|
7543
|
-
* @param nodes - An iterable collection of
|
|
7484
|
+
* @param nodes - An iterable collection of BTNExemplar objects.
|
|
7544
7485
|
* @param [values] - An optional iterable of values that will be assigned to each node being added.
|
|
7545
7486
|
* @returns The function `addMany` returns an array of `N`, `null`, or `undefined` values.
|
|
7546
7487
|
*/
|
|
@@ -7583,7 +7524,7 @@ var dataStructureTyped = (() => {
|
|
|
7583
7524
|
* @param {C} callback - The `callback` parameter is a function that is used to determine the
|
|
7584
7525
|
* identifier of the node to be deleted. It is optional and has a default value of
|
|
7585
7526
|
* `this._defaultOneParamCallback`. The `callback` function should return the identifier of the node.
|
|
7586
|
-
* @returns an array of `
|
|
7527
|
+
* @returns an array of `BinaryTreeDeleteResult<N>`.
|
|
7587
7528
|
*/
|
|
7588
7529
|
delete(identifier, callback = this._defaultOneParamCallback) {
|
|
7589
7530
|
const deletedResult = [];
|
|
@@ -8989,7 +8930,7 @@ var dataStructureTyped = (() => {
|
|
|
8989
8930
|
/**
|
|
8990
8931
|
* This is the constructor function for a binary search tree class in TypeScript, which initializes
|
|
8991
8932
|
* the tree with optional elements and options.
|
|
8992
|
-
* @param [elements] - An optional iterable of
|
|
8933
|
+
* @param [elements] - An optional iterable of BTNExemplar objects that will be added to the
|
|
8993
8934
|
* binary search tree.
|
|
8994
8935
|
* @param [options] - The `options` parameter is an optional object that can contain additional
|
|
8995
8936
|
* configuration options for the binary search tree. It can have the following properties:
|
|
@@ -9040,7 +8981,7 @@ var dataStructureTyped = (() => {
|
|
|
9040
8981
|
}
|
|
9041
8982
|
/**
|
|
9042
8983
|
* The function checks if an exemplar is an instance of BSTNode.
|
|
9043
|
-
* @param exemplar - The `exemplar` parameter is a variable of type `
|
|
8984
|
+
* @param exemplar - The `exemplar` parameter is a variable of type `BTNExemplar<K, V, N>`.
|
|
9044
8985
|
* @returns a boolean value indicating whether the exemplar is an instance of the BSTNode class.
|
|
9045
8986
|
*/
|
|
9046
8987
|
isNode(exemplar) {
|
|
@@ -9049,7 +8990,7 @@ var dataStructureTyped = (() => {
|
|
|
9049
8990
|
/**
|
|
9050
8991
|
* The function `exemplarToNode` takes an exemplar and returns a node if the exemplar is valid,
|
|
9051
8992
|
* otherwise it returns undefined.
|
|
9052
|
-
* @param exemplar - The `exemplar` parameter is of type `
|
|
8993
|
+
* @param exemplar - The `exemplar` parameter is of type `BTNExemplar<K, V, N>`, where:
|
|
9053
8994
|
* @param {V} [value] - The `value` parameter is an optional value that can be passed to the
|
|
9054
8995
|
* `exemplarToNode` function. It represents the value associated with the exemplar node.
|
|
9055
8996
|
* @returns a node of type N or undefined.
|
|
@@ -10040,7 +9981,7 @@ var dataStructureTyped = (() => {
|
|
|
10040
9981
|
var AVLTree = class _AVLTree extends BST {
|
|
10041
9982
|
/**
|
|
10042
9983
|
* The constructor function initializes an AVLTree object with optional elements and options.
|
|
10043
|
-
* @param [elements] - The `elements` parameter is an optional iterable of `
|
|
9984
|
+
* @param [elements] - The `elements` parameter is an optional iterable of `BTNExemplar<K, V, N>`
|
|
10044
9985
|
* objects. It represents a collection of elements that will be added to the AVL tree during
|
|
10045
9986
|
* initialization.
|
|
10046
9987
|
* @param [options] - The `options` parameter is an optional object that allows you to customize the
|
|
@@ -10079,7 +10020,7 @@ var dataStructureTyped = (() => {
|
|
|
10079
10020
|
}
|
|
10080
10021
|
/**
|
|
10081
10022
|
* The function checks if an exemplar is an instance of AVLTreeNode.
|
|
10082
|
-
* @param exemplar - The `exemplar` parameter is of type `
|
|
10023
|
+
* @param exemplar - The `exemplar` parameter is of type `BTNExemplar<K, V, N>`.
|
|
10083
10024
|
* @returns a boolean value indicating whether the exemplar is an instance of the AVLTreeNode class.
|
|
10084
10025
|
*/
|
|
10085
10026
|
isNode(exemplar) {
|
|
@@ -10135,7 +10076,7 @@ var dataStructureTyped = (() => {
|
|
|
10135
10076
|
* that is deleted from the binary tree. It is an optional parameter and if not provided, it will
|
|
10136
10077
|
* default to the `_defaultOneParamCallback` function. The `callback` function should have a single
|
|
10137
10078
|
* parameter of type `N
|
|
10138
|
-
* @returns The method is returning an array of `
|
|
10079
|
+
* @returns The method is returning an array of `BinaryTreeDeleteResult<N>`.
|
|
10139
10080
|
*/
|
|
10140
10081
|
delete(identifier, callback = this._defaultOneParamCallback) {
|
|
10141
10082
|
if (identifier instanceof AVLTreeNode)
|
|
@@ -10465,7 +10406,7 @@ var dataStructureTyped = (() => {
|
|
|
10465
10406
|
/**
|
|
10466
10407
|
* This is the constructor function for a Red-Black Tree data structure in TypeScript, which
|
|
10467
10408
|
* initializes the tree with optional elements and options.
|
|
10468
|
-
* @param [elements] - The `elements` parameter is an optional iterable of `
|
|
10409
|
+
* @param [elements] - The `elements` parameter is an optional iterable of `BTNExemplar<K, V, N>`
|
|
10469
10410
|
* objects. It represents the initial elements that will be added to the RBTree during its
|
|
10470
10411
|
* construction. If this parameter is provided, the `addMany` method is called to add all the
|
|
10471
10412
|
* elements to the
|
|
@@ -10518,7 +10459,7 @@ var dataStructureTyped = (() => {
|
|
|
10518
10459
|
}
|
|
10519
10460
|
/**
|
|
10520
10461
|
* The function checks if an exemplar is an instance of the RedBlackTreeNode class.
|
|
10521
|
-
* @param exemplar - The `exemplar` parameter is of type `
|
|
10462
|
+
* @param exemplar - The `exemplar` parameter is of type `BTNExemplar<K, V, N>`.
|
|
10522
10463
|
* @returns a boolean value indicating whether the exemplar is an instance of the RedBlackTreeNode
|
|
10523
10464
|
* class.
|
|
10524
10465
|
*/
|
|
@@ -10536,7 +10477,7 @@ var dataStructureTyped = (() => {
|
|
|
10536
10477
|
}
|
|
10537
10478
|
/**
|
|
10538
10479
|
* The function `exemplarToNode` takes an exemplar and converts it into a node object if possible.
|
|
10539
|
-
* @param exemplar - The `exemplar` parameter is of type `
|
|
10480
|
+
* @param exemplar - The `exemplar` parameter is of type `BTNExemplar<K, V, N>`, where:
|
|
10540
10481
|
* @param {V} [value] - The `value` parameter is an optional value that can be passed to the
|
|
10541
10482
|
* `exemplarToNode` function. It represents the value associated with the exemplar node. If a value
|
|
10542
10483
|
* is provided, it will be used when creating the new node. If no value is provided, the new node
|
|
@@ -10638,7 +10579,7 @@ var dataStructureTyped = (() => {
|
|
|
10638
10579
|
* @param {C} callback - The `callback` parameter is a function that takes a node of type `N` and
|
|
10639
10580
|
* returns a value of type `ReturnType<C>`. It is used to determine if a node should be deleted based
|
|
10640
10581
|
* on its identifier. The `callback` function is optional and defaults to `this._defaultOneParam
|
|
10641
|
-
* @returns an array of `
|
|
10582
|
+
* @returns an array of `BinaryTreeDeleteResult<N>`.
|
|
10642
10583
|
*/
|
|
10643
10584
|
delete(identifier, callback = this._defaultOneParamCallback) {
|
|
10644
10585
|
const ans = [];
|
|
@@ -10729,7 +10670,7 @@ var dataStructureTyped = (() => {
|
|
|
10729
10670
|
*/
|
|
10730
10671
|
getNode(identifier, callback = this._defaultOneParamCallback, beginRoot = this.root, iterationType = this.iterationType) {
|
|
10731
10672
|
var _a;
|
|
10732
|
-
if (identifier instanceof
|
|
10673
|
+
if (identifier instanceof RedBlackTreeNode)
|
|
10733
10674
|
callback = (node) => node;
|
|
10734
10675
|
beginRoot = this.ensureNode(beginRoot);
|
|
10735
10676
|
return (_a = this.getNodes(identifier, callback, true, beginRoot, iterationType)[0]) != null ? _a : void 0;
|
|
@@ -11049,7 +10990,7 @@ var dataStructureTyped = (() => {
|
|
|
11049
10990
|
}
|
|
11050
10991
|
/**
|
|
11051
10992
|
* The function checks if an exemplar is an instance of the TreeMultimapNode class.
|
|
11052
|
-
* @param exemplar - The `exemplar` parameter is of type `
|
|
10993
|
+
* @param exemplar - The `exemplar` parameter is of type `BTNExemplar<K, V, N>`.
|
|
11053
10994
|
* @returns a boolean value indicating whether the exemplar is an instance of the TreeMultimapNode
|
|
11054
10995
|
* class.
|
|
11055
10996
|
*/
|
|
@@ -11067,7 +11008,7 @@ var dataStructureTyped = (() => {
|
|
|
11067
11008
|
}
|
|
11068
11009
|
/**
|
|
11069
11010
|
* The function `exemplarToNode` converts an exemplar object into a node object.
|
|
11070
|
-
* @param exemplar - The `exemplar` parameter is of type `
|
|
11011
|
+
* @param exemplar - The `exemplar` parameter is of type `BTNExemplar<K, V, N>`, which means it
|
|
11071
11012
|
* can be one of the following:
|
|
11072
11013
|
* @param {V} [value] - The `value` parameter is an optional argument that represents the value
|
|
11073
11014
|
* associated with the node. It is of type `V`, which can be any data type. If no value is provided,
|
|
@@ -11215,7 +11156,7 @@ var dataStructureTyped = (() => {
|
|
|
11215
11156
|
* being deleted. If set to true, the count of the node will not be considered and the node will be
|
|
11216
11157
|
* deleted regardless of its count. If set to false (default), the count of the node will be
|
|
11217
11158
|
* decremented by 1 and
|
|
11218
|
-
* @returns an array of `
|
|
11159
|
+
* @returns an array of `BinaryTreeDeleteResult<N>`.
|
|
11219
11160
|
*/
|
|
11220
11161
|
delete(identifier, callback = this._defaultOneParamCallback, ignoreCount = false) {
|
|
11221
11162
|
var _a;
|
|
@@ -11411,6 +11352,43 @@ var dataStructureTyped = (() => {
|
|
|
11411
11352
|
}
|
|
11412
11353
|
};
|
|
11413
11354
|
|
|
11355
|
+
// src/data-structures/priority-queue/priority-queue.ts
|
|
11356
|
+
var PriorityQueue = class extends Heap {
|
|
11357
|
+
constructor(elements, options) {
|
|
11358
|
+
super(elements, options);
|
|
11359
|
+
}
|
|
11360
|
+
};
|
|
11361
|
+
|
|
11362
|
+
// src/data-structures/priority-queue/min-priority-queue.ts
|
|
11363
|
+
var MinPriorityQueue = class extends PriorityQueue {
|
|
11364
|
+
constructor(elements, options = {
|
|
11365
|
+
comparator: (a, b) => {
|
|
11366
|
+
if (!(typeof a === "number" && typeof b === "number")) {
|
|
11367
|
+
throw new Error("The a, b params of compare function must be number");
|
|
11368
|
+
} else {
|
|
11369
|
+
return a - b;
|
|
11370
|
+
}
|
|
11371
|
+
}
|
|
11372
|
+
}) {
|
|
11373
|
+
super(elements, options);
|
|
11374
|
+
}
|
|
11375
|
+
};
|
|
11376
|
+
|
|
11377
|
+
// src/data-structures/priority-queue/max-priority-queue.ts
|
|
11378
|
+
var MaxPriorityQueue = class extends PriorityQueue {
|
|
11379
|
+
constructor(elements, options = {
|
|
11380
|
+
comparator: (a, b) => {
|
|
11381
|
+
if (!(typeof a === "number" && typeof b === "number")) {
|
|
11382
|
+
throw new Error("The a, b params of compare function must be number");
|
|
11383
|
+
} else {
|
|
11384
|
+
return b - a;
|
|
11385
|
+
}
|
|
11386
|
+
}
|
|
11387
|
+
}) {
|
|
11388
|
+
super(elements, options);
|
|
11389
|
+
}
|
|
11390
|
+
};
|
|
11391
|
+
|
|
11414
11392
|
// src/data-structures/matrix/matrix.ts
|
|
11415
11393
|
var MatrixNTI2D = class {
|
|
11416
11394
|
/**
|
|
@@ -12333,11 +12311,11 @@ var dataStructureTyped = (() => {
|
|
|
12333
12311
|
* @returns The `filter` method is returning an array of strings (`string[]`).
|
|
12334
12312
|
*/
|
|
12335
12313
|
filter(predicate, thisArg) {
|
|
12336
|
-
const results =
|
|
12314
|
+
const results = new _Trie();
|
|
12337
12315
|
let index = 0;
|
|
12338
12316
|
for (const word of this) {
|
|
12339
12317
|
if (predicate.call(thisArg, word, index, this)) {
|
|
12340
|
-
results.
|
|
12318
|
+
results.add(word);
|
|
12341
12319
|
}
|
|
12342
12320
|
index++;
|
|
12343
12321
|
}
|
|
@@ -12369,9 +12347,6 @@ var dataStructureTyped = (() => {
|
|
|
12369
12347
|
}
|
|
12370
12348
|
return newTrie;
|
|
12371
12349
|
}
|
|
12372
|
-
print() {
|
|
12373
|
-
console.log([...this]);
|
|
12374
|
-
}
|
|
12375
12350
|
*_getIterator() {
|
|
12376
12351
|
function* _dfs(node, path) {
|
|
12377
12352
|
if (node.isEnd) {
|