data-structure-typed 0.8.18 → 1.12.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (287) hide show
  1. package/.dependency-cruiser.js +449 -0
  2. package/.idea/data-structure-typed.iml +2 -0
  3. package/.idea/modules.xml +1 -1
  4. package/README.md +298 -2
  5. package/dist/data-structures/binary-tree/aa-tree.js +5 -2
  6. package/dist/data-structures/binary-tree/avl-tree.d.ts +58 -5
  7. package/dist/data-structures/binary-tree/avl-tree.js +150 -46
  8. package/dist/data-structures/binary-tree/b-tree.js +5 -2
  9. package/dist/data-structures/binary-tree/binary-indexed-tree.d.ts +28 -1
  10. package/dist/data-structures/binary-tree/binary-indexed-tree.js +41 -13
  11. package/dist/data-structures/binary-tree/binary-tree.d.ts +230 -36
  12. package/dist/data-structures/binary-tree/binary-tree.js +747 -369
  13. package/dist/data-structures/binary-tree/bst.d.ts +20 -8
  14. package/dist/data-structures/binary-tree/bst.js +164 -107
  15. package/dist/data-structures/binary-tree/rb-tree.js +5 -2
  16. package/dist/data-structures/binary-tree/segment-tree.d.ts +7 -3
  17. package/dist/data-structures/binary-tree/segment-tree.js +95 -61
  18. package/dist/data-structures/binary-tree/splay-tree.js +5 -2
  19. package/dist/data-structures/binary-tree/tree-multiset.d.ts +5 -5
  20. package/dist/data-structures/binary-tree/tree-multiset.js +35 -11
  21. package/dist/data-structures/binary-tree/two-three-tree.js +5 -2
  22. package/dist/data-structures/graph/abstract-graph.d.ts +168 -46
  23. package/dist/data-structures/graph/abstract-graph.js +712 -323
  24. package/dist/data-structures/graph/directed-graph.d.ts +114 -12
  25. package/dist/data-structures/graph/directed-graph.js +372 -128
  26. package/dist/data-structures/graph/undirected-graph.d.ts +67 -3
  27. package/dist/data-structures/graph/undirected-graph.js +233 -81
  28. package/dist/data-structures/hash/coordinate-map.d.ts +33 -1
  29. package/dist/data-structures/hash/coordinate-map.js +70 -20
  30. package/dist/data-structures/hash/coordinate-set.d.ts +25 -0
  31. package/dist/data-structures/hash/coordinate-set.js +58 -15
  32. package/dist/data-structures/hash/index.d.ts +5 -0
  33. package/dist/data-structures/hash/index.js +5 -0
  34. package/dist/data-structures/heap/heap.d.ts +26 -37
  35. package/dist/data-structures/heap/heap.js +56 -60
  36. package/dist/data-structures/heap/max-heap.d.ts +8 -2
  37. package/dist/data-structures/heap/max-heap.js +32 -9
  38. package/dist/data-structures/heap/min-heap.d.ts +9 -2
  39. package/dist/data-structures/heap/min-heap.js +33 -9
  40. package/dist/data-structures/linked-list/doubly-linked-list.d.ts +14 -7
  41. package/dist/data-structures/linked-list/doubly-linked-list.js +101 -61
  42. package/dist/data-structures/linked-list/singly-linked-list.d.ts +18 -19
  43. package/dist/data-structures/linked-list/singly-linked-list.js +312 -174
  44. package/dist/data-structures/matrix/matrix.d.ts +9 -0
  45. package/dist/data-structures/matrix/matrix.js +19 -7
  46. package/dist/data-structures/matrix/matrix2d.d.ts +84 -4
  47. package/dist/data-structures/matrix/matrix2d.js +158 -61
  48. package/dist/data-structures/matrix/navigator.d.ts +34 -16
  49. package/dist/data-structures/matrix/navigator.js +65 -18
  50. package/dist/data-structures/matrix/vector2d.d.ts +153 -29
  51. package/dist/data-structures/matrix/vector2d.js +249 -102
  52. package/dist/data-structures/priority-queue/max-priority-queue.d.ts +11 -2
  53. package/dist/data-structures/priority-queue/max-priority-queue.js +33 -8
  54. package/dist/data-structures/priority-queue/min-priority-queue.d.ts +11 -2
  55. package/dist/data-structures/priority-queue/min-priority-queue.js +33 -8
  56. package/dist/data-structures/priority-queue/priority-queue.d.ts +145 -21
  57. package/dist/data-structures/priority-queue/priority-queue.js +285 -116
  58. package/dist/data-structures/queue/deque.d.ts +69 -0
  59. package/dist/data-structures/queue/deque.js +151 -56
  60. package/dist/data-structures/queue/queue.d.ts +34 -37
  61. package/dist/data-structures/queue/queue.js +59 -61
  62. package/dist/data-structures/stack/stack.d.ts +29 -35
  63. package/dist/data-structures/stack/stack.js +51 -56
  64. package/dist/data-structures/trie/trie.d.ts +36 -6
  65. package/dist/data-structures/trie/trie.js +256 -83
  66. package/dist/data-structures/types/abstract-graph.d.ts +29 -0
  67. package/dist/data-structures/types/abstract-graph.js +2 -0
  68. package/dist/data-structures/types/avl-tree.d.ts +5 -0
  69. package/dist/data-structures/types/avl-tree.js +2 -0
  70. package/dist/data-structures/types/binary-tree.d.ts +16 -0
  71. package/dist/data-structures/types/binary-tree.js +2 -0
  72. package/dist/data-structures/types/bst.d.ts +7 -0
  73. package/dist/data-structures/types/bst.js +2 -0
  74. package/dist/data-structures/types/directed-graph.d.ts +10 -0
  75. package/dist/data-structures/types/directed-graph.js +2 -0
  76. package/dist/data-structures/types/doubly-linked-list.d.ts +1 -0
  77. package/dist/data-structures/types/doubly-linked-list.js +2 -0
  78. package/dist/data-structures/types/heap.d.ts +7 -0
  79. package/dist/data-structures/types/heap.js +2 -0
  80. package/dist/data-structures/types/index.d.ts +13 -0
  81. package/dist/data-structures/types/index.js +29 -0
  82. package/dist/data-structures/types/navigator.d.ts +14 -0
  83. package/dist/data-structures/types/navigator.js +2 -0
  84. package/dist/data-structures/types/priority-queue.d.ts +7 -0
  85. package/dist/data-structures/types/priority-queue.js +2 -0
  86. package/dist/data-structures/types/segment-tree.d.ts +1 -0
  87. package/dist/data-structures/types/segment-tree.js +2 -0
  88. package/dist/data-structures/types/singly-linked-list.js +2 -0
  89. package/dist/data-structures/types/tree-multiset.d.ts +5 -0
  90. package/dist/data-structures/types/tree-multiset.js +2 -0
  91. package/dist/utils/trampoline.d.ts +14 -0
  92. package/dist/utils/trampoline.js +130 -0
  93. package/dist/utils/types/index.js +17 -0
  94. package/dist/{types → utils}/types/utils.d.ts +15 -1
  95. package/dist/{types → utils/types}/utils.js +21 -19
  96. package/dist/{utils.d.ts → utils/utils.d.ts} +5 -22
  97. package/dist/utils/utils.js +651 -0
  98. package/docs/.nojekyll +1 -0
  99. package/docs/assets/highlight.css +85 -0
  100. package/docs/assets/main.js +58 -0
  101. package/docs/assets/search.js +1 -0
  102. package/docs/assets/style.css +1367 -0
  103. package/docs/classes/AVLTree.html +2046 -0
  104. package/docs/classes/AVLTreeNode.html +423 -0
  105. package/docs/classes/AaTree.html +117 -0
  106. package/docs/classes/AbstractEdge.html +198 -0
  107. package/docs/classes/AbstractGraph.html +891 -0
  108. package/docs/classes/AbstractVertex.html +164 -0
  109. package/docs/classes/ArrayDeque.html +384 -0
  110. package/docs/classes/BST.html +1893 -0
  111. package/docs/classes/BSTNode.html +425 -0
  112. package/docs/classes/BTree.html +117 -0
  113. package/docs/classes/BinaryIndexedTree.html +244 -0
  114. package/docs/classes/BinaryTree.html +1754 -0
  115. package/docs/classes/BinaryTreeNode.html +396 -0
  116. package/docs/classes/Character.html +165 -0
  117. package/docs/classes/CoordinateMap.html +394 -0
  118. package/docs/classes/CoordinateSet.html +355 -0
  119. package/docs/classes/Deque.html +617 -0
  120. package/docs/classes/DirectedEdge.html +247 -0
  121. package/docs/classes/DirectedGraph.html +1207 -0
  122. package/docs/classes/DirectedVertex.html +154 -0
  123. package/docs/classes/DoublyLinkedList.html +619 -0
  124. package/docs/classes/DoublyLinkedListNode.html +160 -0
  125. package/docs/classes/Heap.html +315 -0
  126. package/docs/classes/Matrix2D.html +447 -0
  127. package/docs/classes/MatrixNTI2D.html +181 -0
  128. package/docs/classes/MaxHeap.html +325 -0
  129. package/docs/classes/MaxPriorityQueue.html +668 -0
  130. package/docs/classes/MinHeap.html +326 -0
  131. package/docs/classes/MinPriorityQueue.html +668 -0
  132. package/docs/classes/Navigator.html +285 -0
  133. package/docs/classes/ObjectDeque.html +289 -0
  134. package/docs/classes/PriorityQueue.html +643 -0
  135. package/docs/classes/Queue.html +337 -0
  136. package/docs/classes/RBTree.html +117 -0
  137. package/docs/classes/SegmentTree.html +234 -0
  138. package/docs/classes/SegmentTreeNode.html +302 -0
  139. package/docs/classes/SinglyLinkedList.html +1035 -0
  140. package/docs/classes/SinglyLinkedListNode.html +304 -0
  141. package/docs/classes/SplayTree.html +117 -0
  142. package/docs/classes/Stack.html +313 -0
  143. package/docs/classes/TreeMultiSet.html +1897 -0
  144. package/docs/classes/Trie.html +317 -0
  145. package/docs/classes/TrieNode.html +221 -0
  146. package/docs/classes/TwoThreeTree.html +117 -0
  147. package/docs/classes/UndirectedEdge.html +220 -0
  148. package/docs/classes/UndirectedGraph.html +1006 -0
  149. package/docs/classes/UndirectedVertex.html +154 -0
  150. package/docs/classes/Vector2D.html +746 -0
  151. package/docs/enums/CP.html +126 -0
  152. package/docs/enums/FamilyPosition.html +126 -0
  153. package/docs/enums/LoopType.html +119 -0
  154. package/docs/index.html +288 -0
  155. package/docs/modules.html +146 -0
  156. package/jest.config.js +5 -0
  157. package/package.json +33 -47
  158. package/rename_clear_files.sh +29 -0
  159. package/src/assets/complexities-diff.jpg +0 -0
  160. package/src/assets/data-structure-complexities.jpg +0 -0
  161. package/src/data-structures/binary-tree/avl-tree.ts +58 -6
  162. package/src/data-structures/binary-tree/binary-indexed-tree.ts +31 -4
  163. package/src/data-structures/binary-tree/binary-tree.ts +460 -145
  164. package/src/data-structures/binary-tree/bst.ts +31 -25
  165. package/src/data-structures/binary-tree/diagrams/avl-tree-inserting.gif +0 -0
  166. package/src/data-structures/binary-tree/diagrams/bst-rotation.gif +0 -0
  167. package/src/data-structures/binary-tree/diagrams/segment-tree.png +0 -0
  168. package/src/data-structures/binary-tree/segment-tree.ts +25 -12
  169. package/src/data-structures/binary-tree/tree-multiset.ts +5 -4
  170. package/src/data-structures/diagrams/README.md +5 -0
  171. package/src/data-structures/graph/abstract-graph.ts +224 -108
  172. package/src/data-structures/graph/diagrams/adjacency-list-pros-cons.jpg +0 -0
  173. package/src/data-structures/graph/diagrams/adjacency-list.jpg +0 -0
  174. package/src/data-structures/graph/diagrams/adjacency-matrix-pros-cons.jpg +0 -0
  175. package/src/data-structures/graph/diagrams/adjacency-matrix.jpg +0 -0
  176. package/src/data-structures/graph/diagrams/dfs-can-do.jpg +0 -0
  177. package/src/data-structures/graph/diagrams/edge-list-pros-cons.jpg +0 -0
  178. package/src/data-structures/graph/diagrams/edge-list.jpg +0 -0
  179. package/src/data-structures/graph/diagrams/max-flow.jpg +0 -0
  180. package/src/data-structures/graph/diagrams/mst.jpg +0 -0
  181. package/src/data-structures/graph/diagrams/tarjan-articulation-point-bridge.png +0 -0
  182. package/src/data-structures/graph/diagrams/tarjan-complicate-simple.png +0 -0
  183. package/src/data-structures/graph/diagrams/tarjan-strongly-connected-component.png +0 -0
  184. package/src/data-structures/graph/diagrams/tarjan.mp4 +0 -0
  185. package/src/data-structures/graph/diagrams/tarjan.webp +0 -0
  186. package/src/data-structures/graph/directed-graph.ts +132 -26
  187. package/src/data-structures/graph/undirected-graph.ts +78 -11
  188. package/src/data-structures/hash/coordinate-map.ts +33 -1
  189. package/src/data-structures/hash/coordinate-set.ts +25 -0
  190. package/src/data-structures/hash/index.ts +5 -0
  191. package/src/data-structures/heap/heap.ts +27 -41
  192. package/src/data-structures/heap/max-heap.ts +8 -2
  193. package/src/data-structures/heap/min-heap.ts +9 -2
  194. package/src/data-structures/linked-list/doubly-linked-list.ts +50 -17
  195. package/src/data-structures/linked-list/singly-linked-list.ts +56 -39
  196. package/src/data-structures/matrix/matrix.ts +11 -0
  197. package/src/data-structures/matrix/matrix2d.ts +90 -10
  198. package/src/data-structures/matrix/navigator.ts +34 -14
  199. package/src/data-structures/matrix/vector2d.ts +187 -63
  200. package/src/data-structures/priority-queue/max-priority-queue.ts +12 -3
  201. package/src/data-structures/priority-queue/min-priority-queue.ts +12 -3
  202. package/src/data-structures/priority-queue/priority-queue.ts +200 -78
  203. package/src/data-structures/queue/deque.ts +71 -2
  204. package/src/data-structures/queue/queue.ts +37 -40
  205. package/src/data-structures/stack/stack.ts +32 -38
  206. package/src/data-structures/trie/trie.ts +83 -14
  207. package/src/data-structures/types/abstract-graph.ts +51 -0
  208. package/src/data-structures/types/avl-tree.ts +6 -0
  209. package/src/data-structures/types/binary-tree.ts +15 -0
  210. package/src/data-structures/types/bst.ts +5 -0
  211. package/src/data-structures/types/directed-graph.ts +18 -0
  212. package/src/data-structures/types/doubly-linked-list.ts +1 -0
  213. package/src/data-structures/types/heap.ts +8 -0
  214. package/src/data-structures/types/index.ts +13 -0
  215. package/src/data-structures/types/navigator.ts +13 -0
  216. package/src/data-structures/types/priority-queue.ts +9 -0
  217. package/src/data-structures/types/segment-tree.ts +1 -0
  218. package/src/data-structures/types/singly-linked-list.ts +1 -0
  219. package/src/data-structures/types/tree-multiset.ts +3 -0
  220. package/src/utils/index.ts +1 -0
  221. package/src/utils/trampoline.ts +51 -0
  222. package/src/utils/types/index.ts +1 -0
  223. package/src/{types → utils/types}/utils.ts +27 -5
  224. package/src/{utils.ts → utils/utils.ts} +41 -131
  225. package/tests/unit/data-structures/binary-tree/bst.test.ts +185 -0
  226. package/tests/unit/data-structures/graph/directed-graph.test.ts +71 -0
  227. package/{dist/types/data-structures/graph/index.d.ts → tests/unit/data-structures/graph/index.ts} +1 -1
  228. package/tests/unit/data-structures/graph/undirected-graph.ts +0 -0
  229. package/tsconfig.json +9 -6
  230. package/dist/data-structures/trampoline.d.ts +0 -25
  231. package/dist/data-structures/trampoline.js +0 -52
  232. package/dist/types/data-structures/binary-tree/aa-tree.d.ts +0 -2
  233. package/dist/types/data-structures/binary-tree/avl-tree.d.ts +0 -21
  234. package/dist/types/data-structures/binary-tree/b-tree.d.ts +0 -2
  235. package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +0 -8
  236. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +0 -140
  237. package/dist/types/data-structures/binary-tree/bst.d.ts +0 -32
  238. package/dist/types/data-structures/binary-tree/index.d.ts +0 -4
  239. package/dist/types/data-structures/binary-tree/rb-tree.d.ts +0 -2
  240. package/dist/types/data-structures/binary-tree/segment-tree.d.ts +0 -33
  241. package/dist/types/data-structures/binary-tree/splay-tree.d.ts +0 -2
  242. package/dist/types/data-structures/binary-tree/tree-multiset.d.ts +0 -11
  243. package/dist/types/data-structures/binary-tree/two-three-tree.d.ts +0 -2
  244. package/dist/types/data-structures/graph/abstract-graph.d.ts +0 -126
  245. package/dist/types/data-structures/graph/directed-graph.d.ts +0 -51
  246. package/dist/types/data-structures/graph/undirected-graph.d.ts +0 -24
  247. package/dist/types/data-structures/hash/coordinate-map.d.ts +0 -8
  248. package/dist/types/data-structures/hash/coordinate-set.d.ts +0 -7
  249. package/dist/types/data-structures/hash/index.d.ts +0 -1
  250. package/dist/types/data-structures/hash/pair.d.ts +0 -1
  251. package/dist/types/data-structures/hash/tree-map.d.ts +0 -1
  252. package/dist/types/data-structures/hash/tree-set.d.ts +0 -1
  253. package/dist/types/data-structures/heap/heap.d.ts +0 -72
  254. package/dist/types/data-structures/heap/index.d.ts +0 -3
  255. package/dist/types/data-structures/heap/max-heap.d.ts +0 -14
  256. package/dist/types/data-structures/heap/min-heap.d.ts +0 -14
  257. package/dist/types/data-structures/index.d.ts +0 -9
  258. package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +0 -59
  259. package/dist/types/data-structures/linked-list/index.d.ts +0 -2
  260. package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +0 -358
  261. package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +0 -1
  262. package/dist/types/data-structures/matrix/index.d.ts +0 -3
  263. package/dist/types/data-structures/matrix/matrix.d.ts +0 -9
  264. package/dist/types/data-structures/matrix/matrix2d.d.ts +0 -25
  265. package/dist/types/data-structures/matrix/navigator.d.ts +0 -31
  266. package/dist/types/data-structures/matrix/vector2d.d.ts +0 -74
  267. package/dist/types/data-structures/priority-queue/index.d.ts +0 -3
  268. package/dist/types/data-structures/priority-queue/max-priority-queue.d.ts +0 -4
  269. package/dist/types/data-structures/priority-queue/min-priority-queue.d.ts +0 -4
  270. package/dist/types/data-structures/priority-queue/priority-queue.d.ts +0 -36
  271. package/dist/types/data-structures/queue/deque.d.ts +0 -37
  272. package/dist/types/data-structures/queue/index.d.ts +0 -1
  273. package/dist/types/data-structures/queue/queue.d.ts +0 -76
  274. package/dist/types/data-structures/stack/index.d.ts +0 -1
  275. package/dist/types/data-structures/stack/stack.d.ts +0 -69
  276. package/dist/types/data-structures/trampoline.d.ts +0 -25
  277. package/dist/types/data-structures/trie/index.d.ts +0 -1
  278. package/dist/types/data-structures/trie/trie.d.ts +0 -28
  279. package/dist/types/utils.d.ts +0 -46
  280. package/dist/utils.js +0 -569
  281. package/src/data-structures/trampoline.ts +0 -91
  282. package/src/types/index.ts +0 -1
  283. /package/dist/{types/data-structures/hash/hash-table.d.ts → data-structures/types/singly-linked-list.d.ts} +0 -0
  284. /package/dist/{types → utils}/index.d.ts +0 -0
  285. /package/dist/{types → utils}/index.js +0 -0
  286. /package/dist/{types → utils}/types/index.d.ts +0 -0
  287. /package/{src/types/patches/index.d.ts → tests/unit/data-structures/graph/abstract-graph.ts} +0 -0
