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
@@ -216,6 +216,35 @@ var IterableElementBase = class {
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
  *
@@ -478,6 +507,16 @@ var LinearBase = class _LinearBase extends IterableElementBase {
478
507
  }
479
508
  return this;
480
509
  }
510
+ /**
511
+ * Return a new instance of the same type with elements in reverse order (non-mutating).
512
+ * @remarks Provided for familiarity when migrating from Array (ES2023 `toReversed`). Time O(n), Space O(n).
513
+ * @returns A new reversed instance.
514
+ */
515
+ toReversed() {
516
+ const cloned = this.clone();
517
+ cloned.reverse();
518
+ return cloned;
519
+ }
481
520
  };
482
521
 
483
522
  // src/data-structures/queue/deque.ts
@@ -671,7 +710,10 @@ var Deque = class extends LinearBase {
671
710
  }
672
711
  /**
673
712
  * Deque peek at both ends
674
- * @example
713
+
714
+
715
+
716
+ * @example
675
717
  * // Deque peek at both ends
676
718
  * const deque = new Deque<number>([10, 20, 30, 40, 50]);
677
719
  *
@@ -729,6 +771,9 @@ var Deque = class extends LinearBase {
729
771
 
730
772
 
731
773
 
774
+
775
+
776
+
732
777
 
733
778
 
734
779
 
@@ -796,6 +841,9 @@ var Deque = class extends LinearBase {
796
841
 
797
842
 
798
843
 
844
+
845
+
846
+
799
847
 
800
848
 
801
849
 
@@ -876,6 +924,9 @@ var Deque = class extends LinearBase {
876
924
 
877
925
 
878
926
 
927
+
928
+
929
+
879
930
 
880
931
 
881
932
 
@@ -943,6 +994,9 @@ var Deque = class extends LinearBase {
943
994
 
944
995
 
945
996
 
997
+
998
+
999
+
946
1000
 
947
1001
 
948
1002
 
@@ -1011,6 +1065,9 @@ var Deque = class extends LinearBase {
1011
1065
 
1012
1066
 
1013
1067
 
1068
+
1069
+
1070
+
1014
1071
 
1015
1072
 
1016
1073
 
@@ -1120,6 +1177,9 @@ var Deque = class extends LinearBase {
1120
1177
 
1121
1178
 
1122
1179
 
1180
+
1181
+
1182
+
1123
1183
 
1124
1184
 
1125
1185
 
@@ -1169,6 +1229,9 @@ var Deque = class extends LinearBase {
1169
1229
 
1170
1230
 
1171
1231
 
1232
+
1233
+
1234
+
1172
1235
 
1173
1236
 
1174
1237
 
@@ -1222,6 +1285,9 @@ var Deque = class extends LinearBase {
1222
1285
 
1223
1286
 
1224
1287
 
1288
+
1289
+
1290
+
1225
1291
 
1226
1292
 
1227
1293
 
@@ -1426,6 +1492,9 @@ var Deque = class extends LinearBase {
1426
1492
 
1427
1493
 
1428
1494
 
1495
+
1496
+
1497
+
1429
1498
 
1430
1499
 
1431
1500
 
@@ -1520,6 +1589,64 @@ var Deque = class extends LinearBase {
1520
1589
 
1521
1590
 
1522
1591
 
1592
+
1593
+ * @example
1594
+ * // Deque for...of iteration and reverse
1595
+ * const deque = new Deque<string>(['A', 'B', 'C', 'D']);
1596
+ *
1597
+ * // Iterate forward
1598
+ * const forward: string[] = [];
1599
+ * for (const item of deque) {
1600
+ * forward.push(item);
1601
+ * }
1602
+ * console.log(forward); // ['A', 'B', 'C', 'D'];
1603
+ *
1604
+ * // Reverse the deque
1605
+ * deque.reverse();
1606
+ * const backward: string[] = [];
1607
+ * for (const item of deque) {
1608
+ * backward.push(item);
1609
+ * }
1610
+ * console.log(backward); // ['D', 'C', 'B', 'A'];
1611
+ */
1612
+ /**
1613
+ * Find the last value matching a predicate (scans back-to-front).
1614
+ * @remarks Provided for familiarity when migrating from Array. Time O(n), Space O(1).
1615
+ * @param predicate - Function called with (value, index, deque).
1616
+ * @returns Matching value or undefined.
1617
+ * @example
1618
+ * // Find last matching value
1619
+ * const d = new Deque([1, 2, 3, 4, 5]);
1620
+ * console.log(d.findLast(v => v > 2)); // 5;
1621
+ * console.log(d.findLast(v => v % 2 === 0)); // 4;
1622
+ */
1623
+ findLast(predicate) {
1624
+ for (let i = this.length - 1; i >= 0; i--) {
1625
+ const val = this.at(i);
1626
+ if (predicate(val, i, this)) return val;
1627
+ }
1628
+ return void 0;
1629
+ }
1630
+ /**
1631
+ * Find the index of the last value matching a predicate (scans back-to-front).
1632
+ * @remarks Provided for familiarity when migrating from Array. Time O(n), Space O(1).
1633
+ * @param predicate - Function called with (value, index, deque).
1634
+ * @returns Matching index, or -1 if not found.
1635
+ * @example
1636
+ * // Find last matching index
1637
+ * const d = new Deque([10, 20, 30, 20, 10]);
1638
+ * console.log(d.findLastIndex(v => v === 20)); // 3;
1639
+ * console.log(d.findLastIndex(v => v === 10)); // 4;
1640
+ */
1641
+ findLastIndex(predicate) {
1642
+ for (let i = this.length - 1; i >= 0; i--) {
1643
+ if (predicate(this.at(i), i, this)) return i;
1644
+ }
1645
+ return -1;
1646
+ }
1647
+ /**
1648
+ * Deque for...of iteration and reverse
1649
+
1523
1650
 
1524
1651
  * @example
1525
1652
  * // Deque for...of iteration and reverse
@@ -1633,6 +1760,9 @@ var Deque = class extends LinearBase {
1633
1760
 
1634
1761
 
1635
1762
 
1763
+
1764
+
1765
+
1636
1766
 
1637
1767
 
1638
1768
 
@@ -1708,6 +1838,9 @@ var Deque = class extends LinearBase {
1708
1838
 
1709
1839
 
1710
1840
 
1841
+
1842
+
1843
+
1711
1844
 
1712
1845
 
1713
1846
 
@@ -1766,6 +1899,9 @@ var Deque = class extends LinearBase {
1766
1899
 
1767
1900
 
1768
1901
 
1902
+
1903
+
1904
+
1769
1905
 
1770
1906
 
1771
1907
 
@@ -1844,6 +1980,9 @@ var Deque = class extends LinearBase {
1844
1980
 
1845
1981
 
1846
1982
 
1983
+
1984
+
1985
+
1847
1986
 
1848
1987
 
1849
1988