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,1556 +0,0 @@
1
- /**
2
- * data-structure-typed
3
- *
4
- * @author Tyler Zeng
5
- * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
6
- * @license MIT License
7
- */
8
-
9
- import {trampoline} from '../../utils';
10
- import type {
11
- AbstractBinaryTreeNodeNested,
12
- AbstractBinaryTreeNodeProperties,
13
- AbstractBinaryTreeNodeProperty,
14
- BinaryTreeDeletedResult,
15
- BinaryTreeNodeKey,
16
- BinaryTreeNodePropertyName,
17
- DFSOrderPattern,
18
- NodeOrPropertyName
19
- } from '../../types';
20
- import {AbstractBinaryTreeOptions, FamilyPosition, LoopType} from '../../types';
21
- import {IAbstractBinaryTree, IAbstractBinaryTreeNode} from '../../interfaces';
22
-
23
- export abstract class AbstractBinaryTreeNode<
24
- V = any,
25
- NEIGHBOR extends AbstractBinaryTreeNode<V, NEIGHBOR> = AbstractBinaryTreeNodeNested<V>
26
- > implements IAbstractBinaryTreeNode<V, NEIGHBOR>
27
- {
28
- /**
29
- * The constructor function initializes a BinaryTreeNode object with a key and an optional value.
30
- * @param {BinaryTreeNodeKey} key - The `key` parameter is of type `BinaryTreeNodeKey` and represents the unique identifier
31
- * of the binary tree node. It is used to distinguish one node from another in the binary tree.
32
- * @param {V} [val] - The "val" parameter is an optional parameter of type V. It represents the value that will be
33
- * stored in the binary tree node. If no value is provided, it will be set to undefined.
34
- */
35
- protected constructor(key: BinaryTreeNodeKey, val?: V) {
36
- this.key = key;
37
- this.val = val;
38
- }
39
-
40
- key: BinaryTreeNodeKey;
41
-
42
- val: V | undefined;
43
-
44
- private _left: NEIGHBOR | null | undefined;
45
-
46
- get left(): NEIGHBOR | null | undefined {
47
- return this._left;
48
- }
49
-
50
- set left(v: NEIGHBOR | null | undefined) {
51
- if (v) {
52
- v.parent = this as unknown as NEIGHBOR;
53
- }
54
- this._left = v;
55
- }
56
-
57
- private _right: NEIGHBOR | null | undefined;
58
-
59
- get right(): NEIGHBOR | null | undefined {
60
- return this._right;
61
- }
62
-
63
- set right(v: NEIGHBOR | null | undefined) {
64
- if (v) {
65
- v.parent = this as unknown as NEIGHBOR;
66
- }
67
- this._right = v;
68
- }
69
-
70
- parent: NEIGHBOR | null | undefined;
71
-
72
- /**
73
- * The function determines the position of a node in a family tree structure.
74
- * @returns a value of type `FamilyPosition`.
75
- */
76
- get familyPosition(): FamilyPosition {
77
- const that = this as unknown as NEIGHBOR;
78
- if (that.parent) {
79
- if (that.parent.left === that) {
80
- if (that.left || that.right) {
81
- return FamilyPosition.ROOT_LEFT;
82
- } else {
83
- return FamilyPosition.LEFT;
84
- }
85
- } else if (that.parent.right === that) {
86
- if (that.left || that.right) {
87
- return FamilyPosition.ROOT_RIGHT;
88
- } else {
89
- return FamilyPosition.RIGHT;
90
- }
91
- } else {
92
- return FamilyPosition.MAL_NODE;
93
- }
94
- } else {
95
- if (that.left || that.right) {
96
- return FamilyPosition.ROOT;
97
- } else {
98
- return FamilyPosition.ISOLATED;
99
- }
100
- }
101
- }
102
- }
103
-
104
- export abstract class AbstractBinaryTree<N extends AbstractBinaryTreeNode<N['val'], N> = AbstractBinaryTreeNode>
105
- implements IAbstractBinaryTree<N>
106
- {
107
- /**
108
- * The protected constructor initializes the options for an abstract binary tree.
109
- * @param {AbstractBinaryTreeOptions} [options] - An optional object that contains configuration options for the binary
110
- * tree.
111
- */
112
- protected constructor(options?: AbstractBinaryTreeOptions) {
113
- if (options !== undefined) {
114
- const {loopType = LoopType.ITERATIVE} = options;
115
- this._loopType = loopType;
116
- }
117
- this.clear();
118
- }
119
- // TODO placeholder node may need redesigned
120
- private _root: N | null = null;
121
-
122
- get root(): N | null {
123
- return this._root;
124
- }
125
-
126
- private _size = 0;
127
-
128
- get size(): number {
129
- return this._size;
130
- }
131
-
132
- private _loopType: LoopType = LoopType.ITERATIVE;
133
-
134
- get loopType(): LoopType {
135
- return this._loopType;
136
- }
137
-
138
- visitedKey: BinaryTreeNodeKey[] = [];
139
-
140
- visitedVal: N['val'][] = [];
141
-
142
- visitedNode: N[] = [];
143
-
144
- abstract createNode(key: BinaryTreeNodeKey, val?: N['val']): N | null;
145
-
146
- /**
147
- * The `swapLocation` function swaps the location of two nodes in a binary tree.
148
- * @param {N} srcNode - The source node that you want to swap with the destination node.
149
- * @param {N} destNode - The `destNode` parameter represents the destination node where the values from `srcNode` will
150
- * be swapped to.
151
- * @returns The `destNode` is being returned.
152
- */
153
- swapLocation(srcNode: N, destNode: N): N {
154
- const {key, val} = destNode;
155
- const tempNode = this.createNode(key, val);
156
-
157
- if (tempNode) {
158
- destNode.key = srcNode.key;
159
- destNode.val = srcNode.val;
160
-
161
- srcNode.key = tempNode.key;
162
- srcNode.val = tempNode.val;
163
- }
164
-
165
- return destNode;
166
- }
167
-
168
- /**
169
- * The clear() function resets the root, size, and maxKey properties to their initial values.
170
- */
171
- clear() {
172
- this._root = null;
173
- this._size = 0;
174
- this._clearResults();
175
- }
176
-
177
- /**
178
- * The function checks if the size of an object is equal to zero and returns a boolean value.
179
- * @returns A boolean value indicating whether the size of the object is 0 or not.
180
- */
181
- isEmpty(): boolean {
182
- return this.size === 0;
183
- }
184
-
185
- /**
186
- * When all leaf nodes are null, it will no longer be possible to add new entity nodes to this binary tree.
187
- * In this scenario, null nodes serve as "sentinel nodes," "virtual nodes," or "placeholder nodes."
188
- */
189
-
190
- /**
191
- * The `add` function adds a new node to a binary tree, either by ID or by creating a new node with a given value.
192
- * @param {BinaryTreeNodeKey | N | null} keyOrNode - The `keyOrNode` parameter can be either a `BinaryTreeNodeKey`, which
193
- * is a number representing the ID of a binary tree node, or it can be a `N` object, which represents a binary tree
194
- * node itself. It can also be `null` if no node is specified.
195
- * @param [val] - The `val` parameter is an optional value that can be assigned to the `val` property of the new node
196
- * being added to the binary tree.
197
- * @returns The function `add` returns either the inserted node (`N`), `null`, or `undefined`.
198
- */
199
- add(keyOrNode: BinaryTreeNodeKey | N | null, val?: N['val']): N | null | undefined {
200
- const _bfs = (root: N, newNode: N | null): N | undefined | null => {
201
- const queue: Array<N | null> = [root];
202
- while (queue.length > 0) {
203
- const cur = queue.shift();
204
- if (cur) {
205
- if (newNode && cur.key === newNode.key) return;
206
- const inserted = this._addTo(newNode, cur);
207
- if (inserted !== undefined) return inserted;
208
- if (cur.left) queue.push(cur.left);
209
- if (cur.right) queue.push(cur.right);
210
- } else return;
211
- }
212
- return;
213
- };
214
-
215
- let inserted: N | null | undefined, needInsert: N | null;
216
-
217
- if (keyOrNode === null) {
218
- needInsert = null;
219
- } else if (typeof keyOrNode === 'number') {
220
- needInsert = this.createNode(keyOrNode, val);
221
- } else if (keyOrNode instanceof AbstractBinaryTreeNode) {
222
- needInsert = keyOrNode;
223
- } else {
224
- return;
225
- }
226
-
227
- const existNode = keyOrNode ? this.get(keyOrNode, 'key') : undefined;
228
-
229
- if (this.root) {
230
- if (existNode) {
231
- existNode.val = val;
232
- inserted = existNode;
233
- } else {
234
- inserted = _bfs(this.root, needInsert);
235
- }
236
- } else {
237
- this._setRoot(needInsert);
238
- if (needInsert !== null) {
239
- this._setSize(1);
240
- } else {
241
- this._setSize(0);
242
- }
243
- inserted = this.root;
244
- }
245
- return inserted;
246
- }
247
-
248
- /**
249
- * The `addMany` function takes an array of binary tree node IDs or nodes, and optionally an array of corresponding data
250
- * values, and adds them to the binary tree.
251
- * @param {(BinaryTreeNodeKey | null)[] | (N | null)[]} keysOrNodes - An array of BinaryTreeNodeKey or BinaryTreeNode
252
- * objects, or null values.
253
- * @param {N['val'][]} [data] - The `data` parameter is an optional array of values (`N['val'][]`) that corresponds to
254
- * the nodes or node IDs being added. It is used to set the value of each node being added. If `data` is not provided,
255
- * the value of the nodes will be `undefined`.
256
- * @returns The function `addMany` returns an array of `N`, `null`, or `undefined` values.
257
- */
258
- addMany(keysOrNodes: (BinaryTreeNodeKey | null)[] | (N | null)[], data?: N['val'][]): (N | null | undefined)[] {
259
- // TODO not sure addMany not be run multi times
260
- const inserted: (N | null | undefined)[] = [];
261
-
262
- for (let i = 0; i < keysOrNodes.length; i++) {
263
- const keyOrNode = keysOrNodes[i];
264
- if (keyOrNode instanceof AbstractBinaryTreeNode) {
265
- inserted.push(this.add(keyOrNode.key, keyOrNode.val));
266
- continue;
267
- }
268
-
269
- if (keyOrNode === null) {
270
- inserted.push(this.add(null));
271
- continue;
272
- }
273
-
274
- const val = data?.[i];
275
- inserted.push(this.add(keyOrNode, val));
276
- }
277
- return inserted;
278
- }
279
-
280
- /**
281
- * The `refill` function clears the binary tree and adds multiple nodes with the given IDs or nodes and optional data.
282
- * @param {(BinaryTreeNodeKey | N)[]} keysOrNodes - The `keysOrNodes` parameter is an array that can contain either
283
- * `BinaryTreeNodeKey` or `N` values.
284
- * @param {N[] | Array<N['val']>} [data] - The `data` parameter is an optional array of values that will be assigned to
285
- * the nodes being added. If provided, the length of the `data` array should be equal to the length of the `keysOrNodes`
286
- * array. Each value in the `data` array will be assigned to the
287
- * @returns The method is returning a boolean value.
288
- */
289
- refill(keysOrNodes: (BinaryTreeNodeKey | null)[] | (N | null)[], data?: N[] | Array<N['val']>): boolean {
290
- this.clear();
291
- return keysOrNodes.length === this.addMany(keysOrNodes, data).length;
292
- }
293
-
294
- /**
295
- * The `remove` function in TypeScript is used to delete a node from a binary search tree and returns an array of objects
296
- * containing the deleted node and the node that needs to be balanced.
297
- * @param {N | BinaryTreeNodeKey} nodeOrKey - The `nodeOrKey` parameter can be either a node object (`N`) or a binary tree
298
- * node ID (`BinaryTreeNodeKey`).
299
- * @returns The function `remove` returns an array of `BinaryTreeDeletedResult<N>` objects.
300
- */
301
- remove(nodeOrKey: N | BinaryTreeNodeKey): BinaryTreeDeletedResult<N>[] {
302
- const bstDeletedResult: BinaryTreeDeletedResult<N>[] = [];
303
- if (!this.root) return bstDeletedResult;
304
-
305
- const curr: N | null = typeof nodeOrKey === 'number' ? this.get(nodeOrKey) : nodeOrKey;
306
- if (!curr) return bstDeletedResult;
307
-
308
- const parent: N | null = curr?.parent ? curr.parent : null;
309
- let needBalanced: N | null = null,
310
- orgCurrent = curr;
311
-
312
- if (!curr.left) {
313
- if (!parent) {
314
- if (curr.right !== undefined) this._setRoot(curr.right);
315
- } else {
316
- const {familyPosition: fp} = curr;
317
- if (fp === FamilyPosition.LEFT || fp === FamilyPosition.ROOT_LEFT) {
318
- parent.left = curr.right;
319
- } else if (fp === FamilyPosition.RIGHT || fp === FamilyPosition.ROOT_RIGHT) {
320
- parent.right = curr.right;
321
- }
322
- needBalanced = parent;
323
- }
324
- } else {
325
- const leftSubTreeRightMost = curr.left ? this.getRightMost(curr.left) : null;
326
- if (leftSubTreeRightMost) {
327
- const parentOfLeftSubTreeMax = leftSubTreeRightMost.parent;
328
- orgCurrent = this.swapLocation(curr, leftSubTreeRightMost);
329
- if (parentOfLeftSubTreeMax) {
330
- if (parentOfLeftSubTreeMax.right === leftSubTreeRightMost)
331
- parentOfLeftSubTreeMax.right = leftSubTreeRightMost.left;
332
- else parentOfLeftSubTreeMax.left = leftSubTreeRightMost.left;
333
- needBalanced = parentOfLeftSubTreeMax;
334
- }
335
- }
336
- }
337
- this._setSize(this.size - 1);
338
-
339
- bstDeletedResult.push({deleted: orgCurrent, needBalanced});
340
- return bstDeletedResult;
341
- }
342
-
343
- /**
344
- * The function calculates the depth of a node in a binary tree.
345
- * @param {N | BinaryTreeNodeKey | null} beginRoot - The `beginRoot` parameter can be one of the following:
346
- * @returns the depth of the given node or binary tree.
347
- */
348
- getDepth(beginRoot: N | BinaryTreeNodeKey | null = this.root): number {
349
- if (typeof beginRoot === 'number') beginRoot = this.get(beginRoot, 'key');
350
-
351
- let depth = 0;
352
- while (beginRoot?.parent) {
353
- depth++;
354
- beginRoot = beginRoot.parent;
355
- }
356
- return depth;
357
- }
358
-
359
- /**
360
- * The `getHeight` function calculates the maximum height of a binary tree, either recursively or iteratively.
361
- * @param {N | BinaryTreeNodeKey | null} [beginRoot] - The `beginRoot` parameter is optional and can be of type `N` (a
362
- * generic type representing a node in a binary tree), `BinaryTreeNodeKey` (a type representing the ID of a binary tree
363
- * node), or `null`.
364
- * @returns the height of the binary tree.
365
- */
366
- getHeight(beginRoot: N | BinaryTreeNodeKey | null = this.root): number {
367
- if (typeof beginRoot === 'number') beginRoot = this.get(beginRoot, 'key');
368
- if (!beginRoot) return -1;
369
-
370
- if (this._loopType === LoopType.RECURSIVE) {
371
- const _getMaxHeight = (cur: N | null | undefined): number => {
372
- if (!cur) return -1;
373
- const leftHeight = _getMaxHeight(cur.left);
374
- const rightHeight = _getMaxHeight(cur.right);
375
- return Math.max(leftHeight, rightHeight) + 1;
376
- };
377
-
378
- return _getMaxHeight(beginRoot);
379
- } else {
380
- if (!beginRoot) {
381
- return -1;
382
- }
383
-
384
- const stack: {node: N; depth: number}[] = [{node: beginRoot, depth: 0}];
385
- let maxHeight = 0;
386
-
387
- while (stack.length > 0) {
388
- const {node, depth} = stack.pop()!;
389
-
390
- if (node.left) {
391
- stack.push({node: node.left, depth: depth + 1});
392
- }
393
-
394
- if (node.right) {
395
- stack.push({node: node.right, depth: depth + 1});
396
- }
397
-
398
- maxHeight = Math.max(maxHeight, depth);
399
- }
400
-
401
- return maxHeight;
402
- }
403
- }
404
-
405
- /**
406
- * The `getMinHeight` function calculates the minimum height of a binary tree using either a recursive or iterative
407
- * approach.
408
- * @param {N | null} [beginRoot] - The `beginRoot` parameter is an optional parameter of type `N` or `null`. It
409
- * represents the starting node from which to calculate the minimum height of a binary tree. If no value is provided
410
- * for `beginRoot`, the `this.root` property is used as the default value.
411
- * @returns The function `getMinHeight` returns the minimum height of the binary tree.
412
- */
413
- getMinHeight(beginRoot: N | null = this.root): number {
414
- if (!beginRoot) return -1;
415
-
416
- if (this._loopType === LoopType.RECURSIVE) {
417
- const _getMinHeight = (cur: N | null | undefined): number => {
418
- if (!cur) return 0;
419
- if (!cur.left && !cur.right) return 0;
420
- const leftMinHeight = _getMinHeight(cur.left);
421
- const rightMinHeight = _getMinHeight(cur.right);
422
- return Math.min(leftMinHeight, rightMinHeight) + 1;
423
- };
424
-
425
- return _getMinHeight(beginRoot);
426
- } else {
427
- const stack: N[] = [];
428
- let node: N | null | undefined = beginRoot,
429
- last: N | null = null;
430
- const depths: Map<N, number> = new Map();
431
-
432
- while (stack.length > 0 || node) {
433
- if (node) {
434
- stack.push(node);
435
- node = node.left;
436
- } else {
437
- node = stack[stack.length - 1];
438
- if (!node.right || last === node.right) {
439
- node = stack.pop();
440
- if (node) {
441
- const leftMinHeight = node.left ? depths.get(node.left) ?? -1 : -1;
442
- const rightMinHeight = node.right ? depths.get(node.right) ?? -1 : -1;
443
- depths.set(node, 1 + Math.min(leftMinHeight, rightMinHeight));
444
- last = node;
445
- node = null;
446
- }
447
- } else node = node.right;
448
- }
449
- }
450
-
451
- return depths.get(beginRoot) ?? -1;
452
- }
453
- }
454
-
455
- /**
456
- * The function checks if a binary tree is perfectly balanced by comparing the minimum height and the height of the
457
- * tree.
458
- * @param {N | null} [beginRoot] - The parameter `beginRoot` is of type `N` or `null`. It represents the root node of a
459
- * tree or null if the tree is empty.
460
- * @returns The method is returning a boolean value.
461
- */
462
- isPerfectlyBalanced(beginRoot: N | null = this.root): boolean {
463
- return this.getMinHeight(beginRoot) + 1 >= this.getHeight(beginRoot);
464
- }
465
-
466
- /**
467
- * The function `getNodes` returns an array of nodes that match a given property name and value in a binary tree.
468
- * @param {BinaryTreeNodeKey | N} nodeProperty - The `nodeProperty` parameter can be either a `BinaryTreeNodeKey` or a
469
- * generic type `N`. It represents the property of the binary tree node that you want to search for.
470
- * @param {BinaryTreeNodePropertyName} [propertyName] - The `propertyName` parameter is an optional parameter that
471
- * specifies the property name to use when searching for nodes. If not provided, it defaults to 'key'.
472
- * @param {boolean} [onlyOne] - The `onlyOne` parameter is an optional boolean parameter that determines whether to
473
- * return only one node that matches the given `nodeProperty` or `propertyName`. If `onlyOne` is set to `true`, the
474
- * function will stop traversing the tree and return the first matching node. If `only
475
- * @returns an array of nodes (type N).
476
- */
477
- getNodes(
478
- nodeProperty: BinaryTreeNodeKey | N,
479
- propertyName: BinaryTreeNodePropertyName = 'key',
480
- onlyOne = false
481
- ): N[] {
482
- if (!this.root) return [];
483
-
484
- const result: N[] = [];
485
-
486
- if (this.loopType === LoopType.RECURSIVE) {
487
- const _traverse = (cur: N) => {
488
- if (this._pushByPropertyNameStopOrNot(cur, result, nodeProperty, propertyName, onlyOne)) return;
489
- if (!cur.left && !cur.right) return;
490
- cur.left && _traverse(cur.left);
491
- cur.right && _traverse(cur.right);
492
- };
493
-
494
- _traverse(this.root);
495
- } else {
496
- const queue: N[] = [this.root];
497
- while (queue.length > 0) {
498
- const cur = queue.shift();
499
- if (cur) {
500
- if (this._pushByPropertyNameStopOrNot(cur, result, nodeProperty, propertyName, onlyOne)) return result;
501
- cur.left && queue.push(cur.left);
502
- cur.right && queue.push(cur.right);
503
- }
504
- }
505
- }
506
-
507
- return result;
508
- }
509
-
510
- /**
511
- * The function checks if a binary tree node has a specific property.
512
- * @param {BinaryTreeNodeKey | N} nodeProperty - The `nodeProperty` parameter can be either a `BinaryTreeNodeKey` or `N`.
513
- * It represents the property of the binary tree node that you want to check.
514
- * @param {BinaryTreeNodePropertyName} [propertyName] - The `propertyName` parameter is an optional parameter that
515
- * specifies the name of the property to be checked in the nodes. If not provided, it defaults to 'key'.
516
- * @returns a boolean value.
517
- */
518
- has(nodeProperty: BinaryTreeNodeKey | N, propertyName: BinaryTreeNodePropertyName = 'key'): boolean {
519
- // TODO may support finding node by value equal
520
- return this.getNodes(nodeProperty, propertyName).length > 0;
521
- }
522
-
523
- /**
524
- * The function returns the first node that matches the given property name and value, or null if no matching node is
525
- * found.
526
- * @param {BinaryTreeNodeKey | N} nodeProperty - The `nodeProperty` parameter can be either a `BinaryTreeNodeKey` or `N`.
527
- * It represents the property of the binary tree node that you want to search for.
528
- * @param {BinaryTreeNodePropertyName} [propertyName] - The `propertyName` parameter is an optional parameter that
529
- * specifies the property name to be used for searching the binary tree nodes. If this parameter is not provided, the
530
- * default value is set to `'key'`.
531
- * @returns either the value of the specified property of the node, or the node itself if no property name is provided.
532
- * If no matching node is found, it returns null.
533
- */
534
- get(nodeProperty: BinaryTreeNodeKey | N, propertyName: BinaryTreeNodePropertyName = 'key'): N | null {
535
- // TODO may support finding node by value equal
536
- return this.getNodes(nodeProperty, propertyName, true)[0] ?? null;
537
- }
538
-
539
- /**
540
- * The function `getPathToRoot` returns an array of nodes representing the path from a given node to the root node, with
541
- * an option to reverse the order of the nodes.
542
- * @param {N} node - The `node` parameter represents a node in a tree structure. It is of type `N`, which could be any
543
- * type that represents a node in your specific implementation.
544
- * @param {boolean} [isReverse=true] - The `isReverse` parameter is a boolean flag that determines whether the resulting
545
- * path should be reversed or not. If `isReverse` is set to `true`, the path will be reversed before returning it. If
546
- * `isReverse` is set to `false` or not provided, the path will
547
- * @returns The function `getPathToRoot` returns an array of nodes (`N[]`).
548
- */
549
- getPathToRoot(node: N, isReverse = true): N[] {
550
- // TODO to support get path through passing key
551
- const result: N[] = [];
552
- while (node.parent) {
553
- // Array.push + Array.reverse is more efficient than Array.unshift
554
- // TODO may consider using Deque, so far this is not the performance bottleneck
555
- result.push(node);
556
- node = node.parent;
557
- }
558
- result.push(node);
559
- return isReverse ? result.reverse() : result;
560
- }
561
-
562
- /**
563
- * The function `getLeftMost` returns the leftmost node in a binary tree, starting from a specified node or the root if
564
- * no node is specified.
565
- * generic type representing a node in a binary tree), `BinaryTreeNodeKey` (a type representing the ID of a binary tree
566
- * node), or `null`.
567
- * @returns The function `getLeftMost` returns the leftmost node in a binary tree. If the `beginRoot` parameter is
568
- * provided, it starts the traversal from that node. If `beginRoot` is not provided or is `null`, it starts the traversal
569
- * from the root of the binary tree. The function returns the leftmost node found during the traversal. If no leftmost
570
- * node is found (
571
- */
572
- getLeftMost(): N | null;
573
-
574
- /**
575
- * The function `getLeftMost` returns the leftmost node in a binary tree, starting from a specified node or the root if
576
- * no node is specified.
577
- * @param {N | BinaryTreeNodeKey | null} [node] - The `beginRoot` parameter is optional and can be of type `N` (a
578
- * generic type representing a node in a binary tree), `BinaryTreeNodeKey` (a type representing the ID of a binary tree
579
- * node).
580
- * @returns The function `getLeftMost` returns the leftmost node in a binary tree. If the `beginRoot` parameter is
581
- * provided, it starts the traversal from that node. If `beginRoot` is not provided or is `null`, it starts the traversal
582
- * from the root of the binary tree. The function returns the leftmost node found during the traversal. If no leftmost
583
- * node is found (
584
- */
585
- getLeftMost(node: N): N;
586
-
587
- /**
588
- * The function `getLeftMost` returns the leftmost node in a binary tree, starting from a specified node or the root if
589
- * no node is specified.
590
- * @param {N | BinaryTreeNodeKey | null} [beginRoot] - The `beginRoot` parameter is optional and can be of type `N` (a
591
- * generic type representing a node in a binary tree), `BinaryTreeNodeKey` (a type representing the ID of a binary tree
592
- * node), or `null`.
593
- * @returns The function `getLeftMost` returns the leftmost node in a binary tree. If the `beginRoot` parameter is
594
- * provided, it starts the traversal from that node. If `beginRoot` is not provided or is `null`, it starts the traversal
595
- * from the root of the binary tree. The function returns the leftmost node found during the traversal. If no leftmost
596
- * node is found (
597
- */
598
- getLeftMost(beginRoot: N | BinaryTreeNodeKey | null = this.root): N | null {
599
- if (typeof beginRoot === 'number') beginRoot = this.get(beginRoot, 'key');
600
-
601
- if (!beginRoot) return beginRoot;
602
-
603
- if (this._loopType === LoopType.RECURSIVE) {
604
- const _traverse = (cur: N): N => {
605
- if (!cur.left) return cur;
606
- return _traverse(cur.left);
607
- };
608
-
609
- return _traverse(beginRoot);
610
- } else {
611
- // Indirect implementation of iteration using tail recursion optimization
612
- const _traverse = trampoline((cur: N) => {
613
- if (!cur.left) return cur;
614
- return _traverse.cont(cur.left);
615
- });
616
-
617
- return _traverse(beginRoot);
618
- }
619
- }
620
-
621
- /**
622
- * The `getRightMost` function returns the rightmost node in a binary tree, either recursively or iteratively using tail
623
- * recursion optimization.
624
- * @returns The `getRightMost` function returns the rightmost node in a binary tree. It returns the
625
- * rightmost node starting from the root of the binary tree.
626
- */
627
- getRightMost(): N | null;
628
-
629
- /**
630
- * The `getRightMost` function returns the rightmost node in a binary tree, either recursively or iteratively using tail
631
- * recursion optimization.
632
- * @param {N | null} [beginRoot] - The `node` parameter is an optional parameter of type `N` or `null`. It represents the
633
- * starting node from which we want to find the rightmost node. If no node is provided, the function will default to
634
- * using the root node of the data structure.
635
- * @returns The `getRightMost` function returns the rightmost node in a binary tree. It returns the rightmost node
636
- * starting from that node.
637
- */
638
- getRightMost(beginRoot: N): N;
639
-
640
- /**
641
- * The `getRightMost` function returns the rightmost node in a binary tree, either recursively or iteratively using tail
642
- * recursion optimization.
643
- * @param {N | null} [beginRoot] - The `node` parameter is an optional parameter of type `N` or `null`. It represents the
644
- * starting node from which we want to find the rightmost node. If no node is provided, the function will default to
645
- * using the root node of the data structure.
646
- * @returns The `getRightMost` function returns the rightmost node in a binary tree. If the `node` parameter is provided,
647
- * it returns the rightmost node starting from that node. If the `node` parameter is not provided, it returns the
648
- * rightmost node starting from the root of the binary tree.
649
- */
650
- getRightMost(beginRoot: N | null = this.root): N | null {
651
- // TODO support get right most by passing key in
652
- if (!beginRoot) return beginRoot;
653
-
654
- if (this._loopType === LoopType.RECURSIVE) {
655
- const _traverse = (cur: N): N => {
656
- if (!cur.right) return cur;
657
- return _traverse(cur.right);
658
- };
659
-
660
- return _traverse(beginRoot);
661
- } else {
662
- // Indirect implementation of iteration using tail recursion optimization
663
- const _traverse = trampoline((cur: N) => {
664
- if (!cur.right) return cur;
665
- return _traverse.cont(cur.right);
666
- });
667
-
668
- return _traverse(beginRoot);
669
- }
670
- }
671
-
672
- /**
673
- * The function checks if a binary search tree is valid by traversing it either recursively or iteratively.
674
- * @param {N | null} node - The `node` parameter represents the root node of a binary search tree (BST).
675
- * @returns a boolean value.
676
- */
677
- isSubtreeBST(node: N | null): boolean {
678
- // TODO there is a bug
679
- if (!node) return true;
680
-
681
- if (this._loopType === LoopType.RECURSIVE) {
682
- const dfs = (cur: N | null | undefined, min: BinaryTreeNodeKey, max: BinaryTreeNodeKey): boolean => {
683
- if (!cur) return true;
684
- if (cur.key <= min || cur.key >= max) return false;
685
- return dfs(cur.left, min, cur.key) && dfs(cur.right, cur.key, max);
686
- };
687
-
688
- return dfs(node, Number.MIN_SAFE_INTEGER, Number.MAX_SAFE_INTEGER);
689
- } else {
690
- const stack = [];
691
- let prev = Number.MIN_SAFE_INTEGER,
692
- curr: N | null | undefined = node;
693
- while (curr || stack.length > 0) {
694
- while (curr) {
695
- stack.push(curr);
696
- curr = curr.left;
697
- }
698
- curr = stack.pop()!;
699
- if (!curr || prev >= curr.key) return false;
700
- prev = curr.key;
701
- curr = curr.right;
702
- }
703
- return true;
704
- }
705
- }
706
-
707
- /**
708
- * The function isBST checks if the binary tree is valid binary search tree.
709
- * @returns The `isBST()` function is returning a boolean value.
710
- */
711
- isBST(): boolean {
712
- return this.isSubtreeBST(this.root);
713
- }
714
-
715
- /**
716
- * The function calculates the size of a subtree by traversing it either recursively or iteratively.
717
- * @param {N | null | undefined} subTreeRoot - The `subTreeRoot` parameter represents the root node of a subtree in a
718
- * binary tree.
719
- * @returns the size of the subtree rooted at `subTreeRoot`.
720
- */
721
- getSubTreeSize(subTreeRoot: N | null | undefined) {
722
- // TODO support key passed in
723
- let size = 0;
724
- if (!subTreeRoot) return size;
725
-
726
- if (this._loopType === LoopType.RECURSIVE) {
727
- const _traverse = (cur: N) => {
728
- size++;
729
- cur.left && _traverse(cur.left);
730
- cur.right && _traverse(cur.right);
731
- };
732
-
733
- _traverse(subTreeRoot);
734
- return size;
735
- } else {
736
- const stack: N[] = [subTreeRoot];
737
-
738
- while (stack.length > 0) {
739
- const cur = stack.pop()!;
740
- size++;
741
- cur.right && stack.push(cur.right);
742
- cur.left && stack.push(cur.left);
743
- }
744
-
745
- return size;
746
- }
747
- }
748
-
749
- /**
750
- * The function `subTreeSum` calculates the sum of a specified property in a binary tree or subtree.
751
- * @param {N | BinaryTreeNodeKey | null} subTreeRoot - The `subTreeRoot` parameter represents the root node of a binary
752
- * tree or the ID of a binary tree node. It can also be `null` if there is no subtree.
753
- * @param {BinaryTreeNodePropertyName} [propertyName] - propertyName is an optional parameter that specifies the
754
- * property of the binary tree node to use for calculating the sum. It can be either 'key' or 'val'. If propertyName is
755
- * not provided, it defaults to 'key'.
756
- * @returns a number, which is the sum of the values of the specified property in the subtree rooted at `subTreeRoot`.
757
- */
758
- subTreeSum(subTreeRoot: N | BinaryTreeNodeKey | null, propertyName: BinaryTreeNodePropertyName = 'key'): number {
759
- if (typeof subTreeRoot === 'number') subTreeRoot = this.get(subTreeRoot, 'key');
760
-
761
- if (!subTreeRoot) return 0;
762
-
763
- let sum = 0;
764
-
765
- const _sumByProperty = (cur: N) => {
766
- let needSum: number;
767
- switch (propertyName) {
768
- case 'key':
769
- needSum = cur.key;
770
- break;
771
- case 'val':
772
- needSum = typeof cur.val === 'number' ? cur.val : 0;
773
- break;
774
- default:
775
- needSum = cur.key;
776
- break;
777
- }
778
- return needSum;
779
- };
780
-
781
- if (this._loopType === LoopType.RECURSIVE) {
782
- const _traverse = (cur: N): void => {
783
- sum += _sumByProperty(cur);
784
- cur.left && _traverse(cur.left);
785
- cur.right && _traverse(cur.right);
786
- };
787
-
788
- _traverse(subTreeRoot);
789
- } else {
790
- const stack: N[] = [subTreeRoot];
791
-
792
- while (stack.length > 0) {
793
- const cur = stack.pop()!;
794
- sum += _sumByProperty(cur);
795
- cur.right && stack.push(cur.right);
796
- cur.left && stack.push(cur.left);
797
- }
798
- }
799
-
800
- return sum;
801
- }
802
-
803
- /**
804
- * The function `subTreeAdd` adds a delta value to a specified property of each node in a subtree.
805
- * @param {N | BinaryTreeNodeKey | null} subTreeRoot - The `subTreeRoot` parameter represents the root node of a binary
806
- * tree or the ID of a node in the binary tree. It can also be `null` if there is no subtree to add to.
807
- * @param {number} delta - The `delta` parameter is a number that represents the amount by which the property value of
808
- * each node in the subtree should be incremented.
809
- * @param {BinaryTreeNodePropertyName} [propertyName] - The `propertyName` parameter is an optional parameter that
810
- * specifies the property of the binary tree node that should be modified. If not provided, it defaults to 'key'.
811
- * @returns a boolean value.
812
- */
813
- subTreeAdd(
814
- subTreeRoot: N | BinaryTreeNodeKey | null,
815
- delta: number,
816
- propertyName: BinaryTreeNodePropertyName = 'key'
817
- ): boolean {
818
- if (typeof subTreeRoot === 'number') subTreeRoot = this.get(subTreeRoot, 'key');
819
-
820
- if (!subTreeRoot) return false;
821
-
822
- const _addByProperty = (cur: N) => {
823
- switch (propertyName) {
824
- case 'key':
825
- cur.key += delta;
826
- break;
827
- default:
828
- cur.key += delta;
829
- break;
830
- }
831
- };
832
-
833
- if (this._loopType === LoopType.RECURSIVE) {
834
- const _traverse = (cur: N) => {
835
- _addByProperty(cur);
836
- cur.left && _traverse(cur.left);
837
- cur.right && _traverse(cur.right);
838
- };
839
-
840
- _traverse(subTreeRoot);
841
- } else {
842
- const stack: N[] = [subTreeRoot];
843
-
844
- while (stack.length > 0) {
845
- const cur = stack.pop()!;
846
-
847
- _addByProperty(cur);
848
- cur.right && stack.push(cur.right);
849
- cur.left && stack.push(cur.left);
850
- }
851
- }
852
- return true;
853
- }
854
-
855
- /**
856
- * Performs a breadth-first search (bfs) on a binary tree, accumulating properties of each node based on their 'key' property.
857
- * @returns An array of binary tree node IDs.
858
- */
859
- bfs(): BinaryTreeNodeKey[];
860
-
861
- /**
862
- * Performs a breadth-first search (bfs) on a binary tree, accumulating properties of each node based on the specified property name.
863
- * @param {'key'} nodeOrPropertyName - The name of the property to accumulate.
864
- * @returns An array of values corresponding to the specified property.
865
- */
866
- bfs(nodeOrPropertyName: 'key'): BinaryTreeNodeKey[];
867
-
868
- /**
869
- * Performs a breadth-first search (bfs) on a binary tree, accumulating the 'val' property of each node.
870
- * @param {'val'} nodeOrPropertyName - The name of the property to accumulate.
871
- * @returns An array of 'val' properties from each node.
872
- */
873
- bfs(nodeOrPropertyName: 'val'): N['val'][];
874
-
875
- /**
876
- * Performs a breadth-first search (bfs) on a binary tree, accumulating nodes themselves.
877
- * @param {'node'} nodeOrPropertyName - The name of the property to accumulate.
878
- * @returns An array of binary tree nodes.
879
- */
880
- bfs(nodeOrPropertyName: 'node'): N[];
881
-
882
- /**
883
- * The bfs function performs a breadth-first search on a binary tree, accumulating properties of each node based on a specified property name.
884
- * @param {NodeOrPropertyName} [nodeOrPropertyName] - An optional parameter that represents either a node or a property name.
885
- * If a node is provided, the bfs algorithm will be performed starting from that node.
886
- * If a property name is provided, the bfs algorithm will be performed starting from the root node, accumulating the specified property.
887
- * @returns An instance of the `AbstractBinaryTreeNodeProperties` class with generic type `N`.
888
- */
889
- bfs(nodeOrPropertyName: NodeOrPropertyName = 'key'): AbstractBinaryTreeNodeProperties<N> {
890
- this._clearResults();
891
- const queue: Array<N | null | undefined> = [this.root];
892
-
893
- while (queue.length !== 0) {
894
- const cur = queue.shift();
895
- if (cur) {
896
- this._accumulatedByPropertyName(cur, nodeOrPropertyName);
897
- if (cur?.left !== null) queue.push(cur.left);
898
- if (cur?.right !== null) queue.push(cur.right);
899
- }
900
- }
901
-
902
- return this._getResultByPropertyName(nodeOrPropertyName);
903
- }
904
-
905
- /**
906
- * Performs a depth-first search (dfs) traversal on a binary tree and accumulates properties of each node based on their 'key' property.
907
- * @returns An array of binary tree node IDs.
908
- */
909
- dfs(): BinaryTreeNodeKey[];
910
-
911
- /**
912
- * Performs a depth-first search (dfs) traversal on a binary tree and accumulates properties of each node based on the specified property name.
913
- * @param {'in' | 'pre' | 'post'} [pattern] - The traversal pattern: 'in' (in-order), 'pre' (pre-order), or 'post' (post-order).
914
- * @returns An array of values corresponding to the specified property.
915
- */
916
- dfs(pattern: DFSOrderPattern): BinaryTreeNodeKey[];
917
-
918
- /**
919
- * Performs a depth-first search (dfs) traversal on a binary tree and accumulates properties of each node based on the specified property name.
920
- * @param {'in' | 'pre' | 'post'} [pattern] - The traversal pattern: 'in' (in-order), 'pre' (pre-order), or 'post' (post-order).
921
- * @param {string} nodeOrPropertyName - The name of the property to accumulate.
922
- * @returns An array of values corresponding to the specified property.
923
- */
924
- dfs(pattern: DFSOrderPattern, nodeOrPropertyName: 'key'): BinaryTreeNodeKey[];
925
-
926
- /**
927
- * Performs a depth-first search (dfs) traversal on a binary tree and accumulates the 'val' property of each node.
928
- * @param {'in' | 'pre' | 'post'} [pattern] - The traversal pattern: 'in' (in-order), 'pre' (pre-order), or 'post' (post-order).
929
- * @param {'val'} nodeOrPropertyName - The name of the property to accumulate.
930
- * @returns An array of 'val' properties from each node.
931
- */
932
- dfs(pattern: DFSOrderPattern, nodeOrPropertyName: 'val'): N[];
933
-
934
- /**
935
- * Performs a depth-first search (dfs) traversal on a binary tree and accumulates nodes themselves.
936
- * @param {'in' | 'pre' | 'post'} [pattern] - The traversal pattern: 'in' (in-order), 'pre' (pre-order), or 'post' (post-order).
937
- * @param {'node'} nodeOrPropertyName - The name of the property to accumulate.
938
- * @returns An array of binary tree nodes.
939
- */
940
- dfs(pattern: DFSOrderPattern, nodeOrPropertyName: 'node'): N[];
941
-
942
- /**
943
- * The dfs function performs a depth-first search traversal on a binary tree and returns the accumulated properties of
944
- * each node based on the specified pattern and property name.
945
- * @param {'in' | 'pre' | 'post'} [pattern] - The traversal pattern: 'in' (in-order), 'pre' (pre-order), or 'post' (post-order).
946
- * @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'`.
947
- * @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.
948
- */
949
- dfs(
950
- pattern: DFSOrderPattern = 'in',
951
- nodeOrPropertyName: NodeOrPropertyName = 'key'
952
- ): AbstractBinaryTreeNodeProperties<N> {
953
- this._clearResults();
954
- const _traverse = (node: N) => {
955
- switch (pattern) {
956
- case 'in':
957
- if (node.left) _traverse(node.left);
958
- this._accumulatedByPropertyName(node, nodeOrPropertyName);
959
- if (node.right) _traverse(node.right);
960
- break;
961
- case 'pre':
962
- this._accumulatedByPropertyName(node, nodeOrPropertyName);
963
- if (node.left) _traverse(node.left);
964
- if (node.right) _traverse(node.right);
965
- break;
966
- case 'post':
967
- if (node.left) _traverse(node.left);
968
- if (node.right) _traverse(node.right);
969
- this._accumulatedByPropertyName(node, nodeOrPropertyName);
970
- break;
971
- }
972
- };
973
-
974
- this.root && _traverse(this.root);
975
- return this._getResultByPropertyName(nodeOrPropertyName);
976
- }
977
-
978
- // --- start additional methods ---
979
-
980
- /**
981
- * Performs an iterative depth-first search (dfs) traversal on a binary tree and accumulates properties of each node based on their 'key' property.
982
- * @returns An array of binary tree node IDs.
983
- */
984
- dfsIterative(): BinaryTreeNodeKey[];
985
-
986
- /**
987
- * Performs an iterative depth-first search (dfs) traversal on a binary tree and accumulates properties of each node based on their 'key' property.
988
- * @param {'in' | 'pre' | 'post'} [pattern] - The traversal pattern: 'in' (in-order), 'pre' (pre-order), or 'post' (post-order).
989
- * @returns An array of values corresponding to the specified property.
990
- */
991
- dfsIterative(pattern: DFSOrderPattern): BinaryTreeNodeKey[];
992
-
993
- /**
994
- * Performs an iterative depth-first search (dfs) traversal on a binary tree and accumulates properties of each node based on the specified property name.
995
- * @param {'in' | 'pre' | 'post'} [pattern] - The traversal pattern: 'in' (in-order), 'pre' (pre-order), or 'post' (post-order).
996
- * @param {string} nodeOrPropertyName - The name of the property to accumulate.
997
- * @returns An array of values corresponding to the specified property.
998
- */
999
- dfsIterative(pattern: DFSOrderPattern, nodeOrPropertyName: 'key'): BinaryTreeNodeKey[];
1000
-
1001
- /**
1002
- * Performs an iterative depth-first search (dfs) traversal on a binary tree and accumulates the 'val' property of each node.
1003
- * @param {'in' | 'pre' | 'post'} [pattern] - The traversal pattern: 'in' (in-order), 'pre' (pre-order), or 'post' (post-order).
1004
- * @param {'val'} nodeOrPropertyName - The name of the property to accumulate.
1005
- * @returns An array of 'val' properties from each node.
1006
- */
1007
- dfsIterative(pattern: DFSOrderPattern, nodeOrPropertyName: 'val'): N['val'][];
1008
-
1009
- /**
1010
- * Performs an iterative depth-first search (dfs) traversal on a binary tree and accumulates nodes themselves.
1011
- * @param {'in' | 'pre' | 'post'} [pattern] - The traversal pattern: 'in' (in-order), 'pre' (pre-order), or 'post' (post-order).
1012
- * @param {'node'} nodeOrPropertyName - The name of the property to accumulate.
1013
- * @returns An array of binary tree nodes.
1014
- */
1015
- dfsIterative(pattern: DFSOrderPattern, nodeOrPropertyName: 'node'): N[];
1016
-
1017
- /**
1018
- * The dfsIterative function performs an iterative depth-first search traversal on a binary tree, with the option to
1019
- * specify the traversal pattern and the property name to accumulate results by.
1020
- * @param {'in' | 'pre' | 'post'} [pattern] - The traversal pattern: 'in' (in-order), 'pre' (pre-order), or 'post' (post-order).
1021
- * @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'`.
1022
- * @returns An object of type AbstractBinaryTreeNodeProperties<N>.
1023
- */
1024
- dfsIterative(
1025
- pattern: DFSOrderPattern = 'in',
1026
- nodeOrPropertyName: NodeOrPropertyName = 'key'
1027
- ): AbstractBinaryTreeNodeProperties<N> {
1028
- this._clearResults();
1029
- if (!this.root) return this._getResultByPropertyName(nodeOrPropertyName);
1030
- // 0: visit, 1: print
1031
- const stack: {opt: 0 | 1; node: N | null | undefined}[] = [{opt: 0, node: this.root}];
1032
-
1033
- while (stack.length > 0) {
1034
- const cur = stack.pop();
1035
- if (!cur || !cur.node) continue;
1036
- if (cur.opt === 1) {
1037
- this._accumulatedByPropertyName(cur.node, nodeOrPropertyName);
1038
- } else {
1039
- switch (pattern) {
1040
- case 'in':
1041
- stack.push({opt: 0, node: cur.node.right});
1042
- stack.push({opt: 1, node: cur.node});
1043
- stack.push({opt: 0, node: cur.node.left});
1044
- break;
1045
- case 'pre':
1046
- stack.push({opt: 0, node: cur.node.right});
1047
- stack.push({opt: 0, node: cur.node.left});
1048
- stack.push({opt: 1, node: cur.node});
1049
- break;
1050
- case 'post':
1051
- stack.push({opt: 1, node: cur.node});
1052
- stack.push({opt: 0, node: cur.node.right});
1053
- stack.push({opt: 0, node: cur.node.left});
1054
- break;
1055
- default:
1056
- stack.push({opt: 0, node: cur.node.right});
1057
- stack.push({opt: 1, node: cur.node});
1058
- stack.push({opt: 0, node: cur.node.left});
1059
- break;
1060
- }
1061
- }
1062
- }
1063
-
1064
- return this._getResultByPropertyName(nodeOrPropertyName);
1065
- }
1066
-
1067
- /**
1068
- * Performs a level-order traversal on a binary tree starting from the specified node and accumulates properties of each node based on their 'key' property.
1069
- * @returns An array of binary tree node IDs.
1070
- */
1071
- levelIterative(): BinaryTreeNodeKey[];
1072
-
1073
- /**
1074
- * Performs a level-order traversal on a binary tree starting from the specified node and accumulates properties of each node based on their 'key' property.
1075
- * @param {N | null} node - The starting node for the level order traversal. If null, the root node of the tree is used as the starting node.
1076
- * @returns An array of binary tree node IDs.
1077
- */
1078
- levelIterative(node: N | null): BinaryTreeNodeKey[];
1079
-
1080
- /**
1081
- * Performs a level-order traversal on a binary tree starting from the specified node and accumulates properties of each node based on the specified property name.
1082
- * @param {N | null} node - The starting node for the level order traversal. If null, the root node of the tree is used as the starting node.
1083
- * @param {string} nodeOrPropertyName - The name of the property to accumulate.
1084
- * @returns An array of values corresponding to the specified property.
1085
- */
1086
- levelIterative(node: N | null, nodeOrPropertyName: 'key'): BinaryTreeNodeKey[];
1087
-
1088
- /**
1089
- * Performs a level-order traversal on a binary tree starting from the specified node and accumulates the 'val' property of each node.
1090
- * @param {N | null} node - The starting node for the level order traversal. If null, the root node of the tree is used as the starting node.
1091
- * @param {'val'} nodeOrPropertyName - The name of the property to accumulate.
1092
- * @returns An array of 'val' properties from each node.
1093
- */
1094
- levelIterative(node: N | null, nodeOrPropertyName: 'val'): N['val'][];
1095
-
1096
- /**
1097
- * Performs a level-order traversal on a binary tree starting from the specified node and accumulates nodes themselves.
1098
- * @param {N | null} node - The starting node for the level order traversal. If null, the root node of the tree is used as the starting node.
1099
- * @param {'node'} nodeOrPropertyName - The name of the property to accumulate.
1100
- * @returns An array of binary tree nodes.
1101
- */
1102
- levelIterative(node: N | null, nodeOrPropertyName: 'node'): N[];
1103
-
1104
- /**
1105
- * The `levelIterative` function performs a level-order traversal on a binary tree and returns the values of the nodes
1106
- * in an array, based on a specified property name.
1107
- * @param {N | null} node - The `node` parameter is a BinaryTreeNode object representing the starting
1108
- * node for the level order traversal. It can be null if no specific node is provided, in which case the root node of
1109
- * the tree is used as the starting node.
1110
- * @param {NodeOrPropertyName} [nodeOrPropertyName] - The `nodeOrPropertyName` parameter is an optional parameter that
1111
- * can be either a `BinaryTreeNode` property name or the string `'key'`. If a property name is provided, the function
1112
- * will accumulate results based on that property. If no property name is provided, the function will default to
1113
- * accumulating results based on the 'key' property.
1114
- * @returns An object of type `AbstractBinaryTreeNodeProperties<N>`.
1115
- */
1116
- levelIterative(
1117
- node: N | null = this.root,
1118
- nodeOrPropertyName: NodeOrPropertyName = 'key'
1119
- ): AbstractBinaryTreeNodeProperties<N> {
1120
- if (!node) return [];
1121
-
1122
- this._clearResults();
1123
- const queue: N[] = [node];
1124
-
1125
- while (queue.length > 0) {
1126
- const cur = queue.shift();
1127
- if (cur) {
1128
- this._accumulatedByPropertyName(cur, nodeOrPropertyName);
1129
- if (cur.left) {
1130
- queue.push(cur.left);
1131
- }
1132
- if (cur.right) {
1133
- queue.push(cur.right);
1134
- }
1135
- }
1136
- }
1137
-
1138
- return this._getResultByPropertyName(nodeOrPropertyName);
1139
- }
1140
-
1141
- /**
1142
- * Collects nodes from a binary tree by a specified property and organizes them into levels.
1143
- * @returns A 2D array of AbstractBinaryTreeNodeProperty<N> objects.
1144
- */
1145
- listLevels(): BinaryTreeNodeKey[][];
1146
-
1147
- /**
1148
- * Collects nodes from a binary tree by a specified property and organizes them into levels.
1149
- * @param {N | null} node - The root node of the binary tree or null. If null, the function will use the root node of the current binary tree instance.
1150
- * @returns A 2D array of AbstractBinaryTreeNodeProperty<N> objects.
1151
- */
1152
- listLevels(node: N | null): BinaryTreeNodeKey[][];
1153
-
1154
- /**
1155
- * Collects nodes from a binary tree by a specified property and organizes them into levels.
1156
- * @param {N | null} node - The root node of the binary tree or null. If null, the function will use the root node of the current binary tree instance.
1157
- * @param {'key} nodeOrPropertyName - The property of the BinaryTreeNode object to collect at each level.
1158
- * @returns A 2D array of values corresponding to the specified property.
1159
- */
1160
- listLevels(node: N | null, nodeOrPropertyName: 'key'): BinaryTreeNodeKey[][];
1161
-
1162
- /**
1163
- * Collects nodes from a binary tree by a specified property and organizes them into levels.
1164
- * @param {N | null} node - The root node of the binary tree or null. If null, the function will use the root node of the current binary tree instance.
1165
- * @param {'val'} nodeOrPropertyName - The property of the BinaryTreeNode object to collect at each level.
1166
- * @returns A 2D array of 'val' properties from each node.
1167
- */
1168
- listLevels(node: N | null, nodeOrPropertyName: 'val'): N['val'][][];
1169
-
1170
- /**
1171
- * Collects nodes from a binary tree by a specified property and organizes them into levels.
1172
- * @param {N | null} node - The root node of the binary tree or null. If null, the function will use the root node of the current binary tree instance.
1173
- * @param {'node'} nodeOrPropertyName - The property of the BinaryTreeNode object to collect at each level.
1174
- * @returns A 2D array of binary tree nodes.
1175
- */
1176
- listLevels(node: N | null, nodeOrPropertyName: 'node'): N[][];
1177
-
1178
- /**
1179
- * The `listLevels` function collects nodes from a binary tree by a specified property and organizes them into levels.
1180
- * @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.
1181
- * @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'.
1182
- * @returns A 2D array of `AbstractBinaryTreeNodeProperty<N>` objects.
1183
- */
1184
- listLevels(
1185
- node: N | null = this.root,
1186
- nodeOrPropertyName: NodeOrPropertyName = 'key'
1187
- ): AbstractBinaryTreeNodeProperty<N>[][] {
1188
- if (!node) return [];
1189
-
1190
- const levelsNodes: AbstractBinaryTreeNodeProperty<N>[][] = [];
1191
-
1192
- const collectByProperty = (node: N, level: number) => {
1193
- switch (nodeOrPropertyName) {
1194
- case 'key':
1195
- levelsNodes[level].push(node.key);
1196
- break;
1197
- case 'val':
1198
- levelsNodes[level].push(node.val);
1199
- break;
1200
- case 'node':
1201
- levelsNodes[level].push(node);
1202
- break;
1203
- default:
1204
- levelsNodes[level].push(node.key);
1205
- break;
1206
- }
1207
- };
1208
-
1209
- if (this.loopType === LoopType.RECURSIVE) {
1210
- const _recursive = (node: N, level: number) => {
1211
- if (!levelsNodes[level]) levelsNodes[level] = [];
1212
- collectByProperty(node, level);
1213
- if (node.left) _recursive(node.left, level + 1);
1214
- if (node.right) _recursive(node.right, level + 1);
1215
- };
1216
-
1217
- _recursive(node, 0);
1218
- } else {
1219
- const stack: [N, number][] = [[node, 0]];
1220
-
1221
- while (stack.length > 0) {
1222
- const head = stack.pop()!;
1223
- const [node, level] = head;
1224
-
1225
- if (!levelsNodes[level]) levelsNodes[level] = [];
1226
- collectByProperty(node, level);
1227
- if (node.right) stack.push([node.right, level + 1]);
1228
- if (node.left) stack.push([node.left, level + 1]);
1229
- }
1230
- }
1231
-
1232
- return levelsNodes;
1233
- }
1234
-
1235
- /**
1236
- * The function returns the predecessor of a given node in a binary tree.
1237
- * @param node - The parameter `node` is a BinaryTreeNode object, representing a node in a binary tree.
1238
- * @returns the predecessor of the given node in a binary tree.
1239
- */
1240
- getPredecessor(node: N): N {
1241
- if (node.left) {
1242
- let predecessor: N | null | undefined = node.left;
1243
- while (!predecessor || (predecessor.right && predecessor.right !== node)) {
1244
- if (predecessor) {
1245
- predecessor = predecessor.right;
1246
- }
1247
- }
1248
- return predecessor;
1249
- } else {
1250
- return node;
1251
- }
1252
- }
1253
-
1254
- /**
1255
- * Time complexity is O(n)
1256
- * Space complexity of Iterative dfs equals to recursive dfs which is O(n) because of the stack
1257
- */
1258
-
1259
- /**
1260
- * Performs an in-order, pre-order, or post-order traversal on a binary tree using the Morris traversal algorithm.
1261
- * @returns An array of binary tree node IDs.
1262
- */
1263
- morris(): BinaryTreeNodeKey[];
1264
-
1265
- /**
1266
- * Performs an in-order, pre-order, or post-order traversal on a binary tree using the Morris traversal algorithm and accumulates properties of each node based on the specified property name.
1267
- * @param {'in' | 'pre' | 'post'} [pattern] - The traversal pattern: 'in' (in-order), 'pre' (pre-order), or 'post' (post-order).
1268
- * @param {'key'} nodeOrPropertyName - The name of the property to accumulate.
1269
- * @returns An array of values corresponding to the specified property.
1270
- */
1271
- morris(pattern: DFSOrderPattern, nodeOrPropertyName: 'key'): BinaryTreeNodeKey[];
1272
-
1273
- /**
1274
- * Performs an in-order, pre-order, or post-order traversal on a binary tree using the Morris traversal algorithm and accumulates properties of each node based on the specified property name.
1275
- * @param {'in' | 'pre' | 'post'} [pattern] - The traversal pattern: 'in' (in-order), 'pre' (pre-order), or 'post' (post-order).
1276
- * @returns An array of values corresponding to the specified property.
1277
- */
1278
- morris(pattern: DFSOrderPattern): BinaryTreeNodeKey[];
1279
-
1280
- /**
1281
- * Performs an in-order, pre-order, or post-order traversal on a binary tree using the Morris traversal algorithm and accumulates the 'val' property of each node.
1282
- * @param {'in' | 'pre' | 'post'} [pattern] - The traversal pattern: 'in' (in-order), 'pre' (pre-order), or 'post' (post-order).
1283
- * @param {'val'} nodeOrPropertyName - The property of the BinaryTreeNode object to collect at each level.
1284
- * @returns An array of 'val' properties from each node.
1285
- */
1286
- morris(pattern: DFSOrderPattern, nodeOrPropertyName: 'val'): N[];
1287
-
1288
- /**
1289
- * Performs an in-order, pre-order, or post-order traversal on a binary tree using the Morris traversal algorithm and accumulates nodes themselves.
1290
- * @param {'in' | 'pre' | 'post'} [pattern] - The traversal pattern: 'in' (in-order), 'pre' (pre-order), or 'post' (post-order).
1291
- * @param {'node'} nodeOrPropertyName - The property of the BinaryTreeNode object to collect at each level.
1292
- * @returns An array of binary tree nodes.
1293
- */
1294
- morris(pattern: DFSOrderPattern, nodeOrPropertyName: 'node'): N[];
1295
-
1296
- /**
1297
- * The `morris` function performs an in-order, pre-order, or post-order traversal on a binary tree using the Morris traversal algorithm.
1298
- * @param {'in' | 'pre' | 'post'} [pattern] - The traversal pattern: 'in' (in-order), 'pre' (pre-order), or 'post' (post-order).
1299
- * @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'.
1300
- * @returns An array of AbstractBinaryTreeNodeProperties<N> objects.
1301
- */
1302
- morris(
1303
- pattern: DFSOrderPattern = 'in',
1304
- nodeOrPropertyName: NodeOrPropertyName = 'key'
1305
- ): AbstractBinaryTreeNodeProperties<N> {
1306
- if (this.root === null) return [];
1307
-
1308
- this._clearResults();
1309
-
1310
- let cur: N | null | undefined = this.root;
1311
- const _reverseEdge = (node: N | null | undefined) => {
1312
- let pre: N | null | undefined = null;
1313
- let next: N | null | undefined = null;
1314
- while (node) {
1315
- next = node.right;
1316
- node.right = pre;
1317
- pre = node;
1318
- node = next;
1319
- }
1320
- return pre;
1321
- };
1322
- const _printEdge = (node: N | null) => {
1323
- const tail: N | null | undefined = _reverseEdge(node);
1324
- let cur: N | null | undefined = tail;
1325
- while (cur) {
1326
- this._accumulatedByPropertyName(cur, nodeOrPropertyName);
1327
- cur = cur.right;
1328
- }
1329
- _reverseEdge(tail);
1330
- };
1331
- switch (pattern) {
1332
- case 'in':
1333
- while (cur) {
1334
- if (cur.left) {
1335
- const predecessor = this.getPredecessor(cur);
1336
- if (!predecessor.right) {
1337
- predecessor.right = cur;
1338
- cur = cur.left;
1339
- continue;
1340
- } else {
1341
- predecessor.right = null;
1342
- }
1343
- }
1344
- this._accumulatedByPropertyName(cur, nodeOrPropertyName);
1345
- cur = cur.right;
1346
- }
1347
- break;
1348
- case 'pre':
1349
- while (cur) {
1350
- if (cur.left) {
1351
- const predecessor = this.getPredecessor(cur);
1352
- if (!predecessor.right) {
1353
- predecessor.right = cur;
1354
- this._accumulatedByPropertyName(cur, nodeOrPropertyName);
1355
- cur = cur.left;
1356
- continue;
1357
- } else {
1358
- predecessor.right = null;
1359
- }
1360
- } else {
1361
- this._accumulatedByPropertyName(cur, nodeOrPropertyName);
1362
- }
1363
- cur = cur.right;
1364
- }
1365
- break;
1366
- case 'post':
1367
- while (cur) {
1368
- if (cur.left) {
1369
- const predecessor = this.getPredecessor(cur);
1370
- if (predecessor.right === null) {
1371
- predecessor.right = cur;
1372
- cur = cur.left;
1373
- continue;
1374
- } else {
1375
- predecessor.right = null;
1376
- _printEdge(cur.left);
1377
- }
1378
- }
1379
- cur = cur.right;
1380
- }
1381
- _printEdge(this.root);
1382
- break;
1383
- }
1384
-
1385
- return this._getResultByPropertyName(nodeOrPropertyName);
1386
- }
1387
-
1388
- /**
1389
- * The function adds a new node to a binary tree if there is an available position.
1390
- * @param {N | null} newNode - The `newNode` parameter is of type `N | null`, which means it can either be a node of
1391
- * type `N` or `null`. It represents the node that you want to add to the binary tree.
1392
- * @param {N} parent - The parent parameter is of type N, which represents a node in a binary tree.
1393
- * @returns either the left or right child node of the parent node, depending on which child is available for adding
1394
- * the new node. If a new node is added, the function also updates the size of the binary tree. If neither the left nor
1395
- * right child is available, the function returns undefined. If the parent node is null, the function also returns
1396
- * undefined.
1397
- */
1398
- protected _addTo(newNode: N | null, parent: N): N | null | undefined {
1399
- if (parent) {
1400
- // When all leaf nodes are null, it will no longer be possible to add new entity nodes to this binary tree.
1401
- // In this scenario, null nodes serve as "sentinel nodes," "virtual nodes," or "placeholder nodes."
1402
- if (parent.left === undefined) {
1403
- parent.left = newNode;
1404
- if (newNode) {
1405
- this._setSize(this.size + 1);
1406
- }
1407
- return parent.left;
1408
- } else if (parent.right === undefined) {
1409
- parent.right = newNode;
1410
- if (newNode) {
1411
- this._setSize(this.size + 1);
1412
- }
1413
- return parent.right;
1414
- } else {
1415
- return;
1416
- }
1417
- } else {
1418
- return;
1419
- }
1420
- }
1421
-
1422
- /**
1423
- * The function sets the loop type for a protected variable.
1424
- * @param {LoopType} value - The value parameter is of type LoopType.
1425
- */
1426
- protected _setLoopType(value: LoopType) {
1427
- this._loopType = value;
1428
- }
1429
-
1430
- /**
1431
- * The function sets the root property of an object to a given value, and if the value is not null, it also sets the
1432
- * parent property of the value to undefined.
1433
- * @param {N | null} v - The parameter `v` is of type `N | null`, which means it can either be of type `N` or `null`.
1434
- */
1435
- protected _setRoot(v: N | null) {
1436
- if (v) {
1437
- v.parent = undefined;
1438
- }
1439
- this._root = v;
1440
- }
1441
-
1442
- /**
1443
- * The function sets the size of a protected variable.
1444
- * @param {number} v - number
1445
- */
1446
- protected _setSize(v: number) {
1447
- this._size = v;
1448
- }
1449
-
1450
- /**
1451
- * The function `_clearResults` resets the values of several arrays used for tracking visited nodes and their
1452
- * properties.
1453
- */
1454
- protected _clearResults() {
1455
- this.visitedKey = [];
1456
- this.visitedVal = [];
1457
- this.visitedNode = [];
1458
- }
1459
-
1460
- /**
1461
- * The function checks if a given property of a binary tree node matches a specified value, and if so, adds the node to
1462
- * a result array.
1463
- * @param {N} cur - The current node being processed.
1464
- * @param {(N | null | undefined)[]} result - An array that stores the matching nodes.
1465
- * @param {BinaryTreeNodeKey | N} nodeProperty - The `nodeProperty` parameter is either a `BinaryTreeNodeKey` or a `N`
1466
- * type. It represents the property value that we are comparing against in the switch statement.
1467
- * @param {BinaryTreeNodePropertyName} [propertyName] - The `propertyName` parameter is an optional parameter that
1468
- * specifies the property name to compare against when pushing nodes into the `result` array. It can be either `'key'`
1469
- * or `'val'`. If it is not provided or is not equal to `'key'` or `'val'`, the
1470
- * @param {boolean} [onlyOne] - The `onlyOne` parameter is an optional boolean parameter that determines whether to
1471
- * stop after finding the first matching node or continue searching for all matching nodes. If `onlyOne` is set to
1472
- * `true`, the function will stop after finding the first matching node and return `true`. If `onlyOne
1473
- * @returns a boolean value indicating whether only one matching node should be pushed into the result array.
1474
- */
1475
- protected _pushByPropertyNameStopOrNot(
1476
- cur: N,
1477
- result: (N | null | undefined)[],
1478
- nodeProperty: BinaryTreeNodeKey | N,
1479
- propertyName: BinaryTreeNodePropertyName = 'key',
1480
- onlyOne = false
1481
- ) {
1482
- switch (propertyName) {
1483
- case 'key':
1484
- if (cur.key === nodeProperty) {
1485
- result.push(cur);
1486
- return onlyOne;
1487
- }
1488
- break;
1489
- case 'val':
1490
- if (cur.val === nodeProperty) {
1491
- result.push(cur);
1492
- return onlyOne;
1493
- }
1494
- break;
1495
- default:
1496
- if (cur.key === nodeProperty) {
1497
- result.push(cur);
1498
- return onlyOne;
1499
- }
1500
- break;
1501
- }
1502
- }
1503
-
1504
- /**
1505
- * The function `_accumulatedByPropertyName` accumulates values from a given node based on the specified property name.
1506
- * @param {N} node - The `node` parameter is of type `N`, which represents a node in a data structure.
1507
- * @param {NodeOrPropertyName} [nodeOrPropertyName] - The `nodeOrPropertyName` parameter is an optional parameter that
1508
- * can be either a string representing a property name or a reference to a `Node` object. If it is a string, it
1509
- * specifies the property name to be used for accumulating values. If it is a `Node` object, it specifies
1510
- */
1511
- protected _accumulatedByPropertyName(node: N, nodeOrPropertyName: NodeOrPropertyName = 'key') {
1512
- switch (nodeOrPropertyName) {
1513
- case 'key':
1514
- this.visitedKey.push(node.key);
1515
- break;
1516
- case 'val':
1517
- this.visitedVal.push(node.val);
1518
- break;
1519
- case 'node':
1520
- this.visitedNode.push(node);
1521
- break;
1522
- default:
1523
- this.visitedKey.push(node.key);
1524
- break;
1525
- }
1526
- }
1527
-
1528
- /**
1529
- * The time complexity of Morris traversal is O(n), it may slower than others
1530
- * The space complexity Morris traversal is O(1) because no using stack
1531
- */
1532
-
1533
- /**
1534
- * The function `_getResultByPropertyName` returns the corresponding property value based on the given node or property
1535
- * name.
1536
- * @param {NodeOrPropertyName} [nodeOrPropertyName] - The parameter `nodeOrPropertyName` is an optional parameter that
1537
- * can accept either a `NodeOrPropertyName` type or be undefined.
1538
- * @returns The method `_getResultByPropertyName` returns an instance of `AbstractBinaryTreeNodeProperties<N>`.
1539
- */
1540
- protected _getResultByPropertyName(
1541
- nodeOrPropertyName: NodeOrPropertyName = 'key'
1542
- ): AbstractBinaryTreeNodeProperties<N> {
1543
- switch (nodeOrPropertyName) {
1544
- case 'key':
1545
- return this.visitedKey;
1546
- case 'val':
1547
- return this.visitedVal;
1548
- case 'node':
1549
- return this.visitedNode;
1550
- default:
1551
- return this.visitedKey;
1552
- }
1553
- }
1554
-
1555
- // --- end additional methods ---
1556
- }