min-heap-typed 1.38.0 → 1.38.1

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 (334) hide show
  1. package/dist/data-structures/binary-tree/avl-tree.d.ts +100 -0
  2. package/dist/data-structures/binary-tree/avl-tree.js +341 -0
  3. package/dist/data-structures/binary-tree/binary-indexed-tree.d.ts +144 -0
  4. package/dist/data-structures/binary-tree/binary-indexed-tree.js +261 -0
  5. package/dist/data-structures/binary-tree/binary-tree.d.ts +409 -0
  6. package/dist/data-structures/binary-tree/binary-tree.js +1065 -0
  7. package/dist/data-structures/binary-tree/bst.d.ts +167 -0
  8. package/dist/data-structures/binary-tree/bst.js +512 -0
  9. package/dist/data-structures/binary-tree/index.d.ts +7 -0
  10. package/dist/data-structures/binary-tree/index.js +23 -0
  11. package/dist/data-structures/binary-tree/rb-tree.d.ts +13 -0
  12. package/dist/data-structures/binary-tree/rb-tree.js +27 -0
  13. package/dist/data-structures/binary-tree/segment-tree.d.ts +83 -0
  14. package/dist/data-structures/binary-tree/segment-tree.js +228 -0
  15. package/dist/data-structures/binary-tree/tree-multiset.d.ts +122 -0
  16. package/dist/data-structures/binary-tree/tree-multiset.js +351 -0
  17. package/dist/data-structures/graph/abstract-graph.d.ts +332 -0
  18. package/dist/data-structures/graph/abstract-graph.js +923 -0
  19. package/dist/data-structures/graph/directed-graph.d.ts +200 -0
  20. package/dist/data-structures/graph/directed-graph.js +422 -0
  21. package/dist/data-structures/graph/index.d.ts +4 -0
  22. package/dist/data-structures/graph/index.js +20 -0
  23. package/dist/data-structures/graph/map-graph.d.ts +79 -0
  24. package/dist/data-structures/graph/map-graph.js +111 -0
  25. package/dist/data-structures/graph/undirected-graph.d.ts +127 -0
  26. package/dist/data-structures/graph/undirected-graph.js +252 -0
  27. package/dist/data-structures/hash/coordinate-map.d.ts +45 -0
  28. package/dist/data-structures/hash/coordinate-map.js +65 -0
  29. package/dist/data-structures/hash/coordinate-set.d.ts +37 -0
  30. package/dist/data-structures/hash/coordinate-set.js +55 -0
  31. package/dist/data-structures/hash/hash-map.d.ts +56 -0
  32. package/dist/data-structures/hash/hash-map.js +171 -0
  33. package/dist/data-structures/hash/hash-table.d.ts +106 -0
  34. package/dist/data-structures/hash/hash-table.js +245 -0
  35. package/dist/data-structures/hash/index.d.ts +6 -0
  36. package/dist/data-structures/hash/index.js +22 -0
  37. package/dist/data-structures/hash/tree-map.d.ts +2 -0
  38. package/dist/data-structures/hash/tree-map.js +6 -0
  39. package/dist/data-structures/hash/tree-set.d.ts +2 -0
  40. package/dist/data-structures/hash/tree-set.js +6 -0
  41. package/dist/data-structures/heap/heap.d.ts +224 -0
  42. package/dist/data-structures/heap/heap.js +497 -0
  43. package/dist/data-structures/heap/index.d.ts +3 -0
  44. package/dist/data-structures/heap/index.js +19 -0
  45. package/dist/data-structures/heap/max-heap.d.ts +12 -0
  46. package/dist/data-structures/heap/max-heap.js +24 -0
  47. package/dist/data-structures/heap/min-heap.d.ts +12 -0
  48. package/dist/data-structures/heap/min-heap.js +24 -0
  49. package/dist/data-structures/index.d.ts +11 -0
  50. package/dist/data-structures/index.js +27 -0
  51. package/dist/data-structures/linked-list/doubly-linked-list.d.ts +234 -0
  52. package/dist/data-structures/linked-list/doubly-linked-list.js +583 -0
  53. package/dist/data-structures/linked-list/index.d.ts +3 -0
  54. package/dist/data-structures/linked-list/index.js +19 -0
  55. package/dist/data-structures/linked-list/singly-linked-list.d.ts +157 -0
  56. package/dist/data-structures/linked-list/singly-linked-list.js +448 -0
  57. package/dist/data-structures/linked-list/skip-linked-list.d.ts +61 -0
  58. package/dist/data-structures/linked-list/skip-linked-list.js +142 -0
  59. package/dist/data-structures/matrix/index.d.ts +4 -0
  60. package/dist/data-structures/matrix/index.js +20 -0
  61. package/dist/data-structures/matrix/matrix.d.ts +21 -0
  62. package/dist/data-structures/matrix/matrix.js +28 -0
  63. package/dist/data-structures/matrix/matrix2d.d.ts +108 -0
  64. package/dist/data-structures/matrix/matrix2d.js +203 -0
  65. package/dist/data-structures/matrix/navigator.d.ts +52 -0
  66. package/dist/data-structures/matrix/navigator.js +106 -0
  67. package/dist/data-structures/matrix/vector2d.d.ts +201 -0
  68. package/dist/data-structures/matrix/vector2d.js +291 -0
  69. package/dist/data-structures/priority-queue/index.d.ts +3 -0
  70. package/dist/data-structures/priority-queue/index.js +19 -0
  71. package/dist/data-structures/priority-queue/max-priority-queue.d.ts +12 -0
  72. package/dist/data-structures/priority-queue/max-priority-queue.js +24 -0
  73. package/dist/data-structures/priority-queue/min-priority-queue.d.ts +12 -0
  74. package/dist/data-structures/priority-queue/min-priority-queue.js +24 -0
  75. package/dist/data-structures/priority-queue/priority-queue.d.ts +12 -0
  76. package/dist/data-structures/priority-queue/priority-queue.js +17 -0
  77. package/dist/data-structures/queue/deque.d.ts +165 -0
  78. package/dist/data-structures/queue/deque.js +276 -0
  79. package/dist/data-structures/queue/index.d.ts +2 -0
  80. package/dist/data-structures/queue/index.js +18 -0
  81. package/dist/data-structures/queue/queue.d.ts +107 -0
  82. package/dist/data-structures/queue/queue.js +170 -0
  83. package/dist/data-structures/stack/index.d.ts +1 -0
  84. package/dist/data-structures/stack/index.js +17 -0
  85. package/dist/data-structures/stack/stack.d.ts +63 -0
  86. package/dist/data-structures/stack/stack.js +91 -0
  87. package/dist/data-structures/tree/index.d.ts +1 -0
  88. package/dist/data-structures/tree/index.js +17 -0
  89. package/dist/data-structures/tree/tree.d.ts +14 -0
  90. package/dist/data-structures/tree/tree.js +58 -0
  91. package/dist/data-structures/trie/index.d.ts +1 -0
  92. package/dist/data-structures/trie/index.js +17 -0
  93. package/dist/data-structures/trie/trie.d.ts +84 -0
  94. package/dist/data-structures/trie/trie.js +268 -0
  95. package/dist/index.d.ts +3 -3
  96. package/dist/index.js +3 -3
  97. package/dist/interfaces/binary-tree.d.ts +7 -0
  98. package/dist/interfaces/binary-tree.js +2 -0
  99. package/dist/interfaces/doubly-linked-list.d.ts +1 -0
  100. package/dist/interfaces/doubly-linked-list.js +2 -0
  101. package/dist/interfaces/graph.d.ts +5 -0
  102. package/dist/interfaces/graph.js +2 -0
  103. package/dist/interfaces/heap.d.ts +1 -0
  104. package/dist/interfaces/heap.js +2 -0
  105. package/dist/interfaces/index.d.ts +8 -0
  106. package/dist/interfaces/index.js +24 -0
  107. package/dist/interfaces/navigator.d.ts +1 -0
  108. package/dist/interfaces/navigator.js +2 -0
  109. package/dist/interfaces/priority-queue.d.ts +1 -0
  110. package/dist/interfaces/priority-queue.js +2 -0
  111. package/dist/interfaces/segment-tree.d.ts +1 -0
  112. package/dist/interfaces/segment-tree.js +2 -0
  113. package/dist/interfaces/singly-linked-list.d.ts +1 -0
  114. package/dist/interfaces/singly-linked-list.js +2 -0
  115. package/dist/types/data-structures/binary-tree/avl-tree.d.ts +4 -0
  116. package/dist/types/data-structures/binary-tree/avl-tree.js +2 -0
  117. package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +1 -0
  118. package/dist/types/data-structures/binary-tree/binary-indexed-tree.js +2 -0
  119. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +31 -0
  120. package/dist/types/data-structures/binary-tree/binary-tree.js +24 -0
  121. package/dist/types/data-structures/binary-tree/bst.d.ts +7 -0
  122. package/dist/types/data-structures/binary-tree/bst.js +2 -0
  123. package/dist/types/data-structures/binary-tree/index.d.ts +6 -0
  124. package/dist/types/data-structures/binary-tree/index.js +22 -0
  125. package/dist/types/data-structures/binary-tree/rb-tree.d.ts +8 -0
  126. package/dist/types/data-structures/binary-tree/rb-tree.js +8 -0
  127. package/dist/types/data-structures/binary-tree/segment-tree.d.ts +1 -0
  128. package/dist/types/data-structures/binary-tree/segment-tree.js +2 -0
  129. package/dist/types/data-structures/binary-tree/tree-multiset.d.ts +4 -0
  130. package/dist/types/data-structures/binary-tree/tree-multiset.js +2 -0
  131. package/dist/types/data-structures/graph/abstract-graph.d.ts +10 -0
  132. package/dist/types/data-structures/graph/abstract-graph.js +2 -0
  133. package/dist/types/data-structures/graph/directed-graph.d.ts +6 -0
  134. package/dist/types/data-structures/graph/directed-graph.js +9 -0
  135. package/dist/types/data-structures/graph/index.d.ts +3 -0
  136. package/dist/types/data-structures/graph/index.js +19 -0
  137. package/dist/types/data-structures/graph/map-graph.d.ts +1 -0
  138. package/dist/types/data-structures/graph/map-graph.js +2 -0
  139. package/dist/types/data-structures/graph/undirected-graph.d.ts +1 -0
  140. package/dist/types/data-structures/graph/undirected-graph.js +2 -0
  141. package/dist/types/data-structures/hash/coordinate-map.d.ts +1 -0
  142. package/dist/types/data-structures/hash/coordinate-map.js +2 -0
  143. package/dist/types/data-structures/hash/coordinate-set.d.ts +1 -0
  144. package/dist/types/data-structures/hash/coordinate-set.js +2 -0
  145. package/dist/types/data-structures/hash/hash-map.d.ts +1 -0
  146. package/dist/types/data-structures/hash/hash-map.js +2 -0
  147. package/dist/types/data-structures/hash/hash-table.d.ts +1 -0
  148. package/dist/types/data-structures/hash/hash-table.js +2 -0
  149. package/dist/types/data-structures/hash/index.d.ts +1 -0
  150. package/dist/types/data-structures/hash/index.js +2 -0
  151. package/dist/types/data-structures/hash/tree-map.d.ts +1 -0
  152. package/dist/types/data-structures/hash/tree-map.js +2 -0
  153. package/dist/types/data-structures/hash/tree-set.d.ts +1 -0
  154. package/dist/types/data-structures/hash/tree-set.js +2 -0
  155. package/dist/types/data-structures/heap/heap.d.ts +1 -0
  156. package/dist/types/data-structures/heap/heap.js +2 -0
  157. package/dist/types/data-structures/heap/index.d.ts +1 -0
  158. package/dist/types/data-structures/heap/index.js +17 -0
  159. package/dist/types/data-structures/heap/max-heap.d.ts +1 -0
  160. package/dist/types/data-structures/heap/max-heap.js +2 -0
  161. package/dist/types/data-structures/heap/min-heap.d.ts +1 -0
  162. package/dist/types/data-structures/heap/min-heap.js +2 -0
  163. package/dist/types/data-structures/index.d.ts +11 -0
  164. package/dist/types/data-structures/index.js +27 -0
  165. package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +1 -0
  166. package/dist/types/data-structures/linked-list/doubly-linked-list.js +2 -0
  167. package/dist/types/data-structures/linked-list/index.d.ts +2 -0
  168. package/dist/types/data-structures/linked-list/index.js +18 -0
  169. package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +1 -0
  170. package/dist/types/data-structures/linked-list/singly-linked-list.js +2 -0
  171. package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +1 -0
  172. package/dist/types/data-structures/linked-list/skip-linked-list.js +2 -0
  173. package/dist/types/data-structures/matrix/index.d.ts +1 -0
  174. package/dist/types/data-structures/matrix/index.js +17 -0
  175. package/dist/types/data-structures/matrix/matrix.d.ts +1 -0
  176. package/dist/types/data-structures/matrix/matrix.js +2 -0
  177. package/dist/types/data-structures/matrix/matrix2d.d.ts +1 -0
  178. package/dist/types/data-structures/matrix/matrix2d.js +2 -0
  179. package/dist/types/data-structures/matrix/navigator.d.ts +14 -0
  180. package/dist/types/data-structures/matrix/navigator.js +2 -0
  181. package/dist/types/data-structures/matrix/vector2d.d.ts +1 -0
  182. package/dist/types/data-structures/matrix/vector2d.js +2 -0
  183. package/dist/types/data-structures/priority-queue/index.d.ts +3 -0
  184. package/dist/types/data-structures/priority-queue/index.js +19 -0
  185. package/dist/types/data-structures/priority-queue/max-priority-queue.d.ts +1 -0
  186. package/dist/types/data-structures/priority-queue/max-priority-queue.js +2 -0
  187. package/dist/types/data-structures/priority-queue/min-priority-queue.d.ts +1 -0
  188. package/dist/types/data-structures/priority-queue/min-priority-queue.js +2 -0
  189. package/dist/types/data-structures/priority-queue/priority-queue.d.ts +1 -0
  190. package/dist/types/data-structures/priority-queue/priority-queue.js +2 -0
  191. package/dist/types/data-structures/queue/deque.d.ts +1 -0
  192. package/dist/types/data-structures/queue/deque.js +2 -0
  193. package/dist/types/data-structures/queue/index.d.ts +2 -0
  194. package/dist/types/data-structures/queue/index.js +18 -0
  195. package/dist/types/data-structures/queue/queue.d.ts +1 -0
  196. package/dist/types/data-structures/queue/queue.js +2 -0
  197. package/dist/types/data-structures/stack/index.d.ts +1 -0
  198. package/dist/types/data-structures/stack/index.js +17 -0
  199. package/dist/types/data-structures/stack/stack.d.ts +1 -0
  200. package/dist/types/data-structures/stack/stack.js +2 -0
  201. package/dist/types/data-structures/tree/index.d.ts +1 -0
  202. package/dist/types/data-structures/tree/index.js +17 -0
  203. package/dist/types/data-structures/tree/tree.d.ts +1 -0
  204. package/dist/types/data-structures/tree/tree.js +2 -0
  205. package/dist/types/data-structures/trie/index.d.ts +1 -0
  206. package/dist/types/data-structures/trie/index.js +17 -0
  207. package/dist/types/data-structures/trie/trie.d.ts +1 -0
  208. package/dist/types/data-structures/trie/trie.js +2 -0
  209. package/dist/types/helpers.d.ts +9 -0
  210. package/dist/types/helpers.js +9 -0
  211. package/dist/types/index.d.ts +3 -0
  212. package/dist/types/index.js +19 -0
  213. package/dist/types/utils/index.d.ts +2 -0
  214. package/dist/types/utils/index.js +18 -0
  215. package/dist/types/utils/utils.d.ts +7 -0
  216. package/dist/types/utils/utils.js +2 -0
  217. package/dist/types/utils/validate-type.d.ts +19 -0
  218. package/dist/types/utils/validate-type.js +2 -0
  219. package/dist/utils/index.d.ts +1 -0
  220. package/dist/utils/index.js +17 -0
  221. package/dist/utils/utils.d.ts +20 -0
  222. package/dist/utils/utils.js +73 -0
  223. package/package.json +1 -4
  224. package/src/data-structures/binary-tree/avl-tree.ts +342 -0
  225. package/src/data-structures/binary-tree/binary-indexed-tree.ts +298 -0
  226. package/src/data-structures/binary-tree/binary-tree.ts +1141 -0
  227. package/src/data-structures/binary-tree/bst.ts +529 -0
  228. package/src/data-structures/binary-tree/index.ts +7 -0
  229. package/src/data-structures/binary-tree/rb-tree.ts +366 -0
  230. package/src/data-structures/binary-tree/segment-tree.ts +257 -0
  231. package/src/data-structures/binary-tree/tree-multiset.ts +375 -0
  232. package/src/data-structures/graph/abstract-graph.ts +1044 -0
  233. package/src/data-structures/graph/directed-graph.ts +470 -0
  234. package/src/data-structures/graph/index.ts +4 -0
  235. package/src/data-structures/graph/map-graph.ts +134 -0
  236. package/src/data-structures/graph/undirected-graph.ts +274 -0
  237. package/src/data-structures/hash/coordinate-map.ts +67 -0
  238. package/src/data-structures/hash/coordinate-set.ts +56 -0
  239. package/src/data-structures/hash/hash-map.ts +209 -0
  240. package/src/data-structures/hash/hash-table.ts +280 -0
  241. package/src/data-structures/hash/index.ts +6 -0
  242. package/src/data-structures/hash/tree-map.ts +1 -0
  243. package/src/data-structures/hash/tree-set.ts +1 -0
  244. package/src/data-structures/heap/heap.ts +561 -0
  245. package/src/data-structures/heap/index.ts +3 -0
  246. package/src/data-structures/heap/max-heap.ts +24 -0
  247. package/src/data-structures/heap/min-heap.ts +24 -0
  248. package/src/data-structures/index.ts +11 -0
  249. package/src/data-structures/linked-list/doubly-linked-list.ts +636 -0
  250. package/src/data-structures/linked-list/index.ts +3 -0
  251. package/src/data-structures/linked-list/singly-linked-list.ts +501 -0
  252. package/src/data-structures/linked-list/skip-linked-list.ts +173 -0
  253. package/src/data-structures/matrix/index.ts +4 -0
  254. package/src/data-structures/matrix/matrix.ts +27 -0
  255. package/src/data-structures/matrix/matrix2d.ts +213 -0
  256. package/src/data-structures/matrix/navigator.ts +121 -0
  257. package/src/data-structures/matrix/vector2d.ts +316 -0
  258. package/src/data-structures/priority-queue/index.ts +3 -0
  259. package/src/data-structures/priority-queue/max-priority-queue.ts +23 -0
  260. package/src/data-structures/priority-queue/min-priority-queue.ts +23 -0
  261. package/src/data-structures/priority-queue/priority-queue.ts +16 -0
  262. package/src/data-structures/queue/deque.ts +297 -0
  263. package/src/data-structures/queue/index.ts +2 -0
  264. package/src/data-structures/queue/queue.ts +191 -0
  265. package/src/data-structures/stack/index.ts +1 -0
  266. package/src/data-structures/stack/stack.ts +98 -0
  267. package/src/data-structures/tree/index.ts +1 -0
  268. package/src/data-structures/tree/tree.ts +67 -0
  269. package/src/data-structures/trie/index.ts +1 -0
  270. package/src/data-structures/trie/trie.ts +286 -0
  271. package/src/index.ts +3 -3
  272. package/src/interfaces/binary-tree.ts +10 -0
  273. package/src/interfaces/doubly-linked-list.ts +1 -0
  274. package/src/interfaces/graph.ts +7 -0
  275. package/src/interfaces/heap.ts +1 -0
  276. package/src/interfaces/index.ts +8 -0
  277. package/src/interfaces/navigator.ts +1 -0
  278. package/src/interfaces/priority-queue.ts +1 -0
  279. package/src/interfaces/segment-tree.ts +1 -0
  280. package/src/interfaces/singly-linked-list.ts +1 -0
  281. package/src/types/data-structures/binary-tree/avl-tree.ts +5 -0
  282. package/src/types/data-structures/binary-tree/binary-indexed-tree.ts +1 -0
  283. package/src/types/data-structures/binary-tree/binary-tree.ts +35 -0
  284. package/src/types/data-structures/binary-tree/bst.ts +11 -0
  285. package/src/types/data-structures/binary-tree/index.ts +6 -0
  286. package/src/types/data-structures/binary-tree/rb-tree.ts +8 -0
  287. package/src/types/data-structures/binary-tree/segment-tree.ts +1 -0
  288. package/src/types/data-structures/binary-tree/tree-multiset.ts +6 -0
  289. package/src/types/data-structures/graph/abstract-graph.ts +11 -0
  290. package/src/types/data-structures/graph/directed-graph.ts +8 -0
  291. package/src/types/data-structures/graph/index.ts +3 -0
  292. package/src/types/data-structures/graph/map-graph.ts +1 -0
  293. package/src/types/data-structures/graph/undirected-graph.ts +1 -0
  294. package/src/types/data-structures/hash/coordinate-map.ts +1 -0
  295. package/src/types/data-structures/hash/coordinate-set.ts +1 -0
  296. package/src/types/data-structures/hash/hash-map.ts +1 -0
  297. package/src/types/data-structures/hash/hash-table.ts +1 -0
  298. package/src/types/data-structures/hash/index.ts +1 -0
  299. package/src/types/data-structures/hash/tree-map.ts +1 -0
  300. package/src/types/data-structures/hash/tree-set.ts +1 -0
  301. package/src/types/data-structures/heap/heap.ts +1 -0
  302. package/src/types/data-structures/heap/index.ts +1 -0
  303. package/src/types/data-structures/heap/max-heap.ts +1 -0
  304. package/src/types/data-structures/heap/min-heap.ts +1 -0
  305. package/src/types/data-structures/index.ts +11 -0
  306. package/src/types/data-structures/linked-list/doubly-linked-list.ts +1 -0
  307. package/src/types/data-structures/linked-list/index.ts +2 -0
  308. package/src/types/data-structures/linked-list/singly-linked-list.ts +1 -0
  309. package/src/types/data-structures/linked-list/skip-linked-list.ts +1 -0
  310. package/src/types/data-structures/matrix/index.ts +1 -0
  311. package/src/types/data-structures/matrix/matrix.ts +1 -0
  312. package/src/types/data-structures/matrix/matrix2d.ts +1 -0
  313. package/src/types/data-structures/matrix/navigator.ts +14 -0
  314. package/src/types/data-structures/matrix/vector2d.ts +1 -0
  315. package/src/types/data-structures/priority-queue/index.ts +3 -0
  316. package/src/types/data-structures/priority-queue/max-priority-queue.ts +1 -0
  317. package/src/types/data-structures/priority-queue/min-priority-queue.ts +1 -0
  318. package/src/types/data-structures/priority-queue/priority-queue.ts +1 -0
  319. package/src/types/data-structures/queue/deque.ts +1 -0
  320. package/src/types/data-structures/queue/index.ts +2 -0
  321. package/src/types/data-structures/queue/queue.ts +1 -0
  322. package/src/types/data-structures/stack/index.ts +1 -0
  323. package/src/types/data-structures/stack/stack.ts +1 -0
  324. package/src/types/data-structures/tree/index.ts +1 -0
  325. package/src/types/data-structures/tree/tree.ts +1 -0
  326. package/src/types/data-structures/trie/index.ts +1 -0
  327. package/src/types/data-structures/trie/trie.ts +1 -0
  328. package/src/types/helpers.ts +13 -0
  329. package/src/types/index.ts +3 -0
  330. package/src/types/utils/index.ts +2 -0
  331. package/src/types/utils/utils.ts +6 -0
  332. package/src/types/utils/validate-type.ts +35 -0
  333. package/src/utils/index.ts +1 -0
  334. package/src/utils/utils.ts +86 -0
