data-structure-typed 0.8.18 → 1.12.9

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 (287) hide show
  1. package/.dependency-cruiser.js +449 -0
  2. package/.idea/data-structure-typed.iml +2 -0
  3. package/.idea/modules.xml +1 -1
  4. package/README.md +298 -2
  5. package/dist/data-structures/binary-tree/aa-tree.js +5 -2
  6. package/dist/data-structures/binary-tree/avl-tree.d.ts +58 -5
  7. package/dist/data-structures/binary-tree/avl-tree.js +150 -46
  8. package/dist/data-structures/binary-tree/b-tree.js +5 -2
  9. package/dist/data-structures/binary-tree/binary-indexed-tree.d.ts +28 -1
  10. package/dist/data-structures/binary-tree/binary-indexed-tree.js +41 -13
  11. package/dist/data-structures/binary-tree/binary-tree.d.ts +230 -36
  12. package/dist/data-structures/binary-tree/binary-tree.js +747 -369
  13. package/dist/data-structures/binary-tree/bst.d.ts +20 -8
  14. package/dist/data-structures/binary-tree/bst.js +164 -107
  15. package/dist/data-structures/binary-tree/rb-tree.js +5 -2
  16. package/dist/data-structures/binary-tree/segment-tree.d.ts +7 -3
  17. package/dist/data-structures/binary-tree/segment-tree.js +95 -61
  18. package/dist/data-structures/binary-tree/splay-tree.js +5 -2
  19. package/dist/data-structures/binary-tree/tree-multiset.d.ts +5 -5
  20. package/dist/data-structures/binary-tree/tree-multiset.js +35 -11
  21. package/dist/data-structures/binary-tree/two-three-tree.js +5 -2
  22. package/dist/data-structures/graph/abstract-graph.d.ts +168 -46
  23. package/dist/data-structures/graph/abstract-graph.js +712 -323
  24. package/dist/data-structures/graph/directed-graph.d.ts +114 -12
  25. package/dist/data-structures/graph/directed-graph.js +372 -128
  26. package/dist/data-structures/graph/undirected-graph.d.ts +67 -3
  27. package/dist/data-structures/graph/undirected-graph.js +233 -81
  28. package/dist/data-structures/hash/coordinate-map.d.ts +33 -1
  29. package/dist/data-structures/hash/coordinate-map.js +70 -20
  30. package/dist/data-structures/hash/coordinate-set.d.ts +25 -0
  31. package/dist/data-structures/hash/coordinate-set.js +58 -15
  32. package/dist/data-structures/hash/index.d.ts +5 -0
  33. package/dist/data-structures/hash/index.js +5 -0
  34. package/dist/data-structures/heap/heap.d.ts +26 -37
  35. package/dist/data-structures/heap/heap.js +56 -60
  36. package/dist/data-structures/heap/max-heap.d.ts +8 -2
  37. package/dist/data-structures/heap/max-heap.js +32 -9
  38. package/dist/data-structures/heap/min-heap.d.ts +9 -2
  39. package/dist/data-structures/heap/min-heap.js +33 -9
  40. package/dist/data-structures/linked-list/doubly-linked-list.d.ts +14 -7
  41. package/dist/data-structures/linked-list/doubly-linked-list.js +101 -61
  42. package/dist/data-structures/linked-list/singly-linked-list.d.ts +18 -19
  43. package/dist/data-structures/linked-list/singly-linked-list.js +312 -174
  44. package/dist/data-structures/matrix/matrix.d.ts +9 -0
  45. package/dist/data-structures/matrix/matrix.js +19 -7
  46. package/dist/data-structures/matrix/matrix2d.d.ts +84 -4
  47. package/dist/data-structures/matrix/matrix2d.js +158 -61
  48. package/dist/data-structures/matrix/navigator.d.ts +34 -16
  49. package/dist/data-structures/matrix/navigator.js +65 -18
  50. package/dist/data-structures/matrix/vector2d.d.ts +153 -29
  51. package/dist/data-structures/matrix/vector2d.js +249 -102
  52. package/dist/data-structures/priority-queue/max-priority-queue.d.ts +11 -2
  53. package/dist/data-structures/priority-queue/max-priority-queue.js +33 -8
  54. package/dist/data-structures/priority-queue/min-priority-queue.d.ts +11 -2
  55. package/dist/data-structures/priority-queue/min-priority-queue.js +33 -8
  56. package/dist/data-structures/priority-queue/priority-queue.d.ts +145 -21
  57. package/dist/data-structures/priority-queue/priority-queue.js +285 -116
  58. package/dist/data-structures/queue/deque.d.ts +69 -0
  59. package/dist/data-structures/queue/deque.js +151 -56
  60. package/dist/data-structures/queue/queue.d.ts +34 -37
  61. package/dist/data-structures/queue/queue.js +59 -61
  62. package/dist/data-structures/stack/stack.d.ts +29 -35
  63. package/dist/data-structures/stack/stack.js +51 -56
  64. package/dist/data-structures/trie/trie.d.ts +36 -6
  65. package/dist/data-structures/trie/trie.js +256 -83
  66. package/dist/data-structures/types/abstract-graph.d.ts +29 -0
  67. package/dist/data-structures/types/abstract-graph.js +2 -0
  68. package/dist/data-structures/types/avl-tree.d.ts +5 -0
  69. package/dist/data-structures/types/avl-tree.js +2 -0
  70. package/dist/data-structures/types/binary-tree.d.ts +16 -0
  71. package/dist/data-structures/types/binary-tree.js +2 -0
  72. package/dist/data-structures/types/bst.d.ts +7 -0
  73. package/dist/data-structures/types/bst.js +2 -0
  74. package/dist/data-structures/types/directed-graph.d.ts +10 -0
  75. package/dist/data-structures/types/directed-graph.js +2 -0
  76. package/dist/data-structures/types/doubly-linked-list.d.ts +1 -0
  77. package/dist/data-structures/types/doubly-linked-list.js +2 -0
  78. package/dist/data-structures/types/heap.d.ts +7 -0
  79. package/dist/data-structures/types/heap.js +2 -0
  80. package/dist/data-structures/types/index.d.ts +13 -0
  81. package/dist/data-structures/types/index.js +29 -0
  82. package/dist/data-structures/types/navigator.d.ts +14 -0
  83. package/dist/data-structures/types/navigator.js +2 -0
  84. package/dist/data-structures/types/priority-queue.d.ts +7 -0
  85. package/dist/data-structures/types/priority-queue.js +2 -0
  86. package/dist/data-structures/types/segment-tree.d.ts +1 -0
  87. package/dist/data-structures/types/segment-tree.js +2 -0
  88. package/dist/data-structures/types/singly-linked-list.js +2 -0
  89. package/dist/data-structures/types/tree-multiset.d.ts +5 -0
  90. package/dist/data-structures/types/tree-multiset.js +2 -0
  91. package/dist/utils/trampoline.d.ts +14 -0
  92. package/dist/utils/trampoline.js +130 -0
  93. package/dist/utils/types/index.js +17 -0
  94. package/dist/{types → utils}/types/utils.d.ts +15 -1
  95. package/dist/{types → utils/types}/utils.js +21 -19
  96. package/dist/{utils.d.ts → utils/utils.d.ts} +5 -22
  97. package/dist/utils/utils.js +651 -0
  98. package/docs/.nojekyll +1 -0
  99. package/docs/assets/highlight.css +85 -0
  100. package/docs/assets/main.js +58 -0
  101. package/docs/assets/search.js +1 -0
  102. package/docs/assets/style.css +1367 -0
  103. package/docs/classes/AVLTree.html +2046 -0
  104. package/docs/classes/AVLTreeNode.html +423 -0
  105. package/docs/classes/AaTree.html +117 -0
  106. package/docs/classes/AbstractEdge.html +198 -0
  107. package/docs/classes/AbstractGraph.html +891 -0
  108. package/docs/classes/AbstractVertex.html +164 -0
  109. package/docs/classes/ArrayDeque.html +384 -0
  110. package/docs/classes/BST.html +1893 -0
  111. package/docs/classes/BSTNode.html +425 -0
  112. package/docs/classes/BTree.html +117 -0
  113. package/docs/classes/BinaryIndexedTree.html +244 -0
  114. package/docs/classes/BinaryTree.html +1754 -0
  115. package/docs/classes/BinaryTreeNode.html +396 -0
  116. package/docs/classes/Character.html +165 -0
  117. package/docs/classes/CoordinateMap.html +394 -0
  118. package/docs/classes/CoordinateSet.html +355 -0
  119. package/docs/classes/Deque.html +617 -0
  120. package/docs/classes/DirectedEdge.html +247 -0
  121. package/docs/classes/DirectedGraph.html +1207 -0
  122. package/docs/classes/DirectedVertex.html +154 -0
  123. package/docs/classes/DoublyLinkedList.html +619 -0
  124. package/docs/classes/DoublyLinkedListNode.html +160 -0
  125. package/docs/classes/Heap.html +315 -0
  126. package/docs/classes/Matrix2D.html +447 -0
  127. package/docs/classes/MatrixNTI2D.html +181 -0
  128. package/docs/classes/MaxHeap.html +325 -0
  129. package/docs/classes/MaxPriorityQueue.html +668 -0
  130. package/docs/classes/MinHeap.html +326 -0
  131. package/docs/classes/MinPriorityQueue.html +668 -0
  132. package/docs/classes/Navigator.html +285 -0
  133. package/docs/classes/ObjectDeque.html +289 -0
  134. package/docs/classes/PriorityQueue.html +643 -0
  135. package/docs/classes/Queue.html +337 -0
  136. package/docs/classes/RBTree.html +117 -0
  137. package/docs/classes/SegmentTree.html +234 -0
  138. package/docs/classes/SegmentTreeNode.html +302 -0
  139. package/docs/classes/SinglyLinkedList.html +1035 -0
  140. package/docs/classes/SinglyLinkedListNode.html +304 -0
  141. package/docs/classes/SplayTree.html +117 -0
  142. package/docs/classes/Stack.html +313 -0
  143. package/docs/classes/TreeMultiSet.html +1897 -0
  144. package/docs/classes/Trie.html +317 -0
  145. package/docs/classes/TrieNode.html +221 -0
  146. package/docs/classes/TwoThreeTree.html +117 -0
  147. package/docs/classes/UndirectedEdge.html +220 -0
  148. package/docs/classes/UndirectedGraph.html +1006 -0
  149. package/docs/classes/UndirectedVertex.html +154 -0
  150. package/docs/classes/Vector2D.html +746 -0
  151. package/docs/enums/CP.html +126 -0
  152. package/docs/enums/FamilyPosition.html +126 -0
  153. package/docs/enums/LoopType.html +119 -0
  154. package/docs/index.html +288 -0
  155. package/docs/modules.html +146 -0
  156. package/jest.config.js +5 -0
  157. package/package.json +33 -47
  158. package/rename_clear_files.sh +29 -0
  159. package/src/assets/complexities-diff.jpg +0 -0
  160. package/src/assets/data-structure-complexities.jpg +0 -0
  161. package/src/data-structures/binary-tree/avl-tree.ts +58 -6
  162. package/src/data-structures/binary-tree/binary-indexed-tree.ts +31 -4
  163. package/src/data-structures/binary-tree/binary-tree.ts +460 -145
  164. package/src/data-structures/binary-tree/bst.ts +31 -25
  165. package/src/data-structures/binary-tree/diagrams/avl-tree-inserting.gif +0 -0
  166. package/src/data-structures/binary-tree/diagrams/bst-rotation.gif +0 -0
  167. package/src/data-structures/binary-tree/diagrams/segment-tree.png +0 -0
  168. package/src/data-structures/binary-tree/segment-tree.ts +25 -12
  169. package/src/data-structures/binary-tree/tree-multiset.ts +5 -4
  170. package/src/data-structures/diagrams/README.md +5 -0
  171. package/src/data-structures/graph/abstract-graph.ts +224 -108
  172. package/src/data-structures/graph/diagrams/adjacency-list-pros-cons.jpg +0 -0
  173. package/src/data-structures/graph/diagrams/adjacency-list.jpg +0 -0
  174. package/src/data-structures/graph/diagrams/adjacency-matrix-pros-cons.jpg +0 -0
  175. package/src/data-structures/graph/diagrams/adjacency-matrix.jpg +0 -0
  176. package/src/data-structures/graph/diagrams/dfs-can-do.jpg +0 -0
  177. package/src/data-structures/graph/diagrams/edge-list-pros-cons.jpg +0 -0
  178. package/src/data-structures/graph/diagrams/edge-list.jpg +0 -0
  179. package/src/data-structures/graph/diagrams/max-flow.jpg +0 -0
  180. package/src/data-structures/graph/diagrams/mst.jpg +0 -0
  181. package/src/data-structures/graph/diagrams/tarjan-articulation-point-bridge.png +0 -0
  182. package/src/data-structures/graph/diagrams/tarjan-complicate-simple.png +0 -0
  183. package/src/data-structures/graph/diagrams/tarjan-strongly-connected-component.png +0 -0
  184. package/src/data-structures/graph/diagrams/tarjan.mp4 +0 -0
  185. package/src/data-structures/graph/diagrams/tarjan.webp +0 -0
  186. package/src/data-structures/graph/directed-graph.ts +132 -26
  187. package/src/data-structures/graph/undirected-graph.ts +78 -11
  188. package/src/data-structures/hash/coordinate-map.ts +33 -1
  189. package/src/data-structures/hash/coordinate-set.ts +25 -0
  190. package/src/data-structures/hash/index.ts +5 -0
  191. package/src/data-structures/heap/heap.ts +27 -41
  192. package/src/data-structures/heap/max-heap.ts +8 -2
  193. package/src/data-structures/heap/min-heap.ts +9 -2
  194. package/src/data-structures/linked-list/doubly-linked-list.ts +50 -17
  195. package/src/data-structures/linked-list/singly-linked-list.ts +56 -39
  196. package/src/data-structures/matrix/matrix.ts +11 -0
  197. package/src/data-structures/matrix/matrix2d.ts +90 -10
  198. package/src/data-structures/matrix/navigator.ts +34 -14
  199. package/src/data-structures/matrix/vector2d.ts +187 -63
  200. package/src/data-structures/priority-queue/max-priority-queue.ts +12 -3
  201. package/src/data-structures/priority-queue/min-priority-queue.ts +12 -3
  202. package/src/data-structures/priority-queue/priority-queue.ts +200 -78
  203. package/src/data-structures/queue/deque.ts +71 -2
  204. package/src/data-structures/queue/queue.ts +37 -40
  205. package/src/data-structures/stack/stack.ts +32 -38
  206. package/src/data-structures/trie/trie.ts +83 -14
  207. package/src/data-structures/types/abstract-graph.ts +51 -0
  208. package/src/data-structures/types/avl-tree.ts +6 -0
  209. package/src/data-structures/types/binary-tree.ts +15 -0
  210. package/src/data-structures/types/bst.ts +5 -0
  211. package/src/data-structures/types/directed-graph.ts +18 -0
  212. package/src/data-structures/types/doubly-linked-list.ts +1 -0
  213. package/src/data-structures/types/heap.ts +8 -0
  214. package/src/data-structures/types/index.ts +13 -0
  215. package/src/data-structures/types/navigator.ts +13 -0
  216. package/src/data-structures/types/priority-queue.ts +9 -0
  217. package/src/data-structures/types/segment-tree.ts +1 -0
  218. package/src/data-structures/types/singly-linked-list.ts +1 -0
  219. package/src/data-structures/types/tree-multiset.ts +3 -0
  220. package/src/utils/index.ts +1 -0
  221. package/src/utils/trampoline.ts +51 -0
  222. package/src/utils/types/index.ts +1 -0
  223. package/src/{types → utils/types}/utils.ts +27 -5
  224. package/src/{utils.ts → utils/utils.ts} +41 -131
  225. package/tests/unit/data-structures/binary-tree/bst.test.ts +185 -0
  226. package/tests/unit/data-structures/graph/directed-graph.test.ts +71 -0
  227. package/{dist/types/data-structures/graph/index.d.ts → tests/unit/data-structures/graph/index.ts} +1 -1
  228. package/tests/unit/data-structures/graph/undirected-graph.ts +0 -0
  229. package/tsconfig.json +9 -6
  230. package/dist/data-structures/trampoline.d.ts +0 -25
  231. package/dist/data-structures/trampoline.js +0 -52
  232. package/dist/types/data-structures/binary-tree/aa-tree.d.ts +0 -2
  233. package/dist/types/data-structures/binary-tree/avl-tree.d.ts +0 -21
  234. package/dist/types/data-structures/binary-tree/b-tree.d.ts +0 -2
  235. package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +0 -8
  236. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +0 -140
  237. package/dist/types/data-structures/binary-tree/bst.d.ts +0 -32
  238. package/dist/types/data-structures/binary-tree/index.d.ts +0 -4
  239. package/dist/types/data-structures/binary-tree/rb-tree.d.ts +0 -2
  240. package/dist/types/data-structures/binary-tree/segment-tree.d.ts +0 -33
  241. package/dist/types/data-structures/binary-tree/splay-tree.d.ts +0 -2
  242. package/dist/types/data-structures/binary-tree/tree-multiset.d.ts +0 -11
  243. package/dist/types/data-structures/binary-tree/two-three-tree.d.ts +0 -2
  244. package/dist/types/data-structures/graph/abstract-graph.d.ts +0 -126
  245. package/dist/types/data-structures/graph/directed-graph.d.ts +0 -51
  246. package/dist/types/data-structures/graph/undirected-graph.d.ts +0 -24
  247. package/dist/types/data-structures/hash/coordinate-map.d.ts +0 -8
  248. package/dist/types/data-structures/hash/coordinate-set.d.ts +0 -7
  249. package/dist/types/data-structures/hash/index.d.ts +0 -1
  250. package/dist/types/data-structures/hash/pair.d.ts +0 -1
  251. package/dist/types/data-structures/hash/tree-map.d.ts +0 -1
  252. package/dist/types/data-structures/hash/tree-set.d.ts +0 -1
  253. package/dist/types/data-structures/heap/heap.d.ts +0 -72
  254. package/dist/types/data-structures/heap/index.d.ts +0 -3
  255. package/dist/types/data-structures/heap/max-heap.d.ts +0 -14
  256. package/dist/types/data-structures/heap/min-heap.d.ts +0 -14
  257. package/dist/types/data-structures/index.d.ts +0 -9
  258. package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +0 -59
  259. package/dist/types/data-structures/linked-list/index.d.ts +0 -2
  260. package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +0 -358
  261. package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +0 -1
  262. package/dist/types/data-structures/matrix/index.d.ts +0 -3
  263. package/dist/types/data-structures/matrix/matrix.d.ts +0 -9
  264. package/dist/types/data-structures/matrix/matrix2d.d.ts +0 -25
  265. package/dist/types/data-structures/matrix/navigator.d.ts +0 -31
  266. package/dist/types/data-structures/matrix/vector2d.d.ts +0 -74
  267. package/dist/types/data-structures/priority-queue/index.d.ts +0 -3
  268. package/dist/types/data-structures/priority-queue/max-priority-queue.d.ts +0 -4
  269. package/dist/types/data-structures/priority-queue/min-priority-queue.d.ts +0 -4
  270. package/dist/types/data-structures/priority-queue/priority-queue.d.ts +0 -36
  271. package/dist/types/data-structures/queue/deque.d.ts +0 -37
  272. package/dist/types/data-structures/queue/index.d.ts +0 -1
  273. package/dist/types/data-structures/queue/queue.d.ts +0 -76
  274. package/dist/types/data-structures/stack/index.d.ts +0 -1
  275. package/dist/types/data-structures/stack/stack.d.ts +0 -69
  276. package/dist/types/data-structures/trampoline.d.ts +0 -25
  277. package/dist/types/data-structures/trie/index.d.ts +0 -1
  278. package/dist/types/data-structures/trie/trie.d.ts +0 -28
  279. package/dist/types/utils.d.ts +0 -46
  280. package/dist/utils.js +0 -569
  281. package/src/data-structures/trampoline.ts +0 -91
  282. package/src/types/index.ts +0 -1
  283. /package/dist/{types/data-structures/hash/hash-table.d.ts → data-structures/types/singly-linked-list.d.ts} +0 -0
  284. /package/dist/{types → utils}/index.d.ts +0 -0
  285. /package/dist/{types → utils}/index.js +0 -0
  286. /package/dist/{types → utils}/types/index.d.ts +0 -0
  287. /package/{src/types/patches/index.d.ts → tests/unit/data-structures/graph/abstract-graph.ts} +0 -0
