data-structure-typed 1.40.0-rc → 1.40.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 (1065) hide show
  1. package/.eslintrc.js +7 -5
  2. package/.github/workflows/ci.yml +2 -20
  3. package/.travis.yml +3 -4
  4. package/CHANGELOG.md +22 -1
  5. package/CONTRIBUTING.md +13 -0
  6. package/README.md +20 -11
  7. package/dist/cjs/data-structures/binary-tree/avl-tree.d.ts +106 -0
  8. package/dist/cjs/data-structures/binary-tree/avl-tree.js +348 -0
  9. package/dist/cjs/data-structures/binary-tree/avl-tree.js.map +1 -0
  10. package/dist/cjs/data-structures/binary-tree/binary-indexed-tree.d.ts +149 -0
  11. package/dist/cjs/data-structures/binary-tree/binary-indexed-tree.js +270 -0
  12. package/dist/cjs/data-structures/binary-tree/binary-indexed-tree.js.map +1 -0
  13. package/dist/cjs/data-structures/binary-tree/binary-tree.d.ts +355 -0
  14. package/dist/cjs/data-structures/binary-tree/binary-tree.js +1116 -0
  15. package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -0
  16. package/dist/cjs/data-structures/binary-tree/bst.d.ts +167 -0
  17. package/dist/cjs/data-structures/binary-tree/bst.js +513 -0
  18. package/dist/cjs/data-structures/binary-tree/bst.js.map +1 -0
  19. package/dist/cjs/data-structures/binary-tree/index.d.ts +7 -0
  20. package/dist/cjs/data-structures/binary-tree/index.js +24 -0
  21. package/dist/cjs/data-structures/binary-tree/index.js.map +1 -0
  22. package/dist/cjs/data-structures/binary-tree/rb-tree.d.ts +11 -0
  23. package/dist/cjs/data-structures/binary-tree/rb-tree.js +22 -0
  24. package/dist/cjs/data-structures/binary-tree/rb-tree.js.map +1 -0
  25. package/dist/cjs/data-structures/binary-tree/segment-tree.d.ts +67 -0
  26. package/dist/cjs/data-structures/binary-tree/segment-tree.js +181 -0
  27. package/dist/cjs/data-structures/binary-tree/segment-tree.js.map +1 -0
  28. package/dist/cjs/data-structures/binary-tree/tree-multiset.d.ts +126 -0
  29. package/dist/cjs/data-structures/binary-tree/tree-multiset.js +356 -0
  30. package/dist/cjs/data-structures/binary-tree/tree-multiset.js.map +1 -0
  31. package/dist/cjs/data-structures/graph/abstract-graph.d.ts +313 -0
  32. package/dist/cjs/data-structures/graph/abstract-graph.js +885 -0
  33. package/dist/cjs/data-structures/graph/abstract-graph.js.map +1 -0
  34. package/dist/cjs/data-structures/graph/directed-graph.d.ts +194 -0
  35. package/dist/cjs/data-structures/graph/directed-graph.js +405 -0
  36. package/dist/cjs/data-structures/graph/directed-graph.js.map +1 -0
  37. package/dist/cjs/data-structures/graph/index.js.map +1 -0
  38. package/dist/cjs/data-structures/graph/map-graph.d.ts +73 -0
  39. package/dist/cjs/data-structures/graph/map-graph.js +94 -0
  40. package/dist/cjs/data-structures/graph/map-graph.js.map +1 -0
  41. package/dist/cjs/data-structures/graph/undirected-graph.d.ts +120 -0
  42. package/dist/cjs/data-structures/graph/undirected-graph.js +240 -0
  43. package/dist/cjs/data-structures/graph/undirected-graph.js.map +1 -0
  44. package/dist/cjs/data-structures/hash/coordinate-map.d.ts +44 -0
  45. package/dist/cjs/data-structures/hash/coordinate-map.js +63 -0
  46. package/dist/cjs/data-structures/hash/coordinate-map.js.map +1 -0
  47. package/dist/cjs/data-structures/hash/coordinate-set.d.ts +36 -0
  48. package/dist/cjs/data-structures/hash/coordinate-set.js +53 -0
  49. package/dist/cjs/data-structures/hash/coordinate-set.js.map +1 -0
  50. package/dist/cjs/data-structures/hash/hash-map.d.ts +50 -0
  51. package/dist/cjs/data-structures/hash/hash-map.js +154 -0
  52. package/dist/cjs/data-structures/hash/hash-map.js.map +1 -0
  53. package/dist/cjs/data-structures/hash/hash-table.d.ts +103 -0
  54. package/dist/cjs/data-structures/hash/hash-table.js +237 -0
  55. package/dist/cjs/data-structures/hash/hash-table.js.map +1 -0
  56. package/dist/cjs/data-structures/hash/index.d.ts +6 -0
  57. package/dist/cjs/data-structures/hash/index.js +23 -0
  58. package/dist/cjs/data-structures/hash/index.js.map +1 -0
  59. package/dist/cjs/data-structures/hash/tree-map.js.map +1 -0
  60. package/dist/cjs/data-structures/hash/tree-set.js.map +1 -0
  61. package/dist/cjs/data-structures/heap/heap.d.ts +235 -0
  62. package/dist/cjs/data-structures/heap/heap.js +516 -0
  63. package/dist/cjs/data-structures/heap/heap.js.map +1 -0
  64. package/dist/cjs/data-structures/heap/index.js.map +1 -0
  65. package/dist/cjs/data-structures/heap/max-heap.d.ts +15 -0
  66. package/dist/cjs/data-structures/heap/max-heap.js +27 -0
  67. package/dist/cjs/data-structures/heap/max-heap.js.map +1 -0
  68. package/dist/cjs/data-structures/heap/min-heap.d.ts +15 -0
  69. package/dist/cjs/data-structures/heap/min-heap.js +27 -0
  70. package/dist/cjs/data-structures/heap/min-heap.js.map +1 -0
  71. package/dist/cjs/data-structures/index.js.map +1 -0
  72. package/dist/cjs/data-structures/linked-list/doubly-linked-list.d.ts +253 -0
  73. package/dist/cjs/data-structures/linked-list/doubly-linked-list.js +570 -0
  74. package/dist/cjs/data-structures/linked-list/doubly-linked-list.js.map +1 -0
  75. package/dist/cjs/data-structures/linked-list/index.js.map +1 -0
  76. package/dist/cjs/data-structures/linked-list/singly-linked-list.d.ts +232 -0
  77. package/dist/cjs/data-structures/linked-list/singly-linked-list.js +534 -0
  78. package/dist/cjs/data-structures/linked-list/singly-linked-list.js.map +1 -0
  79. package/dist/cjs/data-structures/linked-list/skip-linked-list.d.ts +80 -0
  80. package/dist/cjs/data-structures/linked-list/skip-linked-list.js +188 -0
  81. package/dist/cjs/data-structures/linked-list/skip-linked-list.js.map +1 -0
  82. package/dist/cjs/data-structures/matrix/index.js.map +1 -0
  83. package/dist/cjs/data-structures/matrix/matrix.d.ts +21 -0
  84. package/dist/cjs/data-structures/matrix/matrix.js.map +1 -0
  85. package/dist/cjs/data-structures/matrix/matrix2d.d.ts +107 -0
  86. package/dist/cjs/data-structures/matrix/matrix2d.js +200 -0
  87. package/dist/cjs/data-structures/matrix/matrix2d.js.map +1 -0
  88. package/dist/cjs/data-structures/matrix/navigator.d.ts +52 -0
  89. package/dist/cjs/data-structures/matrix/navigator.js.map +1 -0
  90. package/dist/cjs/data-structures/matrix/vector2d.d.ts +200 -0
  91. package/dist/cjs/data-structures/matrix/vector2d.js +291 -0
  92. package/dist/cjs/data-structures/matrix/vector2d.js.map +1 -0
  93. package/dist/cjs/data-structures/priority-queue/index.js.map +1 -0
  94. package/dist/cjs/data-structures/priority-queue/max-priority-queue.d.ts +15 -0
  95. package/dist/cjs/data-structures/priority-queue/max-priority-queue.js +27 -0
  96. package/dist/cjs/data-structures/priority-queue/max-priority-queue.js.map +1 -0
  97. package/dist/cjs/data-structures/priority-queue/min-priority-queue.d.ts +15 -0
  98. package/dist/cjs/data-structures/priority-queue/min-priority-queue.js +27 -0
  99. package/dist/cjs/data-structures/priority-queue/min-priority-queue.js.map +1 -0
  100. package/dist/cjs/data-structures/priority-queue/priority-queue.d.ts +15 -0
  101. package/dist/cjs/data-structures/priority-queue/priority-queue.js +18 -0
  102. package/dist/cjs/data-structures/priority-queue/priority-queue.js.map +1 -0
  103. package/dist/cjs/data-structures/queue/deque.d.ts +161 -0
  104. package/dist/cjs/data-structures/queue/deque.js +265 -0
  105. package/dist/cjs/data-structures/queue/deque.js.map +1 -0
  106. package/dist/cjs/data-structures/queue/index.js.map +1 -0
  107. package/dist/cjs/data-structures/queue/queue.d.ts +122 -0
  108. package/dist/cjs/data-structures/queue/queue.js +188 -0
  109. package/dist/cjs/data-structures/queue/queue.js.map +1 -0
  110. package/dist/cjs/data-structures/stack/index.js.map +1 -0
  111. package/dist/cjs/data-structures/stack/stack.d.ts +64 -0
  112. package/dist/cjs/data-structures/stack/stack.js +95 -0
  113. package/dist/cjs/data-structures/stack/stack.js.map +1 -0
  114. package/dist/cjs/data-structures/tree/index.js.map +1 -0
  115. package/dist/cjs/data-structures/tree/tree.d.ts +8 -0
  116. package/dist/cjs/data-structures/tree/tree.js +41 -0
  117. package/dist/cjs/data-structures/tree/tree.js.map +1 -0
  118. package/dist/cjs/data-structures/trie/index.js.map +1 -0
  119. package/dist/cjs/data-structures/trie/trie.d.ts +79 -0
  120. package/dist/cjs/data-structures/trie/trie.js +252 -0
  121. package/dist/cjs/data-structures/trie/trie.js.map +1 -0
  122. package/dist/cjs/index.js.map +1 -0
  123. package/dist/cjs/interfaces/binary-tree.d.ts +7 -0
  124. package/dist/cjs/interfaces/binary-tree.js.map +1 -0
  125. package/dist/cjs/interfaces/doubly-linked-list.js.map +1 -0
  126. package/dist/cjs/interfaces/graph.d.ts +5 -0
  127. package/dist/cjs/interfaces/graph.js +3 -0
  128. package/dist/cjs/interfaces/graph.js.map +1 -0
  129. package/dist/cjs/interfaces/heap.js.map +1 -0
  130. package/dist/cjs/interfaces/index.d.ts +8 -0
  131. package/dist/cjs/interfaces/index.js +25 -0
  132. package/dist/cjs/interfaces/index.js.map +1 -0
  133. package/dist/cjs/interfaces/navigator.js.map +1 -0
  134. package/dist/cjs/interfaces/priority-queue.js.map +1 -0
  135. package/dist/cjs/interfaces/segment-tree.js.map +1 -0
  136. package/dist/cjs/interfaces/singly-linked-list.js.map +1 -0
  137. package/dist/cjs/types/data-structures/binary-tree/avl-tree.d.ts +4 -0
  138. package/dist/cjs/types/data-structures/binary-tree/avl-tree.js.map +1 -0
  139. package/dist/cjs/types/data-structures/binary-tree/binary-indexed-tree.js +3 -0
  140. package/dist/cjs/types/data-structures/binary-tree/binary-indexed-tree.js.map +1 -0
  141. package/dist/cjs/types/data-structures/binary-tree/binary-tree.d.ts +29 -0
  142. package/dist/cjs/types/data-structures/binary-tree/binary-tree.js +25 -0
  143. package/dist/cjs/types/data-structures/binary-tree/binary-tree.js.map +1 -0
  144. package/dist/cjs/types/data-structures/binary-tree/bst.d.ts +7 -0
  145. package/dist/cjs/types/data-structures/binary-tree/bst.js.map +1 -0
  146. package/dist/cjs/types/data-structures/binary-tree/index.d.ts +6 -0
  147. package/dist/cjs/types/data-structures/binary-tree/index.js +23 -0
  148. package/dist/cjs/types/data-structures/binary-tree/index.js.map +1 -0
  149. package/dist/cjs/types/data-structures/binary-tree/rb-tree.d.ts +8 -0
  150. package/dist/cjs/types/data-structures/binary-tree/rb-tree.js.map +1 -0
  151. package/dist/cjs/types/data-structures/binary-tree/segment-tree.js.map +1 -0
  152. package/dist/cjs/types/data-structures/binary-tree/tree-multiset.d.ts +4 -0
  153. package/dist/cjs/types/data-structures/binary-tree/tree-multiset.js.map +1 -0
  154. package/dist/cjs/types/data-structures/graph/abstract-graph.d.ts +10 -0
  155. package/dist/cjs/types/data-structures/graph/abstract-graph.js.map +1 -0
  156. package/dist/cjs/types/data-structures/graph/directed-graph.js.map +1 -0
  157. package/dist/cjs/types/data-structures/graph/index.d.ts +3 -0
  158. package/dist/cjs/types/data-structures/graph/index.js +20 -0
  159. package/dist/cjs/types/data-structures/graph/index.js.map +1 -0
  160. package/dist/cjs/types/data-structures/graph/map-graph.js.map +1 -0
  161. package/dist/cjs/types/data-structures/graph/undirected-graph.js.map +1 -0
  162. package/dist/cjs/types/data-structures/hash/coordinate-map.js +3 -0
  163. package/dist/cjs/types/data-structures/hash/coordinate-map.js.map +1 -0
  164. package/dist/cjs/types/data-structures/hash/coordinate-set.js +3 -0
  165. package/dist/cjs/types/data-structures/hash/coordinate-set.js.map +1 -0
  166. package/dist/cjs/types/data-structures/hash/hash-map.js +3 -0
  167. package/dist/cjs/types/data-structures/hash/hash-map.js.map +1 -0
  168. package/dist/cjs/types/data-structures/hash/hash-table.js +3 -0
  169. package/dist/cjs/types/data-structures/hash/hash-table.js.map +1 -0
  170. package/dist/cjs/types/data-structures/hash/index.js +3 -0
  171. package/dist/cjs/types/data-structures/hash/index.js.map +1 -0
  172. package/dist/cjs/types/data-structures/hash/tree-map.js +3 -0
  173. package/dist/cjs/types/data-structures/hash/tree-map.js.map +1 -0
  174. package/dist/cjs/types/data-structures/hash/tree-set.js +3 -0
  175. package/dist/cjs/types/data-structures/hash/tree-set.js.map +1 -0
  176. package/dist/cjs/types/data-structures/heap/heap.js.map +1 -0
  177. package/dist/cjs/types/data-structures/heap/index.d.ts +1 -0
  178. package/dist/cjs/types/data-structures/heap/index.js +18 -0
  179. package/dist/cjs/types/data-structures/heap/index.js.map +1 -0
  180. package/dist/cjs/types/data-structures/heap/max-heap.js +3 -0
  181. package/dist/cjs/types/data-structures/heap/max-heap.js.map +1 -0
  182. package/dist/cjs/types/data-structures/heap/min-heap.js +3 -0
  183. package/dist/cjs/types/data-structures/heap/min-heap.js.map +1 -0
  184. package/dist/cjs/types/data-structures/index.d.ts +11 -0
  185. package/dist/cjs/types/data-structures/index.js +28 -0
  186. package/dist/cjs/types/data-structures/index.js.map +1 -0
  187. package/dist/cjs/types/data-structures/linked-list/doubly-linked-list.js.map +1 -0
  188. package/dist/cjs/types/data-structures/linked-list/index.d.ts +2 -0
  189. package/dist/cjs/types/data-structures/linked-list/index.js +19 -0
  190. package/dist/cjs/types/data-structures/linked-list/index.js.map +1 -0
  191. package/dist/cjs/types/data-structures/linked-list/singly-linked-list.js.map +1 -0
  192. package/dist/cjs/types/data-structures/linked-list/skip-linked-list.js +3 -0
  193. package/dist/cjs/types/data-structures/linked-list/skip-linked-list.js.map +1 -0
  194. package/dist/cjs/types/data-structures/matrix/index.d.ts +1 -0
  195. package/dist/cjs/types/data-structures/matrix/index.js +18 -0
  196. package/dist/cjs/types/data-structures/matrix/index.js.map +1 -0
  197. package/dist/cjs/types/data-structures/matrix/matrix.js +3 -0
  198. package/dist/cjs/types/data-structures/matrix/matrix.js.map +1 -0
  199. package/dist/cjs/types/data-structures/matrix/matrix2d.js +3 -0
  200. package/dist/cjs/types/data-structures/matrix/matrix2d.js.map +1 -0
  201. package/dist/cjs/types/data-structures/matrix/navigator.js.map +1 -0
  202. package/dist/cjs/types/data-structures/matrix/vector2d.js +3 -0
  203. package/dist/cjs/types/data-structures/matrix/vector2d.js.map +1 -0
  204. package/dist/cjs/types/data-structures/priority-queue/index.js +20 -0
  205. package/dist/cjs/types/data-structures/priority-queue/index.js.map +1 -0
  206. package/dist/cjs/types/data-structures/priority-queue/max-priority-queue.js +3 -0
  207. package/dist/cjs/types/data-structures/priority-queue/max-priority-queue.js.map +1 -0
  208. package/dist/cjs/types/data-structures/priority-queue/min-priority-queue.js +3 -0
  209. package/dist/cjs/types/data-structures/priority-queue/min-priority-queue.js.map +1 -0
  210. package/dist/cjs/types/data-structures/priority-queue/priority-queue.js.map +1 -0
  211. package/dist/cjs/types/data-structures/queue/deque.js +3 -0
  212. package/dist/cjs/types/data-structures/queue/deque.js.map +1 -0
  213. package/dist/cjs/types/data-structures/queue/index.js +19 -0
  214. package/dist/cjs/types/data-structures/queue/index.js.map +1 -0
  215. package/dist/cjs/types/data-structures/queue/queue.js +3 -0
  216. package/dist/cjs/types/data-structures/queue/queue.js.map +1 -0
  217. package/dist/cjs/types/data-structures/stack/index.js +18 -0
  218. package/dist/cjs/types/data-structures/stack/index.js.map +1 -0
  219. package/dist/cjs/types/data-structures/stack/stack.js +3 -0
  220. package/dist/cjs/types/data-structures/stack/stack.js.map +1 -0
  221. package/dist/cjs/types/data-structures/tree/index.js +18 -0
  222. package/dist/cjs/types/data-structures/tree/index.js.map +1 -0
  223. package/dist/cjs/types/data-structures/tree/tree.js +3 -0
  224. package/dist/cjs/types/data-structures/tree/tree.js.map +1 -0
  225. package/dist/cjs/types/data-structures/trie/index.js +18 -0
  226. package/dist/cjs/types/data-structures/trie/index.js.map +1 -0
  227. package/dist/cjs/types/data-structures/trie/trie.js +3 -0
  228. package/dist/cjs/types/data-structures/trie/trie.js.map +1 -0
  229. package/dist/cjs/types/helpers.d.ts +8 -0
  230. package/dist/cjs/types/helpers.js +10 -0
  231. package/dist/cjs/types/helpers.js.map +1 -0
  232. package/dist/cjs/types/index.js.map +1 -0
  233. package/dist/cjs/types/utils/index.js.map +1 -0
  234. package/dist/cjs/types/utils/utils.js.map +1 -0
  235. package/dist/cjs/types/utils/validate-type.js.map +1 -0
  236. package/dist/cjs/utils/index.js.map +1 -0
  237. package/dist/cjs/utils/utils.d.ts +20 -0
  238. package/dist/cjs/utils/utils.js +74 -0
  239. package/dist/cjs/utils/utils.js.map +1 -0
  240. package/dist/mjs/data-structures/binary-tree/avl-tree.d.ts +106 -0
  241. package/dist/mjs/data-structures/binary-tree/avl-tree.js +348 -0
  242. package/dist/mjs/data-structures/binary-tree/binary-indexed-tree.d.ts +149 -0
  243. package/dist/mjs/data-structures/binary-tree/binary-indexed-tree.js +274 -0
  244. package/dist/mjs/data-structures/binary-tree/binary-tree.d.ts +355 -0
  245. package/dist/mjs/data-structures/binary-tree/binary-tree.js +1127 -0
  246. package/dist/mjs/data-structures/binary-tree/bst.d.ts +167 -0
  247. package/dist/mjs/data-structures/binary-tree/bst.js +509 -0
  248. package/dist/mjs/data-structures/binary-tree/index.d.ts +7 -0
  249. package/dist/mjs/data-structures/binary-tree/index.js +23 -0
  250. package/dist/mjs/data-structures/binary-tree/rb-tree.d.ts +11 -0
  251. package/dist/mjs/data-structures/binary-tree/rb-tree.js +22 -0
  252. package/dist/mjs/data-structures/binary-tree/segment-tree.d.ts +67 -0
  253. package/dist/mjs/data-structures/binary-tree/segment-tree.js +182 -0
  254. package/dist/mjs/data-structures/binary-tree/tree-multiset.d.ts +126 -0
  255. package/dist/mjs/data-structures/binary-tree/tree-multiset.js +356 -0
  256. package/dist/mjs/data-structures/graph/abstract-graph.d.ts +313 -0
  257. package/dist/mjs/data-structures/graph/abstract-graph.js +883 -0
  258. package/dist/mjs/data-structures/graph/directed-graph.d.ts +194 -0
  259. package/dist/mjs/data-structures/graph/directed-graph.js +406 -0
  260. package/dist/mjs/data-structures/graph/index.js +20 -0
  261. package/dist/mjs/data-structures/graph/map-graph.d.ts +73 -0
  262. package/dist/mjs/data-structures/graph/map-graph.js +96 -0
  263. package/dist/mjs/data-structures/graph/undirected-graph.d.ts +120 -0
  264. package/dist/mjs/data-structures/graph/undirected-graph.js +239 -0
  265. package/dist/mjs/data-structures/hash/coordinate-map.d.ts +44 -0
  266. package/dist/mjs/data-structures/hash/coordinate-map.js +62 -0
  267. package/dist/mjs/data-structures/hash/coordinate-set.d.ts +36 -0
  268. package/dist/mjs/data-structures/hash/coordinate-set.js +52 -0
  269. package/dist/mjs/data-structures/hash/hash-map.d.ts +50 -0
  270. package/dist/mjs/data-structures/hash/hash-map.js +159 -0
  271. package/dist/mjs/data-structures/hash/hash-table.d.ts +103 -0
  272. package/dist/mjs/data-structures/hash/hash-table.js +243 -0
  273. package/dist/mjs/data-structures/hash/index.d.ts +6 -0
  274. package/dist/mjs/data-structures/hash/index.js +22 -0
  275. package/dist/mjs/data-structures/hash/tree-map.js +6 -0
  276. package/dist/mjs/data-structures/hash/tree-set.js +6 -0
  277. package/dist/mjs/data-structures/heap/heap.d.ts +235 -0
  278. package/dist/mjs/data-structures/heap/heap.js +525 -0
  279. package/dist/mjs/data-structures/heap/index.js +19 -0
  280. package/dist/mjs/data-structures/heap/max-heap.d.ts +15 -0
  281. package/dist/mjs/data-structures/heap/max-heap.js +26 -0
  282. package/dist/mjs/data-structures/heap/min-heap.d.ts +15 -0
  283. package/dist/mjs/data-structures/heap/min-heap.js +26 -0
  284. package/dist/mjs/data-structures/index.js +27 -0
  285. package/dist/mjs/data-structures/linked-list/doubly-linked-list.d.ts +253 -0
  286. package/dist/mjs/data-structures/linked-list/doubly-linked-list.js +573 -0
  287. package/dist/mjs/data-structures/linked-list/index.js +19 -0
  288. package/dist/mjs/data-structures/linked-list/singly-linked-list.d.ts +232 -0
  289. package/dist/mjs/data-structures/linked-list/singly-linked-list.js +538 -0
  290. package/dist/mjs/data-structures/linked-list/skip-linked-list.d.ts +80 -0
  291. package/dist/mjs/data-structures/linked-list/skip-linked-list.js +194 -0
  292. package/dist/mjs/data-structures/matrix/index.js +20 -0
  293. package/dist/mjs/data-structures/matrix/matrix.d.ts +21 -0
  294. package/dist/mjs/data-structures/matrix/matrix.js +29 -0
  295. package/dist/mjs/data-structures/matrix/matrix2d.d.ts +107 -0
  296. package/dist/mjs/data-structures/matrix/matrix2d.js +200 -0
  297. package/dist/mjs/data-structures/matrix/navigator.d.ts +52 -0
  298. package/dist/mjs/data-structures/matrix/navigator.js +113 -0
  299. package/dist/mjs/data-structures/matrix/vector2d.d.ts +200 -0
  300. package/dist/mjs/data-structures/matrix/vector2d.js +293 -0
  301. package/dist/mjs/data-structures/priority-queue/index.js +19 -0
  302. package/dist/mjs/data-structures/priority-queue/max-priority-queue.d.ts +15 -0
  303. package/dist/mjs/data-structures/priority-queue/max-priority-queue.js +26 -0
  304. package/dist/mjs/data-structures/priority-queue/min-priority-queue.d.ts +15 -0
  305. package/dist/mjs/data-structures/priority-queue/min-priority-queue.js +26 -0
  306. package/dist/mjs/data-structures/priority-queue/priority-queue.d.ts +15 -0
  307. package/dist/mjs/data-structures/priority-queue/priority-queue.js +17 -0
  308. package/dist/mjs/data-structures/queue/deque.d.ts +161 -0
  309. package/dist/mjs/data-structures/queue/deque.js +257 -0
  310. package/dist/mjs/data-structures/queue/index.js +18 -0
  311. package/dist/mjs/data-structures/queue/queue.d.ts +122 -0
  312. package/dist/mjs/data-structures/queue/queue.js +188 -0
  313. package/dist/mjs/data-structures/stack/index.js +17 -0
  314. package/dist/mjs/data-structures/stack/stack.d.ts +64 -0
  315. package/dist/mjs/data-structures/stack/stack.js +95 -0
  316. package/dist/mjs/data-structures/tree/index.js +17 -0
  317. package/dist/mjs/data-structures/tree/tree.d.ts +8 -0
  318. package/dist/mjs/data-structures/tree/tree.js +43 -0
  319. package/dist/mjs/data-structures/trie/index.js +17 -0
  320. package/dist/mjs/data-structures/trie/trie.d.ts +79 -0
  321. package/dist/mjs/data-structures/trie/trie.js +256 -0
  322. package/dist/mjs/index.js +20 -0
  323. package/dist/mjs/interfaces/binary-tree.d.ts +7 -0
  324. package/dist/mjs/interfaces/binary-tree.js +2 -0
  325. package/dist/mjs/interfaces/doubly-linked-list.js +2 -0
  326. package/dist/mjs/interfaces/graph.d.ts +5 -0
  327. package/dist/mjs/interfaces/graph.js +2 -0
  328. package/dist/mjs/interfaces/heap.js +2 -0
  329. package/dist/mjs/interfaces/index.d.ts +8 -0
  330. package/dist/mjs/interfaces/index.js +24 -0
  331. package/dist/mjs/interfaces/navigator.js +2 -0
  332. package/dist/mjs/interfaces/priority-queue.js +2 -0
  333. package/dist/mjs/interfaces/segment-tree.js +2 -0
  334. package/dist/mjs/interfaces/singly-linked-list.js +2 -0
  335. package/dist/mjs/types/data-structures/binary-tree/avl-tree.d.ts +4 -0
  336. package/dist/mjs/types/data-structures/binary-tree/avl-tree.js +2 -0
  337. package/dist/mjs/types/data-structures/binary-tree/binary-indexed-tree.js +2 -0
  338. package/dist/mjs/types/data-structures/binary-tree/binary-tree.d.ts +29 -0
  339. package/dist/mjs/types/data-structures/binary-tree/binary-tree.js +24 -0
  340. package/dist/mjs/types/data-structures/binary-tree/bst.d.ts +7 -0
  341. package/dist/mjs/types/data-structures/binary-tree/bst.js +2 -0
  342. package/dist/mjs/types/data-structures/binary-tree/index.d.ts +6 -0
  343. package/dist/mjs/types/data-structures/binary-tree/index.js +22 -0
  344. package/dist/mjs/types/data-structures/binary-tree/rb-tree.d.ts +8 -0
  345. package/dist/mjs/types/data-structures/binary-tree/rb-tree.js +8 -0
  346. package/dist/mjs/types/data-structures/binary-tree/segment-tree.js +2 -0
  347. package/dist/mjs/types/data-structures/binary-tree/tree-multiset.d.ts +4 -0
  348. package/dist/mjs/types/data-structures/binary-tree/tree-multiset.js +2 -0
  349. package/dist/mjs/types/data-structures/graph/abstract-graph.d.ts +10 -0
  350. package/dist/mjs/types/data-structures/graph/abstract-graph.js +2 -0
  351. package/dist/mjs/types/data-structures/graph/directed-graph.js +9 -0
  352. package/dist/mjs/types/data-structures/graph/index.d.ts +3 -0
  353. package/dist/mjs/types/data-structures/graph/index.js +19 -0
  354. package/dist/mjs/types/data-structures/graph/map-graph.js +2 -0
  355. package/dist/mjs/types/data-structures/graph/undirected-graph.js +2 -0
  356. package/dist/mjs/types/data-structures/hash/coordinate-map.js +2 -0
  357. package/dist/mjs/types/data-structures/hash/coordinate-set.js +2 -0
  358. package/dist/mjs/types/data-structures/hash/hash-map.js +2 -0
  359. package/dist/mjs/types/data-structures/hash/hash-table.js +2 -0
  360. package/dist/mjs/types/data-structures/hash/index.js +2 -0
  361. package/dist/mjs/types/data-structures/hash/tree-map.js +2 -0
  362. package/dist/mjs/types/data-structures/hash/tree-set.js +2 -0
  363. package/dist/mjs/types/data-structures/heap/heap.js +2 -0
  364. package/dist/mjs/types/data-structures/heap/index.d.ts +1 -0
  365. package/dist/mjs/types/data-structures/heap/index.js +17 -0
  366. package/dist/mjs/types/data-structures/heap/max-heap.js +2 -0
  367. package/dist/mjs/types/data-structures/heap/min-heap.js +2 -0
  368. package/dist/mjs/types/data-structures/index.d.ts +11 -0
  369. package/dist/mjs/types/data-structures/index.js +27 -0
  370. package/dist/mjs/types/data-structures/linked-list/doubly-linked-list.js +2 -0
  371. package/dist/mjs/types/data-structures/linked-list/index.d.ts +2 -0
  372. package/dist/mjs/types/data-structures/linked-list/index.js +18 -0
  373. package/dist/mjs/types/data-structures/linked-list/singly-linked-list.js +2 -0
  374. package/dist/mjs/types/data-structures/linked-list/skip-linked-list.d.ts +1 -0
  375. package/dist/mjs/types/data-structures/linked-list/skip-linked-list.js +2 -0
  376. package/dist/mjs/types/data-structures/matrix/index.d.ts +1 -0
  377. package/dist/mjs/types/data-structures/matrix/index.js +17 -0
  378. package/dist/mjs/types/data-structures/matrix/matrix.d.ts +1 -0
  379. package/dist/mjs/types/data-structures/matrix/matrix.js +2 -0
  380. package/dist/mjs/types/data-structures/matrix/matrix2d.d.ts +1 -0
  381. package/dist/mjs/types/data-structures/matrix/matrix2d.js +2 -0
  382. package/dist/mjs/types/data-structures/matrix/navigator.js +2 -0
  383. package/dist/mjs/types/data-structures/matrix/vector2d.d.ts +1 -0
  384. package/dist/mjs/types/data-structures/matrix/vector2d.js +2 -0
  385. package/dist/mjs/types/data-structures/priority-queue/index.d.ts +3 -0
  386. package/dist/mjs/types/data-structures/priority-queue/index.js +19 -0
  387. package/dist/mjs/types/data-structures/priority-queue/max-priority-queue.d.ts +1 -0
  388. package/dist/mjs/types/data-structures/priority-queue/max-priority-queue.js +2 -0
  389. package/dist/mjs/types/data-structures/priority-queue/min-priority-queue.d.ts +1 -0
  390. package/dist/mjs/types/data-structures/priority-queue/min-priority-queue.js +2 -0
  391. package/dist/mjs/types/data-structures/priority-queue/priority-queue.d.ts +1 -0
  392. package/dist/mjs/types/data-structures/priority-queue/priority-queue.js +2 -0
  393. package/dist/mjs/types/data-structures/queue/deque.d.ts +1 -0
  394. package/dist/mjs/types/data-structures/queue/deque.js +2 -0
  395. package/dist/mjs/types/data-structures/queue/index.d.ts +2 -0
  396. package/dist/mjs/types/data-structures/queue/index.js +18 -0
  397. package/dist/mjs/types/data-structures/queue/queue.d.ts +1 -0
  398. package/dist/mjs/types/data-structures/queue/queue.js +2 -0
  399. package/dist/mjs/types/data-structures/stack/index.d.ts +1 -0
  400. package/dist/mjs/types/data-structures/stack/index.js +17 -0
  401. package/dist/mjs/types/data-structures/stack/stack.d.ts +1 -0
  402. package/dist/mjs/types/data-structures/stack/stack.js +2 -0
  403. package/dist/mjs/types/data-structures/tree/index.d.ts +1 -0
  404. package/dist/mjs/types/data-structures/tree/index.js +17 -0
  405. package/dist/mjs/types/data-structures/tree/tree.d.ts +1 -0
  406. package/dist/mjs/types/data-structures/tree/tree.js +2 -0
  407. package/dist/mjs/types/data-structures/trie/index.d.ts +1 -0
  408. package/dist/mjs/types/data-structures/trie/index.js +17 -0
  409. package/dist/mjs/types/data-structures/trie/trie.d.ts +1 -0
  410. package/dist/mjs/types/data-structures/trie/trie.js +2 -0
  411. package/dist/mjs/types/helpers.d.ts +8 -0
  412. package/dist/mjs/types/helpers.js +9 -0
  413. package/dist/mjs/types/index.js +19 -0
  414. package/dist/mjs/types/utils/index.js +18 -0
  415. package/dist/mjs/types/utils/utils.js +2 -0
  416. package/dist/mjs/types/utils/validate-type.js +2 -0
  417. package/dist/mjs/utils/index.js +17 -0
  418. package/dist/mjs/utils/utils.d.ts +20 -0
  419. package/dist/mjs/utils/utils.js +64 -0
  420. package/dist/umd/data-structure-typed.min.js +27 -0
  421. package/dist/umd/data-structure-typed.min.js.map +1 -0
  422. package/package.json +28 -22
  423. package/src/data-structures/binary-tree/avl-tree.ts +88 -74
  424. package/src/data-structures/binary-tree/binary-indexed-tree.ts +265 -35
  425. package/src/data-structures/binary-tree/binary-tree.ts +1241 -26
  426. package/src/data-structures/binary-tree/bst.ts +217 -237
  427. package/src/data-structures/binary-tree/index.ts +0 -5
  428. package/src/data-structures/binary-tree/rb-tree.ts +28 -36
  429. package/src/data-structures/binary-tree/segment-tree.ts +25 -92
  430. package/src/data-structures/binary-tree/tree-multiset.ts +113 -422
  431. package/src/data-structures/graph/abstract-graph.ts +169 -214
  432. package/src/data-structures/graph/directed-graph.ts +105 -126
  433. package/src/data-structures/graph/map-graph.ts +29 -57
  434. package/src/data-structures/graph/undirected-graph.ts +67 -82
  435. package/src/data-structures/hash/coordinate-map.ts +0 -4
  436. package/src/data-structures/hash/coordinate-set.ts +0 -4
  437. package/src/data-structures/hash/hash-map.ts +65 -83
  438. package/src/data-structures/hash/hash-table.ts +109 -118
  439. package/src/data-structures/hash/index.ts +0 -1
  440. package/src/data-structures/hash/tree-map.ts +2 -1
  441. package/src/data-structures/hash/tree-set.ts +2 -1
  442. package/src/data-structures/heap/heap.ts +505 -128
  443. package/src/data-structures/heap/max-heap.ts +16 -21
  444. package/src/data-structures/heap/min-heap.ts +16 -22
  445. package/src/data-structures/linked-list/doubly-linked-list.ts +143 -174
  446. package/src/data-structures/linked-list/singly-linked-list.ts +174 -99
  447. package/src/data-structures/linked-list/skip-linked-list.ts +104 -49
  448. package/src/data-structures/matrix/matrix.ts +2 -2
  449. package/src/data-structures/matrix/matrix2d.ts +12 -14
  450. package/src/data-structures/matrix/navigator.ts +4 -4
  451. package/src/data-structures/matrix/vector2d.ts +2 -3
  452. package/src/data-structures/priority-queue/max-priority-queue.ts +15 -46
  453. package/src/data-structures/priority-queue/min-priority-queue.ts +15 -47
  454. package/src/data-structures/priority-queue/priority-queue.ts +7 -350
  455. package/src/data-structures/queue/deque.ts +62 -77
  456. package/src/data-structures/queue/queue.ts +39 -21
  457. package/src/data-structures/stack/stack.ts +13 -9
  458. package/src/data-structures/tree/tree.ts +10 -38
  459. package/src/data-structures/trie/trie.ts +108 -71
  460. package/src/interfaces/binary-tree.ts +7 -4
  461. package/src/interfaces/graph.ts +7 -0
  462. package/src/interfaces/index.ts +1 -8
  463. package/src/types/data-structures/binary-tree/avl-tree.ts +5 -0
  464. package/src/types/data-structures/binary-tree/binary-indexed-tree.ts +1 -0
  465. package/src/types/data-structures/binary-tree/binary-tree.ts +31 -0
  466. package/src/types/data-structures/binary-tree/bst.ts +11 -0
  467. package/src/types/data-structures/binary-tree/index.ts +6 -0
  468. package/src/types/data-structures/binary-tree/rb-tree.ts +8 -0
  469. package/src/types/data-structures/binary-tree/tree-multiset.ts +6 -0
  470. package/src/types/data-structures/graph/abstract-graph.ts +11 -0
  471. package/src/types/data-structures/graph/index.ts +3 -0
  472. package/src/types/data-structures/graph/undirected-graph.ts +1 -0
  473. package/src/types/data-structures/hash/coordinate-map.ts +1 -0
  474. package/src/types/data-structures/hash/coordinate-set.ts +1 -0
  475. package/src/types/data-structures/hash/hash-map.ts +1 -0
  476. package/src/types/data-structures/hash/hash-table.ts +1 -0
  477. package/src/types/data-structures/hash/tree-map.ts +1 -0
  478. package/src/types/data-structures/hash/tree-set.ts +1 -0
  479. package/src/types/data-structures/heap/heap.ts +1 -0
  480. package/src/types/data-structures/heap/index.ts +1 -0
  481. package/src/types/data-structures/heap/max-heap.ts +1 -0
  482. package/src/types/data-structures/heap/min-heap.ts +1 -0
  483. package/src/types/data-structures/index.ts +8 -13
  484. package/src/types/data-structures/linked-list/doubly-linked-list.ts +1 -0
  485. package/src/types/data-structures/linked-list/index.ts +2 -0
  486. package/src/types/data-structures/linked-list/singly-linked-list.ts +1 -0
  487. package/src/types/data-structures/linked-list/skip-linked-list.ts +1 -0
  488. package/src/types/data-structures/matrix/index.ts +1 -0
  489. package/src/types/data-structures/matrix/matrix.ts +1 -0
  490. package/src/types/data-structures/matrix/matrix2d.ts +1 -0
  491. package/src/types/data-structures/matrix/navigator.ts +14 -0
  492. package/src/types/data-structures/matrix/vector2d.ts +1 -0
  493. package/src/types/data-structures/priority-queue/index.ts +3 -0
  494. package/src/types/data-structures/priority-queue/max-priority-queue.ts +1 -0
  495. package/src/types/data-structures/priority-queue/min-priority-queue.ts +1 -0
  496. package/src/types/data-structures/priority-queue/priority-queue.ts +1 -0
  497. package/src/types/data-structures/queue/deque.ts +1 -0
  498. package/src/types/data-structures/queue/index.ts +2 -0
  499. package/src/types/data-structures/queue/queue.ts +1 -0
  500. package/src/types/data-structures/stack/index.ts +1 -0
  501. package/src/types/data-structures/stack/stack.ts +1 -0
  502. package/src/types/data-structures/tree/index.ts +1 -0
  503. package/src/types/data-structures/tree/tree.ts +1 -0
  504. package/src/types/data-structures/trie/index.ts +1 -0
  505. package/src/types/data-structures/trie/trie.ts +1 -0
  506. package/src/types/helpers.ts +11 -1
  507. package/src/types/utils/utils.ts +1 -1
  508. package/src/types/utils/validate-type.ts +2 -2
  509. package/src/utils/utils.ts +7 -0
  510. package/test/config.js +4 -0
  511. package/test/config.ts +1 -0
  512. package/test/integration/avl-tree.test.ts +24 -22
  513. package/test/integration/bst.test.ts +52 -47
  514. package/test/integration/index.html +3 -4
  515. package/test/types/index.js +29 -0
  516. package/test/types/utils/big-o.js +2 -0
  517. package/test/types/utils/big-o.ts +1 -0
  518. package/test/types/utils/index.js +29 -0
  519. package/test/types/utils/index.ts +1 -0
  520. package/test/unit/data-structures/binary-tree/avl-tree.test.ts +184 -23
  521. package/test/unit/data-structures/binary-tree/binary-index-tree.test.ts +320 -0
  522. package/test/unit/data-structures/binary-tree/binary-tree.test.ts +393 -40
  523. package/test/unit/data-structures/binary-tree/bst.test.ts +506 -48
  524. package/test/unit/data-structures/binary-tree/overall.test.ts +8 -7
  525. package/test/unit/data-structures/binary-tree/rb-tree.test.ts +79 -13
  526. package/test/unit/data-structures/binary-tree/tree-multiset.test.ts +296 -215
  527. package/test/unit/data-structures/graph/abstract-graph.test.ts +97 -2
  528. package/test/unit/data-structures/graph/directed-graph.test.ts +76 -31
  529. package/test/unit/data-structures/graph/map-graph.test.ts +93 -12
  530. package/test/unit/data-structures/graph/overall.test.ts +2 -2
  531. package/test/unit/data-structures/graph/undirected-graph.test.ts +93 -3
  532. package/test/unit/data-structures/hash/coordinate-map.test.ts +20 -0
  533. package/test/unit/data-structures/hash/coordinate-set.test.ts +25 -0
  534. package/test/unit/data-structures/hash/hash-map.test.ts +2 -3
  535. package/test/unit/data-structures/hash/hash-table.test.ts +10 -8
  536. package/test/unit/data-structures/heap/heap.test.ts +218 -20
  537. package/test/unit/data-structures/heap/max-heap.test.ts +50 -42
  538. package/test/unit/data-structures/heap/min-heap.test.ts +38 -68
  539. package/test/unit/data-structures/linked-list/doubly-linked-list.test.ts +86 -27
  540. package/test/unit/data-structures/linked-list/linked-list.test.ts +4 -4
  541. package/test/unit/data-structures/linked-list/singly-linked-list.test.ts +71 -27
  542. package/test/unit/data-structures/linked-list/skip-list.test.ts +33 -2
  543. package/test/unit/data-structures/matrix/matrix2d.test.ts +207 -0
  544. package/test/unit/data-structures/matrix/navigator.test.ts +167 -2
  545. package/test/unit/data-structures/matrix/vector2d.test.ts +171 -0
  546. package/test/unit/data-structures/priority-queue/max-priority-queue.test.ts +10 -11
  547. package/test/unit/data-structures/priority-queue/min-priority-queue.test.ts +1 -1
  548. package/test/unit/data-structures/priority-queue/priority-queue.test.ts +14 -30
  549. package/test/unit/data-structures/queue/deque.test.ts +303 -23
  550. package/test/unit/data-structures/queue/queue.test.ts +52 -8
  551. package/test/unit/data-structures/tree/tree.test.ts +2 -2
  552. package/test/unit/data-structures/trie/trie.test.ts +743 -13
  553. package/test/utils/big-o.js +212 -0
  554. package/test/utils/big-o.ts +201 -0
  555. package/test/utils/index.js +30 -0
  556. package/test/utils/index.ts +1 -1
  557. package/test/utils/number.js +14 -0
  558. package/tsconfig-base.json +27 -0
  559. package/tsconfig-cjs.json +9 -0
  560. package/tsup.config.js +18 -0
  561. package/umd/bundle.min.js +1 -1
  562. package/umd/bundle.min.js.LICENSE.txt +15 -0
  563. package/umd/bundle.min.js.map +1 -1
  564. package/dist/data-structures/binary-tree/aa-tree.d.ts +0 -2
  565. package/dist/data-structures/binary-tree/aa-tree.js +0 -7
  566. package/dist/data-structures/binary-tree/aa-tree.js.map +0 -1
  567. package/dist/data-structures/binary-tree/abstract-binary-tree.d.ts +0 -527
  568. package/dist/data-structures/binary-tree/abstract-binary-tree.js +0 -1199
  569. package/dist/data-structures/binary-tree/abstract-binary-tree.js.map +0 -1
  570. package/dist/data-structures/binary-tree/avl-tree.d.ts +0 -94
  571. package/dist/data-structures/binary-tree/avl-tree.js +0 -336
  572. package/dist/data-structures/binary-tree/avl-tree.js.map +0 -1
  573. package/dist/data-structures/binary-tree/b-tree.d.ts +0 -2
  574. package/dist/data-structures/binary-tree/b-tree.js +0 -7
  575. package/dist/data-structures/binary-tree/b-tree.js.map +0 -1
  576. package/dist/data-structures/binary-tree/binary-indexed-tree.d.ts +0 -46
  577. package/dist/data-structures/binary-tree/binary-indexed-tree.js +0 -74
  578. package/dist/data-structures/binary-tree/binary-indexed-tree.js.map +0 -1
  579. package/dist/data-structures/binary-tree/binary-tree.d.ts +0 -31
  580. package/dist/data-structures/binary-tree/binary-tree.js +0 -41
  581. package/dist/data-structures/binary-tree/binary-tree.js.map +0 -1
  582. package/dist/data-structures/binary-tree/bst.d.ts +0 -133
  583. package/dist/data-structures/binary-tree/bst.js +0 -554
  584. package/dist/data-structures/binary-tree/bst.js.map +0 -1
  585. package/dist/data-structures/binary-tree/index.d.ts +0 -12
  586. package/dist/data-structures/binary-tree/index.js +0 -29
  587. package/dist/data-structures/binary-tree/index.js.map +0 -1
  588. package/dist/data-structures/binary-tree/rb-tree.d.ts +0 -13
  589. package/dist/data-structures/binary-tree/rb-tree.js +0 -28
  590. package/dist/data-structures/binary-tree/rb-tree.js.map +0 -1
  591. package/dist/data-structures/binary-tree/segment-tree.d.ts +0 -83
  592. package/dist/data-structures/binary-tree/segment-tree.js +0 -229
  593. package/dist/data-structures/binary-tree/segment-tree.js.map +0 -1
  594. package/dist/data-structures/binary-tree/splay-tree.d.ts +0 -2
  595. package/dist/data-structures/binary-tree/splay-tree.js +0 -7
  596. package/dist/data-structures/binary-tree/splay-tree.js.map +0 -1
  597. package/dist/data-structures/binary-tree/tree-multiset.d.ts +0 -209
  598. package/dist/data-structures/binary-tree/tree-multiset.js +0 -669
  599. package/dist/data-structures/binary-tree/tree-multiset.js.map +0 -1
  600. package/dist/data-structures/binary-tree/two-three-tree.d.ts +0 -2
  601. package/dist/data-structures/binary-tree/two-three-tree.js +0 -7
  602. package/dist/data-structures/binary-tree/two-three-tree.js.map +0 -1
  603. package/dist/data-structures/graph/abstract-graph.d.ts +0 -332
  604. package/dist/data-structures/graph/abstract-graph.js +0 -925
  605. package/dist/data-structures/graph/abstract-graph.js.map +0 -1
  606. package/dist/data-structures/graph/directed-graph.d.ts +0 -200
  607. package/dist/data-structures/graph/directed-graph.js +0 -423
  608. package/dist/data-structures/graph/directed-graph.js.map +0 -1
  609. package/dist/data-structures/graph/index.js.map +0 -1
  610. package/dist/data-structures/graph/map-graph.d.ts +0 -79
  611. package/dist/data-structures/graph/map-graph.js +0 -112
  612. package/dist/data-structures/graph/map-graph.js.map +0 -1
  613. package/dist/data-structures/graph/undirected-graph.d.ts +0 -127
  614. package/dist/data-structures/graph/undirected-graph.js +0 -253
  615. package/dist/data-structures/graph/undirected-graph.js.map +0 -1
  616. package/dist/data-structures/hash/coordinate-map.d.ts +0 -45
  617. package/dist/data-structures/hash/coordinate-map.js +0 -66
  618. package/dist/data-structures/hash/coordinate-map.js.map +0 -1
  619. package/dist/data-structures/hash/coordinate-set.d.ts +0 -37
  620. package/dist/data-structures/hash/coordinate-set.js +0 -56
  621. package/dist/data-structures/hash/coordinate-set.js.map +0 -1
  622. package/dist/data-structures/hash/hash-map.d.ts +0 -56
  623. package/dist/data-structures/hash/hash-map.js +0 -172
  624. package/dist/data-structures/hash/hash-map.js.map +0 -1
  625. package/dist/data-structures/hash/hash-table.d.ts +0 -106
  626. package/dist/data-structures/hash/hash-table.js +0 -246
  627. package/dist/data-structures/hash/hash-table.js.map +0 -1
  628. package/dist/data-structures/hash/index.d.ts +0 -7
  629. package/dist/data-structures/hash/index.js +0 -24
  630. package/dist/data-structures/hash/index.js.map +0 -1
  631. package/dist/data-structures/hash/pair.d.ts +0 -2
  632. package/dist/data-structures/hash/pair.js +0 -7
  633. package/dist/data-structures/hash/pair.js.map +0 -1
  634. package/dist/data-structures/hash/tree-map.js.map +0 -1
  635. package/dist/data-structures/hash/tree-set.js.map +0 -1
  636. package/dist/data-structures/heap/heap.d.ts +0 -83
  637. package/dist/data-structures/heap/heap.js +0 -158
  638. package/dist/data-structures/heap/heap.js.map +0 -1
  639. package/dist/data-structures/heap/index.js.map +0 -1
  640. package/dist/data-structures/heap/max-heap.d.ts +0 -23
  641. package/dist/data-structures/heap/max-heap.js +0 -31
  642. package/dist/data-structures/heap/max-heap.js.map +0 -1
  643. package/dist/data-structures/heap/min-heap.d.ts +0 -24
  644. package/dist/data-structures/heap/min-heap.js +0 -32
  645. package/dist/data-structures/heap/min-heap.js.map +0 -1
  646. package/dist/data-structures/index.js.map +0 -1
  647. package/dist/data-structures/linked-list/doubly-linked-list.d.ts +0 -234
  648. package/dist/data-structures/linked-list/doubly-linked-list.js +0 -584
  649. package/dist/data-structures/linked-list/doubly-linked-list.js.map +0 -1
  650. package/dist/data-structures/linked-list/index.js.map +0 -1
  651. package/dist/data-structures/linked-list/singly-linked-list.d.ts +0 -157
  652. package/dist/data-structures/linked-list/singly-linked-list.js +0 -449
  653. package/dist/data-structures/linked-list/singly-linked-list.js.map +0 -1
  654. package/dist/data-structures/linked-list/skip-linked-list.d.ts +0 -61
  655. package/dist/data-structures/linked-list/skip-linked-list.js +0 -143
  656. package/dist/data-structures/linked-list/skip-linked-list.js.map +0 -1
  657. package/dist/data-structures/matrix/index.js.map +0 -1
  658. package/dist/data-structures/matrix/matrix.d.ts +0 -21
  659. package/dist/data-structures/matrix/matrix.js.map +0 -1
  660. package/dist/data-structures/matrix/matrix2d.d.ts +0 -108
  661. package/dist/data-structures/matrix/matrix2d.js +0 -201
  662. package/dist/data-structures/matrix/matrix2d.js.map +0 -1
  663. package/dist/data-structures/matrix/navigator.d.ts +0 -52
  664. package/dist/data-structures/matrix/navigator.js.map +0 -1
  665. package/dist/data-structures/matrix/vector2d.d.ts +0 -201
  666. package/dist/data-structures/matrix/vector2d.js +0 -292
  667. package/dist/data-structures/matrix/vector2d.js.map +0 -1
  668. package/dist/data-structures/priority-queue/index.js.map +0 -1
  669. package/dist/data-structures/priority-queue/max-priority-queue.d.ts +0 -15
  670. package/dist/data-structures/priority-queue/max-priority-queue.js +0 -44
  671. package/dist/data-structures/priority-queue/max-priority-queue.js.map +0 -1
  672. package/dist/data-structures/priority-queue/min-priority-queue.d.ts +0 -15
  673. package/dist/data-structures/priority-queue/min-priority-queue.js +0 -45
  674. package/dist/data-structures/priority-queue/min-priority-queue.js.map +0 -1
  675. package/dist/data-structures/priority-queue/priority-queue.d.ts +0 -180
  676. package/dist/data-structures/priority-queue/priority-queue.js +0 -322
  677. package/dist/data-structures/priority-queue/priority-queue.js.map +0 -1
  678. package/dist/data-structures/queue/deque.d.ts +0 -165
  679. package/dist/data-structures/queue/deque.js +0 -277
  680. package/dist/data-structures/queue/deque.js.map +0 -1
  681. package/dist/data-structures/queue/index.js.map +0 -1
  682. package/dist/data-structures/queue/queue.d.ts +0 -107
  683. package/dist/data-structures/queue/queue.js +0 -171
  684. package/dist/data-structures/queue/queue.js.map +0 -1
  685. package/dist/data-structures/stack/index.js.map +0 -1
  686. package/dist/data-structures/stack/stack.d.ts +0 -63
  687. package/dist/data-structures/stack/stack.js +0 -92
  688. package/dist/data-structures/stack/stack.js.map +0 -1
  689. package/dist/data-structures/tree/index.js.map +0 -1
  690. package/dist/data-structures/tree/tree.d.ts +0 -14
  691. package/dist/data-structures/tree/tree.js +0 -61
  692. package/dist/data-structures/tree/tree.js.map +0 -1
  693. package/dist/data-structures/trie/index.js.map +0 -1
  694. package/dist/data-structures/trie/trie.d.ts +0 -61
  695. package/dist/data-structures/trie/trie.js +0 -211
  696. package/dist/data-structures/trie/trie.js.map +0 -1
  697. package/dist/index.js.map +0 -1
  698. package/dist/interfaces/abstract-binary-tree.d.ts +0 -7
  699. package/dist/interfaces/abstract-binary-tree.js +0 -3
  700. package/dist/interfaces/abstract-binary-tree.js.map +0 -1
  701. package/dist/interfaces/abstract-graph.d.ts +0 -5
  702. package/dist/interfaces/abstract-graph.js.map +0 -1
  703. package/dist/interfaces/avl-tree.d.ts +0 -7
  704. package/dist/interfaces/avl-tree.js.map +0 -1
  705. package/dist/interfaces/binary-tree.d.ts +0 -6
  706. package/dist/interfaces/binary-tree.js.map +0 -1
  707. package/dist/interfaces/bst.d.ts +0 -6
  708. package/dist/interfaces/bst.js.map +0 -1
  709. package/dist/interfaces/directed-graph.d.ts +0 -3
  710. package/dist/interfaces/directed-graph.js +0 -3
  711. package/dist/interfaces/directed-graph.js.map +0 -1
  712. package/dist/interfaces/doubly-linked-list.js.map +0 -1
  713. package/dist/interfaces/heap.js.map +0 -1
  714. package/dist/interfaces/index.d.ts +0 -15
  715. package/dist/interfaces/index.js +0 -32
  716. package/dist/interfaces/index.js.map +0 -1
  717. package/dist/interfaces/navigator.js.map +0 -1
  718. package/dist/interfaces/priority-queue.js.map +0 -1
  719. package/dist/interfaces/rb-tree.d.ts +0 -6
  720. package/dist/interfaces/rb-tree.js +0 -3
  721. package/dist/interfaces/rb-tree.js.map +0 -1
  722. package/dist/interfaces/segment-tree.js.map +0 -1
  723. package/dist/interfaces/singly-linked-list.js.map +0 -1
  724. package/dist/interfaces/tree-multiset.d.ts +0 -6
  725. package/dist/interfaces/tree-multiset.js.map +0 -1
  726. package/dist/interfaces/undirected-graph.d.ts +0 -3
  727. package/dist/interfaces/undirected-graph.js.map +0 -1
  728. package/dist/types/data-structures/abstract-binary-tree.d.ts +0 -34
  729. package/dist/types/data-structures/abstract-binary-tree.js +0 -25
  730. package/dist/types/data-structures/abstract-binary-tree.js.map +0 -1
  731. package/dist/types/data-structures/abstract-graph.d.ts +0 -11
  732. package/dist/types/data-structures/abstract-graph.js +0 -3
  733. package/dist/types/data-structures/abstract-graph.js.map +0 -1
  734. package/dist/types/data-structures/avl-tree.d.ts +0 -4
  735. package/dist/types/data-structures/avl-tree.js +0 -3
  736. package/dist/types/data-structures/avl-tree.js.map +0 -1
  737. package/dist/types/data-structures/binary-tree.d.ts +0 -4
  738. package/dist/types/data-structures/binary-tree.js +0 -3
  739. package/dist/types/data-structures/binary-tree.js.map +0 -1
  740. package/dist/types/data-structures/bst.d.ts +0 -13
  741. package/dist/types/data-structures/bst.js +0 -10
  742. package/dist/types/data-structures/bst.js.map +0 -1
  743. package/dist/types/data-structures/directed-graph.js.map +0 -1
  744. package/dist/types/data-structures/doubly-linked-list.js.map +0 -1
  745. package/dist/types/data-structures/hash.js +0 -3
  746. package/dist/types/data-structures/hash.js.map +0 -1
  747. package/dist/types/data-structures/heap.d.ts +0 -3
  748. package/dist/types/data-structures/heap.js.map +0 -1
  749. package/dist/types/data-structures/index.d.ts +0 -16
  750. package/dist/types/data-structures/index.js +0 -33
  751. package/dist/types/data-structures/index.js.map +0 -1
  752. package/dist/types/data-structures/map-graph.js.map +0 -1
  753. package/dist/types/data-structures/navigator.js.map +0 -1
  754. package/dist/types/data-structures/priority-queue.d.ts +0 -7
  755. package/dist/types/data-structures/priority-queue.js.map +0 -1
  756. package/dist/types/data-structures/rb-tree.d.ts +0 -8
  757. package/dist/types/data-structures/rb-tree.js.map +0 -1
  758. package/dist/types/data-structures/segment-tree.js.map +0 -1
  759. package/dist/types/data-structures/singly-linked-list.js.map +0 -1
  760. package/dist/types/data-structures/tree-multiset.d.ts +0 -4
  761. package/dist/types/data-structures/tree-multiset.js +0 -3
  762. package/dist/types/data-structures/tree-multiset.js.map +0 -1
  763. package/dist/types/helpers.js +0 -3
  764. package/dist/types/helpers.js.map +0 -1
  765. package/dist/types/index.js.map +0 -1
  766. package/dist/types/utils/index.js.map +0 -1
  767. package/dist/types/utils/utils.js.map +0 -1
  768. package/dist/types/utils/validate-type.js.map +0 -1
  769. package/dist/utils/index.js.map +0 -1
  770. package/dist/utils/utils.d.ts +0 -19
  771. package/dist/utils/utils.js +0 -67
  772. package/dist/utils/utils.js.map +0 -1
  773. package/lib/data-structures/binary-tree/aa-tree.d.ts +0 -2
  774. package/lib/data-structures/binary-tree/aa-tree.js +0 -2
  775. package/lib/data-structures/binary-tree/abstract-binary-tree.d.ts +0 -527
  776. package/lib/data-structures/binary-tree/abstract-binary-tree.js +0 -1193
  777. package/lib/data-structures/binary-tree/avl-tree.d.ts +0 -94
  778. package/lib/data-structures/binary-tree/avl-tree.js +0 -330
  779. package/lib/data-structures/binary-tree/b-tree.d.ts +0 -2
  780. package/lib/data-structures/binary-tree/b-tree.js +0 -2
  781. package/lib/data-structures/binary-tree/binary-indexed-tree.d.ts +0 -46
  782. package/lib/data-structures/binary-tree/binary-indexed-tree.js +0 -69
  783. package/lib/data-structures/binary-tree/binary-tree.d.ts +0 -31
  784. package/lib/data-structures/binary-tree/binary-tree.js +0 -35
  785. package/lib/data-structures/binary-tree/bst.d.ts +0 -133
  786. package/lib/data-structures/binary-tree/bst.js +0 -548
  787. package/lib/data-structures/binary-tree/index.d.ts +0 -12
  788. package/lib/data-structures/binary-tree/index.js +0 -12
  789. package/lib/data-structures/binary-tree/rb-tree.d.ts +0 -13
  790. package/lib/data-structures/binary-tree/rb-tree.js +0 -22
  791. package/lib/data-structures/binary-tree/segment-tree.d.ts +0 -83
  792. package/lib/data-structures/binary-tree/segment-tree.js +0 -223
  793. package/lib/data-structures/binary-tree/splay-tree.d.ts +0 -2
  794. package/lib/data-structures/binary-tree/splay-tree.js +0 -2
  795. package/lib/data-structures/binary-tree/tree-multiset.d.ts +0 -209
  796. package/lib/data-structures/binary-tree/tree-multiset.js +0 -663
  797. package/lib/data-structures/binary-tree/two-three-tree.d.ts +0 -2
  798. package/lib/data-structures/binary-tree/two-three-tree.js +0 -2
  799. package/lib/data-structures/graph/abstract-graph.d.ts +0 -332
  800. package/lib/data-structures/graph/abstract-graph.js +0 -918
  801. package/lib/data-structures/graph/directed-graph.d.ts +0 -200
  802. package/lib/data-structures/graph/directed-graph.js +0 -416
  803. package/lib/data-structures/graph/index.js +0 -4
  804. package/lib/data-structures/graph/map-graph.d.ts +0 -79
  805. package/lib/data-structures/graph/map-graph.js +0 -105
  806. package/lib/data-structures/graph/undirected-graph.d.ts +0 -127
  807. package/lib/data-structures/graph/undirected-graph.js +0 -246
  808. package/lib/data-structures/hash/coordinate-map.d.ts +0 -45
  809. package/lib/data-structures/hash/coordinate-map.js +0 -61
  810. package/lib/data-structures/hash/coordinate-set.d.ts +0 -37
  811. package/lib/data-structures/hash/coordinate-set.js +0 -51
  812. package/lib/data-structures/hash/hash-map.d.ts +0 -56
  813. package/lib/data-structures/hash/hash-map.js +0 -167
  814. package/lib/data-structures/hash/hash-table.d.ts +0 -106
  815. package/lib/data-structures/hash/hash-table.js +0 -240
  816. package/lib/data-structures/hash/index.d.ts +0 -7
  817. package/lib/data-structures/hash/index.js +0 -7
  818. package/lib/data-structures/hash/pair.d.ts +0 -2
  819. package/lib/data-structures/hash/pair.js +0 -2
  820. package/lib/data-structures/hash/tree-map.js +0 -2
  821. package/lib/data-structures/hash/tree-set.js +0 -2
  822. package/lib/data-structures/heap/heap.d.ts +0 -83
  823. package/lib/data-structures/heap/heap.js +0 -152
  824. package/lib/data-structures/heap/index.js +0 -3
  825. package/lib/data-structures/heap/max-heap.d.ts +0 -23
  826. package/lib/data-structures/heap/max-heap.js +0 -26
  827. package/lib/data-structures/heap/min-heap.d.ts +0 -24
  828. package/lib/data-structures/heap/min-heap.js +0 -27
  829. package/lib/data-structures/index.js +0 -11
  830. package/lib/data-structures/linked-list/doubly-linked-list.d.ts +0 -234
  831. package/lib/data-structures/linked-list/doubly-linked-list.js +0 -578
  832. package/lib/data-structures/linked-list/index.js +0 -3
  833. package/lib/data-structures/linked-list/singly-linked-list.d.ts +0 -157
  834. package/lib/data-structures/linked-list/singly-linked-list.js +0 -443
  835. package/lib/data-structures/linked-list/skip-linked-list.d.ts +0 -61
  836. package/lib/data-structures/linked-list/skip-linked-list.js +0 -137
  837. package/lib/data-structures/matrix/index.js +0 -4
  838. package/lib/data-structures/matrix/matrix.d.ts +0 -21
  839. package/lib/data-structures/matrix/matrix.js +0 -24
  840. package/lib/data-structures/matrix/matrix2d.d.ts +0 -108
  841. package/lib/data-structures/matrix/matrix2d.js +0 -196
  842. package/lib/data-structures/matrix/navigator.d.ts +0 -52
  843. package/lib/data-structures/matrix/navigator.js +0 -101
  844. package/lib/data-structures/matrix/vector2d.d.ts +0 -201
  845. package/lib/data-structures/matrix/vector2d.js +0 -287
  846. package/lib/data-structures/priority-queue/max-priority-queue.d.ts +0 -15
  847. package/lib/data-structures/priority-queue/max-priority-queue.js +0 -39
  848. package/lib/data-structures/priority-queue/min-priority-queue.d.ts +0 -15
  849. package/lib/data-structures/priority-queue/min-priority-queue.js +0 -40
  850. package/lib/data-structures/priority-queue/priority-queue.d.ts +0 -180
  851. package/lib/data-structures/priority-queue/priority-queue.js +0 -317
  852. package/lib/data-structures/queue/deque.d.ts +0 -165
  853. package/lib/data-structures/queue/deque.js +0 -270
  854. package/lib/data-structures/queue/queue.d.ts +0 -107
  855. package/lib/data-structures/queue/queue.js +0 -165
  856. package/lib/data-structures/stack/stack.d.ts +0 -63
  857. package/lib/data-structures/stack/stack.js +0 -87
  858. package/lib/data-structures/tree/tree.d.ts +0 -14
  859. package/lib/data-structures/tree/tree.js +0 -56
  860. package/lib/data-structures/trie/trie.d.ts +0 -61
  861. package/lib/data-structures/trie/trie.js +0 -205
  862. package/lib/index.js +0 -4
  863. package/lib/interfaces/abstract-binary-tree.d.ts +0 -7
  864. package/lib/interfaces/abstract-graph.d.ts +0 -5
  865. package/lib/interfaces/avl-tree.d.ts +0 -7
  866. package/lib/interfaces/binary-tree.d.ts +0 -6
  867. package/lib/interfaces/bst.d.ts +0 -6
  868. package/lib/interfaces/directed-graph.d.ts +0 -3
  869. package/lib/interfaces/index.d.ts +0 -15
  870. package/lib/interfaces/index.js +0 -15
  871. package/lib/interfaces/rb-tree.d.ts +0 -6
  872. package/lib/interfaces/tree-multiset.d.ts +0 -6
  873. package/lib/interfaces/undirected-graph.d.ts +0 -3
  874. package/lib/types/data-structures/abstract-binary-tree.d.ts +0 -34
  875. package/lib/types/data-structures/abstract-binary-tree.js +0 -21
  876. package/lib/types/data-structures/abstract-graph.d.ts +0 -11
  877. package/lib/types/data-structures/avl-tree.d.ts +0 -4
  878. package/lib/types/data-structures/binary-tree.d.ts +0 -4
  879. package/lib/types/data-structures/bst.d.ts +0 -13
  880. package/lib/types/data-structures/bst.js +0 -6
  881. package/lib/types/data-structures/directed-graph.js +0 -6
  882. package/lib/types/data-structures/heap.d.ts +0 -3
  883. package/lib/types/data-structures/index.d.ts +0 -16
  884. package/lib/types/data-structures/index.js +0 -16
  885. package/lib/types/data-structures/priority-queue.d.ts +0 -7
  886. package/lib/types/data-structures/rb-tree.d.ts +0 -8
  887. package/lib/types/data-structures/rb-tree.js +0 -5
  888. package/lib/types/data-structures/tree-multiset.d.ts +0 -4
  889. package/lib/types/index.js +0 -3
  890. package/lib/types/utils/index.js +0 -2
  891. package/lib/utils/utils.d.ts +0 -19
  892. package/lib/utils/utils.js +0 -57
  893. package/scripts/rename_clear_files.sh +0 -29
  894. package/src/data-structures/binary-tree/aa-tree.ts +0 -1
  895. package/src/data-structures/binary-tree/abstract-binary-tree.ts +0 -1556
  896. package/src/data-structures/binary-tree/b-tree.ts +0 -1
  897. package/src/data-structures/binary-tree/splay-tree.ts +0 -1
  898. package/src/data-structures/binary-tree/two-three-tree.ts +0 -1
  899. package/src/data-structures/hash/pair.ts +0 -1
  900. package/src/interfaces/abstract-binary-tree.ts +0 -8
  901. package/src/interfaces/abstract-graph.ts +0 -7
  902. package/src/interfaces/avl-tree.ts +0 -8
  903. package/src/interfaces/bst.ts +0 -6
  904. package/src/interfaces/directed-graph.ts +0 -3
  905. package/src/interfaces/rb-tree.ts +0 -6
  906. package/src/interfaces/tree-multiset.ts +0 -7
  907. package/src/interfaces/undirected-graph.ts +0 -3
  908. package/src/types/data-structures/abstract-binary-tree.ts +0 -49
  909. package/src/types/data-structures/abstract-graph.ts +0 -11
  910. package/src/types/data-structures/avl-tree.ts +0 -5
  911. package/src/types/data-structures/binary-tree.ts +0 -5
  912. package/src/types/data-structures/bst.ts +0 -13
  913. package/src/types/data-structures/heap.ts +0 -5
  914. package/src/types/data-structures/navigator.ts +0 -13
  915. package/src/types/data-structures/priority-queue.ts +0 -9
  916. package/src/types/data-structures/rb-tree.ts +0 -8
  917. package/src/types/data-structures/tree-multiset.ts +0 -6
  918. package/test/utils/magnitude.ts +0 -21
  919. /package/dist/{data-structures → cjs/data-structures}/graph/index.d.ts +0 -0
  920. /package/dist/{data-structures → cjs/data-structures}/graph/index.js +0 -0
  921. /package/dist/{data-structures → cjs/data-structures}/hash/tree-map.d.ts +0 -0
  922. /package/dist/{data-structures → cjs/data-structures}/hash/tree-map.js +0 -0
  923. /package/dist/{data-structures → cjs/data-structures}/hash/tree-set.d.ts +0 -0
  924. /package/dist/{data-structures → cjs/data-structures}/hash/tree-set.js +0 -0
  925. /package/dist/{data-structures → cjs/data-structures}/heap/index.d.ts +0 -0
  926. /package/dist/{data-structures → cjs/data-structures}/heap/index.js +0 -0
  927. /package/dist/{data-structures → cjs/data-structures}/index.d.ts +0 -0
  928. /package/dist/{data-structures → cjs/data-structures}/index.js +0 -0
  929. /package/dist/{data-structures → cjs/data-structures}/linked-list/index.d.ts +0 -0
  930. /package/dist/{data-structures → cjs/data-structures}/linked-list/index.js +0 -0
  931. /package/dist/{data-structures → cjs/data-structures}/matrix/index.d.ts +0 -0
  932. /package/dist/{data-structures → cjs/data-structures}/matrix/index.js +0 -0
  933. /package/dist/{data-structures → cjs/data-structures}/matrix/matrix.js +0 -0
  934. /package/dist/{data-structures → cjs/data-structures}/matrix/navigator.js +0 -0
  935. /package/dist/{data-structures → cjs/data-structures}/priority-queue/index.d.ts +0 -0
  936. /package/dist/{data-structures → cjs/data-structures}/priority-queue/index.js +0 -0
  937. /package/dist/{data-structures → cjs/data-structures}/queue/index.d.ts +0 -0
  938. /package/dist/{data-structures → cjs/data-structures}/queue/index.js +0 -0
  939. /package/dist/{data-structures → cjs/data-structures}/stack/index.d.ts +0 -0
  940. /package/dist/{data-structures → cjs/data-structures}/stack/index.js +0 -0
  941. /package/dist/{data-structures → cjs/data-structures}/tree/index.d.ts +0 -0
  942. /package/dist/{data-structures → cjs/data-structures}/tree/index.js +0 -0
  943. /package/dist/{data-structures → cjs/data-structures}/trie/index.d.ts +0 -0
  944. /package/dist/{data-structures → cjs/data-structures}/trie/index.js +0 -0
  945. /package/dist/{index.d.ts → cjs/index.d.ts} +0 -0
  946. /package/dist/{index.js → cjs/index.js} +0 -0
  947. /package/dist/{interfaces → cjs/interfaces}/binary-tree.js +0 -0
  948. /package/dist/{interfaces → cjs/interfaces}/doubly-linked-list.d.ts +0 -0
  949. /package/dist/{interfaces → cjs/interfaces}/doubly-linked-list.js +0 -0
  950. /package/dist/{interfaces → cjs/interfaces}/heap.d.ts +0 -0
  951. /package/dist/{interfaces → cjs/interfaces}/heap.js +0 -0
  952. /package/dist/{interfaces → cjs/interfaces}/navigator.d.ts +0 -0
  953. /package/dist/{interfaces → cjs/interfaces}/navigator.js +0 -0
  954. /package/dist/{interfaces → cjs/interfaces}/priority-queue.d.ts +0 -0
  955. /package/dist/{interfaces → cjs/interfaces}/priority-queue.js +0 -0
  956. /package/dist/{interfaces → cjs/interfaces}/segment-tree.d.ts +0 -0
  957. /package/dist/{interfaces → cjs/interfaces}/segment-tree.js +0 -0
  958. /package/dist/{interfaces → cjs/interfaces}/singly-linked-list.d.ts +0 -0
  959. /package/dist/{interfaces → cjs/interfaces}/singly-linked-list.js +0 -0
  960. /package/dist/{interfaces → cjs/types/data-structures/binary-tree}/avl-tree.js +0 -0
  961. /package/dist/{types/data-structures/doubly-linked-list.d.ts → cjs/types/data-structures/binary-tree/binary-indexed-tree.d.ts} +0 -0
  962. /package/dist/{interfaces → cjs/types/data-structures/binary-tree}/bst.js +0 -0
  963. /package/dist/{types/data-structures → cjs/types/data-structures/binary-tree}/rb-tree.js +0 -0
  964. /package/dist/{types/data-structures → cjs/types/data-structures/binary-tree}/segment-tree.d.ts +0 -0
  965. /package/dist/{types/data-structures → cjs/types/data-structures/binary-tree}/segment-tree.js +0 -0
  966. /package/dist/{interfaces → cjs/types/data-structures/binary-tree}/tree-multiset.js +0 -0
  967. /package/dist/{interfaces → cjs/types/data-structures/graph}/abstract-graph.js +0 -0
  968. /package/dist/{types/data-structures → cjs/types/data-structures/graph}/directed-graph.d.ts +0 -0
  969. /package/dist/{types/data-structures → cjs/types/data-structures/graph}/directed-graph.js +0 -0
  970. /package/dist/{types/data-structures → cjs/types/data-structures/graph}/map-graph.d.ts +0 -0
  971. /package/dist/{types/data-structures → cjs/types/data-structures/graph}/map-graph.js +0 -0
  972. /package/dist/{types/data-structures/singly-linked-list.d.ts → cjs/types/data-structures/graph/undirected-graph.d.ts} +0 -0
  973. /package/dist/{interfaces → cjs/types/data-structures/graph}/undirected-graph.js +0 -0
  974. /package/dist/{types/helpers.d.ts → cjs/types/data-structures/hash/coordinate-map.d.ts} +0 -0
  975. /package/{lib/interfaces/abstract-binary-tree.js → dist/cjs/types/data-structures/hash/coordinate-set.d.ts} +0 -0
  976. /package/{lib/interfaces/abstract-graph.js → dist/cjs/types/data-structures/hash/hash-map.d.ts} +0 -0
  977. /package/{lib/interfaces/avl-tree.js → dist/cjs/types/data-structures/hash/hash-table.d.ts} +0 -0
  978. /package/dist/{types/data-structures/hash.d.ts → cjs/types/data-structures/hash/index.d.ts} +0 -0
  979. /package/{lib/interfaces/binary-tree.js → dist/cjs/types/data-structures/hash/tree-map.d.ts} +0 -0
  980. /package/{lib/interfaces/bst.js → dist/cjs/types/data-structures/hash/tree-set.d.ts} +0 -0
  981. /package/{lib/interfaces → dist/cjs/types/data-structures/heap}/heap.d.ts +0 -0
  982. /package/dist/{types/data-structures → cjs/types/data-structures/heap}/heap.js +0 -0
  983. /package/{lib/interfaces/directed-graph.js → dist/cjs/types/data-structures/heap/max-heap.d.ts} +0 -0
  984. /package/{lib/interfaces/doubly-linked-list.d.ts → dist/cjs/types/data-structures/heap/min-heap.d.ts} +0 -0
  985. /package/{lib/types/data-structures → dist/cjs/types/data-structures/linked-list}/doubly-linked-list.d.ts +0 -0
  986. /package/dist/{types/data-structures → cjs/types/data-structures/linked-list}/doubly-linked-list.js +0 -0
  987. /package/{lib/interfaces → dist/cjs/types/data-structures/linked-list}/singly-linked-list.d.ts +0 -0
  988. /package/dist/{types/data-structures → cjs/types/data-structures/linked-list}/singly-linked-list.js +0 -0
  989. /package/{lib/interfaces/doubly-linked-list.js → dist/cjs/types/data-structures/linked-list/skip-linked-list.d.ts} +0 -0
  990. /package/{lib/interfaces/heap.js → dist/cjs/types/data-structures/matrix/matrix.d.ts} +0 -0
  991. /package/{lib/interfaces/navigator.d.ts → dist/cjs/types/data-structures/matrix/matrix2d.d.ts} +0 -0
  992. /package/dist/{types/data-structures → cjs/types/data-structures/matrix}/navigator.d.ts +0 -0
  993. /package/dist/{types/data-structures → cjs/types/data-structures/matrix}/navigator.js +0 -0
  994. /package/{lib/interfaces/navigator.js → dist/cjs/types/data-structures/matrix/vector2d.d.ts} +0 -0
  995. /package/{lib → dist/cjs/types}/data-structures/priority-queue/index.d.ts +0 -0
  996. /package/{lib/interfaces/priority-queue.d.ts → dist/cjs/types/data-structures/priority-queue/max-priority-queue.d.ts} +0 -0
  997. /package/{lib/interfaces/priority-queue.js → dist/cjs/types/data-structures/priority-queue/min-priority-queue.d.ts} +0 -0
  998. /package/{lib/interfaces/rb-tree.js → dist/cjs/types/data-structures/priority-queue/priority-queue.d.ts} +0 -0
  999. /package/dist/{types/data-structures → cjs/types/data-structures/priority-queue}/priority-queue.js +0 -0
  1000. /package/{lib/interfaces/segment-tree.d.ts → dist/cjs/types/data-structures/queue/deque.d.ts} +0 -0
  1001. /package/{lib → dist/cjs/types}/data-structures/queue/index.d.ts +0 -0
  1002. /package/{lib/interfaces/segment-tree.js → dist/cjs/types/data-structures/queue/queue.d.ts} +0 -0
  1003. /package/{lib → dist/cjs/types}/data-structures/stack/index.d.ts +0 -0
  1004. /package/{lib/interfaces/singly-linked-list.js → dist/cjs/types/data-structures/stack/stack.d.ts} +0 -0
  1005. /package/{lib → dist/cjs/types}/data-structures/tree/index.d.ts +0 -0
  1006. /package/{lib/interfaces/tree-multiset.js → dist/cjs/types/data-structures/tree/tree.d.ts} +0 -0
  1007. /package/{lib → dist/cjs/types}/data-structures/trie/index.d.ts +0 -0
  1008. /package/{lib/interfaces/undirected-graph.js → dist/cjs/types/data-structures/trie/trie.d.ts} +0 -0
  1009. /package/dist/{types → cjs/types}/index.d.ts +0 -0
  1010. /package/dist/{types → cjs/types}/index.js +0 -0
  1011. /package/dist/{types → cjs/types}/utils/index.d.ts +0 -0
  1012. /package/dist/{types → cjs/types}/utils/index.js +0 -0
  1013. /package/dist/{types → cjs/types}/utils/utils.d.ts +0 -0
  1014. /package/dist/{types → cjs/types}/utils/utils.js +0 -0
  1015. /package/dist/{types → cjs/types}/utils/validate-type.d.ts +0 -0
  1016. /package/dist/{types → cjs/types}/utils/validate-type.js +0 -0
  1017. /package/dist/{utils → cjs/utils}/index.d.ts +0 -0
  1018. /package/dist/{utils → cjs/utils}/index.js +0 -0
  1019. /package/{lib → dist/mjs}/data-structures/graph/index.d.ts +0 -0
  1020. /package/{lib → dist/mjs}/data-structures/hash/tree-map.d.ts +0 -0
  1021. /package/{lib → dist/mjs}/data-structures/hash/tree-set.d.ts +0 -0
  1022. /package/{lib → dist/mjs}/data-structures/heap/index.d.ts +0 -0
  1023. /package/{lib → dist/mjs}/data-structures/index.d.ts +0 -0
  1024. /package/{lib → dist/mjs}/data-structures/linked-list/index.d.ts +0 -0
  1025. /package/{lib → dist/mjs}/data-structures/matrix/index.d.ts +0 -0
  1026. /package/{lib/data-structures/priority-queue/index.js → dist/mjs/data-structures/priority-queue/index.d.ts} +0 -0
  1027. /package/{lib/data-structures/queue/index.js → dist/mjs/data-structures/queue/index.d.ts} +0 -0
  1028. /package/{lib/data-structures/stack/index.js → dist/mjs/data-structures/stack/index.d.ts} +0 -0
  1029. /package/{lib/data-structures/tree/index.js → dist/mjs/data-structures/tree/index.d.ts} +0 -0
  1030. /package/{lib/data-structures/trie/index.js → dist/mjs/data-structures/trie/index.d.ts} +0 -0
  1031. /package/{lib → dist/mjs}/index.d.ts +0 -0
  1032. /package/{lib/types/data-structures/abstract-graph.js → dist/mjs/interfaces/doubly-linked-list.d.ts} +0 -0
  1033. /package/{lib/types/data-structures/avl-tree.js → dist/mjs/interfaces/heap.d.ts} +0 -0
  1034. /package/{lib/types/data-structures/binary-tree.js → dist/mjs/interfaces/navigator.d.ts} +0 -0
  1035. /package/{lib/types/data-structures/doubly-linked-list.js → dist/mjs/interfaces/priority-queue.d.ts} +0 -0
  1036. /package/{lib/types/data-structures/hash.js → dist/mjs/interfaces/segment-tree.d.ts} +0 -0
  1037. /package/{lib/types/data-structures → dist/mjs/interfaces}/singly-linked-list.d.ts +0 -0
  1038. /package/{lib/types/data-structures/heap.js → dist/mjs/types/data-structures/binary-tree/binary-indexed-tree.d.ts} +0 -0
  1039. /package/{lib/types/data-structures → dist/mjs/types/data-structures/binary-tree}/segment-tree.d.ts +0 -0
  1040. /package/{lib/types/data-structures → dist/mjs/types/data-structures/graph}/directed-graph.d.ts +0 -0
  1041. /package/{lib/types/data-structures → dist/mjs/types/data-structures/graph}/map-graph.d.ts +0 -0
  1042. /package/{lib/types/data-structures/map-graph.js → dist/mjs/types/data-structures/graph/undirected-graph.d.ts} +0 -0
  1043. /package/{lib/types/data-structures/navigator.js → dist/mjs/types/data-structures/hash/coordinate-map.d.ts} +0 -0
  1044. /package/{lib/types/data-structures/priority-queue.js → dist/mjs/types/data-structures/hash/coordinate-set.d.ts} +0 -0
  1045. /package/{lib/types/data-structures/segment-tree.js → dist/mjs/types/data-structures/hash/hash-map.d.ts} +0 -0
  1046. /package/{lib/types/data-structures/singly-linked-list.js → dist/mjs/types/data-structures/hash/hash-table.d.ts} +0 -0
  1047. /package/{lib/types/data-structures/hash.d.ts → dist/mjs/types/data-structures/hash/index.d.ts} +0 -0
  1048. /package/{lib/types/data-structures/tree-multiset.js → dist/mjs/types/data-structures/hash/tree-map.d.ts} +0 -0
  1049. /package/{lib/types/helpers.d.ts → dist/mjs/types/data-structures/hash/tree-set.d.ts} +0 -0
  1050. /package/{lib/types/helpers.js → dist/mjs/types/data-structures/heap/heap.d.ts} +0 -0
  1051. /package/{lib/types/utils/utils.js → dist/mjs/types/data-structures/heap/max-heap.d.ts} +0 -0
  1052. /package/{lib/types/utils/validate-type.js → dist/mjs/types/data-structures/heap/min-heap.d.ts} +0 -0
  1053. /package/{src/types/data-structures/doubly-linked-list.ts → dist/mjs/types/data-structures/linked-list/doubly-linked-list.d.ts} +0 -0
  1054. /package/{src/types/data-structures/singly-linked-list.ts → dist/mjs/types/data-structures/linked-list/singly-linked-list.d.ts} +0 -0
  1055. /package/{lib/types/data-structures → dist/mjs/types/data-structures/matrix}/navigator.d.ts +0 -0
  1056. /package/{lib → dist/mjs}/types/index.d.ts +0 -0
  1057. /package/{lib → dist/mjs}/types/utils/index.d.ts +0 -0
  1058. /package/{lib → dist/mjs}/types/utils/utils.d.ts +0 -0
  1059. /package/{lib → dist/mjs}/types/utils/validate-type.d.ts +0 -0
  1060. /package/{lib → dist/mjs}/utils/index.d.ts +0 -0
  1061. /package/src/types/data-structures/{segment-tree.ts → binary-tree/segment-tree.ts} +0 -0
  1062. /package/src/types/data-structures/{directed-graph.ts → graph/directed-graph.ts} +0 -0
  1063. /package/src/types/data-structures/{map-graph.ts → graph/map-graph.ts} +0 -0
  1064. /package/src/types/data-structures/{hash.ts → hash/index.ts} +0 -0
  1065. /package/{lib/utils/index.js → test/types/index.ts} +0 -0
