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.
Files changed (61) hide show
  1. package/dist/cjs/index.cjs +140 -1
  2. package/dist/cjs/index.cjs.map +1 -1
  3. package/dist/cjs-legacy/index.cjs +140 -1
  4. package/dist/cjs-legacy/index.cjs.map +1 -1
  5. package/dist/esm/index.mjs +140 -1
  6. package/dist/esm/index.mjs.map +1 -1
  7. package/dist/esm-legacy/index.mjs +140 -1
  8. package/dist/esm-legacy/index.mjs.map +1 -1
  9. package/dist/types/data-structures/base/iterable-element-base.d.ts +17 -0
  10. package/dist/types/data-structures/base/linear-base.d.ts +6 -0
  11. package/dist/types/data-structures/binary-tree/avl-tree.d.ts +36 -0
  12. package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +42 -0
  13. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +75 -0
  14. package/dist/types/data-structures/binary-tree/bst.d.ts +72 -0
  15. package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +57 -0
  16. package/dist/types/data-structures/binary-tree/segment-tree.d.ts +18 -0
  17. package/dist/types/data-structures/binary-tree/tree-map.d.ts +375 -0
  18. package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +389 -0
  19. package/dist/types/data-structures/binary-tree/tree-multi-set.d.ts +330 -0
  20. package/dist/types/data-structures/binary-tree/tree-set.d.ts +438 -0
  21. package/dist/types/data-structures/graph/directed-graph.d.ts +30 -0
  22. package/dist/types/data-structures/graph/undirected-graph.d.ts +27 -0
  23. package/dist/types/data-structures/hash/hash-map.d.ts +33 -0
  24. package/dist/types/data-structures/heap/heap.d.ts +42 -0
  25. package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +75 -2
  26. package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +45 -0
  27. package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +54 -0
  28. package/dist/types/data-structures/matrix/matrix.d.ts +24 -0
  29. package/dist/types/data-structures/queue/deque.d.ts +90 -1
  30. package/dist/types/data-structures/queue/queue.d.ts +36 -0
  31. package/dist/types/data-structures/stack/stack.d.ts +30 -0
  32. package/dist/types/data-structures/trie/trie.d.ts +36 -0
  33. package/dist/umd/deque-typed.js +140 -1
  34. package/dist/umd/deque-typed.js.map +1 -1
  35. package/dist/umd/deque-typed.min.js +1 -1
  36. package/dist/umd/deque-typed.min.js.map +1 -1
  37. package/package.json +2 -2
  38. package/src/data-structures/base/iterable-element-base.ts +32 -0
  39. package/src/data-structures/base/linear-base.ts +11 -0
  40. package/src/data-structures/binary-tree/avl-tree.ts +36 -0
  41. package/src/data-structures/binary-tree/binary-indexed-tree.ts +42 -0
  42. package/src/data-structures/binary-tree/binary-tree.ts +75 -0
  43. package/src/data-structures/binary-tree/bst.ts +72 -0
  44. package/src/data-structures/binary-tree/red-black-tree.ts +57 -0
  45. package/src/data-structures/binary-tree/segment-tree.ts +18 -0
  46. package/src/data-structures/binary-tree/tree-map.ts +375 -0
  47. package/src/data-structures/binary-tree/tree-multi-map.ts +392 -0
  48. package/src/data-structures/binary-tree/tree-multi-set.ts +336 -0
  49. package/src/data-structures/binary-tree/tree-set.ts +492 -0
  50. package/src/data-structures/graph/directed-graph.ts +30 -0
  51. package/src/data-structures/graph/undirected-graph.ts +27 -0
  52. package/src/data-structures/hash/hash-map.ts +33 -0
  53. package/src/data-structures/heap/heap.ts +42 -0
  54. package/src/data-structures/linked-list/doubly-linked-list.ts +90 -2
  55. package/src/data-structures/linked-list/singly-linked-list.ts +45 -0
  56. package/src/data-structures/linked-list/skip-linked-list.ts +54 -0
  57. package/src/data-structures/matrix/matrix.ts +24 -0
  58. package/src/data-structures/queue/deque.ts +103 -1
  59. package/src/data-structures/queue/queue.ts +36 -0
  60. package/src/data-structures/stack/stack.ts +30 -0
  61. package/src/data-structures/trie/trie.ts +36 -0
