data-structure-typed 0.8.18 → 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 (272) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +690 -2
  3. package/dist/bundle.js +2 -0
  4. package/dist/bundle.js.LICENSE.txt +13 -0
  5. package/dist/data-structures/binary-tree/abstract-binary-tree.d.ts +364 -0
  6. package/dist/data-structures/binary-tree/abstract-binary-tree.js +1308 -0
  7. package/dist/data-structures/binary-tree/avl-tree.d.ts +85 -18
  8. package/dist/data-structures/binary-tree/avl-tree.js +110 -37
  9. package/dist/data-structures/binary-tree/binary-indexed-tree.d.ts +40 -2
  10. package/dist/data-structures/binary-tree/binary-indexed-tree.js +44 -2
  11. package/dist/data-structures/binary-tree/binary-tree.d.ts +29 -138
  12. package/dist/data-structures/binary-tree/binary-tree.js +27 -979
  13. package/dist/data-structures/binary-tree/bst.d.ts +118 -28
  14. package/dist/data-structures/binary-tree/bst.js +162 -124
  15. package/dist/data-structures/binary-tree/index.d.ts +1 -0
  16. package/dist/data-structures/binary-tree/index.js +1 -0
  17. package/dist/data-structures/binary-tree/rb-tree.d.ts +18 -1
  18. package/dist/data-structures/binary-tree/rb-tree.js +40 -2
  19. package/dist/data-structures/binary-tree/segment-tree.d.ts +63 -13
  20. package/dist/data-structures/binary-tree/segment-tree.js +80 -17
  21. package/dist/data-structures/binary-tree/tree-multiset.d.ts +213 -10
  22. package/dist/data-structures/binary-tree/tree-multiset.js +682 -9
  23. package/dist/data-structures/graph/abstract-graph.d.ts +270 -64
  24. package/dist/data-structures/graph/abstract-graph.js +365 -92
  25. package/dist/data-structures/graph/directed-graph.d.ts +175 -26
  26. package/dist/data-structures/graph/directed-graph.js +249 -95
  27. package/dist/data-structures/graph/index.d.ts +1 -0
  28. package/dist/data-structures/graph/index.js +1 -0
  29. package/dist/data-structures/graph/map-graph.d.ts +79 -0
  30. package/dist/data-structures/graph/map-graph.js +111 -0
  31. package/dist/data-structures/graph/undirected-graph.d.ts +111 -8
  32. package/dist/data-structures/graph/undirected-graph.js +154 -44
  33. package/dist/data-structures/hash/coordinate-map.d.ts +39 -2
  34. package/dist/data-structures/hash/coordinate-map.js +44 -3
  35. package/dist/data-structures/hash/coordinate-set.d.ts +32 -2
  36. package/dist/data-structures/hash/coordinate-set.js +34 -0
  37. package/dist/data-structures/hash/hash-table.d.ts +2 -1
  38. package/dist/data-structures/hash/hash-table.js +4 -0
  39. package/dist/data-structures/hash/index.d.ts +5 -0
  40. package/dist/data-structures/hash/index.js +5 -0
  41. package/dist/data-structures/hash/pair.d.ts +2 -1
  42. package/dist/data-structures/hash/pair.js +4 -0
  43. package/dist/data-structures/hash/tree-map.d.ts +2 -1
  44. package/dist/data-structures/hash/tree-map.js +4 -0
  45. package/dist/data-structures/hash/tree-set.d.ts +2 -1
  46. package/dist/data-structures/hash/tree-set.js +4 -0
  47. package/dist/data-structures/heap/heap.d.ts +62 -51
  48. package/dist/data-structures/heap/heap.js +106 -63
  49. package/dist/data-structures/heap/max-heap.d.ts +13 -4
  50. package/dist/data-structures/heap/max-heap.js +10 -2
  51. package/dist/data-structures/heap/min-heap.d.ts +14 -4
  52. package/dist/data-structures/heap/min-heap.js +11 -2
  53. package/dist/data-structures/index.d.ts +1 -0
  54. package/dist/data-structures/index.js +1 -0
  55. package/dist/data-structures/linked-list/doubly-linked-list.d.ts +193 -57
  56. package/dist/data-structures/linked-list/doubly-linked-list.js +461 -194
  57. package/dist/data-structures/linked-list/index.d.ts +1 -0
  58. package/dist/data-structures/linked-list/index.js +1 -0
  59. package/dist/data-structures/linked-list/singly-linked-list.d.ts +117 -319
  60. package/dist/data-structures/linked-list/singly-linked-list.js +338 -557
  61. package/dist/data-structures/linked-list/skip-linked-list.d.ts +2 -1
  62. package/dist/data-structures/linked-list/skip-linked-list.js +4 -0
  63. package/dist/data-structures/matrix/matrix.d.ts +12 -0
  64. package/dist/data-structures/matrix/matrix.js +14 -0
  65. package/dist/data-structures/matrix/matrix2d.d.ts +87 -4
  66. package/dist/data-structures/matrix/matrix2d.js +91 -8
  67. package/dist/data-structures/matrix/navigator.d.ts +37 -16
  68. package/dist/data-structures/matrix/navigator.js +28 -0
  69. package/dist/data-structures/matrix/vector2d.d.ts +156 -29
  70. package/dist/data-structures/matrix/vector2d.js +184 -55
  71. package/dist/data-structures/priority-queue/max-priority-queue.d.ts +12 -1
  72. package/dist/data-structures/priority-queue/max-priority-queue.js +28 -4
  73. package/dist/data-structures/priority-queue/min-priority-queue.d.ts +12 -1
  74. package/dist/data-structures/priority-queue/min-priority-queue.js +29 -4
  75. package/dist/data-structures/priority-queue/priority-queue.d.ts +166 -22
  76. package/dist/data-structures/priority-queue/priority-queue.js +219 -75
  77. package/dist/data-structures/queue/deque.d.ts +141 -13
  78. package/dist/data-structures/queue/deque.js +151 -7
  79. package/dist/data-structures/queue/queue.d.ts +68 -42
  80. package/dist/data-structures/queue/queue.js +95 -51
  81. package/dist/data-structures/stack/stack.d.ts +30 -36
  82. package/dist/data-structures/stack/stack.js +31 -37
  83. package/dist/data-structures/tree/index.d.ts +1 -0
  84. package/dist/data-structures/tree/index.js +17 -0
  85. package/dist/data-structures/tree/tree.d.ts +14 -0
  86. package/dist/{types/utils.js → data-structures/tree/tree.js} +26 -19
  87. package/dist/data-structures/trie/trie.d.ts +39 -6
  88. package/dist/data-structures/trie/trie.js +81 -12
  89. package/dist/index.d.ts +3 -0
  90. package/dist/index.js +3 -0
  91. package/dist/interfaces/abstract-binary-tree.d.ts +90 -0
  92. package/dist/interfaces/abstract-binary-tree.js +2 -0
  93. package/dist/interfaces/abstract-graph.d.ts +17 -0
  94. package/dist/interfaces/abstract-graph.js +2 -0
  95. package/dist/interfaces/avl-tree.d.ts +9 -0
  96. package/dist/interfaces/avl-tree.js +2 -0
  97. package/dist/interfaces/binary-tree.d.ts +6 -0
  98. package/dist/interfaces/binary-tree.js +2 -0
  99. package/dist/interfaces/bst.d.ts +17 -0
  100. package/dist/interfaces/bst.js +2 -0
  101. package/dist/interfaces/directed-graph.d.ts +12 -0
  102. package/dist/interfaces/directed-graph.js +2 -0
  103. package/dist/interfaces/doubly-linked-list.js +2 -0
  104. package/dist/interfaces/heap.js +2 -0
  105. package/dist/interfaces/index.d.ts +15 -0
  106. package/dist/interfaces/index.js +31 -0
  107. package/dist/interfaces/navigator.js +2 -0
  108. package/dist/interfaces/priority-queue.js +2 -0
  109. package/dist/interfaces/rb-tree.d.ts +8 -0
  110. package/dist/interfaces/rb-tree.js +2 -0
  111. package/dist/interfaces/segment-tree.js +2 -0
  112. package/dist/interfaces/singly-linked-list.js +2 -0
  113. package/dist/interfaces/tree-multiset.d.ts +7 -0
  114. package/dist/interfaces/tree-multiset.js +2 -0
  115. package/dist/interfaces/undirected-graph.d.ts +5 -0
  116. package/dist/interfaces/undirected-graph.js +2 -0
  117. package/dist/types/data-structures/abstract-binary-tree.d.ts +34 -0
  118. package/dist/types/data-structures/abstract-binary-tree.js +25 -0
  119. package/dist/types/data-structures/abstract-graph.d.ts +11 -0
  120. package/dist/types/data-structures/abstract-graph.js +2 -0
  121. package/dist/types/data-structures/avl-tree.d.ts +4 -0
  122. package/dist/types/data-structures/avl-tree.js +2 -0
  123. package/dist/types/data-structures/binary-tree.d.ts +4 -0
  124. package/dist/types/data-structures/binary-tree.js +2 -0
  125. package/dist/types/data-structures/bst.d.ts +13 -0
  126. package/dist/types/data-structures/bst.js +9 -0
  127. package/dist/types/data-structures/directed-graph.d.ts +6 -0
  128. package/dist/types/data-structures/directed-graph.js +9 -0
  129. package/dist/types/data-structures/doubly-linked-list.js +2 -0
  130. package/dist/types/data-structures/heap.d.ts +3 -0
  131. package/dist/types/data-structures/heap.js +2 -0
  132. package/dist/types/data-structures/index.d.ts +13 -7
  133. package/dist/types/data-structures/index.js +31 -0
  134. package/dist/types/data-structures/map-graph.d.ts +1 -0
  135. package/dist/types/data-structures/map-graph.js +2 -0
  136. package/dist/types/data-structures/navigator.d.ts +14 -0
  137. package/dist/types/data-structures/navigator.js +2 -0
  138. package/dist/types/data-structures/priority-queue.d.ts +7 -0
  139. package/dist/types/data-structures/priority-queue.js +2 -0
  140. package/dist/types/data-structures/rb-tree.d.ts +8 -0
  141. package/dist/types/data-structures/rb-tree.js +8 -0
  142. package/dist/types/data-structures/segment-tree.d.ts +1 -0
  143. package/dist/types/data-structures/segment-tree.js +2 -0
  144. package/dist/types/data-structures/singly-linked-list.js +2 -0
  145. package/dist/types/data-structures/tree-multiset.d.ts +4 -0
  146. package/dist/types/data-structures/tree-multiset.js +2 -0
  147. package/dist/types/helpers.d.ts +1 -0
  148. package/dist/types/helpers.js +2 -0
  149. package/dist/types/index.d.ts +2 -0
  150. package/dist/types/index.js +2 -0
  151. package/dist/types/utils/index.d.ts +2 -0
  152. package/dist/types/utils/index.js +18 -0
  153. package/dist/types/utils/utils.d.ts +7 -0
  154. package/dist/types/utils/utils.js +2 -0
  155. package/dist/types/utils/validate-type.d.ts +19 -0
  156. package/dist/types/utils/validate-type.js +2 -0
  157. package/dist/utils/index.js +17 -0
  158. package/dist/utils/utils.d.ts +19 -0
  159. package/dist/{data-structures/trampoline.js → utils/utils.js} +26 -12
  160. package/package.json +106 -55
  161. package/.idea/data-structure-typed.iml +0 -12
  162. package/.idea/modules.xml +0 -8
  163. package/.idea/vcs.xml +0 -6
  164. package/dist/data-structures/trampoline.d.ts +0 -25
  165. package/dist/types/data-structures/binary-tree/aa-tree.d.ts +0 -2
  166. package/dist/types/data-structures/binary-tree/avl-tree.d.ts +0 -21
  167. package/dist/types/data-structures/binary-tree/b-tree.d.ts +0 -2
  168. package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +0 -8
  169. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +0 -140
  170. package/dist/types/data-structures/binary-tree/bst.d.ts +0 -32
  171. package/dist/types/data-structures/binary-tree/index.d.ts +0 -4
  172. package/dist/types/data-structures/binary-tree/rb-tree.d.ts +0 -2
  173. package/dist/types/data-structures/binary-tree/segment-tree.d.ts +0 -33
  174. package/dist/types/data-structures/binary-tree/splay-tree.d.ts +0 -2
  175. package/dist/types/data-structures/binary-tree/tree-multiset.d.ts +0 -11
  176. package/dist/types/data-structures/binary-tree/two-three-tree.d.ts +0 -2
  177. package/dist/types/data-structures/graph/abstract-graph.d.ts +0 -126
  178. package/dist/types/data-structures/graph/directed-graph.d.ts +0 -51
  179. package/dist/types/data-structures/graph/index.d.ts +0 -3
  180. package/dist/types/data-structures/graph/undirected-graph.d.ts +0 -24
  181. package/dist/types/data-structures/hash/coordinate-map.d.ts +0 -8
  182. package/dist/types/data-structures/hash/coordinate-set.d.ts +0 -7
  183. package/dist/types/data-structures/hash/index.d.ts +0 -1
  184. package/dist/types/data-structures/heap/heap.d.ts +0 -72
  185. package/dist/types/data-structures/heap/index.d.ts +0 -3
  186. package/dist/types/data-structures/heap/max-heap.d.ts +0 -14
  187. package/dist/types/data-structures/heap/min-heap.d.ts +0 -14
  188. package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +0 -59
  189. package/dist/types/data-structures/linked-list/index.d.ts +0 -2
  190. package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +0 -358
  191. package/dist/types/data-structures/matrix/index.d.ts +0 -3
  192. package/dist/types/data-structures/matrix/matrix.d.ts +0 -9
  193. package/dist/types/data-structures/matrix/matrix2d.d.ts +0 -25
  194. package/dist/types/data-structures/matrix/navigator.d.ts +0 -31
  195. package/dist/types/data-structures/matrix/vector2d.d.ts +0 -74
  196. package/dist/types/data-structures/priority-queue/index.d.ts +0 -3
  197. package/dist/types/data-structures/priority-queue/max-priority-queue.d.ts +0 -4
  198. package/dist/types/data-structures/priority-queue/min-priority-queue.d.ts +0 -4
  199. package/dist/types/data-structures/priority-queue/priority-queue.d.ts +0 -36
  200. package/dist/types/data-structures/queue/deque.d.ts +0 -37
  201. package/dist/types/data-structures/queue/index.d.ts +0 -1
  202. package/dist/types/data-structures/queue/queue.d.ts +0 -76
  203. package/dist/types/data-structures/stack/index.d.ts +0 -1
  204. package/dist/types/data-structures/stack/stack.d.ts +0 -69
  205. package/dist/types/data-structures/trampoline.d.ts +0 -25
  206. package/dist/types/data-structures/trie/index.d.ts +0 -1
  207. package/dist/types/data-structures/trie/trie.d.ts +0 -28
  208. package/dist/types/types/utils.d.ts +0 -46
  209. package/dist/types/utils.d.ts +0 -46
  210. package/dist/utils.d.ts +0 -122
  211. package/dist/utils.js +0 -569
  212. package/src/data-structures/binary-tree/aa-tree.ts +0 -3
  213. package/src/data-structures/binary-tree/avl-tree.ts +0 -232
  214. package/src/data-structures/binary-tree/b-tree.ts +0 -3
  215. package/src/data-structures/binary-tree/binary-indexed-tree.ts +0 -33
  216. package/src/data-structures/binary-tree/binary-tree.ts +0 -1088
  217. package/src/data-structures/binary-tree/bst.ts +0 -404
  218. package/src/data-structures/binary-tree/index.ts +0 -11
  219. package/src/data-structures/binary-tree/rb-tree.ts +0 -3
  220. package/src/data-structures/binary-tree/segment-tree.ts +0 -164
  221. package/src/data-structures/binary-tree/splay-tree.ts +0 -3
  222. package/src/data-structures/binary-tree/tree-multiset.ts +0 -21
  223. package/src/data-structures/binary-tree/two-three-tree.ts +0 -3
  224. package/src/data-structures/graph/abstract-graph.ts +0 -789
  225. package/src/data-structures/graph/directed-graph.ts +0 -322
  226. package/src/data-structures/graph/index.ts +0 -3
  227. package/src/data-structures/graph/undirected-graph.ts +0 -154
  228. package/src/data-structures/hash/coordinate-map.ts +0 -24
  229. package/src/data-structures/hash/coordinate-set.ts +0 -20
  230. package/src/data-structures/hash/hash-table.ts +0 -1
  231. package/src/data-structures/hash/index.ts +0 -1
  232. package/src/data-structures/heap/heap.ts +0 -136
  233. package/src/data-structures/heap/index.ts +0 -3
  234. package/src/data-structures/heap/max-heap.ts +0 -22
  235. package/src/data-structures/heap/min-heap.ts +0 -24
  236. package/src/data-structures/index.ts +0 -11
  237. package/src/data-structures/linked-list/doubly-linked-list.ts +0 -258
  238. package/src/data-structures/linked-list/index.ts +0 -2
  239. package/src/data-structures/linked-list/singly-linked-list.ts +0 -750
  240. package/src/data-structures/linked-list/skip-linked-list.ts +0 -1
  241. package/src/data-structures/matrix/index.ts +0 -4
  242. package/src/data-structures/matrix/matrix.ts +0 -13
  243. package/src/data-structures/matrix/matrix2d.ts +0 -125
  244. package/src/data-structures/matrix/navigator.ts +0 -99
  245. package/src/data-structures/matrix/vector2d.ts +0 -189
  246. package/src/data-structures/priority-queue/index.ts +0 -3
  247. package/src/data-structures/priority-queue/max-priority-queue.ts +0 -12
  248. package/src/data-structures/priority-queue/min-priority-queue.ts +0 -12
  249. package/src/data-structures/priority-queue/priority-queue.ts +0 -208
  250. package/src/data-structures/queue/deque.ts +0 -139
  251. package/src/data-structures/queue/index.ts +0 -2
  252. package/src/data-structures/queue/queue.ts +0 -123
  253. package/src/data-structures/stack/index.ts +0 -1
  254. package/src/data-structures/stack/stack.ts +0 -104
  255. package/src/data-structures/trampoline.ts +0 -91
  256. package/src/data-structures/trie/index.ts +0 -1
  257. package/src/data-structures/trie/trie.ts +0 -153
  258. package/src/index.ts +0 -1
  259. package/src/types/index.ts +0 -1
  260. package/src/types/patches/index.d.ts +0 -0
  261. package/src/types/utils.ts +0 -158
  262. package/src/utils.ts +0 -605
  263. package/tsconfig.json +0 -53
  264. /package/dist/{types/data-structures/hash/hash-table.d.ts → interfaces/doubly-linked-list.d.ts} +0 -0
  265. /package/dist/{types/data-structures/hash/pair.d.ts → interfaces/heap.d.ts} +0 -0
  266. /package/dist/{types/data-structures/hash/tree-map.d.ts → interfaces/navigator.d.ts} +0 -0
  267. /package/dist/{types/data-structures/hash/tree-set.d.ts → interfaces/priority-queue.d.ts} +0 -0
  268. /package/dist/{types/data-structures/linked-list/skip-linked-list.d.ts → interfaces/segment-tree.d.ts} +0 -0
  269. /package/{src/data-structures/hash/pair.ts → dist/interfaces/singly-linked-list.d.ts} +0 -0
  270. /package/{src/data-structures/hash/tree-map.ts → dist/types/data-structures/doubly-linked-list.d.ts} +0 -0
  271. /package/{src/data-structures/hash/tree-set.ts → dist/types/data-structures/singly-linked-list.d.ts} +0 -0
  272. /package/dist/{types/types → utils}/index.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,12 +1,26 @@
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
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
+ */
6
18
  constructor(options) {
7
19
  const { row, col, initialVal } = options;
8
20
  this._matrix = new Array(row).fill(undefined).map(() => new Array(col).fill(initialVal || 0));
9
21
  }
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. */
10
24
  toArray() {
11
25
  return this._matrix;
12
26
  }
