data-structure-typed 1.49.1 → 1.49.3

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 (106) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/README.md +16 -16
  3. package/README_zh-CN.md +2 -2
  4. package/benchmark/report.html +46 -1
  5. package/benchmark/report.json +457 -22
  6. package/dist/cjs/data-structures/base/iterable-base.d.ts +11 -0
  7. package/dist/cjs/data-structures/base/iterable-base.js +21 -0
  8. package/dist/cjs/data-structures/base/iterable-base.js.map +1 -1
  9. package/dist/cjs/data-structures/graph/abstract-graph.d.ts +7 -7
  10. package/dist/cjs/data-structures/graph/abstract-graph.js +43 -12
  11. package/dist/cjs/data-structures/graph/abstract-graph.js.map +1 -1
  12. package/dist/cjs/data-structures/graph/directed-graph.d.ts +2 -2
  13. package/dist/cjs/data-structures/graph/directed-graph.js +2 -2
  14. package/dist/cjs/data-structures/graph/directed-graph.js.map +1 -1
  15. package/dist/cjs/data-structures/graph/undirected-graph.d.ts +1 -1
  16. package/dist/cjs/data-structures/graph/undirected-graph.js +1 -1
  17. package/dist/cjs/data-structures/graph/undirected-graph.js.map +1 -1
  18. package/dist/cjs/data-structures/hash/hash-map.d.ts +9 -9
  19. package/dist/cjs/data-structures/hash/hash-map.js +16 -15
  20. package/dist/cjs/data-structures/hash/hash-map.js.map +1 -1
  21. package/dist/cjs/data-structures/heap/heap.d.ts +6 -35
  22. package/dist/cjs/data-structures/heap/heap.js +10 -42
  23. package/dist/cjs/data-structures/heap/heap.js.map +1 -1
  24. package/dist/cjs/data-structures/linked-list/doubly-linked-list.d.ts +99 -105
  25. package/dist/cjs/data-structures/linked-list/doubly-linked-list.js +143 -146
  26. package/dist/cjs/data-structures/linked-list/doubly-linked-list.js.map +1 -1
  27. package/dist/cjs/data-structures/linked-list/singly-linked-list.d.ts +16 -21
  28. package/dist/cjs/data-structures/linked-list/singly-linked-list.js +42 -42
  29. package/dist/cjs/data-structures/linked-list/singly-linked-list.js.map +1 -1
  30. package/dist/cjs/data-structures/linked-list/skip-linked-list.d.ts +25 -25
  31. package/dist/cjs/data-structures/linked-list/skip-linked-list.js +36 -36
  32. package/dist/cjs/data-structures/linked-list/skip-linked-list.js.map +1 -1
  33. package/dist/cjs/data-structures/queue/deque.d.ts +70 -75
  34. package/dist/cjs/data-structures/queue/deque.js +100 -110
  35. package/dist/cjs/data-structures/queue/deque.js.map +1 -1
  36. package/dist/cjs/data-structures/queue/queue.d.ts +37 -38
  37. package/dist/cjs/data-structures/queue/queue.js +46 -49
  38. package/dist/cjs/data-structures/queue/queue.js.map +1 -1
  39. package/dist/cjs/data-structures/stack/stack.d.ts +2 -3
  40. package/dist/cjs/data-structures/stack/stack.js +2 -5
  41. package/dist/cjs/data-structures/stack/stack.js.map +1 -1
  42. package/dist/cjs/data-structures/trie/trie.d.ts +1 -2
  43. package/dist/cjs/data-structures/trie/trie.js +2 -5
  44. package/dist/cjs/data-structures/trie/trie.js.map +1 -1
  45. package/dist/mjs/data-structures/base/iterable-base.d.ts +11 -0
  46. package/dist/mjs/data-structures/base/iterable-base.js +21 -0
  47. package/dist/mjs/data-structures/graph/abstract-graph.d.ts +7 -7
  48. package/dist/mjs/data-structures/graph/abstract-graph.js +43 -12
  49. package/dist/mjs/data-structures/graph/directed-graph.d.ts +2 -2
  50. package/dist/mjs/data-structures/graph/directed-graph.js +2 -2
  51. package/dist/mjs/data-structures/graph/undirected-graph.d.ts +1 -1
  52. package/dist/mjs/data-structures/graph/undirected-graph.js +1 -1
  53. package/dist/mjs/data-structures/hash/hash-map.d.ts +9 -9
  54. package/dist/mjs/data-structures/hash/hash-map.js +16 -15
  55. package/dist/mjs/data-structures/heap/heap.d.ts +6 -35
  56. package/dist/mjs/data-structures/heap/heap.js +10 -42
  57. package/dist/mjs/data-structures/linked-list/doubly-linked-list.d.ts +99 -105
  58. package/dist/mjs/data-structures/linked-list/doubly-linked-list.js +142 -145
  59. package/dist/mjs/data-structures/linked-list/singly-linked-list.d.ts +16 -21
  60. package/dist/mjs/data-structures/linked-list/singly-linked-list.js +43 -43
  61. package/dist/mjs/data-structures/linked-list/skip-linked-list.d.ts +25 -25
  62. package/dist/mjs/data-structures/linked-list/skip-linked-list.js +36 -36
  63. package/dist/mjs/data-structures/queue/deque.d.ts +70 -75
  64. package/dist/mjs/data-structures/queue/deque.js +100 -110
  65. package/dist/mjs/data-structures/queue/queue.d.ts +37 -38
  66. package/dist/mjs/data-structures/queue/queue.js +45 -48
  67. package/dist/mjs/data-structures/stack/stack.d.ts +2 -3
  68. package/dist/mjs/data-structures/stack/stack.js +2 -5
  69. package/dist/mjs/data-structures/trie/trie.d.ts +1 -2
  70. package/dist/mjs/data-structures/trie/trie.js +2 -5
  71. package/dist/umd/data-structure-typed.js +531 -532
  72. package/dist/umd/data-structure-typed.min.js +2 -2
  73. package/dist/umd/data-structure-typed.min.js.map +1 -1
  74. package/package.json +1 -1
  75. package/src/data-structures/base/iterable-base.ts +24 -0
  76. package/src/data-structures/graph/abstract-graph.ts +55 -14
  77. package/src/data-structures/graph/directed-graph.ts +3 -2
  78. package/src/data-structures/graph/undirected-graph.ts +1 -1
  79. package/src/data-structures/hash/hash-map.ts +27 -28
  80. package/src/data-structures/heap/heap.ts +19 -57
  81. package/src/data-structures/linked-list/doubly-linked-list.ts +157 -161
  82. package/src/data-structures/linked-list/singly-linked-list.ts +49 -49
  83. package/src/data-structures/linked-list/skip-linked-list.ts +40 -40
  84. package/src/data-structures/queue/deque.ts +122 -135
  85. package/src/data-structures/queue/queue.ts +54 -58
  86. package/src/data-structures/stack/stack.ts +4 -8
  87. package/src/data-structures/trie/trie.ts +5 -9
  88. package/test/performance/data-structures/comparison/comparison.test.ts +6 -6
  89. package/test/performance/data-structures/heap/heap.test.ts +2 -2
  90. package/test/performance/data-structures/linked-list/doubly-linked-list.test.ts +2 -2
  91. package/test/performance/data-structures/linked-list/singly-linked-list.test.ts +2 -2
  92. package/test/performance/data-structures/priority-queue/priority-queue.test.ts +2 -2
  93. package/test/unit/data-structures/binary-tree/binary-tree.test.ts +2 -2
  94. package/test/unit/data-structures/graph/abstract-graph.test.ts +1 -1
  95. package/test/unit/data-structures/graph/directed-graph.test.ts +48 -3
  96. package/test/unit/data-structures/graph/undirected-graph.test.ts +48 -4
  97. package/test/unit/data-structures/hash/hash-map.test.ts +2 -2
  98. package/test/unit/data-structures/heap/heap.test.ts +6 -1
  99. package/test/unit/data-structures/heap/min-heap.test.ts +1 -1
  100. package/test/unit/data-structures/linked-list/doubly-linked-list.test.ts +30 -30
  101. package/test/unit/data-structures/linked-list/linked-list.test.ts +1 -1
  102. package/test/unit/data-structures/linked-list/singly-linked-list.test.ts +21 -21
  103. package/test/unit/data-structures/linked-list/skip-list.test.ts +2 -2
  104. package/test/unit/data-structures/queue/deque.test.ts +5 -5
  105. package/test/unit/data-structures/queue/queue.test.ts +4 -4
  106. package/test/unit/data-structures/trie/trie.test.ts +1 -1
@@ -616,6 +616,20 @@ var dataStructureTyped = (() => {
616
616
  }
617
617
  return accumulator;
618
618
  }
619
+ hasValue(value) {
620
+ for (const [, elementValue] of this) {
621
+ if (elementValue === value)
622
+ return true;
623
+ }
624
+ return false;
625
+ }
626
+ /**
627
+ * Time Complexity: O(n)
628
+ * Space Complexity: O(n)
629
+ */
630
+ print() {
631
+ console.log([...this]);
632
+ }
619
633
  };
620
634
  var IterableElementBase = class {
621
635
  /**
@@ -751,6 +765,13 @@ var dataStructureTyped = (() => {
751
765
  }
752
766
  return accumulator;
753
767
  }
768
+ /**
769
+ * Time Complexity: O(n)
770
+ * Space Complexity: O(n)
771
+ */
772
+ print() {
773
+ console.log([...this]);
774
+ }
754
775
  };
755
776
 
756
777
  // src/utils/utils.ts
@@ -886,6 +907,7 @@ var dataStructureTyped = (() => {
886
907
  }
887
908
  this._store[strKey] = { key, value };
888
909
  }
910
+ return true;
889
911
  }
890
912
  /**
891
913
  * The function "setMany" sets multiple key-value pairs in a map.
@@ -893,8 +915,10 @@ var dataStructureTyped = (() => {
893
915
  * key-value pair is represented as an array with two elements: the key and the value.
894
916
  */
895
917
  setMany(elements) {
918
+ const results = [];
896
919
  for (const [key, value] of elements)
897
- this.set(key, value);
920
+ results.push(this.set(key, value));
921
+ return results;
898
922
  }
