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.
Files changed (63) hide show
  1. package/dist/cjs/index.cjs +223 -0
  2. package/dist/cjs/index.cjs.map +1 -1
  3. package/dist/cjs-legacy/index.cjs +223 -0
  4. package/dist/cjs-legacy/index.cjs.map +1 -1
  5. package/dist/esm/index.mjs +223 -0
  6. package/dist/esm/index.mjs.map +1 -1
  7. package/dist/esm-legacy/index.mjs +223 -0
  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 +86 -2
  12. package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +98 -0
  13. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +191 -15
  14. package/dist/types/data-structures/binary-tree/bst.d.ts +171 -3
  15. package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +136 -8
  16. package/dist/types/data-structures/binary-tree/segment-tree.d.ts +42 -0
  17. package/dist/types/data-structures/binary-tree/tree-map.d.ts +1061 -167
  18. package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +1232 -355
  19. package/dist/types/data-structures/binary-tree/tree-multi-set.d.ts +916 -194
  20. package/dist/types/data-structures/binary-tree/tree-set.d.ts +1078 -141
  21. package/dist/types/data-structures/graph/directed-graph.d.ts +70 -0
  22. package/dist/types/data-structures/graph/undirected-graph.d.ts +63 -0
  23. package/dist/types/data-structures/hash/hash-map.d.ts +84 -6
  24. package/dist/types/data-structures/heap/heap.d.ts +140 -12
  25. package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +150 -2
  26. package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +106 -1
  27. package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +126 -0
  28. package/dist/types/data-structures/matrix/matrix.d.ts +56 -0
  29. package/dist/types/data-structures/queue/deque.d.ts +171 -0
  30. package/dist/types/data-structures/queue/queue.d.ts +97 -0
  31. package/dist/types/data-structures/stack/stack.d.ts +72 -2
  32. package/dist/types/data-structures/trie/trie.d.ts +84 -0
  33. package/dist/types/interfaces/binary-tree.d.ts +2 -3
  34. package/dist/umd/deque-typed.js +223 -0
  35. package/dist/umd/deque-typed.js.map +1 -1
  36. package/dist/umd/deque-typed.min.js +1 -1
  37. package/dist/umd/deque-typed.min.js.map +1 -1
  38. package/package.json +2 -2
  39. package/src/data-structures/base/iterable-element-base.ts +32 -0
  40. package/src/data-structures/base/linear-base.ts +11 -0
  41. package/src/data-structures/binary-tree/avl-tree.ts +88 -5
  42. package/src/data-structures/binary-tree/binary-indexed-tree.ts +98 -0
  43. package/src/data-structures/binary-tree/binary-tree.ts +242 -81
  44. package/src/data-structures/binary-tree/bst.ts +173 -7
  45. package/src/data-structures/binary-tree/red-black-tree.ts +139 -15
  46. package/src/data-structures/binary-tree/segment-tree.ts +42 -0
  47. package/src/data-structures/binary-tree/tree-map.ts +948 -36
  48. package/src/data-structures/binary-tree/tree-multi-map.ts +893 -13
  49. package/src/data-structures/binary-tree/tree-multi-set.ts +761 -33
  50. package/src/data-structures/binary-tree/tree-set.ts +1260 -251
  51. package/src/data-structures/graph/directed-graph.ts +71 -1
  52. package/src/data-structures/graph/undirected-graph.ts +64 -1
  53. package/src/data-structures/hash/hash-map.ts +100 -12
  54. package/src/data-structures/heap/heap.ts +149 -19
  55. package/src/data-structures/linked-list/doubly-linked-list.ts +178 -2
  56. package/src/data-structures/linked-list/singly-linked-list.ts +106 -1
  57. package/src/data-structures/linked-list/skip-linked-list.ts +126 -0
  58. package/src/data-structures/matrix/matrix.ts +56 -0
  59. package/src/data-structures/queue/deque.ts +187 -0
  60. package/src/data-structures/queue/queue.ts +109 -0
  61. package/src/data-structures/stack/stack.ts +75 -5
  62. package/src/data-structures/trie/trie.ts +84 -0
  63. package/src/interfaces/binary-tree.ts +1 -9