@@ -1,1199 +0,0 @@
1
- "use strict";
2
- /**
3
- * data-structure-typed
4
- *
5
- * @author Tyler Zeng
6
- * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
7
- * @license MIT License
8
- */
9
- Object.defineProperty(exports, "__esModule", { value: true });
10
- exports.AbstractBinaryTree = exports.AbstractBinaryTreeNode = void 0;
11
- const utils_1 = require("../../utils");
12
- const types_1 = require("../../types");
13
- class AbstractBinaryTreeNode {
14
- /**
15
- * The constructor function initializes a BinaryTreeNode object with a key and an optional value.
16
- * @param {BinaryTreeNodeKey} key - The `key` parameter is of type `BinaryTreeNodeKey` and represents the unique identifier
17
- * of the binary tree node. It is used to distinguish one node from another in the binary tree.
18
- * @param {V} [val] - The "val" parameter is an optional parameter of type V. It represents the value that will be
19
- * stored in the binary tree node. If no value is provided, it will be set to undefined.
20
- */
21
- constructor(key, val) {
22
- this.key = key;
23
- this.val = val;
24
- }
25
- get left() {
26
- return this._left;
27
- }
28
- set left(v) {
29
- if (v) {
30
- v.parent = this;
31
- }
32
- this._left = v;
33
- }
34
- get right() {
35
- return this._right;
36
- }
37
- set right(v) {
38
- if (v) {
39
- v.parent = this;
40
- }
41
- this._right = v;
42
- }
43
- /**
44
- * The function determines the position of a node in a family tree structure.
45
- * @returns a value of type `FamilyPosition`.
46
- */
47
- get familyPosition() {
48
- const that = this;
49
- if (that.parent) {
50
- if (that.parent.left === that) {
51
- if (that.left || that.right) {
52
- return types_1.FamilyPosition.ROOT_LEFT;
53
- }
54
- else {
55
- return types_1.FamilyPosition.LEFT;
56
- }
57
- }
58
- else if (that.parent.right === that) {
59
- if (that.left || that.right) {
60
- return types_1.FamilyPosition.ROOT_RIGHT;
61
- }
62
- else {
63
- return types_1.FamilyPosition.RIGHT;
64
- }
65
- }
66
- else {
67
- return types_1.FamilyPosition.MAL_NODE;
68
- }
69
- }
70
- else {
71
- if (that.left || that.right) {
72
- return types_1.FamilyPosition.ROOT;
73
- }
74
- else {
75
- return types_1.FamilyPosition.ISOLATED;
76
- }
77
- }
78
- }
79
- }
80
- exports.AbstractBinaryTreeNode = AbstractBinaryTreeNode;
81
- class AbstractBinaryTree {
82
- /**
83
- * The protected constructor initializes the options for an abstract binary tree.
84
- * @param {AbstractBinaryTreeOptions} [options] - An optional object that contains configuration options for the binary
85
- * tree.
86
- */
87
- constructor(options) {
88
- // TODO placeholder node may need redesigned
89
- this._root = null;
90
- this._size = 0;
91
- this._loopType = types_1.LoopType.ITERATIVE;
92
- this.visitedKey = [];
93
- this.visitedVal = [];
94
- this.visitedNode = [];
95
- if (options !== undefined) {
96
- const { loopType = types_1.LoopType.ITERATIVE } = options;
97
- this._loopType = loopType;
98
- }
99
- this.clear();
100
- }
101
- get root() {
102
- return this._root;
103
- }
104
- get size() {
105
- return this._size;
106
- }
107
- get loopType() {
108
- return this._loopType;
109
- }
110
- /**
111
- * The `swapLocation` function swaps the location of two nodes in a binary tree.
112
- * @param {N} srcNode - The source node that you want to swap with the destination node.
113
- * @param {N} destNode - The `destNode` parameter represents the destination node where the values from `srcNode` will
114
- * be swapped to.
115
- * @returns The `destNode` is being returned.
116
- */
117
- swapLocation(srcNode, destNode) {
118
- const { key, val } = destNode;
119
- const tempNode = this.createNode(key, val);
120
- if (tempNode) {
121
- destNode.key = srcNode.key;
122
- destNode.val = srcNode.val;
123
- srcNode.key = tempNode.key;
124
- srcNode.val = tempNode.val;
125
- }
126
- return destNode;
127
- }
128
- /**
129
- * The clear() function resets the root, size, and maxKey properties to their initial values.
130
- */
131
- clear() {
132
- this._root = null;
133
- this._size = 0;
134
- this._clearResults();
135
- }
136
- /**
137
- * The function checks if the size of an object is equal to zero and returns a boolean value.
138
- * @returns A boolean value indicating whether the size of the object is 0 or not.
139
- */
140
- isEmpty() {
141
- return this.size === 0;
142
- }
143
- /**
144
- * When all leaf nodes are null, it will no longer be possible to add new entity nodes to this binary tree.
145
- * In this scenario, null nodes serve as "sentinel nodes," "virtual nodes," or "placeholder nodes."
146
- */
147
- /**
148
- * The `add` function adds a new node to a binary tree, either by ID or by creating a new node with a given value.
149
- * @param {BinaryTreeNodeKey | N | null} keyOrNode - The `keyOrNode` parameter can be either a `BinaryTreeNodeKey`, which
150
- * is a number representing the ID of a binary tree node, or it can be a `N` object, which represents a binary tree
151
- * node itself. It can also be `null` if no node is specified.
152
- * @param [val] - The `val` parameter is an optional value that can be assigned to the `val` property of the new node
153
- * being added to the binary tree.
154
- * @returns The function `add` returns either the inserted node (`N`), `null`, or `undefined`.
155
- */
156
- add(keyOrNode, val) {
157
- const _bfs = (root, newNode) => {
158
- const queue = [root];
159
- while (queue.length > 0) {
160
- const cur = queue.shift();
161
- if (cur) {
162
- if (newNode && cur.key === newNode.key)
163
- return;
164
- const inserted = this._addTo(newNode, cur);
165
- if (inserted !== undefined)
166
- return inserted;
167
- if (cur.left)
168
- queue.push(cur.left);
169
- if (cur.right)
170
- queue.push(cur.right);
171
- }
172
- else
173
- return;
174
- }
175
- return;
176
- };
177
- let inserted, needInsert;
178
- if (keyOrNode === null) {
179
- needInsert = null;
180
- }
181
- else if (typeof keyOrNode === 'number') {
182
- needInsert = this.createNode(keyOrNode, val);
183
- }
184
- else if (keyOrNode instanceof AbstractBinaryTreeNode) {
185
- needInsert = keyOrNode;
186
- }
187
- else {
188
- return;
189
- }
190
- const existNode = keyOrNode ? this.get(keyOrNode, 'key') : undefined;
191
- if (this.root) {
192
- if (existNode) {
193
- existNode.val = val;
194
- inserted = existNode;
195
- }
196
- else {
197
- inserted = _bfs(this.root, needInsert);
198
- }
199
- }
200
- else {
201
- this._setRoot(needInsert);
202
- if (needInsert !== null) {
203
- this._setSize(1);
204
- }
205
- else {
206
- this._setSize(0);
207
- }
208
- inserted = this.root;
209
- }
210
- return inserted;
211
- }
212
- /**
213
- * The `addMany` function takes an array of binary tree node IDs or nodes, and optionally an array of corresponding data
214
- * values, and adds them to the binary tree.
215
- * @param {(BinaryTreeNodeKey | null)[] | (N | null)[]} keysOrNodes - An array of BinaryTreeNodeKey or BinaryTreeNode
216
- * objects, or null values.
217
- * @param {N['val'][]} [data] - The `data` parameter is an optional array of values (`N['val'][]`) that corresponds to
218
- * the nodes or node IDs being added. It is used to set the value of each node being added. If `data` is not provided,
219
- * the value of the nodes will be `undefined`.
220
- * @returns The function `addMany` returns an array of `N`, `null`, or `undefined` values.
221
- */
222
- addMany(keysOrNodes, data) {
223
- // TODO not sure addMany not be run multi times
224
- const inserted = [];
225
- for (let i = 0; i < keysOrNodes.length; i++) {
226
- const keyOrNode = keysOrNodes[i];
227
- if (keyOrNode instanceof AbstractBinaryTreeNode) {
228
- inserted.push(this.add(keyOrNode.key, keyOrNode.val));
229
- continue;
230
- }
231
- if (keyOrNode === null) {
232
- inserted.push(this.add(null));
233
- continue;
234
- }
235
- const val = data === null || data === void 0 ? void 0 : data[i];
236
- inserted.push(this.add(keyOrNode, val));
237
- }
238
- return inserted;
239
- }
240
- /**
241
- * The `refill` function clears the binary tree and adds multiple nodes with the given IDs or nodes and optional data.
242
- * @param {(BinaryTreeNodeKey | N)[]} keysOrNodes - The `keysOrNodes` parameter is an array that can contain either
243
- * `BinaryTreeNodeKey` or `N` values.
244
- * @param {N[] | Array<N['val']>} [data] - The `data` parameter is an optional array of values that will be assigned to
245
- * the nodes being added. If provided, the length of the `data` array should be equal to the length of the `keysOrNodes`
246
- * array. Each value in the `data` array will be assigned to the
247
- * @returns The method is returning a boolean value.
248
- */
249
- refill(keysOrNodes, data) {
250
- this.clear();
251
- return keysOrNodes.length === this.addMany(keysOrNodes, data).length;
252
- }
253
- /**
254
- * The `remove` function in TypeScript is used to delete a node from a binary search tree and returns an array of objects
255
- * containing the deleted node and the node that needs to be balanced.
256
- * @param {N | BinaryTreeNodeKey} nodeOrKey - The `nodeOrKey` parameter can be either a node object (`N`) or a binary tree
257
- * node ID (`BinaryTreeNodeKey`).
258
- * @returns The function `remove` returns an array of `BinaryTreeDeletedResult<N>` objects.
259
- */
260
- remove(nodeOrKey) {
261
- const bstDeletedResult = [];
262
- if (!this.root)
263
- return bstDeletedResult;
264
- const curr = typeof nodeOrKey === 'number' ? this.get(nodeOrKey) : nodeOrKey;
265
- if (!curr)
266
- return bstDeletedResult;
267
- const parent = (curr === null || curr === void 0 ? void 0 : curr.parent) ? curr.parent : null;
268
- let needBalanced = null, orgCurrent = curr;
269
- if (!curr.left) {
270
- if (!parent) {
271
- if (curr.right !== undefined)
272
- this._setRoot(curr.right);
273
- }
274
- else {
275
- const { familyPosition: fp } = curr;
276
- if (fp === types_1.FamilyPosition.LEFT || fp === types_1.FamilyPosition.ROOT_LEFT) {
277
- parent.left = curr.right;
278
- }
279
- else if (fp === types_1.FamilyPosition.RIGHT || fp === types_1.FamilyPosition.ROOT_RIGHT) {
280
- parent.right = curr.right;
281
- }
282
- needBalanced = parent;
283
- }
284
- }
285
- else {
286
- const leftSubTreeRightMost = curr.left ? this.getRightMost(curr.left) : null;
287
- if (leftSubTreeRightMost) {
288
- const parentOfLeftSubTreeMax = leftSubTreeRightMost.parent;
289
- orgCurrent = this.swapLocation(curr, leftSubTreeRightMost);
290
- if (parentOfLeftSubTreeMax) {
291
- if (parentOfLeftSubTreeMax.right === leftSubTreeRightMost)
292
- parentOfLeftSubTreeMax.right = leftSubTreeRightMost.left;
293
- else
294
- parentOfLeftSubTreeMax.left = leftSubTreeRightMost.left;
295
- needBalanced = parentOfLeftSubTreeMax;
296
- }
297
- }
298
- }
299
- this._setSize(this.size - 1);
300
- bstDeletedResult.push({ deleted: orgCurrent, needBalanced });
301
- return bstDeletedResult;
302
- }
303
- /**
304
- * The function calculates the depth of a node in a binary tree.
305
- * @param {N | BinaryTreeNodeKey | null} beginRoot - The `beginRoot` parameter can be one of the following:
306
- * @returns the depth of the given node or binary tree.
307
- */
308
- getDepth(beginRoot = this.root) {
309
- if (typeof beginRoot === 'number')
310
- beginRoot = this.get(beginRoot, 'key');
311
- let depth = 0;
312
- while (beginRoot === null || beginRoot === void 0 ? void 0 : beginRoot.parent) {
313
- depth++;
314
- beginRoot = beginRoot.parent;
315
- }
316
- return depth;
317
- }
318
- /**
319
- * The `getHeight` function calculates the maximum height of a binary tree, either recursively or iteratively.
320
- * @param {N | BinaryTreeNodeKey | null} [beginRoot] - The `beginRoot` parameter is optional and can be of type `N` (a
321
- * generic type representing a node in a binary tree), `BinaryTreeNodeKey` (a type representing the ID of a binary tree
322
- * node), or `null`.
323
- * @returns the height of the binary tree.
324
- */
325
- getHeight(beginRoot = this.root) {
326
- if (typeof beginRoot === 'number')
327
- beginRoot = this.get(beginRoot, 'key');
328
- if (!beginRoot)
329
- return -1;
330
- if (this._loopType === types_1.LoopType.RECURSIVE) {
331
- const _getMaxHeight = (cur) => {
332
- if (!cur)
333
- return -1;
334
- const leftHeight = _getMaxHeight(cur.left);
335
- const rightHeight = _getMaxHeight(cur.right);
336
- return Math.max(leftHeight, rightHeight) + 1;
337
- };
338
- return _getMaxHeight(beginRoot);
339
- }
340
- else {
341
- if (!beginRoot) {
342
- return -1;
343
- }
344
- const stack = [{ node: beginRoot, depth: 0 }];
345
- let maxHeight = 0;
346
- while (stack.length > 0) {
347
- const { node, depth } = stack.pop();
348
- if (node.left) {
349
- stack.push({ node: node.left, depth: depth + 1 });
350
- }
351
- if (node.right) {
352
- stack.push({ node: node.right, depth: depth + 1 });
353
- }
354
- maxHeight = Math.max(maxHeight, depth);
355
- }
356
- return maxHeight;
357
- }
358
- }
359
- /**
360
- * The `getMinHeight` function calculates the minimum height of a binary tree using either a recursive or iterative
361
- * approach.
362
- * @param {N | null} [beginRoot] - The `beginRoot` parameter is an optional parameter of type `N` or `null`. It
363
- * represents the starting node from which to calculate the minimum height of a binary tree. If no value is provided
364
- * for `beginRoot`, the `this.root` property is used as the default value.
365
- * @returns The function `getMinHeight` returns the minimum height of the binary tree.
366
- */
367
- getMinHeight(beginRoot = this.root) {
368
- var _a, _b, _c;
369
- if (!beginRoot)
370
- return -1;
371
- if (this._loopType === types_1.LoopType.RECURSIVE) {
372
- const _getMinHeight = (cur) => {
373
- if (!cur)
374
- return 0;
375
- if (!cur.left && !cur.right)
376
- return 0;
377
- const leftMinHeight = _getMinHeight(cur.left);
378
- const rightMinHeight = _getMinHeight(cur.right);
379
- return Math.min(leftMinHeight, rightMinHeight) + 1;
380
- };
381
- return _getMinHeight(beginRoot);
382
- }
383
- else {
384
- const stack = [];
385
- let node = beginRoot, last = null;
386
- const depths = new Map();
387
- while (stack.length > 0 || node) {
388
- if (node) {
389
- stack.push(node);
390
- node = node.left;
391
- }
392
- else {
393
- node = stack[stack.length - 1];
394
- if (!node.right || last === node.right) {
395
- node = stack.pop();
396
- if (node) {
397
- const leftMinHeight = node.left ? (_a = depths.get(node.left)) !== null && _a !== void 0 ? _a : -1 : -1;
398
- const rightMinHeight = node.right ? (_b = depths.get(node.right)) !== null && _b !== void 0 ? _b : -1 : -1;
399
- depths.set(node, 1 + Math.min(leftMinHeight, rightMinHeight));
400
- last = node;
401
- node = null;
402
- }
403
- }
404
- else
405
- node = node.right;
406
- }
407
- }
408
- return (_c = depths.get(beginRoot)) !== null && _c !== void 0 ? _c : -1;
409
- }
410
- }
411
- /**
412
- * The function checks if a binary tree is perfectly balanced by comparing the minimum height and the height of the
413
- * tree.
414
- * @param {N | null} [beginRoot] - The parameter `beginRoot` is of type `N` or `null`. It represents the root node of a
415
- * tree or null if the tree is empty.
416
- * @returns The method is returning a boolean value.
417
- */
418
- isPerfectlyBalanced(beginRoot = this.root) {
419
- return this.getMinHeight(beginRoot) + 1 >= this.getHeight(beginRoot);
420
- }
421
- /**
422
- * The function `getNodes` returns an array of nodes that match a given property name and value in a binary tree.
423
- * @param {BinaryTreeNodeKey | N} nodeProperty - The `nodeProperty` parameter can be either a `BinaryTreeNodeKey` or a
424
- * generic type `N`. It represents the property of the binary tree node that you want to search for.
425
- * @param {BinaryTreeNodePropertyName} [propertyName] - The `propertyName` parameter is an optional parameter that
426
- * specifies the property name to use when searching for nodes. If not provided, it defaults to 'key'.
427
- * @param {boolean} [onlyOne] - The `onlyOne` parameter is an optional boolean parameter that determines whether to
428
- * return only one node that matches the given `nodeProperty` or `propertyName`. If `onlyOne` is set to `true`, the
429
- * function will stop traversing the tree and return the first matching node. If `only
430
- * @returns an array of nodes (type N).
431
- */
432
- getNodes(nodeProperty, propertyName = 'key', onlyOne = false) {
433
- if (!this.root)
434
- return [];
435
- const result = [];
436
- if (this.loopType === types_1.LoopType.RECURSIVE) {
437
- const _traverse = (cur) => {
438
- if (this._pushByPropertyNameStopOrNot(cur, result, nodeProperty, propertyName, onlyOne))
439
- return;
440
- if (!cur.left && !cur.right)
441
- return;
442
- cur.left && _traverse(cur.left);
443
- cur.right && _traverse(cur.right);
444
- };
445
- _traverse(this.root);
446
- }
447
- else {
448
- const queue = [this.root];
449
- while (queue.length > 0) {
450
- const cur = queue.shift();
451
- if (cur) {
452
- if (this._pushByPropertyNameStopOrNot(cur, result, nodeProperty, propertyName, onlyOne))
453
- return result;
454
- cur.left && queue.push(cur.left);
455
- cur.right && queue.push(cur.right);
456
- }
457
- }
458
- }
459
- return result;
460
- }
461
- /**
462
- * The function checks if a binary tree node has a specific property.
463
- * @param {BinaryTreeNodeKey | N} nodeProperty - The `nodeProperty` parameter can be either a `BinaryTreeNodeKey` or `N`.
464
- * It represents the property of the binary tree node that you want to check.
465
- * @param {BinaryTreeNodePropertyName} [propertyName] - The `propertyName` parameter is an optional parameter that
466
- * specifies the name of the property to be checked in the nodes. If not provided, it defaults to 'key'.
467
- * @returns a boolean value.
468
- */
469
- has(nodeProperty, propertyName = 'key') {
470
- // TODO may support finding node by value equal
471
- return this.getNodes(nodeProperty, propertyName).length > 0;
472
- }
473
- /**
474
- * The function returns the first node that matches the given property name and value, or null if no matching node is
475
- * found.
476
- * @param {BinaryTreeNodeKey | N} nodeProperty - The `nodeProperty` parameter can be either a `BinaryTreeNodeKey` or `N`.
477
- * It represents the property of the binary tree node that you want to search for.
478
- * @param {BinaryTreeNodePropertyName} [propertyName] - The `propertyName` parameter is an optional parameter that
479
- * specifies the property name to be used for searching the binary tree nodes. If this parameter is not provided, the
480
- * default value is set to `'key'`.
481
- * @returns either the value of the specified property of the node, or the node itself if no property name is provided.
482
- * If no matching node is found, it returns null.
483
- */
484
- get(nodeProperty, propertyName = 'key') {
485
- var _a;
486
- // TODO may support finding node by value equal
487
- return (_a = this.getNodes(nodeProperty, propertyName, true)[0]) !== null && _a !== void 0 ? _a : null;
488
- }
489
- /**
490
- * The function `getPathToRoot` returns an array of nodes representing the path from a given node to the root node, with
491
- * an option to reverse the order of the nodes.
492
- * @param {N} node - The `node` parameter represents a node in a tree structure. It is of type `N`, which could be any
493
- * type that represents a node in your specific implementation.
494
- * @param {boolean} [isReverse=true] - The `isReverse` parameter is a boolean flag that determines whether the resulting
495
- * path should be reversed or not. If `isReverse` is set to `true`, the path will be reversed before returning it. If
496
- * `isReverse` is set to `false` or not provided, the path will
497
- * @returns The function `getPathToRoot` returns an array of nodes (`N[]`).
498
- */
499
- getPathToRoot(node, isReverse = true) {
500
- // TODO to support get path through passing key
501
- const result = [];
502
- while (node.parent) {
503
- // Array.push + Array.reverse is more efficient than Array.unshift
504
- // TODO may consider using Deque, so far this is not the performance bottleneck
505
- result.push(node);
506
- node = node.parent;
507
- }
508
- result.push(node);
509
- return isReverse ? result.reverse() : result;
510
- }
511
- /**
512
- * The function `getLeftMost` returns the leftmost node in a binary tree, starting from a specified node or the root if
513
- * no node is specified.
514
- * @param {N | BinaryTreeNodeKey | null} [beginRoot] - The `beginRoot` parameter is optional and can be of type `N` (a
515
- * generic type representing a node in a binary tree), `BinaryTreeNodeKey` (a type representing the ID of a binary tree
516
- * node), or `null`.
517
- * @returns The function `getLeftMost` returns the leftmost node in a binary tree. If the `beginRoot` parameter is
518
- * provided, it starts the traversal from that node. If `beginRoot` is not provided or is `null`, it starts the traversal
519
- * from the root of the binary tree. The function returns the leftmost node found during the traversal. If no leftmost
520
- * node is found (
521
- */
522
- getLeftMost(beginRoot = this.root) {
523
- if (typeof beginRoot === 'number')
524
- beginRoot = this.get(beginRoot, 'key');
525
- if (!beginRoot)
526
- return beginRoot;
527
- if (this._loopType === types_1.LoopType.RECURSIVE) {
528
- const _traverse = (cur) => {
529
- if (!cur.left)
530
- return cur;
531
- return _traverse(cur.left);
532
- };
533
- return _traverse(beginRoot);
534
- }
535
- else {
536
- // Indirect implementation of iteration using tail recursion optimization
537
- const _traverse = (0, utils_1.trampoline)((cur) => {
538
- if (!cur.left)
539
- return cur;
540
- return _traverse.cont(cur.left);
541
- });
542
- return _traverse(beginRoot);
543
- }
544
- }
545
- /**
546
- * The `getRightMost` function returns the rightmost node in a binary tree, either recursively or iteratively using tail
547
- * recursion optimization.
548
- * @param {N | null} [beginRoot] - The `node` parameter is an optional parameter of type `N` or `null`. It represents the
549
- * starting node from which we want to find the rightmost node. If no node is provided, the function will default to
550
- * using the root node of the data structure.
551
- * @returns The `getRightMost` function returns the rightmost node in a binary tree. If the `node` parameter is provided,
552
- * it returns the rightmost node starting from that node. If the `node` parameter is not provided, it returns the
553
- * rightmost node starting from the root of the binary tree.
554
- */
555
- getRightMost(beginRoot = this.root) {
556
- // TODO support get right most by passing key in
557
- if (!beginRoot)
558
- return beginRoot;
559
- if (this._loopType === types_1.LoopType.RECURSIVE) {
560
- const _traverse = (cur) => {
561
- if (!cur.right)
562
- return cur;
563
- return _traverse(cur.right);
564
- };
565
- return _traverse(beginRoot);
566
- }
567
- else {
568
- // Indirect implementation of iteration using tail recursion optimization
569
- const _traverse = (0, utils_1.trampoline)((cur) => {
570
- if (!cur.right)
571
- return cur;
572
- return _traverse.cont(cur.right);
573
- });
574
- return _traverse(beginRoot);
575
- }
576
- }
577
- /**
578
- * The function checks if a binary search tree is valid by traversing it either recursively or iteratively.
579
- * @param {N | null} node - The `node` parameter represents the root node of a binary search tree (BST).
580
- * @returns a boolean value.
581
- */
582
- isSubtreeBST(node) {
583
- // TODO there is a bug
584
- if (!node)
585
- return true;
586
- if (this._loopType === types_1.LoopType.RECURSIVE) {
587
- const dfs = (cur, min, max) => {
588
- if (!cur)
589
- return true;
590
- if (cur.key <= min || cur.key >= max)
591
- return false;
592
- return dfs(cur.left, min, cur.key) && dfs(cur.right, cur.key, max);
593
- };
594
- return dfs(node, Number.MIN_SAFE_INTEGER, Number.MAX_SAFE_INTEGER);
595
- }
596
- else {
597
- const stack = [];
598
- let prev = Number.MIN_SAFE_INTEGER, curr = node;
599
- while (curr || stack.length > 0) {
600
- while (curr) {
601
- stack.push(curr);
602
- curr = curr.left;
603
- }
604
- curr = stack.pop();
605
- if (!curr || prev >= curr.key)
606
- return false;
607
- prev = curr.key;
608
- curr = curr.right;
609
- }
610
- return true;
611
- }
612
- }
613
- /**
614
- * The function isBST checks if the binary tree is valid binary search tree.
615
- * @returns The `isBST()` function is returning a boolean value.
616
- */
617
- isBST() {
618
- return this.isSubtreeBST(this.root);
619
- }
620
- /**
621
- * The function calculates the size of a subtree by traversing it either recursively or iteratively.
622
- * @param {N | null | undefined} subTreeRoot - The `subTreeRoot` parameter represents the root node of a subtree in a
623
- * binary tree.
624
- * @returns the size of the subtree rooted at `subTreeRoot`.
625
- */
626
- getSubTreeSize(subTreeRoot) {
627
- // TODO support key passed in
628
- let size = 0;
629
- if (!subTreeRoot)
630
- return size;
631
- if (this._loopType === types_1.LoopType.RECURSIVE) {
632
- const _traverse = (cur) => {
633
- size++;
634
- cur.left && _traverse(cur.left);
635
- cur.right && _traverse(cur.right);
636
- };
637
- _traverse(subTreeRoot);
638
- return size;
639
- }
640
- else {
641
- const stack = [subTreeRoot];
642
- while (stack.length > 0) {
643
- const cur = stack.pop();
644
- size++;
645
- cur.right && stack.push(cur.right);
646
- cur.left && stack.push(cur.left);
647
- }
648
- return size;
649
- }
650
- }
651
- /**
652
- * The function `subTreeSum` calculates the sum of a specified property in a binary tree or subtree.
653
- * @param {N | BinaryTreeNodeKey | null} subTreeRoot - The `subTreeRoot` parameter represents the root node of a binary
654
- * tree or the ID of a binary tree node. It can also be `null` if there is no subtree.
655
- * @param {BinaryTreeNodePropertyName} [propertyName] - propertyName is an optional parameter that specifies the
656
- * property of the binary tree node to use for calculating the sum. It can be either 'key' or 'val'. If propertyName is
657
- * not provided, it defaults to 'key'.
658
- * @returns a number, which is the sum of the values of the specified property in the subtree rooted at `subTreeRoot`.
659
- */
660
- subTreeSum(subTreeRoot, propertyName = 'key') {
661
- if (typeof subTreeRoot === 'number')
662
- subTreeRoot = this.get(subTreeRoot, 'key');
663
- if (!subTreeRoot)
664
- return 0;
665
- let sum = 0;
666
- const _sumByProperty = (cur) => {
667
- let needSum;
668
- switch (propertyName) {
669
- case 'key':
670
- needSum = cur.key;
671
- break;
672
- case 'val':
673
- needSum = typeof cur.val === 'number' ? cur.val : 0;
674
- break;
675
- default:
676
- needSum = cur.key;
677
- break;
678
- }
679
- return needSum;
680
- };
681
- if (this._loopType === types_1.LoopType.RECURSIVE) {
682
- const _traverse = (cur) => {
683
- sum += _sumByProperty(cur);
684
- cur.left && _traverse(cur.left);
685
- cur.right && _traverse(cur.right);
686
- };
687
- _traverse(subTreeRoot);
688
- }
689
- else {
690
- const stack = [subTreeRoot];
691
- while (stack.length > 0) {
692
- const cur = stack.pop();
693
- sum += _sumByProperty(cur);
694
- cur.right && stack.push(cur.right);
695
- cur.left && stack.push(cur.left);
696
- }
697
- }
698
- return sum;
699
- }
700
- /**
701
- * The function `subTreeAdd` adds a delta value to a specified property of each node in a subtree.
702
- * @param {N | BinaryTreeNodeKey | null} subTreeRoot - The `subTreeRoot` parameter represents the root node of a binary
703
- * tree or the ID of a node in the binary tree. It can also be `null` if there is no subtree to add to.
704
- * @param {number} delta - The `delta` parameter is a number that represents the amount by which the property value of
705
- * each node in the subtree should be incremented.
706
- * @param {BinaryTreeNodePropertyName} [propertyName] - The `propertyName` parameter is an optional parameter that
707
- * specifies the property of the binary tree node that should be modified. If not provided, it defaults to 'key'.
708
- * @returns a boolean value.
709
- */
710
- subTreeAdd(subTreeRoot, delta, propertyName = 'key') {
711
- if (typeof subTreeRoot === 'number')
712
- subTreeRoot = this.get(subTreeRoot, 'key');
713
- if (!subTreeRoot)
714
- return false;
715
- const _addByProperty = (cur) => {
716
- switch (propertyName) {
717
- case 'key':
718
- cur.key += delta;
719
- break;
720
- default:
721
- cur.key += delta;
722
- break;
723
- }
724
- };
725
- if (this._loopType === types_1.LoopType.RECURSIVE) {
726
- const _traverse = (cur) => {
727
- _addByProperty(cur);
728
- cur.left && _traverse(cur.left);
729
- cur.right && _traverse(cur.right);
730
- };
731
- _traverse(subTreeRoot);
732
- }
733
- else {
734
- const stack = [subTreeRoot];
735
- while (stack.length > 0) {
736
- const cur = stack.pop();
737
- _addByProperty(cur);
738
- cur.right && stack.push(cur.right);
739
- cur.left && stack.push(cur.left);
740
- }
741
- }
742
- return true;
743
- }
744
- /**
745
- * The bfs function performs a breadth-first search on a binary tree, accumulating properties of each node based on a specified property name.
746
- * @param {NodeOrPropertyName} [nodeOrPropertyName] - An optional parameter that represents either a node or a property name.
747
- * If a node is provided, the bfs algorithm will be performed starting from that node.
748
- * If a property name is provided, the bfs algorithm will be performed starting from the root node, accumulating the specified property.
749
- * @returns An instance of the `AbstractBinaryTreeNodeProperties` class with generic type `N`.
750
- */
751
- bfs(nodeOrPropertyName = 'key') {
752
- this._clearResults();
753
- const queue = [this.root];
754
- while (queue.length !== 0) {
755
- const cur = queue.shift();
756
- if (cur) {
757
- this._accumulatedByPropertyName(cur, nodeOrPropertyName);
758
- if ((cur === null || cur === void 0 ? void 0 : cur.left) !== null)
759
- queue.push(cur.left);
760
- if ((cur === null || cur === void 0 ? void 0 : cur.right) !== null)
761
- queue.push(cur.right);
762
- }
763
- }
764
- return this._getResultByPropertyName(nodeOrPropertyName);
765
- }
766
- /**
767
- * The dfs function performs a depth-first search traversal on a binary tree and returns the accumulated properties of
768
- * each node based on the specified pattern and property name.
769
- * @param {'in' | 'pre' | 'post'} [pattern] - The traversal pattern: 'in' (in-order), 'pre' (pre-order), or 'post' (post-order).
770
- * @param {NodeOrPropertyName} [nodeOrPropertyName] - The name of a property of the nodes in the binary tree. This property will be used to accumulate values during the depth-first search traversal. If no `nodeOrPropertyName` is provided, the default value is `'key'`.
771
- * @returns an instance of the AbstractBinaryTreeNodeProperties class, which contains the accumulated properties of the binary tree nodes based on the specified pattern and node or property name.
772
- */
773
- dfs(pattern = 'in', nodeOrPropertyName = 'key') {
774
- this._clearResults();
775
- const _traverse = (node) => {
776
- switch (pattern) {
777
- case 'in':
778
- if (node.left)
779
- _traverse(node.left);
780
- this._accumulatedByPropertyName(node, nodeOrPropertyName);
781
- if (node.right)
782
- _traverse(node.right);
783
- break;
784
- case 'pre':
785
- this._accumulatedByPropertyName(node, nodeOrPropertyName);
786
- if (node.left)
787
- _traverse(node.left);
788
- if (node.right)
789
- _traverse(node.right);
790
- break;
791
- case 'post':
792
- if (node.left)
793
- _traverse(node.left);
794
- if (node.right)
795
- _traverse(node.right);
796
- this._accumulatedByPropertyName(node, nodeOrPropertyName);
797
- break;
798
- }
799
- };
800
- this.root && _traverse(this.root);
801
- return this._getResultByPropertyName(nodeOrPropertyName);
802
- }
803
- /**
804
- * The dfsIterative function performs an iterative depth-first search traversal on a binary tree, with the option to
805
- * specify the traversal pattern and the property name to accumulate results by.
806
- * @param {'in' | 'pre' | 'post'} [pattern] - The traversal pattern: 'in' (in-order), 'pre' (pre-order), or 'post' (post-order).
807
- * @param {NodeOrPropertyName} [nodeOrPropertyName] - The name of a property of the nodes in the binary tree. This property will be used to accumulate values during the depth-first search traversal. By default, it is set to `'key'`.
808
- * @returns An object of type AbstractBinaryTreeNodeProperties<N>.
809
- */
810
- dfsIterative(pattern = 'in', nodeOrPropertyName = 'key') {
811
- this._clearResults();
812
- if (!this.root)
813
- return this._getResultByPropertyName(nodeOrPropertyName);
814
- // 0: visit, 1: print
815
- const stack = [{ opt: 0, node: this.root }];
816
- while (stack.length > 0) {
817
- const cur = stack.pop();
818
- if (!cur || !cur.node)
819
- continue;
820
- if (cur.opt === 1) {
821
- this._accumulatedByPropertyName(cur.node, nodeOrPropertyName);
822
- }
823
- else {
824
- switch (pattern) {
825
- case 'in':
826
- stack.push({ opt: 0, node: cur.node.right });
827
- stack.push({ opt: 1, node: cur.node });
828
- stack.push({ opt: 0, node: cur.node.left });
829
- break;
830
- case 'pre':
831
- stack.push({ opt: 0, node: cur.node.right });
832
- stack.push({ opt: 0, node: cur.node.left });
833
- stack.push({ opt: 1, node: cur.node });
834
- break;
835
- case 'post':
836
- stack.push({ opt: 1, node: cur.node });
837
- stack.push({ opt: 0, node: cur.node.right });
838
- stack.push({ opt: 0, node: cur.node.left });
839
- break;
840
- default:
841
- stack.push({ opt: 0, node: cur.node.right });
842
- stack.push({ opt: 1, node: cur.node });
843
- stack.push({ opt: 0, node: cur.node.left });
844
- break;
845
- }
846
- }
847
- }
848
- return this._getResultByPropertyName(nodeOrPropertyName);
849
- }
850
- /**
851
- * The `levelIterative` function performs a level-order traversal on a binary tree and returns the values of the nodes
852
- * in an array, based on a specified property name.
853
- * @param {N | null} node - The `node` parameter is a BinaryTreeNode object representing the starting
854
- * node for the level order traversal. It can be null if no specific node is provided, in which case the root node of
855
- * the tree is used as the starting node.
856
- * @param {NodeOrPropertyName} [nodeOrPropertyName] - The `nodeOrPropertyName` parameter is an optional parameter that
857
- * can be either a `BinaryTreeNode` property name or the string `'key'`. If a property name is provided, the function
858
- * will accumulate results based on that property. If no property name is provided, the function will default to
859
- * accumulating results based on the 'key' property.
860
- * @returns An object of type `AbstractBinaryTreeNodeProperties<N>`.
861
- */
862
- levelIterative(node = this.root, nodeOrPropertyName = 'key') {
863
- if (!node)
864
- return [];
865
- this._clearResults();
866
- const queue = [node];
867
- while (queue.length > 0) {
868
- const cur = queue.shift();
869
- if (cur) {
870
- this._accumulatedByPropertyName(cur, nodeOrPropertyName);
871
- if (cur.left) {
872
- queue.push(cur.left);
873
- }
874
- if (cur.right) {
875
- queue.push(cur.right);
876
- }
877
- }
878
- }
879
- return this._getResultByPropertyName(nodeOrPropertyName);
880
- }
881
- /**
882
- * The `listLevels` function collects nodes from a binary tree by a specified property and organizes them into levels.
883
- * @param {N | null} node - The `node` parameter is a BinaryTreeNode object or null. It represents the root node of a binary tree. If it is null, the function will use the root node of the current binary tree instance.
884
- * @param {NodeOrPropertyName} [nodeOrPropertyName] - The `nodeOrPropertyName` parameter is an optional parameter that specifies the property of the `BinaryTreeNode` object to collect at each level. It can be one of the following values: 'key', 'val', or 'node'. If not provided, it defaults to 'key'.
885
- * @returns A 2D array of `AbstractBinaryTreeNodeProperty<N>` objects.
886
- */
887
- listLevels(node = this.root, nodeOrPropertyName = 'key') {
888
- if (!node)
889
- return [];
890
- const levelsNodes = [];
891
- const collectByProperty = (node, level) => {
892
- switch (nodeOrPropertyName) {
893
- case 'key':
894
- levelsNodes[level].push(node.key);
895
- break;
896
- case 'val':
897
- levelsNodes[level].push(node.val);
898
- break;
899
- case 'node':
900
- levelsNodes[level].push(node);
901
- break;
902
- default:
903
- levelsNodes[level].push(node.key);
904
- break;
905
- }
906
- };
907
- if (this.loopType === types_1.LoopType.RECURSIVE) {
908
- const _recursive = (node, level) => {
909
- if (!levelsNodes[level])
910
- levelsNodes[level] = [];
911
- collectByProperty(node, level);
912
- if (node.left)
913
- _recursive(node.left, level + 1);
914
- if (node.right)
915
- _recursive(node.right, level + 1);
916
- };
917
- _recursive(node, 0);
918
- }
919
- else {
920
- const stack = [[node, 0]];
921
- while (stack.length > 0) {
922
- const head = stack.pop();
923
- const [node, level] = head;
924
- if (!levelsNodes[level])
925
- levelsNodes[level] = [];
926
- collectByProperty(node, level);
927
- if (node.right)
928
- stack.push([node.right, level + 1]);
929
- if (node.left)
930
- stack.push([node.left, level + 1]);
931
- }
932
- }
933
- return levelsNodes;
934
- }
935
- /**
936
- * The function returns the predecessor of a given node in a binary tree.
937
- * @param node - The parameter `node` is a BinaryTreeNode object, representing a node in a binary tree.
938
- * @returns the predecessor of the given node in a binary tree.
939
- */
940
- getPredecessor(node) {
941
- if (node.left) {
942
- let predecessor = node.left;
943
- while (!predecessor || (predecessor.right && predecessor.right !== node)) {
944
- if (predecessor) {
945
- predecessor = predecessor.right;
946
- }
947
- }
948
- return predecessor;
949
- }
950
- else {
951
- return node;
952
- }
953
- }
954
- /**
955
- * The `morris` function performs an in-order, pre-order, or post-order traversal on a binary tree using the Morris traversal algorithm.
956
- * @param {'in' | 'pre' | 'post'} [pattern] - The traversal pattern: 'in' (in-order), 'pre' (pre-order), or 'post' (post-order).
957
- * @param {NodeOrPropertyName} [nodeOrPropertyName] - The property name of the nodes to retrieve or perform operations on during the traversal. It can be any valid property name of the nodes in the binary tree. If not provided, it defaults to 'key'.
958
- * @returns An array of AbstractBinaryTreeNodeProperties<N> objects.
959
- */
960
- morris(pattern = 'in', nodeOrPropertyName = 'key') {
961
- if (this.root === null)
962
- return [];
963
- this._clearResults();
964
- let cur = this.root;
965
- const _reverseEdge = (node) => {
966
- let pre = null;
967
- let next = null;
968
- while (node) {
969
- next = node.right;
970
- node.right = pre;
971
- pre = node;
972
- node = next;
973
- }
974
- return pre;
975
- };
976
- const _printEdge = (node) => {
977
- const tail = _reverseEdge(node);
978
- let cur = tail;
979
- while (cur) {
980
- this._accumulatedByPropertyName(cur, nodeOrPropertyName);
981
- cur = cur.right;
982
- }
983
- _reverseEdge(tail);
984
- };
985
- switch (pattern) {
986
- case 'in':
987
- while (cur) {
988
- if (cur.left) {
989
- const predecessor = this.getPredecessor(cur);
990
- if (!predecessor.right) {
991
- predecessor.right = cur;
992
- cur = cur.left;
993
- continue;
994
- }
995
- else {
996
- predecessor.right = null;
997
- }
998
- }
999
- this._accumulatedByPropertyName(cur, nodeOrPropertyName);
1000
- cur = cur.right;
1001
- }
1002
- break;
1003
- case 'pre':
1004
- while (cur) {
1005
- if (cur.left) {
1006
- const predecessor = this.getPredecessor(cur);
1007
- if (!predecessor.right) {
1008
- predecessor.right = cur;
1009
- this._accumulatedByPropertyName(cur, nodeOrPropertyName);
1010
- cur = cur.left;
1011
- continue;
1012
- }
1013
- else {
1014
- predecessor.right = null;
1015
- }
1016
- }
1017
- else {
1018
- this._accumulatedByPropertyName(cur, nodeOrPropertyName);
1019
- }
1020
- cur = cur.right;
1021
- }
1022
- break;
1023
- case 'post':
1024
- while (cur) {
1025
- if (cur.left) {
1026
- const predecessor = this.getPredecessor(cur);
1027
- if (predecessor.right === null) {
1028
- predecessor.right = cur;
1029
- cur = cur.left;
1030
- continue;
1031
- }
1032
- else {
1033
- predecessor.right = null;
1034
- _printEdge(cur.left);
1035
- }
1036
- }
1037
- cur = cur.right;
1038
- }
1039
- _printEdge(this.root);
1040
- break;
1041
- }
1042
- return this._getResultByPropertyName(nodeOrPropertyName);
1043
- }
1044
- /**
1045
- * The function adds a new node to a binary tree if there is an available position.
1046
- * @param {N | null} newNode - The `newNode` parameter is of type `N | null`, which means it can either be a node of
1047
- * type `N` or `null`. It represents the node that you want to add to the binary tree.
1048
- * @param {N} parent - The parent parameter is of type N, which represents a node in a binary tree.
1049
- * @returns either the left or right child node of the parent node, depending on which child is available for adding
1050
- * the new node. If a new node is added, the function also updates the size of the binary tree. If neither the left nor
1051
- * right child is available, the function returns undefined. If the parent node is null, the function also returns
1052
- * undefined.
1053
- */
1054
- _addTo(newNode, parent) {
1055
- if (parent) {
1056
- // When all leaf nodes are null, it will no longer be possible to add new entity nodes to this binary tree.
1057
- // In this scenario, null nodes serve as "sentinel nodes," "virtual nodes," or "placeholder nodes."
1058
- if (parent.left === undefined) {
1059
- parent.left = newNode;
1060
- if (newNode) {
1061
- this._setSize(this.size + 1);
1062
- }
1063
- return parent.left;
1064
- }
1065
- else if (parent.right === undefined) {
1066
- parent.right = newNode;
1067
- if (newNode) {
1068
- this._setSize(this.size + 1);
1069
- }
1070
- return parent.right;
1071
- }
1072
- else {
1073
- return;
1074
- }
1075
- }
1076
- else {
1077
- return;
1078
- }
1079
- }
1080
- /**
1081
- * The function sets the loop type for a protected variable.
1082
- * @param {LoopType} value - The value parameter is of type LoopType.
1083
- */
1084
- _setLoopType(value) {
1085
- this._loopType = value;
1086
- }
1087
- /**
1088
- * The function sets the root property of an object to a given value, and if the value is not null, it also sets the
1089
- * parent property of the value to undefined.
1090
- * @param {N | null} v - The parameter `v` is of type `N | null`, which means it can either be of type `N` or `null`.
1091
- */
1092
- _setRoot(v) {
1093
- if (v) {
1094
- v.parent = undefined;
1095
- }
1096
- this._root = v;
1097
- }
1098
- /**
1099
- * The function sets the size of a protected variable.
1100
- * @param {number} v - number
1101
- */
1102
- _setSize(v) {
1103
- this._size = v;
1104
- }
1105
- /**
1106
- * The function `_clearResults` resets the values of several arrays used for tracking visited nodes and their
1107
- * properties.
1108
- */
1109
- _clearResults() {
1110
- this.visitedKey = [];
1111
- this.visitedVal = [];
1112
- this.visitedNode = [];
1113
- }
1114
- /**
1115
- * The function checks if a given property of a binary tree node matches a specified value, and if so, adds the node to
1116
- * a result array.
1117
- * @param {N} cur - The current node being processed.
1118
- * @param {(N | null | undefined)[]} result - An array that stores the matching nodes.
1119
- * @param {BinaryTreeNodeKey | N} nodeProperty - The `nodeProperty` parameter is either a `BinaryTreeNodeKey` or a `N`
1120
- * type. It represents the property value that we are comparing against in the switch statement.
1121
- * @param {BinaryTreeNodePropertyName} [propertyName] - The `propertyName` parameter is an optional parameter that
1122
- * specifies the property name to compare against when pushing nodes into the `result` array. It can be either `'key'`
1123
- * or `'val'`. If it is not provided or is not equal to `'key'` or `'val'`, the
1124
- * @param {boolean} [onlyOne] - The `onlyOne` parameter is an optional boolean parameter that determines whether to
1125
- * stop after finding the first matching node or continue searching for all matching nodes. If `onlyOne` is set to
1126
- * `true`, the function will stop after finding the first matching node and return `true`. If `onlyOne
1127
- * @returns a boolean value indicating whether only one matching node should be pushed into the result array.
1128
- */
1129
- _pushByPropertyNameStopOrNot(cur, result, nodeProperty, propertyName = 'key', onlyOne = false) {
1130
- switch (propertyName) {
1131
- case 'key':
1132
- if (cur.key === nodeProperty) {
1133
- result.push(cur);
1134
- return onlyOne;
1135
- }
1136
- break;
1137
- case 'val':
1138
- if (cur.val === nodeProperty) {
1139
- result.push(cur);
1140
- return onlyOne;
1141
- }
1142
- break;
1143
- default:
1144
- if (cur.key === nodeProperty) {
1145
- result.push(cur);
1146
- return onlyOne;
1147
- }
1148
- break;
1149
- }
1150
- }
1151
- /**
1152
- * The function `_accumulatedByPropertyName` accumulates values from a given node based on the specified property name.
1153
- * @param {N} node - The `node` parameter is of type `N`, which represents a node in a data structure.
1154
- * @param {NodeOrPropertyName} [nodeOrPropertyName] - The `nodeOrPropertyName` parameter is an optional parameter that
1155
- * can be either a string representing a property name or a reference to a `Node` object. If it is a string, it
1156
- * specifies the property name to be used for accumulating values. If it is a `Node` object, it specifies
1157
- */
1158
- _accumulatedByPropertyName(node, nodeOrPropertyName = 'key') {
1159
- switch (nodeOrPropertyName) {
1160
- case 'key':
1161
- this.visitedKey.push(node.key);
1162
- break;
1163
- case 'val':
1164
- this.visitedVal.push(node.val);
1165
- break;
1166
- case 'node':
1167
- this.visitedNode.push(node);
1168
- break;
1169
- default:
1170
- this.visitedKey.push(node.key);
1171
- break;
1172
- }
1173
- }
1174
- /**
1175
- * The time complexity of Morris traversal is O(n), it may slower than others
1176
- * The space complexity Morris traversal is O(1) because no using stack
1177
- */
1178
- /**
1179
- * The function `_getResultByPropertyName` returns the corresponding property value based on the given node or property
1180
- * name.
1181
- * @param {NodeOrPropertyName} [nodeOrPropertyName] - The parameter `nodeOrPropertyName` is an optional parameter that
1182
- * can accept either a `NodeOrPropertyName` type or be undefined.
1183
- * @returns The method `_getResultByPropertyName` returns an instance of `AbstractBinaryTreeNodeProperties<N>`.
1184
- */
1185
- _getResultByPropertyName(nodeOrPropertyName = 'key') {
1186
- switch (nodeOrPropertyName) {
1187
- case 'key':
1188
- return this.visitedKey;
1189
- case 'val':
1190
- return this.visitedVal;
1191
- case 'node':
1192
- return this.visitedNode;
1193
- default:
1194
- return this.visitedKey;
1195
- }
1196
- }
1197
- }
1198
- exports.AbstractBinaryTree = AbstractBinaryTree;
1199
- //# sourceMappingURL=abstract-binary-tree.js.map