899
923
  /**
900
924
  * The `get` function retrieves a value from a map based on a given key, either from an object map or
@@ -1009,6 +1033,9 @@ var dataStructureTyped = (() => {
1009
1033
  print() {
1010
1034
  console.log([...this.entries()]);
1011
1035
  }
1036
+ put(key, value) {
1037
+ return this.set(key, value);
1038
+ }
1012
1039
  /**
1013
1040
  * The function returns an iterator that yields key-value pairs from both an object store and an
1014
1041
  * object map.
@@ -1160,7 +1187,7 @@ var dataStructureTyped = (() => {
1160
1187
  this._sentinel.prev = node;
1161
1188
  this._size++;
1162
1189
  }
1163
- return this._size;
1190
+ return true;
1164
1191
  }
1165
1192
  has(key) {
1166
1193
  if (isWeakKey(key)) {
@@ -1171,18 +1198,13 @@ var dataStructureTyped = (() => {
1171
1198
  return hash in this._noObjMap;
1172
1199
  }
1173
1200
  }
1174
- hasValue(value) {
1175
- for (const [, elementValue] of this) {
1176
- if (elementValue === value)
1177
- return true;
1178
- }
1179
- return false;
1180
- }
1181
1201
  setMany(entries) {
1202
+ const results = [];
1182
1203
  for (const entry of entries) {
1183
1204
  const [key, value] = entry;
1184
- this.set(key, value);
1205
+ results.push(this.set(key, value));
1185
1206
  }
1207
+ return results;
1186
1208
  }
1187
1209
  /**
1188
1210
  * Time Complexity: O(1)
@@ -1225,7 +1247,7 @@ var dataStructureTyped = (() => {
1225
1247
  while (index--) {
1226
1248
  node = node.next;
1227
1249
  }
1228
- return [node.key, node.value];
1250
+ return node.value;
1229
1251
  }
1230
1252
  /**
1231
1253
  * Time Complexity: O(1)
@@ -1272,8 +1294,7 @@ var dataStructureTyped = (() => {
1272
1294
  while (index--) {
1273
1295
  node = node.next;
1274
1296
  }
1275
- this._deleteNode(node);
1276
- return this._size;
1297
+ return this._deleteNode(node);
1277
1298
  }
1278
1299
  /**
1279
1300
  * Time Complexity: O(1)
@@ -1366,8 +1387,8 @@ var dataStructureTyped = (() => {
1366
1387
  }
1367
1388
  return mappedMap;
1368
1389
  }
1369
- print() {
1370
- console.log([...this]);
1390
+ put(key, value) {
1391
+ return this.set(key, value);
1371
1392
  }
1372
1393
  /**
1373
1394
  * Time Complexity: O(n), where n is the number of elements in the LinkedHashMap.
@@ -1403,6 +1424,7 @@ var dataStructureTyped = (() => {
1403
1424
  this._tail = prev;
1404
1425
  }
1405
1426
  this._size -= 1;
1427
+ return true;
1406
1428
  }
1407
1429
  };
1408
1430
 
@@ -1428,10 +1450,10 @@ var dataStructureTyped = (() => {
1428
1450
  super();
1429
1451
  __publicField(this, "_head");
1430
1452
  __publicField(this, "_tail");
1431
- __publicField(this, "_length");
1453
+ __publicField(this, "_size");
1432
1454
  this._head = void 0;
1433
1455
  this._tail = void 0;
1434
- this._length = 0;
1456
+ this._size = 0;
1435
1457
  if (elements) {
1436
1458
  for (const el of elements)
1437
1459
  this.push(el);
@@ -1443,8 +1465,8 @@ var dataStructureTyped = (() => {
1443
1465
  get tail() {
1444
1466
  return this._tail;
1445
1467
  }
1446
- get length() {
1447
- return this._length;
1468
+ get size() {
1469
+ return this._size;
1448
1470
  }
1449
1471
  /**
1450
1472
  * Time Complexity: O(n) - Linear time, where n is the length of the input array, as it performs a loop to push each element into the linked list.
@@ -1487,7 +1509,8 @@ var dataStructureTyped = (() => {
1487
1509
  this.tail.next = newNode;
1488
1510
  this._tail = newNode;
1489
1511
  }
1490
- this._length++;
1512
+ this._size++;
1513
+ return true;
1491
1514
  }
1492
1515
  /**
1493
1516
  * Time Complexity: O(1) - Constant time, as it involves basic pointer adjustments.
@@ -1502,7 +1525,7 @@ var dataStructureTyped = (() => {
1502
1525
  * any type (E) as specified in the generic type declaration of the class or function.
1503
1526
  */
1504
1527
  addLast(value) {
1505
- this.push(value);
1528
+ return this.push(value);
1506
1529
  }
1507
1530
  /**
1508
1531
  * Time Complexity: O(n) - Linear time in the worst case, as it may need to traverse the list to find the last element.
@@ -1524,7 +1547,7 @@ var dataStructureTyped = (() => {
1524
1547
  const value2 = this.head.value;
1525
1548
  this._head = void 0;
1526
1549
  this._tail = void 0;
1527
- this._length--;
1550
+ this._size--;
1528
1551
  return value2;
1529
1552
  }
1530
1553
  let current = this.head;
@@ -1534,7 +1557,7 @@ var dataStructureTyped = (() => {
1534
1557
  const value = this.tail.value;
1535
1558
  current.next = void 0;
1536
1559
  this._tail = current;
1537
- this._length--;
1560
+ this._size--;
1538
1561
  return value;
1539
1562
  }
1540
1563
  /**
@@ -1569,7 +1592,7 @@ var dataStructureTyped = (() => {
1569
1592
  return void 0;
1570
1593
  const removedNode = this.head;
1571
1594
  this._head = this.head.next;
1572
- this._length--;
1595
+ this._size--;
1573
1596
  return removedNode.value;
1574
1597
  }
1575
1598
  /**
@@ -1607,7 +1630,8 @@ var dataStructureTyped = (() => {
1607
1630
  newNode.next = this.head;
1608
1631
  this._head = newNode;
1609
1632
  }
1610
- this._length++;
1633
+ this._size++;
1634
+ return true;
1611
1635
  }
1612
1636
  /**
1613
1637
  * Time Complexity: O(1) - Constant time, as it involves adjusting pointers at the head.
@@ -1622,7 +1646,7 @@ var dataStructureTyped = (() => {
1622
1646
  * linked list.
1623
1647
  */
1624
1648
  addFirst(value) {
1625
- this.unshift(value);
1649
+ return this.unshift(value);
1626
1650
  }
1627
1651
  /**
1628
1652
  * Time Complexity: O(n) - Linear time, where n is the index, as it may need to traverse the list to find the desired node.
@@ -1639,7 +1663,7 @@ var dataStructureTyped = (() => {
1639
1663
  * `undefined` if the index is out of bounds.
1640
1664
  */
