data-structure-typed 1.21.3 → 1.31.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 (560) hide show
  1. package/.auto-changelog +9 -0
  2. package/.auto-changelog-template.hbs +36 -0
  3. package/.eslintrc.js +61 -0
  4. package/.github/workflows/ci.yml +30 -0
  5. package/.prettierignore +6 -0
  6. package/.prettierrc.js +16 -0
  7. package/CHANGELOG.md +17 -0
  8. package/README.md +150 -98
  9. package/dist/data-structures/binary-tree/aa-tree.js +6 -2
  10. package/dist/data-structures/binary-tree/aa-tree.js.map +1 -0
  11. package/dist/data-structures/binary-tree/abstract-binary-tree.js +398 -672
  12. package/dist/data-structures/binary-tree/abstract-binary-tree.js.map +1 -0
  13. package/dist/data-structures/binary-tree/avl-tree.js +122 -151
  14. package/dist/data-structures/binary-tree/avl-tree.js.map +1 -0
  15. package/dist/data-structures/binary-tree/b-tree.js +6 -2
  16. package/dist/data-structures/binary-tree/b-tree.js.map +1 -0
  17. package/dist/data-structures/binary-tree/binary-indexed-tree.js +24 -54
  18. package/dist/data-structures/binary-tree/binary-indexed-tree.js.map +1 -0
  19. package/dist/data-structures/binary-tree/binary-tree.js +31 -32
  20. package/dist/data-structures/binary-tree/binary-tree.js.map +1 -0
  21. package/dist/data-structures/binary-tree/bst.js +266 -208
  22. package/dist/data-structures/binary-tree/bst.js.map +1 -0
  23. package/dist/data-structures/binary-tree/index.js +1 -0
  24. package/dist/data-structures/binary-tree/index.js.map +1 -0
  25. package/dist/data-structures/binary-tree/rb-tree.js +46 -37
  26. package/dist/data-structures/binary-tree/rb-tree.js.map +1 -0
  27. package/dist/data-structures/binary-tree/segment-tree.js +124 -127
  28. package/dist/data-structures/binary-tree/segment-tree.js.map +1 -0
  29. package/dist/data-structures/binary-tree/splay-tree.js +6 -2
  30. package/dist/data-structures/binary-tree/splay-tree.js.map +1 -0
  31. package/dist/data-structures/binary-tree/tree-multiset.js +227 -354
  32. package/dist/data-structures/binary-tree/tree-multiset.js.map +1 -0
  33. package/dist/data-structures/binary-tree/two-three-tree.js +6 -2
  34. package/dist/data-structures/binary-tree/two-three-tree.js.map +1 -0
  35. package/dist/data-structures/graph/abstract-graph.js +582 -609
  36. package/dist/data-structures/graph/abstract-graph.js.map +1 -0
  37. package/dist/data-structures/graph/directed-graph.js +276 -312
  38. package/dist/data-structures/graph/directed-graph.js.map +1 -0
  39. package/dist/data-structures/graph/index.js +1 -0
  40. package/dist/data-structures/graph/index.js.map +1 -0
  41. package/dist/data-structures/graph/map-graph.js +88 -100
  42. package/dist/data-structures/graph/map-graph.js.map +1 -0
  43. package/dist/data-structures/graph/undirected-graph.js +180 -195
  44. package/dist/data-structures/graph/undirected-graph.js.map +1 -0
  45. package/dist/data-structures/hash/coordinate-map.js +46 -58
  46. package/dist/data-structures/hash/coordinate-map.js.map +1 -0
  47. package/dist/data-structures/hash/coordinate-set.js +43 -48
  48. package/dist/data-structures/hash/coordinate-set.js.map +1 -0
  49. package/dist/data-structures/hash/hash-table.js +6 -2
  50. package/dist/data-structures/hash/hash-table.js.map +1 -0
  51. package/dist/data-structures/hash/index.js +1 -0
  52. package/dist/data-structures/hash/index.js.map +1 -0
  53. package/dist/data-structures/hash/pair.js +6 -2
  54. package/dist/data-structures/hash/pair.js.map +1 -0
  55. package/dist/data-structures/hash/tree-map.js +6 -2
  56. package/dist/data-structures/hash/tree-map.js.map +1 -0
  57. package/dist/data-structures/hash/tree-set.js +6 -2
  58. package/dist/data-structures/hash/tree-set.js.map +1 -0
  59. package/dist/data-structures/heap/heap.js +83 -120
  60. package/dist/data-structures/heap/heap.js.map +1 -0
  61. package/dist/data-structures/heap/index.js +1 -0
  62. package/dist/data-structures/heap/index.js.map +1 -0
  63. package/dist/data-structures/heap/max-heap.js +27 -24
  64. package/dist/data-structures/heap/max-heap.js.map +1 -0
  65. package/dist/data-structures/heap/min-heap.js +27 -25
  66. package/dist/data-structures/heap/min-heap.js.map +1 -0
  67. package/dist/data-structures/index.js +1 -0
  68. package/dist/data-structures/index.js.map +1 -0
  69. package/dist/data-structures/linked-list/doubly-linked-list.js +202 -307
  70. package/dist/data-structures/linked-list/doubly-linked-list.js.map +1 -0
  71. package/dist/data-structures/linked-list/index.js +1 -0
  72. package/dist/data-structures/linked-list/index.js.map +1 -0
  73. package/dist/data-structures/linked-list/singly-linked-list.js +223 -251
  74. package/dist/data-structures/linked-list/singly-linked-list.js.map +1 -0
  75. package/dist/data-structures/linked-list/skip-linked-list.js +6 -2
  76. package/dist/data-structures/linked-list/skip-linked-list.js.map +1 -0
  77. package/dist/data-structures/matrix/index.js +1 -0
  78. package/dist/data-structures/matrix/index.js.map +1 -0
  79. package/dist/data-structures/matrix/matrix.js +9 -22
  80. package/dist/data-structures/matrix/matrix.js.map +1 -0
  81. package/dist/data-structures/matrix/matrix2d.js +75 -149
  82. package/dist/data-structures/matrix/matrix2d.js.map +1 -0
  83. package/dist/data-structures/matrix/navigator.js +38 -46
  84. package/dist/data-structures/matrix/navigator.js.map +1 -0
  85. package/dist/data-structures/matrix/vector2d.js +90 -254
  86. package/dist/data-structures/matrix/vector2d.js.map +1 -0
  87. package/dist/data-structures/priority-queue/index.js +1 -0
  88. package/dist/data-structures/priority-queue/index.js.map +1 -0
  89. package/dist/data-structures/priority-queue/max-priority-queue.js +47 -32
  90. package/dist/data-structures/priority-queue/max-priority-queue.js.map +1 -0
  91. package/dist/data-structures/priority-queue/min-priority-queue.js +47 -33
  92. package/dist/data-structures/priority-queue/min-priority-queue.js.map +1 -0
  93. package/dist/data-structures/priority-queue/priority-queue.js +150 -241
  94. package/dist/data-structures/priority-queue/priority-queue.js.map +1 -0
  95. package/dist/data-structures/queue/deque.js +130 -162
  96. package/dist/data-structures/queue/deque.js.map +1 -0
  97. package/dist/data-structures/queue/index.js +1 -0
  98. package/dist/data-structures/queue/index.js.map +1 -0
  99. package/dist/data-structures/queue/queue.js +181 -100
  100. package/dist/data-structures/queue/queue.js.map +1 -0
  101. package/dist/data-structures/stack/index.js +1 -0
  102. package/dist/data-structures/stack/index.js.map +1 -0
  103. package/dist/data-structures/stack/stack.js +23 -71
  104. package/dist/data-structures/stack/stack.js.map +1 -0
  105. package/dist/data-structures/tree/index.js +1 -0
  106. package/dist/data-structures/tree/index.js.map +1 -0
  107. package/dist/data-structures/tree/tree.js +46 -33
  108. package/dist/data-structures/tree/tree.js.map +1 -0
  109. package/dist/data-structures/trie/index.js +1 -0
  110. package/dist/data-structures/trie/index.js.map +1 -0
  111. package/dist/data-structures/trie/trie.js +201 -129
  112. package/dist/data-structures/trie/trie.js.map +1 -0
  113. package/dist/index.js +1 -0
  114. package/dist/index.js.map +1 -0
  115. package/dist/interfaces/abstract-binary-tree.js +1 -0
  116. package/dist/interfaces/abstract-binary-tree.js.map +1 -0
  117. package/dist/interfaces/abstract-graph.js +1 -0
  118. package/dist/interfaces/abstract-graph.js.map +1 -0
  119. package/dist/interfaces/avl-tree.js +1 -0
  120. package/dist/interfaces/avl-tree.js.map +1 -0
  121. package/dist/interfaces/binary-tree.js +1 -0
  122. package/dist/interfaces/binary-tree.js.map +1 -0
  123. package/dist/interfaces/bst.js +1 -0
  124. package/dist/interfaces/bst.js.map +1 -0
  125. package/dist/interfaces/directed-graph.js +1 -0
  126. package/dist/interfaces/directed-graph.js.map +1 -0
  127. package/dist/interfaces/doubly-linked-list.js +1 -0
  128. package/dist/interfaces/doubly-linked-list.js.map +1 -0
  129. package/dist/interfaces/heap.js +1 -0
  130. package/dist/interfaces/heap.js.map +1 -0
  131. package/dist/interfaces/index.js +1 -0
  132. package/dist/interfaces/index.js.map +1 -0
  133. package/dist/interfaces/navigator.js +1 -0
  134. package/dist/interfaces/navigator.js.map +1 -0
  135. package/dist/interfaces/priority-queue.js +1 -0
  136. package/dist/interfaces/priority-queue.js.map +1 -0
  137. package/dist/interfaces/rb-tree.js +1 -0
  138. package/dist/interfaces/rb-tree.js.map +1 -0
  139. package/dist/interfaces/segment-tree.js +1 -0
  140. package/dist/interfaces/segment-tree.js.map +1 -0
  141. package/dist/interfaces/singly-linked-list.js +1 -0
  142. package/dist/interfaces/singly-linked-list.js.map +1 -0
  143. package/dist/interfaces/tree-multiset.js +1 -0
  144. package/dist/interfaces/tree-multiset.js.map +1 -0
  145. package/dist/interfaces/undirected-graph.js +1 -0
  146. package/dist/interfaces/undirected-graph.js.map +1 -0
  147. package/dist/types/data-structures/abstract-binary-tree.js +1 -7
  148. package/dist/types/data-structures/abstract-binary-tree.js.map +1 -0
  149. package/dist/types/data-structures/abstract-graph.js +1 -0
  150. package/dist/types/data-structures/abstract-graph.js.map +1 -0
  151. package/dist/types/data-structures/avl-tree.js +1 -0
  152. package/dist/types/data-structures/avl-tree.js.map +1 -0
  153. package/dist/types/data-structures/binary-tree.js +1 -0
  154. package/dist/types/data-structures/binary-tree.js.map +1 -0
  155. package/dist/types/data-structures/bst.js +1 -0
  156. package/dist/types/data-structures/bst.js.map +1 -0
  157. package/dist/types/data-structures/directed-graph.js +1 -0
  158. package/dist/types/data-structures/directed-graph.js.map +1 -0
  159. package/dist/types/data-structures/doubly-linked-list.js +1 -0
  160. package/dist/types/data-structures/doubly-linked-list.js.map +1 -0
  161. package/dist/types/data-structures/heap.js +1 -0
  162. package/dist/types/data-structures/heap.js.map +1 -0
  163. package/dist/types/data-structures/index.js +1 -0
  164. package/dist/types/data-structures/index.js.map +1 -0
  165. package/dist/types/data-structures/map-graph.js +1 -0
  166. package/dist/types/data-structures/map-graph.js.map +1 -0
  167. package/dist/types/data-structures/navigator.js +1 -0
  168. package/dist/types/data-structures/navigator.js.map +1 -0
  169. package/dist/types/data-structures/priority-queue.js +1 -0
  170. package/dist/types/data-structures/priority-queue.js.map +1 -0
  171. package/dist/types/data-structures/rb-tree.js +1 -0
  172. package/dist/types/data-structures/rb-tree.js.map +1 -0
  173. package/dist/types/data-structures/segment-tree.js +1 -0
  174. package/dist/types/data-structures/segment-tree.js.map +1 -0
  175. package/dist/types/data-structures/singly-linked-list.js +1 -0
  176. package/dist/types/data-structures/singly-linked-list.js.map +1 -0
  177. package/dist/types/data-structures/tree-multiset.js +1 -0
  178. package/dist/types/data-structures/tree-multiset.js.map +1 -0
  179. package/dist/types/helpers.js +1 -0
  180. package/dist/types/helpers.js.map +1 -0
  181. package/dist/types/index.js +1 -0
  182. package/dist/types/index.js.map +1 -0
  183. package/dist/types/utils/index.js +1 -0
  184. package/dist/types/utils/index.js.map +1 -0
  185. package/dist/types/utils/utils.js +1 -0
  186. package/dist/types/utils/utils.js.map +1 -0
  187. package/dist/types/utils/validate-type.js +1 -0
  188. package/dist/types/utils/validate-type.js.map +1 -0
  189. package/dist/utils/index.js +1 -0
  190. package/dist/utils/index.js.map +1 -0
  191. package/dist/utils/utils.js +108 -22
  192. package/dist/utils/utils.js.map +1 -0
  193. package/docs/.nojekyll +1 -0
  194. package/docs/assets/highlight.css +127 -0
  195. package/docs/assets/main.js +58 -0
  196. package/docs/assets/search.js +1 -0
  197. package/docs/assets/style.css +1367 -0
  198. package/docs/classes/AVLTree.html +2259 -0
  199. package/docs/classes/AVLTreeNode.html +399 -0
  200. package/docs/classes/AaTree.html +202 -0
  201. package/docs/classes/AbstractBinaryTree.html +1913 -0
  202. package/docs/classes/AbstractBinaryTreeNode.html +441 -0
  203. package/docs/classes/AbstractEdge.html +345 -0
  204. package/docs/classes/AbstractGraph.html +1105 -0
  205. package/docs/classes/AbstractVertex.html +299 -0
  206. package/docs/classes/ArrayDeque.html +469 -0
  207. package/docs/classes/BST.html +2103 -0
  208. package/docs/classes/BSTNode.html +400 -0
  209. package/docs/classes/BTree.html +202 -0
  210. package/docs/classes/BinaryIndexedTree.html +371 -0
  211. package/docs/classes/BinaryTree.html +1944 -0
  212. package/docs/classes/BinaryTreeNode.html +399 -0
  213. package/docs/classes/Character.html +250 -0
  214. package/docs/classes/CoordinateMap.html +513 -0
  215. package/docs/classes/CoordinateSet.html +474 -0
  216. package/docs/classes/Deque.html +1005 -0
  217. package/docs/classes/DirectedEdge.html +404 -0
  218. package/docs/classes/DirectedGraph.html +1530 -0
  219. package/docs/classes/DirectedVertex.html +286 -0
  220. package/docs/classes/DoublyLinkedList.html +998 -0
  221. package/docs/classes/DoublyLinkedListNode.html +327 -0
  222. package/docs/classes/HashTable.html +202 -0
  223. package/docs/classes/Heap.html +647 -0
  224. package/docs/classes/HeapItem.html +296 -0
  225. package/docs/classes/LinkedListQueue.html +884 -0
  226. package/docs/classes/MapEdge.html +391 -0
  227. package/docs/classes/MapGraph.html +1583 -0
  228. package/docs/classes/MapVertex.html +356 -0
  229. package/docs/classes/Matrix2D.html +532 -0
  230. package/docs/classes/MatrixNTI2D.html +270 -0
  231. package/docs/classes/MaxHeap.html +671 -0
  232. package/docs/classes/MaxPriorityQueue.html +866 -0
  233. package/docs/classes/MinHeap.html +672 -0
  234. package/docs/classes/MinPriorityQueue.html +868 -0
  235. package/docs/classes/Navigator.html +343 -0
  236. package/docs/classes/ObjectDeque.html +527 -0
  237. package/docs/classes/Pair.html +202 -0
  238. package/docs/classes/PriorityQueue.html +790 -0
  239. package/docs/classes/Queue.html +521 -0
  240. package/docs/classes/RBTree.html +2101 -0
  241. package/docs/classes/RBTreeNode.html +431 -0
  242. package/docs/classes/SegmentTree.html +464 -0
  243. package/docs/classes/SegmentTreeNode.html +387 -0
  244. package/docs/classes/SinglyLinkedList.html +830 -0
  245. package/docs/classes/SinglyLinkedListNode.html +300 -0
  246. package/docs/classes/SkipLinkedList.html +202 -0
  247. package/docs/classes/SplayTree.html +202 -0
  248. package/docs/classes/Stack.html +398 -0
  249. package/docs/classes/TreeMap.html +202 -0
  250. package/docs/classes/TreeMultiset.html +2587 -0
  251. package/docs/classes/TreeMultisetNode.html +447 -0
  252. package/docs/classes/TreeNode.html +344 -0
  253. package/docs/classes/TreeSet.html +202 -0
  254. package/docs/classes/Trie.html +402 -0
  255. package/docs/classes/TrieNode.html +310 -0
  256. package/docs/classes/TwoThreeTree.html +202 -0
  257. package/docs/classes/UndirectedEdge.html +374 -0
  258. package/docs/classes/UndirectedGraph.html +1285 -0
  259. package/docs/classes/UndirectedVertex.html +284 -0
  260. package/docs/classes/Vector2D.html +835 -0
  261. package/docs/enums/CP.html +211 -0
  262. package/docs/enums/FamilyPosition.html +239 -0
  263. package/docs/enums/LoopType.html +212 -0
  264. package/docs/enums/RBColor.html +204 -0
  265. package/docs/enums/TopologicalProperty.html +211 -0
  266. package/docs/functions/arrayRemove.html +208 -0
  267. package/docs/functions/isThunk.html +186 -0
  268. package/docs/functions/toThunk.html +186 -0
  269. package/docs/functions/trampoline.html +186 -0
  270. package/docs/functions/trampolineAsync.html +186 -0
  271. package/docs/functions/uuidV4.html +181 -0
  272. package/docs/index.html +693 -0
  273. package/docs/interfaces/IAVLTree.html +1245 -0
  274. package/docs/interfaces/IAbstractBinaryTree.html +1101 -0
  275. package/docs/interfaces/IAbstractBinaryTreeNode.html +335 -0
  276. package/docs/interfaces/IAbstractGraph.html +433 -0
  277. package/docs/interfaces/IBST.html +1245 -0
  278. package/docs/interfaces/IDirectedGraph.html +570 -0
  279. package/docs/interfaces/IRBTree.html +1247 -0
  280. package/docs/interfaces/IUNDirectedGraph.html +463 -0
  281. package/docs/modules.html +328 -0
  282. package/docs/types/AVLTreeNodeNested.html +182 -0
  283. package/docs/types/AVLTreeOptions.html +180 -0
  284. package/docs/types/AbstractBinaryTreeNodeNested.html +182 -0
  285. package/docs/types/AbstractBinaryTreeNodeProperties.html +182 -0
  286. package/docs/types/AbstractBinaryTreeNodeProperty.html +182 -0
  287. package/docs/types/AbstractBinaryTreeOptions.html +182 -0
  288. package/docs/types/BSTComparator.html +192 -0
  289. package/docs/types/BSTNodeNested.html +182 -0
  290. package/docs/types/BSTOptions.html +182 -0
  291. package/docs/types/BinaryTreeDeletedResult.html +189 -0
  292. package/docs/types/BinaryTreeNodeId.html +177 -0
  293. package/docs/types/BinaryTreeNodeNested.html +182 -0
  294. package/docs/types/BinaryTreeNodePropertyName.html +177 -0
  295. package/docs/types/BinaryTreeOptions.html +180 -0
  296. package/docs/types/DFSOrderPattern.html +177 -0
  297. package/docs/types/DijkstraResult.html +199 -0
  298. package/docs/types/Direction.html +177 -0
  299. package/docs/types/DummyAny.html +190 -0
  300. package/docs/types/EdgeId.html +177 -0
  301. package/docs/types/HeapOptions.html +198 -0
  302. package/docs/types/IAVLTreeNode.html +184 -0
  303. package/docs/types/IBSTNode.html +184 -0
  304. package/docs/types/IBinaryTree.html +182 -0
  305. package/docs/types/IBinaryTreeNode.html +184 -0
  306. package/docs/types/IRBTreeNode.html +184 -0
  307. package/docs/types/ITreeMultiset.html +182 -0
  308. package/docs/types/ITreeMultisetNode.html +184 -0
  309. package/docs/types/KeyValueObject.html +182 -0
  310. package/docs/types/KeyValueObjectWithId.html +184 -0
  311. package/docs/types/MapGraphCoordinate.html +177 -0
  312. package/docs/types/NavigatorParams.html +211 -0
  313. package/docs/types/NodeOrPropertyName.html +177 -0
  314. package/docs/types/NonNumberNonObjectButDefined.html +177 -0
  315. package/docs/types/ObjectWithNonNumberId.html +184 -0
  316. package/docs/types/ObjectWithNumberId.html +184 -0
  317. package/docs/types/ObjectWithoutId.html +177 -0
  318. package/docs/types/PriorityQueueComparator.html +197 -0
  319. package/docs/types/PriorityQueueDFSOrderPattern.html +177 -0
  320. package/docs/types/PriorityQueueOptions.html +191 -0
  321. package/docs/types/RBTreeNodeNested.html +182 -0
  322. package/docs/types/RBTreeOptions.html +180 -0
  323. package/docs/types/RestrictValById.html +177 -0
  324. package/docs/types/SegmentTreeNodeVal.html +177 -0
  325. package/docs/types/SpecifyOptional.html +184 -0
  326. package/docs/types/Thunk.html +185 -0
  327. package/docs/types/ToThunkFn.html +185 -0
  328. package/docs/types/TopologicalStatus.html +177 -0
  329. package/docs/types/TreeMultisetNodeNested.html +182 -0
  330. package/docs/types/TreeMultisetOptions.html +180 -0
  331. package/docs/types/TrlAsyncFn.html +190 -0
  332. package/docs/types/TrlFn.html +190 -0
  333. package/docs/types/Turning.html +177 -0
  334. package/docs/types/VertexId.html +177 -0
  335. package/docs/variables/THUNK_SYMBOL.html +177 -0
  336. package/jest.config.js +5 -0
  337. package/lib/data-structures/binary-tree/aa-tree.js +2 -0
  338. package/{dist → lib}/data-structures/binary-tree/abstract-binary-tree.d.ts +25 -20
  339. package/lib/data-structures/binary-tree/abstract-binary-tree.js +1307 -0
  340. package/{dist → lib}/data-structures/binary-tree/avl-tree.d.ts +12 -12
  341. package/lib/data-structures/binary-tree/avl-tree.js +311 -0
  342. package/lib/data-structures/binary-tree/b-tree.js +2 -0
  343. package/lib/data-structures/binary-tree/binary-indexed-tree.js +69 -0
  344. package/lib/data-structures/binary-tree/binary-tree.js +35 -0
  345. package/{dist → lib}/data-structures/binary-tree/bst.d.ts +19 -8
  346. package/lib/data-structures/binary-tree/bst.js +551 -0
  347. package/lib/data-structures/binary-tree/index.js +12 -0
  348. package/{dist → lib}/data-structures/binary-tree/rb-tree.d.ts +0 -6
  349. package/lib/data-structures/binary-tree/rb-tree.js +22 -0
  350. package/lib/data-structures/binary-tree/segment-tree.js +210 -0
  351. package/lib/data-structures/binary-tree/splay-tree.js +2 -0
  352. package/{dist → lib}/data-structures/binary-tree/tree-multiset.d.ts +20 -23
  353. package/lib/data-structures/binary-tree/tree-multiset.js +673 -0
  354. package/lib/data-structures/binary-tree/two-three-tree.js +2 -0
  355. package/lib/data-structures/graph/abstract-graph.js +918 -0
  356. package/lib/data-structures/graph/directed-graph.js +416 -0
  357. package/lib/data-structures/graph/index.js +4 -0
  358. package/lib/data-structures/graph/map-graph.js +105 -0
  359. package/lib/data-structures/graph/undirected-graph.js +246 -0
  360. package/lib/data-structures/hash/coordinate-map.js +61 -0
  361. package/lib/data-structures/hash/coordinate-set.js +51 -0
  362. package/lib/data-structures/hash/hash-table.js +2 -0
  363. package/lib/data-structures/hash/index.js +6 -0
  364. package/lib/data-structures/hash/pair.js +2 -0
  365. package/lib/data-structures/hash/tree-map.js +2 -0
  366. package/lib/data-structures/hash/tree-set.js +2 -0
  367. package/lib/data-structures/heap/heap.js +152 -0
  368. package/lib/data-structures/heap/index.js +3 -0
  369. package/lib/data-structures/heap/max-heap.js +26 -0
  370. package/lib/data-structures/heap/min-heap.js +27 -0
  371. package/lib/data-structures/index.js +11 -0
  372. package/{dist → lib}/data-structures/linked-list/doubly-linked-list.d.ts +5 -5
  373. package/lib/data-structures/linked-list/doubly-linked-list.js +521 -0
  374. package/lib/data-structures/linked-list/index.js +3 -0
  375. package/{dist → lib}/data-structures/linked-list/singly-linked-list.d.ts +6 -5
  376. package/lib/data-structures/linked-list/singly-linked-list.js +443 -0
  377. package/lib/data-structures/linked-list/skip-linked-list.js +2 -0
  378. package/lib/data-structures/matrix/index.js +4 -0
  379. package/lib/data-structures/matrix/matrix.js +24 -0
  380. package/lib/data-structures/matrix/matrix2d.js +195 -0
  381. package/lib/data-structures/matrix/navigator.js +101 -0
  382. package/lib/data-structures/matrix/vector2d.js +287 -0
  383. package/lib/data-structures/priority-queue/index.js +3 -0
  384. package/lib/data-structures/priority-queue/max-priority-queue.js +39 -0
  385. package/lib/data-structures/priority-queue/min-priority-queue.js +40 -0
  386. package/lib/data-structures/priority-queue/priority-queue.js +317 -0
  387. package/{dist → lib}/data-structures/queue/deque.d.ts +45 -0
  388. package/lib/data-structures/queue/deque.js +270 -0
  389. package/lib/data-structures/queue/index.js +2 -0
  390. package/{dist → lib}/data-structures/queue/queue.d.ts +47 -13
  391. package/lib/data-structures/queue/queue.js +165 -0
  392. package/lib/data-structures/stack/index.js +1 -0
  393. package/lib/data-structures/stack/stack.js +87 -0
  394. package/lib/data-structures/tree/index.js +1 -0
  395. package/lib/data-structures/tree/tree.js +56 -0
  396. package/lib/data-structures/trie/index.js +1 -0
  397. package/lib/data-structures/trie/trie.js +205 -0
  398. package/lib/index.js +4 -0
  399. package/{dist → lib}/interfaces/avl-tree.d.ts +1 -9
  400. package/lib/interfaces/binary-tree.d.ts +4 -0
  401. package/{dist → lib}/interfaces/bst.d.ts +1 -2
  402. package/lib/interfaces/heap.js +1 -0
  403. package/lib/interfaces/index.js +15 -0
  404. package/lib/interfaces/navigator.d.ts +1 -0
  405. package/lib/interfaces/navigator.js +1 -0
  406. package/lib/interfaces/priority-queue.d.ts +1 -0
  407. package/lib/interfaces/priority-queue.js +1 -0
  408. package/{dist → lib}/interfaces/rb-tree.d.ts +1 -2
  409. package/lib/interfaces/rb-tree.js +1 -0
  410. package/lib/interfaces/segment-tree.d.ts +1 -0
  411. package/lib/interfaces/segment-tree.js +1 -0
  412. package/lib/interfaces/singly-linked-list.d.ts +1 -0
  413. package/lib/interfaces/singly-linked-list.js +1 -0
  414. package/lib/interfaces/tree-multiset.d.ts +5 -0
  415. package/lib/interfaces/tree-multiset.js +1 -0
  416. package/lib/interfaces/undirected-graph.js +1 -0
  417. package/{dist → lib}/types/data-structures/abstract-binary-tree.d.ts +1 -1
  418. package/lib/types/data-structures/abstract-binary-tree.js +22 -0
  419. package/lib/types/data-structures/abstract-graph.js +1 -0
  420. package/{dist → lib}/types/data-structures/avl-tree.d.ts +1 -1
  421. package/lib/types/data-structures/avl-tree.js +1 -0
  422. package/lib/types/data-structures/binary-tree.js +1 -0
  423. package/lib/types/data-structures/bst.js +6 -0
  424. package/lib/types/data-structures/directed-graph.js +6 -0
  425. package/lib/types/data-structures/doubly-linked-list.d.ts +1 -0
  426. package/lib/types/data-structures/doubly-linked-list.js +1 -0
  427. package/lib/types/data-structures/heap.js +1 -0
  428. package/lib/types/data-structures/index.js +15 -0
  429. package/lib/types/data-structures/map-graph.js +1 -0
  430. package/lib/types/data-structures/navigator.js +1 -0
  431. package/lib/types/data-structures/priority-queue.js +1 -0
  432. package/lib/types/data-structures/rb-tree.js +5 -0
  433. package/lib/types/data-structures/segment-tree.js +1 -0
  434. package/lib/types/data-structures/singly-linked-list.d.ts +1 -0
  435. package/lib/types/data-structures/singly-linked-list.js +1 -0
  436. package/lib/types/data-structures/tree-multiset.js +1 -0
  437. package/lib/types/helpers.d.ts +1 -0
  438. package/lib/types/helpers.js +1 -0
  439. package/lib/types/index.js +3 -0
  440. package/lib/types/utils/index.js +2 -0
  441. package/{dist → lib}/types/utils/utils.d.ts +1 -1
  442. package/lib/types/utils/utils.js +1 -0
  443. package/{dist → lib}/types/utils/validate-type.d.ts +1 -1
  444. package/lib/types/utils/validate-type.js +1 -0
  445. package/lib/utils/index.js +1 -0
  446. package/lib/utils/utils.js +57 -0
  447. package/package.json +147 -56
  448. package/rename_clear_files.sh +29 -0
  449. package/test/integration/avl-tree.test.ts +111 -0
  450. package/test/integration/bst.test.ts +371 -0
  451. package/test/integration/heap.test.js +19 -0
  452. package/test/integration/index.html +44 -0
  453. package/test/unit/data-structures/binary-tree/avl-tree.test.ts +111 -0
  454. package/test/unit/data-structures/binary-tree/bst.test.ts +371 -0
  455. package/test/unit/data-structures/binary-tree/overall.test.ts +57 -0
  456. package/test/unit/data-structures/binary-tree/tree-multiset.test.ts +405 -0
  457. package/test/unit/data-structures/graph/abstract-graph.test.ts +5 -0
  458. package/test/unit/data-structures/graph/directed-graph.test.ts +517 -0
  459. package/test/unit/data-structures/graph/index.ts +2 -0
  460. package/test/unit/data-structures/graph/map-graph.test.ts +46 -0
  461. package/test/unit/data-structures/graph/overall.test.ts +50 -0
  462. package/test/unit/data-structures/graph/undirected-graph.test.ts +60 -0
  463. package/test/unit/data-structures/heap/heap.test.ts +56 -0
  464. package/test/unit/data-structures/heap/max-heap.test.ts +42 -0
  465. package/test/unit/data-structures/heap/min-heap.test.ts +81 -0
  466. package/test/unit/data-structures/linked-list/doubly-linked-list.test.ts +365 -0
  467. package/test/unit/data-structures/linked-list/index.ts +4 -0
  468. package/test/unit/data-structures/linked-list/linked-list.test.ts +37 -0
  469. package/test/unit/data-structures/linked-list/singly-linked-list.test.ts +401 -0
  470. package/test/unit/data-structures/linked-list/skip-linked-list.test.ts +13 -0
  471. package/test/unit/data-structures/priority-queue/max-priority-queue.test.ts +106 -0
  472. package/test/unit/data-structures/priority-queue/min-priority-queue.test.ts +105 -0
  473. package/test/unit/data-structures/priority-queue/priority-queue.test.ts +27 -0
  474. package/test/unit/data-structures/queue/queue.test.ts +36 -0
  475. package/test/utils/index.ts +2 -0
  476. package/test/utils/magnitude.ts +21 -0
  477. package/test/utils/number.ts +3 -0
  478. package/tsconfig.build.json +33 -0
  479. package/tsconfig.json +38 -0
  480. package/umd/bundle.min.js +3 -0
  481. package/umd/bundle.min.js.map +1 -0
  482. package/webpack.config.js +28 -0
  483. package/dist/bundle.js +0 -2
  484. package/dist/interfaces/binary-tree.d.ts +0 -6
  485. package/dist/interfaces/tree-multiset.d.ts +0 -7
  486. /package/{dist → lib}/data-structures/binary-tree/aa-tree.d.ts +0 -0
  487. /package/{dist → lib}/data-structures/binary-tree/b-tree.d.ts +0 -0
  488. /package/{dist → lib}/data-structures/binary-tree/binary-indexed-tree.d.ts +0 -0
  489. /package/{dist → lib}/data-structures/binary-tree/binary-tree.d.ts +0 -0
  490. /package/{dist → lib}/data-structures/binary-tree/index.d.ts +0 -0
  491. /package/{dist → lib}/data-structures/binary-tree/segment-tree.d.ts +0 -0
  492. /package/{dist → lib}/data-structures/binary-tree/splay-tree.d.ts +0 -0
  493. /package/{dist → lib}/data-structures/binary-tree/two-three-tree.d.ts +0 -0
  494. /package/{dist → lib}/data-structures/graph/abstract-graph.d.ts +0 -0
  495. /package/{dist → lib}/data-structures/graph/directed-graph.d.ts +0 -0
  496. /package/{dist → lib}/data-structures/graph/index.d.ts +0 -0
  497. /package/{dist → lib}/data-structures/graph/map-graph.d.ts +0 -0
  498. /package/{dist → lib}/data-structures/graph/undirected-graph.d.ts +0 -0
  499. /package/{dist → lib}/data-structures/hash/coordinate-map.d.ts +0 -0
  500. /package/{dist → lib}/data-structures/hash/coordinate-set.d.ts +0 -0
  501. /package/{dist → lib}/data-structures/hash/hash-table.d.ts +0 -0
  502. /package/{dist → lib}/data-structures/hash/index.d.ts +0 -0
  503. /package/{dist → lib}/data-structures/hash/pair.d.ts +0 -0
  504. /package/{dist → lib}/data-structures/hash/tree-map.d.ts +0 -0
  505. /package/{dist → lib}/data-structures/hash/tree-set.d.ts +0 -0
  506. /package/{dist → lib}/data-structures/heap/heap.d.ts +0 -0
  507. /package/{dist → lib}/data-structures/heap/index.d.ts +0 -0
  508. /package/{dist → lib}/data-structures/heap/max-heap.d.ts +0 -0
  509. /package/{dist → lib}/data-structures/heap/min-heap.d.ts +0 -0
  510. /package/{dist → lib}/data-structures/index.d.ts +0 -0
  511. /package/{dist → lib}/data-structures/linked-list/index.d.ts +0 -0
  512. /package/{dist → lib}/data-structures/linked-list/skip-linked-list.d.ts +0 -0
  513. /package/{dist → lib}/data-structures/matrix/index.d.ts +0 -0
  514. /package/{dist → lib}/data-structures/matrix/matrix.d.ts +0 -0
  515. /package/{dist → lib}/data-structures/matrix/matrix2d.d.ts +0 -0
  516. /package/{dist → lib}/data-structures/matrix/navigator.d.ts +0 -0
  517. /package/{dist → lib}/data-structures/matrix/vector2d.d.ts +0 -0
  518. /package/{dist → lib}/data-structures/priority-queue/index.d.ts +0 -0
  519. /package/{dist → lib}/data-structures/priority-queue/max-priority-queue.d.ts +0 -0
  520. /package/{dist → lib}/data-structures/priority-queue/min-priority-queue.d.ts +0 -0
  521. /package/{dist → lib}/data-structures/priority-queue/priority-queue.d.ts +0 -0
  522. /package/{dist → lib}/data-structures/queue/index.d.ts +0 -0
  523. /package/{dist → lib}/data-structures/stack/index.d.ts +0 -0
  524. /package/{dist → lib}/data-structures/stack/stack.d.ts +0 -0
  525. /package/{dist → lib}/data-structures/tree/index.d.ts +0 -0
  526. /package/{dist → lib}/data-structures/tree/tree.d.ts +0 -0
  527. /package/{dist → lib}/data-structures/trie/index.d.ts +0 -0
  528. /package/{dist → lib}/data-structures/trie/trie.d.ts +0 -0
  529. /package/{dist → lib}/index.d.ts +0 -0
  530. /package/{dist → lib}/interfaces/abstract-binary-tree.d.ts +0 -0
  531. /package/{dist/interfaces/doubly-linked-list.d.ts → lib/interfaces/abstract-binary-tree.js} +0 -0
  532. /package/{dist → lib}/interfaces/abstract-graph.d.ts +0 -0
  533. /package/{dist/interfaces/heap.d.ts → lib/interfaces/abstract-graph.js} +0 -0
  534. /package/{dist/interfaces/navigator.d.ts → lib/interfaces/avl-tree.js} +0 -0
  535. /package/{dist/interfaces/priority-queue.d.ts → lib/interfaces/binary-tree.js} +0 -0
  536. /package/{dist/interfaces/segment-tree.d.ts → lib/interfaces/bst.js} +0 -0
  537. /package/{dist → lib}/interfaces/directed-graph.d.ts +0 -0
  538. /package/{dist/interfaces/singly-linked-list.d.ts → lib/interfaces/directed-graph.js} +0 -0
  539. /package/{dist/types/data-structures → lib/interfaces}/doubly-linked-list.d.ts +0 -0
  540. /package/{dist/types/data-structures/singly-linked-list.d.ts → lib/interfaces/doubly-linked-list.js} +0 -0
  541. /package/{dist/types/helpers.d.ts → lib/interfaces/heap.d.ts} +0 -0
  542. /package/{dist → lib}/interfaces/index.d.ts +0 -0
  543. /package/{dist → lib}/interfaces/undirected-graph.d.ts +0 -0
  544. /package/{dist → lib}/types/data-structures/abstract-graph.d.ts +0 -0
  545. /package/{dist → lib}/types/data-structures/binary-tree.d.ts +0 -0
  546. /package/{dist → lib}/types/data-structures/bst.d.ts +0 -0
  547. /package/{dist → lib}/types/data-structures/directed-graph.d.ts +0 -0
  548. /package/{dist → lib}/types/data-structures/heap.d.ts +0 -0
  549. /package/{dist → lib}/types/data-structures/index.d.ts +0 -0
  550. /package/{dist → lib}/types/data-structures/map-graph.d.ts +0 -0
  551. /package/{dist → lib}/types/data-structures/navigator.d.ts +0 -0
  552. /package/{dist → lib}/types/data-structures/priority-queue.d.ts +0 -0
  553. /package/{dist → lib}/types/data-structures/rb-tree.d.ts +0 -0
  554. /package/{dist → lib}/types/data-structures/segment-tree.d.ts +0 -0
  555. /package/{dist → lib}/types/data-structures/tree-multiset.d.ts +0 -0
  556. /package/{dist → lib}/types/index.d.ts +0 -0
  557. /package/{dist → lib}/types/utils/index.d.ts +0 -0
  558. /package/{dist → lib}/utils/index.d.ts +0 -0
  559. /package/{dist → lib}/utils/utils.d.ts +0 -0
  560. /package/{dist/bundle.js.LICENSE.txt → umd/bundle.min.js.LICENSE.txt} +0 -0
