data-structure-typed 0.9.16 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (264) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +665 -172
  3. package/dist/bundle.js +2 -0
  4. package/dist/bundle.js.LICENSE.txt +13 -0
  5. package/dist/data-structures/binary-tree/aa-tree.js +2 -5
  6. package/dist/data-structures/binary-tree/abstract-binary-tree.d.ts +364 -0
  7. package/dist/data-structures/binary-tree/abstract-binary-tree.js +1308 -0
  8. package/dist/data-structures/binary-tree/avl-tree.d.ts +85 -14
  9. package/dist/data-structures/binary-tree/avl-tree.js +142 -116
  10. package/dist/data-structures/binary-tree/b-tree.js +2 -5
  11. package/dist/data-structures/binary-tree/binary-indexed-tree.d.ts +39 -1
  12. package/dist/data-structures/binary-tree/binary-indexed-tree.js +54 -13
  13. package/dist/data-structures/binary-tree/binary-tree.d.ts +29 -126
  14. package/dist/data-structures/binary-tree/binary-tree.js +31 -1093
  15. package/dist/data-structures/binary-tree/bst.d.ts +117 -23
  16. package/dist/data-structures/binary-tree/bst.js +233 -240
  17. package/dist/data-structures/binary-tree/index.d.ts +1 -0
  18. package/dist/data-structures/binary-tree/index.js +1 -0
  19. package/dist/data-structures/binary-tree/rb-tree.d.ts +18 -1
  20. package/dist/data-structures/binary-tree/rb-tree.js +40 -5
  21. package/dist/data-structures/binary-tree/segment-tree.d.ts +61 -11
  22. package/dist/data-structures/binary-tree/segment-tree.js +126 -93
  23. package/dist/data-structures/binary-tree/splay-tree.js +2 -5
  24. package/dist/data-structures/binary-tree/tree-multiset.d.ts +213 -6
  25. package/dist/data-structures/binary-tree/tree-multiset.js +687 -34
  26. package/dist/data-structures/binary-tree/two-three-tree.js +2 -5
  27. package/dist/data-structures/graph/abstract-graph.d.ts +270 -36
  28. package/dist/data-structures/graph/abstract-graph.js +610 -572
  29. package/dist/data-structures/graph/directed-graph.d.ts +173 -16
  30. package/dist/data-structures/graph/directed-graph.js +345 -313
  31. package/dist/data-structures/graph/index.d.ts +1 -0
  32. package/dist/data-structures/graph/index.js +1 -0
  33. package/dist/data-structures/graph/map-graph.d.ts +79 -0
  34. package/dist/data-structures/graph/map-graph.js +111 -0
  35. package/dist/data-structures/graph/undirected-graph.d.ts +111 -9
  36. package/dist/data-structures/graph/undirected-graph.js +203 -178
  37. package/dist/data-structures/hash/coordinate-map.d.ts +38 -1
  38. package/dist/data-structures/hash/coordinate-map.js +59 -36
  39. package/dist/data-structures/hash/coordinate-set.d.ts +32 -2
  40. package/dist/data-structures/hash/coordinate-set.js +49 -33
  41. package/dist/data-structures/hash/hash-table.d.ts +2 -1
  42. package/dist/data-structures/hash/hash-table.js +4 -0
  43. package/dist/data-structures/hash/pair.d.ts +2 -1
  44. package/dist/data-structures/hash/pair.js +4 -0
  45. package/dist/data-structures/hash/tree-map.d.ts +2 -1
  46. package/dist/data-structures/hash/tree-map.js +4 -0
  47. package/dist/data-structures/hash/tree-set.d.ts +2 -1
  48. package/dist/data-structures/hash/tree-set.js +4 -0
  49. package/dist/data-structures/heap/heap.d.ts +62 -45
  50. package/dist/data-structures/heap/heap.js +124 -86
  51. package/dist/data-structures/heap/max-heap.d.ts +13 -5
  52. package/dist/data-structures/heap/max-heap.js +18 -28
  53. package/dist/data-structures/heap/min-heap.d.ts +14 -5
  54. package/dist/data-structures/heap/min-heap.js +19 -28
  55. package/dist/data-structures/index.d.ts +1 -1
  56. package/dist/data-structures/index.js +1 -1
  57. package/dist/data-structures/linked-list/doubly-linked-list.d.ts +193 -56
  58. package/dist/data-structures/linked-list/doubly-linked-list.js +484 -220
  59. package/dist/data-structures/linked-list/index.d.ts +1 -0
  60. package/dist/data-structures/linked-list/index.js +1 -0
  61. package/dist/data-structures/linked-list/singly-linked-list.d.ts +117 -315
  62. package/dist/data-structures/linked-list/singly-linked-list.js +374 -727
  63. package/dist/data-structures/linked-list/skip-linked-list.d.ts +2 -1
  64. package/dist/data-structures/linked-list/skip-linked-list.js +4 -0
  65. package/dist/data-structures/matrix/matrix.d.ts +12 -0
  66. package/dist/data-structures/matrix/matrix.js +21 -8
  67. package/dist/data-structures/matrix/matrix2d.d.ts +85 -2
  68. package/dist/data-structures/matrix/matrix2d.js +146 -80
  69. package/dist/data-structures/matrix/navigator.d.ts +36 -1
  70. package/dist/data-structures/matrix/navigator.js +46 -37
  71. package/dist/data-structures/matrix/vector2d.d.ts +142 -15
  72. package/dist/data-structures/matrix/vector2d.js +215 -109
  73. package/dist/data-structures/priority-queue/max-priority-queue.d.ts +12 -2
  74. package/dist/data-structures/priority-queue/max-priority-queue.js +33 -26
  75. package/dist/data-structures/priority-queue/min-priority-queue.d.ts +12 -2
  76. package/dist/data-structures/priority-queue/min-priority-queue.js +34 -26
  77. package/dist/data-structures/priority-queue/priority-queue.d.ts +153 -3
  78. package/dist/data-structures/priority-queue/priority-queue.js +244 -143
  79. package/dist/data-structures/queue/deque.d.ts +141 -13
  80. package/dist/data-structures/queue/deque.js +200 -82
  81. package/dist/data-structures/queue/queue.d.ts +65 -38
  82. package/dist/data-structures/queue/queue.js +110 -66
  83. package/dist/data-structures/stack/stack.d.ts +27 -32
  84. package/dist/data-structures/stack/stack.js +47 -53
  85. package/dist/data-structures/tree/index.d.ts +1 -0
  86. package/dist/data-structures/tree/index.js +17 -0
  87. package/dist/data-structures/tree/tree.d.ts +14 -0
  88. package/dist/data-structures/tree/tree.js +60 -0
  89. package/dist/data-structures/trie/trie.d.ts +33 -10
  90. package/dist/data-structures/trie/trie.js +123 -208
  91. package/dist/index.d.ts +3 -0
  92. package/dist/index.js +3 -0
  93. package/dist/interfaces/abstract-binary-tree.d.ts +90 -0
  94. package/dist/interfaces/abstract-graph.d.ts +17 -0
  95. package/dist/interfaces/avl-tree.d.ts +9 -0
  96. package/dist/interfaces/binary-tree.d.ts +6 -0
  97. package/dist/interfaces/bst.d.ts +17 -0
  98. package/dist/interfaces/directed-graph.d.ts +12 -0
  99. package/{src/data-structures/types/index.ts → dist/interfaces/index.d.ts} +10 -8
  100. package/dist/interfaces/index.js +31 -0
  101. package/{src/data-structures/hash/hash-table.ts → dist/interfaces/priority-queue.d.ts} +1 -1
  102. package/dist/interfaces/rb-tree.d.ts +8 -0
  103. package/dist/interfaces/segment-tree.d.ts +1 -0
  104. package/dist/interfaces/singly-linked-list.d.ts +1 -0
  105. package/dist/interfaces/singly-linked-list.js +2 -0
  106. package/dist/interfaces/tree-multiset.d.ts +7 -0
  107. package/dist/interfaces/tree-multiset.js +2 -0
  108. package/dist/interfaces/undirected-graph.d.ts +5 -0
  109. package/dist/interfaces/undirected-graph.js +2 -0
  110. package/dist/types/data-structures/abstract-binary-tree.d.ts +34 -0
  111. package/dist/types/data-structures/abstract-binary-tree.js +25 -0
  112. package/dist/types/data-structures/abstract-graph.d.ts +11 -0
  113. package/dist/types/data-structures/abstract-graph.js +2 -0
  114. package/dist/types/data-structures/avl-tree.d.ts +4 -0
  115. package/dist/types/data-structures/avl-tree.js +2 -0
  116. package/dist/types/data-structures/binary-tree.d.ts +4 -0
  117. package/dist/types/data-structures/binary-tree.js +2 -0
  118. package/dist/types/data-structures/bst.d.ts +13 -0
  119. package/dist/types/data-structures/bst.js +9 -0
  120. package/dist/types/data-structures/directed-graph.d.ts +6 -0
  121. package/dist/types/data-structures/directed-graph.js +9 -0
  122. package/dist/types/data-structures/doubly-linked-list.d.ts +1 -0
  123. package/dist/types/data-structures/doubly-linked-list.js +2 -0
  124. package/dist/types/data-structures/heap.d.ts +3 -0
  125. package/dist/types/data-structures/heap.js +2 -0
  126. package/dist/{data-structures/types → types/data-structures}/index.d.ts +3 -1
  127. package/dist/{data-structures/types → types/data-structures}/index.js +3 -1
  128. package/dist/types/data-structures/map-graph.d.ts +1 -0
  129. package/dist/types/data-structures/map-graph.js +2 -0
  130. package/dist/{data-structures/types → types/data-structures}/navigator.d.ts +2 -2
  131. package/dist/types/data-structures/navigator.js +2 -0
  132. package/dist/{data-structures/types → types/data-structures}/priority-queue.d.ts +2 -2
  133. package/dist/types/data-structures/priority-queue.js +2 -0
  134. package/dist/types/data-structures/rb-tree.d.ts +8 -0
  135. package/dist/types/data-structures/rb-tree.js +8 -0
  136. package/dist/types/data-structures/segment-tree.js +2 -0
  137. package/dist/types/data-structures/singly-linked-list.d.ts +1 -0
  138. package/dist/types/data-structures/singly-linked-list.js +2 -0
  139. package/dist/types/data-structures/tree-multiset.d.ts +4 -0
  140. package/dist/types/data-structures/tree-multiset.js +2 -0
  141. package/dist/types/helpers.d.ts +1 -0
  142. package/dist/types/helpers.js +2 -0
  143. package/dist/types/index.d.ts +3 -0
  144. package/dist/types/index.js +19 -0
  145. package/dist/types/utils/index.d.ts +2 -0
  146. package/dist/types/utils/index.js +18 -0
  147. package/dist/types/utils/utils.d.ts +7 -0
  148. package/dist/types/utils/utils.js +2 -0
  149. package/dist/types/utils/validate-type.d.ts +19 -0
  150. package/dist/types/utils/validate-type.js +2 -0
  151. package/dist/utils/utils.d.ts +17 -103
  152. package/dist/utils/utils.js +40 -625
  153. package/package.json +96 -23
  154. package/.idea/data-structure-typed.iml +0 -12
  155. package/.idea/modules.xml +0 -8
  156. package/.idea/vcs.xml +0 -6
  157. package/dist/data-structures/trampoline.d.ts +0 -16
  158. package/dist/data-structures/trampoline.js +0 -130
  159. package/dist/data-structures/types/abstract-graph.d.ts +0 -29
  160. package/dist/data-structures/types/avl-tree.d.ts +0 -5
  161. package/dist/data-structures/types/binary-tree.d.ts +0 -16
  162. package/dist/data-structures/types/bst.d.ts +0 -7
  163. package/dist/data-structures/types/directed-graph.d.ts +0 -10
  164. package/dist/data-structures/types/doubly-linked-list.d.ts +0 -1
  165. package/dist/data-structures/types/heap.d.ts +0 -7
  166. package/dist/data-structures/types/singly-linked-list.d.ts +0 -5
  167. package/dist/data-structures/types/tree-multiset.d.ts +0 -5
  168. package/dist/data-structures/types/utils.d.ts +0 -52
  169. package/dist/data-structures/types/utils.js +0 -54
  170. package/src/data-structures/binary-tree/aa-tree.ts +0 -3
  171. package/src/data-structures/binary-tree/avl-tree.ts +0 -227
  172. package/src/data-structures/binary-tree/b-tree.ts +0 -3
  173. package/src/data-structures/binary-tree/binary-indexed-tree.ts +0 -33
  174. package/src/data-structures/binary-tree/binary-tree.ts +0 -1133
  175. package/src/data-structures/binary-tree/bst.ts +0 -395
  176. package/src/data-structures/binary-tree/diagrams/avl-tree-inserting.gif +0 -0
  177. package/src/data-structures/binary-tree/diagrams/bst-rotation.gif +0 -0
  178. package/src/data-structures/binary-tree/diagrams/segment-tree.png +0 -0
  179. package/src/data-structures/binary-tree/index.ts +0 -11
  180. package/src/data-structures/binary-tree/rb-tree.ts +0 -3
  181. package/src/data-structures/binary-tree/segment-tree.ts +0 -172
  182. package/src/data-structures/binary-tree/splay-tree.ts +0 -3
  183. package/src/data-structures/binary-tree/tree-multiset.ts +0 -18
  184. package/src/data-structures/binary-tree/two-three-tree.ts +0 -3
  185. package/src/data-structures/diagrams/README.md +0 -7
  186. package/src/data-structures/graph/abstract-graph.ts +0 -753
  187. package/src/data-structures/graph/diagrams/adjacency-list-pros-cons.png +0 -0
  188. package/src/data-structures/graph/diagrams/adjacency-list.png +0 -0
  189. package/src/data-structures/graph/diagrams/adjacency-matrix-pros-cons.png +0 -0
  190. package/src/data-structures/graph/diagrams/adjacency-matrix.png +0 -0
  191. package/src/data-structures/graph/diagrams/dfs-can-do.png +0 -0
  192. package/src/data-structures/graph/diagrams/edge-list-pros-cons.png +0 -0
  193. package/src/data-structures/graph/diagrams/edge-list.png +0 -0
  194. package/src/data-structures/graph/diagrams/max-flow.png +0 -0
  195. package/src/data-structures/graph/diagrams/mst.png +0 -0
  196. package/src/data-structures/graph/diagrams/tarjan-articulation-point-bridge.png +0 -0
  197. package/src/data-structures/graph/diagrams/tarjan-complicate-simple.png +0 -0
  198. package/src/data-structures/graph/diagrams/tarjan-strongly-connected-component.png +0 -0
  199. package/src/data-structures/graph/diagrams/tarjan.mp4 +0 -0
  200. package/src/data-structures/graph/directed-graph.ts +0 -306
  201. package/src/data-structures/graph/index.ts +0 -3
  202. package/src/data-structures/graph/undirected-graph.ts +0 -155
  203. package/src/data-structures/hash/coordinate-map.ts +0 -24
  204. package/src/data-structures/hash/coordinate-set.ts +0 -20
  205. package/src/data-structures/hash/index.ts +0 -6
  206. package/src/data-structures/heap/heap.ts +0 -127
  207. package/src/data-structures/heap/index.ts +0 -3
  208. package/src/data-structures/heap/max-heap.ts +0 -23
  209. package/src/data-structures/heap/min-heap.ts +0 -25
  210. package/src/data-structures/index.ts +0 -12
  211. package/src/data-structures/linked-list/doubly-linked-list.ts +0 -250
  212. package/src/data-structures/linked-list/index.ts +0 -2
  213. package/src/data-structures/linked-list/singly-linked-list.ts +0 -736
  214. package/src/data-structures/linked-list/skip-linked-list.ts +0 -1
  215. package/src/data-structures/matrix/index.ts +0 -4
  216. package/src/data-structures/matrix/matrix.ts +0 -13
  217. package/src/data-structures/matrix/matrix2d.ts +0 -125
  218. package/src/data-structures/matrix/navigator.ts +0 -87
  219. package/src/data-structures/matrix/vector2d.ts +0 -189
  220. package/src/data-structures/priority-queue/index.ts +0 -3
  221. package/src/data-structures/priority-queue/max-priority-queue.ts +0 -13
  222. package/src/data-structures/priority-queue/min-priority-queue.ts +0 -13
  223. package/src/data-structures/priority-queue/priority-queue.ts +0 -200
  224. package/src/data-structures/queue/deque.ts +0 -139
  225. package/src/data-structures/queue/index.ts +0 -2
  226. package/src/data-structures/queue/queue.ts +0 -122
  227. package/src/data-structures/stack/index.ts +0 -1
  228. package/src/data-structures/stack/stack.ts +0 -103
  229. package/src/data-structures/trampoline.ts +0 -51
  230. package/src/data-structures/trie/index.ts +0 -1
  231. package/src/data-structures/trie/trie.ts +0 -203
  232. package/src/data-structures/types/abstract-graph.ts +0 -51
  233. package/src/data-structures/types/avl-tree.ts +0 -6
  234. package/src/data-structures/types/binary-tree.ts +0 -15
  235. package/src/data-structures/types/bst.ts +0 -5
  236. package/src/data-structures/types/directed-graph.ts +0 -18
  237. package/src/data-structures/types/doubly-linked-list.ts +0 -1
  238. package/src/data-structures/types/heap.ts +0 -8
  239. package/src/data-structures/types/navigator.ts +0 -12
  240. package/src/data-structures/types/priority-queue.ts +0 -9
  241. package/src/data-structures/types/segment-tree.ts +0 -1
  242. package/src/data-structures/types/singly-linked-list.ts +0 -15
  243. package/src/data-structures/types/tree-multiset.ts +0 -3
  244. package/src/data-structures/types/utils.ts +0 -173
  245. package/src/index.ts +0 -1
  246. package/src/utils/index.ts +0 -1
  247. package/src/utils/utils.ts +0 -505
  248. package/tsconfig.json +0 -56
  249. /package/dist/{data-structures/types/abstract-graph.js → interfaces/abstract-binary-tree.js} +0 -0
  250. /package/dist/{data-structures/types/avl-tree.js → interfaces/abstract-graph.js} +0 -0
  251. /package/dist/{data-structures/types/binary-tree.js → interfaces/avl-tree.js} +0 -0
  252. /package/dist/{data-structures/types/bst.js → interfaces/binary-tree.js} +0 -0
  253. /package/dist/{data-structures/types/directed-graph.js → interfaces/bst.js} +0 -0
  254. /package/dist/{data-structures/types/doubly-linked-list.js → interfaces/directed-graph.js} +0 -0
  255. /package/{src/data-structures/hash/pair.ts → dist/interfaces/doubly-linked-list.d.ts} +0 -0
  256. /package/dist/{data-structures/types/heap.js → interfaces/doubly-linked-list.js} +0 -0
  257. /package/{src/data-structures/hash/tree-map.ts → dist/interfaces/heap.d.ts} +0 -0
  258. /package/dist/{data-structures/types/navigator.js → interfaces/heap.js} +0 -0
  259. /package/{src/data-structures/hash/tree-set.ts → dist/interfaces/navigator.d.ts} +0 -0
  260. /package/dist/{data-structures/types/priority-queue.js → interfaces/navigator.js} +0 -0
  261. /package/dist/{data-structures/types/segment-tree.js → interfaces/priority-queue.js} +0 -0
  262. /package/dist/{data-structures/types/singly-linked-list.js → interfaces/rb-tree.js} +0 -0
  263. /package/dist/{data-structures/types/tree-multiset.js → interfaces/segment-tree.js} +0 -0
  264. /package/dist/{data-structures/types → types/data-structures}/segment-tree.d.ts +0 -0
