data-structure-typed 0.9.16 → 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 (199) hide show
  1. package/.dependency-cruiser.js +449 -0
  2. package/.idea/data-structure-typed.iml +2 -0
  3. package/README.md +102 -1
  4. package/dist/data-structures/binary-tree/avl-tree.d.ts +57 -0
  5. package/dist/data-structures/binary-tree/avl-tree.js +57 -0
  6. package/dist/data-structures/binary-tree/binary-indexed-tree.d.ts +27 -0
  7. package/dist/data-structures/binary-tree/binary-indexed-tree.js +27 -0
  8. package/dist/data-structures/binary-tree/binary-tree.d.ts +215 -9
  9. package/dist/data-structures/binary-tree/binary-tree.js +283 -15
  10. package/dist/data-structures/binary-tree/bst.d.ts +16 -0
  11. package/dist/data-structures/binary-tree/bst.js +12 -0
  12. package/dist/data-structures/binary-tree/segment-tree.d.ts +4 -0
  13. package/dist/data-structures/binary-tree/segment-tree.js +4 -0
  14. package/dist/data-structures/binary-tree/tree-multiset.d.ts +4 -0
  15. package/dist/data-structures/binary-tree/tree-multiset.js +4 -0
  16. package/dist/data-structures/graph/abstract-graph.d.ts +163 -13
  17. package/dist/data-structures/graph/abstract-graph.js +166 -12
  18. package/dist/data-structures/graph/directed-graph.d.ts +111 -1
  19. package/dist/data-structures/graph/directed-graph.js +122 -0
  20. package/dist/data-structures/graph/undirected-graph.d.ts +63 -0
  21. package/dist/data-structures/graph/undirected-graph.js +67 -0
  22. package/dist/data-structures/hash/coordinate-map.d.ts +32 -0
  23. package/dist/data-structures/hash/coordinate-map.js +32 -0
  24. package/dist/data-structures/hash/coordinate-set.d.ts +25 -0
  25. package/dist/data-structures/hash/coordinate-set.js +25 -0
  26. package/dist/data-structures/heap/heap.d.ts +26 -31
  27. package/dist/data-structures/heap/heap.js +23 -32
  28. package/dist/data-structures/heap/max-heap.d.ts +6 -1
  29. package/dist/data-structures/heap/max-heap.js +6 -1
  30. package/dist/data-structures/heap/min-heap.d.ts +7 -1
  31. package/dist/data-structures/heap/min-heap.js +7 -1
  32. package/dist/data-structures/index.d.ts +0 -1
  33. package/dist/data-structures/index.js +0 -1
  34. package/dist/data-structures/linked-list/doubly-linked-list.d.ts +14 -6
  35. package/dist/data-structures/linked-list/doubly-linked-list.js +45 -8
  36. package/dist/data-structures/linked-list/singly-linked-list.d.ts +11 -8
  37. package/dist/data-structures/linked-list/singly-linked-list.js +4 -0
  38. package/dist/data-structures/matrix/matrix.d.ts +9 -0
  39. package/dist/data-structures/matrix/matrix.js +11 -0
  40. package/dist/data-structures/matrix/matrix2d.d.ts +82 -2
  41. package/dist/data-structures/matrix/matrix2d.js +82 -2
  42. package/dist/data-structures/matrix/navigator.d.ts +32 -0
  43. package/dist/data-structures/matrix/navigator.js +28 -0
  44. package/dist/data-structures/matrix/vector2d.d.ts +139 -15
  45. package/dist/data-structures/matrix/vector2d.js +139 -15
  46. package/dist/data-structures/priority-queue/max-priority-queue.d.ts +8 -0
  47. package/dist/data-structures/priority-queue/max-priority-queue.js +8 -0
  48. package/dist/data-structures/priority-queue/min-priority-queue.d.ts +8 -0
  49. package/dist/data-structures/priority-queue/min-priority-queue.js +8 -0
  50. package/dist/data-structures/priority-queue/priority-queue.d.ts +130 -0
  51. package/dist/data-structures/priority-queue/priority-queue.js +126 -0
  52. package/dist/data-structures/queue/deque.d.ts +69 -0
  53. package/dist/data-structures/queue/deque.js +69 -0
  54. package/dist/data-structures/queue/queue.d.ts +30 -32
  55. package/dist/data-structures/queue/queue.js +30 -32
  56. package/dist/data-structures/stack/stack.d.ts +26 -31
  57. package/dist/data-structures/stack/stack.js +26 -31
  58. package/dist/data-structures/trie/trie.d.ts +26 -6
  59. package/dist/data-structures/trie/trie.js +26 -7
  60. package/dist/data-structures/types/avl-tree.d.ts +1 -1
  61. package/dist/data-structures/types/binary-tree.d.ts +1 -1
  62. package/dist/data-structures/types/index.d.ts +1 -1
  63. package/dist/data-structures/types/index.js +1 -1
  64. package/dist/data-structures/types/singly-linked-list.d.ts +1 -5
  65. package/dist/data-structures/types/tree-multiset.d.ts +1 -1
  66. package/dist/{data-structures → utils}/trampoline.d.ts +5 -7
  67. package/dist/utils/types/index.d.ts +1 -0
  68. package/dist/utils/types/index.js +17 -0
  69. package/dist/{data-structures → utils}/types/utils.d.ts +8 -0
  70. package/dist/{data-structures → utils}/types/utils.js +1 -0
  71. package/dist/utils/utils.d.ts +1 -1
  72. package/docs/.nojekyll +1 -0
  73. package/docs/assets/highlight.css +85 -0
  74. package/docs/assets/main.js +58 -0
  75. package/docs/assets/search.js +1 -0
  76. package/docs/assets/style.css +1367 -0
  77. package/docs/classes/AVLTree.html +2046 -0
  78. package/docs/classes/AVLTreeNode.html +423 -0
  79. package/docs/classes/AaTree.html +117 -0
  80. package/docs/classes/AbstractEdge.html +198 -0
  81. package/docs/classes/AbstractGraph.html +891 -0
  82. package/docs/classes/AbstractVertex.html +164 -0
  83. package/docs/classes/ArrayDeque.html +384 -0
  84. package/docs/classes/BST.html +1893 -0
  85. package/docs/classes/BSTNode.html +425 -0
  86. package/docs/classes/BTree.html +117 -0
  87. package/docs/classes/BinaryIndexedTree.html +244 -0
  88. package/docs/classes/BinaryTree.html +1754 -0
  89. package/docs/classes/BinaryTreeNode.html +396 -0
  90. package/docs/classes/Character.html +165 -0
  91. package/docs/classes/CoordinateMap.html +394 -0
  92. package/docs/classes/CoordinateSet.html +355 -0
  93. package/docs/classes/Deque.html +617 -0
  94. package/docs/classes/DirectedEdge.html +247 -0
  95. package/docs/classes/DirectedGraph.html +1207 -0
  96. package/docs/classes/DirectedVertex.html +154 -0
  97. package/docs/classes/DoublyLinkedList.html +619 -0
  98. package/docs/classes/DoublyLinkedListNode.html +160 -0
  99. package/docs/classes/Heap.html +315 -0
  100. package/docs/classes/Matrix2D.html +447 -0
  101. package/docs/classes/MatrixNTI2D.html +181 -0
  102. package/docs/classes/MaxHeap.html +325 -0
  103. package/docs/classes/MaxPriorityQueue.html +668 -0
  104. package/docs/classes/MinHeap.html +326 -0
  105. package/docs/classes/MinPriorityQueue.html +668 -0
  106. package/docs/classes/Navigator.html +285 -0
  107. package/docs/classes/ObjectDeque.html +289 -0
  108. package/docs/classes/PriorityQueue.html +643 -0
  109. package/docs/classes/Queue.html +337 -0
  110. package/docs/classes/RBTree.html +117 -0
  111. package/docs/classes/SegmentTree.html +234 -0
  112. package/docs/classes/SegmentTreeNode.html +302 -0
  113. package/docs/classes/SinglyLinkedList.html +1035 -0
  114. package/docs/classes/SinglyLinkedListNode.html +304 -0
  115. package/docs/classes/SplayTree.html +117 -0
  116. package/docs/classes/Stack.html +313 -0
  117. package/docs/classes/TreeMultiSet.html +1897 -0
  118. package/docs/classes/Trie.html +317 -0
  119. package/docs/classes/TrieNode.html +221 -0
  120. package/docs/classes/TwoThreeTree.html +117 -0
  121. package/docs/classes/UndirectedEdge.html +220 -0
  122. package/docs/classes/UndirectedGraph.html +1006 -0
  123. package/docs/classes/UndirectedVertex.html +154 -0
  124. package/docs/classes/Vector2D.html +746 -0
  125. package/docs/enums/CP.html +126 -0
  126. package/docs/enums/FamilyPosition.html +126 -0
  127. package/docs/enums/LoopType.html +119 -0
  128. package/docs/index.html +288 -0
  129. package/docs/modules.html +146 -0
  130. package/jest.config.js +5 -0
  131. package/package.json +19 -11
  132. package/rename_clear_files.sh +29 -0
  133. package/src/assets/complexities-diff.jpg +0 -0
  134. package/src/assets/data-structure-complexities.jpg +0 -0
  135. package/src/data-structures/binary-tree/avl-tree.ts +57 -0
  136. package/src/data-structures/binary-tree/binary-indexed-tree.ts +27 -0
  137. package/src/data-structures/binary-tree/binary-tree.ts +288 -18
  138. package/src/data-structures/binary-tree/bst.ts +16 -1
  139. package/src/data-structures/binary-tree/segment-tree.ts +5 -0
  140. package/src/data-structures/binary-tree/tree-multiset.ts +4 -0
  141. package/src/data-structures/diagrams/README.md +5 -7
  142. package/src/data-structures/graph/abstract-graph.ts +167 -15
  143. package/src/data-structures/graph/diagrams/adjacency-list-pros-cons.jpg +0 -0
  144. package/src/data-structures/graph/diagrams/adjacency-list.jpg +0 -0
  145. package/src/data-structures/graph/diagrams/adjacency-matrix-pros-cons.jpg +0 -0
  146. package/src/data-structures/graph/diagrams/adjacency-matrix.jpg +0 -0
  147. package/src/data-structures/graph/diagrams/dfs-can-do.jpg +0 -0
  148. package/src/data-structures/graph/diagrams/edge-list-pros-cons.jpg +0 -0
  149. package/src/data-structures/graph/diagrams/edge-list.jpg +0 -0
  150. package/src/data-structures/graph/diagrams/max-flow.jpg +0 -0
  151. package/src/data-structures/graph/diagrams/mst.jpg +0 -0
  152. package/src/data-structures/graph/diagrams/tarjan.webp +0 -0
  153. package/src/data-structures/graph/directed-graph.ts +127 -5
  154. package/src/data-structures/graph/undirected-graph.ts +67 -1
  155. package/src/data-structures/hash/coordinate-map.ts +32 -0
  156. package/src/data-structures/hash/coordinate-set.ts +25 -0
  157. package/src/data-structures/heap/heap.ts +27 -32
  158. package/src/data-structures/heap/max-heap.ts +6 -1
  159. package/src/data-structures/heap/min-heap.ts +7 -1
  160. package/src/data-structures/index.ts +0 -1
  161. package/src/data-structures/linked-list/doubly-linked-list.ts +49 -8
  162. package/src/data-structures/linked-list/singly-linked-list.ts +39 -8
  163. package/src/data-structures/matrix/matrix.ts +11 -0
  164. package/src/data-structures/matrix/matrix2d.ts +82 -2
  165. package/src/data-structures/matrix/navigator.ts +32 -0
  166. package/src/data-structures/matrix/vector2d.ts +139 -15
  167. package/src/data-structures/priority-queue/max-priority-queue.ts +8 -0
  168. package/src/data-structures/priority-queue/min-priority-queue.ts +8 -0
  169. package/src/data-structures/priority-queue/priority-queue.ts +130 -0
  170. package/src/data-structures/queue/deque.ts +69 -0
  171. package/src/data-structures/queue/queue.ts +30 -32
  172. package/src/data-structures/stack/stack.ts +26 -31
  173. package/src/data-structures/trie/trie.ts +26 -7
  174. package/src/data-structures/types/avl-tree.ts +1 -1
  175. package/src/data-structures/types/binary-tree.ts +1 -1
  176. package/src/data-structures/types/bst.ts +1 -1
  177. package/src/data-structures/types/index.ts +1 -1
  178. package/src/data-structures/types/navigator.ts +1 -0
  179. package/src/data-structures/types/singly-linked-list.ts +1 -15
  180. package/src/data-structures/types/tree-multiset.ts +1 -1
  181. package/src/{data-structures → utils}/trampoline.ts +6 -6
  182. package/src/utils/types/index.ts +1 -0
  183. package/src/{data-structures → utils}/types/utils.ts +7 -0
  184. package/src/utils/utils.ts +12 -2
  185. package/tests/unit/data-structures/binary-tree/bst.test.ts +185 -0
  186. package/tests/unit/data-structures/graph/abstract-graph.ts +0 -0
  187. package/tests/unit/data-structures/graph/directed-graph.test.ts +71 -0
  188. package/tests/unit/data-structures/graph/index.ts +3 -0
  189. package/tests/unit/data-structures/graph/undirected-graph.ts +0 -0
  190. package/src/data-structures/graph/diagrams/adjacency-list-pros-cons.png +0 -0
  191. package/src/data-structures/graph/diagrams/adjacency-list.png +0 -0
  192. package/src/data-structures/graph/diagrams/adjacency-matrix-pros-cons.png +0 -0
  193. package/src/data-structures/graph/diagrams/adjacency-matrix.png +0 -0
  194. package/src/data-structures/graph/diagrams/dfs-can-do.png +0 -0
  195. package/src/data-structures/graph/diagrams/edge-list-pros-cons.png +0 -0
  196. package/src/data-structures/graph/diagrams/edge-list.png +0 -0
  197. package/src/data-structures/graph/diagrams/max-flow.png +0 -0
  198. package/src/data-structures/graph/diagrams/mst.png +0 -0
  199. /package/dist/{data-structures → utils}/trampoline.js +0 -0