@@ -1,17 +1,41 @@
1
1
  "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
2
17
  Object.defineProperty(exports, "__esModule", { value: true });
3
18
  exports.ArrayDeque = exports.ObjectDeque = exports.Deque = void 0;
4
- const linked_list_1 = require("../linked-list");
19
+ /**
20
+ * @copyright 2030 Tyler Zeng <zrwusa@gmail.com>
21
+ * @license MIT
22
+ */
23
+ var linked_list_1 = require("../linked-list");
5
24
  // O(n) time complexity of obtaining the value
6
25
  // O(1) time complexity of adding at the beginning and the end
7
- class Deque extends linked_list_1.DoublyLinkedList {
8
- }
26
+ var Deque = /** @class */ (function (_super) {
27
+ __extends(Deque, _super);
28
+ function Deque() {
29
+ return _super !== null && _super.apply(this, arguments) || this;
30
+ }
31
+ return Deque;
32
+ }(linked_list_1.DoublyLinkedList));
9
33
  exports.Deque = Deque;
10
34
  // O(1) time complexity of obtaining the value
11
35
  // O(n) time complexity of adding at the beginning and the end
12
36
  // todo tested slowest one
13
- class ObjectDeque {
14
- constructor(capacity) {
37
+ var ObjectDeque = /** @class */ (function () {
38
+ function ObjectDeque(capacity) {
15
39
  this._nodes = {};
16
40
  this._capacity = Number.MAX_SAFE_INTEGER;
17
41
  this._first = -1;
@@ -20,12 +44,12 @@ class ObjectDeque {
20
44
  if (capacity !== undefined)
21
45
  this._capacity = capacity;
22
46
  }
23
- size() {
47
+ ObjectDeque.prototype.size = function () {
24
48
  return this._size;
25
- }
26
- offerFirst(value) {
49
+ };
50
+ ObjectDeque.prototype.offerFirst = function (value) {
27
51
  if (this._size === 0) {
28
- const mid = Math.floor(this._capacity / 2);
52
+ var mid = Math.floor(this._capacity / 2);
29
53
  this._first = mid;
30
54
  this._last = mid;
31
55
  }
@@ -34,10 +58,10 @@ class ObjectDeque {
34
58
  }
35
59
  this._nodes[this._first] = value;
36
60
  this._size++;
37
- }
38
- offerLast(value) {
61
+ };
62
+ ObjectDeque.prototype.offerLast = function (value) {
39
63
  if (this._size === 0) {
40
- const mid = Math.floor(this._capacity / 2);
64
+ var mid = Math.floor(this._capacity / 2);
41
65
  this._first = mid;
42
66
  this._last = mid;
43
67
  }
@@ -46,87 +70,158 @@ class ObjectDeque {
46
70
  }
47
71
  this._nodes[this._last] = value;
48
72
  this._size++;
49
- }
50
- pollFirst() {
73
+ };
74
+ ObjectDeque.prototype.pollFirst = function () {
51
75
  if (!this._size)
52
76
  return;
53
- let value = this.peekFirst();
77
+ var value = this.peekFirst();
54
78
  delete this._nodes[this._first];
55
79
  this._first++;
56
80
  this._size--;
57
81
  return value;
58
- }
59
- peekFirst() {
82
+ };
83
+ ObjectDeque.prototype.peekFirst = function () {
60
84
  if (this._size)
61
85
  return this._nodes[this._first];
62
- }
63
- pollLast() {
86
+ };
87
+ ObjectDeque.prototype.pollLast = function () {
64
88
  if (!this._size)
65
89
  return;
66
- let value = this.peekLast();
90
+ var value = this.peekLast();
67
91
  delete this._nodes[this._last];
68
92
  this._last--;
69
93
  this._size--;
70
94
  return value;
71
- }
72
- peekLast() {
95
+ };
96
+ ObjectDeque.prototype.peekLast = function () {
73
97
  if (this._size)
74
98
  return this._nodes[this._last];
75
- }
76
- get(index) {
99
+ };
100
+ ObjectDeque.prototype.get = function (index) {
77
101
  return this._nodes[this._first + index] || null;
78
- }
79
- isEmpty() {
102
+ };
103
+ ObjectDeque.prototype.isEmpty = function () {
80
104
  return this._size <= 0;
81
- }
82
- }
105
+ };
106
+ return ObjectDeque;
107
+ }());
83
108
  exports.ObjectDeque = ObjectDeque;
84
109
  // O(1) time complexity of obtaining the value
85
110
  // O(n) time complexity of adding at the beginning and the end
86
- class ArrayDeque {
87
- constructor() {
111
+ var ArrayDeque = /** @class */ (function () {
112
+ function ArrayDeque() {
88
113
  this._nodes = [];
89
114
  }
90
- get size() {
91
- return this._nodes.length;
92
- }
93
- offerLast(value) {
115
+ Object.defineProperty(ArrayDeque.prototype, "size", {
116
+ get: function () {
117
+ return this._nodes.length;
118
+ },
119
+ enumerable: false,
120
+ configurable: true
121
+ });
122
+ /**
123
+ * The function "offerLast" adds a value to the end of an array.
124
+ * @param {T} value - The value parameter represents the value that you want to add to the end of the array.
125
+ * @returns The return value is the new length of the array after the value has been added.
126
+ */
127
+ ArrayDeque.prototype.offerLast = function (value) {
94
128
  return this._nodes.push(value);
95
- }
96
- pollLast() {
129
+ };
130
+ /**
131
+ * The function "pollLast" returns and removes the last element from an array, or returns null if the array is empty.
132
+ * @returns The method `pollLast()` returns the last element of the `_nodes` array, or `null` if the array is empty.
133
+ */
134
+ ArrayDeque.prototype.pollLast = function () {
97
135
  var _a;
98
136
  return (_a = this._nodes.pop()) !== null && _a !== void 0 ? _a : null;
99
- }
100
- pollFirst() {
137
+ };
138
+ /**
139
+ * The `pollFirst` function removes and returns the first element from an array, or returns null if the array is empty.
140
+ * @returns The `pollFirst()` function returns the first element of the `_nodes` array, or `null` if the array is
141
+ * empty.
142
+ */
143
+ ArrayDeque.prototype.pollFirst = function () {
101
144
  var _a;
102
145
  return (_a = this._nodes.shift()) !== null && _a !== void 0 ? _a : null;
103
- }
104
- offerFirst(value) {
146
+ };
147
+ /**
148
+ * The function "offerFirst" adds a value to the beginning of an array.
149
+ * @param {T} value - The value parameter represents the value that you want to add to the beginning of the array.
150
+ * @returns The return value of the `offerFirst` function is the new length of the array `_nodes` after adding the
151
+ * `value` at the beginning.
152
+ */
153
+ ArrayDeque.prototype.offerFirst = function (value) {
105
154
  return this._nodes.unshift(value);
106
- }
107
- peekFirst() {
155
+ };
156
+ /**
157
+ * The `peekFirst` function returns the first element of an array or null if the array is empty.
158
+ * @returns The function `peekFirst()` is returning the first element (`T`) of the `_nodes` array. If the array is
159
+ * empty, it will return `null`.
160
+ */
161
+ ArrayDeque.prototype.peekFirst = function () {
108
162
  var _a;
109
163
  return (_a = this._nodes[0]) !== null && _a !== void 0 ? _a : null;
110
- }
111
- peekLast() {
164
+ };
165
+ /**
166
+ * The `peekLast` function returns the last element of an array or null if the array is empty.
167
+ * @returns The method `peekLast()` returns the last element of the `_nodes` array, or `null` if the array is empty.
168
+ */
169
+ ArrayDeque.prototype.peekLast = function () {
112
170
  var _a;
113
171
  return (_a = this._nodes[this._nodes.length - 1]) !== null && _a !== void 0 ? _a : null;
114
- }
115
- get(index) {
172
+ };
173
+ /**
174
+ * The get function returns the element at the specified index in an array, or null if the index is out of bounds.
175
+ * @param {number} index - The index parameter is a number that represents the position of the element you want to
176
+ * retrieve from the array.
177
+ * @returns The method is returning the element at the specified index in the `_nodes` array. If the element exists, it
178
+ * will be returned. If the element does not exist (i.e., the index is out of bounds), `null` will be returned.
179
+ */
180
+ ArrayDeque.prototype.get = function (index) {
116
181
  var _a;
117
182
  return (_a = this._nodes[index]) !== null && _a !== void 0 ? _a : null;
118
- }
119
- set(index, value) {
183
+ };
184
+ /**
185
+ * The set function assigns a value to a specific index in an array.
186
+ * @param {number} index - The index parameter is a number that represents the position of the element in the array
187
+ * that you want to set a new value for.
188
+ * @param {T} value - The value parameter represents the new value that you want to set at the specified index in the
189
+ * _nodes array.
190
+ * @returns The value that is being set at the specified index in the `_nodes` array.
191
+ */
192
+ ArrayDeque.prototype.set = function (index, value) {
120
193
  return this._nodes[index] = value;
121
- }
122
- insert(index, value) {
194
+ };
195
+ /**
196
+ * The insert function adds a value at a specified index in an array.
197
+ * @param {number} index - The index parameter specifies the position at which the value should be inserted in the
198
+ * array. It is a number that represents the index of the array where the value should be inserted. The index starts
199
+ * from 0, so the first element of the array has an index of 0, the second element has
200
+ * @param {T} value - The value parameter represents the value that you want to insert into the array at the specified
201
+ * index.
202
+ * @returns The splice method returns an array containing the removed elements, if any. In this case, since no elements
203
+ * are being removed, an empty array will be returned.
204
+ */
205
+ ArrayDeque.prototype.insert = function (index, value) {
123
206
  return this._nodes.splice(index, 0, value);
124
- }
125
- remove(index) {
207
+ };
208
+ /**
209
+ * The remove function removes an element from an array at a specified index.
210
+ * @param {number} index - The index parameter specifies the position of the element to be removed from the array. It
211
+ * is a number that represents the index of the element to be removed.
212
+ * @returns The method is returning an array containing the removed element.
213
+ */
214
+ ArrayDeque.prototype.remove = function (index) {
126
215
  return this._nodes.splice(index, 1);
127
- }
128
- isEmpty() {
216
+ };
217
+ /**
218
+ * The function checks if an array called "_nodes" is empty.
219
+ * @returns The method `isEmpty()` is returning a boolean value. It returns `true` if the length of the `_nodes` array
220
+ * is 0, indicating that the array is empty. Otherwise, it returns `false`.
221
+ */
222
+ ArrayDeque.prototype.isEmpty = function () {
129
223
  return this._nodes.length === 0;
130
- }
131
- }
224
+ };
225
+ return ArrayDeque;
226
+ }());
132
227
  exports.ArrayDeque = ArrayDeque;
@@ -1,76 +1,73 @@
1
1
  /**
2
2
  * @license MIT
3
- * @copyright 2020 Pablo
4
- *
3
+ * @copyright 2030 Tyler Zeng <zrwusa@gmail.com>
5
4
  * @class
6
5
  */
7
6
  export declare class Queue<T> {
8
7
  protected _nodes: T[];
9
8
  protected _offset: number;
10
9
  /**
11
- * Creates a queue.
12
- * @param {array} [elements]
10
+ * The constructor initializes an instance of a class with an optional array of elements and sets the offset to 0.
11
+ * @param {T[]} [elements] - The `elements` parameter is an optional array of elements of type `T`. If provided, it
12
+ * will be used to initialize the `_nodes` property of the class. If not provided, the `_nodes` property will be
13
+ * initialized as an empty array.
13
14
  */
14
15
  constructor(elements?: T[]);
15
16
  /**
16
- * Adds an element at the back of the queue.
17
+ * The function "fromArray" creates a new Queue object from an array of elements.Creates a queue from an existing array.
17
18
  * @public
18
- * @param {any} element
19
+ * @static
20
+ * @param {T[]} elements - The "elements" parameter is an array of elements of type T.
21
+ * @returns The method is returning a new instance of the Queue class, initialized with the elements from the input
22
+ * array.
23
+ */
24
+ static fromArray<T>(elements: T[]): Queue<T>;
25
+ /**
26
+ * The offer function adds an element to the end of the queue and returns the updated queue.Adds an element at the back of the queue.
27
+ * @param {T} element - The `element` parameter represents the element that you want to add to the queue.
28
+ * @returns The `offer` method is returning a `Queue<T>` object.
19
29
  */
20
30
  offer(element: T): Queue<T>;
21
31
  /**
22
- * Dequeues the front element in the queue.
23
- * @public
24
- * @returns {any}
32
+ * The `poll` function removes and returns the first element in the queue, and adjusts the internal data structure if
33
+ * necessary to optimize performance.
34
+ * @returns The function `poll()` returns either the first element in the queue or `null` if the queue is empty.
25
35
  */
26
36
  poll(): T | null;
27
37
  /**
28
- * Returns the front element of the queue.
29
- * @public
30
- * @returns {any}
38
+ * The `peek` function returns the first element of the array `_nodes` if it exists, otherwise it returns `null`.
39
+ * @returns The `peek()` method returns the first element of the data structure, represented by the `_nodes` array at
40
+ * the `_offset` index. If the data structure is empty (size is 0), it returns `null`.
31
41
  */
32
42
  peek(): T | null;
33
43
  /**
34
- * Returns the back element of the queue.
35
- * @public
36
- * @returns {any}
44
+ * The `peekLast` function returns the last element in an array-like data structure, or null if the structure is empty.
45
+ * @returns The method `peekLast()` returns the last element of the `_nodes` array if the array is not empty. If the
46
+ * array is empty, it returns `null`.
37
47
  */
38
48
  peekLast(): T | null;
39
49
  /**
40
- * Returns the number of elements in the queue.
41
- * @public
42
- * @returns {number}
50
+ * The size function returns the number of elements in an array.
51
+ * @returns {number} The size of the array, which is the difference between the length of the array and the offset.
43
52
  */
44
53
  size(): number;
45
54
  /**
46
- * Checks if the queue is empty.
47
- * @public
48
- * @returns {boolean}
55
+ * The function checks if a data structure is empty by comparing its size to zero.
56
+ * @returns {boolean} A boolean value indicating whether the size of the object is 0 or not.
49
57
  */
50
58
  isEmpty(): boolean;
51
59
  /**
52
- * Returns the remaining elements in the queue as an array.
53
- * @public
54
- * @returns {array}
60
+ * The toArray() function returns an array of elements from the current offset to the end of the _nodes array.
61
+ * @returns An array of type T is being returned.
55
62
  */
56
63
  toArray(): T[];
57
64
  /**
58
- * Clears the queue.
59
- * @public
65
+ * The clear function resets the nodes array and offset to their initial values.
60
66
  */
61
67
  clear(): void;
62
68
  /**
63
- * Creates a shallow copy of the queue.
64
- * @public
65
- * @return {Queue}
69
+ * The `clone()` function returns a new Queue object with the same elements as the original Queue.
70
+ * @returns The `clone()` method is returning a new instance of the `Queue` class.
66
71
  */
67
72
  clone(): Queue<T>;
68
- /**
69
- * Creates a queue from an existing array.
70
- * @public
71
- * @static
72
- * @param {array} elements
73
- * @return {Queue}
74
- */
75
- static fromArray<T>(elements: T[]): Queue<T>;
76
73
  }
@@ -3,37 +3,49 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Queue = void 0;
4
4
  /**
5
5
  * @license MIT
6
- * @copyright 2020 Pablo
7
- *
6
+ * @copyright 2030 Tyler Zeng <zrwusa@gmail.com>
8
7
  * @class
9
8
  */
10
- class Queue {
9
+ var Queue = /** @class */ (function () {
11
10
  /**
12
- * Creates a queue.
13
- * @param {array} [elements]
11
+ * The constructor initializes an instance of a class with an optional array of elements and sets the offset to 0.
12
+ * @param {T[]} [elements] - The `elements` parameter is an optional array of elements of type `T`. If provided, it
13
+ * will be used to initialize the `_nodes` property of the class. If not provided, the `_nodes` property will be
14
+ * initialized as an empty array.
14
15
  */
15
- constructor(elements) {
16
+ function Queue(elements) {
16
17
  this._nodes = elements || [];
17
18
  this._offset = 0;
18
19
  }
19
20
  /**
20
- * Adds an element at the back of the queue.
21
+ * The function "fromArray" creates a new Queue object from an array of elements.Creates a queue from an existing array.
21
22
  * @public
22
- * @param {any} element
23
+ * @static
24
+ * @param {T[]} elements - The "elements" parameter is an array of elements of type T.
25
+ * @returns The method is returning a new instance of the Queue class, initialized with the elements from the input
26
+ * array.
27
+ */
28
+ Queue.fromArray = function (elements) {
29
+ return new Queue(elements);
30
+ };
31
+ /**
32
+ * The offer function adds an element to the end of the queue and returns the updated queue.Adds an element at the back of the queue.
33
+ * @param {T} element - The `element` parameter represents the element that you want to add to the queue.
34
+ * @returns The `offer` method is returning a `Queue<T>` object.
23
35
  */
24
- offer(element) {
36
+ Queue.prototype.offer = function (element) {
25
37
  this._nodes.push(element);
26
38
  return this;
27
- }
39
+ };
28
40
  /**
29
- * Dequeues the front element in the queue.
30
- * @public
31
- * @returns {any}
41
+ * The `poll` function removes and returns the first element in the queue, and adjusts the internal data structure if
42
+ * necessary to optimize performance.
43
+ * @returns The function `poll()` returns either the first element in the queue or `null` if the queue is empty.
32
44
  */
33
- poll() {
45
+ Queue.prototype.poll = function () {
34
46
  if (this.size() === 0)
35
47
  return null;
36
- const first = this.peek();
48
+ var first = this.peek();
37
49
  this._offset += 1;
38
50
  if (this._offset * 2 < this._nodes.length)
39
51
  return first;
@@ -42,72 +54,58 @@ class Queue {
42
54
  this._nodes = this._nodes.slice(this._offset);
43
55
  this._offset = 0;
44
56
  return first;
45
- }
57
+ };
46
58
  /**
47
- * Returns the front element of the queue.
48
- * @public
49
- * @returns {any}
59
+ * The `peek` function returns the first element of the array `_nodes` if it exists, otherwise it returns `null`.
60
+ * @returns The `peek()` method returns the first element of the data structure, represented by the `_nodes` array at
61
+ * the `_offset` index. If the data structure is empty (size is 0), it returns `null`.
50
62
  */
51
- peek() {
63
+ Queue.prototype.peek = function () {
52
64
  return this.size() > 0 ? this._nodes[this._offset] : null;
53
- }
65
+ };
54
66
  /**
55
- * Returns the back element of the queue.
56
- * @public
57
- * @returns {any}
67
+ * The `peekLast` function returns the last element in an array-like data structure, or null if the structure is empty.
68
+ * @returns The method `peekLast()` returns the last element of the `_nodes` array if the array is not empty. If the
69
+ * array is empty, it returns `null`.
58
70
  */
59
- peekLast() {
71
+ Queue.prototype.peekLast = function () {
60
72
  return this.size() > 0 ? this._nodes[this._nodes.length - 1] : null;
61
- }
73
+ };
62
74
  /**
63
- * Returns the number of elements in the queue.
64
- * @public
65
- * @returns {number}
75
+ * The size function returns the number of elements in an array.
76
+ * @returns {number} The size of the array, which is the difference between the length of the array and the offset.
66
77
  */
67
- size() {
78
+ Queue.prototype.size = function () {
68
79
  return this._nodes.length - this._offset;
69
- }
80
+ };
70
81
  /**
71
- * Checks if the queue is empty.
72
- * @public
73
- * @returns {boolean}
82
+ * The function checks if a data structure is empty by comparing its size to zero.
83
+ * @returns {boolean} A boolean value indicating whether the size of the object is 0 or not.
74
84
  */
75
- isEmpty() {
85
+ Queue.prototype.isEmpty = function () {
76
86
  return this.size() === 0;
77
- }
87
+ };
78
88
  /**
79
- * Returns the remaining elements in the queue as an array.
80
- * @public
81
- * @returns {array}
89
+ * The toArray() function returns an array of elements from the current offset to the end of the _nodes array.
90
+ * @returns An array of type T is being returned.
82
91
  */
83
- toArray() {
92
+ Queue.prototype.toArray = function () {
84
93
  return this._nodes.slice(this._offset);
85
- }
94
+ };
86
95
  /**
87
- * Clears the queue.
88
- * @public
96
+ * The clear function resets the nodes array and offset to their initial values.
89
97
  */
90
- clear() {
98
+ Queue.prototype.clear = function () {
91
99
  this._nodes = [];
92
100
  this._offset = 0;
93
- }
101
+ };
94
102
  /**
95
- * Creates a shallow copy of the queue.
96
- * @public
97
- * @return {Queue}
103
+ * The `clone()` function returns a new Queue object with the same elements as the original Queue.
104
+ * @returns The `clone()` method is returning a new instance of the `Queue` class.
98
105
  */
99
- clone() {
106
+ Queue.prototype.clone = function () {
100
107
  return new Queue(this._nodes.slice(this._offset));
101
- }
102
- /**
103
- * Creates a queue from an existing array.
104
- * @public
105
- * @static
106
- * @param {array} elements
107
- * @return {Queue}
108
- */
109
- static fromArray(elements) {
110
- return new Queue(elements);
111
- }
112
- }
108
+ };
109
+ return Queue;
110
+ }());
113
111
  exports.Queue = Queue;
@@ -1,69 +1,63 @@
1
1
  /**
2
2
  * @license MIT
3
- * @copyright 2020 Pablo Rios <zrwusa@gmail.com>
4
- *
3
+ * @copyright 2030 Tyler Zeng <zrwusa@gmail.com>
5
4
  * @class
6
5
  */
7
6
  export declare class Stack<T> {
8
7
  protected _elements: T[];
9
8
  /**
10
- * Creates a stack.
11
- * @param {array} [elements]
9
+ * The constructor initializes an array of elements, which can be provided as an optional parameter.
10
+ * @param {T[]} [elements] - The `elements` parameter is an optional parameter of type `T[]`, which represents an array
11
+ * of elements of type `T`. It is used to initialize the `_elements` property of the class. If the `elements` parameter
12
+ * is provided and is an array, it is assigned to the `_elements
12
13
  */
13
14
  constructor(elements?: T[]);
14
15
  /**
15
- * Checks if the stack is empty.
16
- * @public
17
- * @returns {boolean}
16
+ * The function "fromArray" creates a new Stack object from an array of elements.
17
+ * @param {T[]} elements - The `elements` parameter is an array of elements of type `T`.
18
+ * @returns {Stack} The method is returning a new instance of the Stack class, initialized with the elements from the input
19
+ * array.
20
+ */
21
+ static fromArray<T>(elements: T[]): Stack<T>;
22
+ /**
23
+ * The function checks if an array is empty and returns a boolean value.
24
+ * @returns A boolean value indicating whether the `_elements` array is empty or not.
18
25
  */
19
26
  isEmpty(): boolean;
20
27
  /**
21
- * Returns the number of elements in the stack.
22
- * @public
23
- * @returns {number}
28
+ * The size() function returns the number of elements in an array.
29
+ * @returns The size of the elements array.
24
30
  */
25
31
  size(): number;
26
32
  /**
27
- * Returns the top element in the stack.
28
- * @public
29
- * @returns {object}
33
+ * The `peek` function returns the last element of an array, or null if the array is empty.
34
+ * @returns The `peek()` function returns the last element of the `_elements` array, or `null` if the array is empty.
30
35
  */
31
36
  peek(): T | null;
32
37
  /**
33
- * Adds an element to the top of the stack.
34
- * @public
35
- * @param {object} element
38
+ * The push function adds an element to the stack and returns the updated stack.
39
+ * @param {T} element - The parameter "element" is of type T, which means it can be any data type.
40
+ * @returns The `push` method is returning the updated `Stack<T>` object.
36
41
  */
37
42
  push(element: T): Stack<T>;
38
43
  /**
39
- * Removes and returns the top element in the stack.
40
- * @public
41
- * @returns {object}
44
+ * The `pop` function removes and returns the last element from an array, or returns null if the array is empty.
45
+ * @returns The `pop()` method is returning the last element of the array `_elements` if the array is not empty. If the
46
+ * array is empty, it returns `null`.
42
47
  */
43
48
  pop(): T | null;
44
49
  /**
45
- * Returns the remaining elements as an array.
46
- * @public
47
- * @returns {array}
50
+ * The toArray function returns a copy of the elements in an array.
51
+ * @returns An array of type T.
48
52
  */
49
53
  toArray(): T[];
50
54
  /**
51
- * Clears all elements from the stack.
52
- * @public
55
+ * The clear function clears the elements array.
53
56
  */
54
57
  clear(): void;
55
58
  /**
56
- * Creates a shallow copy from the stack.
57
- * @public
58
- * @return {Stack}
59
+ * The `clone()` function returns a new `Stack` object with the same elements as the original stack.
60
+ * @returns The `clone()` method is returning a new `Stack` object with a copy of the `_elements` array.
59
61
  */
60
62
  clone(): Stack<T>;
61
- /**
62
- * Creates a stack from an existing array
63
- * @public
64
- * @static
65
- * @param {array} [elements]
66
- * @return {Stack}
67
- */
68
- static fromArray<T>(elements: T[]): Stack<T>;
69
63
  }