@@ -1 +1,2 @@
1
- export {};
1
+ export declare class SkipLinkedList {
2
+ }
@@ -1,2 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SkipLinkedList = void 0;
4
+ class SkipLinkedList {
5
+ }
6
+ exports.SkipLinkedList = SkipLinkedList;
@@ -1,5 +1,17 @@
1
+ /**
2
+ * data-structure-typed
3
+ *
4
+ * @author Tyler Zeng
5
+ * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
6
+ * @license MIT License
7
+ */
1
8
  export declare class MatrixNTI2D<T = number> {
2
9
  private readonly _matrix;
10
+ /**
11
+ * The constructor creates a matrix with the specified number of rows and columns, and initializes all elements to a
12
+ * given initial value or 0 if not provided.
13
+ * @param options - An object containing the following properties:
14
+ */
3
15
  constructor(options: {
4
16
  row: number;
5
17
  col: number;
@@ -1,15 +1,28 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.MatrixNTI2D = void 0;
4
+ /**
5
+ * data-structure-typed
6
+ *
7
+ * @author Tyler Zeng
8
+ * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
9
+ * @license MIT License
10
+ */
4
11
  // todo need to be improved
5
- var MatrixNTI2D = /** @class */ (function () {
6
- function MatrixNTI2D(options) {
7
- var row = options.row, col = options.col, initialVal = options.initialVal;
8
- this._matrix = new Array(row).fill(undefined).map(function () { return new Array(col).fill(initialVal || 0); });
12
+ class MatrixNTI2D {
13
+ /**
14
+ * The constructor creates a matrix with the specified number of rows and columns, and initializes all elements to a
15
+ * given initial value or 0 if not provided.
16
+ * @param options - An object containing the following properties:
17
+ */
18
+ constructor(options) {
19
+ const { row, col, initialVal } = options;
20
+ this._matrix = new Array(row).fill(undefined).map(() => new Array(col).fill(initialVal || 0));
9
21
  }
10
- MatrixNTI2D.prototype.toArray = function () {
22
+ /* The `toArray` method returns the matrix as a two-dimensional array. It converts the internal representation of the
23
+ matrix, which is an array of arrays, into a format that is more commonly used in JavaScript. */
24
+ toArray() {
11
25
  return this._matrix;
12
- };
13
- return MatrixNTI2D;
14
- }());
26
+ }
27
+ }
15
28
  exports.MatrixNTI2D = MatrixNTI2D;
@@ -1,25 +1,108 @@
1
+ /**
2
+ * data-structure-typed
3
+ *
4
+ * @author Tyler Zeng
5
+ * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
6
+ * @license MIT License
7
+ */
1
8
  import Vector2D from './vector2d';
2
9
  export declare class Matrix2D {
3
10
  private readonly _matrix;
11
+ /**
12
+ * The constructor function initializes a Matrix2D object with either a default identity matrix, or a provided matrix
13
+ * or Vector2D object.
14
+ * @param {number[][] | Vector2D} [value] - The `value` parameter can be either a 2D array of numbers (`number[][]`) or
15
+ * an instance of the `Vector2D` class.
16
+ */
4
17
  constructor(value?: number[][] | Vector2D);
18
+ /**
19
+ * The function returns a 2D array with three empty arrays.
20
+ * @returns An empty 2-dimensional array with 3 empty arrays inside.
21
+ */
5
22
  static get empty(): number[][];
6
23
  /**
7
- * Initialize an identity matrix
24
+ * The above function returns a 3x3 identity matrix.
25
+ * @returns The method is returning a 2-dimensional array of numbers representing the identity matrix.
8
26
  */
9
27
  static get identity(): number[][];
10
28
  /**
11
- * Return the matrix values
29
+ * The function returns a two-dimensional array of numbers.
30
+ * @returns The getter method is returning the value of the private variable `_matrix`, which is a two-dimensional
31
+ * array of numbers.
12
32
  */
13
33
  get m(): number[][];
34
+ /**
35
+ * The function "toVector" returns a new Vector2D object with the values from the first and second elements of the
36
+ * _matrix array.
37
+ * @returns A new instance of the Vector2D class is being returned. The values of the returned vector are taken from
38
+ * the first column of the matrix.
39
+ */
14
40
  get toVector(): Vector2D;
41
+ /**
42
+ * The function takes two 2D matrices as input and returns their sum as a new 2D matrix.
43
+ * @param {Matrix2D} matrix1 - Matrix2D - The first matrix to be added.
44
+ * @param {Matrix2D} matrix2 - The parameter `matrix2` is a Matrix2D object.
45
+ * @returns a new instance of the Matrix2D class, which is created using the result array.
46
+ */
15
47
  static add(matrix1: Matrix2D, matrix2: Matrix2D): Matrix2D;
48
+ /**
49
+ * The function subtracts two 2D matrices and returns the result as a new Matrix2D object.
50
+ * @param {Matrix2D} matrix1 - Matrix2D - The first matrix to subtract from.
51
+ * @param {Matrix2D} matrix2 - Matrix2D is a class representing a 2D matrix. It has a property `m` which is a 2D array
52
+ * representing the matrix elements.
53
+ * @returns a new instance of the Matrix2D class, which is created using the result array.
54
+ */
16
55
  static subtract(matrix1: Matrix2D, matrix2: Matrix2D): Matrix2D;
56
+ /**
57
+ * The function multiplies two 2D matrices and returns the result as a new Matrix2D object.
58
+ * @param {Matrix2D} matrix1 - A 2D matrix represented by the Matrix2D class.
59
+ * @param {Matrix2D} matrix2 - The parameter `matrix2` is a 2D matrix of size 3x3.
60
+ * @returns a new instance of the Matrix2D class, created using the result array.
61
+ */
17
62
  static multiply(matrix1: Matrix2D, matrix2: Matrix2D): Matrix2D;
63
+ /**
64
+ * The function multiplies each element of a 2D matrix by a given value and returns the resulting matrix.
65
+ * @param {Matrix2D} matrix - The `matrix` parameter is an instance of the `Matrix2D` class, which represents a 2D
66
+ * matrix. It contains a property `m` that is a 2D array representing the matrix elements.
67
+ * @param {number} value - The `value` parameter is a number that you want to multiply each element of the `matrix` by.
68
+ * @returns a new instance of the Matrix2D class, which is created using the result array.
69
+ */
18
70
  static multiplyByValue(matrix: Matrix2D, value: number): Matrix2D;
71
+ /**
72
+ * The function multiplies a 2D matrix by a 2D vector and returns the result as a 2D vector.
73
+ * @param {Matrix2D} matrix - The parameter "matrix" is of type Matrix2D. It represents a 2-dimensional matrix.
74
+ * @param {Vector2D} vector - The "vector" parameter is a 2D vector, represented by an object of type Vector2D.
75
+ * @returns a Vector2D.
76
+ */
19
77
  static multiplyByVector(matrix: Matrix2D, vector: Vector2D): Vector2D;
78
+ /**
79
+ * The function returns a 2D matrix that scales and flips a vector around the center of a given width and height.
80
+ * @param {number} width - The width parameter represents the width of the view or the canvas. It is a number that
81
+ * specifies the width in pixels or any other unit of measurement.
82
+ * @param {number} height - The height parameter represents the height of the view or the canvas. It is used to
83
+ * calculate the centerY value, which is the vertical center of the view.
84
+ * @returns a Matrix2D object.
85
+ */
20
86
  static view(width: number, height: number): Matrix2D;
87
+ /**
88
+ * The function scales a matrix by a given factor.
89
+ * @param {number} factor - The factor parameter is a number that represents the scaling factor by which the matrix
90
+ * should be scaled.
91
+ * @returns the result of multiplying a new instance of Matrix2D by the given factor.
92
+ */
21
93
  static scale(factor: number): Matrix2D;
94
+ /**
95
+ * The function "rotate" takes an angle in radians and returns a 2D transformation matrix for rotating objects.
96
+ * @param {number} radians - The "radians" parameter is the angle in radians by which you want to rotate an object.
97
+ * @returns The code is returning a new instance of a Matrix2D object.
98
+ */
22
99
  static rotate(radians: number): Matrix2D;
100
+ /**
101
+ * The translate function takes a 2D vector and returns a 2D matrix that represents a translation transformation.
102
+ * @param {Vector2D} vector - The parameter "vector" is of type Vector2D. It represents a 2D vector with components x
103
+ * and y, and an optional w component.
104
+ * @returns The method is returning a new instance of the Matrix2D class.
105
+ */
23
106
  static translate(vector: Vector2D): Matrix2D;
24
107
  }
25
108
  export default Matrix2D;
@@ -4,9 +4,22 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.Matrix2D = void 0;
7
- var vector2d_1 = __importDefault(require("./vector2d"));
8
- var Matrix2D = /** @class */ (function () {
9
- function Matrix2D(value) {
7
+ /**
8
+ * data-structure-typed
9
+ *
10
+ * @author Tyler Zeng
11
+ * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
12
+ * @license MIT License
13
+ */
14
+ const vector2d_1 = __importDefault(require("./vector2d"));
15
+ class Matrix2D {
16
+ /**
17
+ * The constructor function initializes a Matrix2D object with either a default identity matrix, or a provided matrix
18
+ * or Vector2D object.
19
+ * @param {number[][] | Vector2D} [value] - The `value` parameter can be either a 2D array of numbers (`number[][]`) or
20
+ * an instance of the `Vector2D` class.
21
+ */
22
+ constructor(value) {
10
23
  if (typeof value === 'undefined') {
11
24
  this._matrix = Matrix2D.identity;
12
25
  }
@@ -20,117 +33,170 @@ var Matrix2D = /** @class */ (function () {
20
33
  this._matrix = value;
21
34
  }
22
35
  }
23
- Object.defineProperty(Matrix2D, "empty", {
24
- get: function () {
25
- return [[], [], []];
26
- },
27
- enumerable: false,
28
- configurable: true
29
- });
30
- Object.defineProperty(Matrix2D, "identity", {
31
- /**
32
- * Initialize an identity matrix
33
- */
34
- get: function () {
35
- return [
36
- [1, 0, 0],
37
- [0, 1, 0],
38
- [0, 0, 1]
39
- ];
40
- },
41
- enumerable: false,
42
- configurable: true
43
- });
44
- Object.defineProperty(Matrix2D.prototype, "m", {
45
- /**
46
- * Return the matrix values
47
- */
48
- get: function () {
49
- return this._matrix;
50
- },
51
- enumerable: false,
52
- configurable: true
53
- });
54
- Object.defineProperty(Matrix2D.prototype, "toVector", {
55
- get: function () {
56
- return new vector2d_1.default(this._matrix[0][0], this._matrix[1][0]);
57
- },
58
- enumerable: false,
59
- configurable: true
60
- });
61
- Matrix2D.add = function (matrix1, matrix2) {
62
- var result = Matrix2D.empty;
63
- for (var i = 0; i < 3; i++) {
64
- for (var j = 0; j < 3; j++) {
36
+ /**
37
+ * The function returns a 2D array with three empty arrays.
38
+ * @returns An empty 2-dimensional array with 3 empty arrays inside.
39
+ */
40
+ static get empty() {
41
+ return [[], [], []];
42
+ }
43
+ /**
44
+ * The above function returns a 3x3 identity matrix.
45
+ * @returns The method is returning a 2-dimensional array of numbers representing the identity matrix.
46
+ */
47
+ static get identity() {
48
+ return [
49
+ [1, 0, 0],
50
+ [0, 1, 0],
51
+ [0, 0, 1]
52
+ ];
53
+ }
54
+ /**
55
+ * The function returns a two-dimensional array of numbers.
56
+ * @returns The getter method is returning the value of the private variable `_matrix`, which is a two-dimensional
57
+ * array of numbers.
58
+ */
59
+ get m() {
60
+ return this._matrix;
61
+ }
62
+ /**
63
+ * The function "toVector" returns a new Vector2D object with the values from the first and second elements of the
64
+ * _matrix array.
65
+ * @returns A new instance of the Vector2D class is being returned. The values of the returned vector are taken from
66
+ * the first column of the matrix.
67
+ */
68
+ get toVector() {
69
+ return new vector2d_1.default(this._matrix[0][0], this._matrix[1][0]);
70
+ }
71
+ /**
72
+ * The function takes two 2D matrices as input and returns their sum as a new 2D matrix.
73
+ * @param {Matrix2D} matrix1 - Matrix2D - The first matrix to be added.
74
+ * @param {Matrix2D} matrix2 - The parameter `matrix2` is a Matrix2D object.
75
+ * @returns a new instance of the Matrix2D class, which is created using the result array.
76
+ */
77
+ static add(matrix1, matrix2) {
78
+ const result = Matrix2D.empty;
79
+ for (let i = 0; i < 3; i++) {
80
+ for (let j = 0; j < 3; j++) {
65
81
  result[i][j] = matrix1.m[i][j] + matrix2.m[i][j];
66
82
  }
67
83
  }
68
84
  return new Matrix2D(result);
69
- };
70
- Matrix2D.subtract = function (matrix1, matrix2) {
71
- var result = Matrix2D.empty;
72
- for (var i = 0; i < 3; i++) {
73
- for (var j = 0; j < 3; j++) {
85
+ }
86
+ /**
87
+ * The function subtracts two 2D matrices and returns the result as a new Matrix2D object.
88
+ * @param {Matrix2D} matrix1 - Matrix2D - The first matrix to subtract from.
89
+ * @param {Matrix2D} matrix2 - Matrix2D is a class representing a 2D matrix. It has a property `m` which is a 2D array
90
+ * representing the matrix elements.
91
+ * @returns a new instance of the Matrix2D class, which is created using the result array.
92
+ */
93
+ static subtract(matrix1, matrix2) {
94
+ const result = Matrix2D.empty;
95
+ for (let i = 0; i < 3; i++) {
96
+ for (let j = 0; j < 3; j++) {
74
97
  result[i][j] = matrix1.m[i][j] - matrix2.m[i][j];
75
98
  }
76
99
  }
77
100
  return new Matrix2D(result);
78
- };
79
- Matrix2D.multiply = function (matrix1, matrix2) {
80
- var result = Matrix2D.empty;
81
- for (var i = 0; i < 3; i++) {
82
- for (var j = 0; j < 3; j++) {
101
+ }
102
+ /**
103
+ * The function multiplies two 2D matrices and returns the result as a new Matrix2D object.
104
+ * @param {Matrix2D} matrix1 - A 2D matrix represented by the Matrix2D class.
105
+ * @param {Matrix2D} matrix2 - The parameter `matrix2` is a 2D matrix of size 3x3.
106
+ * @returns a new instance of the Matrix2D class, created using the result array.
107
+ */
108
+ static multiply(matrix1, matrix2) {
109
+ const result = Matrix2D.empty;
110
+ for (let i = 0; i < 3; i++) {
111
+ for (let j = 0; j < 3; j++) {
83
112
  result[i][j] = 0;
84
- for (var k = 0; k < 3; k++) {
113
+ for (let k = 0; k < 3; k++) {
85
114
  result[i][j] += matrix1.m[i][k] * matrix2.m[k][j];
86
115
  }
87
116
  }
88
117
  }
89
118
  return new Matrix2D(result);
90
- };
91
- Matrix2D.multiplyByValue = function (matrix, value) {
92
- var result = Matrix2D.empty;
93
- for (var i = 0; i < 3; i++) {
94
- for (var j = 0; j < 3; j++) {
119
+ }
120
+ /**
121
+ * The function multiplies each element of a 2D matrix by a given value and returns the resulting matrix.
122
+ * @param {Matrix2D} matrix - The `matrix` parameter is an instance of the `Matrix2D` class, which represents a 2D
123
+ * matrix. It contains a property `m` that is a 2D array representing the matrix elements.
124
+ * @param {number} value - The `value` parameter is a number that you want to multiply each element of the `matrix` by.
125
+ * @returns a new instance of the Matrix2D class, which is created using the result array.
126
+ */
127
+ static multiplyByValue(matrix, value) {
128
+ const result = Matrix2D.empty;
129
+ for (let i = 0; i < 3; i++) {
130
+ for (let j = 0; j < 3; j++) {
95
131
  result[i][j] = matrix.m[i][j] * value;
96
132
  }
97
133
  }
98
134
  return new Matrix2D(result);
99
- };
100
- Matrix2D.multiplyByVector = function (matrix, vector) {
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
+ */
142
+ static multiplyByVector(matrix, vector) {
101
143
  return Matrix2D.multiply(matrix, new Matrix2D(vector)).toVector;
102
- };
103
- Matrix2D.view = function (width, height) {
104
- var scaleStep = 1; // Scale every vector * scaleStep
105
- var centerX = width / 2;
106
- var centerY = height / 2;
107
- var flipX = Math.cos(Math.PI); // rotate 180deg / 3.14radian around X-axis
144
+ }
145
+ /**
146
+ * The function returns a 2D matrix that scales and flips a vector around the center of a given width and height.
147
+ * @param {number} width - The width parameter represents the width of the view or the canvas. It is a number that
148
+ * specifies the width in pixels or any other unit of measurement.
149
+ * @param {number} height - The height parameter represents the height of the view or the canvas. It is used to
150
+ * calculate the centerY value, which is the vertical center of the view.
151
+ * @returns a Matrix2D object.
152
+ */
153
+ static view(width, height) {
154
+ const scaleStep = 1; // Scale every vector * scaleStep
155
+ const centerX = width / 2;
156
+ const centerY = height / 2;
157
+ const flipX = Math.cos(Math.PI); // rotate 180deg / 3.14radian around X-axis
108
158
  return new Matrix2D([
109
159
  [scaleStep, 0, centerX],
110
160
  [0, flipX * scaleStep, centerY],
111
161
  [0, 0, 1]
112
162
  ]);
113
- };
114
- Matrix2D.scale = function (factor) {
163
+ }
164
+ /**
165
+ * The function scales a matrix by a given factor.
166
+ * @param {number} factor - The factor parameter is a number that represents the scaling factor by which the matrix
167
+ * should be scaled.
168
+ * @returns the result of multiplying a new instance of Matrix2D by the given factor.
169
+ */
170
+ static scale(factor) {
115
171
  return Matrix2D.multiplyByValue(new Matrix2D(), factor);
116
- };
117
- Matrix2D.rotate = function (radians) {
118
- var cos = Math.cos(radians);
119
- var sin = Math.sin(radians);
172
+ }
173
+ /**
174
+ * The function "rotate" takes an angle in radians and returns a 2D transformation matrix for rotating objects.
175
+ * @param {number} radians - The "radians" parameter is the angle in radians by which you want to rotate an object.
176
+ * @returns The code is returning a new instance of a Matrix2D object.
177
+ */
178
+ static rotate(radians) {
179
+ const cos = Math.cos(radians);
180
+ const sin = Math.sin(radians);
120
181
  return new Matrix2D([
121
182
  [cos, -sin, 0],
122
183
  [sin, cos, 0],
123
184
  [0, 0, 1]
124
185
  ]);
125
- };
126
- Matrix2D.translate = function (vector) {
186
+ }
187
+ /**
188
+ * The translate function takes a 2D vector and returns a 2D matrix that represents a translation transformation.
189
+ * @param {Vector2D} vector - The parameter "vector" is of type Vector2D. It represents a 2D vector with components x
190
+ * and y, and an optional w component.
191
+ * @returns The method is returning a new instance of the Matrix2D class.
192
+ */
193
+ static translate(vector) {
127
194
  return new Matrix2D([
128
195
  [1, 0, vector.x],
129
196
  [0, 1, vector.y],
130
197
  [0, 0, vector.w]
131
198
  ]);
132
- };
133
- return Matrix2D;
134
- }());
199
+ }
200
+ }
135
201
  exports.Matrix2D = Matrix2D;
136
202
  exports.default = Matrix2D;
@@ -1,7 +1,22 @@
1
- import type { Direction, NavigatorParams, Turning } from '../types';
1
+ /**
2
+ * data-structure-typed
3
+ *
4
+ * @author Tyler Zeng
5
+ * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
6
+ * @license MIT License
7
+ */
8
+ import type { Direction, NavigatorParams, Turning } from '../../types';
2
9
  export declare class Character {
3
10
  direction: Direction;
4
11
  turn: () => Character;
12
+ /**
13
+ * The constructor function takes in a direction and turning object and sets the direction and turn properties of the
14
+ * Character class.
15
+ * @param {Direction} direction - The direction parameter is used to specify the current direction of the character. It
16
+ * can be any value that represents a direction, such as "north", "south", "east", or "west".
17
+ * @param {Turning} turning - The `turning` parameter is an object that maps each direction to the corresponding
18
+ * turning direction. It is used to determine the new direction when the character turns.
19
+ */
5
20
  constructor(direction: Direction, turning: Turning);
6
21
  }
7
22
  export declare class Navigator<T = number> {
@@ -10,8 +25,28 @@ export declare class Navigator<T = number> {
10
25
  private readonly _cur;
11
26
  private _character;
12
27
  private readonly _VISITED;
28
+ /**
29
+ * The constructor initializes the Navigator object with the given parameters and sets the current position as visited
30
+ * in the matrix.
31
+ * @param - - `matrix`: a 2D array representing the grid or map
32
+ */
13
33
  constructor({ matrix, turning, onMove, init: { cur, charDir, VISITED } }: NavigatorParams<T>);
34
+ /**
35
+ * The "start" function moves the character in its current direction until it encounters an obstacle, then it turns the
36
+ * character and repeats the process.
37
+ */
14
38
  start(): void;
39
+ /**
40
+ * The function checks if there is a valid move in the specified direction in a matrix.
41
+ * @param {Direction} direction - The direction parameter is a string that represents the direction in which to check.
42
+ * It can be one of the following values: 'up', 'right', 'down', or 'left'.
43
+ * @returns a boolean value.
44
+ */
15
45
  check(direction: Direction): boolean;
46
+ /**
47
+ * The `move` function updates the current position based on the given direction and updates the matrix accordingly.
48
+ * @param {Direction} direction - The `direction` parameter is a string that represents the direction in which to move.
49
+ * It can have one of the following values: 'up', 'right', 'down', or 'left'.
50
+ */
16
51
  move(direction: Direction): void;
17
52
  }
@@ -1,33 +1,28 @@
1
1
  "use strict";
2
- var __read = (this && this.__read) || function (o, n) {
3
- var m = typeof Symbol === "function" && o[Symbol.iterator];
4
- if (!m) return o;
5
- var i = m.call(o), r, ar = [], e;
6
- try {
7
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
8
- }
9
- catch (error) { e = { error: error }; }
10
- finally {
11
- try {
12
- if (r && !r.done && (m = i["return"])) m.call(i);
13
- }
14
- finally { if (e) throw e.error; }
15
- }
16
- return ar;
17
- };
18
2
  Object.defineProperty(exports, "__esModule", { value: true });
19
3
  exports.Navigator = exports.Character = void 0;
20
- var Character = /** @class */ (function () {
21
- function Character(direction, turning) {
4
+ class Character {
5
+ /**
6
+ * The constructor function takes in a direction and turning object and sets the direction and turn properties of the
7
+ * Character class.
8
+ * @param {Direction} direction - The direction parameter is used to specify the current direction of the character. It
9
+ * can be any value that represents a direction, such as "north", "south", "east", or "west".
10
+ * @param {Turning} turning - The `turning` parameter is an object that maps each direction to the corresponding
11
+ * turning direction. It is used to determine the new direction when the character turns.
12
+ */
13
+ constructor(direction, turning) {
22
14
  this.direction = direction;
23
- this.turn = function () { return new Character(turning[direction], turning); };
15
+ this.turn = () => new Character(turning[direction], turning);
24
16
  }
25
- return Character;
26
- }());
17
+ }
27
18
  exports.Character = Character;
28
- var Navigator = /** @class */ (function () {
29
- function Navigator(_a) {
30
- var matrix = _a.matrix, turning = _a.turning, onMove = _a.onMove, _b = _a.init, cur = _b.cur, charDir = _b.charDir, VISITED = _b.VISITED;
19
+ class Navigator {
20
+ /**
21
+ * The constructor initializes the Navigator object with the given parameters and sets the current position as visited
22
+ * in the matrix.
23
+ * @param - - `matrix`: a 2D array representing the grid or map
24
+ */
25
+ constructor({ matrix, turning, onMove, init: { cur, charDir, VISITED } }) {
31
26
  this._matrix = matrix;
32
27
  this._cur = cur;
33
28
  this._character = new Character(charDir, turning);
@@ -36,9 +31,13 @@ var Navigator = /** @class */ (function () {
36
31
  this._VISITED = VISITED;
37
32
  this._matrix[this._cur[0]][this._cur[1]] = this._VISITED;
38
33
  }
39
- Navigator.prototype.start = function () {
34
+ /**
35
+ * The "start" function moves the character in its current direction until it encounters an obstacle, then it turns the
36
+ * character and repeats the process.
37
+ */
38
+ start() {
40
39
  while (this.check(this._character.direction) || this.check(this._character.turn().direction)) {
41
- var direction = this._character.direction;
40
+ const { direction } = this._character;
42
41
  if (this.check(direction)) {
43
42
  this.move(direction);
44
43
  }
@@ -46,11 +45,17 @@ var Navigator = /** @class */ (function () {
46
45
  this._character = this._character.turn();
47
46
  }
48
47
  }
49
- };
50
- Navigator.prototype.check = function (direction) {
51
- var forward, row;
52
- var matrix = this._matrix;
53
- var _a = __read(this._cur, 2), i = _a[0], j = _a[1];
48
+ }
49
+ /**
50
+ * The function checks if there is a valid move in the specified direction in a matrix.
51
+ * @param {Direction} direction - The direction parameter is a string that represents the direction in which to check.
52
+ * It can be one of the following values: 'up', 'right', 'down', or 'left'.
53
+ * @returns a boolean value.
54
+ */
55
+ check(direction) {
56
+ let forward, row;
57
+ const matrix = this._matrix;
58
+ const [i, j] = this._cur;
54
59
  switch (direction) {
55
60
  case 'up':
56
61
  row = matrix[i - 1];
@@ -72,8 +77,13 @@ var Navigator = /** @class */ (function () {
72
77
  break;
73
78
  }
74
79
  return forward !== undefined && forward !== this._VISITED;
75
- };
76
- Navigator.prototype.move = function (direction) {
80
+ }
81
+ /**
82
+ * The `move` function updates the current position based on the given direction and updates the matrix accordingly.
83
+ * @param {Direction} direction - The `direction` parameter is a string that represents the direction in which to move.
84
+ * It can have one of the following values: 'up', 'right', 'down', or 'left'.
85
+ */
86
+ move(direction) {
77
87
  switch (direction) {
78
88
  case 'up':
79
89
  this._cur[0]--;
@@ -88,10 +98,9 @@ var Navigator = /** @class */ (function () {
88
98
  this._cur[1]--;
89
99
  break;
90
100
  }
91
- var _a = __read(this._cur, 2), i = _a[0], j = _a[1];
101
+ const [i, j] = this._cur;
92
102
  this._matrix[i][j] = this._VISITED;
93
103
  this.onMove && this.onMove(this._cur);
94
- };
95
- return Navigator;
96
- }());
104
+ }
105
+ }
97
106
  exports.Navigator = Navigator;