data-structure-typed 0.9.16 → 1.12.10

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
@@ -1,8 +1,18 @@
1
+ /**
2
+ * @copyright 2030 Tyler Zeng <zrwusa@gmail.com>
3
+ * @license MIT
4
+ */
1
5
  import Vector2D from './vector2d'
2
6
 
3
7
  export class Matrix2D {
4
8
  private readonly _matrix: number[][];
5
9
 
10
+ /**
11
+ * The constructor function initializes a Matrix2D object with either a default identity matrix, or a provided matrix
12
+ * or Vector2D object.
13
+ * @param {number[][] | Vector2D} [value] - The `value` parameter can be either a 2D array of numbers (`number[][]`) or
14
+ * an instance of the `Vector2D` class.
15
+ */
6
16
  constructor(value?: number[][] | Vector2D) {
7
17
  if (typeof value === 'undefined') {
8
18
  this._matrix = Matrix2D.identity
@@ -16,12 +26,17 @@ export class Matrix2D {
16
26
  }
17
27
  }
18
28
 
29
+ /**
30
+ * The function returns a 2D array with three empty arrays.
31
+ * @returns An empty 2-dimensional array with 3 empty arrays inside.
32
+ */
19
33
  public static get empty(): number[][] {
20
34
  return [[], [], []]
21
35
  }
22
36
 
23
37
  /**
24
- * Initialize an identity matrix
38
+ * The above function returns a 3x3 identity matrix.
39
+ * @returns The method is returning a 2-dimensional array of numbers representing the identity matrix.
25
40
  */
26
41
  public static get identity(): number[][] {
27
42
  return [
@@ -31,16 +46,30 @@ export class Matrix2D {
31
46
  }
32
47
 
33
48
  /**
34
- * Return the matrix values
49
+ * The function returns a two-dimensional array of numbers.
50
+ * @returns The getter method is returning the value of the private variable `_matrix`, which is a two-dimensional
51
+ * array of numbers.
35
52
  */
36
53
  public get m(): number[][] {
37
54
  return this._matrix
38
55
  }
39
56
 
57
+ /**
58
+ * The function "toVector" returns a new Vector2D object with the values from the first and second elements of the
59
+ * _matrix array.
60
+ * @returns A new instance of the Vector2D class is being returned. The values of the returned vector are taken from
61
+ * the first column of the matrix.
62
+ */
40
63
  public get toVector(): Vector2D {
41
64
  return new Vector2D(this._matrix[0][0], this._matrix[1][0])
42
65
  }
43
66
 
67
+ /**
68
+ * The function takes two 2D matrices as input and returns their sum as a new 2D matrix.
69
+ * @param {Matrix2D} matrix1 - Matrix2D - The first matrix to be added.
70
+ * @param {Matrix2D} matrix2 - The parameter `matrix2` is a Matrix2D object.
71
+ * @returns a new instance of the Matrix2D class, which is created using the result array.
72
+ */
44
73
  public static add(matrix1: Matrix2D, matrix2: Matrix2D): Matrix2D {
45
74
  const result = Matrix2D.empty
46
75
  for (let i = 0; i < 3; i++) {
@@ -51,6 +80,13 @@ export class Matrix2D {
51
80
  return new Matrix2D(result);
52
81
  }
53
82
 
83
+ /**
84
+ * The function subtracts two 2D matrices and returns the result as a new Matrix2D object.
85
+ * @param {Matrix2D} matrix1 - Matrix2D - The first matrix to subtract from.
86
+ * @param {Matrix2D} matrix2 - Matrix2D is a class representing a 2D matrix. It has a property `m` which is a 2D array
87
+ * representing the matrix elements.
88
+ * @returns a new instance of the Matrix2D class, which is created using the result array.
89
+ */
54
90
  public static subtract(matrix1: Matrix2D, matrix2: Matrix2D): Matrix2D {
55
91
  const result = Matrix2D.empty
56
92
  for (let i = 0; i < 3; i++) {
@@ -61,6 +97,12 @@ export class Matrix2D {
61
97
  return new Matrix2D(result);
62
98
  }
63
99
 
100
+ /**
101
+ * The function multiplies two 2D matrices and returns the result as a new Matrix2D object.
102
+ * @param {Matrix2D} matrix1 - A 2D matrix represented by the Matrix2D class.
103
+ * @param {Matrix2D} matrix2 - The parameter `matrix2` is a 2D matrix of size 3x3.
104
+ * @returns a new instance of the Matrix2D class, created using the result array.
105
+ */
64
106
  public static multiply(matrix1: Matrix2D, matrix2: Matrix2D): Matrix2D {
65
107
  const result = Matrix2D.empty
66
108
  for (let i = 0; i < 3; i++) {
@@ -74,6 +116,13 @@ export class Matrix2D {
74
116
  return new Matrix2D(result);
75
117
  }
76
118
 
119
+ /**
120
+ * The function multiplies each element of a 2D matrix by a given value and returns the resulting matrix.
121
+ * @param {Matrix2D} matrix - The `matrix` parameter is an instance of the `Matrix2D` class, which represents a 2D
122
+ * matrix. It contains a property `m` that is a 2D array representing the matrix elements.
123
+ * @param {number} value - The `value` parameter is a number that you want to multiply each element of the `matrix` by.
124
+ * @returns a new instance of the Matrix2D class, which is created using the result array.
125
+ */
77
126
  public static multiplyByValue(matrix: Matrix2D, value: number): Matrix2D {
78
127
  const result = Matrix2D.empty
79
128
  for (let i = 0; i < 3; i++) {
@@ -84,10 +133,24 @@ export class Matrix2D {
84
133
  return new Matrix2D(result);
85
134
  }
86
135
 
136
+ /**
137
+ * The function multiplies a 2D matrix by a 2D vector and returns the result as a 2D vector.
138
+ * @param {Matrix2D} matrix - The parameter "matrix" is of type Matrix2D. It represents a 2-dimensional matrix.
139
+ * @param {Vector2D} vector - The "vector" parameter is a 2D vector, represented by an object of type Vector2D.
140
+ * @returns a Vector2D.
141
+ */
87
142
  public static multiplyByVector(matrix: Matrix2D, vector: Vector2D): Vector2D {
88
143
  return Matrix2D.multiply(matrix, new Matrix2D(vector)).toVector
89
144
  }
90
145
 
146
+ /**
147
+ * The function returns a 2D matrix that scales and flips a vector around the center of a given width and height.
148
+ * @param {number} width - The width parameter represents the width of the view or the canvas. It is a number that
149
+ * specifies the width in pixels or any other unit of measurement.
150
+ * @param {number} height - The height parameter represents the height of the view or the canvas. It is used to
151
+ * calculate the centerY value, which is the vertical center of the view.
152
+ * @returns a Matrix2D object.
153
+ */
91
154
  public static view(width: number, height: number): Matrix2D {
92
155
  const scaleStep = 1 // Scale every vector * scaleStep
93
156
  const centerX = width / 2
@@ -100,10 +163,21 @@ export class Matrix2D {
100
163
  [0, 0, 1]])
101
164
  }
102
165
 
166
+ /**
167
+ * The function scales a matrix by a given factor.
168
+ * @param {number} factor - The factor parameter is a number that represents the scaling factor by which the matrix
169
+ * should be scaled.
170
+ * @returns the result of multiplying a new instance of Matrix2D by the given factor.
171
+ */
103
172
  public static scale(factor: number) {
104
173
  return Matrix2D.multiplyByValue(new Matrix2D(), factor)
105
174
  }
106
175
 
176
+ /**
177
+ * The function "rotate" takes an angle in radians and returns a 2D transformation matrix for rotating objects.
178
+ * @param {number} radians - The "radians" parameter is the angle in radians by which you want to rotate an object.
179
+ * @returns The code is returning a new instance of a Matrix2D object.
180
+ */
107
181
  public static rotate(radians: number) {
108
182
  const cos = Math.cos(radians)
109
183
  const sin = Math.sin(radians)
@@ -114,6 +188,12 @@ export class Matrix2D {
114
188
  [0, 0, 1]])
115
189
  }
116
190
 
191
+ /**
192
+ * The translate function takes a 2D vector and returns a 2D matrix that represents a translation transformation.
193
+ * @param {Vector2D} vector - The parameter "vector" is of type Vector2D. It represents a 2D vector with components x
194
+ * and y, and an optional w component.
195
+ * @returns The method is returning a new instance of the Matrix2D class.
196
+ */
117
197
  public static translate(vector: Vector2D): Matrix2D {
118
198
  return new Matrix2D([
119
199
  [1, 0, vector.x],
@@ -1,9 +1,21 @@
1
+ /**
2
+ * @copyright 2030 Tyler Zeng <zrwusa@gmail.com>
3
+ * @license MIT
4
+ */
1
5
  import type {Direction, NavigatorParams, Turning} from '../types';
2
6
 
3
7
  export class Character {
4
8
  direction: Direction;
5
9
  turn: () => Character;
6
10
 
11
+ /**
12
+ * The constructor function takes in a direction and turning object and sets the direction and turn properties of the
13
+ * Character class.
14
+ * @param {Direction} direction - The direction parameter is used to specify the current direction of the character. It
15
+ * can be any value that represents a direction, such as "north", "south", "east", or "west".
16
+ * @param {Turning} turning - The `turning` parameter is an object that maps each direction to the corresponding
17
+ * turning direction. It is used to determine the new direction when the character turns.
18
+ */
7
19
  constructor(direction: Direction, turning: Turning) {
8
20
  this.direction = direction;
9
21
  this.turn = () => new Character(turning[direction], turning);
@@ -17,6 +29,11 @@ export class Navigator<T = number> {
17
29
  private _character: Character;
18
30
  private readonly _VISITED: T;
19
31
 
32
+ /**
33
+ * The constructor initializes the Navigator object with the given parameters and sets the current position as visited
34
+ * in the matrix.
35
+ * @param - - `matrix`: a 2D array representing the grid or map
36
+ */
20
37
  constructor({matrix, turning, onMove, init: {cur, charDir, VISITED}}: NavigatorParams<T>) {
21
38
  this._matrix = matrix;
22
39
  this._cur = cur;
@@ -27,6 +44,10 @@ export class Navigator<T = number> {
27
44
  this._matrix[this._cur[0]][this._cur[1]] = this._VISITED;
28
45
  }
29
46
 
47
+ /**
48
+ * The "start" function moves the character in its current direction until it encounters an obstacle, then it turns the
49
+ * character and repeats the process.
50
+ */
30
51
  start() {
31
52
  while (this.check(this._character.direction) || this.check(this._character.turn().direction)) {
32
53
  const {direction} = this._character;
@@ -38,6 +59,12 @@ export class Navigator<T = number> {
38
59
  }
39
60
  }
40
61
 
62
+ /**
63
+ * The function checks if there is a valid move in the specified direction in a matrix.
64
+ * @param {Direction} direction - The direction parameter is a string that represents the direction in which to check.
65
+ * It can be one of the following values: 'up', 'right', 'down', or 'left'.
66
+ * @returns a boolean value.
67
+ */
41
68
  check(direction: Direction) {
42
69
  let forward: T | undefined, row: T[] | undefined;
43
70
  const matrix = this._matrix;
@@ -63,6 +90,11 @@ export class Navigator<T = number> {
63
90
  return forward !== undefined && forward !== this._VISITED;
64
91
  }
65
92
 
93
+ /**
94
+ * The `move` function updates the current position based on the given direction and updates the matrix accordingly.
95
+ * @param {Direction} direction - The `direction` parameter is a string that represents the direction in which to move.
96
+ * It can have one of the following values: 'up', 'right', 'down', or 'left'.
97
+ */
66
98
  move(direction: Direction) {
67
99
  switch (direction) {
68
100
  case 'up':
@@ -1,3 +1,7 @@
1
+ /**
2
+ * @copyright 2030 Tyler Zeng <zrwusa@gmail.com>
3
+ * @license MIT
4
+ */
1
5
  export class Vector2D {
2
6
  constructor(
3
7
  public x: number = 0,
@@ -7,57 +11,125 @@ export class Vector2D {
7
11
  }
8
12
 
9
13
  /**
10
- * Set x and y both to zero
14
+ * The function checks if the x and y values of a point are both zero.
15
+ * @returns A boolean value indicating whether both the x and y properties of the object are equal to 0.
11
16
  */
12
17
  public get isZero(): boolean {
13
18
  return this.x === 0 && this.y === 0
14
19
  }
15
20
 
16
21
  /**
17
- * The length / magnitude of the vector
22
+ * The above function calculates the length of a vector using the Pythagorean theorem.
23
+ * @returns The length of a vector, calculated using the Pythagorean theorem.
18
24
  */
19
25
  public get length(): number {
20
26
  return Math.sqrt((this.x * this.x) + (this.y * this.y))
21
27
  }
22
28
 
23
29
  /**
24
- * The squared length of the vector
30
+ * The function calculates the square of the length of a vector.
31
+ * @returns The method is returning the sum of the squares of the x and y values.
25
32
  */
26
33
  public get lengthSq(): number {
27
34
  return (this.x * this.x) + (this.y * this.y)
28
35
  }
29
36
 
30
37
  /**
31
- * Return the vector with rounded values
38
+ * The "rounded" function returns a new Vector2D object with the x and y values rounded to the nearest whole number.
39
+ * @returns The method is returning a new instance of the Vector2D class with the x and y values rounded to the nearest
40
+ * whole number.
32
41
  */
33
42
  public get rounded(): Vector2D {
34
43
  return new Vector2D(Math.round(this.x), Math.round(this.y))
35
44
  }
36
45
 
46
+ /**
47
+ * The function "add" takes two Vector2D objects as parameters and returns a new Vector2D object with the sum of their
48
+ * x and y components.
49
+ * @param {Vector2D} vector1 - The parameter `vector1` is an instance of the `Vector2D` class. It represents a
50
+ * 2-dimensional vector with an `x` and `y` component.
51
+ * @param {Vector2D} vector2 - The parameter "vector2" is of type Vector2D. It represents a 2-dimensional vector with
52
+ * an x and y component.
53
+ * @returns The method is returning a new instance of the Vector2D class with the x and y components of the two input
54
+ * vectors added together.
55
+ */
37
56
  public static add(vector1: Vector2D, vector2: Vector2D): Vector2D {
38
57
  return new Vector2D(vector1.x + vector2.x, vector1.y + vector2.y)
39
58
  }
40
59
 
60
+ /**
61
+ * The subtract function takes two Vector2D objects as parameters and returns a new Vector2D object with the x and y
62
+ * components subtracted.
63
+ * @param {Vector2D} vector1 - The parameter `vector1` is an instance of the `Vector2D` class, representing a
64
+ * 2-dimensional vector. It has properties `x` and `y` which represent the x and y components of the vector
65
+ * respectively.
66
+ * @param {Vector2D} vector2 - The parameter "vector2" is a Vector2D object. It represents the second vector that you
67
+ * want to subtract from the first vector.
68
+ * @returns The method is returning a new Vector2D object with the x and y components subtracted from vector1 and
69
+ * vector2.
70
+ */
41
71
  public static subtract(vector1: Vector2D, vector2: Vector2D): Vector2D {
42
72
  return new Vector2D(vector1.x - vector2.x, vector1.y - vector2.y)
43
73
  }
44
74
 
75
+ /**
76
+ * The function subtracts a given value from the x and y components of a Vector2D object and returns a new Vector2D
77
+ * object.
78
+ * @param {Vector2D} vector - The parameter "vector" is of type Vector2D, which represents a 2-dimensional vector with
79
+ * x and y components.
80
+ * @param {number} value - The "value" parameter is a number that will be subtracted from both the x and y components
81
+ * of the "vector" parameter.
82
+ * @returns A new Vector2D object with the x and y values subtracted by the given value.
83
+ */
45
84
  public static subtractValue(vector: Vector2D, value: number): Vector2D {
46
85
  return new Vector2D(vector.x - value, vector.y - value)
47
86
  }
48
87
 
88
+ /**
89
+ * The function multiplies a Vector2D object by a given value.
90
+ * @param {Vector2D} vector - The parameter "vector" is of type Vector2D, which represents a 2-dimensional vector with
91
+ * x and y components.
92
+ * @param {number} value - The "value" parameter is a number that represents the value by which the x and y components
93
+ * of the vector will be multiplied.
94
+ * @returns A new Vector2D object with the x and y values multiplied by the given value.
95
+ */
49
96
  public static multiply(vector: Vector2D, value: number): Vector2D {
50
97
  return new Vector2D(vector.x * value, vector.y * value)
51
98
  }
52
99
 
100
+ /**
101
+ * The function divides the x and y components of a Vector2D by a given value and returns a new Vector2D.
102
+ * @param {Vector2D} vector - The parameter "vector" is of type Vector2D, which represents a 2-dimensional vector with
103
+ * x and y components.
104
+ * @param {number} value - The value parameter is a number that will be used to divide the x and y components of the
105
+ * vector.
106
+ * @returns A new instance of the Vector2D class with the x and y values divided by the given value.
107
+ */
53
108
  public static divide(vector: Vector2D, value: number): Vector2D {
54
109
  return new Vector2D(vector.x / value, vector.y / value)
55
110
  }
56
111
 
112
+ /**
113
+ * The function checks if two Vector2D objects are equal by comparing their x and y values.
114
+ * @param {Vector2D} vector1 - The parameter `vector1` is of type `Vector2D`, which represents a 2-dimensional vector.
115
+ * It has two properties: `x` and `y`, which represent the x and y components of the vector, respectively.
116
+ * @param {Vector2D} vector2 - The parameter "vector2" is of type Vector2D.
117
+ * @returns a boolean value, which indicates whether the two input vectors are equal or not.
118
+ */
57
119
  public static equals(vector1: Vector2D, vector2: Vector2D): boolean {
58
120
  return vector1.x === vector2.x && vector1.y === vector2.y
59
121
  }
60
122
 
123
+ /**
124
+ * The function checks if two Vector2D objects are equal within a specified rounding factor.
125
+ * @param {Vector2D} vector1 - The first vector to compare.
126
+ * @param {Vector2D} vector2 - The parameter "vector2" is a Vector2D object, which represents a 2-dimensional vector.
127
+ * It is used as one of the inputs for the "equalsRounded" function.
128
+ * @param [roundingFactor=12] - The roundingFactor parameter is used to determine the threshold for considering two
129
+ * vectors as equal. If the absolute difference in the x and y components of the vectors is less than the
130
+ * roundingFactor, the vectors are considered equal.
131
+ * @returns a boolean value.
132
+ */
61
133
  public static equalsRounded(vector1: Vector2D, vector2: Vector2D, roundingFactor = 12): boolean {
62
134
  const vector = Vector2D.abs(Vector2D.subtract(vector1, vector2))
63
135
  if (vector.x < roundingFactor && vector.y < roundingFactor) {
@@ -68,7 +140,10 @@ export class Vector2D {
68
140
  }
69
141
 
70
142
  /**
71
- * Normalizes the vector if it matches a certain condition
143
+ * The normalize function takes a vector as input and returns a normalized version of the vector.Normalizes the vector if it matches a certain condition
144
+ * @param {Vector2D} vector - The parameter "vector" is of type Vector2D.
145
+ * @returns the normalized vector if its length is greater than a very small value (epsilon), otherwise it returns the
146
+ * original vector.
72
147
  */
73
148
  public static normalize(vector: Vector2D): Vector2D {
74
149
  const length = vector.length
@@ -80,7 +155,12 @@ export class Vector2D {
80
155
  }
81
156
 
82
157
  /**
83
- * Adjusts x and y so that the length of the vector does not exceed max
158
+ * The function truncates a vector to a maximum length if it exceeds that length.Adjusts x and y so that the length of the vector does not exceed max
159
+ * @param {Vector2D} vector - A 2D vector represented by the Vector2D class.
160
+ * @param {number} max - The `max` parameter is a number that represents the maximum length that the `vector` should
161
+ * have.
162
+ * @returns either the original vector or a truncated version of the vector, depending on whether the length of the
163
+ * vector is greater than the maximum value specified.
84
164
  */
85
165
  public static truncate(vector: Vector2D, max: number): Vector2D {
86
166
  if (vector.length > max) {
@@ -91,25 +171,42 @@ export class Vector2D {
91
171
  }
92
172
 
93
173
  /**
94
- * The vector that is perpendicular to this one
174
+ * The function returns a new Vector2D object that is perpendicular to the input vector.The vector that is perpendicular to this one
175
+ * @param {Vector2D} vector - The parameter "vector" is of type Vector2D.
176
+ * @returns A new Vector2D object is being returned.
95
177
  */
96
178
  public static perp(vector: Vector2D): Vector2D {
97
179
  return new Vector2D(-vector.y, vector.x)
98
180
  }
99
181
 
100
182
  /**
101
- * returns the vector that is the reverse of this vector
183
+ * The reverse function takes a Vector2D object and returns a new Vector2D object with the negated x and y values.
184
+ * @param {Vector2D} vector - The parameter "vector" is of type Vector2D, which represents a 2-dimensional vector. It
185
+ * has two properties: "x" and "y", which represent the x and y components of the vector, respectively.
186
+ * @returns A new Vector2D object with the negated x and y values of the input vector. Returns the vector that is the reverse of this vector
102
187
  */
103
188
  public static reverse(vector: Vector2D): Vector2D {
104
189
  return new Vector2D(-vector.x, -vector.y)
105
190
  }
106
191
 
192
+ /**
193
+ * The function takes a Vector2D object as input and returns a new Vector2D object with the absolute values of its x
194
+ * and y components.
195
+ * @param {Vector2D} vector - The parameter "vector" is of type Vector2D, which represents a 2-dimensional vector. It
196
+ * has two properties: "x" and "y", which represent the x and y components of the vector, respectively.
197
+ * @returns The method is returning a new Vector2D object with the absolute values of the x and y components of the
198
+ * input vector.
199
+ */
107
200
  public static abs(vector: Vector2D): Vector2D {
108
201
  return new Vector2D(Math.abs(vector.x), Math.abs(vector.y))
109
202
  }
110
203
 
111
204
  /**
112
- * The dot product of v1 and v2
205
+ * The dot function calculates the dot product of two 2D vectors.The dot product of v1 and v2
206
+ * @param {Vector2D} vector1 - The parameter `vector1` represents a 2D vector with its x and y components.
207
+ * @param {Vector2D} vector2 - The "vector2" parameter is a Vector2D object. It represents a two-dimensional vector
208
+ * with an x and y component.
209
+ * @returns The dot product of the two input vectors.
113
210
  */
114
211
  public static dot(vector1: Vector2D, vector2: Vector2D): number {
115
212
  return (vector1.x * vector2.x) + (vector1.y * vector2.y)
@@ -132,7 +229,14 @@ export class Vector2D {
132
229
  // }
133
230
 
134
231
  /**
135
- * The distance between this and the vector
232
+ * The function calculates the distance between two points in a two-dimensional space.
233
+ * @param {Vector2D} vector1 - The parameter `vector1` represents the first vector in 2D space, while `vector2`
234
+ * represents the second vector. Each vector has an `x` and `y` component, which represent their respective coordinates
235
+ * in the 2D space.
236
+ * @param {Vector2D} vector2 - The `vector2` parameter represents the second vector in the calculation of distance. It
237
+ * is an instance of the `Vector2D` class, which typically has properties `x` and `y` representing the coordinates of
238
+ * the vector in a 2D space.
239
+ * @returns The distance between vector1 and vector2.
136
240
  */
137
241
  public static distance(vector1: Vector2D, vector2: Vector2D): number {
138
242
  const ySeparation = vector2.y - vector1.y
@@ -141,7 +245,12 @@ export class Vector2D {
141
245
  }
142
246
 
143
247
  /**
144
- * The distance between this and the vector squared
248
+ * The function calculates the squared distance between two 2D vectors.
249
+ * @param {Vector2D} vector1 - The parameter `vector1` represents the first vector, which is an instance of the
250
+ * `Vector2D` class. It contains the x and y coordinates of the vector.
251
+ * @param {Vector2D} vector2 - The `vector2` parameter represents the second vector in a two-dimensional space. It has
252
+ * properties `x` and `y` which represent the coordinates of the vector.
253
+ * @returns the square of the distance between the two input vectors.
145
254
  */
146
255
  public static distanceSq(vector1: Vector2D, vector2: Vector2D): number {
147
256
  const ySeparation = vector2.y - vector1.y
@@ -150,8 +259,13 @@ export class Vector2D {
150
259
  }
151
260
 
152
261
  /**
153
- * Returns positive if v2 is clockwise of this vector, negative if counterclockwise
262
+ * The sign function determines the sign of the cross product between two 2D vectors.
154
263
  * (assuming the Y axis is pointing down, X axis to right like a Window app)
264
+ * @param {Vector2D} vector1 - The parameter `vector1` is of type `Vector2D`, which represents a 2-dimensional vector.
265
+ * It likely has properties `x` and `y` representing the x and y components of the vector, respectively.
266
+ * @param {Vector2D} vector2 - The above code defines a function called "sign" that takes two parameters: vector1 and
267
+ * vector2. Both vector1 and vector2 are of type Vector2D.
268
+ * @returns either -1 or 1. Returns positive if v2 is clockwise of this vector, negative if counterclockwise
155
269
  */
156
270
  public static sign(vector1: Vector2D, vector2: Vector2D): number {
157
271
  if (vector1.y * vector2.x > vector1.x * vector2.y) {
@@ -162,8 +276,11 @@ export class Vector2D {
162
276
  }
163
277
 
164
278
  /**
165
- * Returns the angle between origin and the given vector in radians
166
- * @param vector
279
+ * The function calculates the angle between a given vector and the negative y-axis.
280
+ * @param {Vector2D} vector - The "vector" parameter is an instance of the Vector2D class, which represents a
281
+ * 2-dimensional vector. It has two properties: "x" and "y", which represent the x and y components of the vector,
282
+ * respectively.
283
+ * @returns the angle between the given vector and the vector (0, -1) in radians.Returns the angle between origin and the given vector in radians
167
284
  */
168
285
  public static angle(vector: Vector2D): number {
169
286
  const origin = new Vector2D(0, -1)
@@ -171,6 +288,13 @@ export class Vector2D {
171
288
  return Vector2D.sign(vector, origin) === 1 ? ((Math.PI * 2) - radian) : radian
172
289
  }
173
290
 
291
+ /**
292
+ * The function "random" generates a random Vector2D object with x and y values within the specified range.
293
+ * @param {number} maxX - The maxX parameter represents the maximum value for the x-coordinate of the random vector.
294
+ * @param {number} maxY - The `maxY` parameter represents the maximum value for the y-coordinate of the generated
295
+ * random vector.
296
+ * @returns a new instance of the Vector2D class with random x and y values.
297
+ */
174
298
  public static random(maxX: number, maxY: number): Vector2D {
175
299
  const randX = Math.floor(Math.random() * maxX - (maxX / 2))
176
300
  const randY = Math.floor(Math.random() * maxY - (maxY / 2))
@@ -178,7 +302,7 @@ export class Vector2D {
178
302
  }
179
303
 
180
304
  /**
181
- * Check wether both x and y are zero
305
+ * The function sets the values of x and y to zero.
182
306
  */
183
307
  public zero(): void {
184
308
  this.x = 0
@@ -1,7 +1,15 @@
1
+ /**
2
+ * @copyright 2030 Tyler Zeng <zrwusa@gmail.com>
3
+ * @license MIT
4
+ */
1
5
  import {PriorityQueue} from './priority-queue';
2
6
  import type {PriorityQueueOptions} from '../types';
3
7
 
4
8
  export class MaxPriorityQueue<T = number> extends PriorityQueue<T> {
9
+ /**
10
+ * The constructor initializes a PriorityQueue with optional nodes and a comparator function.
11
+ * @param [options] - An optional object that contains the following properties:
12
+ */
5
13
  constructor(options?: PriorityQueueOptions<T>) {
6
14
  super({
7
15
  nodes: options?.nodes, comparator: options?.comparator ? options.comparator : (a: T, b: T) => {
@@ -1,7 +1,15 @@
1
+ /**
2
+ * @copyright 2030 Tyler Zeng <zrwusa@gmail.com>
3
+ * @license MIT
4
+ */
1
5
  import {PriorityQueue} from './priority-queue';
2
6
  import type {PriorityQueueOptions} from '../types';
3
7
 
4
8
  export class MinPriorityQueue<T = number> extends PriorityQueue<T> {
9
+ /**
10
+ * The constructor initializes a PriorityQueue with optional nodes and a comparator function.
11
+ * @param [options] - An optional object that contains the following properties:
12
+ */
5
13
  constructor(options?: PriorityQueueOptions<T>) {
6
14
  super({
7
15
  nodes: options?.nodes, comparator: options?.comparator ? options.comparator : (a: T, b: T) => {