@@ -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;
@@ -667,7 +706,10 @@ var _Deque = class _Deque extends LinearBase {
667
706
  }
668
707
  /**
669
708
  * Deque peek at both ends
670
- * @example
709
+
710
+
711
+
712
+ * @example
671
713
  * // Deque peek at both ends
672
714
  * const deque = new Deque<number>([10, 20, 30, 40, 50]);
673
715
  *
@@ -725,6 +767,9 @@ var _Deque = class _Deque extends LinearBase {
725
767
 
726
768
 
727
769
 
770
+
771
+
772
+
728
773
 
729
774
 
730
775
 
@@ -792,6 +837,9 @@ var _Deque = class _Deque extends LinearBase {
792
837
 
793
838
 
794
839
 
840
+
841
+
842
+
795
843
 
796
844
 
797
845
 
@@ -872,6 +920,9 @@ var _Deque = class _Deque extends LinearBase {
872
920
 
873
921
 
874
922
 
923
+
924
+
925
+
875
926
 
876
927
 
877
928
 
@@ -939,6 +990,9 @@ var _Deque = class _Deque extends LinearBase {
939
990
 
940
991
 
941
992
 
993
+
994
+
995
+
942
996
 
943
997
 
944
998
 
@@ -1007,6 +1061,9 @@ var _Deque = class _Deque extends LinearBase {
1007
1061
 
1008
1062
 
1009
1063
 
1064
+
1065
+
1066
+
1010
1067
 
1011
1068
 
1012
1069
 
@@ -1116,6 +1173,9 @@ var _Deque = class _Deque extends LinearBase {
1116
1173
 
1117
1174
 
1118
1175
 
1176
+
1177
+
1178
+
1119
1179
 
1120
1180
 
1121
1181
 
@@ -1165,6 +1225,9 @@ var _Deque = class _Deque extends LinearBase {
1165
1225
 
1166
1226
 
1167
1227
 
1228
+
1229
+
1230
+
1168
1231
 
1169
1232
 
1170
1233
 
@@ -1218,6 +1281,9 @@ var _Deque = class _Deque extends LinearBase {
1218
1281
 
1219
1282
 
1220
1283
 
1284
+
1285
+
1286
+
1221
1287
 
1222
1288
 
1223
1289
 
@@ -1422,6 +1488,9 @@ var _Deque = class _Deque extends LinearBase {
1422
1488
 
1423
1489
 
1424
1490
 
1491
+
1492
+
1493
+
1425
1494
 
1426
1495
 
1427
1496
 
@@ -1516,6 +1585,64 @@ var _Deque = class _Deque extends LinearBase {
1516
1585
 
1517
1586
 
1518
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
+
1519
1646
 
1520
1647
  * @example
1521
1648
  * // Deque for...of iteration and reverse
@@ -1629,6 +1756,9 @@ var _Deque = class _Deque extends LinearBase {
1629
1756
 
1630
1757
 
1631
1758
 
1759
+
1760
+
1761
+
1632
1762
 
1633
1763
 
1634
1764
 
@@ -1704,6 +1834,9 @@ var _Deque = class _Deque extends LinearBase {
1704
1834
 
1705
1835
 
1706
1836
 
1837
+
1838
+
1839
+
1707
1840
 
1708
1841
 
1709
1842
 
@@ -1762,6 +1895,9 @@ var _Deque = class _Deque extends LinearBase {
1762
1895
 
1763
1896
 
1764
1897
 
1898
+
1899
+
1900
+
1765
1901
 
1766
1902
 
1767
1903
 
@@ -1840,6 +1976,9 @@ var _Deque = class _Deque extends LinearBase {
1840
1976
 
1841
1977
 
1842
1978
 
1979
+
1980
+
1981
+
1843
1982
 
1844
1983
 
1845
1984