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
@@ -218,6 +218,35 @@ var IterableElementBase = class {
218
218
  for (const ele of this) if (ele === element) return true;
219
219
  return false;
220
220
  }
221
+ /**
222
+ * Check whether a value exists (Array-compatible alias for `has`).
223
+ * @remarks Provided for familiarity when migrating from Array. Time O(n), Space O(1).
224
+ * @param element - Element to search for (uses `===`).
225
+ * @returns `true` if found.
226
+ */
227
+ includes(element) {
228
+ return this.has(element);
229
+ }
230
+ /**
231
+ * Return an iterator of `[index, value]` pairs (Array-compatible).
232
+ * @remarks Provided for familiarity when migrating from Array. Time O(n), Space O(1) per step.
233
+ */
234
+ *entries() {
235
+ let index = 0;
236
+ for (const value of this) {
237
+ yield [index++, value];
238
+ }
239
+ }
240
+ /**
241
+ * Return an iterator of numeric indices (Array-compatible).
242
+ * @remarks Provided for familiarity when migrating from Array. Time O(n), Space O(1) per step.
243
+ */
244
+ *keys() {
245
+ let index = 0;
246
+ for (const _ of this) {
247
+ yield index++;
248
+ }
249
+ }
221
250
  /**
222
251
  * Reduces all elements to a single accumulated value.
223
252
  *
@@ -480,6 +509,16 @@ var LinearBase = class _LinearBase extends IterableElementBase {
480
509
  }
481
510
  return this;
482
511
  }
512
+ /**
513
+ * Return a new instance of the same type with elements in reverse order (non-mutating).
514
+ * @remarks Provided for familiarity when migrating from Array (ES2023 `toReversed`). Time O(n), Space O(n).
515
+ * @returns A new reversed instance.
516
+ */
517
+ toReversed() {
518
+ const cloned = this.clone();
519
+ cloned.reverse();
520
+ return cloned;
521
+ }
483
522
  };
484
523
 
485
524
  // src/data-structures/queue/deque.ts
@@ -673,7 +712,10 @@ var Deque = class extends LinearBase {
673
712
  }