@@ -3,41 +3,44 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Queue = void 0;
4
4
  /**
5
5
  * @license MIT
6
- * @copyright 2020 Tyler Zeng <zrwusa@gmail.com>
6
+ * @copyright 2030 Tyler Zeng <zrwusa@gmail.com>
7
7
  * @class
8
8
  */
9
9
  var Queue = /** @class */ (function () {
10
10
  /**
11
- * Creates a queue.
12
- * @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.
13
15
  */
14
16
  function Queue(elements) {
15
17
  this._nodes = elements || [];
16
18
  this._offset = 0;
17
19
  }
18
20
  /**
19
- * Creates a queue from an existing array.
21
+ * The function "fromArray" creates a new Queue object from an array of elements.Creates a queue from an existing array.
20
22
  * @public
21
23
  * @static
22
- * @param {array} elements
23
- * @return {Queue}
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.
24
27
  */
25
28
  Queue.fromArray = function (elements) {
26
29
  return new Queue(elements);
27
30
  };
28
31
  /**
29
- * Adds an element at the back of the queue.
30
- * @public
31
- * @param {any} element
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.
32
35
  */
33
36
  Queue.prototype.offer = function (element) {
34
37
  this._nodes.push(element);
35
38
  return this;
36
39
  };
37
40
  /**
38
- * Dequeues the front element in the queue.
39
- * @public
40
- * @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.
41
44
  */
42
45
  Queue.prototype.poll = function () {
43
46
  if (this.size() === 0)
@@ -53,57 +56,52 @@ var Queue = /** @class */ (function () {
53
56
  return first;
54
57
  };
55
58
  /**
56
- * Returns the front element of the queue.
57
- * @public
58
- * @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`.
59
62
  */
60
63
  Queue.prototype.peek = function () {
61
64
  return this.size() > 0 ? this._nodes[this._offset] : null;
62
65
  };
63
66
  /**
64
- * Returns the back element of the queue.
65
- * @public
66
- * @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`.
67
70
  */
68
71
  Queue.prototype.peekLast = function () {
69
72
  return this.size() > 0 ? this._nodes[this._nodes.length - 1] : null;
70
73
  };
71
74
  /**
72
- * Returns the number of elements in the queue.
73
- * @public
74
- * @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.
75
77
  */
76
78
  Queue.prototype.size = function () {
77
79
  return this._nodes.length - this._offset;
78
80
  };
79
81
  /**
80
- * Checks if the queue is empty.
81
- * @public
82
- * @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.
83
84
  */
84
85
  Queue.prototype.isEmpty = function () {
85
86
  return this.size() === 0;
86
87
  };
87
88
  /**
88
- * Returns the remaining elements in the queue as an array.
89
- * @public
90
- * @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.
91
91
  */
92
92
  Queue.prototype.toArray = function () {
93
93
  return this._nodes.slice(this._offset);
94
94
  };
95
95
  /**
96
- * Clears the queue.
97
- * @public
96
+ * The clear function resets the nodes array and offset to their initial values.
98
97
  */
99
98
  Queue.prototype.clear = function () {
100
99
  this._nodes = [];
101
100
  this._offset = 0;
102
101
  };
103
102
  /**
104
- * Creates a shallow copy of the queue.
105
- * @public
106
- * @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.
107
105
  */
108
106
  Queue.prototype.clone = function () {
109
107
  return new Queue(this._nodes.slice(this._offset));
@@ -1,68 +1,63 @@
1
1
  /**
2
2
  * @license MIT
3
- * @copyright 2020 Tyler Zeng <zrwusa@gmail.com>
3
+ * @copyright 2030 Tyler Zeng <zrwusa@gmail.com>
4
4
  * @class
5
5
  */
6
6
  export declare class Stack<T> {
7
7
  protected _elements: T[];
8
8
  /**
9
- * Creates a stack.
10
- * @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
11
13
  */
12
14
  constructor(elements?: T[]);
13
15
  /**
14
- * Creates a stack from an existing array
15
- * @public
16
- * @static
17
- * @param {array} [elements]
18
- * @return {Stack}
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.
19
20
  */
20
21
  static fromArray<T>(elements: T[]): Stack<T>;
21
22
  /**
22
- * Checks if the stack is empty.
23
- * @public
24
- * @returns {boolean}
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.
25
25
  */
26
26
  isEmpty(): boolean;
27
27
  /**
28
- * Returns the number of elements in the stack.
29
- * @public
30
- * @returns {number}
28
+ * The size() function returns the number of elements in an array.
29
+ * @returns The size of the elements array.
31
30
  */
32
31
  size(): number;
33
32
  /**
34
- * Returns the top element in the stack.
35
- * @public
36
- * @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.
37
35
  */
38
36
  peek(): T | null;
39
37
  /**
40
- * Adds an element to the top of the stack.
41
- * @public
42
- * @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.
43
41
  */
44
42
  push(element: T): Stack<T>;
45
43
  /**
46
- * Removes and returns the top element in the stack.
47
- * @public
48
- * @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`.
49
47
  */
50
48
  pop(): T | null;
51
49
  /**
52
- * Returns the remaining elements as an array.
53
- * @public
54
- * @returns {array}
50
+ * The toArray function returns a copy of the elements in an array.
51
+ * @returns An array of type T.
55
52
  */
56
53
  toArray(): T[];
57
54
  /**
58
- * Clears all elements from the stack.
59
- * @public
55
+ * The clear function clears the elements array.
60
56
  */
61
57
  clear(): void;
62
58
  /**
63
- * Creates a shallow copy from the stack.
64
- * @public
65
- * @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.
66
61
  */
67
62
  clone(): Stack<T>;
68
63
  }
@@ -3,47 +3,45 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Stack = void 0;
4
4
  /**
5
5
  * @license MIT
6
- * @copyright 2020 Tyler Zeng <zrwusa@gmail.com>
6
+ * @copyright 2030 Tyler Zeng <zrwusa@gmail.com>
7
7
  * @class
8
8
  */
9
9
  var Stack = /** @class */ (function () {
10
10
  /**
11
- * Creates a stack.
12
- * @param {array} [elements]
11
+ * The constructor initializes an array of elements, which can be provided as an optional parameter.
12
+ * @param {T[]} [elements] - The `elements` parameter is an optional parameter of type `T[]`, which represents an array
13
+ * of elements of type `T`. It is used to initialize the `_elements` property of the class. If the `elements` parameter
14
+ * is provided and is an array, it is assigned to the `_elements
13
15
  */
14
16
  function Stack(elements) {
15
17
  this._elements = Array.isArray(elements) ? elements : [];
16
18
  }
17
19
  /**
18
- * Creates a stack from an existing array
19
- * @public
20
- * @static
21
- * @param {array} [elements]
22
- * @return {Stack}
20
+ * The function "fromArray" creates a new Stack object from an array of elements.
21
+ * @param {T[]} elements - The `elements` parameter is an array of elements of type `T`.
22
+ * @returns {Stack} The method is returning a new instance of the Stack class, initialized with the elements from the input
23
+ * array.
23
24
  */
24
25
  Stack.fromArray = function (elements) {
25
26
  return new Stack(elements);
26
27
  };
27
28
  /**
28
- * Checks if the stack is empty.
29
- * @public
30
- * @returns {boolean}
29
+ * The function checks if an array is empty and returns a boolean value.
30
+ * @returns A boolean value indicating whether the `_elements` array is empty or not.
31
31
  */
32
32
  Stack.prototype.isEmpty = function () {
33
33
  return this._elements.length === 0;
34
34
  };
35
35
  /**
36
- * Returns the number of elements in the stack.
37
- * @public
38
- * @returns {number}
36
+ * The size() function returns the number of elements in an array.
37
+ * @returns The size of the elements array.
39
38
  */
40
39
  Stack.prototype.size = function () {
41
40
  return this._elements.length;
42
41
  };
43
42
  /**
44
- * Returns the top element in the stack.
45
- * @public
46
- * @returns {object}
43
+ * The `peek` function returns the last element of an array, or null if the array is empty.
44
+ * @returns The `peek()` function returns the last element of the `_elements` array, or `null` if the array is empty.
47
45
  */
48
46
  Stack.prototype.peek = function () {
49
47
  if (this.isEmpty())
@@ -51,18 +49,18 @@ var Stack = /** @class */ (function () {
51
49
  return this._elements[this._elements.length - 1];
52
50
  };
53
51
  /**
54
- * Adds an element to the top of the stack.
55
- * @public
56
- * @param {object} element
52
+ * The push function adds an element to the stack and returns the updated stack.
53
+ * @param {T} element - The parameter "element" is of type T, which means it can be any data type.
54
+ * @returns The `push` method is returning the updated `Stack<T>` object.
57
55
  */
58
56
  Stack.prototype.push = function (element) {
59
57
  this._elements.push(element);
60
58
  return this;
61
59
  };
62
60
  /**
63
- * Removes and returns the top element in the stack.
64
- * @public
65
- * @returns {object}
61
+ * The `pop` function removes and returns the last element from an array, or returns null if the array is empty.
62
+ * @returns The `pop()` method is returning the last element of the array `_elements` if the array is not empty. If the
63
+ * array is empty, it returns `null`.
66
64
  */
67
65
  Stack.prototype.pop = function () {
68
66
  if (this.isEmpty())
@@ -70,24 +68,21 @@ var Stack = /** @class */ (function () {
70
68
  return this._elements.pop() || null;
71
69
  };
72
70
  /**
73
- * Returns the remaining elements as an array.
74
- * @public
75
- * @returns {array}
71
+ * The toArray function returns a copy of the elements in an array.
72
+ * @returns An array of type T.
76
73
  */
77
74
  Stack.prototype.toArray = function () {
78
75
  return this._elements.slice();
79
76
  };
80
77
  /**
81
- * Clears all elements from the stack.
82
- * @public
78
+ * The clear function clears the elements array.
83
79
  */
84
80
  Stack.prototype.clear = function () {
85
81
  this._elements = [];
86
82
  };
87
83
  /**
88
- * Creates a shallow copy from the stack.
89
- * @public
90
- * @return {Stack}
84
+ * The `clone()` function returns a new `Stack` object with the same elements as the original stack.
85
+ * @returns The `clone()` method is returning a new `Stack` object with a copy of the `_elements` array.
91
86
  */
92
87
  Stack.prototype.clone = function () {
93
88
  return new Stack(this._elements.slice());
@@ -1,3 +1,7 @@
1
+ /**
2
+ * @copyright 2030 Tyler Zeng <zrwusa@gmail.com>
3
+ * @license MIT
4
+ */
1
5
  export declare class TrieNode {
2
6
  protected _value: string;
3
7
  constructor(v: string);
@@ -19,20 +23,36 @@ export declare class Trie {
19
23
  has(input: string): boolean;
20
24
  remove(word: string): boolean;
21
25
  /**
22
- * Only can present as a prefix, not a word
23
- * @param input
26
+ * The function checks if a given input string has an absolute prefix in a tree data structure.Only can present as a prefix, not a word
27
+ * @param {string} input - The input parameter is a string that represents the input value for the function.
28
+ * @returns a boolean value.
24
29
  */
25
30
  isAbsPrefix(input: string): boolean;
26
31
  /**
27
- * Can present as a abs prefix or word
28
- * @param input
32
+ * The function checks if a given input string is a prefix of any existing string in a tree structure.Can present as a abs prefix or word
33
+ * @param {string} input - The input parameter is a string that represents the prefix we want to check.
34
+ * @returns a boolean value.
29
35
  */
30
36
  isPrefix(input: string): boolean;
31
37
  /**
32
- * Check if the input string is the common prefix of all the words
33
- * @param input
38
+ * The function checks if the input string is a common prefix in a Trie data structure.Check if the input string is the common prefix of all the words
39
+ * @param {string} input - The input parameter is a string that represents the common prefix that we want to check for
40
+ * in the Trie data structure.
41
+ * @returns a boolean value indicating whether the input string is a common prefix in the Trie data structure.
34
42
  */
35
43
  isCommonPrefix(input: string): boolean;
44
+ /**
45
+ * The function `getLongestCommonPrefix` returns the longest common prefix among all the words stored in a Trie data
46
+ * structure.
47
+ * @returns The function `getLongestCommonPrefix` returns a string, which is the longest common prefix found in the
48
+ * Trie.
49
+ */
36
50
  getLongestCommonPrefix(): string;
51
+ /**
52
+ * The `getAll` function returns an array of all words in a Trie data structure that start with a given prefix.
53
+ * @param [prefix] - The `prefix` parameter is a string that represents the prefix that we want to search for in the
54
+ * trie. It is an optional parameter, so if no prefix is provided, it will default to an empty string.
55
+ * @returns an array of strings.
56
+ */
37
57
  getAll(prefix?: string): string[];
38
58
  }
@@ -12,6 +12,10 @@ var __values = (this && this.__values) || function(o) {
12
12
  };
13
13
  Object.defineProperty(exports, "__esModule", { value: true });
14
14
  exports.Trie = exports.TrieNode = void 0;
15
+ /**
16
+ * @copyright 2030 Tyler Zeng <zrwusa@gmail.com>
17
+ * @license MIT
18
+ */
15
19
  var TrieNode = /** @class */ (function () {
16
20
  function TrieNode(v) {
17
21
  this._value = v;
@@ -159,8 +163,9 @@ var Trie = /** @class */ (function () {
159
163
  };
160
164
  // --- start additional methods ---
161
165
  /**
162
- * Only can present as a prefix, not a word
163
- * @param input
166
+ * The function checks if a given input string has an absolute prefix in a tree data structure.Only can present as a prefix, not a word
167
+ * @param {string} input - The input parameter is a string that represents the input value for the function.
168
+ * @returns a boolean value.
164
169
  */
165
170
  Trie.prototype.isAbsPrefix = function (input) {
166
171
  var e_4, _a;
@@ -184,8 +189,9 @@ var Trie = /** @class */ (function () {
184
189
  return !cur.isEnd;
185
190
  };
186
191
  /**
187
- * Can present as a abs prefix or word
188
- * @param input
192
+ * The function checks if a given input string is a prefix of any existing string in a tree structure.Can present as a abs prefix or word
193
+ * @param {string} input - The input parameter is a string that represents the prefix we want to check.
194
+ * @returns a boolean value.
189
195
  */
190
196
  Trie.prototype.isPrefix = function (input) {
191
197
  var e_5, _a;
@@ -209,8 +215,10 @@ var Trie = /** @class */ (function () {
209
215
  return true;
210
216
  };
211
217
  /**
212
- * Check if the input string is the common prefix of all the words
213
- * @param input
218
+ * The function checks if the input string is a common prefix in a Trie data structure.Check if the input string is the common prefix of all the words
219
+ * @param {string} input - The input parameter is a string that represents the common prefix that we want to check for
220
+ * in the Trie data structure.
221
+ * @returns a boolean value indicating whether the input string is a common prefix in the Trie data structure.
214
222
  */
215
223
  Trie.prototype.isCommonPrefix = function (input) {
216
224
  var commonPre = '';
@@ -228,7 +236,12 @@ var Trie = /** @class */ (function () {
228
236
  dfs(this._root);
229
237
  return commonPre === input;
230
238
  };
231
- // Retrieve the longest common prefix of all the words
239
+ /**
240
+ * The function `getLongestCommonPrefix` returns the longest common prefix among all the words stored in a Trie data
241
+ * structure.
242
+ * @returns The function `getLongestCommonPrefix` returns a string, which is the longest common prefix found in the
243
+ * Trie.
244
+ */
232
245
  Trie.prototype.getLongestCommonPrefix = function () {
233
246
  var commonPre = '';
234
247
  var dfs = function (cur) {
@@ -243,6 +256,12 @@ var Trie = /** @class */ (function () {
243
256
  dfs(this._root);
244
257
  return commonPre;
245
258
  };
259
+ /**
260
+ * The `getAll` function returns an array of all words in a Trie data structure that start with a given prefix.
261
+ * @param [prefix] - The `prefix` parameter is a string that represents the prefix that we want to search for in the
262
+ * trie. It is an optional parameter, so if no prefix is provided, it will default to an empty string.
263
+ * @returns an array of strings.
264
+ */
246
265
  Trie.prototype.getAll = function (prefix) {
247
266
  var e_6, _a;
248
267
  if (prefix === void 0) { prefix = ''; }
@@ -1,4 +1,4 @@
1
- import { AVLTreeNode } from "../binary-tree";
1
+ import { AVLTreeNode } from '../binary-tree';
2
2
  export interface AVLTreeDeleted<T> {
3
3
  deleted: AVLTreeNode<T> | null;
4
4
  needBalanced: AVLTreeNode<T> | null;
@@ -1,4 +1,4 @@
1
- import { BinaryTreeNode } from "../binary-tree";
1
+ import { BinaryTreeNode } from '../binary-tree';
2
2
  export type BinaryTreeNodePropertyName = 'id' | 'val' | 'count';
3
3
  export type NodeOrPropertyName = 'node' | BinaryTreeNodePropertyName;
4
4
  export type DFSOrderPattern = 'in' | 'pre' | 'post';
@@ -10,4 +10,4 @@ export * from './heap';
10
10
  export * from './singly-linked-list';
11
11
  export * from './doubly-linked-list';
12
12
  export * from './navigator';
13
- export * from './utils';
13
+ export * from '../../utils/types/utils';
@@ -26,4 +26,4 @@ __exportStar(require("./heap"), exports);
26
26
  __exportStar(require("./singly-linked-list"), exports);
27
27
  __exportStar(require("./doubly-linked-list"), exports);
28
28
  __exportStar(require("./navigator"), exports);
29
- __exportStar(require("./utils"), exports);
29
+ __exportStar(require("../../utils/types/utils"), exports);
@@ -1,5 +1 @@
1
- import { SinglyLinkedList } from "../linked-list";
2
- /** Type used for filter and find methods, returning a boolean */
3
- export type TTestFunction<NodeData> = (data: NodeData, index: number, list: SinglyLinkedList<NodeData>) => boolean;
4
- /** Type used for map and forEach methods, returning anything */
5
- export type TMapFunction<NodeData> = (data: any, index: number, list: SinglyLinkedList<NodeData>) => any;
1
+ export {};
@@ -1,4 +1,4 @@
1
- import { BSTNode } from "../binary-tree";
1
+ import { BSTNode } from '../binary-tree';
2
2
  export type TreeMultiSetDeletedResult<T> = {
3
3
  deleted: BSTNode<T> | null;
4
4
  needBalanced: BSTNode<T> | null;
@@ -1,16 +1,14 @@
1
+ /**
2
+ * @copyright 2030 Tyler Zeng <zrwusa@gmail.com>
3
+ * @license MIT
4
+ */
5
+ import { Thunk, ToThunkFn, TrlAsyncFn, TrlFn } from './types';
1
6
  export declare const THUNK_SYMBOL: unique symbol;
2
7
  export declare const isThunk: (fnOrValue: any) => boolean;
3
- type ToThunkFn = () => ReturnType<TrlFn>;
4
- type Thunk = () => ReturnType<ToThunkFn> & {
5
- __THUNK__: typeof THUNK_SYMBOL;
6
- };
7
8
  export declare const toThunk: (fn: ToThunkFn) => Thunk;
8
- type TrlFn = (...args: any[]) => any;
9
9
  export declare const trampoline: (fn: TrlFn) => ((...args: [...Parameters<TrlFn>]) => any) & {
10
10
  cont: (...args: [...Parameters<TrlFn>]) => Thunk;
11
11
  };
12
- type TrlAsyncFn = (...args: any[]) => any;
13
12
  export declare const trampolineAsync: (fn: TrlAsyncFn) => ((...args: [...Parameters<TrlAsyncFn>]) => Promise<any>) & {
14
13
  cont: (...args: [...Parameters<TrlAsyncFn>]) => Thunk;
15
14
  };
16
- export {};
@@ -0,0 +1 @@
1
+ export * from './utils';
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./utils"), exports);
@@ -50,3 +50,11 @@ export type DeepProxy<T> = T extends (...args: any[]) => infer R ? (...args: [..
50
50
  export type DeepProxyOnChange = (target: any, property: string | symbol, value: any, receiver: any, descriptor: any, result: any) => void;
51
51
  export type DeepProxyOnGet = (target: any, property: string | symbol, value: any, receiver: any, descriptor: any, result: any) => void;
52
52
  export type CurryFunc<T> = T extends (...args: infer Args) => infer R ? Args extends [infer Arg, ...infer RestArgs] ? (arg: Arg) => CurryFunc<(...args: RestArgs) => R> : R : T;
53
+ export type ToThunkFn = () => ReturnType<TrlFn>;
54
+ declare const THUNK_SYMBOL: unique symbol;
55
+ export type Thunk = () => ReturnType<ToThunkFn> & {
56
+ __THUNK__: typeof THUNK_SYMBOL;
57
+ };
58
+ export type TrlFn = (...args: any[]) => any;
59
+ export type TrlAsyncFn = (...args: any[]) => any;
60
+ export {};
@@ -52,3 +52,4 @@ var TreeNode = /** @class */ (function () {
52
52
  return TreeNode;
53
53
  }());
54
54
  exports.TreeNode = TreeNode;
55
+ var THUNK_SYMBOL = Symbol('thunk');
@@ -1,4 +1,4 @@
1
- import { AnyFunction } from '../data-structures/types';
1
+ import { AnyFunction } from './types';
2
2
  export type JSONSerializable = {
3
3
  [key: string]: any;
4
4
  };
package/docs/.nojekyll ADDED
@@ -0,0 +1 @@
1
+ TypeDoc added this file to prevent GitHub Pages from using Jekyll. You can turn off this behavior by setting the `githubPages` option to false.