@@ -0,0 +1,501 @@
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<E = any> {
9
+ /**
10
+ * The constructor function initializes an instance of a class with a given value and sets the next property to null.
11
+ * @param {E} val - The "val" parameter is of type E, 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: E) {
15
+ this._val = val;
16
+ this._next = null;
17
+ }
18
+
19
+ private _val: E;
20
+
21
+ get val(): E {
22
+ return this._val;
23
+ }
24
+
25
+ set val(value: E) {
26
+ this._val = value;
27
+ }
28
+
29
+ private _next: SinglyLinkedListNode<E> | null;
30
+
31
+ get next(): SinglyLinkedListNode<E> | null {
32
+ return this._next;
33
+ }
34
+
35
+ set next(value: SinglyLinkedListNode<E> | null) {
36
+ this._next = value;
37
+ }
38
+ }
39
+
40
+ export class SinglyLinkedList<E = any> {
41
+ /**
42
+ * The constructor initializes the linked list with an empty head, tail, and length.
43
+ */
44
+ constructor() {
45
+ this._head = null;
46
+ this._tail = null;
47
+ this._length = 0;
48
+ }
49
+
50
+ private _head: SinglyLinkedListNode<E> | null;
51
+
52
+ get head(): SinglyLinkedListNode<E> | null {
53
+ return this._head;
54
+ }
55
+
56
+ set head(value: SinglyLinkedListNode<E> | null) {
57
+ this._head = value;
58
+ }
59
+
60
+ private _tail: SinglyLinkedListNode<E> | null;
61
+
62
+ get tail(): SinglyLinkedListNode<E> | null {
63
+ return this._tail;
64
+ }
65
+
66
+ set tail(value: SinglyLinkedListNode<E> | null) {
67
+ this._tail = value;
68
+ }
69
+
70
+ private _length: number;
71
+
72
+ get length(): number {
73
+ return this._length;
74
+ }
75
+
76
+ /**
77
+ * The `fromArray` function creates a new SinglyLinkedList instance and populates it with the elements from the given
78
+ * array.
79
+ * @param {E[]} data - The `data` parameter is an array of elements of type `E`.
80
+ * @returns The `fromArray` function returns a `SinglyLinkedList` object.
81
+ */
82
+ static fromArray<E>(data: E[]) {
83
+ const singlyLinkedList = new SinglyLinkedList<E>();
84
+ for (const item of data) {
85
+ singlyLinkedList.push(item);
86
+ }
87
+ return singlyLinkedList;
88
+ }
89
+
90
+ getLength(): number {
91
+ return this._length;
92
+ }
93
+
94
+ /**
95
+ * The `push` function adds a new node with the given data to the end of a singly linked list.
96
+ * @param {E} data - The "data" parameter represents the value that you want to add to the linked list. It can be of
97
+ * any type (E) as specified in the generic type declaration of the class or function.
98
+ */
99
+ push(data: E): void {
100
+ const newNode = new SinglyLinkedListNode(data);
101
+ if (!this.head) {
102
+ this.head = newNode;
103
+ this.tail = newNode;
104
+ } else {
105
+ this.tail!.next = newNode;
106
+ this.tail = newNode;
107
+ }
108
+ this._length++;
109
+ }
110
+
111
+ /**
112
+ * The `pop()` function removes and returns the value of the last element in a linked list, updating the head and tail
113
+ * pointers accordingly.
114
+ * @returns The method `pop()` returns the value of the node that is being removed from the end of the linked list. If
115
+ * the linked list is empty, it returns `null`.
116
+ */
117
+ pop(): E | undefined {
118
+ if (!this.head) return undefined;
119
+ if (this.head === this.tail) {
120
+ const val = this.head.val;
121
+ this.head = null;
122
+ this.tail = null;
123
+ this._length--;
124
+ return val;
125
+ }
126
+
127
+ let current = this.head;
128
+ while (current.next !== this.tail) {
129
+ current = current.next!;
130
+ }
131
+ const val = this.tail!.val;
132
+ current.next = null;
133
+ this.tail = current;
134
+ this._length--;
135
+ return val;
136
+ }
137
+
138
+ /**
139
+ * The `shift()` function removes and returns the value of the first node in a linked list.
140
+ * @returns The value of the node that is being removed from the beginning of the linked list.
141
+ */
142
+ shift(): E | undefined {
143
+ if (!this.head) return undefined;
144
+ const removedNode = this.head;
145
+ this.head = this.head.next;
146
+ this._length--;
147
+ return removedNode.val;
148
+ }
149
+
150
+ /**
151
+ * The unshift function adds a new node with the given value to the beginning of a singly linked list.
152
+ * @param {E} val - The parameter "val" represents the value of the new node that will be added to the beginning of the
153
+ * linked list.
154
+ */
155
+ unshift(val: E): void {
156
+ const newNode = new SinglyLinkedListNode(val);
157
+ if (!this.head) {
158
+ this.head = newNode;
159
+ this.tail = newNode;
160
+ } else {
161
+ newNode.next = this.head;
162
+ this.head = newNode;
163
+ }
164
+ this._length++;
165
+ }
166
+
167
+ /**
168
+ * The function `getAt` returns the value at a specified index in a linked list, or null if the index is out of range.
169
+ * @param {number} index - The index parameter is a number that represents the position of the element we want to
170
+ * retrieve from the list.
171
+ * @returns The method `getAt(index: number): E | null` returns the value at the specified index in the linked list, or
172
+ * `null` if the index is out of bounds.
173
+ */
174
+ getAt(index: number): E | undefined {
175
+ if (index < 0 || index >= this.length) return undefined;
176
+ let current = this.head;
177
+ for (let i = 0; i < index; i++) {
178
+ current = current!.next;
179
+ }
180
+ return current!.val;
181
+ }
182
+
183
+ /**
184
+ * The function `getNodeAt` returns the node at a given index in a singly linked list.
185
+ * @param {number} index - The `index` parameter is a number that represents the position of the node we want to
186
+ * retrieve from the linked list. It indicates the zero-based index of the node we want to access.
187
+ * @returns The method `getNodeAt(index: number)` returns a `SinglyLinkedListNode<E>` object if the node at the
188
+ * specified index exists, or `null` if the index is out of bounds.
189
+ */
190
+ getNodeAt(index: number): SinglyLinkedListNode<E> | null {
191
+ let current = this.head;
192
+ for (let i = 0; i < index; i++) {
193
+ current = current!.next;
194
+ }
195
+ return current;
196
+ }
197
+
198
+ /**
199
+ * The `deleteAt` function removes an element at a specified index from a linked list and returns the removed element.
200
+ * @param {number} index - The index parameter represents the position of the element that needs to be deleted in the
201
+ * data structure. It is of type number.
202
+ * @returns The method `deleteAt` returns the value of the node that was deleted, or `null` if the index is out of
203
+ * bounds.
204
+ */
205
+ deleteAt(index: number): E | undefined {
206
+ if (index < 0 || index >= this.length) return undefined;
207
+ if (index === 0) return this.shift();
208
+ if (index === this.length - 1) return this.pop();
209
+
210
+ const prevNode = this.getNodeAt(index - 1);
211
+ const removedNode = prevNode!.next;
212
+ prevNode!.next = removedNode!.next;
213
+ this._length--;
214
+ return removedNode!.val;
215
+ }
216
+
217
+ delete(valueOrNode: E): boolean;
218
+ delete(valueOrNode: SinglyLinkedListNode<E>): boolean;
219
+
220
+ /**
221
+ * The delete function removes a node with a specific value from a singly linked list.
222
+ * @param {E | SinglyLinkedListNode<E>} valueOrNode - The `valueOrNode` parameter can accept either a value of type `E`
223
+ * or a `SinglyLinkedListNode<E>` object.
224
+ * @returns The `delete` method returns a boolean value. It returns `true` if the value or node is found and
225
+ * successfully deleted from the linked list, and `false` if the value or node is not found in the linked list.
226
+ */
227
+ delete(valueOrNode: E | SinglyLinkedListNode<E>): boolean {
228
+ let value: E;
229
+ if (valueOrNode instanceof SinglyLinkedListNode) {
230
+ value = valueOrNode.val;
231
+ } else {
232
+ value = valueOrNode;
233
+ }
234
+ let current = this.head,
235
+ prev = null;
236
+
237
+ while (current) {
238
+ if (current.val === value) {
239
+ if (prev === null) {
240
+ this.head = current.next;
241
+ if (current === this.tail) {
242
+ this.tail = null;
243
+ }
244
+ } else {
245
+ prev.next = current.next;
246
+ if (current === this.tail) {
247
+ this.tail = prev;
248
+ }
249
+ }
250
+ this._length--;
251
+ return true;
252
+ }
253
+ prev = current;
254
+ current = current.next;
255
+ }
256
+
257
+ return false;
258
+ }
259
+
260
+ /**
261
+ * The `insertAt` function inserts a value at a specified index in a singly linked list.
262
+ * @param {number} index - The index parameter represents the position at which the new value should be inserted in the
263
+ * linked list. It is of type number.
264
+ * @param {E} val - The `val` parameter represents the value that you want to insert into the linked list at the
265
+ * specified index.
266
+ * @returns The `insert` method returns a boolean value. It returns `true` if the insertion is successful, and `false`
267
+ * if the index is out of bounds.
268
+ */
269
+ insertAt(index: number, val: E): boolean {
270
+ if (index < 0 || index > this.length) return false;
271
+ if (index === 0) {
272
+ this.unshift(val);
273
+ return true;
274
+ }
275
+ if (index === this.length) {
276
+ this.push(val);
277
+ return true;
278
+ }
279
+
280
+ const newNode = new SinglyLinkedListNode(val);
281
+ const prevNode = this.getNodeAt(index - 1);
282
+ newNode.next = prevNode!.next;
283
+ prevNode!.next = newNode;
284
+ this._length++;
285
+ return true;
286
+ }
287
+
288
+ /**
289
+ * The function checks if the length of a data structure is equal to zero and returns a boolean value indicating
290
+ * whether it is empty or not.
291
+ * @returns A boolean value indicating whether the length of the object is equal to 0.
292
+ */
293
+ isEmpty(): boolean {
294
+ return this.length === 0;
295
+ }
296
+
297
+ /**
298
+ * The `clear` function resets the linked list by setting the head, tail, and length to null and 0 respectively.
299
+ */
300
+ clear(): void {
301
+ this._head = null;
302
+ this._tail = null;
303
+ this._length = 0;
304
+ }
305
+
306
+ /**
307
+ * The `toArray` function converts a linked list into an array.
308
+ * @returns The `toArray()` method is returning an array of type `E[]`.
309
+ */
310
+ toArray(): E[] {
311
+ const array: E[] = [];
312
+ let current = this.head;
313
+ while (current) {
314
+ array.push(current.val);
315
+ current = current.next;
316
+ }
317
+ return array;
318
+ }
319
+
320
+ /**
321
+ * The `reverse` function reverses the order of the nodes in a singly linked list.
322
+ * @returns The reverse() method does not return anything. It has a return type of void.
323
+ */
324
+ reverse(): void {
325
+ if (!this.head || this.head === this.tail) return;
326
+
327
+ let prev: SinglyLinkedListNode<E> | null = null;
328
+ let current: SinglyLinkedListNode<E> | null = this.head;
329
+ let next: SinglyLinkedListNode<E> | null = null;
330
+
331
+ while (current) {
332
+ next = current.next;
333
+ current.next = prev;
334
+ prev = current;
335
+ current = next;
336
+ }
337
+
338
+ [this.head, this.tail] = [this.tail!, this.head!];
339
+ }
340
+
341
+ /**
342
+ * The `find` function iterates through a linked list and returns the first element that satisfies a given condition.
343
+ * @param callback - A function that takes a value of type E as its parameter and returns a boolean value. This
344
+ * function is used to determine whether a particular value in the linked list satisfies a certain condition.
345
+ * @returns The method `find` returns the first element in the linked list that satisfies the condition specified by
346
+ * the callback function. If no element satisfies the condition, it returns `null`.
347
+ */
348
+ find(callback: (val: E) => boolean): E | null {
349
+ let current = this.head;
350
+ while (current) {
351
+ if (callback(current.val)) {
352
+ return current.val;
353
+ }
354
+ current = current.next;
355
+ }
356
+ return null;
357
+ }
358
+
359
+ /**
360
+ * The `indexOf` function returns the index of the first occurrence of a given value in a linked list.
361
+ * @param {E} value - The value parameter is the value that you want to find the index of in the linked list.
362
+ * @returns The method is returning the index of the first occurrence of the specified value in the linked list. If the
363
+ * value is not found, it returns -1.
364
+ */
365
+ indexOf(value: E): number {
366
+ let index = 0;
367
+ let current = this.head;
368
+
369
+ while (current) {
370
+ if (current.val === value) {
371
+ return index;
372
+ }
373
+ index++;
374
+ current = current.next;
375
+ }
376
+
377
+ return -1;
378
+ }
379
+
380
+ /**
381
+ * The function finds a node in a singly linked list by its value and returns the node if found, otherwise returns
382
+ * null.
383
+ * @param {E} value - The value parameter is the value that we want to search for in the linked list.
384
+ * @returns a `SinglyLinkedListNode<E>` if a node with the specified value is found in the linked list. If no node with
385
+ * the specified value is found, the function returns `null`.
386
+ */
387
+ findNode(value: E): SinglyLinkedListNode<E> | null {
388
+ let current = this.head;
389
+
390
+ while (current) {
391
+ if (current.val === value) {
392
+ return current;
393
+ }
394
+ current = current.next;
395
+ }
396
+
397
+ return null;
398
+ }
399
+
400
+ insertBefore(existingValue: E, newValue: E): boolean;
401
+ insertBefore(existingValue: SinglyLinkedListNode<E>, newValue: E): boolean;
402
+
403
+ /**
404
+ * The `insertBefore` function inserts a new value before an existing value in a singly linked list.
405
+ * @param {E | SinglyLinkedListNode<E>} existingValueOrNode - The existing value or node that you want to insert the
406
+ * new value before. It can be either the value itself or a node containing the value in the linked list.
407
+ * @param {E} newValue - The `newValue` parameter represents the value that you want to insert into the linked list.
408
+ * @returns The method `insertBefore` returns a boolean value. It returns `true` if the new value was successfully
409
+ * inserted before the existing value, and `false` otherwise.
410
+ */
411
+ insertBefore(existingValueOrNode: E | SinglyLinkedListNode<E>, newValue: E): boolean {
412
+ if (!this.head) return false;
413
+
414
+ let existingValue: E;
415
+ if (existingValueOrNode instanceof SinglyLinkedListNode) {
416
+ existingValue = existingValueOrNode.val;
417
+ } else {
418
+ existingValue = existingValueOrNode;
419
+ }
420
+ if (this.head.val === existingValue) {
421
+ this.unshift(newValue);
422
+ return true;
423
+ }
424
+
425
+ let current = this.head;
426
+ while (current.next) {
427
+ if (current.next.val === existingValue) {
428
+ const newNode = new SinglyLinkedListNode(newValue);
429
+ newNode.next = current.next;
430
+ current.next = newNode;
431
+ this._length++;
432
+ return true;
433
+ }
434
+ current = current.next;
435
+ }
436
+
437
+ return false;
438
+ }
439
+
440
+ insertAfter(existingValueOrNode: E, newValue: E): boolean;
441
+ insertAfter(existingValueOrNode: SinglyLinkedListNode<E>, newValue: E): boolean;
442
+
443
+ /**
444
+ * The `insertAfter` function inserts a new node with a given value after an existing node in a singly linked list.
445
+ * @param {E | SinglyLinkedListNode<E>} existingValueOrNode - The existing value or node in the linked list after which
446
+ * the new value will be inserted. It can be either the value of the existing node or the existing node itself.
447
+ * @param {E} newValue - The value that you want to insert into the linked list after the existing value or node.
448
+ * @returns The method returns a boolean value. It returns true if the new value was successfully inserted after the
449
+ * existing value or node, and false if the existing value or node was not found in the linked list.
450
+ */
451
+ insertAfter(existingValueOrNode: E | SinglyLinkedListNode<E>, newValue: E): boolean {
452
+ let existingNode: E | SinglyLinkedListNode<E> | null;
453
+
454
+ if (existingValueOrNode instanceof SinglyLinkedListNode) {
455
+ existingNode = existingValueOrNode;
456
+ } else {
457
+ existingNode = this.findNode(existingValueOrNode);
458
+ }
459
+
460
+ if (existingNode) {
461
+ const newNode = new SinglyLinkedListNode(newValue);
462
+ newNode.next = existingNode.next;
463
+ existingNode.next = newNode;
464
+ if (existingNode === this.tail) {
465
+ this.tail = newNode;
466
+ }
467
+ this._length++;
468
+ return true;
469
+ }
470
+
471
+ return false;
472
+ }
473
+
474
+ /**
475
+ * The function counts the number of occurrences of a given value in a linked list.
476
+ * @param {E} value - The value parameter is the value that you want to count the occurrences of in the linked list.
477
+ * @returns The count of occurrences of the given value in the linked list.
478
+ */
479
+ countOccurrences(value: E): number {
480
+ let count = 0;
481
+ let current = this.head;
482
+
483
+ while (current) {
484
+ if (current.val === value) {
485
+ count++;
486
+ }
487
+ current = current.next;
488
+ }
489
+
490
+ return count;
491
+ }
492
+
493
+ *[Symbol.iterator]() {
494
+ let current = this.head;
495
+
496
+ while (current) {
497
+ yield current.val;
498
+ current = current.next;
499
+ }
500
+ }
501
+ }
@@ -0,0 +1,173 @@
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
+
9
+ export class SkipListNode<K, V> {
10
+ key: K;
11
+ value: V;
12
+ forward: SkipListNode<K, V>[];
13
+
14
+ constructor(key: K, value: V, level: number) {
15
+ this.key = key;
16
+ this.value = value;
17
+ this.forward = new Array(level);
18
+ }
19
+ }
20
+
21
+ export class SkipList<K, V> {
22
+ /**
23
+ * The constructor initializes a SkipList with a specified maximum level and probability.
24
+ * @param [maxLevel=16] - The `maxLevel` parameter represents the maximum level that a skip list can have. It determines
25
+ * the maximum number of levels that can be created in the skip list.
26
+ * @param [probability=0.5] - The probability parameter represents the probability of a node being promoted to a higher
27
+ * level in the skip list. It is used to determine the height of each node in the skip list.
28
+ */
29
+ constructor(maxLevel = 16, probability = 0.5) {
30
+ this._head = new SkipListNode<K, V>(null as any, null as any, maxLevel);
31
+ this._level = 0;
32
+ this._maxLevel = maxLevel;
33
+ this._probability = probability;
34
+ }
35
+
36
+ private _head: SkipListNode<K, V>;
37
+
38
+ get head(): SkipListNode<K, V> {
39
+ return this._head;
40
+ }
41
+
42
+ set head(value: SkipListNode<K, V>) {
43
+ this._head = value;
44
+ }
45
+
46
+ private _level: number;
47
+
48
+ get level(): number {
49
+ return this._level;
50
+ }
51
+
52
+ set level(value: number) {
53
+ this._level = value;
54
+ }
55
+
56
+ private _maxLevel: number;
57
+
58
+ get maxLevel(): number {
59
+ return this._maxLevel;
60
+ }
61
+
62
+ set maxLevel(value: number) {
63
+ this._maxLevel = value;
64
+ }
65
+
66
+ private _probability: number;
67
+
68
+ get probability(): number {
69
+ return this._probability;
70
+ }
71
+
72
+ set probability(value: number) {
73
+ this._probability = value;
74
+ }
75
+
76
+ /**
77
+ * The add function adds a new node with a given key and value to a Skip List data structure.
78
+ * @param {K} key - The key parameter represents the key of the node that needs to be added to the skip list.
79
+ * @param {V} value - The "value" parameter represents the value associated with the key that is being added to the Skip
80
+ * List.
81
+ */
82
+ add(key: K, value: V): void {
83
+ const newNode = new SkipListNode(key, value, this.randomLevel());
84
+ const update: SkipListNode<K, V>[] = new Array(this.maxLevel).fill(this.head);
85
+ let current = this.head;
86
+
87
+ for (let i = this.level - 1; i >= 0; i--) {
88
+ while (current.forward[i] && current.forward[i].key < key) {
89
+ current = current.forward[i];
90
+ }
91
+ update[i] = current;
92
+ }
93
+
94
+ for (let i = 0; i < newNode.forward.length; i++) {
95
+ newNode.forward[i] = update[i].forward[i];
96
+ update[i].forward[i] = newNode;
97
+ }
98
+
99
+ if (newNode.forward[0] !== null) {
100
+ this.level = Math.max(this.level, newNode.forward.length);
101
+ }
102
+ }
103
+
104
+ /**
105
+ * The function `get` retrieves the value associated with a given key from a skip list data structure.
106
+ * @param {K} key - The `key` parameter is the key of the element that we want to retrieve from the data structure.
107
+ * @returns The method `get(key: K)` returns the value associated with the given key if it exists in the data structure,
108
+ * otherwise it returns `undefined`.
109
+ */
110
+ get(key: K): V | undefined {
111
+ let current = this.head;
112
+ for (let i = this.level - 1; i >= 0; i--) {
113
+ while (current.forward[i] && current.forward[i].key < key) {
114
+ current = current.forward[i];
115
+ }
116
+ }
117
+
118
+ current = current.forward[0];
119
+
120
+ if (current && current.key === key) {
121
+ return current.value;
122
+ }
123
+
124
+ return undefined;
125
+ }
126
+
127
+ /**
128
+ * The `delete` function removes a node with a specific key from a Skip List data structure.
129
+ * @param {K} key - The key parameter represents the key of the node that needs to be removed from the skip list.
130
+ * @returns The `delete` method returns a boolean value. It returns `true` if the key was successfully removed from the
131
+ * skip list, and `false` if the key was not found in the skip list.
132
+ */
133
+ delete(key: K): boolean {
134
+ const update: SkipListNode<K, V>[] = new Array(this.maxLevel).fill(this.head);
135
+ let current = this.head;
136
+
137
+ for (let i = this.level - 1; i >= 0; i--) {
138
+ while (current.forward[i] && current.forward[i].key < key) {
139
+ current = current.forward[i];
140
+ }
141
+ update[i] = current;
142
+ }
143
+
144
+ current = current.forward[0];
145
+
146
+ if (current && current.key === key) {
147
+ for (let i = 0; i < this.level; i++) {
148
+ if (update[i].forward[i] !== current) {
149
+ break;
150
+ }
151
+ update[i].forward[i] = current.forward[i];
152
+ }
153
+ while (this.level > 0 && this.head.forward[this.level - 1] === null) {
154
+ this.level--;
155
+ }
156
+ return true;
157
+ }
158
+
159
+ return false;
160
+ }
161
+
162
+ /**
163
+ * The function "randomLevel" generates a random level based on a given probability and maximum level.
164
+ * @returns the level, which is a number.
165
+ */
166
+ private randomLevel(): number {
167
+ let level = 1;
168
+ while (Math.random() < this.probability && level < this.maxLevel) {
169
+ level++;
170
+ }
171
+ return level;
172
+ }
173
+ }
@@ -0,0 +1,4 @@
1
+ export * from './matrix';
2
+ export * from './vector2d';
3
+ export * from './matrix2d';
4
+ export * from './navigator';
@@ -0,0 +1,27 @@
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<V = any> {
10
+ private readonly _matrix: Array<Array<V>>;
11
+
12
+ /**
13
+ * The constructor creates a matrix with the specified number of rows and columns, and initializes all elements to a
14
+ * given initial value or 0 if not provided.
15
+ * @param options - An object containing the following properties:
16
+ */
17
+ constructor(options: {row: number; col: number; initialVal?: V}) {
18
+ const {row, col, initialVal} = options;
19
+ this._matrix = new Array(row).fill(undefined).map(() => new Array(col).fill(initialVal || 0));
20
+ }
21
+
22
+ /* The `toArray` method returns the matrix as a two-dimensional array. It converts the internal representation of the
23
+ matrix, which is an array of arrays, into a format that is more commonly used in JavaScript. */
24
+ toArray(): Array<Array<V>> {
25
+ return this._matrix;
26
+ }
27
+ }