1641
1665
  getAt(index) {
1642
- if (index < 0 || index >= this.length)
1666
+ if (index < 0 || index >= this.size)
1643
1667
  return void 0;
1644
1668
  let current = this.head;
1645
1669
  for (let i = 0; i < index; i++) {
@@ -1683,17 +1707,21 @@ var dataStructureTyped = (() => {
1683
1707
  * bounds.
1684
1708
  */
1685
1709
  deleteAt(index) {
1686
- if (index < 0 || index >= this.length)
1687
- return void 0;
1688
- if (index === 0)
1689
- return this.shift();
1690
- if (index === this.length - 1)
1691
- return this.pop();
1710
+ if (index < 0 || index >= this.size)
1711
+ return false;
1712
+ if (index === 0) {
1713
+ this.shift();
1714
+ return true;
1715
+ }
1716
+ if (index === this.size - 1) {
1717
+ this.pop();
1718
+ return true;
1719
+ }
1692
1720
  const prevNode = this.getNodeAt(index - 1);
1693
1721
  const removedNode = prevNode.next;
1694
1722
  prevNode.next = removedNode.next;
1695
- this._length--;
1696
- return removedNode.value;
1723
+ this._size--;
1724
+ return true;
1697
1725
  }
1698
1726
  /**
1699
1727
  * Time Complexity: O(n) - Linear time, where n is the index, as it may need to traverse the list to find the desired node.
@@ -1732,7 +1760,7 @@ var dataStructureTyped = (() => {
1732
1760
  this._tail = prev;
1733
1761
  }
1734
1762
  }
1735
- this._length--;
1763
+ this._size--;
1736
1764
  return true;
1737
1765
  }
1738
1766
  prev = current;
@@ -1748,7 +1776,7 @@ var dataStructureTyped = (() => {
1748
1776
  * Time Complexity: O(n) - Linear time, where n is the index, as it may need to traverse the list to find the desired node.
1749
1777
  * Space Complexity: O(1) - Constant space.
1750
1778
  *
1751
- * The `insertAt` function inserts a value at a specified index in a singly linked list.
1779
+ * The `addAt` function inserts a value at a specified index in a singly linked list.
1752
1780
  * @param {number} index - The index parameter represents the position at which the new value should be inserted in the
1753
1781
  * linked list. It is of type number.
1754
1782
  * @param {E} value - The `value` parameter represents the value that you want to insert into the linked list at the
@@ -1756,14 +1784,14 @@ var dataStructureTyped = (() => {
1756
1784
  * @returns The `insert` method returns a boolean value. It returns `true` if the insertion is successful, and `false`
1757
1785
  * if the index is out of bounds.
1758
1786
  */
1759
- insertAt(index, value) {
1760
- if (index < 0 || index > this.length)
1787
+ addAt(index, value) {
1788
+ if (index < 0 || index > this.size)
1761
1789
  return false;
1762
1790
  if (index === 0) {
1763
1791
  this.unshift(value);
1764
1792
  return true;
1765
1793
  }
1766
- if (index === this.length) {
1794
+ if (index === this.size) {
1767
1795
  this.push(value);
1768
1796
  return true;
1769
1797
  }
@@ -1771,7 +1799,7 @@ var dataStructureTyped = (() => {
1771
1799
  const prevNode = this.getNodeAt(index - 1);
1772
1800
  newNode.next = prevNode.next;
1773
1801
  prevNode.next = newNode;
1774
- this._length++;
1802
+ this._size++;
1775
1803
  return true;
1776
1804
  }
1777
1805
  /**
@@ -1780,7 +1808,7 @@ var dataStructureTyped = (() => {
1780
1808
  * @returns A boolean value indicating whether the length of the object is equal to 0.
1781
1809
  */
1782
1810
  isEmpty() {
1783
- return this.length === 0;
1811
+ return this.size === 0;
1784
1812
  }
1785
1813
  /**
1786
1814
  * The `clear` function resets the linked list by setting the head, tail, and length to undefined and 0 respectively.
@@ -1788,7 +1816,7 @@ var dataStructureTyped = (() => {
1788
1816
  clear() {
1789
1817
  this._head = void 0;
1790
1818
  this._tail = void 0;
1791
- this._length = 0;
1819
+ this._size = 0;
1792
1820
  }
1793
1821
  /**
1794
1822
  * Time Complexity: O(n) - Linear time, where n is the length of the list, as it needs to traverse the entire list to convert it to an array.
@@ -1823,7 +1851,7 @@ var dataStructureTyped = (() => {
1823
1851
  */
1824
1852
  reverse() {
1825
1853
  if (!this.head || this.head === this.tail)
1826
- return;
1854
+ return this;
1827
1855
  let prev = void 0;
1828
1856
  let current = this.head;
1829
1857
  let next = void 0;
@@ -1834,6 +1862,7 @@ var dataStructureTyped = (() => {
1834
1862
  current = next;
1835
1863
  }
1836
1864
  [this._head, this._tail] = [this.tail, this.head];
1865
+ return this;
1837
1866
  }
1838
1867
  /**
1839
1868
  * Time Complexity: O(n) - Linear time, where n is the length of the list, as it needs to reverse the pointers of each node.
@@ -1916,14 +1945,14 @@ var dataStructureTyped = (() => {
1916
1945
  * Time Complexity: O(n) - Linear time, where n is the length of the list, as it needs to reverse the pointers of each node.
1917
1946
  * Space Complexity: O(1) - Constant space.
1918
1947
  *
1919
- * The `insertBefore` function inserts a new value before an existing value in a singly linked list.
1948
+ * The `addBefore` function inserts a new value before an existing value in a singly linked list.
1920
1949
  * @param {E | SinglyLinkedListNode<E>} existingValueOrNode - The existing value or node that you want to insert the
1921
1950
  * new value before. It can be either the value itself or a node containing the value in the linked list.
1922
1951
  * @param {E} newValue - The `newValue` parameter represents the value that you want to insert into the linked list.
1923
- * @returns The method `insertBefore` returns a boolean value. It returns `true` if the new value was successfully
1952
+ * @returns The method `addBefore` returns a boolean value. It returns `true` if the new value was successfully
1924
1953
  * inserted before the existing value, and `false` otherwise.
1925
1954
  */
1926
- insertBefore(existingValueOrNode, newValue) {
1955
+ addBefore(existingValueOrNode, newValue) {
1927
1956
  if (!this.head)
1928
1957
  return false;
1929
1958
  let existingValue;
@@ -1942,7 +1971,7 @@ var dataStructureTyped = (() => {
1942
1971
  const newNode = new SinglyLinkedListNode(newValue);
1943
1972
  newNode.next = current.next;
1944
1973
  current.next = newNode;
1945
- this._length++;
1974
+ this._size++;
1946
1975
  return true;
1947
1976
  }
1948
1977
  current = current.next;
@@ -1957,14 +1986,14 @@ var dataStructureTyped = (() => {
1957
1986
  * Time Complexity: O(n) - Linear time, where n is the length of the list, as it needs to reverse the pointers of each node.
1958
1987
  * Space Complexity: O(1) - Constant space.
1959
1988
  *
1960
- * The `insertAfter` function inserts a new node with a given value after an existing node in a singly linked list.
1989
+ * The `addAfter` function inserts a new node with a given value after an existing node in a singly linked list.
1961
1990
  * @param {E | SinglyLinkedListNode<E>} existingValueOrNode - The existing value or node in the linked list after which
1962
1991
  * the new value will be inserted. It can be either the value of the existing node or the existing node itself.
1963
1992
  * @param {E} newValue - The value that you want to insert into the linked list after the existing value or node.
1964
1993
  * @returns The method returns a boolean value. It returns true if the new value was successfully inserted after the
1965
1994
  * existing value or node, and false if the existing value or node was not found in the linked list.
1966
1995
  */
1967
- insertAfter(existingValueOrNode, newValue) {
1996
+ addAfter(existingValueOrNode, newValue) {
1968
1997
  let existingNode;
1969
1998
  if (existingValueOrNode instanceof SinglyLinkedListNode) {
1970
1999
  existingNode = existingValueOrNode;
@@ -1978,7 +2007,7 @@ var dataStructureTyped = (() => {
1978
2007
  if (existingNode === this.tail) {
1979
2008
  this._tail = newNode;
1980
2009
  }
1981
- this._length++;
2010
+ this._size++;
1982
2011
  return true;
1983
2012
  }
1984
2013
  return false;
@@ -2065,13 +2094,6 @@ var dataStructureTyped = (() => {
2065
2094
  }
2066
2095
  return mappedList;
2067
2096
  }
2068
- /**
2069
- * Time Complexity: O(n), where n is the number of elements in the linked list.
2070
- * Space Complexity: O(n)
2071
- */
2072
- print() {
2073
- console.log([...this]);
2074
- }
2075
2097
  *_getIterator() {
2076
2098
  let current = this.head;
2077
2099
  while (current) {
@@ -2099,16 +2121,16 @@ var dataStructureTyped = (() => {
2099
2121
  };
2100
2122
  var DoublyLinkedList = class _DoublyLinkedList extends IterableElementBase {
2101
2123
  /**
2102
- * The constructor initializes the linked list with an empty head, tail, and length.
2124
+ * The constructor initializes the linked list with an empty head, tail, and size.
2103
2125
  */
2104
2126
  constructor(elements) {
2105
2127
  super();
2106
2128
  __publicField(this, "_head");
2107
2129
  __publicField(this, "_tail");
2108
- __publicField(this, "_length");
2130
+ __publicField(this, "_size");
2109
2131
  this._head = void 0;
2110
2132
  this._tail = void 0;
2111
- this._length = 0;
2133
+ this._size = 0;
2112
2134
  if (elements) {
2113
2135
  for (const el of elements) {
2114
2136
  this.push(el);
@@ -2121,18 +2143,45 @@ var dataStructureTyped = (() => {
2121
2143
  get tail() {
2122
2144
  return this._tail;
2123
2145
  }
2124
- get length() {
2125
- return this._length;
2126
- }
2127
2146
  get size() {
2128
- return this.length;
2147
+ return this._size;
2129
2148
  }
2130
2149
  /**
2131
- * Time Complexity: O(n), where n is the length of the input array.
2150
+ * Time Complexity: O(n), where n is the size of the input array.
2132
2151
  * Space Complexity: O(n)
2133
2152
  */
2134
2153
  /**
2135
- * Time Complexity: O(n), where n is the length of the input array.
2154
+ * Time Complexity: O(n), where n is the number of elements in the linked list.
2155
+ * Space Complexity: O(1)
2156
+ *
2157
+ * The `get first` function returns the first node in a doubly linked list, or undefined if the list is empty.
2158
+ * @returns The method `get first()` returns the first node of the doubly linked list, or `undefined` if the list is empty.
2159
+ */
2160
+ get first() {
2161
+ var _a;
2162
+ return (_a = this.head) == null ? void 0 : _a.value;
2163
+ }
2164
+ /**
2165
+ * Time Complexity: O(1)
2166
+ * Space Complexity: O(1)
2167
+ */
2168
+ /**
2169
+ * Time Complexity: O(n), where n is the number of elements in the linked list.
2170
+ * Space Complexity: O(1)
2171
+ *
2172
+ * The `get last` function returns the last node in a doubly linked list, or undefined if the list is empty.
2173
+ * @returns The method `get last()` returns the last node of the doubly linked list, or `undefined` if the list is empty.
2174
+ */
2175
+ get last() {
2176
+ var _a;
2177
+ return (_a = this.tail) == null ? void 0 : _a.value;
2178
+ }
2179
+ /**
2180
+ * Time Complexity: O(1)
2181
+ * Space Complexity: O(1)
2182
+ */
2183
+ /**
2184
+ * Time Complexity: O(n), where n is the size of the input array.
2136
2185
  * Space Complexity: O(n)
2137
2186
  *
2138
2187
  * The `fromArray` function creates a new instance of a DoublyLinkedList and populates it with the elements from the
@@ -2168,21 +2217,8 @@ var dataStructureTyped = (() => {
2168
2217
  this.tail.next = newNode;
2169
2218
  this._tail = newNode;
2170
2219
  }
2171
- this._length++;
2172
- }
2173
- /**
2174
- * Time Complexity: O(1)
2175
- * Space Complexity: O(1)
2176
- */
2177
- /**
2178
- * Time Complexity: O(1)
2179
- * Space Complexity: O(1)
2180
- *
2181
- * The addLast function adds a new node with the given value to the end of the doubly linked list.
2182
- * @param {E} value - The value to be added to the linked list.
2183
- */
2184
- addLast(value) {
2185
- this.push(value);
2220
+ this._size++;
2221
+ return true;
2186
2222
  }
2187
2223
  /**
2188
2224
  * Time Complexity: O(1)
@@ -2207,26 +2243,11 @@ var dataStructureTyped = (() => {
2207
2243
  this._tail = removedNode.prev;
2208
2244
  this.tail.next = void 0;
2209
2245
  }
2210
- this._length--;
2246
+ this._size--;
2211
2247
  return removedNode.value;
2212
2248
  }
2213
2249
  /**
2214
- * Time Complexity: O(1)
2215
- * Space Complexity: O(1)
2216
- */
2217
- /**
2218
- * Time Complexity: O(1)
2219
- * Space Complexity: O(1)
2220
- *
2221
- * The `pollLast()` function removes and returns the value of the last node in a doubly linked list.
2222
- * @returns The method is returning the value of the removed node (removedNode.value) if the list is not empty. If the
2223
- * list is empty, it returns undefined.
2224
- */
2225
- pollLast() {
2226
- return this.pop();
2227
- }
2228
- /**
2229
- * Time Complexity: O(1)
2250
+ * Time Complexity: O(n), where n is the number of elements in the linked list.
2230
2251
  * Space Complexity: O(1)
2231
2252
  */
2232
2253
  /**
@@ -2248,26 +2269,11 @@ var dataStructureTyped = (() => {
2248
2269
  this._head = removedNode.next;
2249
2270
  this.head.prev = void 0;
2250
2271
  }
2251
- this._length--;
2272
+ this._size--;
2252
2273
  return removedNode.value;
2253
2274
  }
2254
2275
  /**
2255
- * Time Complexity: O(1)
2256
- * Space Complexity: O(1)
2257
- */
2258
- /**
2259
- * Time Complexity: O(1)
2260
- * Space Complexity: O(1)
2261
- *
2262
- * The `pollFirst()` function removes and returns the value of the first node in a doubly linked list.
2263
- * @returns The method `shift()` returns the value of the node that is removed from the beginning of the doubly linked
2264
- * list.
2265
- */
2266
- pollFirst() {
2267
- return this.shift();
2268
- }
2269
- /**
2270
- * Time Complexity: O(1)
2276
+ * Time Complexity: O(n), where n is the number of elements in the linked list.
2271
2277
  * Space Complexity: O(1)
2272
2278
  */
2273
2279
  /**
@@ -2288,52 +2294,8 @@ var dataStructureTyped = (() => {
2288
2294
  this.head.prev = newNode;
2289
2295
  this._head = newNode;
2290
2296
  }
2291
- this._length++;
2292
- }
2293
- /**
2294
- * Time Complexity: O(1)
2295
- * Space Complexity: O(1)
2296
- */
2297
- /**
2298
- * Time Complexity: O(1)
2299
- * Space Complexity: O(1)
2300
- *
2301
- * The addFirst function adds a new node with the given value to the beginning of a doubly linked list.
2302
- * @param {E} value - The `value` parameter represents the value of the new node that will be added to the beginning of the
2303
- * doubly linked list.
2304
- */
2305
- addFirst(value) {
2306
- this.unshift(value);
2307
- }
2308
- /**
2309
- * Time Complexity: O(n), where n is the number of elements in the linked list.
2310
- * Space Complexity: O(1)
2311
- */
2312
- /**
2313
- * Time Complexity: O(n), where n is the number of elements in the linked list.
2314
- * Space Complexity: O(1)
2315
- *
2316
- * The `getFirst` function returns the first node in a doubly linked list, or undefined if the list is empty.
2317
- * @returns The method `getFirst()` returns the first node of the doubly linked list, or `undefined` if the list is empty.
2318
- */
2319
- getFirst() {
2320
- var _a;
2321
- return (_a = this.head) == null ? void 0 : _a.value;
2322
- }
2323
- /**
2324
- * Time Complexity: O(n), where n is the number of elements in the linked list.
2325
- * Space Complexity: O(1)
2326
- */
2327
- /**
2328
- * Time Complexity: O(n), where n is the number of elements in the linked list.
2329
- * Space Complexity: O(1)
2330
- *
2331
- * The `getLast` function returns the last node in a doubly linked list, or undefined if the list is empty.
2332
- * @returns The method `getLast()` returns the last node of the doubly linked list, or `undefined` if the list is empty.
2333
- */
2334
- getLast() {
2335
- var _a;
2336
- return (_a = this.tail) == null ? void 0 : _a.value;
2297
+ this._size++;
2298
+ return true;
2337
2299
  }
2338
2300
  /**
2339
2301
  * Time Complexity: O(n), where n is the number of elements in the linked list.
@@ -2350,7 +2312,7 @@ var dataStructureTyped = (() => {
2350
2312
  * or the linked list is empty, it will return undefined.
2351
2313
  */
2352
2314
  getAt(index) {
2353
- if (index < 0 || index >= this.length)
2315
+ if (index < 0 || index >= this.size)
2354
2316
  return void 0;
2355
2317
  let current = this.head;
2356
2318
  for (let i = 0; i < index; i++) {
@@ -2374,7 +2336,7 @@ var dataStructureTyped = (() => {
2374
2336
  * valid range of the linked list, otherwise it returns `undefined`.
2375
2337
  */
2376
2338
  getNodeAt(index) {
2377
- if (index < 0 || index >= this.length)
2339
+ if (index < 0 || index >= this.size)
2378
2340
  return void 0;
2379
2341
  let current = this.head;
2380
2342
  for (let i = 0; i < index; i++) {
@@ -2422,14 +2384,14 @@ var dataStructureTyped = (() => {
2422
2384
  * @returns The `insert` method returns a boolean value. It returns `true` if the insertion is successful, and `false`
2423
2385
  * if the index is out of bounds.
2424
2386
  */
2425
- insertAt(index, value) {
2426
- if (index < 0 || index > this.length)
2387
+ addAt(index, value) {
2388
+ if (index < 0 || index > this.size)
2427
2389
  return false;
2428
2390
  if (index === 0) {
2429
2391
  this.unshift(value);
2430
2392
  return true;
2431
2393
  }
2432
- if (index === this.length) {
2394
+ if (index === this.size) {
2433
2395
  this.push(value);
2434
2396
  return true;
2435
2397
  }
@@ -2440,7 +2402,7 @@ var dataStructureTyped = (() => {
2440
2402
  newNode.next = nextNode;
2441
2403
  prevNode.next = newNode;
2442
2404
  nextNode.prev = newNode;
2443
- this._length++;
2405
+ this._size++;
2444
2406
  return true;
2445
2407
  }
2446
2408
  /**
@@ -2451,7 +2413,7 @@ var dataStructureTyped = (() => {
2451
2413
  * Time Complexity: O(n), where n is the number of elements in the linked list.
2452
2414
  * Space Complexity: O(1)
2453
2415
  *
2454
- * The `insertBefore` function inserts a new value before an existing value or node in a doubly linked list.
2416
+ * The `addBefore` function inserts a new value before an existing value or node in a doubly linked list.
2455
2417
  * @param {E | DoublyLinkedListNode<E>} existingValueOrNode - The existing value or node in the doubly linked list
2456
2418
  * before which the new value will be inserted. It can be either the value of the existing node or the existing node
2457
2419
  * itself.
@@ -2460,7 +2422,7 @@ var dataStructureTyped = (() => {
2460
2422
  * @returns The method returns a boolean value. It returns `true` if the insertion is successful, and `false` if the
2461
2423
  * insertion fails.
2462
2424
  */
2463
- insertBefore(existingValueOrNode, newValue) {
2425
+ addBefore(existingValueOrNode, newValue) {
2464
2426
  let existingNode;
2465
2427
  if (existingValueOrNode instanceof DoublyLinkedListNode) {
2466
2428
  existingNode = existingValueOrNode;
@@ -2478,7 +2440,7 @@ var dataStructureTyped = (() => {
2478
2440
  if (existingNode === this.head) {
2479
2441
  this._head = newNode;
2480
2442
  }
2481
- this._length++;
2443
+ this._size++;
2482
2444
  return true;
2483
2445
  }
2484
2446
  return false;
@@ -2491,7 +2453,7 @@ var dataStructureTyped = (() => {
2491
2453
  * Time Complexity: O(n), where n is the number of elements in the linked list.
2492
2454
  * Space Complexity: O(1)
2493
2455
  *
2494
- * The `insertAfter` function inserts a new node with a given value after an existing node in a doubly linked list.
2456
+ * The `addAfter` function inserts a new node with a given value after an existing node in a doubly linked list.
2495
2457
  * @param {E | DoublyLinkedListNode<E>} existingValueOrNode - The existing value or node in the doubly linked list
2496
2458
  * after which the new value will be inserted. It can be either the value of the existing node or the existing node
2497
2459
  * itself.
@@ -2499,7 +2461,7 @@ var dataStructureTyped = (() => {
2499
2461
  * @returns The method returns a boolean value. It returns true if the insertion is successful, and false if the
2500
2462
  * existing value or node is not found in the doubly linked list.
2501
2463
  */
2502
- insertAfter(existingValueOrNode, newValue) {
2464
+ addAfter(existingValueOrNode, newValue) {
2503
2465
  let existingNode;
2504
2466
  if (existingValueOrNode instanceof DoublyLinkedListNode) {
2505
2467
  existingNode = existingValueOrNode;
@@ -2517,15 +2479,11 @@ var dataStructureTyped = (() => {
2517
2479
  if (existingNode === this.tail) {
2518
2480
  this._tail = newNode;
2519
2481
  }
2520
- this._length++;
2482
+ this._size++;
2521
2483
  return true;
2522
2484
  }
2523
2485
  return false;
2524
2486
  }
2525
- /**
2526
- * Time Complexity: O(n), where n is the number of elements in the linked list.
2527
- * Space Complexity: O(1)
2528
- */
2529
2487
  /**
2530
2488
  * Time Complexity: O(n), where n is the number of elements in the linked list.
2531
2489
  * Space Complexity: O(1)
@@ -2537,24 +2495,24 @@ var dataStructureTyped = (() => {
2537
2495
  * bounds.
2538
2496
  */
2539
2497
  deleteAt(index) {
2540
- if (index < 0 || index >= this.length)
2541
- return void 0;
2542
- if (index === 0)
2543
- return this.shift();
2544
- if (index === this.length - 1)
2545
- return this.pop();
2498
+ if (index < 0 || index >= this.size)
2499
+ return false;
2500
+ if (index === 0) {
2501
+ this.shift();
2502
+ return true;
2503
+ }
2504
+ if (index === this.size - 1) {
2505
+ this.pop();
2506
+ return true;
2507
+ }
2546
2508
  const removedNode = this.getNodeAt(index);
2547
2509
  const prevNode = removedNode.prev;
2548
2510
  const nextNode = removedNode.next;
2549
2511
  prevNode.next = nextNode;
2550
2512
  nextNode.prev = prevNode;
2551
- this._length--;
2552
- return removedNode.value;
2513
+ this._size--;
2514
+ return true;
2553
2515
  }
2554
- /**
2555
- * Time Complexity: O(n), where n is the number of elements in the linked list.
2556
- * Space Complexity: O(1)
2557
- */
2558
2516
  /**
2559
2517
  * Time Complexity: O(n), where n is the number of elements in the linked list.
2560
2518
  * Space Complexity: O(1)
@@ -2582,26 +2540,34 @@ var dataStructureTyped = (() => {
2582
2540
  const nextNode = node.next;
2583
2541
  prevNode.next = nextNode;
2584
2542
  nextNode.prev = prevNode;
2585
- this._length--;
2543
+ this._size--;
2586
2544
  }
2587
2545
  return true;
2588
2546
  }
2589
2547
  return false;
2590
2548
  }
2591
2549
  /**
2592
- * The function checks if a variable has a length greater than zero and returns a boolean value.
2550
+ * Time Complexity: O(n), where n is the number of elements in the linked list.
2551
+ * Space Complexity: O(1)
2552
+ */
2553
+ /**
2554
+ * The function checks if a variable has a size greater than zero and returns a boolean value.
2593
2555
  * @returns A boolean value is being returned.
2594
2556
  */
2595
2557
  isEmpty() {
2596
- return this.length === 0;
2558
+ return this.size === 0;
2597
2559
  }
2598
2560
  /**
2599
- * The `clear` function resets the linked list by setting the head, tail, and length to undefined and 0 respectively.
2561
+ * Time Complexity: O(n), where n is the number of elements in the linked list.
2562
+ * Space Complexity: O(1)
2563
+ */
2564
+ /**
2565
+ * The `clear` function resets the linked list by setting the head, tail, and size to undefined and 0 respectively.
2600
2566
  */
2601
2567
  clear() {
2602
2568
  this._head = void 0;
2603
2569
  this._tail = void 0;
2604
- this._length = 0;
2570
+ this._size = 0;
2605
2571
  }
2606
2572
  /**
2607
2573
  * Time Complexity: O(n), where n is the number of elements in the linked list.
@@ -2655,7 +2621,7 @@ var dataStructureTyped = (() => {
2655
2621
  }
2656
2622
  /**
2657
2623
  * Time Complexity: O(n), where n is the number of elements in the linked list.
2658
- * Space Complexity: O(1)
2624
+ * Space Complexity: O(n)
2659
2625
  */
2660
2626
  /**
2661
2627
  * Time Complexity: O(n), where n is the number of elements in the linked list.
@@ -2680,7 +2646,7 @@ var dataStructureTyped = (() => {
2680
2646
  }
2681
2647
  /**
2682
2648
  * Time Complexity: O(n), where n is the number of elements in the linked list.
2683
- * Space Complexity: O(1)
2649
+ * Space Complexity: O(n)
2684
2650
  */
2685
2651
  /**
2686
2652
  * Time Complexity: O(n), where n is the number of elements in the linked list.
@@ -2696,9 +2662,10 @@ var dataStructureTyped = (() => {
2696
2662
  [current.prev, current.next] = [current.next, current.prev];
2697
2663
  current = next;
2698
2664
  }
2665
+ return this;
2699
2666
  }
2700
2667
  /**
2701
- * Time Complexity: O(n), where n is the number of elements in the linked list.
2668
+ * Time Complexity: O(n)
2702
2669
  * Space Complexity: O(n)
2703
2670
  */
2704
2671
  /**
@@ -2738,8 +2705,8 @@ var dataStructureTyped = (() => {
2738
2705
  return array;
2739
2706
  }
2740
2707
  /**
2741
- * Time Complexity: O(n)
2742
- * Space Complexity: O(n)
2708
+ * Time Complexity: O(1)
2709
+ * Space Complexity: O(1)
2743
2710
  */
2744
2711
  /**
2745
2712
  * Time Complexity: O(n)
@@ -2770,8 +2737,8 @@ var dataStructureTyped = (() => {
2770
2737
  return filteredList;
2771
2738
  }
2772
2739
  /**
2773
- * Time Complexity: O(n), where n is the number of elements in the linked list.
2774
- * Space Complexity: O(n)
2740
+ * Time Complexity: O(1)
2741
+ * Space Complexity: O(1)
2775
2742
  */
2776
2743
  /**
2777
2744
  * Time Complexity: O(n)
@@ -2799,12 +2766,64 @@ var dataStructureTyped = (() => {
2799
2766
  }
2800
2767
  return mappedList;
2801
2768
  }
2769
+ /**
2770
+ * Time Complexity: O(1)
2771
+ * Space Complexity: O(1)
2772
+ */
2773
+ /**
2774
+ * Time Complexity: O(1)
2775
+ * Space Complexity: O(1)
2776
+ *
2777
+ * The addLast function adds a new node with the given value to the end of the doubly linked list.
2778
+ * @param {E} value - The value to be added to the linked list.
2779
+ */
2780
+ addLast(value) {
2781
+ return this.push(value);
2782
+ }
2783
+ /**
2784
+ * Time Complexity: O(1)
2785
+ * Space Complexity: O(1)
2786
+ */
2787
+ /**
2788
+ * Time Complexity: O(1)
2789
+ * Space Complexity: O(1)
2790
+ *
2791
+ * The `pollLast()` function removes and returns the value of the last node in a doubly linked list.
2792
+ * @returns The method is returning the value of the removed node (removedNode.value) if the list is not empty. If the
2793
+ * list is empty, it returns undefined.
2794
+ */
2795
+ pollLast() {
2796
+ return this.pop();
2797
+ }
2802
2798
  /**
2803
2799
  * Time Complexity: O(n), where n is the number of elements in the linked list.
2804
- * Space Complexity: O(n)
2800
+ * Space Complexity: O(1)
2805
2801
  */
2806
- print() {
2807
- console.log([...this]);
2802
+ /**
2803
+ * Time Complexity: O(1)
2804
+ * Space Complexity: O(1)
2805
+ *
2806
+ * The `pollFirst()` function removes and returns the value of the first node in a doubly linked list.
2807
+ * @returns The method `shift()` returns the value of the node that is removed from the beginning of the doubly linked
2808
+ * list.
2809
+ */
2810
+ pollFirst() {
2811
+ return this.shift();
2812
+ }
2813
+ /**
2814
+ * Time Complexity: O(n), where n is the number of elements in the linked list.
2815
+ * Space Complexity: O(1)
2816
+ */
2817
+ /**
2818
+ * Time Complexity: O(1)
2819
+ * Space Complexity: O(1)
2820
+ *
2821
+ * The addFirst function adds a new node with the given value to the beginning of a doubly linked list.
2822
+ * @param {E} value - The `value` parameter represents the value of the new node that will be added to the beginning of the
2823
+ * doubly linked list.
2824
+ */
2825
+ addFirst(value) {
2826
+ this.unshift(value);
2808
2827
  }
2809
2828
  /**
2810
2829
  * The function returns an iterator that iterates over the values of a linked list.
@@ -2859,6 +2878,41 @@ var dataStructureTyped = (() => {
2859
2878
  get probability() {
2860
2879
  return this._probability;
2861
2880
  }
2881
+ /**
2882
+ * Time Complexity: O(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
2883
+ * Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
2884
+ */
2885
+ /**
2886
+ * Time Complexity: O(1) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
2887
+ * Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
2888
+ *
2889
+ * Get the value of the first element (the smallest element) in the Skip List.
2890
+ * @returns The value of the first element, or undefined if the Skip List is empty.
2891
+ */
2892
+ get first() {
2893
+ const firstNode = this.head.forward[0];
2894
+ return firstNode ? firstNode.value : void 0;
2895
+ }
2896
+ /**
2897
+ * Time Complexity: O(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
2898
+ * Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
2899
+ */
2900
+ /**
2901
+ * Time Complexity: O(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
2902
+ * Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
2903
+ *
2904
+ * Get the value of the last element (the largest element) in the Skip List.
2905
+ * @returns The value of the last element, or undefined if the Skip List is empty.
2906
+ */
2907
+ get last() {
2908
+ let current = this.head;
2909
+ for (let i = this.level - 1; i >= 0; i--) {
2910
+ while (current.forward[i]) {
2911
+ current = current.forward[i];
2912
+ }
2913
+ }
2914
+ return current.value;
2915
+ }
2862
2916
  /**
2863
2917
  * Time Complexity: O(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
2864
2918
  * Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
@@ -2917,7 +2971,7 @@ var dataStructureTyped = (() => {
2917
2971
  return void 0;
2918
2972
  }
2919
2973
  /**
2920
- * Time Complexity: O(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
2974
+ * Time Complexity: O(1) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
2921
2975
  * Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
2922
2976
  */
2923
2977
  /**
@@ -2964,41 +3018,6 @@ var dataStructureTyped = (() => {
2964
3018
  }
2965
3019
  return false;
2966
3020
  }
2967
- /**
2968
- * Time Complexity: O(1) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
2969
- * Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
2970
- */
2971
- /**
2972
- * Time Complexity: O(1) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
2973
- * Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
2974
- *
2975
- * Get the value of the first element (the smallest element) in the Skip List.
2976
- * @returns The value of the first element, or undefined if the Skip List is empty.
2977
- */
2978
- getFirst() {
2979
- const firstNode = this.head.forward[0];
2980
- return firstNode ? firstNode.value : void 0;
2981
- }
2982
- /**
2983
- * Time Complexity: O(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
2984
- * Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
2985
- */
2986
- /**
2987
- * Time Complexity: O(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
2988
- * Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
2989
- *
2990
- * Get the value of the last element (the largest element) in the Skip List.
2991
- * @returns The value of the last element, or undefined if the Skip List is empty.
2992
- */
2993
- getLast() {
2994
- let current = this.head;
2995
- for (let i = this.level - 1; i >= 0; i--) {
2996
- while (current.forward[i]) {
2997
- current = current.forward[i];
2998
- }
2999
- }
3000
- return current.value;
3001
- }
3002
3021
  /**
3003
3022
  * Time Complexity: O(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
3004
3023
  * Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
@@ -3147,7 +3166,7 @@ var dataStructureTyped = (() => {
3147
3166
  */
3148
3167
  push(element) {
3149
3168
  this.elements.push(element);
3150
- return this;
3169
+ return true;
3151
3170
  }
3152
3171
  /**
3153
3172
  * Time Complexity: O(1), as it only involves accessing the last element of the array.
@@ -3163,7 +3182,7 @@ var dataStructureTyped = (() => {
3163
3182
  */
3164
3183
  pop() {
3165
3184
  if (this.isEmpty())
3166
- return void 0;
3185
+ return;
3167
3186
  return this.elements.pop();
3168
3187
  }
3169
3188
  /**
@@ -3257,9 +3276,6 @@ var dataStructureTyped = (() => {
3257
3276
  }
3258
3277
  return newStack;
3259
3278
  }
3260
- print() {
3261
- console.log([...this]);
3262
- }
3263
3279
  /**
3264
3280
  * Custom iterator for the Stack class.
3265
3281
  * @returns An iterator object.
@@ -3299,6 +3315,36 @@ var dataStructureTyped = (() => {
3299
3315
  get size() {
3300
3316
  return this.nodes.length - this.offset;
3301
3317
  }
3318
+ /**
3319
+ * Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
3320
+ * Space Complexity: O(1) - no additional space is used.
3321
+ *
3322
+ * The `first` function returns the first element of the array `_nodes` if it exists, otherwise it returns `undefined`.
3323
+ * @returns The `get first()` method returns the first element of the data structure, represented by the `_nodes` array at
3324
+ * the `_offset` index. If the data structure is empty (size is 0), it returns `undefined`.
3325
+ */
3326
+ get first() {
3327
+ return this.size > 0 ? this.nodes[this.offset] : void 0;
3328
+ }
3329
+ /**
3330
+ * Time Complexity: O(1) - constant time as it adds an element to the end of the array.
3331
+ * Space Complexity: O(1) - no additional space is used.
3332
+ */
3333
+ /**
3334
+ * Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
3335
+ * Space Complexity: O(1) - no additional space is used.
3336
+ *
3337
+ * The `last` function returns the last element in an array-like data structure, or undefined if the structure is empty.
3338
+ * @returns The method `get last()` returns the last element of the `_nodes` array if the array is not empty. If the
3339
+ * array is empty, it returns `undefined`.
3340
+ */
3341
+ get last() {
3342
+ return this.size > 0 ? this.nodes[this.nodes.length - 1] : void 0;
3343
+ }
3344
+ /**
3345
+ * Time Complexity: O(n) - where n is the number of elements in the queue. In the worst case, it may need to shift all elements to update the offset.
3346
+ * Space Complexity: O(1) - no additional space is used.
3347
+ */
3302
3348
  /**
3303
3349
  * The function "fromArray" creates a new Queue object from an array of elements.Creates a queue from an existing array.
3304
3350
  * @public
@@ -3311,7 +3357,7 @@ var dataStructureTyped = (() => {
3311
3357
  return new _Queue(elements);
3312
3358
  }
3313
3359
  /**
3314
- * Time Complexity: O(1) - constant time as it adds an element to the end of the array.
3360
+ * Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
3315
3361
  * Space Complexity: O(1) - no additional space is used.
3316
3362
  */
3317
3363
  /**
@@ -3324,10 +3370,10 @@ var dataStructureTyped = (() => {
3324
3370
  */
3325
3371
  push(element) {
3326
3372
  this.nodes.push(element);
3327
- return this;
3373
+ return true;
3328
3374
  }
3329
3375
  /**
3330
- * Time Complexity: O(n) - where n is the number of elements in the queue. In the worst case, it may need to shift all elements to update the offset.
3376
+ * Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
3331
3377
  * Space Complexity: O(1) - no additional space is used.
3332
3378
  */
3333
3379
  /**
@@ -3341,7 +3387,7 @@ var dataStructureTyped = (() => {
3341
3387
  shift() {
3342
3388
  if (this.size === 0)
3343
3389
  return void 0;
3344
- const first = this.getFirst();
3390
+ const first = this.first;
3345
3391
  this._offset += 1;
3346
3392
  if (this.offset * 2 < this.nodes.length)
3347
3393
  return first;
@@ -3349,21 +3395,6 @@ var dataStructureTyped = (() => {
3349
3395
  this._offset = 0;
3350
3396
  return first;
3351
3397
  }
3352
- /**
3353
- * Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
3354
- * Space Complexity: O(1) - no additional space is used.
3355
- */
3356
- /**
3357
- * Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
3358
- * Space Complexity: O(1) - no additional space is used.
3359
- *
3360
- * The `getFirst` function returns the first element of the array `_nodes` if it exists, otherwise it returns `undefined`.
3361
- * @returns The `getFirst()` method returns the first element of the data structure, represented by the `_nodes` array at
3362
- * the `_offset` index. If the data structure is empty (size is 0), it returns `undefined`.
3363
- */
3364
- getFirst() {
3365
- return this.size > 0 ? this.nodes[this.offset] : void 0;
3366
- }
3367
3398
  /**
3368
3399
  * Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
3369
3400
  * Space Complexity: O(1) - no additional space is used.
@@ -3377,22 +3408,7 @@ var dataStructureTyped = (() => {
3377
3408
  * the `_offset` index. If the data structure is empty (size is 0), it returns `undefined`.
3378
3409
  */
3379
3410
  peek() {
3380
- return this.getFirst();
3381
- }
3382
- /**
3383
- * Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
3384
- * Space Complexity: O(1) - no additional space is used.
3385
- */
3386
- /**
3387
- * Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
3388
- * Space Complexity: O(1) - no additional space is used.
3389
- *
3390
- * The `getLast` function returns the last element in an array-like data structure, or undefined if the structure is empty.
3391
- * @returns The method `getLast()` returns the last element of the `_nodes` array if the array is not empty. If the
3392
- * array is empty, it returns `undefined`.
3393
- */
3394
- getLast() {
3395
- return this.size > 0 ? this.nodes[this.nodes.length - 1] : void 0;
3411
+ return this.first;
3396
3412
  }
3397
3413
  /**
3398
3414
  * Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
@@ -3407,7 +3423,7 @@ var dataStructureTyped = (() => {
3407
3423
  * array is empty, it returns `undefined`.
3408
3424
  */
3409
3425
  peekLast() {
3410
- return this.getLast();
3426
+ return this.last;
3411
3427
  }
3412
3428
  /**
3413
3429
  * Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
@@ -3499,9 +3515,6 @@ var dataStructureTyped = (() => {
3499
3515
  clone() {
3500
3516
  return new _Queue(this.nodes.slice(this.offset));
3501
3517
  }
3502
- print() {
3503
- console.log([...this]);
3504
- }
3505
3518
  /**
3506
3519
  * Time Complexity: O(n)
3507
3520
  * Space Complexity: O(n)
@@ -3572,190 +3585,101 @@ var dataStructureTyped = (() => {
3572
3585
  };
3573
3586
  var LinkedListQueue = class extends SinglyLinkedList {
3574
3587
  /**
3575
- * The enqueue function adds a value to the end of an array.
3576
- * @param {E} value - The value parameter represents the value that you want to add to the queue.
3588
+ * The `get first` function returns the value of the head node in a linked list, or `undefined` if the list is empty.
3589
+ * @returns The `get first()` method is returning the value of the `head` node if it exists, otherwise it returns `undefined`.
3577
3590
  */
3578
- enqueue(value) {
3579
- this.push(value);
3580
- }
3581
- /**
3582
- * The `dequeue` function removes and returns the first element from a queue, or returns undefined if the queue is empty.
3583
- * @returns The method is returning the element at the front of the queue, or undefined if the queue is empty.
3584
- */
3585
- dequeue() {
3586
- return this.shift();
3587
- }
3588
- /**
3589
- * The `getFirst` function returns the value of the head node in a linked list, or `undefined` if the list is empty.
3590
- * @returns The `getFirst()` method is returning the value of the `head` node if it exists, otherwise it returns `undefined`.
3591
- */
3592
- getFirst() {
3591
+ get first() {
3593
3592
  var _a;
3594
3593
  return (_a = this.head) == null ? void 0 : _a.value;
3595
3594
  }
3596
3595
  /**
3597
- * The `peek` function returns the value of the head node in a linked list, or `undefined` if the list is empty.
3598
- * @returns The `peek()` method is returning the value of the `head` node if it exists, otherwise it returns `undefined`.
3599
- */
3600
- peek() {
3601
- return this.getFirst();
3602
- }
3603
- };
3604
-
3605
- // src/data-structures/queue/deque.ts
3606
- var Deque = class _Deque extends IterableElementBase {
3607
- /**
3608
- * The constructor initializes a data structure with a specified bucket size and populates it with
3609
- * elements from an iterable.
3610
- * @param elements - The `elements` parameter is an iterable object (such as an array or a Set) that
3611
- * contains the initial elements to be stored in the data structure. It can also be an object with a
3612
- * `length` property or a `size` property, which represents the number of elements in the iterable.
3613
- * @param bucketSize - The `bucketSize` parameter is the maximum number of elements that can be
3614
- * stored in each bucket. It determines the size of each bucket in the data structure.
3615
- */
3616
- constructor(elements = [], bucketSize = 1 << 12) {
3617
- super();
3618
- __publicField(this, "_bucketFirst", 0);
3619
- __publicField(this, "_firstInBucket", 0);
3620
- __publicField(this, "_bucketLast", 0);
3621
- __publicField(this, "_lastInBucket", 0);
3622
- __publicField(this, "_bucketCount", 0);
3623
- __publicField(this, "_bucketSize");
3624
- __publicField(this, "_buckets", []);
3625
- __publicField(this, "_size", 0);
3626
- let _size;
3627
- if ("length" in elements) {
3628
- if (elements.length instanceof Function)
3629
- _size = elements.length();
3630
- else
3631
- _size = elements.length;
3632
- } else {
3633
- if (elements.size instanceof Function)
3634
- _size = elements.size();
3635
- else
3636
- _size = elements.size;
3637
- }
3638
- this._bucketSize = bucketSize;
3639
- this._bucketCount = calcMinUnitsRequired(_size, this._bucketSize) || 1;
3640
- for (let i = 0; i < this._bucketCount; ++i) {
3641
- this._buckets.push(new Array(this._bucketSize));
3642
- }
3643
- const needBucketNum = calcMinUnitsRequired(_size, this._bucketSize);
3644
- this._bucketFirst = this._bucketLast = (this._bucketCount >> 1) - (needBucketNum >> 1);
3645
- this._firstInBucket = this._lastInBucket = this._bucketSize - _size % this._bucketSize >> 1;
3646
- for (const element of elements) {
3647
- this.push(element);
3648
- }
3649
- }
3650
- get buckets() {
3651
- return this._buckets;
3652
- }
3653
- get size() {
3654
- return this._size;
3655
- }
3656
- /**
3657
- * The function returns the first element in a collection if it exists, otherwise it returns
3658
- * undefined.
3659
- * @returns The first element of the collection, of type E, is being returned.
3660
- */
3661
- get first() {
3662
- if (this.size === 0)
3663
- return;
3664
- return this._buckets[this._bucketFirst][this._firstInBucket];
3665
- }
3666
- get last() {
3667
- if (this.size === 0)
3668
- return;
3669
- return this._buckets[this._bucketLast][this._lastInBucket];
3670
- }
3671
- /**
3672
- * Time Complexity: O(1) - Removes the last element.
3673
- * Space Complexity: O(1) - Operates in-place.
3674
- */
3675
- isEmpty() {
3676
- return this.size === 0;
3677
- }
3678
- /**
3679
- * Time Complexity: Amortized O(1) - Similar to push, resizing leads to O(n).
3680
- * Space Complexity: O(n) - Due to potential resizing.
3681
- */
3682
- /**
3683
- * Time Complexity: O(1)
3684
- * Space Complexity: O(n) - In worst case, resizing doubles the array size.
3685
- *
3686
- * The addLast function adds an element to the end of an array.
3687
- * @param {E} element - The element parameter represents the element that you want to add to the end of the
3688
- * data structure.
3689
- */
3690
- addLast(element) {
3691
- this.push(element);
3692
- }
3693
- /**
3694
- * Time Complexity: O(1) - Removes the first element.
3695
- * Space Complexity: O(1) - In-place operation.
3696
- */
3697
- /**
3698
- * Time Complexity: O(1) - Removes the last element.
3699
- * Space Complexity: O(1) - Operates in-place.
3700
- *
3701
- * The function "pollLast" removes and returns the last element of an array.
3702
- * @returns The last element of the array is being returned.
3703
- */
3704
- pollLast() {
3705
- return this.pop();
3706
- }
3707
- /**
3708
- * Time Complexity: O(1).
3709
- * Space Complexity: O(n) - Due to potential resizing.
3710
- *
3711
- * The "addFirst" function adds an element to the beginning of an array.
3712
- * @param {E} element - The parameter "element" represents the element that you want to add to the
3713
- * beginning of the data structure.
3596
+ * The enqueue function adds a value to the end of an array.
3597
+ * @param {E} value - The value parameter represents the value that you want to add to the queue.
3714
3598
  */
3715
- addFirst(element) {
3716
- this.unshift(element);
3599
+ enqueue(value) {
3600
+ return this.push(value);
3717
3601
  }
3718
3602
  /**
3719
- * Time Complexity: O(1) - Removes the first element.
3720
- * Space Complexity: O(1) - In-place operation.
3721
- *
3722
- * The function "pollFirst" removes and returns the first element of an array.
3723
- * @returns The method `pollFirst()` is returning the first element of the array after removing it
3724
- * from the beginning. If the array is empty, it will return `undefined`.
3603
+ * The `dequeue` function removes and returns the first element from a queue, or returns undefined if the queue is empty.
3604
+ * @returns The method is returning the element at the front of the queue, or undefined if the queue is empty.
3725
3605
  */
3726
- pollFirst() {
3606
+ dequeue() {
3727
3607
  return this.shift();
3728
3608
  }
3729
3609
  /**
3730
- * The clear() function resets the state of the object by initializing all variables to their default
3731
- * values.
3610
+ * The `peek` function returns the value of the head node in a linked list, or `undefined` if the list is empty.
3611
+ * @returns The `peek()` method is returning the value of the `head` node if it exists, otherwise it returns `undefined`.
3732
3612
  */
3733
- clear() {
3734
- this._buckets = [new Array(this._bucketSize)];
3735
- this._bucketCount = 1;
3736
- this._bucketFirst = this._bucketLast = this._size = 0;
3737
- this._firstInBucket = this._lastInBucket = this._bucketSize >> 1;
3613
+ peek() {
3614
+ return this.first;
3738
3615
  }
3616
+ };
3617
+
3618
+ // src/data-structures/queue/deque.ts
3619
+ var Deque = class _Deque extends IterableElementBase {
3739
3620
  /**
3740
- * The below function is a generator that yields elements from a collection one by one.
3621
+ * The constructor initializes a data structure with a specified bucket size and populates it with
3622
+ * elements from an iterable.
3623
+ * @param elements - The `elements` parameter is an iterable object (such as an array or a Set) that
3624
+ * contains the initial elements to be stored in the data structure. It can also be an object with a
3625
+ * `length` property or a `size` property, which represents the number of elements in the iterable.
3626
+ * @param bucketSize - The `bucketSize` parameter is the maximum number of elements that can be
3627
+ * stored in each bucket. It determines the size of each bucket in the data structure.
3741
3628
  */
3742
- *begin() {
3743
- let index = 0;
3744
- while (index < this.size) {
3745
- yield this.getAt(index);
3746
- index++;
3629
+ constructor(elements = [], bucketSize = 1 << 12) {
3630
+ super();
3631
+ __publicField(this, "_bucketFirst", 0);
3632
+ __publicField(this, "_firstInBucket", 0);
3633
+ __publicField(this, "_bucketLast", 0);
3634
+ __publicField(this, "_lastInBucket", 0);
3635
+ __publicField(this, "_bucketCount", 0);
3636
+ __publicField(this, "_bucketSize");
3637
+ __publicField(this, "_buckets", []);
3638
+ __publicField(this, "_size", 0);
3639
+ let _size;
3640
+ if ("length" in elements) {
3641
+ if (elements.length instanceof Function)
3642
+ _size = elements.length();
3643
+ else
3644
+ _size = elements.length;
3645
+ } else {
3646
+ if (elements.size instanceof Function)
3647
+ _size = elements.size();
3648
+ else
3649
+ _size = elements.size;
3650
+ }
3651
+ this._bucketSize = bucketSize;
3652
+ this._bucketCount = calcMinUnitsRequired(_size, this._bucketSize) || 1;
3653
+ for (let i = 0; i < this._bucketCount; ++i) {
3654
+ this._buckets.push(new Array(this._bucketSize));
3655
+ }
3656
+ const needBucketNum = calcMinUnitsRequired(_size, this._bucketSize);
3657
+ this._bucketFirst = this._bucketLast = (this._bucketCount >> 1) - (needBucketNum >> 1);
3658
+ this._firstInBucket = this._lastInBucket = this._bucketSize - _size % this._bucketSize >> 1;
3659
+ for (const element of elements) {
3660
+ this.push(element);
3747
3661
  }
3748
3662
  }
3663
+ get buckets() {
3664
+ return this._buckets;
3665
+ }
3666
+ get size() {
3667
+ return this._size;
3668
+ }
3749
3669
  /**
3750
- * The function `reverseBegin()` is a generator that yields elements in reverse order starting from
3751
- * the last element.
3670
+ * The function returns the first element in a collection if it exists, otherwise it returns
3671
+ * undefined.
3672
+ * @returns The first element of the collection, of type E, is being returned.
3752
3673
  */
3753
- *reverseBegin() {
3754
- let index = this.size - 1;
3755
- while (index >= 0) {
3756
- yield this.getAt(index);
3757
- index--;
3758
- }
3674
+ get first() {
3675
+ if (this.size === 0)
3676
+ return;
3677
+ return this._buckets[this._bucketFirst][this._firstInBucket];
3678
+ }
3679
+ get last() {
3680
+ if (this.size === 0)
3681
+ return;
3682
+ return this._buckets[this._bucketLast][this._lastInBucket];
3759
3683
  }
3760
3684
  /**
3761
3685
  * Time Complexity - Amortized O(1) (possible reallocation)
@@ -3786,7 +3710,7 @@ var dataStructureTyped = (() => {
3786
3710
  }
3787
3711
  this._size += 1;
3788
3712
  this._buckets[this._bucketLast][this._lastInBucket] = element;
3789
- return this.size;
3713
+ return true;
3790
3714
  }
3791
3715
  /**
3792
3716
  * Time Complexity: O(1)
@@ -3848,7 +3772,7 @@ var dataStructureTyped = (() => {
3848
3772
  }
3849
3773
  this._size += 1;
3850
3774
  this._buckets[this._bucketFirst][this._firstInBucket] = element;
3851
- return this.size;
3775
+ return true;
3852
3776
  }
3853
3777
  /**
3854
3778
  * Time Complexity: O(1)
@@ -3881,6 +3805,44 @@ var dataStructureTyped = (() => {
3881
3805
  this._size -= 1;
3882
3806
  return element;
3883
3807
  }
3808
+ /**
3809
+ * Time Complexity: O(1) - Removes the last element.
3810
+ * Space Complexity: O(1) - Operates in-place.
3811
+ */
3812
+ isEmpty() {
3813
+ return this.size === 0;
3814
+ }
3815
+ /**
3816
+ * The clear() function resets the state of the object by initializing all variables to their default
3817
+ * values.
3818
+ */
3819
+ clear() {
3820
+ this._buckets = [new Array(this._bucketSize)];
3821
+ this._bucketCount = 1;
3822
+ this._bucketFirst = this._bucketLast = this._size = 0;
3823
+ this._firstInBucket = this._lastInBucket = this._bucketSize >> 1;
3824
+ }
3825
+ /**
3826
+ * The below function is a generator that yields elements from a collection one by one.
3827
+ */
3828
+ *begin() {
3829
+ let index = 0;
3830
+ while (index < this.size) {
3831
+ yield this.getAt(index);
3832
+ index++;
3833
+ }
3834
+ }
3835
+ /**
3836
+ * The function `reverseBegin()` is a generator that yields elements in reverse order starting from
3837
+ * the last element.
3838
+ */
3839
+ *reverseBegin() {
3840
+ let index = this.size - 1;
3841
+ while (index >= 0) {
3842
+ yield this.getAt(index);
3843
+ index--;
3844
+ }
3845
+ }
3884
3846
  /**
3885
3847
  * Time Complexity: O(1)
3886
3848
  * Space Complexity: O(1)
@@ -3924,6 +3886,7 @@ var dataStructureTyped = (() => {
3924
3886
  indexInBucket
3925
3887
  } = this._getBucketAndPosition(pos);
3926
3888
  this._buckets[bucketIndex][indexInBucket] = element;
3889
+ return true;
3927
3890
  }
3928
3891
  /**
3929
3892
  * Time Complexity: O(n)
@@ -3933,7 +3896,7 @@ var dataStructureTyped = (() => {
3933
3896
  * Time Complexity: O(n)
3934
3897
  * Space Complexity: O(n)
3935
3898
  *
3936
- * The `insertAt` function inserts one or more elements at a specified position in an array-like data
3899
+ * The `addAt` function inserts one or more elements at a specified position in an array-like data
3937
3900
  * structure.
3938
3901
  * @param {number} pos - The `pos` parameter represents the position at which the element(s) should
3939
3902
  * be inserted. It is of type `number`.
@@ -3944,7 +3907,7 @@ var dataStructureTyped = (() => {
3944
3907
  * will be inserted once. However, you can provide a different value for `num` if you want
3945
3908
  * @returns The size of the array after the insertion is being returned.
3946
3909
  */
3947
- insertAt(pos, element, num = 1) {
3910
+ addAt(pos, element, num = 1) {
3948
3911
  const length = this.size;
3949
3912
  rangeCheck(pos, 0, length);
3950
3913
  if (pos === 0) {
@@ -3964,7 +3927,7 @@ var dataStructureTyped = (() => {
3964
3927
  for (let i = 0; i < arr.length; ++i)
3965
3928
  this.push(arr[i]);
3966
3929
  }
3967
- return this.size;
3930
+ return true;
3968
3931
  }
3969
3932
  /**
3970
3933
  * Time Complexity: O(1)
@@ -4032,7 +3995,7 @@ var dataStructureTyped = (() => {
4032
3995
  }
4033
3996
  this.pop();
4034
3997
  }
4035
- return this.size;
3998
+ return true;
4036
3999
  }
4037
4000
  /**
4038
4001
  * Time Complexity: O(n)
@@ -4051,7 +4014,7 @@ var dataStructureTyped = (() => {
4051
4014
  delete(element) {
4052
4015
  const size = this.size;
4053
4016
  if (size === 0)
4054
- return 0;
4017
+ return false;
4055
4018
  let i = 0;
4056
4019
  let index = 0;
4057
4020
  while (i < size) {
@@ -4063,7 +4026,7 @@ var dataStructureTyped = (() => {
4063
4026
  i += 1;
4064
4027
  }
4065
4028
  this.cut(index - 1);
4066
- return this.size;
4029
+ return true;
4067
4030
  }
4068
4031
  /**
4069
4032
  * Time Complexity: O(n)
@@ -4103,7 +4066,7 @@ var dataStructureTyped = (() => {
4103
4066
  */
4104
4067
  unique() {
4105
4068
  if (this.size <= 1) {
4106
- return this.size;
4069
+ return this;
4107
4070
  }
4108
4071
  let index = 1;
4109
4072
  let prev = this.getAt(0);
@@ -4115,7 +4078,7 @@ var dataStructureTyped = (() => {
4115
4078
  }
4116
4079
  }
4117
4080
  this.cut(index - 1);
4118
- return this.size;
4081
+ return this;
4119
4082
  }
4120
4083
  /**
4121
4084
  * Time Complexity: O(n log n)
@@ -4129,7 +4092,7 @@ var dataStructureTyped = (() => {
4129
4092
  * @param [comparator] - The `comparator` parameter is a function that takes in two elements `x` and
4130
4093
  * `y` of type `E` and returns a number. The comparator function is used to determine the order of
4131
4094
  * the elements in the sorted array.
4132
- * @returns The method is returning the sorted instance of the object on which the method is called.
4095
+ * @returns Deque<E>
4133
4096
  */
4134
4097
  sort(comparator) {
4135
4098
  const arr = [];
@@ -4199,7 +4162,7 @@ var dataStructureTyped = (() => {
4199
4162
  return element;
4200
4163
  }
4201
4164
  }
4202
- return void 0;
4165
+ return;
4203
4166
  }
4204
4167
  /**
4205
4168
  * Time Complexity: O(n)
@@ -4236,11 +4199,7 @@ var dataStructureTyped = (() => {
4236
4199
  * @returns The `toArray()` method is returning an array of elements of type `E`.
4237
4200
  */
4238
4201
  toArray() {
4239
- const arr = [];
4240
- for (let i = 0; i < this.size; ++i) {
4241
- arr.push(this.getAt(i));
4242
- }
4243
- return arr;
4202
+ return [...this];
4244
4203
  }
4245
4204
  /**
4246
4205
  * Time Complexity: O(n)
@@ -4300,11 +4259,55 @@ var dataStructureTyped = (() => {
4300
4259
  return newDeque;
4301
4260
  }
4302
4261
  /**
4303
- * Time Complexity: O(n)
4304
- * Space Complexity: O(n)
4262
+ * Time Complexity: Amortized O(1) - Similar to push, resizing leads to O(n).
4263
+ * Space Complexity: O(n) - Due to potential resizing.
4305
4264
  */
4306
- print() {
4307
- console.log([...this]);
4265
+ /**
4266
+ * Time Complexity: O(1)
4267
+ * Space Complexity: O(n) - In worst case, resizing doubles the array size.
4268
+ *
4269
+ * The addLast function adds an element to the end of an array.
4270
+ * @param {E} element - The element parameter represents the element that you want to add to the end of the
4271
+ * data structure.
4272
+ */
4273
+ addLast(element) {
4274
+ return this.push(element);
4275
+ }
4276
+ /**
4277
+ * Time Complexity: O(1) - Removes the first element.
4278
+ * Space Complexity: O(1) - In-place operation.
4279
+ */
4280
+ /**
4281
+ * Time Complexity: O(1) - Removes the last element.
4282
+ * Space Complexity: O(1) - Operates in-place.
4283
+ *
4284
+ * The function "pollLast" removes and returns the last element of an array.
4285
+ * @returns The last element of the array is being returned.
4286
+ */
4287
+ pollLast() {
4288
+ return this.pop();
4289
+ }
4290
+ /**
4291
+ * Time Complexity: O(1).
4292
+ * Space Complexity: O(n) - Due to potential resizing.
4293
+ *
4294
+ * The "addFirst" function adds an element to the beginning of an array.
4295
+ * @param {E} element - The parameter "element" represents the element that you want to add to the
4296
+ * beginning of the data structure.
4297
+ */
4298
+ addFirst(element) {
4299
+ return this.unshift(element);
4300
+ }
4301
+ /**
4302
+ * Time Complexity: O(1) - Removes the first element.
4303
+ * Space Complexity: O(1) - In-place operation.
4304
+ *
4305
+ * The function "pollFirst" removes and returns the first element of an array.
4306
+ * @returns The method `pollFirst()` is returning the first element of the array after removing it
4307
+ * from the beginning. If the array is empty, it will return `undefined`.
4308
+ */
4309
+ pollFirst() {
4310
+ return this.shift();
4308
4311
  }
4309
4312
  /**
4310
4313
  * Time Complexity: O(n)
@@ -4403,7 +4406,7 @@ var dataStructureTyped = (() => {
4403
4406
  }
4404
4407
  if (elements) {
4405
4408
  for (const el of elements) {
4406
- this.push(el);
4409
+ this.add(el);
4407
4410
  }
4408
4411
  }
4409
4412
  }
@@ -4445,23 +4448,8 @@ var dataStructureTyped = (() => {
4445
4448
  * @param element - The element to be inserted.
4446
4449
  */
4447
4450
  add(element) {
4448
- return this.push(element);
4449
- }
4450
- /**
4451
- * Time Complexity: O(log n), where n is the number of elements in the heap.
4452
- * Space Complexity: O(1)
4453
- */
4454
- /**
4455
- * Time Complexity: O(log n), where n is the number of elements in the heap.
4456
- * Space Complexity: O(1)
4457
- *
4458
- * Insert an element into the heap and maintain the heap properties.
4459
- * @param element - The element to be inserted.
4460
- */
4461
- push(element) {
4462
4451
  this._elements.push(element);
4463
- this._bubbleUp(this.elements.length - 1);
4464
- return this;
4452
+ return this._bubbleUp(this.elements.length - 1);
4465
4453
  }
4466
4454
  /**
4467
4455
  * Time Complexity: O(log n), where n is the number of elements in the heap.
@@ -4485,20 +4473,6 @@ var dataStructureTyped = (() => {
4485
4473
  }
4486
4474
  return value;
4487
4475
  }
4488
- /**
4489
- * Time Complexity: O(log n), where n is the number of elements in the heap.
4490
- * Space Complexity: O(1)
4491
- */
4492
- /**
4493
- * Time Complexity: O(log n), where n is the number of elements in the heap.
4494
- * Space Complexity: O(1)
4495
- *
4496
- * Remove and return the top element (smallest or largest element) from the heap.
4497
- * @returns The top element or undefined if the heap is empty.
4498
- */
4499
- pop() {
4500
- return this.poll();
4501
- }
4502
4476
  /**
4503
4477
  * Peek at the top element of the heap without removing it.
4504
4478
  * @returns The top element or undefined if the heap is empty.
@@ -4532,7 +4506,7 @@ var dataStructureTyped = (() => {
4532
4506
  */
4533
4507
  refill(elements) {
4534
4508
  this._elements = elements;
4535
- this.fix();
4509
+ return this.fix();
4536
4510
  }
4537
4511
  /**
4538
4512
  * Time Complexity: O(n), where n is the number of elements in the heap.
@@ -4569,7 +4543,7 @@ var dataStructureTyped = (() => {
4569
4543
  if (index < 0)
4570
4544
  return false;
4571
4545
  if (index === 0) {
4572
- this.pop();
4546
+ this.poll();
4573
4547
  } else if (index === this.elements.length - 1) {
4574
4548
  this.elements.pop();
4575
4549
  } else {
@@ -4676,8 +4650,10 @@ var dataStructureTyped = (() => {
4676
4650
  * Fix the entire heap to maintain heap properties.
4677
4651
  */
4678
4652
  fix() {
4653
+ const results = [];
4679
4654
  for (let i = Math.floor(this.size / 2); i >= 0; i--)
4680
- this._sinkDown(i, this.elements.length >> 1);
4655
+ results.push(this._sinkDown(i, this.elements.length >> 1));
4656
+ return results;
4681
4657
  }
4682
4658
  /**
4683
4659
  * Time Complexity: O(n)
@@ -4704,7 +4680,7 @@ var dataStructureTyped = (() => {
4704
4680
  let index = 0;
4705
4681
  for (const current of this) {
4706
4682
  if (callback.call(thisArg, current, index, this)) {
4707
- filteredList.push(current);
4683
+ filteredList.add(current);
4708
4684
  }
4709
4685
  index++;
4710
4686
  }
@@ -4743,13 +4719,6 @@ var dataStructureTyped = (() => {
4743
4719
  }
4744
4720
  return mappedHeap;
4745
4721
  }
4746
- /**
4747
- * Time Complexity: O(log n)
4748
- * Space Complexity: O(1)
4749
- */
4750
- print() {
4751
- console.log([...this]);
4752
- }
4753
4722
  *_getIterator() {
4754
4723
  for (const element of this.elements) {
4755
4724
  yield element;
@@ -4777,6 +4746,7 @@ var dataStructureTyped = (() => {
4777
4746
  index = parent;
4778
4747
  }
4779
4748
  this.elements[index] = element;
4749
+ return true;
4780
4750
  }
4781
4751
  /**
4782
4752
  * Time Complexity: O(log n)
@@ -4802,6 +4772,7 @@ var dataStructureTyped = (() => {
4802
4772
  index = left;
4803
4773
  }
4804
4774
  this.elements[index] = element;
4775
+ return true;
4805
4776
  }
4806
4777
  };
4807
4778
  var FibonacciHeapNode = class {
@@ -5271,10 +5242,10 @@ var dataStructureTyped = (() => {
5271
5242
  */
5272
5243
  addVertex(keyOrVertex, value) {
5273
5244
  if (keyOrVertex instanceof AbstractVertex) {
5274
- return this._addVertexOnly(keyOrVertex);
5245
+ return this._addVertex(keyOrVertex);
5275
5246
  } else {
5276
5247
  const newVertex = this.createVertex(keyOrVertex, value);
5277
- return this._addVertexOnly(newVertex);
5248
+ return this._addVertex(newVertex);
5278
5249
  }
5279
5250
  }
5280
5251
  isVertexKey(potentialKey) {
@@ -5344,7 +5315,7 @@ var dataStructureTyped = (() => {
5344
5315
  */
5345
5316
  addEdge(srcOrEdge, dest, weight, value) {
5346
5317
  if (srcOrEdge instanceof AbstractEdge) {
5347
- return this._addEdgeOnly(srcOrEdge);
5318
+ return this._addEdge(srcOrEdge);
5348
5319
  } else {
5349
5320
  if (dest instanceof AbstractVertex || typeof dest === "string" || typeof dest === "number") {
5350
5321
  if (!(this.hasVertex(srcOrEdge) && this.hasVertex(dest)))
@@ -5354,7 +5325,7 @@ var dataStructureTyped = (() => {
5354
5325
  if (dest instanceof AbstractVertex)
5355
5326
  dest = dest.key;
5356
5327
  const newEdge = this.createEdge(srcOrEdge, dest, weight, value);
5357
- return this._addEdgeOnly(newEdge);
5328
+ return this._addEdge(newEdge);
5358
5329
  } else {
5359
5330
  throw new Error("dest must be a Vertex or vertex key while srcOrEdge is an Edge");
5360
5331
  }
@@ -6160,13 +6131,6 @@ var dataStructureTyped = (() => {
6160
6131
  getLowMap() {
6161
6132
  return this.tarjan(false, false, false, false).lowMap;
6162
6133
  }
6163
- /**
6164
- * The function `getCycles` returns a map of cycles found using the Tarjan algorithm.
6165
- * @returns The function `getCycles()` is returning a `Map<number, VO[]>`.
6166
- */
6167
- getCycles() {
6168
- return this.tarjan(false, false, false, true).cycles;
6169
- }
6170
6134
  /**
6171
6135
  * The function "getCutVertexes" returns an array of cut vertexes using the Tarjan algorithm.
6172
6136
  * @returns an array of VO objects, specifically the cut vertexes.
@@ -6189,6 +6153,44 @@ var dataStructureTyped = (() => {
6189
6153
  getBridges() {
6190
6154
  return this.tarjan(false, true, false, false).bridges;
6191
6155
  }
6156
+ /**
6157
+ * O(V+E+C)
6158
+ * O(V+C)
6159
+ */
6160
+ getCycles(isInclude2Cycle = false) {
6161
+ const cycles = [];
6162
+ const visited = /* @__PURE__ */ new Set();
6163
+ const dfs = (vertex, currentPath, visited2) => {
6164
+ if (visited2.has(vertex)) {
6165
+ if ((!isInclude2Cycle && currentPath.length > 2 || isInclude2Cycle && currentPath.length >= 2) && currentPath[0] === vertex.key) {
6166
+ cycles.push([...currentPath]);
6167
+ }
6168
+ return;
6169
+ }
6170
+ visited2.add(vertex);
6171
+ currentPath.push(vertex.key);
6172
+ for (const neighbor of this.getNeighbors(vertex)) {
6173
+ neighbor && dfs(neighbor, currentPath, visited2);
6174
+ }
6175
+ visited2.delete(vertex);
6176
+ currentPath.pop();
6177
+ };
6178
+ for (const vertex of this.vertexMap.values()) {
6179
+ dfs(vertex, [], visited);
6180
+ }
6181
+ const uniqueCycles = /* @__PURE__ */ new Map();
6182
+ for (const cycle of cycles) {
6183
+ const sorted = [...cycle].sort().toString();
6184
+ if (uniqueCycles.has(sorted))
6185
+ continue;
6186
+ else {
6187
+ uniqueCycles.set(sorted, cycle);
6188
+ }
6189
+ }
6190
+ return [...uniqueCycles].map(
6191
+ (cycleString) => cycleString[1]
6192
+ );
6193
+ }
6192
6194
  /**
6193
6195
  * Time Complexity: O(n)
6194
6196
  * Space Complexity: O(n)
@@ -6251,7 +6253,7 @@ var dataStructureTyped = (() => {
6251
6253
  yield [vertex.key, vertex.value];
6252
6254
  }
6253
6255
  }
6254
- _addVertexOnly(newVertex) {
6256
+ _addVertex(newVertex) {
6255
6257
  if (this.hasVertex(newVertex)) {
6256
6258
  return false;
6257
6259
  }
@@ -6788,13 +6790,13 @@ var dataStructureTyped = (() => {
6788
6790
  * Time Complexity: O(1)
6789
6791
  * Space Complexity: O(1)
6790
6792
  *
6791
- * The function `_addEdgeOnly` adds an edge to a graph if the source and destination vertexMap exist.
6793
+ * The function `_addEdge` adds an edge to a graph if the source and destination vertexMap exist.
6792
6794
  * @param {EO} edge - The parameter `edge` is of type `EO`, which represents an edge in a graph. It is the edge that
6793
6795
  * needs to be added to the graph.
6794
6796
  * @returns a boolean value. It returns true if the edge was successfully added to the graph, and false if either the
6795
6797
  * source or destination vertex does not exist in the graph.
6796
6798
  */
6797
- _addEdgeOnly(edge) {
6799
+ _addEdge(edge) {
6798
6800
  if (!(this.hasVertex(edge.src) && this.hasVertex(edge.dest))) {
6799
6801
  return false;
6800
6802
  }
@@ -7148,7 +7150,7 @@ var dataStructureTyped = (() => {
7148
7150
  * @param {EO} edge - The parameter "edge" is of type EO, which represents an edge in a graph.
7149
7151
  * @returns a boolean value.
7150
7152
  */
7151
- _addEdgeOnly(edge) {
7153
+ _addEdge(edge) {
7152
7154
  for (const end of edge.vertexMap) {
7153
7155
  const endVertex = this._getVertex(end);
7154
7156
  if (endVertex === void 0)
@@ -12340,11 +12342,11 @@ var dataStructureTyped = (() => {
12340
12342
  * @returns The `filter` method is returning an array of strings (`string[]`).
12341
12343
  */
12342
12344
  filter(predicate, thisArg) {
12343
- const results = [];
12345
+ const results = new _Trie();
12344
12346
  let index = 0;
12345
12347
  for (const word of this) {
12346
12348
  if (predicate.call(thisArg, word, index, this)) {
12347
- results.push(word);
12349
+ results.add(word);
12348
12350
  }
12349
12351
  index++;
12350
12352
  }
@@ -12376,9 +12378,6 @@ var dataStructureTyped = (() => {
12376
12378
  }
12377
12379
  return newTrie;
12378
12380
  }
12379
- print() {
12380
- console.log([...this]);
12381
- }
12382
12381
  *_getIterator() {
12383
12382
  function* _dfs(node, path) {
12384
12383
  if (node.isEnd) {