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
@@ -216,6 +216,35 @@ var _IterableElementBase = class _IterableElementBase {
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
  *
@@ -477,6 +506,16 @@ var _LinearBase = class _LinearBase extends IterableElementBase {
477
506
  }
478
507
  return this;
479
508
  }
509
+ /**
510
+ * Return a new instance of the same type with elements in reverse order (non-mutating).
511
+ * @remarks Provided for familiarity when migrating from Array (ES2023 `toReversed`). Time O(n), Space O(n).
512
+ * @returns A new reversed instance.
513
+ */
514
+ toReversed() {
515
+ const cloned = this.clone();
516
+ cloned.reverse();
517
+ return cloned;
518
+ }
480
519
  };
481
520
  __name(_LinearBase, "LinearBase");
482
521
  var LinearBase = _LinearBase;
@@ -637,8 +676,39 @@ var _Deque = class _Deque extends LinearBase {
637
676
 
638
677
 
639
678
 
679
+
680
+
681
+
640
682
 
641
683
 
684
+
685
+
686
+ * @example
687
+ * // Deque peek at both ends
688
+ * const deque = new Deque<number>([10, 20, 30, 40, 50]);
689
+ *
690
+ * // Get first element without removing
691
+ * const first = deque.at(0);
692
+ * console.log(first); // 10;
693
+ *
694
+ * // Get last element without removing
695
+ * const last = deque.at(deque.length - 1);
696
+ * console.log(last); // 50;
697
+ *
698
+ * // Length unchanged
699
+ * console.log(deque.length); // 5;
700
+ */
701
+ /**
702
+ * Peek at the front element without removing it (alias for `first`).
703
+ * @remarks Time O(1), Space O(1)
704
+ * @returns Front element or undefined.
705
+ */
706
+ peek() {
707
+ return this.first;
708
+ }
709
+ /**
710
+ * Deque peek at both ends
711
+
642
712
 
643
713
 
644
714
  * @example
@@ -691,6 +761,13 @@ var _Deque = class _Deque extends LinearBase {
691
761
 
692
762
 
693
763
 
764
+
765
+
766
+
767
+
768
+
769
+
770
+
694
771
 
695
772
 
696
773
 
@@ -754,6 +831,13 @@ var _Deque = class _Deque extends LinearBase {
754
831
 
755
832
 
756
833
 
834
+
835
+
836
+
837
+
838
+
839
+
840
+
757
841
 
758
842
 
759
843
 
@@ -830,6 +914,13 @@ var _Deque = class _Deque extends LinearBase {
830
914
 
831
915
 
832
916
 
917
+
918
+
919
+
920
+
921
+
922
+
923
+
833
924
 
834
925
 
835
926
 
@@ -893,6 +984,13 @@ var _Deque = class _Deque extends LinearBase {
893
984
 
894
985
 
895
986
 
987
+
988
+
989
+
990
+
991
+
992
+
993
+
896
994
 
897
995
 
898
996
 
@@ -957,6 +1055,13 @@ var _Deque = class _Deque extends LinearBase {
957
1055
 
958
1056
 
959
1057
 
1058
+
1059
+
1060
+
1061
+
1062
+
1063
+
1064
+
960
1065
 
961
1066
 
962
1067
 
@@ -1062,6 +1167,13 @@ var _Deque = class _Deque extends LinearBase {
1062
1167
 
1063
1168
 
1064
1169
 
1170
+
1171
+
1172
+
1173
+
1174
+
1175
+
1176
+
1065
1177
 
1066
1178
 
1067
1179
 
@@ -1107,6 +1219,13 @@ var _Deque = class _Deque extends LinearBase {
1107
1219
 
1108
1220
 
1109
1221
 
1222
+
1223
+
1224
+
1225
+
1226
+
1227
+
1228
+
1110
1229
 
1111
1230
 
1112
1231
 
@@ -1156,6 +1275,13 @@ var _Deque = class _Deque extends LinearBase {
1156
1275
 
1157
1276
 
1158
1277
 
1278
+
1279
+
1280
+
1281
+
1282
+
1283
+
1284
+
1159
1285
 
1160
1286
 
1161
1287
 
@@ -1356,6 +1482,13 @@ var _Deque = class _Deque extends LinearBase {
1356
1482
 
1357
1483
 
1358
1484
 
1485
+
1486
+
1487
+
1488
+
1489
+
1490
+
1491
+
1359
1492
 
1360
1493
 
1361
1494
 
@@ -1446,10 +1579,72 @@ var _Deque = class _Deque extends LinearBase {
1446
1579
 
1447
1580
 
1448
1581
 
1582
+
1583
+
1584
+
1585
+
1449
1586
 
1450
1587
 
1451
1588
 
1452
1589
 
1590
+
1591
+ * @example
1592
+ * // Deque for...of iteration and reverse
1593
+ * const deque = new Deque<string>(['A', 'B', 'C', 'D']);
1594
+ *
1595
+ * // Iterate forward
1596
+ * const forward: string[] = [];
1597
+ * for (const item of deque) {
1598
+ * forward.push(item);
1599
+ * }
1600
+ * console.log(forward); // ['A', 'B', 'C', 'D'];
1601
+ *
1602
+ * // Reverse the deque
1603
+ * deque.reverse();
1604
+ * const backward: string[] = [];
1605
+ * for (const item of deque) {
1606
+ * backward.push(item);
1607
+ * }
1608
+ * console.log(backward); // ['D', 'C', 'B', 'A'];
1609
+ */
1610
+ /**
1611
+ * Find the last value matching a predicate (scans back-to-front).
1612
+ * @remarks Provided for familiarity when migrating from Array. Time O(n), Space O(1).
1613
+ * @param predicate - Function called with (value, index, deque).
1614
+ * @returns Matching value or undefined.
1615
+ * @example
1616
+ * // Find last matching value
1617
+ * const d = new Deque([1, 2, 3, 4, 5]);
1618
+ * console.log(d.findLast(v => v > 2)); // 5;
1619
+ * console.log(d.findLast(v => v % 2 === 0)); // 4;
1620
+ */
1621
+ findLast(predicate) {
1622
+ for (let i = this.length - 1; i >= 0; i--) {
1623
+ const val = this.at(i);
1624
+ if (predicate(val, i, this)) return val;
1625
+ }
1626
+ return void 0;
1627
+ }
1628
+ /**
1629
+ * Find the index of the last value matching a predicate (scans back-to-front).
1630
+ * @remarks Provided for familiarity when migrating from Array. Time O(n), Space O(1).
1631
+ * @param predicate - Function called with (value, index, deque).
1632
+ * @returns Matching index, or -1 if not found.
1633
+ * @example
1634
+ * // Find last matching index
1635
+ * const d = new Deque([10, 20, 30, 20, 10]);
1636
+ * console.log(d.findLastIndex(v => v === 20)); // 3;
1637
+ * console.log(d.findLastIndex(v => v === 10)); // 4;
1638
+ */
1639
+ findLastIndex(predicate) {
1640
+ for (let i = this.length - 1; i >= 0; i--) {
1641
+ if (predicate(this.at(i), i, this)) return i;
1642
+ }
1643
+ return -1;
1644
+ }
1645
+ /**
1646
+ * Deque for...of iteration and reverse
1647
+
1453
1648
 
1454
1649
  * @example
1455
1650
  * // Deque for...of iteration and reverse
@@ -1555,6 +1750,13 @@ var _Deque = class _Deque extends LinearBase {
1555
1750
 
1556
1751
 
1557
1752
 
1753
+
1754
+
1755
+
1756
+
1757
+
1758
+
1759
+
1558
1760
 
1559
1761
 
1560
1762
 
@@ -1626,6 +1828,13 @@ var _Deque = class _Deque extends LinearBase {
1626
1828
 
1627
1829
 
1628
1830
 
1831
+
1832
+
1833
+
1834
+
1835
+
1836
+
1837
+
1629
1838
 
1630
1839
 
1631
1840
 
@@ -1680,6 +1889,13 @@ var _Deque = class _Deque extends LinearBase {
1680
1889
 
1681
1890
 
1682
1891
 
1892
+
1893
+
1894
+
1895
+
1896
+
1897
+
1898
+
1683
1899
 
1684
1900
 
1685
1901
 
@@ -1754,6 +1970,13 @@ var _Deque = class _Deque extends LinearBase {
1754
1970
 
1755
1971
 
1756
1972
 
1973
+
1974
+
1975
+
1976
+
1977
+
1978
+
1979
+
1757
1980
 
1758
1981
 
1759
1982