@@ -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
@@ -641,8 +680,39 @@ var Deque = class extends LinearBase {
641
680
 
642
681
 
643
682
 
683
+
684
+
685
+
644
686
 
645
687
 
688
+
689
+
690
+ * @example
691
+ * // Deque peek at both ends
692
+ * const deque = new Deque<number>([10, 20, 30, 40, 50]);
693
+ *
694
+ * // Get first element without removing
695
+ * const first = deque.at(0);
696
+ * console.log(first); // 10;
697
+ *
698
+ * // Get last element without removing
699
+ * const last = deque.at(deque.length - 1);
700
+ * console.log(last); // 50;
701
+ *
702
+ * // Length unchanged
703
+ * console.log(deque.length); // 5;
704
+ */
705
+ /**
706
+ * Peek at the front element without removing it (alias for `first`).
707
+ * @remarks Time O(1), Space O(1)
708
+ * @returns Front element or undefined.
709
+ */
710
+ peek() {
711
+ return this.first;
712
+ }
713
+ /**
714
+ * Deque peek at both ends
715
+
646
716
 
647
717
 
648
718
  * @example
@@ -695,6 +765,13 @@ var Deque = class extends LinearBase {
695
765
 
696
766
 
697
767
 
768
+
769
+
770
+
771
+
772
+
773
+
774
+
698
775
 
699
776
 
700
777
 
@@ -758,6 +835,13 @@ var Deque = class extends LinearBase {
758
835
 
759
836
 
760
837
 
838
+
839
+
840
+
841
+
842
+
843
+
844
+
761
845
 
762
846
 
763
847
 
@@ -834,6 +918,13 @@ var Deque = class extends LinearBase {
834
918
 
835
919
 
836
920
 
921
+
922
+
923
+
924
+
925
+
926
+
927
+
837
928
 
838
929
 
839
930
 
@@ -897,6 +988,13 @@ var Deque = class extends LinearBase {
897
988
 
898
989
 
899
990
 
991
+
992
+
993
+
994
+
995
+
996
+
997
+
900
998
 
901
999
 
902
1000
 
@@ -961,6 +1059,13 @@ var Deque = class extends LinearBase {
961
1059
 
962
1060
 
963
1061
 
1062
+
1063
+
1064
+
1065
+
1066
+
1067
+
1068
+
964
1069
 
965
1070
 
966
1071
 
@@ -1066,6 +1171,13 @@ var Deque = class extends LinearBase {
1066
1171
 
1067
1172
 
1068
1173
 
1174
+
1175
+
1176
+
1177
+
1178
+
1179
+
1180
+
1069
1181
 
1070
1182
 
1071
1183
 
@@ -1111,6 +1223,13 @@ var Deque = class extends LinearBase {
1111
1223
 
1112
1224
 
1113
1225
 
1226
+
1227
+
1228
+
1229
+
1230
+
1231
+
1232
+
1114
1233
 
1115
1234
 
1116
1235
 
@@ -1160,6 +1279,13 @@ var Deque = class extends LinearBase {
1160
1279
 
1161
1280
 
1162
1281
 
1282
+
1283
+
1284
+
1285
+
1286
+
1287
+
1288
+
1163
1289
 
1164
1290
 
1165
1291
 
@@ -1360,6 +1486,13 @@ var Deque = class extends LinearBase {
1360
1486
 
1361
1487
 
1362
1488
 
1489
+
1490
+
1491
+
1492
+
1493
+
1494
+
1495
+
1363
1496
 
1364
1497
 
1365
1498
 
@@ -1450,10 +1583,72 @@ var Deque = class extends LinearBase {
1450
1583
 
1451
1584
 
1452
1585
 
1586
+
1587
+
1588
+
1589
+
1453
1590
 
1454
1591
 
1455
1592
 
1456
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
+
1457
1652
 
1458
1653
  * @example
1459
1654
  * // Deque for...of iteration and reverse
@@ -1559,6 +1754,13 @@ var Deque = class extends LinearBase {
1559
1754
 
1560
1755
 
1561
1756
 
1757
+
1758
+
1759
+
1760
+
1761
+
1762
+
1763
+
1562
1764
 
1563
1765
 
1564
1766
 
@@ -1630,6 +1832,13 @@ var Deque = class extends LinearBase {
1630
1832
 
1631
1833
 
1632
1834
 
1835
+
1836
+
1837
+
1838
+
1839
+
1840
+
1841
+
1633
1842
 
1634
1843
 
1635
1844
 
@@ -1684,6 +1893,13 @@ var Deque = class extends LinearBase {
1684
1893
 
1685
1894
 
1686
1895
 
1896
+
1897
+
1898
+
1899
+
1900
+
1901
+
1902
+
1687
1903
 
1688
1904
 
1689
1905
 
@@ -1758,6 +1974,13 @@ var Deque = class extends LinearBase {
1758
1974
 
1759
1975
 
1760
1976
 
1977
+
1978
+
1979
+
1980
+
1981
+
1982
+
1983
+
1761
1984
 
1762
1985
 
1763
1986