deque-typed 2.5.3 → 2.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.cjs +140 -1
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs-legacy/index.cjs +140 -1
- package/dist/cjs-legacy/index.cjs.map +1 -1
- package/dist/esm/index.mjs +140 -1
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm-legacy/index.mjs +140 -1
- package/dist/esm-legacy/index.mjs.map +1 -1
- package/dist/types/data-structures/base/iterable-element-base.d.ts +17 -0
- package/dist/types/data-structures/base/linear-base.d.ts +6 -0
- package/dist/types/data-structures/binary-tree/avl-tree.d.ts +36 -0
- package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +42 -0
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +75 -0
- package/dist/types/data-structures/binary-tree/bst.d.ts +72 -0
- package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +57 -0
- package/dist/types/data-structures/binary-tree/segment-tree.d.ts +18 -0
- package/dist/types/data-structures/binary-tree/tree-map.d.ts +375 -0
- package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +389 -0
- package/dist/types/data-structures/binary-tree/tree-multi-set.d.ts +330 -0
- package/dist/types/data-structures/binary-tree/tree-set.d.ts +438 -0
- package/dist/types/data-structures/graph/directed-graph.d.ts +30 -0
- package/dist/types/data-structures/graph/undirected-graph.d.ts +27 -0
- package/dist/types/data-structures/hash/hash-map.d.ts +33 -0
- package/dist/types/data-structures/heap/heap.d.ts +42 -0
- package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +75 -2
- package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +45 -0
- package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +54 -0
- package/dist/types/data-structures/matrix/matrix.d.ts +24 -0
- package/dist/types/data-structures/queue/deque.d.ts +90 -1
- package/dist/types/data-structures/queue/queue.d.ts +36 -0
- package/dist/types/data-structures/stack/stack.d.ts +30 -0
- package/dist/types/data-structures/trie/trie.d.ts +36 -0
- package/dist/umd/deque-typed.js +140 -1
- package/dist/umd/deque-typed.js.map +1 -1
- package/dist/umd/deque-typed.min.js +1 -1
- package/dist/umd/deque-typed.min.js.map +1 -1
- package/package.json +2 -2
- package/src/data-structures/base/iterable-element-base.ts +32 -0
- package/src/data-structures/base/linear-base.ts +11 -0
- package/src/data-structures/binary-tree/avl-tree.ts +36 -0
- package/src/data-structures/binary-tree/binary-indexed-tree.ts +42 -0
- package/src/data-structures/binary-tree/binary-tree.ts +75 -0
- package/src/data-structures/binary-tree/bst.ts +72 -0
- package/src/data-structures/binary-tree/red-black-tree.ts +57 -0
- package/src/data-structures/binary-tree/segment-tree.ts +18 -0
- package/src/data-structures/binary-tree/tree-map.ts +375 -0
- package/src/data-structures/binary-tree/tree-multi-map.ts +392 -0
- package/src/data-structures/binary-tree/tree-multi-set.ts +336 -0
- package/src/data-structures/binary-tree/tree-set.ts +492 -0
- package/src/data-structures/graph/directed-graph.ts +30 -0
- package/src/data-structures/graph/undirected-graph.ts +27 -0
- package/src/data-structures/hash/hash-map.ts +33 -0
- package/src/data-structures/heap/heap.ts +42 -0
- package/src/data-structures/linked-list/doubly-linked-list.ts +90 -2
- package/src/data-structures/linked-list/singly-linked-list.ts +45 -0
- package/src/data-structures/linked-list/skip-linked-list.ts +54 -0
- package/src/data-structures/matrix/matrix.ts +24 -0
- package/src/data-structures/queue/deque.ts +103 -1
- package/src/data-structures/queue/queue.ts +36 -0
- package/src/data-structures/stack/stack.ts +30 -0
- package/src/data-structures/trie/trie.ts +36 -0
|
@@ -216,6 +216,35 @@ var _IterableElementBase = class _IterableElementBase {
|
|
|
216
216
|
for (const ele of this) if (ele === element) return true;
|
|
217
217
|
return false;
|
|
218
218
|
}
|
|
219
|
+
/**
|
|
220
|
+
* Check whether a value exists (Array-compatible alias for `has`).
|
|
221
|
+
* @remarks Provided for familiarity when migrating from Array. Time O(n), Space O(1).
|
|
222
|
+
* @param element - Element to search for (uses `===`).
|
|
223
|
+
* @returns `true` if found.
|
|
224
|
+
*/
|
|
225
|
+
includes(element) {
|
|
226
|
+
return this.has(element);
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* Return an iterator of `[index, value]` pairs (Array-compatible).
|
|
230
|
+
* @remarks Provided for familiarity when migrating from Array. Time O(n), Space O(1) per step.
|
|
231
|
+
*/
|
|
232
|
+
*entries() {
|
|
233
|
+
let index = 0;
|
|
234
|
+
for (const value of this) {
|
|
235
|
+
yield [index++, value];
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* Return an iterator of numeric indices (Array-compatible).
|
|
240
|
+
* @remarks Provided for familiarity when migrating from Array. Time O(n), Space O(1) per step.
|
|
241
|
+
*/
|
|
242
|
+
*keys() {
|
|
243
|
+
let index = 0;
|
|
244
|
+
for (const _ of this) {
|
|
245
|
+
yield index++;
|
|
246
|
+
}
|
|
247
|
+
}
|
|
219
248
|
/**
|
|
220
249
|
* Reduces all elements to a single accumulated value.
|
|
221
250
|
*
|
|
@@ -477,6 +506,16 @@ var _LinearBase = class _LinearBase extends IterableElementBase {
|
|
|
477
506
|
}
|
|
478
507
|
return this;
|
|
479
508
|
}
|
|
509
|
+
/**
|
|
510
|
+
* Return a new instance of the same type with elements in reverse order (non-mutating).
|
|
511
|
+
* @remarks Provided for familiarity when migrating from Array (ES2023 `toReversed`). Time O(n), Space O(n).
|
|
512
|
+
* @returns A new reversed instance.
|
|
513
|
+
*/
|
|
514
|
+
toReversed() {
|
|
515
|
+
const cloned = this.clone();
|
|
516
|
+
cloned.reverse();
|
|
517
|
+
return cloned;
|
|
518
|
+
}
|
|
480
519
|
};
|
|
481
520
|
__name(_LinearBase, "LinearBase");
|
|
482
521
|
var LinearBase = _LinearBase;
|
|
@@ -669,7 +708,10 @@ var _Deque = class _Deque extends LinearBase {
|
|
|
669
708
|
}
|
|
670
709
|
/**
|
|
671
710
|
* Deque peek at both ends
|
|
672
|
-
|
|
711
|
+
|
|
712
|
+
|
|
713
|
+
|
|
714
|
+
* @example
|
|
673
715
|
* // Deque peek at both ends
|
|
674
716
|
* const deque = new Deque<number>([10, 20, 30, 40, 50]);
|
|
675
717
|
*
|
|
@@ -727,6 +769,9 @@ var _Deque = class _Deque extends LinearBase {
|
|
|
727
769
|
|
|
728
770
|
|
|
729
771
|
|
|
772
|
+
|
|
773
|
+
|
|
774
|
+
|
|
730
775
|
|
|
731
776
|
|
|
732
777
|
|
|
@@ -794,6 +839,9 @@ var _Deque = class _Deque extends LinearBase {
|
|
|
794
839
|
|
|
795
840
|
|
|
796
841
|
|
|
842
|
+
|
|
843
|
+
|
|
844
|
+
|
|
797
845
|
|
|
798
846
|
|
|
799
847
|
|
|
@@ -874,6 +922,9 @@ var _Deque = class _Deque extends LinearBase {
|
|
|
874
922
|
|
|
875
923
|
|
|
876
924
|
|
|
925
|
+
|
|
926
|
+
|
|
927
|
+
|
|
877
928
|
|
|
878
929
|
|
|
879
930
|
|
|
@@ -941,6 +992,9 @@ var _Deque = class _Deque extends LinearBase {
|
|
|
941
992
|
|
|
942
993
|
|
|
943
994
|
|
|
995
|
+
|
|
996
|
+
|
|
997
|
+
|
|
944
998
|
|
|
945
999
|
|
|
946
1000
|
|
|
@@ -1009,6 +1063,9 @@ var _Deque = class _Deque extends LinearBase {
|
|
|
1009
1063
|
|
|
1010
1064
|
|
|
1011
1065
|
|
|
1066
|
+
|
|
1067
|
+
|
|
1068
|
+
|
|
1012
1069
|
|
|
1013
1070
|
|
|
1014
1071
|
|
|
@@ -1118,6 +1175,9 @@ var _Deque = class _Deque extends LinearBase {
|
|
|
1118
1175
|
|
|
1119
1176
|
|
|
1120
1177
|
|
|
1178
|
+
|
|
1179
|
+
|
|
1180
|
+
|
|
1121
1181
|
|
|
1122
1182
|
|
|
1123
1183
|
|
|
@@ -1167,6 +1227,9 @@ var _Deque = class _Deque extends LinearBase {
|
|
|
1167
1227
|
|
|
1168
1228
|
|
|
1169
1229
|
|
|
1230
|
+
|
|
1231
|
+
|
|
1232
|
+
|
|
1170
1233
|
|
|
1171
1234
|
|
|
1172
1235
|
|
|
@@ -1220,6 +1283,9 @@ var _Deque = class _Deque extends LinearBase {
|
|
|
1220
1283
|
|
|
1221
1284
|
|
|
1222
1285
|
|
|
1286
|
+
|
|
1287
|
+
|
|
1288
|
+
|
|
1223
1289
|
|
|
1224
1290
|
|
|
1225
1291
|
|
|
@@ -1424,6 +1490,9 @@ var _Deque = class _Deque extends LinearBase {
|
|
|
1424
1490
|
|
|
1425
1491
|
|
|
1426
1492
|
|
|
1493
|
+
|
|
1494
|
+
|
|
1495
|
+
|
|
1427
1496
|
|
|
1428
1497
|
|
|
1429
1498
|
|
|
@@ -1518,6 +1587,64 @@ var _Deque = class _Deque extends LinearBase {
|
|
|
1518
1587
|
|
|
1519
1588
|
|
|
1520
1589
|
|
|
1590
|
+
|
|
1591
|
+
* @example
|
|
1592
|
+
* // Deque for...of iteration and reverse
|
|
1593
|
+
* const deque = new Deque<string>(['A', 'B', 'C', 'D']);
|
|
1594
|
+
*
|
|
1595
|
+
* // Iterate forward
|
|
1596
|
+
* const forward: string[] = [];
|
|
1597
|
+
* for (const item of deque) {
|
|
1598
|
+
* forward.push(item);
|
|
1599
|
+
* }
|
|
1600
|
+
* console.log(forward); // ['A', 'B', 'C', 'D'];
|
|
1601
|
+
*
|
|
1602
|
+
* // Reverse the deque
|
|
1603
|
+
* deque.reverse();
|
|
1604
|
+
* const backward: string[] = [];
|
|
1605
|
+
* for (const item of deque) {
|
|
1606
|
+
* backward.push(item);
|
|
1607
|
+
* }
|
|
1608
|
+
* console.log(backward); // ['D', 'C', 'B', 'A'];
|
|
1609
|
+
*/
|
|
1610
|
+
/**
|
|
1611
|
+
* Find the last value matching a predicate (scans back-to-front).
|
|
1612
|
+
* @remarks Provided for familiarity when migrating from Array. Time O(n), Space O(1).
|
|
1613
|
+
* @param predicate - Function called with (value, index, deque).
|
|
1614
|
+
* @returns Matching value or undefined.
|
|
1615
|
+
* @example
|
|
1616
|
+
* // Find last matching value
|
|
1617
|
+
* const d = new Deque([1, 2, 3, 4, 5]);
|
|
1618
|
+
* console.log(d.findLast(v => v > 2)); // 5;
|
|
1619
|
+
* console.log(d.findLast(v => v % 2 === 0)); // 4;
|
|
1620
|
+
*/
|
|
1621
|
+
findLast(predicate) {
|
|
1622
|
+
for (let i = this.length - 1; i >= 0; i--) {
|
|
1623
|
+
const val = this.at(i);
|
|
1624
|
+
if (predicate(val, i, this)) return val;
|
|
1625
|
+
}
|
|
1626
|
+
return void 0;
|
|
1627
|
+
}
|
|
1628
|
+
/**
|
|
1629
|
+
* Find the index of the last value matching a predicate (scans back-to-front).
|
|
1630
|
+
* @remarks Provided for familiarity when migrating from Array. Time O(n), Space O(1).
|
|
1631
|
+
* @param predicate - Function called with (value, index, deque).
|
|
1632
|
+
* @returns Matching index, or -1 if not found.
|
|
1633
|
+
* @example
|
|
1634
|
+
* // Find last matching index
|
|
1635
|
+
* const d = new Deque([10, 20, 30, 20, 10]);
|
|
1636
|
+
* console.log(d.findLastIndex(v => v === 20)); // 3;
|
|
1637
|
+
* console.log(d.findLastIndex(v => v === 10)); // 4;
|
|
1638
|
+
*/
|
|
1639
|
+
findLastIndex(predicate) {
|
|
1640
|
+
for (let i = this.length - 1; i >= 0; i--) {
|
|
1641
|
+
if (predicate(this.at(i), i, this)) return i;
|
|
1642
|
+
}
|
|
1643
|
+
return -1;
|
|
1644
|
+
}
|
|
1645
|
+
/**
|
|
1646
|
+
* Deque for...of iteration and reverse
|
|
1647
|
+
|
|
1521
1648
|
|
|
1522
1649
|
* @example
|
|
1523
1650
|
* // Deque for...of iteration and reverse
|
|
@@ -1631,6 +1758,9 @@ var _Deque = class _Deque extends LinearBase {
|
|
|
1631
1758
|
|
|
1632
1759
|
|
|
1633
1760
|
|
|
1761
|
+
|
|
1762
|
+
|
|
1763
|
+
|
|
1634
1764
|
|
|
1635
1765
|
|
|
1636
1766
|
|
|
@@ -1706,6 +1836,9 @@ var _Deque = class _Deque extends LinearBase {
|
|
|
1706
1836
|
|
|
1707
1837
|
|
|
1708
1838
|
|
|
1839
|
+
|
|
1840
|
+
|
|
1841
|
+
|
|
1709
1842
|
|
|
1710
1843
|
|
|
1711
1844
|
|
|
@@ -1764,6 +1897,9 @@ var _Deque = class _Deque extends LinearBase {
|
|
|
1764
1897
|
|
|
1765
1898
|
|
|
1766
1899
|
|
|
1900
|
+
|
|
1901
|
+
|
|
1902
|
+
|
|
1767
1903
|
|
|
1768
1904
|
|
|
1769
1905
|
|
|
@@ -1842,6 +1978,9 @@ var _Deque = class _Deque extends LinearBase {
|
|
|
1842
1978
|
|
|
1843
1979
|
|
|
1844
1980
|
|
|
1981
|
+
|
|
1982
|
+
|
|
1983
|
+
|
|
1845
1984
|
|
|
1846
1985
|
|
|
1847
1986
|
|