674
713
  /**
675
714
  * Deque peek at both ends
676
- * @example
715
+
716
+
717
+
718
+ * @example
677
719
  * // Deque peek at both ends
678
720
  * const deque = new Deque<number>([10, 20, 30, 40, 50]);
679
721
  *
@@ -731,6 +773,9 @@ var Deque = class extends LinearBase {
731
773
 
732
774
 
733
775
 
776
+
777
+
778
+
734
779
 
735
780
 
736
781
 
@@ -798,6 +843,9 @@ var Deque = class extends LinearBase {
798
843
 
799
844
 
800
845
 
846
+
847
+
848
+
801
849
 
802
850
 
803
851
 
@@ -878,6 +926,9 @@ var Deque = class extends LinearBase {
878
926
 
879
927
 
880
928
 
929
+
930
+
931
+
881
932
 
882
933
 
883
934
 
@@ -945,6 +996,9 @@ var Deque = class extends LinearBase {
945
996
 
946
997
 
947
998
 
999
+
1000
+
1001
+
948
1002
 
949
1003
 
950
1004
 
@@ -1013,6 +1067,9 @@ var Deque = class extends LinearBase {
1013
1067
 
1014
1068
 
1015
1069
 
1070
+
1071
+
1072
+
1016
1073
 
1017
1074
 
1018
1075
 
@@ -1122,6 +1179,9 @@ var Deque = class extends LinearBase {
1122
1179
 
1123
1180
 
1124
1181
 
1182
+
1183
+
1184
+
1125
1185
 
1126
1186
 
1127
1187
 
@@ -1171,6 +1231,9 @@ var Deque = class extends LinearBase {
1171
1231
 
1172
1232
 
1173
1233
 
1234
+
1235
+
1236
+
1174
1237
 
1175
1238
 
1176
1239
 
@@ -1224,6 +1287,9 @@ var Deque = class extends LinearBase {
1224
1287
 
1225
1288
 
1226
1289
 
1290
+
1291
+
1292
+
1227
1293
 
1228
1294
 
1229
1295
 
@@ -1428,6 +1494,9 @@ var Deque = class extends LinearBase {
1428
1494
 
1429
1495
 
1430
1496
 
1497
+
1498
+
1499
+
1431
1500
 
1432
1501
 
1433
1502
 
@@ -1522,6 +1591,64 @@ var Deque = class extends LinearBase {
1522
1591
 
1523
1592
 
1524
1593
 
1594
+
1595
+ * @example
1596
+ * // Deque for...of iteration and reverse
1597
+ * const deque = new Deque<string>(['A', 'B', 'C', 'D']);
1598
+ *
1599
+ * // Iterate forward
1600
+ * const forward: string[] = [];
1601
+ * for (const item of deque) {
1602
+ * forward.push(item);
1603
+ * }
1604
+ * console.log(forward); // ['A', 'B', 'C', 'D'];
1605
+ *
1606
+ * // Reverse the deque
1607
+ * deque.reverse();
1608
+ * const backward: string[] = [];
1609
+ * for (const item of deque) {
1610
+ * backward.push(item);
1611
+ * }
1612
+ * console.log(backward); // ['D', 'C', 'B', 'A'];
1613
+ */
1614
+ /**
1615
+ * Find the last value matching a predicate (scans back-to-front).
1616
+ * @remarks Provided for familiarity when migrating from Array. Time O(n), Space O(1).
1617
+ * @param predicate - Function called with (value, index, deque).
1618
+ * @returns Matching value or undefined.
1619
+ * @example
1620
+ * // Find last matching value
1621
+ * const d = new Deque([1, 2, 3, 4, 5]);
1622
+ * console.log(d.findLast(v => v > 2)); // 5;
1623
+ * console.log(d.findLast(v => v % 2 === 0)); // 4;
1624
+ */
1625
+ findLast(predicate) {
1626
+ for (let i = this.length - 1; i >= 0; i--) {
1627
+ const val = this.at(i);
1628
+ if (predicate(val, i, this)) return val;
1629
+ }
1630
+ return void 0;
1631
+ }
1632
+ /**
1633
+ * Find the index of the last value matching a predicate (scans back-to-front).
1634
+ * @remarks Provided for familiarity when migrating from Array. Time O(n), Space O(1).
1635
+ * @param predicate - Function called with (value, index, deque).
1636
+ * @returns Matching index, or -1 if not found.
1637
+ * @example
1638
+ * // Find last matching index
1639
+ * const d = new Deque([10, 20, 30, 20, 10]);
1640
+ * console.log(d.findLastIndex(v => v === 20)); // 3;
1641
+ * console.log(d.findLastIndex(v => v === 10)); // 4;
1642
+ */
1643
+ findLastIndex(predicate) {
1644
+ for (let i = this.length - 1; i >= 0; i--) {
1645
+ if (predicate(this.at(i), i, this)) return i;
1646
+ }
1647
+ return -1;
1648
+ }
1649
+ /**
1650
+ * Deque for...of iteration and reverse
1651
+
1525
1652
 
1526
1653
  * @example
1527
1654
  * // Deque for...of iteration and reverse
@@ -1635,6 +1762,9 @@ var Deque = class extends LinearBase {
1635
1762
 
1636
1763
 
1637
1764
 
1765
+
1766
+
1767
+
1638
1768
 
1639
1769
 
1640
1770
 
@@ -1710,6 +1840,9 @@ var Deque = class extends LinearBase {
1710
1840
 
1711
1841
 
1712
1842
 
1843
+
1844
+
1845
+
1713
1846
 
1714
1847
 
1715
1848
 
@@ -1768,6 +1901,9 @@ var Deque = class extends LinearBase {
1768
1901
 
1769
1902
 
1770
1903
 
1904
+
1905
+
1906
+
1771
1907
 
1772
1908
 
1773
1909
 
@@ -1846,6 +1982,9 @@ var Deque = class extends LinearBase {
1846
1982
 
1847
1983
 
1848
1984
 
1985
+
1986
+
1987
+
1849
1988
 
1850
1989
 
1851
1990