@@ -0,0 +1,443 @@
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
+ export class SinglyLinkedListNode {
9
+ /**
10
+ * The constructor function initializes an instance of a class with a given value and sets the next property to null.
11
+ * @param {T} val - The "val" parameter is of type T, which means it can be any data type. It represents the value that
12
+ * will be stored in the node of a linked list.
13
+ */
14
+ constructor(val) {
15
+ this._val = val;
16
+ this._next = null;
17
+ }
18
+ get val() {
19
+ return this._val;
20
+ }
21
+ set val(value) {
22
+ this._val = value;
23
+ }
24
+ get next() {
25
+ return this._next;
26
+ }
27
+ set next(value) {
28
+ this._next = value;
29
+ }
30
+ }
31
+ export class SinglyLinkedList {
32
+ /**
33
+ * The constructor initializes the linked list with an empty head, tail, and length.
34
+ */
35
+ constructor() {
36
+ this._head = null;
37
+ this._tail = null;
38
+ this._length = 0;
39
+ }
40
+ get head() {
41
+ return this._head;
42
+ }
43
+ set head(value) {
44
+ this._head = value;
45
+ }
46
+ get tail() {
47
+ return this._tail;
48
+ }
49
+ set tail(value) {
50
+ this._tail = value;
51
+ }
52
+ get length() {
53
+ return this._length;
54
+ }
55
+ /**
56
+ * The `fromArray` function creates a new SinglyLinkedList instance and populates it with the elements from the given
57
+ * array.
58
+ * @param {T[]} data - The `data` parameter is an array of elements of type `T`.
59
+ * @returns The `fromArray` function returns a `SinglyLinkedList` object.
60
+ */
61
+ static fromArray(data) {
62
+ const singlyLinkedList = new SinglyLinkedList();
63
+ for (const item of data) {
64
+ singlyLinkedList.push(item);
65
+ }
66
+ return singlyLinkedList;
67
+ }
68
+ getLength() {
69
+ return this._length;
70
+ }
71
+ /**
72
+ * The `push` function adds a new node with the given data to the end of a singly linked list.
73
+ * @param {T} data - The "data" parameter represents the value that you want to add to the linked list. It can be of
74
+ * any type (T) as specified in the generic type declaration of the class or function.
75
+ */
76
+ push(data) {
77
+ const newNode = new SinglyLinkedListNode(data);
78
+ if (!this.head) {
79
+ this.head = newNode;
80
+ this.tail = newNode;
81
+ }
82
+ else {
83
+ this.tail.next = newNode;
84
+ this.tail = newNode;
85
+ }
86
+ this._length++;
87
+ }
88
+ /**
89
+ * The `pop()` function removes and returns the value of the last element in a linked list, updating the head and tail
90
+ * pointers accordingly.
91
+ * @returns The method `pop()` returns the value of the node that is being removed from the end of the linked list. If
92
+ * the linked list is empty, it returns `null`.
93
+ */
94
+ pop() {
95
+ if (!this.head)
96
+ return undefined;
97
+ if (this.head === this.tail) {
98
+ const val = this.head.val;
99
+ this.head = null;
100
+ this.tail = null;
101
+ this._length--;
102
+ return val;
103
+ }
104
+ let current = this.head;
105
+ while (current.next !== this.tail) {
106
+ current = current.next;
107
+ }
108
+ const val = this.tail.val;
109
+ current.next = null;
110
+ this.tail = current;
111
+ this._length--;
112
+ return val;
113
+ }
114
+ /**
115
+ * The `shift()` function removes and returns the value of the first node in a linked list.
116
+ * @returns The value of the node that is being removed from the beginning of the linked list.
117
+ */
118
+ shift() {
119
+ if (!this.head)
120
+ return undefined;
121
+ const removedNode = this.head;
122
+ this.head = this.head.next;
123
+ this._length--;
124
+ return removedNode.val;
125
+ }
126
+ /**
127
+ * The unshift function adds a new node with the given value to the beginning of a singly linked list.
128
+ * @param {T} val - The parameter "val" represents the value of the new node that will be added to the beginning of the
129
+ * linked list.
130
+ */
131
+ unshift(val) {
132
+ const newNode = new SinglyLinkedListNode(val);
133
+ if (!this.head) {
134
+ this.head = newNode;
135
+ this.tail = newNode;
136
+ }
137
+ else {
138
+ newNode.next = this.head;
139
+ this.head = newNode;
140
+ }
141
+ this._length++;
142
+ }
143
+ /**
144
+ * The function `getAt` returns the value at a specified index in a linked list, or null if the index is out of range.
145
+ * @param {number} index - The index parameter is a number that represents the position of the element we want to
146
+ * retrieve from the list.
147
+ * @returns The method `getAt(index: number): T | null` returns the value at the specified index in the linked list, or
148
+ * `null` if the index is out of bounds.
149
+ */
150
+ getAt(index) {
151
+ if (index < 0 || index >= this.length)
152
+ return undefined;
153
+ let current = this.head;
154
+ for (let i = 0; i < index; i++) {
155
+ current = current.next;
156
+ }
157
+ return current.val;
158
+ }
159
+ /**
160
+ * The function `getNodeAt` returns the node at a given index in a singly linked list.
161
+ * @param {number} index - The `index` parameter is a number that represents the position of the node we want to
162
+ * retrieve from the linked list. It indicates the zero-based index of the node we want to access.
163
+ * @returns The method `getNodeAt(index: number)` returns a `SinglyLinkedListNode<T>` object if the node at the
164
+ * specified index exists, or `null` if the index is out of bounds.
165
+ */
166
+ getNodeAt(index) {
167
+ let current = this.head;
168
+ for (let i = 0; i < index; i++) {
169
+ current = current.next;
170
+ }
171
+ return current;
172
+ }
173
+ /**
174
+ * The `deleteAt` function removes an element at a specified index from a linked list and returns the removed element.
175
+ * @param {number} index - The index parameter represents the position of the element that needs to be deleted in the
176
+ * data structure. It is of type number.
177
+ * @returns The method `deleteAt` returns the value of the node that was deleted, or `null` if the index is out of
178
+ * bounds.
179
+ */
180
+ deleteAt(index) {
181
+ if (index < 0 || index >= this.length)
182
+ return undefined;
183
+ if (index === 0)
184
+ return this.shift();
185
+ if (index === this.length - 1)
186
+ return this.pop();
187
+ const prevNode = this.getNodeAt(index - 1);
188
+ const removedNode = prevNode.next;
189
+ prevNode.next = removedNode.next;
190
+ this._length--;
191
+ return removedNode.val;
192
+ }
193
+ /**
194
+ * The delete function removes a node with a specific value from a singly linked list.
195
+ * @param {T | SinglyLinkedListNode<T>} valueOrNode - The `valueOrNode` parameter can accept either a value of type `T`
196
+ * or a `SinglyLinkedListNode<T>` object.
197
+ * @returns The `delete` method returns a boolean value. It returns `true` if the value or node is found and
198
+ * successfully deleted from the linked list, and `false` if the value or node is not found in the linked list.
199
+ */
200
+ delete(valueOrNode) {
201
+ let value;
202
+ if (valueOrNode instanceof SinglyLinkedListNode) {
203
+ value = valueOrNode.val;
204
+ }
205
+ else {
206
+ value = valueOrNode;
207
+ }
208
+ let current = this.head, prev = null;
209
+ while (current) {
210
+ if (current.val === value) {
211
+ if (prev === null) {
212
+ this.head = current.next;
213
+ if (current === this.tail) {
214
+ this.tail = null;
215
+ }
216
+ }
217
+ else {
218
+ prev.next = current.next;
219
+ if (current === this.tail) {
220
+ this.tail = prev;
221
+ }
222
+ }
223
+ this._length--;
224
+ return true;
225
+ }
226
+ prev = current;
227
+ current = current.next;
228
+ }
229
+ return false;
230
+ }
231
+ /**
232
+ * The `insertAt` function inserts a value at a specified index in a singly linked list.
233
+ * @param {number} index - The index parameter represents the position at which the new value should be inserted in the
234
+ * linked list. It is of type number.
235
+ * @param {T} val - The `val` parameter represents the value that you want to insert into the linked list at the
236
+ * specified index.
237
+ * @returns The `insert` method returns a boolean value. It returns `true` if the insertion is successful, and `false`
238
+ * if the index is out of bounds.
239
+ */
240
+ insertAt(index, val) {
241
+ if (index < 0 || index > this.length)
242
+ return false;
243
+ if (index === 0) {
244
+ this.unshift(val);
245
+ return true;
246
+ }
247
+ if (index === this.length) {
248
+ this.push(val);
249
+ return true;
250
+ }
251
+ const newNode = new SinglyLinkedListNode(val);
252
+ const prevNode = this.getNodeAt(index - 1);
253
+ newNode.next = prevNode.next;
254
+ prevNode.next = newNode;
255
+ this._length++;
256
+ return true;
257
+ }
258
+ /**
259
+ * The function checks if the length of a data structure is equal to zero and returns a boolean value indicating
260
+ * whether it is empty or not.
261
+ * @returns A boolean value indicating whether the length of the object is equal to 0.
262
+ */
263
+ isEmpty() {
264
+ return this.length === 0;
265
+ }
266
+ /**
267
+ * The `clear` function resets the linked list by setting the head, tail, and length to null and 0 respectively.
268
+ */
269
+ clear() {
270
+ this._head = null;
271
+ this._tail = null;
272
+ this._length = 0;
273
+ }
274
+ /**
275
+ * The `toArray` function converts a linked list into an array.
276
+ * @returns The `toArray()` method is returning an array of type `T[]`.
277
+ */
278
+ toArray() {
279
+ const array = [];
280
+ let current = this.head;
281
+ while (current) {
282
+ array.push(current.val);
283
+ current = current.next;
284
+ }
285
+ return array;
286
+ }
287
+ /**
288
+ * The `reverse` function reverses the order of the nodes in a singly linked list.
289
+ * @returns The reverse() method does not return anything. It has a return type of void.
290
+ */
291
+ reverse() {
292
+ if (!this.head || this.head === this.tail)
293
+ return;
294
+ let prev = null;
295
+ let current = this.head;
296
+ let next = null;
297
+ while (current) {
298
+ next = current.next;
299
+ current.next = prev;
300
+ prev = current;
301
+ current = next;
302
+ }
303
+ [this.head, this.tail] = [this.tail, this.head];
304
+ }
305
+ /**
306
+ * The `find` function iterates through a linked list and returns the first element that satisfies a given condition.
307
+ * @param callback - A function that takes a value of type T as its parameter and returns a boolean value. This
308
+ * function is used to determine whether a particular value in the linked list satisfies a certain condition.
309
+ * @returns The method `find` returns the first element in the linked list that satisfies the condition specified by
310
+ * the callback function. If no element satisfies the condition, it returns `null`.
311
+ */
312
+ find(callback) {
313
+ let current = this.head;
314
+ while (current) {
315
+ if (callback(current.val)) {
316
+ return current.val;
317
+ }
318
+ current = current.next;
319
+ }
320
+ return null;
321
+ }
322
+ /**
323
+ * The `indexOf` function returns the index of the first occurrence of a given value in a linked list.
324
+ * @param {T} value - The value parameter is the value that you want to find the index of in the linked list.
325
+ * @returns The method is returning the index of the first occurrence of the specified value in the linked list. If the
326
+ * value is not found, it returns -1.
327
+ */
328
+ indexOf(value) {
329
+ let index = 0;
330
+ let current = this.head;
331
+ while (current) {
332
+ if (current.val === value) {
333
+ return index;
334
+ }
335
+ index++;
336
+ current = current.next;
337
+ }
338
+ return -1;
339
+ }
340
+ /**
341
+ * The function finds a node in a singly linked list by its value and returns the node if found, otherwise returns
342
+ * null.
343
+ * @param {T} value - The value parameter is the value that we want to search for in the linked list.
344
+ * @returns a `SinglyLinkedListNode<T>` if a node with the specified value is found in the linked list. If no node with
345
+ * the specified value is found, the function returns `null`.
346
+ */
347
+ findNode(value) {
348
+ let current = this.head;
349
+ while (current) {
350
+ if (current.val === value) {
351
+ return current;
352
+ }
353
+ current = current.next;
354
+ }
355
+ return null;
356
+ }
357
+ /**
358
+ * The `insertBefore` function inserts a new value before an existing value in a singly linked list.
359
+ * @param {T | SinglyLinkedListNode<T>} existingValueOrNode - The existing value or node that you want to insert the
360
+ * new value before. It can be either the value itself or a node containing the value in the linked list.
361
+ * @param {T} newValue - The `newValue` parameter represents the value that you want to insert into the linked list.
362
+ * @returns The method `insertBefore` returns a boolean value. It returns `true` if the new value was successfully
363
+ * inserted before the existing value, and `false` otherwise.
364
+ */
365
+ insertBefore(existingValueOrNode, newValue) {
366
+ if (!this.head)
367
+ return false;
368
+ let existingValue;
369
+ if (existingValueOrNode instanceof SinglyLinkedListNode) {
370
+ existingValue = existingValueOrNode.val;
371
+ }
372
+ else {
373
+ existingValue = existingValueOrNode;
374
+ }
375
+ if (this.head.val === existingValue) {
376
+ this.unshift(newValue);
377
+ return true;
378
+ }
379
+ let current = this.head;
380
+ while (current.next) {
381
+ if (current.next.val === existingValue) {
382
+ const newNode = new SinglyLinkedListNode(newValue);
383
+ newNode.next = current.next;
384
+ current.next = newNode;
385
+ this._length++;
386
+ return true;
387
+ }
388
+ current = current.next;
389
+ }
390
+ return false;
391
+ }
392
+ /**
393
+ * The `insertAfter` function inserts a new node with a given value after an existing node in a singly linked list.
394
+ * @param {T | SinglyLinkedListNode<T>} existingValueOrNode - The existing value or node in the linked list after which
395
+ * the new value will be inserted. It can be either the value of the existing node or the existing node itself.
396
+ * @param {T} newValue - The value that you want to insert into the linked list after the existing value or node.
397
+ * @returns The method returns a boolean value. It returns true if the new value was successfully inserted after the
398
+ * existing value or node, and false if the existing value or node was not found in the linked list.
399
+ */
400
+ insertAfter(existingValueOrNode, newValue) {
401
+ let existingNode;
402
+ if (existingValueOrNode instanceof SinglyLinkedListNode) {
403
+ existingNode = existingValueOrNode;
404
+ }
405
+ else {
406
+ existingNode = this.findNode(existingValueOrNode);
407
+ }
408
+ if (existingNode) {
409
+ const newNode = new SinglyLinkedListNode(newValue);
410
+ newNode.next = existingNode.next;
411
+ existingNode.next = newNode;
412
+ if (existingNode === this.tail) {
413
+ this.tail = newNode;
414
+ }
415
+ this._length++;
416
+ return true;
417
+ }
418
+ return false;
419
+ }
420
+ /**
421
+ * The function counts the number of occurrences of a given value in a linked list.
422
+ * @param {T} value - The value parameter is the value that you want to count the occurrences of in the linked list.
423
+ * @returns The count of occurrences of the given value in the linked list.
424
+ */
425
+ countOccurrences(value) {
426
+ let count = 0;
427
+ let current = this.head;
428
+ while (current) {
429
+ if (current.val === value) {
430
+ count++;
431
+ }
432
+ current = current.next;
433
+ }
434
+ return count;
435
+ }
436
+ *[Symbol.iterator]() {
437
+ let current = this.head;
438
+ while (current) {
439
+ yield current.val;
440
+ current = current.next;
441
+ }
442
+ }
443
+ }
@@ -0,0 +1,2 @@
1
+ export class SkipLinkedList {
2
+ }
@@ -0,0 +1,4 @@
1
+ export * from './matrix';
2
+ export * from './vector2d';
3
+ export * from './matrix2d';
4
+ export * from './navigator';
@@ -0,0 +1,24 @@
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
+ // todo need to be improved
9
+ export class MatrixNTI2D {
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
+ constructor(options) {
16
+ const { row, col, initialVal } = options;
17
+ this._matrix = new Array(row).fill(undefined).map(() => new Array(col).fill(initialVal || 0));
18
+ }
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
+ toArray() {
22
+ return this._matrix;
23
+ }
24
+ }
@@ -0,0 +1,195 @@
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 Vector2D from './vector2d';
9
+ export class Matrix2D {
10
+ /**
11
+ * The constructor function initializes a Matrix2D object with either a default identity matrix, or a provided matrix
12
+ * or Vector2D object.
13
+ * @param {number[][] | Vector2D} [value] - The `value` parameter can be either a 2D array of numbers (`number[][]`) or
14
+ * an instance of the `Vector2D` class.
15
+ */
16
+ constructor(value) {
17
+ if (typeof value === 'undefined') {
18
+ this._matrix = Matrix2D.identity;
19
+ }
20
+ else if (value instanceof Vector2D) {
21
+ this._matrix = Matrix2D.identity;
22
+ this._matrix[0][0] = value.x;
23
+ this._matrix[1][0] = value.y;
24
+ this._matrix[2][0] = value.w;
25
+ }
26
+ else {
27
+ this._matrix = value;
28
+ }
29
+ }
30
+ /**
31
+ * The function returns a 2D array with three empty arrays.
32
+ * @returns An empty 2-dimensional array with 3 empty arrays inside.
33
+ */
34
+ static get empty() {
35
+ return [[], [], []];
36
+ }
37
+ /**
38
+ * The above function returns a 3x3 identity matrix.
39
+ * @returns The method is returning a 2-dimensional array of numbers representing the identity matrix.
40
+ */
41
+ static get identity() {
42
+ return [
43
+ [1, 0, 0],
44
+ [0, 1, 0],
45
+ [0, 0, 1]
46
+ ];
47
+ }
48
+ /**
49
+ * The function returns a two-dimensional array of numbers.
50
+ * @returns The getter method is returning the value of the private variable `_matrix`, which is a two-dimensional
51
+ * array of numbers.
52
+ */
53
+ get m() {
54
+ return this._matrix;
55
+ }
56
+ /**
57
+ * The function "toVector" returns a new Vector2D object with the values from the first and second elements of the
58
+ * _matrix array.
59
+ * @returns A new instance of the Vector2D class is being returned. The values of the returned vector are taken from
60
+ * the first column of the matrix.
61
+ */
62
+ get toVector() {
63
+ return new Vector2D(this._matrix[0][0], this._matrix[1][0]);
64
+ }
65
+ /**
66
+ * The function takes two 2D matrices as input and returns their sum as a new 2D matrix.
67
+ * @param {Matrix2D} matrix1 - Matrix2D - The first matrix to be added.
68
+ * @param {Matrix2D} matrix2 - The parameter `matrix2` is a Matrix2D object.
69
+ * @returns a new instance of the Matrix2D class, which is created using the result array.
70
+ */
71
+ static add(matrix1, matrix2) {
72
+ const result = Matrix2D.empty;
73
+ for (let i = 0; i < 3; i++) {
74
+ for (let j = 0; j < 3; j++) {
75
+ result[i][j] = matrix1.m[i][j] + matrix2.m[i][j];
76
+ }
77
+ }
78
+ return new Matrix2D(result);
79
+ }
80
+ /**
81
+ * The function subtracts two 2D matrices and returns the result as a new Matrix2D object.
82
+ * @param {Matrix2D} matrix1 - Matrix2D - The first matrix to subtract from.
83
+ * @param {Matrix2D} matrix2 - Matrix2D is a class representing a 2D matrix. It has a property `m` which is a 2D array
84
+ * representing the matrix elements.
85
+ * @returns a new instance of the Matrix2D class, which is created using the result array.
86
+ */
87
+ static subtract(matrix1, matrix2) {
88
+ const result = Matrix2D.empty;
89
+ for (let i = 0; i < 3; i++) {
90
+ for (let j = 0; j < 3; j++) {
91
+ result[i][j] = matrix1.m[i][j] - matrix2.m[i][j];
92
+ }
93
+ }
94
+ return new Matrix2D(result);
95
+ }
96
+ /**
97
+ * The function multiplies two 2D matrices and returns the result as a new Matrix2D object.
98
+ * @param {Matrix2D} matrix1 - A 2D matrix represented by the Matrix2D class.
99
+ * @param {Matrix2D} matrix2 - The parameter `matrix2` is a 2D matrix of size 3x3.
100
+ * @returns a new instance of the Matrix2D class, created using the result array.
101
+ */
102
+ static multiply(matrix1, matrix2) {
103
+ const result = Matrix2D.empty;
104
+ for (let i = 0; i < 3; i++) {
105
+ for (let j = 0; j < 3; j++) {
106
+ result[i][j] = 0;
107
+ for (let k = 0; k < 3; k++) {
108
+ result[i][j] += matrix1.m[i][k] * matrix2.m[k][j];
109
+ }
110
+ }
111
+ }
112
+ return new Matrix2D(result);
113
+ }
114
+ /**
115
+ * The function multiplies each element of a 2D matrix by a given value and returns the resulting matrix.
116
+ * @param {Matrix2D} matrix - The `matrix` parameter is an instance of the `Matrix2D` class, which represents a 2D
117
+ * matrix. It contains a property `m` that is a 2D array representing the matrix elements.
118
+ * @param {number} value - The `value` parameter is a number that you want to multiply each element of the `matrix` by.
119
+ * @returns a new instance of the Matrix2D class, which is created using the result array.
120
+ */
121
+ static multiplyByValue(matrix, value) {
122
+ const result = Matrix2D.empty;
123
+ for (let i = 0; i < 3; i++) {
124
+ for (let j = 0; j < 3; j++) {
125
+ result[i][j] = matrix.m[i][j] * value;
126
+ }
127
+ }
128
+ return new Matrix2D(result);
129
+ }
130
+ /**
131
+ * The function multiplies a 2D matrix by a 2D vector and returns the result as a 2D vector.
132
+ * @param {Matrix2D} matrix - The parameter "matrix" is of type Matrix2D. It represents a 2-dimensional matrix.
133
+ * @param {Vector2D} vector - The "vector" parameter is a 2D vector, represented by an object of type Vector2D.
134
+ * @returns a Vector2D.
135
+ */
136
+ static multiplyByVector(matrix, vector) {
137
+ return Matrix2D.multiply(matrix, new Matrix2D(vector)).toVector;
138
+ }
139
+ /**
140
+ * The function returns a 2D matrix that scales and flips a vector around the center of a given width and height.
141
+ * @param {number} width - The width parameter represents the width of the view or the canvas. It is a number that
142
+ * specifies the width in pixels or any other unit of measurement.
143
+ * @param {number} height - The height parameter represents the height of the view or the canvas. It is used to
144
+ * calculate the centerY value, which is the vertical center of the view.
145
+ * @returns a Matrix2D object.
146
+ */
147
+ static view(width, height) {
148
+ const scaleStep = 1; // Scale every vector * scaleStep
149
+ const centerX = width / 2;
150
+ const centerY = height / 2;
151
+ const flipX = Math.cos(Math.PI); // rotate 180deg / 3.14radian around X-axis
152
+ return new Matrix2D([
153
+ [scaleStep, 0, centerX],
154
+ [0, flipX * scaleStep, centerY],
155
+ [0, 0, 1]
156
+ ]);
157
+ }
158
+ /**
159
+ * The function scales a matrix by a given factor.
160
+ * @param {number} factor - The factor parameter is a number that represents the scaling factor by which the matrix
161
+ * should be scaled.
162
+ * @returns the result of multiplying a new instance of Matrix2D by the given factor.
163
+ */
164
+ static scale(factor) {
165
+ return Matrix2D.multiplyByValue(new Matrix2D(), factor);
166
+ }
167
+ /**
168
+ * The function "rotate" takes an angle in radians and returns a 2D transformation matrix for rotating objects.
169
+ * @param {number} radians - The "radians" parameter is the angle in radians by which you want to rotate an object.
170
+ * @returns The code is returning a new instance of a Matrix2D object.
171
+ */
172
+ static rotate(radians) {
173
+ const cos = Math.cos(radians);
174
+ const sin = Math.sin(radians);
175
+ return new Matrix2D([
176
+ [cos, -sin, 0],
177
+ [sin, cos, 0],
178
+ [0, 0, 1]
179
+ ]);
180
+ }
181
+ /**
182
+ * The translate function takes a 2D vector and returns a 2D matrix that represents a translation transformation.
183
+ * @param {Vector2D} vector - The parameter "vector" is of type Vector2D. It represents a 2D vector with components x
184
+ * and y, and an optional w component.
185
+ * @returns The method is returning a new instance of the Matrix2D class.
186
+ */
187
+ static translate(vector) {
188
+ return new Matrix2D([
189
+ [1, 0, vector.x],
190
+ [0, 1, vector.y],
191
+ [0, 0, vector.w]
192
+ ]);
193
+ }
194
+ }
195
+ export default Matrix2D;