@@ -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);
5
18
  /**
6
- * Return the matrix values
19
+ * The function returns a 2D array with three empty arrays.
20
+ * @returns An empty 2-dimensional array with 3 empty arrays inside.
7
21
  */
8
- get m(): number[][];
9
22
  static get empty(): number[][];
10
- get toVector(): Vector2D;
11
23
  /**
12
- * 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.
13
26
  */
14
27
  static get identity(): number[][];
28
+ /**
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.
32
+ */
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
+ */
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,8 +4,21 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.Matrix2D = void 0;
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
+ */
7
14
  const vector2d_1 = __importDefault(require("./vector2d"));
8
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
+ */
9
22
  constructor(value) {
10
23
  if (typeof value === 'undefined') {
11
24
  this._matrix = Matrix2D.identity;
@@ -21,19 +34,15 @@ class Matrix2D {
21
34
  }
22
35
  }
23
36
  /**
24
- * Return the matrix values
37
+ * The function returns a 2D array with three empty arrays.
38
+ * @returns An empty 2-dimensional array with 3 empty arrays inside.
25
39
  */
26
- get m() {
27
- return this._matrix;
28
- }
29
40
  static get empty() {
30
41
  return [[], [], []];
31
42
  }
32
- get toVector() {
33
- return new vector2d_1.default(this._matrix[0][0], this._matrix[1][0]);
34
- }
35
43
  /**
36
- * Initialize an identity matrix
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.
37
46
  */
38
47
  static get identity() {
39
48
  return [
@@ -42,6 +51,29 @@ class Matrix2D {
42
51
  [0, 0, 1]
43
52
  ];
44
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
+ */
45
77
  static add(matrix1, matrix2) {
46
78
  const result = Matrix2D.empty;
47
79
  for (let i = 0; i < 3; i++) {
@@ -51,6 +83,13 @@ class Matrix2D {
51
83
  }
52
84
  return new Matrix2D(result);
53
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
+ */
54
93
  static subtract(matrix1, matrix2) {
55
94
  const result = Matrix2D.empty;
56
95
  for (let i = 0; i < 3; i++) {
@@ -60,6 +99,12 @@ class Matrix2D {
60
99
  }
61
100
  return new Matrix2D(result);
62
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
+ */
63
108
  static multiply(matrix1, matrix2) {
64
109
  const result = Matrix2D.empty;
65
110
  for (let i = 0; i < 3; i++) {
@@ -72,6 +117,13 @@ class Matrix2D {
72
117
  }
73
118
  return new Matrix2D(result);
74
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
+ */
75
127
  static multiplyByValue(matrix, value) {
76
128
  const result = Matrix2D.empty;
77
129
  for (let i = 0; i < 3; i++) {
@@ -81,9 +133,23 @@ class Matrix2D {
81
133
  }
82
134
  return new Matrix2D(result);
83
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
+ */
84
142
  static multiplyByVector(matrix, vector) {
85
143
  return Matrix2D.multiply(matrix, new Matrix2D(vector)).toVector;
86
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
+ */
87
153
  static view(width, height) {
88
154
  const scaleStep = 1; // Scale every vector * scaleStep
89
155
  const centerX = width / 2;
@@ -95,9 +161,20 @@ class Matrix2D {
95
161
  [0, 0, 1]
96
162
  ]);
97
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
+ */
98
170
  static scale(factor) {
99
171
  return Matrix2D.multiplyByValue(new Matrix2D(), factor);
100
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
+ */
101
178
  static rotate(radians) {
102
179
  const cos = Math.cos(radians);
103
180
  const sin = Math.sin(radians);
@@ -107,6 +184,12 @@ class Matrix2D {
107
184
  [0, 0, 1]
108
185
  ]);
109
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
+ */
110
193
  static translate(vector) {
111
194
  return new Matrix2D([
112
195
  [1, 0, vector.x],
@@ -1,31 +1,52 @@
1
- type Direction = 'up' | 'right' | 'down' | 'left';
2
- type Turning = {
3
- [key in Direction]: Direction;
4
- };
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';
5
9
  export declare class Character {
6
10
  direction: Direction;
7
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
+ */
8
20
  constructor(direction: Direction, turning: Turning);
9
21
  }
10
- interface NavigatorParams<T> {
11
- matrix: T[][];
12
- turning: Turning;
13
- onMove: (cur: [number, number]) => void;
14
- init: {
15
- cur: [number, number];
16
- charDir: Direction;
17
- VISITED: T;
18
- };
19
- }
20
22
  export declare class Navigator<T = number> {
23
+ onMove: (cur: [number, number]) => void;
21
24
  private readonly _matrix;
22
25
  private readonly _cur;
23
26
  private _character;
24
27
  private readonly _VISITED;
25
- onMove: (cur: [number, number]) => void;
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
+ */
26
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
+ */
27
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
+ */
28
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
+ */
29
51
  move(direction: Direction): void;
30
52
  }
31
- export {};
@@ -2,6 +2,14 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Navigator = exports.Character = void 0;
4
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
+ */
5
13
  constructor(direction, turning) {
6
14
  this.direction = direction;
7
15
  this.turn = () => new Character(turning[direction], turning);
@@ -9,6 +17,11 @@ class Character {
9
17
  }
10
18
  exports.Character = Character;
11
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
+ */
12
25
  constructor({ matrix, turning, onMove, init: { cur, charDir, VISITED } }) {
13
26
  this._matrix = matrix;
14
27
  this._cur = cur;
@@ -18,6 +31,10 @@ class Navigator {
18
31
  this._VISITED = VISITED;
19
32
  this._matrix[this._cur[0]][this._cur[1]] = this._VISITED;
20
33
  }
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
+ */
21
38
  start() {
22
39
  while (this.check(this._character.direction) || this.check(this._character.turn().direction)) {
23
40
  const { direction } = this._character;
@@ -29,6 +46,12 @@ class Navigator {
29
46
  }
30
47
  }
31
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
+ */
32
55
  check(direction) {
33
56
  let forward, row;
34
57
  const matrix = this._matrix;
@@ -55,6 +78,11 @@ class Navigator {
55
78
  }
56
79
  return forward !== undefined && forward !== this._VISITED;
57
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
+ */
58
86
  move(direction) {
59
87
  switch (direction) {
60
88
  case 'up':