deque-typed 2.5.2 → 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 +223 -0
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs-legacy/index.cjs +223 -0
- package/dist/cjs-legacy/index.cjs.map +1 -1
- package/dist/esm/index.mjs +223 -0
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm-legacy/index.mjs +223 -0
- 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 +86 -2
- package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +98 -0
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +191 -15
- package/dist/types/data-structures/binary-tree/bst.d.ts +171 -3
- package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +136 -8
- package/dist/types/data-structures/binary-tree/segment-tree.d.ts +42 -0
- package/dist/types/data-structures/binary-tree/tree-map.d.ts +1061 -167
- package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +1232 -355
- package/dist/types/data-structures/binary-tree/tree-multi-set.d.ts +916 -194
- package/dist/types/data-structures/binary-tree/tree-set.d.ts +1078 -141
- package/dist/types/data-structures/graph/directed-graph.d.ts +70 -0
- package/dist/types/data-structures/graph/undirected-graph.d.ts +63 -0
- package/dist/types/data-structures/hash/hash-map.d.ts +84 -6
- package/dist/types/data-structures/heap/heap.d.ts +140 -12
- package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +150 -2
- package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +106 -1
- package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +126 -0
- package/dist/types/data-structures/matrix/matrix.d.ts +56 -0
- package/dist/types/data-structures/queue/deque.d.ts +171 -0
- package/dist/types/data-structures/queue/queue.d.ts +97 -0
- package/dist/types/data-structures/stack/stack.d.ts +72 -2
- package/dist/types/data-structures/trie/trie.d.ts +84 -0
- package/dist/types/interfaces/binary-tree.d.ts +2 -3
- package/dist/umd/deque-typed.js +223 -0
- 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 +88 -5
- package/src/data-structures/binary-tree/binary-indexed-tree.ts +98 -0
- package/src/data-structures/binary-tree/binary-tree.ts +242 -81
- package/src/data-structures/binary-tree/bst.ts +173 -7
- package/src/data-structures/binary-tree/red-black-tree.ts +139 -15
- package/src/data-structures/binary-tree/segment-tree.ts +42 -0
- package/src/data-structures/binary-tree/tree-map.ts +948 -36
- package/src/data-structures/binary-tree/tree-multi-map.ts +893 -13
- package/src/data-structures/binary-tree/tree-multi-set.ts +761 -33
- package/src/data-structures/binary-tree/tree-set.ts +1260 -251
- package/src/data-structures/graph/directed-graph.ts +71 -1
- package/src/data-structures/graph/undirected-graph.ts +64 -1
- package/src/data-structures/hash/hash-map.ts +100 -12
- package/src/data-structures/heap/heap.ts +149 -19
- package/src/data-structures/linked-list/doubly-linked-list.ts +178 -2
- package/src/data-structures/linked-list/singly-linked-list.ts +106 -1
- package/src/data-structures/linked-list/skip-linked-list.ts +126 -0
- package/src/data-structures/matrix/matrix.ts +56 -0
- package/src/data-structures/queue/deque.ts +187 -0
- package/src/data-structures/queue/queue.ts +109 -0
- package/src/data-structures/stack/stack.ts +75 -5
- package/src/data-structures/trie/trie.ts +84 -0
- package/src/interfaces/binary-tree.ts +1 -9
|
@@ -214,6 +214,35 @@ var _IterableElementBase = class _IterableElementBase {
|
|
|
214
214
|
for (const ele of this) if (ele === element) return true;
|
|
215
215
|
return false;
|
|
216
216
|
}
|
|
217
|
+
/**
|
|
218
|
+
* Check whether a value exists (Array-compatible alias for `has`).
|
|
219
|
+
* @remarks Provided for familiarity when migrating from Array. Time O(n), Space O(1).
|
|
220
|
+
* @param element - Element to search for (uses `===`).
|
|
221
|
+
* @returns `true` if found.
|
|
222
|
+
*/
|
|
223
|
+
includes(element) {
|
|
224
|
+
return this.has(element);
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* Return an iterator of `[index, value]` pairs (Array-compatible).
|
|
228
|
+
* @remarks Provided for familiarity when migrating from Array. Time O(n), Space O(1) per step.
|
|
229
|
+
*/
|
|
230
|
+
*entries() {
|
|
231
|
+
let index = 0;
|
|
232
|
+
for (const value of this) {
|
|
233
|
+
yield [index++, value];
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* Return an iterator of numeric indices (Array-compatible).
|
|
238
|
+
* @remarks Provided for familiarity when migrating from Array. Time O(n), Space O(1) per step.
|
|
239
|
+
*/
|
|
240
|
+
*keys() {
|
|
241
|
+
let index = 0;
|
|
242
|
+
for (const _ of this) {
|
|
243
|
+
yield index++;
|
|
244
|
+
}
|
|
245
|
+
}
|
|
217
246
|
/**
|
|
218
247
|
* Reduces all elements to a single accumulated value.
|
|
219
248
|
*
|
|
@@ -475,6 +504,16 @@ var _LinearBase = class _LinearBase extends IterableElementBase {
|
|
|
475
504
|
}
|
|
476
505
|
return this;
|
|
477
506
|
}
|
|
507
|
+
/**
|
|
508
|
+
* Return a new instance of the same type with elements in reverse order (non-mutating).
|
|
509
|
+
* @remarks Provided for familiarity when migrating from Array (ES2023 `toReversed`). Time O(n), Space O(n).
|
|
510
|
+
* @returns A new reversed instance.
|
|
511
|
+
*/
|
|
512
|
+
toReversed() {
|
|
513
|
+
const cloned = this.clone();
|
|
514
|
+
cloned.reverse();
|
|
515
|
+
return cloned;
|
|
516
|
+
}
|
|
478
517
|
};
|
|
479
518
|
__name(_LinearBase, "LinearBase");
|
|
480
519
|
var LinearBase = _LinearBase;
|
|
@@ -635,8 +674,39 @@ var _Deque = class _Deque extends LinearBase {
|
|
|
635
674
|
|
|
636
675
|
|
|
637
676
|
|
|
677
|
+
|
|
678
|
+
|
|
679
|
+
|
|
638
680
|
|
|
639
681
|
|
|
682
|
+
|
|
683
|
+
|
|
684
|
+
* @example
|
|
685
|
+
* // Deque peek at both ends
|
|
686
|
+
* const deque = new Deque<number>([10, 20, 30, 40, 50]);
|
|
687
|
+
*
|
|
688
|
+
* // Get first element without removing
|
|
689
|
+
* const first = deque.at(0);
|
|
690
|
+
* console.log(first); // 10;
|
|
691
|
+
*
|
|
692
|
+
* // Get last element without removing
|
|
693
|
+
* const last = deque.at(deque.length - 1);
|
|
694
|
+
* console.log(last); // 50;
|
|
695
|
+
*
|
|
696
|
+
* // Length unchanged
|
|
697
|
+
* console.log(deque.length); // 5;
|
|
698
|
+
*/
|
|
699
|
+
/**
|
|
700
|
+
* Peek at the front element without removing it (alias for `first`).
|
|
701
|
+
* @remarks Time O(1), Space O(1)
|
|
702
|
+
* @returns Front element or undefined.
|
|
703
|
+
*/
|
|
704
|
+
peek() {
|
|
705
|
+
return this.first;
|
|
706
|
+
}
|
|
707
|
+
/**
|
|
708
|
+
* Deque peek at both ends
|
|
709
|
+
|
|
640
710
|
|
|
641
711
|
|
|
642
712
|
* @example
|
|
@@ -689,6 +759,13 @@ var _Deque = class _Deque extends LinearBase {
|
|
|
689
759
|
|
|
690
760
|
|
|
691
761
|
|
|
762
|
+
|
|
763
|
+
|
|
764
|
+
|
|
765
|
+
|
|
766
|
+
|
|
767
|
+
|
|
768
|
+
|
|
692
769
|
|
|
693
770
|
|
|
694
771
|
|
|
@@ -752,6 +829,13 @@ var _Deque = class _Deque extends LinearBase {
|
|
|
752
829
|
|
|
753
830
|
|
|
754
831
|
|
|
832
|
+
|
|
833
|
+
|
|
834
|
+
|
|
835
|
+
|
|
836
|
+
|
|
837
|
+
|
|
838
|
+
|
|
755
839
|
|
|
756
840
|
|
|
757
841
|
|
|
@@ -828,6 +912,13 @@ var _Deque = class _Deque extends LinearBase {
|
|
|
828
912
|
|
|
829
913
|
|
|
830
914
|
|
|
915
|
+
|
|
916
|
+
|
|
917
|
+
|
|
918
|
+
|
|
919
|
+
|
|
920
|
+
|
|
921
|
+
|
|
831
922
|
|
|
832
923
|
|
|
833
924
|
|
|
@@ -891,6 +982,13 @@ var _Deque = class _Deque extends LinearBase {
|
|
|
891
982
|
|
|
892
983
|
|
|
893
984
|
|
|
985
|
+
|
|
986
|
+
|
|
987
|
+
|
|
988
|
+
|
|
989
|
+
|
|
990
|
+
|
|
991
|
+
|
|
894
992
|
|
|
895
993
|
|
|
896
994
|
|
|
@@ -955,6 +1053,13 @@ var _Deque = class _Deque extends LinearBase {
|
|
|
955
1053
|
|
|
956
1054
|
|
|
957
1055
|
|
|
1056
|
+
|
|
1057
|
+
|
|
1058
|
+
|
|
1059
|
+
|
|
1060
|
+
|
|
1061
|
+
|
|
1062
|
+
|
|
958
1063
|
|
|
959
1064
|
|
|
960
1065
|
|
|
@@ -1060,6 +1165,13 @@ var _Deque = class _Deque extends LinearBase {
|
|
|
1060
1165
|
|
|
1061
1166
|
|
|
1062
1167
|
|
|
1168
|
+
|
|
1169
|
+
|
|
1170
|
+
|
|
1171
|
+
|
|
1172
|
+
|
|
1173
|
+
|
|
1174
|
+
|
|
1063
1175
|
|
|
1064
1176
|
|
|
1065
1177
|
|
|
@@ -1105,6 +1217,13 @@ var _Deque = class _Deque extends LinearBase {
|
|
|
1105
1217
|
|
|
1106
1218
|
|
|
1107
1219
|
|
|
1220
|
+
|
|
1221
|
+
|
|
1222
|
+
|
|
1223
|
+
|
|
1224
|
+
|
|
1225
|
+
|
|
1226
|
+
|
|
1108
1227
|
|
|
1109
1228
|
|
|
1110
1229
|
|
|
@@ -1154,6 +1273,13 @@ var _Deque = class _Deque extends LinearBase {
|
|
|
1154
1273
|
|
|
1155
1274
|
|
|
1156
1275
|
|
|
1276
|
+
|
|
1277
|
+
|
|
1278
|
+
|
|
1279
|
+
|
|
1280
|
+
|
|
1281
|
+
|
|
1282
|
+
|
|
1157
1283
|
|
|
1158
1284
|
|
|
1159
1285
|
|
|
@@ -1354,6 +1480,13 @@ var _Deque = class _Deque extends LinearBase {
|
|
|
1354
1480
|
|
|
1355
1481
|
|
|
1356
1482
|
|
|
1483
|
+
|
|
1484
|
+
|
|
1485
|
+
|
|
1486
|
+
|
|
1487
|
+
|
|
1488
|
+
|
|
1489
|
+
|
|
1357
1490
|
|
|
1358
1491
|
|
|
1359
1492
|
|
|
@@ -1444,10 +1577,72 @@ var _Deque = class _Deque extends LinearBase {
|
|
|
1444
1577
|
|
|
1445
1578
|
|
|
1446
1579
|
|
|
1580
|
+
|
|
1581
|
+
|
|
1582
|
+
|
|
1583
|
+
|
|
1447
1584
|
|
|
1448
1585
|
|
|
1449
1586
|
|
|
1450
1587
|
|
|
1588
|
+
|
|
1589
|
+
* @example
|
|
1590
|
+
* // Deque for...of iteration and reverse
|
|
1591
|
+
* const deque = new Deque<string>(['A', 'B', 'C', 'D']);
|
|
1592
|
+
*
|
|
1593
|
+
* // Iterate forward
|
|
1594
|
+
* const forward: string[] = [];
|
|
1595
|
+
* for (const item of deque) {
|
|
1596
|
+
* forward.push(item);
|
|
1597
|
+
* }
|
|
1598
|
+
* console.log(forward); // ['A', 'B', 'C', 'D'];
|
|
1599
|
+
*
|
|
1600
|
+
* // Reverse the deque
|
|
1601
|
+
* deque.reverse();
|
|
1602
|
+
* const backward: string[] = [];
|
|
1603
|
+
* for (const item of deque) {
|
|
1604
|
+
* backward.push(item);
|
|
1605
|
+
* }
|
|
1606
|
+
* console.log(backward); // ['D', 'C', 'B', 'A'];
|
|
1607
|
+
*/
|
|
1608
|
+
/**
|
|
1609
|
+
* Find the last value matching a predicate (scans back-to-front).
|
|
1610
|
+
* @remarks Provided for familiarity when migrating from Array. Time O(n), Space O(1).
|
|
1611
|
+
* @param predicate - Function called with (value, index, deque).
|
|
1612
|
+
* @returns Matching value or undefined.
|
|
1613
|
+
* @example
|
|
1614
|
+
* // Find last matching value
|
|
1615
|
+
* const d = new Deque([1, 2, 3, 4, 5]);
|
|
1616
|
+
* console.log(d.findLast(v => v > 2)); // 5;
|
|
1617
|
+
* console.log(d.findLast(v => v % 2 === 0)); // 4;
|
|
1618
|
+
*/
|
|
1619
|
+
findLast(predicate) {
|
|
1620
|
+
for (let i = this.length - 1; i >= 0; i--) {
|
|
1621
|
+
const val = this.at(i);
|
|
1622
|
+
if (predicate(val, i, this)) return val;
|
|
1623
|
+
}
|
|
1624
|
+
return void 0;
|
|
1625
|
+
}
|
|
1626
|
+
/**
|
|
1627
|
+
* Find the index of the last value matching a predicate (scans back-to-front).
|
|
1628
|
+
* @remarks Provided for familiarity when migrating from Array. Time O(n), Space O(1).
|
|
1629
|
+
* @param predicate - Function called with (value, index, deque).
|
|
1630
|
+
* @returns Matching index, or -1 if not found.
|
|
1631
|
+
* @example
|
|
1632
|
+
* // Find last matching index
|
|
1633
|
+
* const d = new Deque([10, 20, 30, 20, 10]);
|
|
1634
|
+
* console.log(d.findLastIndex(v => v === 20)); // 3;
|
|
1635
|
+
* console.log(d.findLastIndex(v => v === 10)); // 4;
|
|
1636
|
+
*/
|
|
1637
|
+
findLastIndex(predicate) {
|
|
1638
|
+
for (let i = this.length - 1; i >= 0; i--) {
|
|
1639
|
+
if (predicate(this.at(i), i, this)) return i;
|
|
1640
|
+
}
|
|
1641
|
+
return -1;
|
|
1642
|
+
}
|
|
1643
|
+
/**
|
|
1644
|
+
* Deque for...of iteration and reverse
|
|
1645
|
+
|
|
1451
1646
|
|
|
1452
1647
|
* @example
|
|
1453
1648
|
* // Deque for...of iteration and reverse
|
|
@@ -1553,6 +1748,13 @@ var _Deque = class _Deque extends LinearBase {
|
|
|
1553
1748
|
|
|
1554
1749
|
|
|
1555
1750
|
|
|
1751
|
+
|
|
1752
|
+
|
|
1753
|
+
|
|
1754
|
+
|
|
1755
|
+
|
|
1756
|
+
|
|
1757
|
+
|
|
1556
1758
|
|
|
1557
1759
|
|
|
1558
1760
|
|
|
@@ -1624,6 +1826,13 @@ var _Deque = class _Deque extends LinearBase {
|
|
|
1624
1826
|
|
|
1625
1827
|
|
|
1626
1828
|
|
|
1829
|
+
|
|
1830
|
+
|
|
1831
|
+
|
|
1832
|
+
|
|
1833
|
+
|
|
1834
|
+
|
|
1835
|
+
|
|
1627
1836
|
|
|
1628
1837
|
|
|
1629
1838
|
|
|
@@ -1678,6 +1887,13 @@ var _Deque = class _Deque extends LinearBase {
|
|
|
1678
1887
|
|
|
1679
1888
|
|
|
1680
1889
|
|
|
1890
|
+
|
|
1891
|
+
|
|
1892
|
+
|
|
1893
|
+
|
|
1894
|
+
|
|
1895
|
+
|
|
1896
|
+
|
|
1681
1897
|
|
|
1682
1898
|
|
|
1683
1899
|
|
|
@@ -1752,6 +1968,13 @@ var _Deque = class _Deque extends LinearBase {
|
|
|
1752
1968
|
|
|
1753
1969
|
|
|
1754
1970
|
|
|
1971
|
+
|
|
1972
|
+
|
|
1973
|
+
|
|
1974
|
+
|
|
1975
|
+
|
|
1976
|
+
|
|
1977
|
+
|
|
1755
1978
|
|
|
1756
1979
|
|
|
1757
1980
|
|