@@ -1,5 +1,14 @@
1
+ /**
2
+ * @copyright 2030 Tyler Zeng <zrwusa@gmail.com>
3
+ * @license MIT
4
+ */
1
5
  export declare class MatrixNTI2D<T = number> {
2
6
  private readonly _matrix;
7
+ /**
8
+ * The constructor creates a matrix with the specified number of rows and columns, and initializes all elements to a
9
+ * given initial value or 0 if not provided.
10
+ * @param options - An object containing the following properties:
11
+ */
3
12
  constructor(options: {
4
13
  row: number;
5
14
  col: number;
@@ -1,14 +1,26 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.MatrixNTI2D = void 0;
4
+ /**
5
+ * @copyright 2030 Tyler Zeng <zrwusa@gmail.com>
6
+ * @license MIT
7
+ */
4
8
  // todo need to be improved
5
- class MatrixNTI2D {
6
- constructor(options) {
7
- const { row, col, initialVal } = options;
8
- this._matrix = new Array(row).fill(undefined).map(() => new Array(col).fill(initialVal || 0));
9
+ var MatrixNTI2D = /** @class */ (function () {
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
+ */
15
+ function MatrixNTI2D(options) {
16
+ var row = options.row, col = options.col, initialVal = options.initialVal;
17
+ this._matrix = new Array(row).fill(undefined).map(function () { return new Array(col).fill(initialVal || 0); });
9
18
  }
10
- toArray() {
19
+ /* The `toArray` method returns the matrix as a two-dimensional array. It converts the internal representation of the
20
+ matrix, which is an array of arrays, into a format that is more commonly used in JavaScript. */
21
+ MatrixNTI2D.prototype.toArray = function () {
11
22
  return this._matrix;
12
- }
13
- }
23
+ };
24
+ return MatrixNTI2D;
25
+ }());
14
26
  exports.MatrixNTI2D = MatrixNTI2D;
@@ -1,25 +1,105 @@
1
+ /**
2
+ * @copyright 2030 Tyler Zeng <zrwusa@gmail.com>
3
+ * @license MIT
4
+ */
1
5
  import Vector2D from './vector2d';
2
6
  export declare class Matrix2D {
3
7
  private readonly _matrix;
8
+ /**
9
+ * The constructor function initializes a Matrix2D object with either a default identity matrix, or a provided matrix
10
+ * or Vector2D object.
11
+ * @param {number[][] | Vector2D} [value] - The `value` parameter can be either a 2D array of numbers (`number[][]`) or
12
+ * an instance of the `Vector2D` class.
13
+ */
4
14
  constructor(value?: number[][] | Vector2D);
5
15
  /**
6
- * Return the matrix values
16
+ * The function returns a 2D array with three empty arrays.
17
+ * @returns An empty 2-dimensional array with 3 empty arrays inside.
7
18
  */
8
- get m(): number[][];
9
19
  static get empty(): number[][];
10
- get toVector(): Vector2D;
11
20
  /**
12
- * Initialize an identity matrix
21
+ * The above function returns a 3x3 identity matrix.
22
+ * @returns The method is returning a 2-dimensional array of numbers representing the identity matrix.
13
23
  */
14
24
  static get identity(): number[][];
25
+ /**
26
+ * The function returns a two-dimensional array of numbers.
27
+ * @returns The getter method is returning the value of the private variable `_matrix`, which is a two-dimensional
28
+ * array of numbers.
29
+ */
30
+ get m(): number[][];
31
+ /**
32
+ * The function "toVector" returns a new Vector2D object with the values from the first and second elements of the
33
+ * _matrix array.
34
+ * @returns A new instance of the Vector2D class is being returned. The values of the returned vector are taken from
35
+ * the first column of the matrix.
36
+ */
37
+ get toVector(): Vector2D;
38
+ /**
39
+ * The function takes two 2D matrices as input and returns their sum as a new 2D matrix.
40
+ * @param {Matrix2D} matrix1 - Matrix2D - The first matrix to be added.
41
+ * @param {Matrix2D} matrix2 - The parameter `matrix2` is a Matrix2D object.
42
+ * @returns a new instance of the Matrix2D class, which is created using the result array.
43
+ */
15
44
  static add(matrix1: Matrix2D, matrix2: Matrix2D): Matrix2D;
45
+ /**
46
+ * The function subtracts two 2D matrices and returns the result as a new Matrix2D object.
47
+ * @param {Matrix2D} matrix1 - Matrix2D - The first matrix to subtract from.
48
+ * @param {Matrix2D} matrix2 - Matrix2D is a class representing a 2D matrix. It has a property `m` which is a 2D array
49
+ * representing the matrix elements.
50
+ * @returns a new instance of the Matrix2D class, which is created using the result array.
51
+ */
16
52
  static subtract(matrix1: Matrix2D, matrix2: Matrix2D): Matrix2D;
53
+ /**
54
+ * The function multiplies two 2D matrices and returns the result as a new Matrix2D object.
55
+ * @param {Matrix2D} matrix1 - A 2D matrix represented by the Matrix2D class.
56
+ * @param {Matrix2D} matrix2 - The parameter `matrix2` is a 2D matrix of size 3x3.
57
+ * @returns a new instance of the Matrix2D class, created using the result array.
58
+ */
17
59
  static multiply(matrix1: Matrix2D, matrix2: Matrix2D): Matrix2D;
60
+ /**
61
+ * The function multiplies each element of a 2D matrix by a given value and returns the resulting matrix.
62
+ * @param {Matrix2D} matrix - The `matrix` parameter is an instance of the `Matrix2D` class, which represents a 2D
63
+ * matrix. It contains a property `m` that is a 2D array representing the matrix elements.
64
+ * @param {number} value - The `value` parameter is a number that you want to multiply each element of the `matrix` by.
65
+ * @returns a new instance of the Matrix2D class, which is created using the result array.
66
+ */
18
67
  static multiplyByValue(matrix: Matrix2D, value: number): Matrix2D;
68
+ /**
69
+ * The function multiplies a 2D matrix by a 2D vector and returns the result as a 2D vector.
70
+ * @param {Matrix2D} matrix - The parameter "matrix" is of type Matrix2D. It represents a 2-dimensional matrix.
71
+ * @param {Vector2D} vector - The "vector" parameter is a 2D vector, represented by an object of type Vector2D.
72
+ * @returns a Vector2D.
73
+ */
19
74
  static multiplyByVector(matrix: Matrix2D, vector: Vector2D): Vector2D;
75
+ /**
76
+ * The function returns a 2D matrix that scales and flips a vector around the center of a given width and height.
77
+ * @param {number} width - The width parameter represents the width of the view or the canvas. It is a number that
78
+ * specifies the width in pixels or any other unit of measurement.
79
+ * @param {number} height - The height parameter represents the height of the view or the canvas. It is used to
80
+ * calculate the centerY value, which is the vertical center of the view.
81
+ * @returns a Matrix2D object.
82
+ */
20
83
  static view(width: number, height: number): Matrix2D;
84
+ /**
85
+ * The function scales a matrix by a given factor.
86
+ * @param {number} factor - The factor parameter is a number that represents the scaling factor by which the matrix
87
+ * should be scaled.
88
+ * @returns the result of multiplying a new instance of Matrix2D by the given factor.
89
+ */
21
90
  static scale(factor: number): Matrix2D;
91
+ /**
92
+ * The function "rotate" takes an angle in radians and returns a 2D transformation matrix for rotating objects.
93
+ * @param {number} radians - The "radians" parameter is the angle in radians by which you want to rotate an object.
94
+ * @returns The code is returning a new instance of a Matrix2D object.
95
+ */
22
96
  static rotate(radians: number): Matrix2D;
97
+ /**
98
+ * The translate function takes a 2D vector and returns a 2D matrix that represents a translation transformation.
99
+ * @param {Vector2D} vector - The parameter "vector" is of type Vector2D. It represents a 2D vector with components x
100
+ * and y, and an optional w component.
101
+ * @returns The method is returning a new instance of the Matrix2D class.
102
+ */
23
103
  static translate(vector: Vector2D): Matrix2D;
24
104
  }
25
105
  export default Matrix2D;
@@ -4,9 +4,19 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.Matrix2D = void 0;
7
- const vector2d_1 = __importDefault(require("./vector2d"));
8
- class Matrix2D {
9
- constructor(value) {
7
+ /**
8
+ * @copyright 2030 Tyler Zeng <zrwusa@gmail.com>
9
+ * @license MIT
10
+ */
11
+ var vector2d_1 = __importDefault(require("./vector2d"));
12
+ var Matrix2D = /** @class */ (function () {
13
+ /**
14
+ * The constructor function initializes a Matrix2D object with either a default identity matrix, or a provided matrix
15
+ * or Vector2D object.
16
+ * @param {number[][] | Vector2D} [value] - The `value` parameter can be either a 2D array of numbers (`number[][]`) or
17
+ * an instance of the `Vector2D` class.
18
+ */
19
+ function Matrix2D(value) {
10
20
  if (typeof value === 'undefined') {
11
21
  this._matrix = Matrix2D.identity;
12
22
  }
@@ -20,100 +30,187 @@ class Matrix2D {
20
30
  this._matrix = value;
21
31
  }
22
32
  }
33
+ Object.defineProperty(Matrix2D, "empty", {
34
+ /**
35
+ * The function returns a 2D array with three empty arrays.
36
+ * @returns An empty 2-dimensional array with 3 empty arrays inside.
37
+ */
38
+ get: function () {
39
+ return [[], [], []];
40
+ },
41
+ enumerable: false,
42
+ configurable: true
43
+ });
44
+ Object.defineProperty(Matrix2D, "identity", {
45
+ /**
46
+ * The above function returns a 3x3 identity matrix.
47
+ * @returns The method is returning a 2-dimensional array of numbers representing the identity matrix.
48
+ */
49
+ get: function () {
50
+ return [
51
+ [1, 0, 0],
52
+ [0, 1, 0],
53
+ [0, 0, 1]
54
+ ];
55
+ },
56
+ enumerable: false,
57
+ configurable: true
58
+ });
59
+ Object.defineProperty(Matrix2D.prototype, "m", {
60
+ /**
61
+ * The function returns a two-dimensional array of numbers.
62
+ * @returns The getter method is returning the value of the private variable `_matrix`, which is a two-dimensional
63
+ * array of numbers.
64
+ */
65
+ get: function () {
66
+ return this._matrix;
67
+ },
68
+ enumerable: false,
69
+ configurable: true
70
+ });
71
+ Object.defineProperty(Matrix2D.prototype, "toVector", {
72
+ /**
73
+ * The function "toVector" returns a new Vector2D object with the values from the first and second elements of the
74
+ * _matrix array.
75
+ * @returns A new instance of the Vector2D class is being returned. The values of the returned vector are taken from
76
+ * the first column of the matrix.
77
+ */
78
+ get: function () {
79
+ return new vector2d_1.default(this._matrix[0][0], this._matrix[1][0]);
80
+ },
81
+ enumerable: false,
82
+ configurable: true
83
+ });
23
84
  /**
24
- * Return the matrix values
85
+ * The function takes two 2D matrices as input and returns their sum as a new 2D matrix.
86
+ * @param {Matrix2D} matrix1 - Matrix2D - The first matrix to be added.
87
+ * @param {Matrix2D} matrix2 - The parameter `matrix2` is a Matrix2D object.
88
+ * @returns a new instance of the Matrix2D class, which is created using the result array.
25
89
  */
26
- get m() {
27
- return this._matrix;
28
- }
29
- static get empty() {
30
- return [[], [], []];
31
- }
32
- get toVector() {
33
- return new vector2d_1.default(this._matrix[0][0], this._matrix[1][0]);
34
- }
35
- /**
36
- * Initialize an identity matrix
37
- */
38
- static get identity() {
39
- return [
40
- [1, 0, 0],
41
- [0, 1, 0],
42
- [0, 0, 1]
43
- ];
44
- }
45
- static add(matrix1, matrix2) {
46
- const result = Matrix2D.empty;
47
- for (let i = 0; i < 3; i++) {
48
- for (let j = 0; j < 3; j++) {
90
+ Matrix2D.add = function (matrix1, matrix2) {
91
+ var result = Matrix2D.empty;
92
+ for (var i = 0; i < 3; i++) {
93
+ for (var j = 0; j < 3; j++) {
49
94
  result[i][j] = matrix1.m[i][j] + matrix2.m[i][j];
50
95
  }
51
96
  }
52
97
  return new Matrix2D(result);
53
- }
54
- static subtract(matrix1, matrix2) {
55
- const result = Matrix2D.empty;
56
- for (let i = 0; i < 3; i++) {
57
- for (let j = 0; j < 3; j++) {
98
+ };
99
+ /**
100
+ * The function subtracts two 2D matrices and returns the result as a new Matrix2D object.
101
+ * @param {Matrix2D} matrix1 - Matrix2D - The first matrix to subtract from.
102
+ * @param {Matrix2D} matrix2 - Matrix2D is a class representing a 2D matrix. It has a property `m` which is a 2D array
103
+ * representing the matrix elements.
104
+ * @returns a new instance of the Matrix2D class, which is created using the result array.
105
+ */
106
+ Matrix2D.subtract = function (matrix1, matrix2) {
107
+ var result = Matrix2D.empty;
108
+ for (var i = 0; i < 3; i++) {
109
+ for (var j = 0; j < 3; j++) {
58
110
  result[i][j] = matrix1.m[i][j] - matrix2.m[i][j];
59
111
  }
60
112
  }
61
113
  return new Matrix2D(result);
62
- }
63
- static multiply(matrix1, matrix2) {
64
- const result = Matrix2D.empty;
65
- for (let i = 0; i < 3; i++) {
66
- for (let j = 0; j < 3; j++) {
114
+ };
115
+ /**
116
+ * The function multiplies two 2D matrices and returns the result as a new Matrix2D object.
117
+ * @param {Matrix2D} matrix1 - A 2D matrix represented by the Matrix2D class.
118
+ * @param {Matrix2D} matrix2 - The parameter `matrix2` is a 2D matrix of size 3x3.
119
+ * @returns a new instance of the Matrix2D class, created using the result array.
120
+ */
121
+ Matrix2D.multiply = function (matrix1, matrix2) {
122
+ var result = Matrix2D.empty;
123
+ for (var i = 0; i < 3; i++) {
124
+ for (var j = 0; j < 3; j++) {
67
125
  result[i][j] = 0;
68
- for (let k = 0; k < 3; k++) {
126
+ for (var k = 0; k < 3; k++) {
69
127
  result[i][j] += matrix1.m[i][k] * matrix2.m[k][j];
70
128
  }
71
129
  }
72
130
  }
73
131
  return new Matrix2D(result);
74
- }
75
- static multiplyByValue(matrix, value) {
76
- const result = Matrix2D.empty;
77
- for (let i = 0; i < 3; i++) {
78
- for (let j = 0; j < 3; j++) {
132
+ };
133
+ /**
134
+ * The function multiplies each element of a 2D matrix by a given value and returns the resulting matrix.
135
+ * @param {Matrix2D} matrix - The `matrix` parameter is an instance of the `Matrix2D` class, which represents a 2D
136
+ * matrix. It contains a property `m` that is a 2D array representing the matrix elements.
137
+ * @param {number} value - The `value` parameter is a number that you want to multiply each element of the `matrix` by.
138
+ * @returns a new instance of the Matrix2D class, which is created using the result array.
139
+ */
140
+ Matrix2D.multiplyByValue = function (matrix, value) {
141
+ var result = Matrix2D.empty;
142
+ for (var i = 0; i < 3; i++) {
143
+ for (var j = 0; j < 3; j++) {
79
144
  result[i][j] = matrix.m[i][j] * value;
80
145
  }
81
146
  }
82
147
  return new Matrix2D(result);
83
- }
84
- static multiplyByVector(matrix, vector) {
148
+ };
149
+ /**
150
+ * The function multiplies a 2D matrix by a 2D vector and returns the result as a 2D vector.
151
+ * @param {Matrix2D} matrix - The parameter "matrix" is of type Matrix2D. It represents a 2-dimensional matrix.
152
+ * @param {Vector2D} vector - The "vector" parameter is a 2D vector, represented by an object of type Vector2D.
153
+ * @returns a Vector2D.
154
+ */
155
+ Matrix2D.multiplyByVector = function (matrix, vector) {
85
156
  return Matrix2D.multiply(matrix, new Matrix2D(vector)).toVector;
86
- }
87
- static view(width, height) {
88
- const scaleStep = 1; // Scale every vector * scaleStep
89
- const centerX = width / 2;
90
- const centerY = height / 2;
91
- const flipX = Math.cos(Math.PI); // rotate 180deg / 3.14radian around X-axis
157
+ };
158
+ /**
159
+ * The function returns a 2D matrix that scales and flips a vector around the center of a given width and height.
160
+ * @param {number} width - The width parameter represents the width of the view or the canvas. It is a number that
161
+ * specifies the width in pixels or any other unit of measurement.
162
+ * @param {number} height - The height parameter represents the height of the view or the canvas. It is used to
163
+ * calculate the centerY value, which is the vertical center of the view.
164
+ * @returns a Matrix2D object.
165
+ */
166
+ Matrix2D.view = function (width, height) {
167
+ var scaleStep = 1; // Scale every vector * scaleStep
168
+ var centerX = width / 2;
169
+ var centerY = height / 2;
170
+ var flipX = Math.cos(Math.PI); // rotate 180deg / 3.14radian around X-axis
92
171
  return new Matrix2D([
93
172
  [scaleStep, 0, centerX],
94
173
  [0, flipX * scaleStep, centerY],
95
174
  [0, 0, 1]
96
175
  ]);
97
- }
98
- static scale(factor) {
176
+ };
177
+ /**
178
+ * The function scales a matrix by a given factor.
179
+ * @param {number} factor - The factor parameter is a number that represents the scaling factor by which the matrix
180
+ * should be scaled.
181
+ * @returns the result of multiplying a new instance of Matrix2D by the given factor.
182
+ */
183
+ Matrix2D.scale = function (factor) {
99
184
  return Matrix2D.multiplyByValue(new Matrix2D(), factor);
100
- }
101
- static rotate(radians) {
102
- const cos = Math.cos(radians);
103
- const sin = Math.sin(radians);
185
+ };
186
+ /**
187
+ * The function "rotate" takes an angle in radians and returns a 2D transformation matrix for rotating objects.
188
+ * @param {number} radians - The "radians" parameter is the angle in radians by which you want to rotate an object.
189
+ * @returns The code is returning a new instance of a Matrix2D object.
190
+ */
191
+ Matrix2D.rotate = function (radians) {
192
+ var cos = Math.cos(radians);
193
+ var sin = Math.sin(radians);
104
194
  return new Matrix2D([
105
195
  [cos, -sin, 0],
106
196
  [sin, cos, 0],
107
197
  [0, 0, 1]
108
198
  ]);
109
- }
110
- static translate(vector) {
199
+ };
200
+ /**
201
+ * The translate function takes a 2D vector and returns a 2D matrix that represents a translation transformation.
202
+ * @param {Vector2D} vector - The parameter "vector" is of type Vector2D. It represents a 2D vector with components x
203
+ * and y, and an optional w component.
204
+ * @returns The method is returning a new instance of the Matrix2D class.
205
+ */
206
+ Matrix2D.translate = function (vector) {
111
207
  return new Matrix2D([
112
208
  [1, 0, vector.x],
113
209
  [0, 1, vector.y],
114
210
  [0, 0, vector.w]
115
211
  ]);
116
- }
117
- }
212
+ };
213
+ return Matrix2D;
214
+ }());
118
215
  exports.Matrix2D = Matrix2D;
119
216
  exports.default = Matrix2D;
@@ -1,31 +1,49 @@
1
- type Direction = 'up' | 'right' | 'down' | 'left';
2
- type Turning = {
3
- [key in Direction]: Direction;
4
- };
1
+ /**
2
+ * @copyright 2030 Tyler Zeng <zrwusa@gmail.com>
3
+ * @license MIT
4
+ */
5
+ import type { Direction, NavigatorParams, Turning } from '../types';
5
6
  export declare class Character {
6
7
  direction: Direction;
7
8
  turn: () => Character;
9
+ /**
10
+ * The constructor function takes in a direction and turning object and sets the direction and turn properties of the
11
+ * Character class.
12
+ * @param {Direction} direction - The direction parameter is used to specify the current direction of the character. It
13
+ * can be any value that represents a direction, such as "north", "south", "east", or "west".
14
+ * @param {Turning} turning - The `turning` parameter is an object that maps each direction to the corresponding
15
+ * turning direction. It is used to determine the new direction when the character turns.
16
+ */
8
17
  constructor(direction: Direction, turning: Turning);
9
18
  }
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
19
  export declare class Navigator<T = number> {
20
+ onMove: (cur: [number, number]) => void;
21
21
  private readonly _matrix;
22
22
  private readonly _cur;
23
23
  private _character;
24
24
  private readonly _VISITED;
25
- onMove: (cur: [number, number]) => void;
25
+ /**
26
+ * The constructor initializes the Navigator object with the given parameters and sets the current position as visited
27
+ * in the matrix.
28
+ * @param - - `matrix`: a 2D array representing the grid or map
29
+ */
26
30
  constructor({ matrix, turning, onMove, init: { cur, charDir, VISITED } }: NavigatorParams<T>);
31
+ /**
32
+ * The "start" function moves the character in its current direction until it encounters an obstacle, then it turns the
33
+ * character and repeats the process.
34
+ */
27
35
  start(): void;
36
+ /**
37
+ * The function checks if there is a valid move in the specified direction in a matrix.
38
+ * @param {Direction} direction - The direction parameter is a string that represents the direction in which to check.
39
+ * It can be one of the following values: 'up', 'right', 'down', or 'left'.
40
+ * @returns a boolean value.
41
+ */
28
42
  check(direction: Direction): boolean;
43
+ /**
44
+ * The `move` function updates the current position based on the given direction and updates the matrix accordingly.
45
+ * @param {Direction} direction - The `direction` parameter is a string that represents the direction in which to move.
46
+ * It can have one of the following values: 'up', 'right', 'down', or 'left'.
47
+ */
29
48
  move(direction: Direction): void;
30
49
  }
31
- export {};
@@ -1,15 +1,46 @@
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
+ };
2
18
  Object.defineProperty(exports, "__esModule", { value: true });
3
19
  exports.Navigator = exports.Character = void 0;
4
- class Character {
5
- constructor(direction, turning) {
20
+ var Character = /** @class */ (function () {
21
+ /**
22
+ * The constructor function takes in a direction and turning object and sets the direction and turn properties of the
23
+ * Character class.
24
+ * @param {Direction} direction - The direction parameter is used to specify the current direction of the character. It
25
+ * can be any value that represents a direction, such as "north", "south", "east", or "west".
26
+ * @param {Turning} turning - The `turning` parameter is an object that maps each direction to the corresponding
27
+ * turning direction. It is used to determine the new direction when the character turns.
28
+ */
29
+ function Character(direction, turning) {
6
30
  this.direction = direction;
7
- this.turn = () => new Character(turning[direction], turning);
31
+ this.turn = function () { return new Character(turning[direction], turning); };
8
32
  }
9
- }
33
+ return Character;
34
+ }());
10
35
  exports.Character = Character;
11
- class Navigator {
12
- constructor({ matrix, turning, onMove, init: { cur, charDir, VISITED } }) {
36
+ var Navigator = /** @class */ (function () {
37
+ /**
38
+ * The constructor initializes the Navigator object with the given parameters and sets the current position as visited
39
+ * in the matrix.
40
+ * @param - - `matrix`: a 2D array representing the grid or map
41
+ */
42
+ function Navigator(_a) {
43
+ var matrix = _a.matrix, turning = _a.turning, onMove = _a.onMove, _b = _a.init, cur = _b.cur, charDir = _b.charDir, VISITED = _b.VISITED;
13
44
  this._matrix = matrix;
14
45
  this._cur = cur;
15
46
  this._character = new Character(charDir, turning);
@@ -18,9 +49,13 @@ class Navigator {
18
49
  this._VISITED = VISITED;
19
50
  this._matrix[this._cur[0]][this._cur[1]] = this._VISITED;
20
51
  }
21
- start() {
52
+ /**
53
+ * The "start" function moves the character in its current direction until it encounters an obstacle, then it turns the
54
+ * character and repeats the process.
55
+ */
56
+ Navigator.prototype.start = function () {
22
57
  while (this.check(this._character.direction) || this.check(this._character.turn().direction)) {
23
- const { direction } = this._character;
58
+ var direction = this._character.direction;
24
59
  if (this.check(direction)) {
25
60
  this.move(direction);
26
61
  }
@@ -28,11 +63,17 @@ class Navigator {
28
63
  this._character = this._character.turn();
29
64
  }
30
65
  }
31
- }
32
- check(direction) {
33
- let forward, row;
34
- const matrix = this._matrix;
35
- const [i, j] = this._cur;
66
+ };
67
+ /**
68
+ * The function checks if there is a valid move in the specified direction in a matrix.
69
+ * @param {Direction} direction - The direction parameter is a string that represents the direction in which to check.
70
+ * It can be one of the following values: 'up', 'right', 'down', or 'left'.
71
+ * @returns a boolean value.
72
+ */
73
+ Navigator.prototype.check = function (direction) {
74
+ var forward, row;
75
+ var matrix = this._matrix;
76
+ var _a = __read(this._cur, 2), i = _a[0], j = _a[1];
36
77
  switch (direction) {
37
78
  case 'up':
38
79
  row = matrix[i - 1];
@@ -54,8 +95,13 @@ class Navigator {
54
95
  break;
55
96
  }
56
97
  return forward !== undefined && forward !== this._VISITED;
57
- }
58
- move(direction) {
98
+ };
99
+ /**
100
+ * The `move` function updates the current position based on the given direction and updates the matrix accordingly.
101
+ * @param {Direction} direction - The `direction` parameter is a string that represents the direction in which to move.
102
+ * It can have one of the following values: 'up', 'right', 'down', or 'left'.
103
+ */
104
+ Navigator.prototype.move = function (direction) {
59
105
  switch (direction) {
60
106
  case 'up':
61
107
  this._cur[0]--;
@@ -70,9 +116,10 @@ class Navigator {
70
116
  this._cur[1]--;
71
117
  break;
72
118
  }
73
- const [i, j] = this._cur;
119
+ var _a = __read(this._cur, 2), i = _a[0], j = _a[1];
74
120
  this._matrix[i][j] = this._VISITED;
75
121
  this.onMove && this.onMove(this._cur);
76
- }
77
- }
122
+ };
123
+ return Navigator;
124
+ }());
78
125
  exports.Navigator = Navigator;