data-structure-typed 1.21.4 → 1.32.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 (660) hide show
  1. package/.auto-changelog +9 -0
  2. package/.auto-changelog-template.hbs +36 -0
  3. package/.eslintrc.js +61 -0
  4. package/.gitattributes +112 -0
  5. package/.github/workflows/ci.yml +30 -0
  6. package/.prettierignore +6 -0
  7. package/.prettierrc.js +16 -0
  8. package/CHANGELOG.md +17 -0
  9. package/CODE-OF-CONDUCT.md +80 -0
  10. package/COMMANDS.md +28 -0
  11. package/README.md +147 -95
  12. package/SECURITY.md +15 -0
  13. package/coverage/clover.xml +3393 -0
  14. package/coverage/coverage-final.json +67 -0
  15. package/coverage/lcov-report/base.css +224 -0
  16. package/coverage/lcov-report/block-navigation.js +87 -0
  17. package/coverage/lcov-report/favicon.png +0 -0
  18. package/coverage/lcov-report/index.html +386 -0
  19. package/coverage/lcov-report/prettify.css +1 -0
  20. package/coverage/lcov-report/prettify.js +2 -0
  21. package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
  22. package/coverage/lcov-report/sorter.js +196 -0
  23. package/coverage/lcov-report/src/data-structures/binary-tree/aa-tree.ts.html +88 -0
  24. package/coverage/lcov-report/src/data-structures/binary-tree/abstract-binary-tree.ts.html +4966 -0
  25. package/coverage/lcov-report/src/data-structures/binary-tree/avl-tree.ts.html +1015 -0
  26. package/coverage/lcov-report/src/data-structures/binary-tree/b-tree.ts.html +88 -0
  27. package/coverage/lcov-report/src/data-structures/binary-tree/binary-indexed-tree.ts.html +313 -0
  28. package/coverage/lcov-report/src/data-structures/binary-tree/binary-tree.ts.html +226 -0
  29. package/coverage/lcov-report/src/data-structures/binary-tree/bst.ts.html +1714 -0
  30. package/coverage/lcov-report/src/data-structures/binary-tree/index.html +296 -0
  31. package/coverage/lcov-report/src/data-structures/binary-tree/index.ts.html +121 -0
  32. package/coverage/lcov-report/src/data-structures/binary-tree/rb-tree.ts.html +388 -0
  33. package/coverage/lcov-report/src/data-structures/binary-tree/segment-tree.ts.html +811 -0
  34. package/coverage/lcov-report/src/data-structures/binary-tree/splay-tree.ts.html +88 -0
  35. package/coverage/lcov-report/src/data-structures/binary-tree/tree-multiset.ts.html +2185 -0
  36. package/coverage/lcov-report/src/data-structures/binary-tree/two-three-tree.ts.html +88 -0
  37. package/coverage/lcov-report/src/data-structures/graph/abstract-graph.ts.html +3205 -0
  38. package/coverage/lcov-report/src/data-structures/graph/directed-graph.ts.html +1495 -0
  39. package/coverage/lcov-report/src/data-structures/graph/index.html +176 -0
  40. package/coverage/lcov-report/src/data-structures/graph/index.ts.html +97 -0
  41. package/coverage/lcov-report/src/data-structures/graph/map-graph.ts.html +472 -0
  42. package/coverage/lcov-report/src/data-structures/graph/undirected-graph.ts.html +907 -0
  43. package/coverage/lcov-report/src/data-structures/hash/coordinate-map.ts.html +286 -0
  44. package/coverage/lcov-report/src/data-structures/hash/coordinate-set.ts.html +253 -0
  45. package/coverage/lcov-report/src/data-structures/hash/hash-table.ts.html +88 -0
  46. package/coverage/lcov-report/src/data-structures/hash/index.html +206 -0
  47. package/coverage/lcov-report/src/data-structures/hash/index.ts.html +103 -0
  48. package/coverage/lcov-report/src/data-structures/hash/pair.ts.html +88 -0
  49. package/coverage/lcov-report/src/data-structures/hash/tree-map.ts.html +88 -0
  50. package/coverage/lcov-report/src/data-structures/hash/tree-set.ts.html +88 -0
  51. package/coverage/lcov-report/src/data-structures/heap/heap.ts.html +721 -0
  52. package/coverage/lcov-report/src/data-structures/heap/index.html +161 -0
  53. package/coverage/lcov-report/src/data-structures/heap/index.ts.html +94 -0
  54. package/coverage/lcov-report/src/data-structures/heap/max-heap.ts.html +178 -0
  55. package/coverage/lcov-report/src/data-structures/heap/min-heap.ts.html +181 -0
  56. package/coverage/lcov-report/src/data-structures/index.html +116 -0
  57. package/coverage/lcov-report/src/data-structures/index.ts.html +118 -0
  58. package/coverage/lcov-report/src/data-structures/linked-list/doubly-linked-list.ts.html +1804 -0
  59. package/coverage/lcov-report/src/data-structures/linked-list/index.html +161 -0
  60. package/coverage/lcov-report/src/data-structures/linked-list/index.ts.html +94 -0
  61. package/coverage/lcov-report/src/data-structures/linked-list/singly-linked-list.ts.html +1588 -0
  62. package/coverage/lcov-report/src/data-structures/linked-list/skip-linked-list.ts.html +88 -0
  63. package/coverage/lcov-report/src/data-structures/matrix/index.html +176 -0
  64. package/coverage/lcov-report/src/data-structures/matrix/index.ts.html +97 -0
  65. package/coverage/lcov-report/src/data-structures/matrix/matrix.ts.html +166 -0
  66. package/coverage/lcov-report/src/data-structures/matrix/matrix2d.ts.html +721 -0
  67. package/coverage/lcov-report/src/data-structures/matrix/navigator.ts.html +448 -0
  68. package/coverage/lcov-report/src/data-structures/matrix/vector2d.ts.html +1033 -0
  69. package/coverage/lcov-report/src/data-structures/priority-queue/index.html +161 -0
  70. package/coverage/lcov-report/src/data-structures/priority-queue/index.ts.html +94 -0
  71. package/coverage/lcov-report/src/data-structures/priority-queue/max-priority-queue.ts.html +253 -0
  72. package/coverage/lcov-report/src/data-structures/priority-queue/min-priority-queue.ts.html +256 -0
  73. package/coverage/lcov-report/src/data-structures/priority-queue/priority-queue.ts.html +1162 -0
  74. package/coverage/lcov-report/src/data-structures/queue/deque.ts.html +976 -0
  75. package/coverage/lcov-report/src/data-structures/queue/index.html +146 -0
  76. package/coverage/lcov-report/src/data-structures/queue/index.ts.html +91 -0
  77. package/coverage/lcov-report/src/data-structures/queue/queue.ts.html +658 -0
  78. package/coverage/lcov-report/src/data-structures/stack/index.html +131 -0
  79. package/coverage/lcov-report/src/data-structures/stack/index.ts.html +88 -0
  80. package/coverage/lcov-report/src/data-structures/stack/stack.ts.html +379 -0
  81. package/coverage/lcov-report/src/data-structures/tree/index.html +131 -0
  82. package/coverage/lcov-report/src/data-structures/tree/index.ts.html +88 -0
  83. package/coverage/lcov-report/src/data-structures/tree/tree.ts.html +292 -0
  84. package/coverage/lcov-report/src/data-structures/trie/index.html +131 -0
  85. package/coverage/lcov-report/src/data-structures/trie/index.ts.html +88 -0
  86. package/coverage/lcov-report/src/data-structures/trie/trie.ts.html +760 -0
  87. package/coverage/lcov-report/src/index.html +116 -0
  88. package/coverage/lcov-report/src/index.ts.html +97 -0
  89. package/coverage/lcov-report/src/interfaces/index.html +116 -0
  90. package/coverage/lcov-report/src/interfaces/index.ts.html +130 -0
  91. package/coverage/lcov-report/src/types/data-structures/abstract-binary-tree.ts.html +235 -0
  92. package/coverage/lcov-report/src/types/data-structures/bst.ts.html +124 -0
  93. package/coverage/lcov-report/src/types/data-structures/directed-graph.ts.html +109 -0
  94. package/coverage/lcov-report/src/types/data-structures/index.html +176 -0
  95. package/coverage/lcov-report/src/types/data-structures/index.ts.html +130 -0
  96. package/coverage/lcov-report/src/types/data-structures/rb-tree.ts.html +106 -0
  97. package/coverage/lcov-report/src/types/index.html +116 -0
  98. package/coverage/lcov-report/src/types/index.ts.html +94 -0
  99. package/coverage/lcov-report/src/types/utils/index.html +116 -0
  100. package/coverage/lcov-report/src/types/utils/index.ts.html +91 -0
  101. package/coverage/lcov-report/src/utils/index.html +131 -0
  102. package/coverage/lcov-report/src/utils/index.ts.html +88 -0
  103. package/coverage/lcov-report/src/utils/utils.ts.html +322 -0
  104. package/coverage/lcov-report/test/utils/index.html +146 -0
  105. package/coverage/lcov-report/test/utils/index.ts.html +91 -0
  106. package/coverage/lcov-report/test/utils/magnitude.ts.html +148 -0
  107. package/coverage/lcov-report/test/utils/number.ts.html +94 -0
  108. package/coverage/lcov.info +6676 -0
  109. package/dist/data-structures/binary-tree/aa-tree.js +6 -2
  110. package/dist/data-structures/binary-tree/aa-tree.js.map +1 -0
  111. package/dist/data-structures/binary-tree/abstract-binary-tree.js +398 -672
  112. package/dist/data-structures/binary-tree/abstract-binary-tree.js.map +1 -0
  113. package/dist/data-structures/binary-tree/avl-tree.js +122 -151
  114. package/dist/data-structures/binary-tree/avl-tree.js.map +1 -0
  115. package/dist/data-structures/binary-tree/b-tree.js +6 -2
  116. package/dist/data-structures/binary-tree/b-tree.js.map +1 -0
  117. package/dist/data-structures/binary-tree/binary-indexed-tree.js +24 -54
  118. package/dist/data-structures/binary-tree/binary-indexed-tree.js.map +1 -0
  119. package/dist/data-structures/binary-tree/binary-tree.js +31 -32
  120. package/dist/data-structures/binary-tree/binary-tree.js.map +1 -0
  121. package/dist/data-structures/binary-tree/bst.js +266 -208
  122. package/dist/data-structures/binary-tree/bst.js.map +1 -0
  123. package/dist/data-structures/binary-tree/index.js +1 -0
  124. package/dist/data-structures/binary-tree/index.js.map +1 -0
  125. package/dist/data-structures/binary-tree/rb-tree.js +46 -37
  126. package/dist/data-structures/binary-tree/rb-tree.js.map +1 -0
  127. package/dist/data-structures/binary-tree/segment-tree.js +124 -127
  128. package/dist/data-structures/binary-tree/segment-tree.js.map +1 -0
  129. package/dist/data-structures/binary-tree/splay-tree.js +6 -2
  130. package/dist/data-structures/binary-tree/splay-tree.js.map +1 -0
  131. package/dist/data-structures/binary-tree/tree-multiset.js +227 -354
  132. package/dist/data-structures/binary-tree/tree-multiset.js.map +1 -0
  133. package/dist/data-structures/binary-tree/two-three-tree.js +6 -2
  134. package/dist/data-structures/binary-tree/two-three-tree.js.map +1 -0
  135. package/dist/data-structures/graph/abstract-graph.js +582 -609
  136. package/dist/data-structures/graph/abstract-graph.js.map +1 -0
  137. package/dist/data-structures/graph/directed-graph.js +276 -312
  138. package/dist/data-structures/graph/directed-graph.js.map +1 -0
  139. package/dist/data-structures/graph/index.js +1 -0
  140. package/dist/data-structures/graph/index.js.map +1 -0
  141. package/dist/data-structures/graph/map-graph.js +88 -100
  142. package/dist/data-structures/graph/map-graph.js.map +1 -0
  143. package/dist/data-structures/graph/undirected-graph.js +180 -195
  144. package/dist/data-structures/graph/undirected-graph.js.map +1 -0
  145. package/dist/data-structures/hash/coordinate-map.js +46 -58
  146. package/dist/data-structures/hash/coordinate-map.js.map +1 -0
  147. package/dist/data-structures/hash/coordinate-set.js +43 -48
  148. package/dist/data-structures/hash/coordinate-set.js.map +1 -0
  149. package/dist/data-structures/hash/hash-table.js +6 -2
  150. package/dist/data-structures/hash/hash-table.js.map +1 -0
  151. package/dist/data-structures/hash/index.js +1 -0
  152. package/dist/data-structures/hash/index.js.map +1 -0
  153. package/dist/data-structures/hash/pair.js +6 -2
  154. package/dist/data-structures/hash/pair.js.map +1 -0
  155. package/dist/data-structures/hash/tree-map.js +6 -2
  156. package/dist/data-structures/hash/tree-map.js.map +1 -0
  157. package/dist/data-structures/hash/tree-set.js +6 -2
  158. package/dist/data-structures/hash/tree-set.js.map +1 -0
  159. package/dist/data-structures/heap/heap.js +83 -120
  160. package/dist/data-structures/heap/heap.js.map +1 -0
  161. package/dist/data-structures/heap/index.js +1 -0
  162. package/dist/data-structures/heap/index.js.map +1 -0
  163. package/dist/data-structures/heap/max-heap.js +27 -24
  164. package/dist/data-structures/heap/max-heap.js.map +1 -0
  165. package/dist/data-structures/heap/min-heap.js +27 -25
  166. package/dist/data-structures/heap/min-heap.js.map +1 -0
  167. package/dist/data-structures/index.js +1 -0
  168. package/dist/data-structures/index.js.map +1 -0
  169. package/dist/data-structures/linked-list/doubly-linked-list.js +202 -307
  170. package/dist/data-structures/linked-list/doubly-linked-list.js.map +1 -0
  171. package/dist/data-structures/linked-list/index.js +1 -0
  172. package/dist/data-structures/linked-list/index.js.map +1 -0
  173. package/dist/data-structures/linked-list/singly-linked-list.js +223 -251
  174. package/dist/data-structures/linked-list/singly-linked-list.js.map +1 -0
  175. package/dist/data-structures/linked-list/skip-linked-list.js +6 -2
  176. package/dist/data-structures/linked-list/skip-linked-list.js.map +1 -0
  177. package/dist/data-structures/matrix/index.js +1 -0
  178. package/dist/data-structures/matrix/index.js.map +1 -0
  179. package/dist/data-structures/matrix/matrix.js +9 -22
  180. package/dist/data-structures/matrix/matrix.js.map +1 -0
  181. package/dist/data-structures/matrix/matrix2d.js +75 -149
  182. package/dist/data-structures/matrix/matrix2d.js.map +1 -0
  183. package/dist/data-structures/matrix/navigator.js +38 -46
  184. package/dist/data-structures/matrix/navigator.js.map +1 -0
  185. package/dist/data-structures/matrix/vector2d.js +90 -254
  186. package/dist/data-structures/matrix/vector2d.js.map +1 -0
  187. package/dist/data-structures/priority-queue/index.js +1 -0
  188. package/dist/data-structures/priority-queue/index.js.map +1 -0
  189. package/dist/data-structures/priority-queue/max-priority-queue.js +47 -32
  190. package/dist/data-structures/priority-queue/max-priority-queue.js.map +1 -0
  191. package/dist/data-structures/priority-queue/min-priority-queue.js +47 -33
  192. package/dist/data-structures/priority-queue/min-priority-queue.js.map +1 -0
  193. package/dist/data-structures/priority-queue/priority-queue.js +150 -241
  194. package/dist/data-structures/priority-queue/priority-queue.js.map +1 -0
  195. package/dist/data-structures/queue/deque.js +130 -162
  196. package/dist/data-structures/queue/deque.js.map +1 -0
  197. package/dist/data-structures/queue/index.js +1 -0
  198. package/dist/data-structures/queue/index.js.map +1 -0
  199. package/dist/data-structures/queue/queue.js +181 -100
  200. package/dist/data-structures/queue/queue.js.map +1 -0
  201. package/dist/data-structures/stack/index.js +1 -0
  202. package/dist/data-structures/stack/index.js.map +1 -0
  203. package/dist/data-structures/stack/stack.js +23 -71
  204. package/dist/data-structures/stack/stack.js.map +1 -0
  205. package/dist/data-structures/tree/index.js +1 -0
  206. package/dist/data-structures/tree/index.js.map +1 -0
  207. package/dist/data-structures/tree/tree.js +46 -33
  208. package/dist/data-structures/tree/tree.js.map +1 -0
  209. package/dist/data-structures/trie/index.js +1 -0
  210. package/dist/data-structures/trie/index.js.map +1 -0
  211. package/dist/data-structures/trie/trie.js +201 -129
  212. package/dist/data-structures/trie/trie.js.map +1 -0
  213. package/dist/index.js +1 -0
  214. package/dist/index.js.map +1 -0
  215. package/dist/interfaces/abstract-binary-tree.js +1 -0
  216. package/dist/interfaces/abstract-binary-tree.js.map +1 -0
  217. package/dist/interfaces/abstract-graph.js +1 -0
  218. package/dist/interfaces/abstract-graph.js.map +1 -0
  219. package/dist/interfaces/avl-tree.js +1 -0
  220. package/dist/interfaces/avl-tree.js.map +1 -0
  221. package/dist/interfaces/binary-tree.js +1 -0
  222. package/dist/interfaces/binary-tree.js.map +1 -0
  223. package/dist/interfaces/bst.js +1 -0
  224. package/dist/interfaces/bst.js.map +1 -0
  225. package/dist/interfaces/directed-graph.js +1 -0
  226. package/dist/interfaces/directed-graph.js.map +1 -0
  227. package/dist/interfaces/doubly-linked-list.js +1 -0
  228. package/dist/interfaces/doubly-linked-list.js.map +1 -0
  229. package/dist/interfaces/heap.js +1 -0
  230. package/dist/interfaces/heap.js.map +1 -0
  231. package/dist/interfaces/index.js +1 -0
  232. package/dist/interfaces/index.js.map +1 -0
  233. package/dist/interfaces/navigator.js +1 -0
  234. package/dist/interfaces/navigator.js.map +1 -0
  235. package/dist/interfaces/priority-queue.js +1 -0
  236. package/dist/interfaces/priority-queue.js.map +1 -0
  237. package/dist/interfaces/rb-tree.js +1 -0
  238. package/dist/interfaces/rb-tree.js.map +1 -0
  239. package/dist/interfaces/segment-tree.js +1 -0
  240. package/dist/interfaces/segment-tree.js.map +1 -0
  241. package/dist/interfaces/singly-linked-list.js +1 -0
  242. package/dist/interfaces/singly-linked-list.js.map +1 -0
  243. package/dist/interfaces/tree-multiset.js +1 -0
  244. package/dist/interfaces/tree-multiset.js.map +1 -0
  245. package/dist/interfaces/undirected-graph.js +1 -0
  246. package/dist/interfaces/undirected-graph.js.map +1 -0
  247. package/dist/types/data-structures/abstract-binary-tree.js +1 -7
  248. package/dist/types/data-structures/abstract-binary-tree.js.map +1 -0
  249. package/dist/types/data-structures/abstract-graph.js +1 -0
  250. package/dist/types/data-structures/abstract-graph.js.map +1 -0
  251. package/dist/types/data-structures/avl-tree.js +1 -0
  252. package/dist/types/data-structures/avl-tree.js.map +1 -0
  253. package/dist/types/data-structures/binary-tree.js +1 -0
  254. package/dist/types/data-structures/binary-tree.js.map +1 -0
  255. package/dist/types/data-structures/bst.js +1 -0
  256. package/dist/types/data-structures/bst.js.map +1 -0
  257. package/dist/types/data-structures/directed-graph.js +1 -0
  258. package/dist/types/data-structures/directed-graph.js.map +1 -0
  259. package/dist/types/data-structures/doubly-linked-list.js +1 -0
  260. package/dist/types/data-structures/doubly-linked-list.js.map +1 -0
  261. package/dist/types/data-structures/heap.js +1 -0
  262. package/dist/types/data-structures/heap.js.map +1 -0
  263. package/dist/types/data-structures/index.js +1 -0
  264. package/dist/types/data-structures/index.js.map +1 -0
  265. package/dist/types/data-structures/map-graph.js +1 -0
  266. package/dist/types/data-structures/map-graph.js.map +1 -0
  267. package/dist/types/data-structures/navigator.js +1 -0
  268. package/dist/types/data-structures/navigator.js.map +1 -0
  269. package/dist/types/data-structures/priority-queue.js +1 -0
  270. package/dist/types/data-structures/priority-queue.js.map +1 -0
  271. package/dist/types/data-structures/rb-tree.js +1 -0
  272. package/dist/types/data-structures/rb-tree.js.map +1 -0
  273. package/dist/types/data-structures/segment-tree.js +1 -0
  274. package/dist/types/data-structures/segment-tree.js.map +1 -0
  275. package/dist/types/data-structures/singly-linked-list.js +1 -0
  276. package/dist/types/data-structures/singly-linked-list.js.map +1 -0
  277. package/dist/types/data-structures/tree-multiset.js +1 -0
  278. package/dist/types/data-structures/tree-multiset.js.map +1 -0
  279. package/dist/types/helpers.js +1 -0
  280. package/dist/types/helpers.js.map +1 -0
  281. package/dist/types/index.js +1 -0
  282. package/dist/types/index.js.map +1 -0
  283. package/dist/types/utils/index.js +1 -0
  284. package/dist/types/utils/index.js.map +1 -0
  285. package/dist/types/utils/utils.js +1 -0
  286. package/dist/types/utils/utils.js.map +1 -0
  287. package/dist/types/utils/validate-type.js +1 -0
  288. package/dist/types/utils/validate-type.js.map +1 -0
  289. package/dist/utils/index.js +1 -0
  290. package/dist/utils/index.js.map +1 -0
  291. package/dist/utils/utils.js +108 -22
  292. package/dist/utils/utils.js.map +1 -0
  293. package/docs/.nojekyll +1 -0
  294. package/docs/assets/highlight.css +127 -0
  295. package/docs/assets/main.js +58 -0
  296. package/docs/assets/search.js +1 -0
  297. package/docs/assets/style.css +1367 -0
  298. package/docs/classes/AVLTree.html +2182 -0
  299. package/docs/classes/AVLTreeNode.html +399 -0
  300. package/docs/classes/AaTree.html +202 -0
  301. package/docs/classes/AbstractBinaryTree.html +1836 -0
  302. package/docs/classes/AbstractBinaryTreeNode.html +441 -0
  303. package/docs/classes/AbstractEdge.html +345 -0
  304. package/docs/classes/AbstractGraph.html +1105 -0
  305. package/docs/classes/AbstractVertex.html +299 -0
  306. package/docs/classes/ArrayDeque.html +469 -0
  307. package/docs/classes/BST.html +2026 -0
  308. package/docs/classes/BSTNode.html +400 -0
  309. package/docs/classes/BTree.html +202 -0
  310. package/docs/classes/BinaryIndexedTree.html +371 -0
  311. package/docs/classes/BinaryTree.html +1867 -0
  312. package/docs/classes/BinaryTreeNode.html +399 -0
  313. package/docs/classes/Character.html +250 -0
  314. package/docs/classes/CoordinateMap.html +513 -0
  315. package/docs/classes/CoordinateSet.html +474 -0
  316. package/docs/classes/Deque.html +1005 -0
  317. package/docs/classes/DirectedEdge.html +404 -0
  318. package/docs/classes/DirectedGraph.html +1530 -0
  319. package/docs/classes/DirectedVertex.html +286 -0
  320. package/docs/classes/DoublyLinkedList.html +998 -0
  321. package/docs/classes/DoublyLinkedListNode.html +327 -0
  322. package/docs/classes/HashTable.html +202 -0
  323. package/docs/classes/Heap.html +647 -0
  324. package/docs/classes/HeapItem.html +296 -0
  325. package/docs/classes/LinkedListQueue.html +884 -0
  326. package/docs/classes/MapEdge.html +391 -0
  327. package/docs/classes/MapGraph.html +1583 -0
  328. package/docs/classes/MapVertex.html +356 -0
  329. package/docs/classes/Matrix2D.html +532 -0
  330. package/docs/classes/MatrixNTI2D.html +270 -0
  331. package/docs/classes/MaxHeap.html +671 -0
  332. package/docs/classes/MaxPriorityQueue.html +866 -0
  333. package/docs/classes/MinHeap.html +672 -0
  334. package/docs/classes/MinPriorityQueue.html +868 -0
  335. package/docs/classes/Navigator.html +343 -0
  336. package/docs/classes/ObjectDeque.html +527 -0
  337. package/docs/classes/Pair.html +202 -0
  338. package/docs/classes/PriorityQueue.html +790 -0
  339. package/docs/classes/Queue.html +521 -0
  340. package/docs/classes/RBTree.html +2024 -0
  341. package/docs/classes/RBTreeNode.html +431 -0
  342. package/docs/classes/SegmentTree.html +464 -0
  343. package/docs/classes/SegmentTreeNode.html +387 -0
  344. package/docs/classes/SinglyLinkedList.html +830 -0
  345. package/docs/classes/SinglyLinkedListNode.html +300 -0
  346. package/docs/classes/SkipLinkedList.html +202 -0
  347. package/docs/classes/SplayTree.html +202 -0
  348. package/docs/classes/Stack.html +398 -0
  349. package/docs/classes/TreeMap.html +202 -0
  350. package/docs/classes/TreeMultiset.html +2510 -0
  351. package/docs/classes/TreeMultisetNode.html +447 -0
  352. package/docs/classes/TreeNode.html +344 -0
  353. package/docs/classes/TreeSet.html +202 -0
  354. package/docs/classes/Trie.html +402 -0
  355. package/docs/classes/TrieNode.html +310 -0
  356. package/docs/classes/TwoThreeTree.html +202 -0
  357. package/docs/classes/UndirectedEdge.html +374 -0
  358. package/docs/classes/UndirectedGraph.html +1285 -0
  359. package/docs/classes/UndirectedVertex.html +284 -0
  360. package/docs/classes/Vector2D.html +835 -0
  361. package/docs/enums/CP.html +211 -0
  362. package/docs/enums/FamilyPosition.html +239 -0
  363. package/docs/enums/LoopType.html +212 -0
  364. package/docs/enums/RBColor.html +204 -0
  365. package/docs/enums/TopologicalProperty.html +211 -0
  366. package/docs/functions/arrayRemove.html +208 -0
  367. package/docs/functions/isThunk.html +186 -0
  368. package/docs/functions/toThunk.html +186 -0
  369. package/docs/functions/trampoline.html +186 -0
  370. package/docs/functions/trampolineAsync.html +186 -0
  371. package/docs/functions/uuidV4.html +181 -0
  372. package/docs/index.html +693 -0
  373. package/docs/interfaces/IAVLTree.html +1245 -0
  374. package/docs/interfaces/IAbstractBinaryTree.html +1101 -0
  375. package/docs/interfaces/IAbstractBinaryTreeNode.html +335 -0
  376. package/docs/interfaces/IAbstractGraph.html +433 -0
  377. package/docs/interfaces/IBST.html +1245 -0
  378. package/docs/interfaces/IDirectedGraph.html +570 -0
  379. package/docs/interfaces/IRBTree.html +1247 -0
  380. package/docs/interfaces/IUNDirectedGraph.html +463 -0
  381. package/docs/modules.html +328 -0
  382. package/docs/types/AVLTreeNodeNested.html +182 -0
  383. package/docs/types/AVLTreeOptions.html +180 -0
  384. package/docs/types/AbstractBinaryTreeNodeNested.html +182 -0
  385. package/docs/types/AbstractBinaryTreeNodeProperties.html +182 -0
  386. package/docs/types/AbstractBinaryTreeNodeProperty.html +182 -0
  387. package/docs/types/AbstractBinaryTreeOptions.html +182 -0
  388. package/docs/types/BSTComparator.html +192 -0
  389. package/docs/types/BSTNodeNested.html +182 -0
  390. package/docs/types/BSTOptions.html +182 -0
  391. package/docs/types/BinaryTreeDeletedResult.html +189 -0
  392. package/docs/types/BinaryTreeNodeId.html +177 -0
  393. package/docs/types/BinaryTreeNodeNested.html +182 -0
  394. package/docs/types/BinaryTreeNodePropertyName.html +177 -0
  395. package/docs/types/BinaryTreeOptions.html +180 -0
  396. package/docs/types/DFSOrderPattern.html +177 -0
  397. package/docs/types/DijkstraResult.html +199 -0
  398. package/docs/types/Direction.html +177 -0
  399. package/docs/types/DummyAny.html +190 -0
  400. package/docs/types/EdgeId.html +177 -0
  401. package/docs/types/HeapOptions.html +198 -0
  402. package/docs/types/IAVLTreeNode.html +184 -0
  403. package/docs/types/IBSTNode.html +184 -0
  404. package/docs/types/IBinaryTree.html +182 -0
  405. package/docs/types/IBinaryTreeNode.html +184 -0
  406. package/docs/types/IRBTreeNode.html +184 -0
  407. package/docs/types/ITreeMultiset.html +182 -0
  408. package/docs/types/ITreeMultisetNode.html +184 -0
  409. package/docs/types/KeyValueObject.html +182 -0
  410. package/docs/types/KeyValueObjectWithId.html +184 -0
  411. package/docs/types/MapGraphCoordinate.html +177 -0
  412. package/docs/types/NavigatorParams.html +211 -0
  413. package/docs/types/NodeOrPropertyName.html +177 -0
  414. package/docs/types/NonNumberNonObjectButDefined.html +177 -0
  415. package/docs/types/ObjectWithNonNumberId.html +184 -0
  416. package/docs/types/ObjectWithNumberId.html +184 -0
  417. package/docs/types/ObjectWithoutId.html +177 -0
  418. package/docs/types/PriorityQueueComparator.html +197 -0
  419. package/docs/types/PriorityQueueDFSOrderPattern.html +177 -0
  420. package/docs/types/PriorityQueueOptions.html +191 -0
  421. package/docs/types/RBTreeNodeNested.html +182 -0
  422. package/docs/types/RBTreeOptions.html +180 -0
  423. package/docs/types/RestrictValById.html +177 -0
  424. package/docs/types/SegmentTreeNodeVal.html +177 -0
  425. package/docs/types/SpecifyOptional.html +184 -0
  426. package/docs/types/Thunk.html +185 -0
  427. package/docs/types/ToThunkFn.html +185 -0
  428. package/docs/types/TopologicalStatus.html +177 -0
  429. package/docs/types/TreeMultisetNodeNested.html +182 -0
  430. package/docs/types/TreeMultisetOptions.html +180 -0
  431. package/docs/types/TrlAsyncFn.html +190 -0
  432. package/docs/types/TrlFn.html +190 -0
  433. package/docs/types/Turning.html +177 -0
  434. package/docs/types/VertexId.html +177 -0
  435. package/docs/variables/THUNK_SYMBOL.html +177 -0
  436. package/jest.config.js +7 -0
  437. package/lib/data-structures/binary-tree/aa-tree.js +2 -0
  438. package/{dist → lib}/data-structures/binary-tree/abstract-binary-tree.d.ts +194 -22
  439. package/lib/data-structures/binary-tree/abstract-binary-tree.js +1291 -0
  440. package/{dist → lib}/data-structures/binary-tree/avl-tree.d.ts +12 -12
  441. package/lib/data-structures/binary-tree/avl-tree.js +311 -0
  442. package/lib/data-structures/binary-tree/b-tree.js +2 -0
  443. package/lib/data-structures/binary-tree/binary-indexed-tree.js +69 -0
  444. package/lib/data-structures/binary-tree/binary-tree.js +35 -0
  445. package/{dist → lib}/data-structures/binary-tree/bst.d.ts +19 -8
  446. package/lib/data-structures/binary-tree/bst.js +551 -0
  447. package/lib/data-structures/binary-tree/index.js +12 -0
  448. package/{dist → lib}/data-structures/binary-tree/rb-tree.d.ts +0 -6
  449. package/lib/data-structures/binary-tree/rb-tree.js +22 -0
  450. package/lib/data-structures/binary-tree/segment-tree.js +210 -0
  451. package/lib/data-structures/binary-tree/splay-tree.js +2 -0
  452. package/{dist → lib}/data-structures/binary-tree/tree-multiset.d.ts +20 -23
  453. package/lib/data-structures/binary-tree/tree-multiset.js +673 -0
  454. package/lib/data-structures/binary-tree/two-three-tree.js +2 -0
  455. package/lib/data-structures/graph/abstract-graph.js +918 -0
  456. package/lib/data-structures/graph/directed-graph.js +416 -0
  457. package/lib/data-structures/graph/index.js +4 -0
  458. package/lib/data-structures/graph/map-graph.js +105 -0
  459. package/lib/data-structures/graph/undirected-graph.js +246 -0
  460. package/lib/data-structures/hash/coordinate-map.js +61 -0
  461. package/lib/data-structures/hash/coordinate-set.js +51 -0
  462. package/lib/data-structures/hash/hash-table.js +2 -0
  463. package/lib/data-structures/hash/index.js +6 -0
  464. package/lib/data-structures/hash/pair.js +2 -0
  465. package/lib/data-structures/hash/tree-map.js +2 -0
  466. package/lib/data-structures/hash/tree-set.js +2 -0
  467. package/lib/data-structures/heap/heap.js +152 -0
  468. package/lib/data-structures/heap/index.js +3 -0
  469. package/lib/data-structures/heap/max-heap.js +26 -0
  470. package/lib/data-structures/heap/min-heap.js +27 -0
  471. package/lib/data-structures/index.js +11 -0
  472. package/{dist → lib}/data-structures/linked-list/doubly-linked-list.d.ts +5 -5
  473. package/lib/data-structures/linked-list/doubly-linked-list.js +521 -0
  474. package/lib/data-structures/linked-list/index.js +3 -0
  475. package/{dist → lib}/data-structures/linked-list/singly-linked-list.d.ts +6 -5
  476. package/lib/data-structures/linked-list/singly-linked-list.js +443 -0
  477. package/lib/data-structures/linked-list/skip-linked-list.js +2 -0
  478. package/lib/data-structures/matrix/index.js +4 -0
  479. package/lib/data-structures/matrix/matrix.js +24 -0
  480. package/lib/data-structures/matrix/matrix2d.js +195 -0
  481. package/lib/data-structures/matrix/navigator.js +101 -0
  482. package/lib/data-structures/matrix/vector2d.js +287 -0
  483. package/lib/data-structures/priority-queue/index.js +3 -0
  484. package/lib/data-structures/priority-queue/max-priority-queue.js +39 -0
  485. package/lib/data-structures/priority-queue/min-priority-queue.js +40 -0
  486. package/lib/data-structures/priority-queue/priority-queue.js +317 -0
  487. package/{dist → lib}/data-structures/queue/deque.d.ts +45 -0
  488. package/lib/data-structures/queue/deque.js +270 -0
  489. package/lib/data-structures/queue/index.js +2 -0
  490. package/{dist → lib}/data-structures/queue/queue.d.ts +47 -13
  491. package/lib/data-structures/queue/queue.js +165 -0
  492. package/lib/data-structures/stack/index.js +1 -0
  493. package/lib/data-structures/stack/stack.js +87 -0
  494. package/lib/data-structures/tree/index.js +1 -0
  495. package/lib/data-structures/tree/tree.js +56 -0
  496. package/lib/data-structures/trie/index.js +1 -0
  497. package/lib/data-structures/trie/trie.js +205 -0
  498. package/lib/index.js +4 -0
  499. package/{dist → lib}/interfaces/avl-tree.d.ts +1 -9
  500. package/lib/interfaces/binary-tree.d.ts +4 -0
  501. package/{dist → lib}/interfaces/bst.d.ts +1 -2
  502. package/lib/interfaces/heap.js +1 -0
  503. package/lib/interfaces/index.js +15 -0
  504. package/lib/interfaces/navigator.d.ts +1 -0
  505. package/lib/interfaces/navigator.js +1 -0
  506. package/lib/interfaces/priority-queue.d.ts +1 -0
  507. package/lib/interfaces/priority-queue.js +1 -0
  508. package/{dist → lib}/interfaces/rb-tree.d.ts +1 -2
  509. package/lib/interfaces/rb-tree.js +1 -0
  510. package/lib/interfaces/segment-tree.d.ts +1 -0
  511. package/lib/interfaces/segment-tree.js +1 -0
  512. package/lib/interfaces/singly-linked-list.d.ts +1 -0
  513. package/lib/interfaces/singly-linked-list.js +1 -0
  514. package/lib/interfaces/tree-multiset.d.ts +5 -0
  515. package/lib/interfaces/tree-multiset.js +1 -0
  516. package/lib/interfaces/undirected-graph.js +1 -0
  517. package/{dist → lib}/types/data-structures/abstract-binary-tree.d.ts +1 -1
  518. package/lib/types/data-structures/abstract-binary-tree.js +22 -0
  519. package/lib/types/data-structures/abstract-graph.js +1 -0
  520. package/{dist → lib}/types/data-structures/avl-tree.d.ts +1 -1
  521. package/lib/types/data-structures/avl-tree.js +1 -0
  522. package/lib/types/data-structures/binary-tree.js +1 -0
  523. package/lib/types/data-structures/bst.js +6 -0
  524. package/lib/types/data-structures/directed-graph.js +6 -0
  525. package/lib/types/data-structures/doubly-linked-list.d.ts +1 -0
  526. package/lib/types/data-structures/doubly-linked-list.js +1 -0
  527. package/lib/types/data-structures/heap.js +1 -0
  528. package/lib/types/data-structures/index.js +15 -0
  529. package/lib/types/data-structures/map-graph.js +1 -0
  530. package/lib/types/data-structures/navigator.js +1 -0
  531. package/lib/types/data-structures/priority-queue.js +1 -0
  532. package/lib/types/data-structures/rb-tree.js +5 -0
  533. package/lib/types/data-structures/segment-tree.js +1 -0
  534. package/lib/types/data-structures/singly-linked-list.d.ts +1 -0
  535. package/lib/types/data-structures/singly-linked-list.js +1 -0
  536. package/lib/types/data-structures/tree-multiset.js +1 -0
  537. package/lib/types/helpers.d.ts +1 -0
  538. package/lib/types/helpers.js +1 -0
  539. package/lib/types/index.js +3 -0
  540. package/lib/types/utils/index.js +2 -0
  541. package/{dist → lib}/types/utils/utils.d.ts +1 -1
  542. package/lib/types/utils/utils.js +1 -0
  543. package/{dist → lib}/types/utils/validate-type.d.ts +1 -1
  544. package/lib/types/utils/validate-type.js +1 -0
  545. package/lib/utils/index.js +1 -0
  546. package/lib/utils/utils.js +57 -0
  547. package/package.json +150 -56
  548. package/rename_clear_files.sh +29 -0
  549. package/test/integration/avl-tree.test.ts +111 -0
  550. package/test/integration/bst.test.ts +371 -0
  551. package/test/integration/heap.test.js +19 -0
  552. package/test/integration/index.html +44 -0
  553. package/test/unit/data-structures/binary-tree/avl-tree.test.ts +111 -0
  554. package/test/unit/data-structures/binary-tree/bst.test.ts +371 -0
  555. package/test/unit/data-structures/binary-tree/overall.test.ts +57 -0
  556. package/test/unit/data-structures/binary-tree/tree-multiset.test.ts +405 -0
  557. package/test/unit/data-structures/graph/abstract-graph.test.ts +5 -0
  558. package/test/unit/data-structures/graph/directed-graph.test.ts +517 -0
  559. package/test/unit/data-structures/graph/index.ts +2 -0
  560. package/test/unit/data-structures/graph/map-graph.test.ts +46 -0
  561. package/test/unit/data-structures/graph/overall.test.ts +50 -0
  562. package/test/unit/data-structures/graph/undirected-graph.test.ts +60 -0
  563. package/test/unit/data-structures/heap/heap.test.ts +56 -0
  564. package/test/unit/data-structures/heap/max-heap.test.ts +42 -0
  565. package/test/unit/data-structures/heap/min-heap.test.ts +81 -0
  566. package/test/unit/data-structures/linked-list/doubly-linked-list.test.ts +365 -0
  567. package/test/unit/data-structures/linked-list/index.ts +4 -0
  568. package/test/unit/data-structures/linked-list/linked-list.test.ts +37 -0
  569. package/test/unit/data-structures/linked-list/singly-linked-list.test.ts +401 -0
  570. package/test/unit/data-structures/linked-list/skip-linked-list.test.ts +13 -0
  571. package/test/unit/data-structures/priority-queue/max-priority-queue.test.ts +108 -0
  572. package/test/unit/data-structures/priority-queue/min-priority-queue.test.ts +105 -0
  573. package/test/unit/data-structures/priority-queue/priority-queue.test.ts +27 -0
  574. package/test/unit/data-structures/queue/queue.test.ts +36 -0
  575. package/test/utils/index.ts +2 -0
  576. package/test/utils/magnitude.ts +21 -0
  577. package/test/utils/number.ts +3 -0
  578. package/tsconfig.build.json +33 -0
  579. package/tsconfig.json +38 -0
  580. package/umd/bundle.min.js +3 -0
  581. package/umd/bundle.min.js.map +1 -0
  582. package/webpack.config.js +28 -0
  583. package/dist/bundle.js +0 -2
  584. package/dist/interfaces/binary-tree.d.ts +0 -6
  585. package/dist/interfaces/tree-multiset.d.ts +0 -7
  586. /package/{dist → lib}/data-structures/binary-tree/aa-tree.d.ts +0 -0
  587. /package/{dist → lib}/data-structures/binary-tree/b-tree.d.ts +0 -0
  588. /package/{dist → lib}/data-structures/binary-tree/binary-indexed-tree.d.ts +0 -0
  589. /package/{dist → lib}/data-structures/binary-tree/binary-tree.d.ts +0 -0
  590. /package/{dist → lib}/data-structures/binary-tree/index.d.ts +0 -0
  591. /package/{dist → lib}/data-structures/binary-tree/segment-tree.d.ts +0 -0
  592. /package/{dist → lib}/data-structures/binary-tree/splay-tree.d.ts +0 -0
  593. /package/{dist → lib}/data-structures/binary-tree/two-three-tree.d.ts +0 -0
  594. /package/{dist → lib}/data-structures/graph/abstract-graph.d.ts +0 -0
  595. /package/{dist → lib}/data-structures/graph/directed-graph.d.ts +0 -0
  596. /package/{dist → lib}/data-structures/graph/index.d.ts +0 -0
  597. /package/{dist → lib}/data-structures/graph/map-graph.d.ts +0 -0
  598. /package/{dist → lib}/data-structures/graph/undirected-graph.d.ts +0 -0
  599. /package/{dist → lib}/data-structures/hash/coordinate-map.d.ts +0 -0
  600. /package/{dist → lib}/data-structures/hash/coordinate-set.d.ts +0 -0
  601. /package/{dist → lib}/data-structures/hash/hash-table.d.ts +0 -0
  602. /package/{dist → lib}/data-structures/hash/index.d.ts +0 -0
  603. /package/{dist → lib}/data-structures/hash/pair.d.ts +0 -0
  604. /package/{dist → lib}/data-structures/hash/tree-map.d.ts +0 -0
  605. /package/{dist → lib}/data-structures/hash/tree-set.d.ts +0 -0
  606. /package/{dist → lib}/data-structures/heap/heap.d.ts +0 -0
  607. /package/{dist → lib}/data-structures/heap/index.d.ts +0 -0
  608. /package/{dist → lib}/data-structures/heap/max-heap.d.ts +0 -0
  609. /package/{dist → lib}/data-structures/heap/min-heap.d.ts +0 -0
  610. /package/{dist → lib}/data-structures/index.d.ts +0 -0
  611. /package/{dist → lib}/data-structures/linked-list/index.d.ts +0 -0
  612. /package/{dist → lib}/data-structures/linked-list/skip-linked-list.d.ts +0 -0
  613. /package/{dist → lib}/data-structures/matrix/index.d.ts +0 -0
  614. /package/{dist → lib}/data-structures/matrix/matrix.d.ts +0 -0
  615. /package/{dist → lib}/data-structures/matrix/matrix2d.d.ts +0 -0
  616. /package/{dist → lib}/data-structures/matrix/navigator.d.ts +0 -0
  617. /package/{dist → lib}/data-structures/matrix/vector2d.d.ts +0 -0
  618. /package/{dist → lib}/data-structures/priority-queue/index.d.ts +0 -0
  619. /package/{dist → lib}/data-structures/priority-queue/max-priority-queue.d.ts +0 -0
  620. /package/{dist → lib}/data-structures/priority-queue/min-priority-queue.d.ts +0 -0
  621. /package/{dist → lib}/data-structures/priority-queue/priority-queue.d.ts +0 -0
  622. /package/{dist → lib}/data-structures/queue/index.d.ts +0 -0
  623. /package/{dist → lib}/data-structures/stack/index.d.ts +0 -0
  624. /package/{dist → lib}/data-structures/stack/stack.d.ts +0 -0
  625. /package/{dist → lib}/data-structures/tree/index.d.ts +0 -0
  626. /package/{dist → lib}/data-structures/tree/tree.d.ts +0 -0
  627. /package/{dist → lib}/data-structures/trie/index.d.ts +0 -0
  628. /package/{dist → lib}/data-structures/trie/trie.d.ts +0 -0
  629. /package/{dist → lib}/index.d.ts +0 -0
  630. /package/{dist → lib}/interfaces/abstract-binary-tree.d.ts +0 -0
  631. /package/{dist/interfaces/doubly-linked-list.d.ts → lib/interfaces/abstract-binary-tree.js} +0 -0
  632. /package/{dist → lib}/interfaces/abstract-graph.d.ts +0 -0
  633. /package/{dist/interfaces/heap.d.ts → lib/interfaces/abstract-graph.js} +0 -0
  634. /package/{dist/interfaces/navigator.d.ts → lib/interfaces/avl-tree.js} +0 -0
  635. /package/{dist/interfaces/priority-queue.d.ts → lib/interfaces/binary-tree.js} +0 -0
  636. /package/{dist/interfaces/segment-tree.d.ts → lib/interfaces/bst.js} +0 -0
  637. /package/{dist → lib}/interfaces/directed-graph.d.ts +0 -0
  638. /package/{dist/interfaces/singly-linked-list.d.ts → lib/interfaces/directed-graph.js} +0 -0
  639. /package/{dist/types/data-structures → lib/interfaces}/doubly-linked-list.d.ts +0 -0
  640. /package/{dist/types/data-structures/singly-linked-list.d.ts → lib/interfaces/doubly-linked-list.js} +0 -0
  641. /package/{dist/types/helpers.d.ts → lib/interfaces/heap.d.ts} +0 -0
  642. /package/{dist → lib}/interfaces/index.d.ts +0 -0
  643. /package/{dist → lib}/interfaces/undirected-graph.d.ts +0 -0
  644. /package/{dist → lib}/types/data-structures/abstract-graph.d.ts +0 -0
  645. /package/{dist → lib}/types/data-structures/binary-tree.d.ts +0 -0
  646. /package/{dist → lib}/types/data-structures/bst.d.ts +0 -0
  647. /package/{dist → lib}/types/data-structures/directed-graph.d.ts +0 -0
  648. /package/{dist → lib}/types/data-structures/heap.d.ts +0 -0
  649. /package/{dist → lib}/types/data-structures/index.d.ts +0 -0
  650. /package/{dist → lib}/types/data-structures/map-graph.d.ts +0 -0
  651. /package/{dist → lib}/types/data-structures/navigator.d.ts +0 -0
  652. /package/{dist → lib}/types/data-structures/priority-queue.d.ts +0 -0
  653. /package/{dist → lib}/types/data-structures/rb-tree.d.ts +0 -0
  654. /package/{dist → lib}/types/data-structures/segment-tree.d.ts +0 -0
  655. /package/{dist → lib}/types/data-structures/tree-multiset.d.ts +0 -0
  656. /package/{dist → lib}/types/index.d.ts +0 -0
  657. /package/{dist → lib}/types/utils/index.d.ts +0 -0
  658. /package/{dist → lib}/utils/index.d.ts +0 -0
  659. /package/{dist → lib}/utils/utils.d.ts +0 -0
  660. /package/{dist/bundle.js.LICENSE.txt → umd/bundle.min.js.LICENSE.txt} +0 -0
@@ -1,115 +1,137 @@
1
1
  "use strict";
2
- /**
3
- * data-structure-typed
4
- *
5
- * @author Tyler Zeng
6
- * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
7
- * @license MIT License
8
- */
2
+ var __read = (this && this.__read) || function (o, n) {
3
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
4
+ if (!m) return o;
5
+ var i = m.call(o), r, ar = [], e;
6
+ try {
7
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
8
+ }
9
+ catch (error) { e = { error: error }; }
10
+ finally {
11
+ try {
12
+ if (r && !r.done && (m = i["return"])) m.call(i);
13
+ }
14
+ finally { if (e) throw e.error; }
15
+ }
16
+ return ar;
17
+ };
9
18
  Object.defineProperty(exports, "__esModule", { value: true });
10
19
  exports.AbstractBinaryTree = exports.AbstractBinaryTreeNode = void 0;
11
- const utils_1 = require("../../utils");
12
- const types_1 = require("../../types");
13
- class AbstractBinaryTreeNode {
14
- /**
15
- * The constructor function initializes a BinaryTreeNode object with an id and an optional value.
16
- * @param {BinaryTreeNodeId} id - The `id` parameter is of type `BinaryTreeNodeId` and represents the unique identifier
17
- * of the binary tree node. It is used to distinguish one node from another in the binary tree.
18
- * @param {T} [val] - The "val" parameter is an optional parameter of type T. It represents the value that will be
19
- * stored in the binary tree node. If no value is provided, it will be set to undefined.
20
- */
21
- constructor(id, val) {
20
+ var utils_1 = require("../../utils");
21
+ var types_1 = require("../../types");
22
+ var AbstractBinaryTreeNode = (function () {
23
+ function AbstractBinaryTreeNode(id, val) {
22
24
  this._height = 0;
23
25
  this._id = id;
24
26
  this._val = val;
25
27
  }
26
- get id() {
27
- return this._id;
28
- }
29
- set id(v) {
30
- this._id = v;
31
- }
32
- get val() {
33
- return this._val;
34
- }
35
- set val(value) {
36
- this._val = value;
37
- }
38
- get left() {
39
- return this._left;
40
- }
41
- set left(v) {
42
- if (v) {
43
- v.parent = this;
44
- }
45
- this._left = v;
46
- }
47
- get right() {
48
- return this._right;
49
- }
50
- set right(v) {
51
- if (v) {
52
- v.parent = this;
53
- }
54
- this._right = v;
55
- }
56
- get parent() {
57
- return this._parent;
58
- }
59
- set parent(v) {
60
- this._parent = v;
61
- }
62
- get height() {
63
- return this._height;
64
- }
65
- set height(v) {
66
- this._height = v;
67
- }
68
- /**
69
- * The function determines the position of a node in a family tree structure.
70
- * @returns a value of type `FamilyPosition`.
71
- */
72
- get familyPosition() {
73
- const that = this;
74
- if (that.parent) {
75
- if (that.parent.left === that) {
76
- if (that.left || that.right) {
77
- return types_1.FamilyPosition.ROOT_LEFT;
28
+ Object.defineProperty(AbstractBinaryTreeNode.prototype, "id", {
29
+ get: function () {
30
+ return this._id;
31
+ },
32
+ set: function (v) {
33
+ this._id = v;
34
+ },
35
+ enumerable: false,
36
+ configurable: true
37
+ });
38
+ Object.defineProperty(AbstractBinaryTreeNode.prototype, "val", {
39
+ get: function () {
40
+ return this._val;
41
+ },
42
+ set: function (value) {
43
+ this._val = value;
44
+ },
45
+ enumerable: false,
46
+ configurable: true
47
+ });
48
+ Object.defineProperty(AbstractBinaryTreeNode.prototype, "left", {
49
+ get: function () {
50
+ return this._left;
51
+ },
52
+ set: function (v) {
53
+ if (v) {
54
+ v.parent = this;
55
+ }
56
+ this._left = v;
57
+ },
58
+ enumerable: false,
59
+ configurable: true
60
+ });
61
+ Object.defineProperty(AbstractBinaryTreeNode.prototype, "right", {
62
+ get: function () {
63
+ return this._right;
64
+ },
65
+ set: function (v) {
66
+ if (v) {
67
+ v.parent = this;
68
+ }
69
+ this._right = v;
70
+ },
71
+ enumerable: false,
72
+ configurable: true
73
+ });
74
+ Object.defineProperty(AbstractBinaryTreeNode.prototype, "parent", {
75
+ get: function () {
76
+ return this._parent;
77
+ },
78
+ set: function (v) {
79
+ this._parent = v;
80
+ },
81
+ enumerable: false,
82
+ configurable: true
83
+ });
84
+ Object.defineProperty(AbstractBinaryTreeNode.prototype, "height", {
85
+ get: function () {
86
+ return this._height;
87
+ },
88
+ set: function (v) {
89
+ this._height = v;
90
+ },
91
+ enumerable: false,
92
+ configurable: true
93
+ });
94
+ Object.defineProperty(AbstractBinaryTreeNode.prototype, "familyPosition", {
95
+ get: function () {
96
+ var that = this;
97
+ if (that.parent) {
98
+ if (that.parent.left === that) {
99
+ if (that.left || that.right) {
100
+ return types_1.FamilyPosition.ROOT_LEFT;
101
+ }
102
+ else {
103
+ return types_1.FamilyPosition.LEFT;
104
+ }
105
+ }
106
+ else if (that.parent.right === that) {
107
+ if (that.left || that.right) {
108
+ return types_1.FamilyPosition.ROOT_RIGHT;
109
+ }
110
+ else {
111
+ return types_1.FamilyPosition.RIGHT;
112
+ }
78
113
  }
79
114
  else {
80
- return types_1.FamilyPosition.LEFT;
115
+ return types_1.FamilyPosition.MAL_NODE;
81
116
  }
82
117
  }
83
- else if (that.parent.right === that) {
118
+ else {
84
119
  if (that.left || that.right) {
85
- return types_1.FamilyPosition.ROOT_RIGHT;
120
+ return types_1.FamilyPosition.ROOT;
86
121
  }
87
122
  else {
88
- return types_1.FamilyPosition.RIGHT;
123
+ return types_1.FamilyPosition.ISOLATED;
89
124
  }
90
125
  }
91
- else {
92
- return types_1.FamilyPosition.MAL_NODE;
93
- }
94
- }
95
- else {
96
- if (that.left || that.right) {
97
- return types_1.FamilyPosition.ROOT;
98
- }
99
- else {
100
- return types_1.FamilyPosition.ISOLATED;
101
- }
102
- }
103
- }
104
- }
126
+ },
127
+ enumerable: false,
128
+ configurable: true
129
+ });
130
+ return AbstractBinaryTreeNode;
131
+ }());
105
132
  exports.AbstractBinaryTreeNode = AbstractBinaryTreeNode;
106
- class AbstractBinaryTree {
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
- constructor(options) {
133
+ var AbstractBinaryTree = (function () {
134
+ function AbstractBinaryTree(options) {
113
135
  this._root = null;
114
136
  this._size = 0;
115
137
  this._loopType = types_1.LoopType.ITERATIVE;
@@ -118,42 +140,63 @@ class AbstractBinaryTree {
118
140
  this._visitedNode = [];
119
141
  this._visitedLeftSum = [];
120
142
  if (options !== undefined) {
121
- const { loopType = types_1.LoopType.ITERATIVE } = options;
143
+ var _a = options.loopType, loopType = _a === void 0 ? types_1.LoopType.ITERATIVE : _a;
122
144
  this._loopType = loopType;
123
145
  }
124
146
  this.clear();
125
147
  }
126
- get root() {
127
- return this._root;
128
- }
129
- get size() {
130
- return this._size;
131
- }
132
- get loopType() {
133
- return this._loopType;
134
- }
135
- get visitedId() {
136
- return this._visitedId;
137
- }
138
- get visitedVal() {
139
- return this._visitedVal;
140
- }
141
- get visitedNode() {
142
- return this._visitedNode;
143
- }
144
- get visitedLeftSum() {
145
- return this._visitedLeftSum;
146
- }
147
- /**
148
- * The `swapLocation` function swaps the location of two nodes in a binary tree.
149
- * @param {N} srcNode - The source node that you want to swap with the destination node.
150
- * @param {N} destNode - The `destNode` parameter represents the destination node where the values from `srcNode` will
151
- * be swapped to.
152
- * @returns The `destNode` is being returned.
153
- */
154
- swapLocation(srcNode, destNode) {
155
- const { id, val, height } = destNode;
156
- const tempNode = this.createNode(id, val);
148
+ Object.defineProperty(AbstractBinaryTree.prototype, "root", {
149
+ get: function () {
150
+ return this._root;
151
+ },
152
+ enumerable: false,
153
+ configurable: true
154
+ });
155
+ Object.defineProperty(AbstractBinaryTree.prototype, "size", {
156
+ get: function () {
157
+ return this._size;
158
+ },
159
+ enumerable: false,
160
+ configurable: true
161
+ });
162
+ Object.defineProperty(AbstractBinaryTree.prototype, "loopType", {
163
+ get: function () {
164
+ return this._loopType;
165
+ },
166
+ enumerable: false,
167
+ configurable: true
168
+ });
169
+ Object.defineProperty(AbstractBinaryTree.prototype, "visitedId", {
170
+ get: function () {
171
+ return this._visitedId;
172
+ },
173
+ enumerable: false,
174
+ configurable: true
175
+ });
176
+ Object.defineProperty(AbstractBinaryTree.prototype, "visitedVal", {
177
+ get: function () {
178
+ return this._visitedVal;
179
+ },
180
+ enumerable: false,
181
+ configurable: true
182
+ });
183
+ Object.defineProperty(AbstractBinaryTree.prototype, "visitedNode", {
184
+ get: function () {
185
+ return this._visitedNode;
186
+ },
187
+ enumerable: false,
188
+ configurable: true
189
+ });
190
+ Object.defineProperty(AbstractBinaryTree.prototype, "visitedLeftSum", {
191
+ get: function () {
192
+ return this._visitedLeftSum;
193
+ },
194
+ enumerable: false,
195
+ configurable: true
196
+ });
197
+ AbstractBinaryTree.prototype.swapLocation = function (srcNode, destNode) {
198
+ var id = destNode.id, val = destNode.val, height = destNode.height;
199
+ var tempNode = this.createNode(id, val);
157
200
  if (tempNode) {
158
201
  tempNode.height = height;
159
202
  destNode.id = srcNode.id;
@@ -164,46 +207,27 @@ class AbstractBinaryTree {
164
207
  srcNode.height = tempNode.height;
165
208
  }
166
209
  return destNode;
167
- }
168
- /**
169
- * The clear() function resets the root, size, and maxId properties to their initial values.
170
- */
171
- clear() {
210
+ };
211
+ AbstractBinaryTree.prototype.clear = function () {
172
212
  this._root = null;
173
213
  this._size = 0;
174
214
  this._clearResults();
175
- }
176
- /**
177
- * The function checks if the size of an object is equal to zero and returns a boolean value.
178
- * @returns A boolean value indicating whether the size of the object is 0 or not.
179
- */
180
- isEmpty() {
215
+ };
216
+ AbstractBinaryTree.prototype.isEmpty = function () {
181
217
  return this.size === 0;
182
- }
183
- /**
184
- * When all leaf nodes are null, it will no longer be possible to add new entity nodes to this binary tree.
185
- * In this scenario, null nodes serve as "sentinel nodes," "virtual nodes," or "placeholder nodes."
186
- */
187
- /**
188
- * The `add` function adds a new node to a binary tree, either by ID or by creating a new node with a given value.
189
- * @param {BinaryTreeNodeId | N | null} idOrNode - The `idOrNode` parameter can be either a `BinaryTreeNodeId`, which
190
- * is a number representing the ID of a binary tree node, or it can be a `N` object, which represents a binary tree
191
- * node itself. It can also be `null` if no node is specified.
192
- * @param [val] - The `val` parameter is an optional value that can be assigned to the `val` property of the new node
193
- * being added to the binary tree.
194
- * @returns The function `add` returns either the inserted node (`N`), `null`, or `undefined`.
195
- */
196
- add(idOrNode, val) {
197
- const _bfs = (root, newNode) => {
198
- const queue = [root];
218
+ };
219
+ AbstractBinaryTree.prototype.add = function (idOrNode, val) {
220
+ var _this = this;
221
+ var _bfs = function (root, newNode) {
222
+ var queue = [root];
199
223
  while (queue.length > 0) {
200
- const cur = queue.shift();
224
+ var cur = queue.shift();
201
225
  if (cur) {
202
226
  if (newNode && cur.id === newNode.id)
203
227
  return;
204
- const inserted = this._addTo(newNode, cur);
205
- if (inserted !== undefined)
206
- return inserted;
228
+ var inserted_1 = _this._addTo(newNode, cur);
229
+ if (inserted_1 !== undefined)
230
+ return inserted_1;
207
231
  if (cur.left)
208
232
  queue.push(cur.left);
209
233
  if (cur.right)
@@ -214,7 +238,7 @@ class AbstractBinaryTree {
214
238
  }
215
239
  return;
216
240
  };
217
- let inserted, needInsert;
241
+ var inserted, needInsert;
218
242
  if (idOrNode === null) {
219
243
  needInsert = null;
220
244
  }
@@ -227,7 +251,7 @@ class AbstractBinaryTree {
227
251
  else {
228
252
  return;
229
253
  }
230
- const existNode = idOrNode ? this.get(idOrNode, 'id') : undefined;
254
+ var existNode = idOrNode ? this.get(idOrNode, 'id') : undefined;
231
255
  if (this.root) {
232
256
  if (existNode) {
233
257
  existNode.val = val;
@@ -248,80 +272,47 @@ class AbstractBinaryTree {
248
272
  inserted = this.root;
249
273
  }
250
274
  return inserted;
251
- }
252
- /**
253
- * The `addMany` function adds multiple nodes to a tree data structure and returns an array of the inserted nodes or
254
- * null/undefined values.
255
- * @param {(BinaryTreeNodeId|N)[]} idsOrNodes - An array of BinaryTreeNodeId or N objects. These can be either the ID
256
- * of a binary tree node or the actual node object itself.
257
- * @param {N['val'][]} [data] - Optional array of values to be added to the nodes. If provided, the length of this
258
- * array should be the same as the length of the `idsOrNodes` array.
259
- * @returns The function `addMany` returns an array of values `(N | null | undefined)[]`.
260
- */
261
- addMany(idsOrNodes, data) {
262
- var _a;
263
- // TODO not sure addMany not be run multi times
264
- const inserted = [];
265
- const map = new Map();
266
- for (const idOrNode of idsOrNodes)
267
- map.set(idOrNode, ((_a = map.get(idOrNode)) !== null && _a !== void 0 ? _a : 0) + 1);
268
- for (let i = 0; i < idsOrNodes.length; i++) {
269
- const idOrNode = idsOrNodes[i];
270
- if (map.has(idOrNode)) {
271
- if (idOrNode instanceof AbstractBinaryTreeNode) {
272
- inserted.push(this.add(idOrNode.id, idOrNode.val));
273
- continue;
274
- }
275
- if (idOrNode === null) {
276
- inserted.push(this.add(null));
277
- continue;
278
- }
279
- const val = data === null || data === void 0 ? void 0 : data[i];
280
- inserted.push(this.add(idOrNode, val));
281
- map.delete(idOrNode);
275
+ };
276
+ AbstractBinaryTree.prototype.addMany = function (idsOrNodes, data) {
277
+ var inserted = [];
278
+ for (var i = 0; i < idsOrNodes.length; i++) {
279
+ var idOrNode = idsOrNodes[i];
280
+ if (idOrNode instanceof AbstractBinaryTreeNode) {
281
+ inserted.push(this.add(idOrNode.id, idOrNode.val));
282
+ continue;
282
283
  }
284
+ if (idOrNode === null) {
285
+ inserted.push(this.add(null));
286
+ continue;
287
+ }
288
+ var val = data === null || data === void 0 ? void 0 : data[i];
289
+ inserted.push(this.add(idOrNode, val));
283
290
  }
284
291
  return inserted;
285
- }
286
- /**
287
- * The `fill` function clears the binary tree and adds multiple nodes with the given IDs or nodes and optional data.
288
- * @param {(BinaryTreeNodeId | N)[]} idsOrNodes - The `idsOrNodes` parameter is an array that can contain either
289
- * `BinaryTreeNodeId` or `N` values.
290
- * @param {N[] | Array<N['val']>} [data] - The `data` parameter is an optional array of values that will be assigned to
291
- * the nodes being added. If provided, the length of the `data` array should be equal to the length of the `idsOrNodes`
292
- * array. Each value in the `data` array will be assigned to the
293
- * @returns The method is returning a boolean value.
294
- */
295
- fill(idsOrNodes, data) {
292
+ };
293
+ AbstractBinaryTree.prototype.fill = function (idsOrNodes, data) {
296
294
  this.clear();
297
295
  return idsOrNodes.length === this.addMany(idsOrNodes, data).length;
298
- }
299
- /**
300
- * The `remove` function removes a node from a binary search tree and returns the deleted node along with the parent
301
- * node that needs to be balanced.
302
- * @param {N | BinaryTreeNodeId} nodeOrId - The `nodeOrId` parameter can be either a node object (`N`) or a binary tree
303
- * node ID (`BinaryTreeNodeId`).
304
- * @param {boolean} [ignoreCount] - The `ignoreCount` parameter is an optional boolean parameter that determines
305
- * whether to ignore the count of the nodes in the binary tree. If `ignoreCount` is set to `true`, the count of the
306
- * nodes in the binary tree will not be updated after removing a node. If `ignoreCount`
307
- * @returns The function `remove` returns an array of `BinaryTreeDeletedResult<N>` objects.
308
- */
309
- remove(nodeOrId, ignoreCount) {
310
- const bstDeletedResult = [];
296
+ };
297
+ AbstractBinaryTree.prototype.remove = function (nodeOrId, isUpdateAllLeftSum) {
298
+ isUpdateAllLeftSum = isUpdateAllLeftSum === undefined ? true : isUpdateAllLeftSum;
299
+ if (isUpdateAllLeftSum) {
300
+ }
301
+ var bstDeletedResult = [];
311
302
  if (!this.root)
312
303
  return bstDeletedResult;
313
- const curr = (typeof nodeOrId === 'number') ? this.get(nodeOrId) : nodeOrId;
304
+ var curr = typeof nodeOrId === 'number' ? this.get(nodeOrId) : nodeOrId;
314
305
  if (!curr)
315
306
  return bstDeletedResult;
316
- const parent = (curr === null || curr === void 0 ? void 0 : curr.parent) ? curr.parent : null;
317
- let needBalanced = null, orgCurrent = curr;
307
+ var parent = (curr === null || curr === void 0 ? void 0 : curr.parent) ? curr.parent : null;
308
+ var needBalanced = null, orgCurrent = curr;
318
309
  if (!curr.left) {
319
310
  if (!parent) {
320
311
  if (curr.right !== undefined)
321
312
  this._setRoot(curr.right);
322
313
  }
323
314
  else {
324
- const { familyPosition: fp } = curr;
315
+ var fp = curr.familyPosition;
325
316
  if (fp === types_1.FamilyPosition.LEFT || fp === types_1.FamilyPosition.ROOT_LEFT) {
326
317
  parent.left = curr.right;
327
318
  }
@@ -332,9 +323,9 @@ class AbstractBinaryTree {
332
323
  }
333
324
  }
334
325
  else {
335
- const leftSubTreeRightMost = curr.left ? this.getRightMost(curr.left) : null;
326
+ var leftSubTreeRightMost = curr.left ? this.getRightMost(curr.left) : null;
336
327
  if (leftSubTreeRightMost) {
337
- const parentOfLeftSubTreeMax = leftSubTreeRightMost.parent;
328
+ var parentOfLeftSubTreeMax = leftSubTreeRightMost.parent;
338
329
  orgCurrent = this.swapLocation(curr, leftSubTreeRightMost);
339
330
  if (parentOfLeftSubTreeMax) {
340
331
  if (parentOfLeftSubTreeMax.right === leftSubTreeRightMost)
@@ -346,55 +337,43 @@ class AbstractBinaryTree {
346
337
  }
347
338
  }
348
339
  this._setSize(this.size - 1);
349
- bstDeletedResult.push({ deleted: orgCurrent, needBalanced });
340
+ bstDeletedResult.push({ deleted: orgCurrent, needBalanced: needBalanced });
350
341
  return bstDeletedResult;
351
- }
352
- /**
353
- * The function calculates the depth of a node in a binary tree.
354
- * @param {N | BinaryTreeNodeId | null} beginRoot - The `beginRoot` parameter can be one of the following:
355
- * @returns the depth of the given node or binary tree.
356
- */
357
- getDepth(beginRoot) {
342
+ };
343
+ AbstractBinaryTree.prototype.getDepth = function (beginRoot) {
358
344
  if (typeof beginRoot === 'number')
359
345
  beginRoot = this.get(beginRoot, 'id');
360
- let depth = 0;
346
+ var depth = 0;
361
347
  while (beginRoot === null || beginRoot === void 0 ? void 0 : beginRoot.parent) {
362
348
  depth++;
363
349
  beginRoot = beginRoot.parent;
364
350
  }
365
351
  return depth;
366
- }
367
- /**
368
- * The `getHeight` function calculates the maximum height of a binary tree, either recursively or iteratively.
369
- * @param {N | BinaryTreeNodeId | null} [beginRoot] - The `beginRoot` parameter is optional and can be of type `N` (a
370
- * generic type representing a node in a binary tree), `BinaryTreeNodeId` (a type representing the ID of a binary tree
371
- * node), or `null`.
372
- * @returns the height of the binary tree.
373
- */
374
- getHeight(beginRoot) {
352
+ };
353
+ AbstractBinaryTree.prototype.getHeight = function (beginRoot) {
375
354
  beginRoot = beginRoot !== null && beginRoot !== void 0 ? beginRoot : this.root;
376
355
  if (typeof beginRoot === 'number')
377
356
  beginRoot = this.get(beginRoot, 'id');
378
357
  if (!beginRoot)
379
358
  return -1;
380
359
  if (this._loopType === types_1.LoopType.RECURSIVE) {
381
- const _getMaxHeight = (cur) => {
360
+ var _getMaxHeight_1 = function (cur) {
382
361
  if (!cur)
383
362
  return -1;
384
- const leftHeight = _getMaxHeight(cur.left);
385
- const rightHeight = _getMaxHeight(cur.right);
363
+ var leftHeight = _getMaxHeight_1(cur.left);
364
+ var rightHeight = _getMaxHeight_1(cur.right);
386
365
  return Math.max(leftHeight, rightHeight) + 1;
387
366
  };
388
- return _getMaxHeight(beginRoot);
367
+ return _getMaxHeight_1(beginRoot);
389
368
  }
390
369
  else {
391
370
  if (!beginRoot) {
392
371
  return -1;
393
372
  }
394
- const stack = [{ node: beginRoot, depth: 0 }];
395
- let maxHeight = 0;
373
+ var stack = [{ node: beginRoot, depth: 0 }];
374
+ var maxHeight = 0;
396
375
  while (stack.length > 0) {
397
- const { node, depth } = stack.pop();
376
+ var _a = stack.pop(), node = _a.node, depth = _a.depth;
398
377
  if (node.left) {
399
378
  stack.push({ node: node.left, depth: depth + 1 });
400
379
  }
@@ -405,36 +384,28 @@ class AbstractBinaryTree {
405
384
  }
406
385
  return maxHeight;
407
386
  }
408
- }
409
- /**
410
- * The `getMinHeight` function calculates the minimum height of a binary tree using either a recursive or iterative
411
- * approach.
412
- * @param {N | null} [beginRoot] - The `beginRoot` parameter is an optional parameter of type `N` or `null`. It
413
- * represents the starting node from which to calculate the minimum height of a binary tree. If no value is provided
414
- * for `beginRoot`, the `this.root` property is used as the default value.
415
- * @returns The function `getMinHeight` returns the minimum height of the binary tree.
416
- */
417
- getMinHeight(beginRoot) {
387
+ };
388
+ AbstractBinaryTree.prototype.getMinHeight = function (beginRoot) {
418
389
  var _a, _b, _c;
419
390
  beginRoot = beginRoot || this.root;
420
391
  if (!beginRoot)
421
392
  return -1;
422
393
  if (this._loopType === types_1.LoopType.RECURSIVE) {
423
- const _getMinHeight = (cur) => {
394
+ var _getMinHeight_1 = function (cur) {
424
395
  if (!cur)
425
396
  return 0;
426
397
  if (!cur.left && !cur.right)
427
398
  return 0;
428
- const leftMinHeight = _getMinHeight(cur.left);
429
- const rightMinHeight = _getMinHeight(cur.right);
399
+ var leftMinHeight = _getMinHeight_1(cur.left);
400
+ var rightMinHeight = _getMinHeight_1(cur.right);
430
401
  return Math.min(leftMinHeight, rightMinHeight) + 1;
431
402
  };
432
- return _getMinHeight(beginRoot);
403
+ return _getMinHeight_1(beginRoot);
433
404
  }
434
405
  else {
435
- const stack = [];
436
- let node = beginRoot, last = null;
437
- const depths = new Map();
406
+ var stack = [];
407
+ var node = beginRoot, last = null;
408
+ var depths = new Map();
438
409
  while (stack.length > 0 || node) {
439
410
  if (node) {
440
411
  stack.push(node);
@@ -445,8 +416,8 @@ class AbstractBinaryTree {
445
416
  if (!node.right || last === node.right) {
446
417
  node = stack.pop();
447
418
  if (node) {
448
- const leftMinHeight = node.left ? (_a = depths.get(node.left)) !== null && _a !== void 0 ? _a : -1 : -1;
449
- const rightMinHeight = node.right ? (_b = depths.get(node.right)) !== null && _b !== void 0 ? _b : -1 : -1;
419
+ var leftMinHeight = node.left ? (_a = depths.get(node.left)) !== null && _a !== void 0 ? _a : -1 : -1;
420
+ var rightMinHeight = node.right ? (_b = depths.get(node.right)) !== null && _b !== void 0 ? _b : -1 : -1;
450
421
  depths.set(node, 1 + Math.min(leftMinHeight, rightMinHeight));
451
422
  last = node;
452
423
  node = null;
@@ -458,48 +429,31 @@ class AbstractBinaryTree {
458
429
  }
459
430
  return (_c = depths.get(beginRoot)) !== null && _c !== void 0 ? _c : -1;
460
431
  }
461
- }
462
- /**
463
- * The function checks if a binary tree is perfectly balanced by comparing the minimum height and the height of the
464
- * tree.
465
- * @param {N | null} [beginRoot] - The parameter `beginRoot` is of type `N` or `null`. It represents the root node of a
466
- * tree or null if the tree is empty.
467
- * @returns The method is returning a boolean value.
468
- */
469
- isPerfectlyBalanced(beginRoot) {
470
- return (this.getMinHeight(beginRoot) + 1 >= this.getHeight(beginRoot));
471
- }
472
- /**
473
- * The function `getNodes` returns an array of nodes that match a given property name and value in a binary tree.
474
- * @param {BinaryTreeNodeId | N} nodeProperty - The `nodeProperty` parameter can be either a `BinaryTreeNodeId` or a
475
- * generic type `N`. It represents the property of the binary tree node that you want to search for.
476
- * @param {BinaryTreeNodePropertyName} [propertyName] - The `propertyName` parameter is an optional parameter that
477
- * specifies the property name to use when searching for nodes. If not provided, it defaults to 'id'.
478
- * @param {boolean} [onlyOne] - The `onlyOne` parameter is an optional boolean parameter that determines whether to
479
- * return only one node that matches the given `nodeProperty` or `propertyName`. If `onlyOne` is set to `true`, the
480
- * function will stop traversing the tree and return the first matching node. If `only
481
- * @returns an array of nodes (type N).
482
- */
483
- getNodes(nodeProperty, propertyName, onlyOne) {
432
+ };
433
+ AbstractBinaryTree.prototype.isPerfectlyBalanced = function (beginRoot) {
434
+ return this.getMinHeight(beginRoot) + 1 >= this.getHeight(beginRoot);
435
+ };
436
+ AbstractBinaryTree.prototype.getNodes = function (nodeProperty, propertyName, onlyOne) {
437
+ var _this = this;
484
438
  if (!this.root)
485
439
  return [];
486
440
  propertyName = propertyName !== null && propertyName !== void 0 ? propertyName : 'id';
487
- const result = [];
441
+ var result = [];
488
442
  if (this.loopType === types_1.LoopType.RECURSIVE) {
489
- const _traverse = (cur) => {
490
- if (this._pushByPropertyNameStopOrNot(cur, result, nodeProperty, propertyName, onlyOne))
443
+ var _traverse_1 = function (cur) {
444
+ if (_this._pushByPropertyNameStopOrNot(cur, result, nodeProperty, propertyName, onlyOne))
491
445
  return;
492
446
  if (!cur.left && !cur.right)
493
447
  return;
494
- cur.left && _traverse(cur.left);
495
- cur.right && _traverse(cur.right);
448
+ cur.left && _traverse_1(cur.left);
449
+ cur.right && _traverse_1(cur.right);
496
450
  };
497
- _traverse(this.root);
451
+ _traverse_1(this.root);
498
452
  }
499
453
  else {
500
- const queue = [this.root];
454
+ var queue = [this.root];
501
455
  while (queue.length > 0) {
502
- const cur = queue.shift();
456
+ var cur = queue.shift();
503
457
  if (cur) {
504
458
  if (this._pushByPropertyNameStopOrNot(cur, result, nodeProperty, propertyName, onlyOne))
505
459
  return result;
@@ -509,212 +463,136 @@ class AbstractBinaryTree {
509
463
  }
510
464
  }
511
465
  return result;
512
- }
513
- /**
514
- * The function checks if a binary tree node has a specific property.
515
- * @param {BinaryTreeNodeId | N} nodeProperty - The `nodeProperty` parameter can be either a `BinaryTreeNodeId` or `N`.
516
- * It represents the property of the binary tree node that you want to check.
517
- * @param {BinaryTreeNodePropertyName} [propertyName] - The `propertyName` parameter is an optional parameter that
518
- * specifies the name of the property to be checked in the nodes. If not provided, it defaults to 'id'.
519
- * @returns a boolean value.
520
- */
521
- has(nodeProperty, propertyName) {
466
+ };
467
+ AbstractBinaryTree.prototype.has = function (nodeProperty, propertyName) {
522
468
  propertyName = propertyName !== null && propertyName !== void 0 ? propertyName : 'id';
523
- // TODO may support finding node by value equal
524
469
  return this.getNodes(nodeProperty, propertyName).length > 0;
525
- }
526
- /**
527
- * The function returns the first node that matches the given property name and value, or null if no matching node is
528
- * found.
529
- * @param {BinaryTreeNodeId | N} nodeProperty - The `nodeProperty` parameter can be either a `BinaryTreeNodeId` or `N`.
530
- * It represents the property of the binary tree node that you want to search for.
531
- * @param {BinaryTreeNodePropertyName} [propertyName] - The `propertyName` parameter is an optional parameter that
532
- * specifies the property name to be used for searching the binary tree nodes. If this parameter is not provided, the
533
- * default value is set to `'id'`.
534
- * @returns either the value of the specified property of the node, or the node itself if no property name is provided.
535
- * If no matching node is found, it returns null.
536
- */
537
- get(nodeProperty, propertyName) {
470
+ };
471
+ AbstractBinaryTree.prototype.get = function (nodeProperty, propertyName) {
538
472
  var _a;
539
473
  propertyName = propertyName !== null && propertyName !== void 0 ? propertyName : 'id';
540
- // TODO may support finding node by value equal
541
474
  return (_a = this.getNodes(nodeProperty, propertyName, true)[0]) !== null && _a !== void 0 ? _a : null;
542
- }
543
- /**
544
- * The function getPathToRoot takes a node and returns an array of nodes representing the path from the given node to
545
- * the root node.
546
- * @param {N} node - The parameter `node` represents a node in a tree data structure.
547
- * @returns The function `getPathToRoot` returns an array of nodes (`N[]`).
548
- */
549
- getPathToRoot(node) {
550
- // TODO to support get path through passing id
551
- const result = [];
475
+ };
476
+ AbstractBinaryTree.prototype.getPathToRoot = function (node, isReverse) {
477
+ if (isReverse === void 0) { isReverse = true; }
478
+ var result = [];
552
479
  while (node.parent) {
553
- result.unshift(node);
480
+ result.push(node);
554
481
  node = node.parent;
555
482
  }
556
- result.unshift(node);
557
- return result;
558
- }
559
- /**
560
- * The `getLeftMost` function returns the leftmost node in a binary tree, starting from a specified node or the root if
561
- * no node is specified.
562
- * @param {N | BinaryTreeNodeId | null} [beginRoot] - The `beginRoot` parameter is optional and can be of type `N` (a
563
- * generic type representing a node in a binary tree), `BinaryTreeNodeId` (a type representing the ID of a binary tree
564
- * node), or `null`.
565
- * @returns The function `getLeftMost` returns the leftmost node in a binary tree. If the `beginRoot` parameter is
566
- * provided, it starts the traversal from that node. If `beginRoot` is not provided or is `null`, it starts the
567
- * traversal from the root of the binary tree. If there are no nodes in the binary tree, it returns `null`.
568
- */
569
- getLeftMost(beginRoot) {
483
+ result.push(node);
484
+ return isReverse ? result.reverse() : result;
485
+ };
486
+ AbstractBinaryTree.prototype.getLeftMost = function (beginRoot) {
570
487
  if (typeof beginRoot === 'number')
571
488
  beginRoot = this.get(beginRoot, 'id');
572
489
  beginRoot = beginRoot !== null && beginRoot !== void 0 ? beginRoot : this.root;
573
490
  if (!beginRoot)
574
491
  return beginRoot;
575
492
  if (this._loopType === types_1.LoopType.RECURSIVE) {
576
- const _traverse = (cur) => {
493
+ var _traverse_2 = function (cur) {
577
494
  if (!cur.left)
578
495
  return cur;
579
- return _traverse(cur.left);
496
+ return _traverse_2(cur.left);
580
497
  };
581
- return _traverse(beginRoot);
498
+ return _traverse_2(beginRoot);
582
499
  }
583
500
  else {
584
- // Indirect implementation of iteration using tail recursion optimization
585
- const _traverse = (0, utils_1.trampoline)((cur) => {
501
+ var _traverse_3 = (0, utils_1.trampoline)(function (cur) {
586
502
  if (!cur.left)
587
503
  return cur;
588
- return _traverse.cont(cur.left);
504
+ return _traverse_3.cont(cur.left);
589
505
  });
590
- return _traverse(beginRoot);
506
+ return _traverse_3(beginRoot);
591
507
  }
592
- }
593
- /**
594
- * The `getRightMost` function returns the rightmost node in a binary tree, either recursively or iteratively using
595
- * tail recursion optimization.
596
- * @param {N | null} [node] - The `node` parameter is an optional parameter of type `N` or `null`. It represents the
597
- * starting node from which we want to find the rightmost node. If no node is provided, the `node` parameter defaults
598
- * to `this.root`, which is the root node of the data structure
599
- * @returns The function `getRightMost` returns the rightmost node (`N`) in a binary tree. If the `node` parameter is
600
- * not provided, it defaults to the root node of the tree. If the tree is empty or the `node` parameter is `null`, the
601
- * function returns `null`.
602
- */
603
- getRightMost(node) {
604
- // TODO support get right most by passing id in
508
+ };
509
+ AbstractBinaryTree.prototype.getRightMost = function (node) {
605
510
  node = node !== null && node !== void 0 ? node : this.root;
606
511
  if (!node)
607
512
  return node;
608
513
  if (this._loopType === types_1.LoopType.RECURSIVE) {
609
- const _traverse = (cur) => {
514
+ var _traverse_4 = function (cur) {
610
515
  if (!cur.right)
611
516
  return cur;
612
- return _traverse(cur.right);
517
+ return _traverse_4(cur.right);
613
518
  };
614
- return _traverse(node);
519
+ return _traverse_4(node);
615
520
  }
616
521
  else {
617
- // Indirect implementation of iteration using tail recursion optimization
618
- const _traverse = (0, utils_1.trampoline)((cur) => {
522
+ var _traverse_5 = (0, utils_1.trampoline)(function (cur) {
619
523
  if (!cur.right)
620
524
  return cur;
621
- return _traverse.cont(cur.right);
525
+ return _traverse_5.cont(cur.right);
622
526
  });
623
- return _traverse(node);
527
+ return _traverse_5(node);
624
528
  }
625
- }
626
- /**
627
- * The function checks if a binary search tree is valid by traversing it either recursively or iteratively.
628
- * @param {N | null} node - The `node` parameter represents the root node of a binary search tree (BST).
629
- * @returns a boolean value.
630
- */
631
- isSubtreeBST(node) {
632
- // TODO there is a bug
529
+ };
530
+ AbstractBinaryTree.prototype.isSubtreeBST = function (node) {
633
531
  if (!node)
634
532
  return true;
635
533
  if (this._loopType === types_1.LoopType.RECURSIVE) {
636
- const dfs = (cur, min, max) => {
534
+ var dfs_1 = function (cur, min, max) {
637
535
  if (!cur)
638
536
  return true;
639
537
  if (cur.id <= min || cur.id >= max)
640
538
  return false;
641
- return dfs(cur.left, min, cur.id) && dfs(cur.right, cur.id, max);
539
+ return dfs_1(cur.left, min, cur.id) && dfs_1(cur.right, cur.id, max);
642
540
  };
643
- return dfs(node, Number.MIN_SAFE_INTEGER, Number.MAX_SAFE_INTEGER);
541
+ return dfs_1(node, Number.MIN_SAFE_INTEGER, Number.MAX_SAFE_INTEGER);
644
542
  }
645
543
  else {
646
- const stack = [];
647
- let prev = Number.MIN_SAFE_INTEGER, curr = node;
544
+ var stack = [];
545
+ var prev = Number.MIN_SAFE_INTEGER, curr = node;
648
546
  while (curr || stack.length > 0) {
649
547
  while (curr) {
650
548
  stack.push(curr);
651
549
  curr = curr.left;
652
550
  }
653
551
  curr = stack.pop();
654
- if (!(curr) || prev >= curr.id)
552
+ if (!curr || prev >= curr.id)
655
553
  return false;
656
554
  prev = curr.id;
657
555
  curr = curr.right;
658
556
  }
659
557
  return true;
660
558
  }
661
- }
662
- /**
663
- * The function isBST checks if the binary search tree is valid.
664
- * @returns The `isBST()` function is returning a boolean value.
665
- */
666
- isBST() {
559
+ };
560
+ AbstractBinaryTree.prototype.isBST = function () {
667
561
  return this.isSubtreeBST(this.root);
668
- }
669
- /**
670
- * The function calculates the size of a subtree by traversing it either recursively or iteratively.
671
- * @param {N | null | undefined} subTreeRoot - The `subTreeRoot` parameter represents the root node of a subtree in a
672
- * binary tree.
673
- * @returns the size of the subtree rooted at `subTreeRoot`.
674
- */
675
- getSubTreeSize(subTreeRoot) {
676
- // TODO support id passed in
677
- let size = 0;
562
+ };
563
+ AbstractBinaryTree.prototype.getSubTreeSize = function (subTreeRoot) {
564
+ var size = 0;
678
565
  if (!subTreeRoot)
679
566
  return size;
680
567
  if (this._loopType === types_1.LoopType.RECURSIVE) {
681
- const _traverse = (cur) => {
568
+ var _traverse_6 = function (cur) {
682
569
  size++;
683
- cur.left && _traverse(cur.left);
684
- cur.right && _traverse(cur.right);
570
+ cur.left && _traverse_6(cur.left);
571
+ cur.right && _traverse_6(cur.right);
685
572
  };
686
- _traverse(subTreeRoot);
573
+ _traverse_6(subTreeRoot);
687
574
  return size;
688
575
  }
689
576
  else {
690
- const stack = [subTreeRoot];
577
+ var stack = [subTreeRoot];
691
578
  while (stack.length > 0) {
692
- const cur = stack.pop();
579
+ var cur = stack.pop();
693
580
  size++;
694
581
  cur.right && stack.push(cur.right);
695
582
  cur.left && stack.push(cur.left);
696
583
  }
697
584
  return size;
698
585
  }
699
- }
700
- /**
701
- * The function `subTreeSum` calculates the sum of a specified property in a binary tree or subtree.
702
- * @param {N | BinaryTreeNodeId | null} subTreeRoot - The `subTreeRoot` parameter represents the root node of a binary
703
- * tree or the ID of a binary tree node. It can also be `null` if there is no subtree.
704
- * @param {BinaryTreeNodePropertyName} [propertyName] - propertyName is an optional parameter that specifies the
705
- * property of the binary tree node to use for calculating the sum. It can be either 'id' or 'val'. If propertyName is
706
- * not provided, it defaults to 'id'.
707
- * @returns a number, which is the sum of the values of the specified property in the subtree rooted at `subTreeRoot`.
708
- */
709
- subTreeSum(subTreeRoot, propertyName) {
586
+ };
587
+ AbstractBinaryTree.prototype.subTreeSum = function (subTreeRoot, propertyName) {
710
588
  propertyName = propertyName !== null && propertyName !== void 0 ? propertyName : 'id';
711
589
  if (typeof subTreeRoot === 'number')
712
590
  subTreeRoot = this.get(subTreeRoot, 'id');
713
591
  if (!subTreeRoot)
714
592
  return 0;
715
- let sum = 0;
716
- const _sumByProperty = (cur) => {
717
- let needSum;
593
+ var sum = 0;
594
+ var _sumByProperty = function (cur) {
595
+ var needSum;
718
596
  switch (propertyName) {
719
597
  case 'id':
720
598
  needSum = cur.id;
@@ -729,41 +607,31 @@ class AbstractBinaryTree {
729
607
  return needSum;
730
608
  };
731
609
  if (this._loopType === types_1.LoopType.RECURSIVE) {
732
- const _traverse = (cur) => {
610
+ var _traverse_7 = function (cur) {
733
611
  sum += _sumByProperty(cur);
734
- cur.left && _traverse(cur.left);
735
- cur.right && _traverse(cur.right);
612
+ cur.left && _traverse_7(cur.left);
613
+ cur.right && _traverse_7(cur.right);
736
614
  };
737
- _traverse(subTreeRoot);
615
+ _traverse_7(subTreeRoot);
738
616
  }
739
617
  else {
740
- const stack = [subTreeRoot];
618
+ var stack = [subTreeRoot];
741
619
  while (stack.length > 0) {
742
- const cur = stack.pop();
620
+ var cur = stack.pop();
743
621
  sum += _sumByProperty(cur);
744
622
  cur.right && stack.push(cur.right);
745
623
  cur.left && stack.push(cur.left);
746
624
  }
747
625
  }
748
626
  return sum;
749
- }
750
- /**
751
- * The function `subTreeAdd` adds a delta value to a specified property of each node in a subtree.
752
- * @param {N | BinaryTreeNodeId | null} subTreeRoot - The `subTreeRoot` parameter represents the root node of a binary
753
- * tree or the ID of a node in the binary tree. It can also be `null` if there is no subtree to add to.
754
- * @param {number} delta - The `delta` parameter is a number that represents the amount by which the property value of
755
- * each node in the subtree should be incremented.
756
- * @param {BinaryTreeNodePropertyName} [propertyName] - The `propertyName` parameter is an optional parameter that
757
- * specifies the property of the binary tree node that should be modified. If not provided, it defaults to 'id'.
758
- * @returns a boolean value.
759
- */
760
- subTreeAdd(subTreeRoot, delta, propertyName) {
627
+ };
628
+ AbstractBinaryTree.prototype.subTreeAdd = function (subTreeRoot, delta, propertyName) {
761
629
  propertyName = propertyName !== null && propertyName !== void 0 ? propertyName : 'id';
762
630
  if (typeof subTreeRoot === 'number')
763
631
  subTreeRoot = this.get(subTreeRoot, 'id');
764
632
  if (!subTreeRoot)
765
633
  return false;
766
- const _addByProperty = (cur) => {
634
+ var _addByProperty = function (cur) {
767
635
  switch (propertyName) {
768
636
  case 'id':
769
637
  cur.id += delta;
@@ -774,39 +642,30 @@ class AbstractBinaryTree {
774
642
  }
775
643
  };
776
644
  if (this._loopType === types_1.LoopType.RECURSIVE) {
777
- const _traverse = (cur) => {
645
+ var _traverse_8 = function (cur) {
778
646
  _addByProperty(cur);
779
- cur.left && _traverse(cur.left);
780
- cur.right && _traverse(cur.right);
647
+ cur.left && _traverse_8(cur.left);
648
+ cur.right && _traverse_8(cur.right);
781
649
  };
782
- _traverse(subTreeRoot);
650
+ _traverse_8(subTreeRoot);
783
651
  }
784
652
  else {
785
- const stack = [subTreeRoot];
653
+ var stack = [subTreeRoot];
786
654
  while (stack.length > 0) {
787
- const cur = stack.pop();
655
+ var cur = stack.pop();
788
656
  _addByProperty(cur);
789
657
  cur.right && stack.push(cur.right);
790
658
  cur.left && stack.push(cur.left);
791
659
  }
792
660
  }
793
661
  return true;
794
- }
795
- /**
796
- * The BFS function performs a breadth-first search on a binary tree, accumulating properties of each node based on a
797
- * specified property name.
798
- * @param {NodeOrPropertyName} [nodeOrPropertyName] - The parameter `nodeOrPropertyName` is an optional parameter that
799
- * represents either a node or a property name. If a node is provided, the breadth-first search (BFS) algorithm will be
800
- * performed starting from that node. If a property name is provided, the BFS algorithm will be performed starting from
801
- * the
802
- * @returns an instance of the `AbstractBinaryTreeNodeProperties` class with generic type `N`.
803
- */
804
- BFS(nodeOrPropertyName) {
662
+ };
663
+ AbstractBinaryTree.prototype.BFS = function (nodeOrPropertyName) {
805
664
  nodeOrPropertyName = nodeOrPropertyName !== null && nodeOrPropertyName !== void 0 ? nodeOrPropertyName : 'id';
806
665
  this._clearResults();
807
- const queue = [this.root];
666
+ var queue = [this.root];
808
667
  while (queue.length !== 0) {
809
- const cur = queue.shift();
668
+ var cur = queue.shift();
810
669
  if (cur) {
811
670
  this._accumulatedByPropertyName(cur, nodeOrPropertyName);
812
671
  if ((cur === null || cur === void 0 ? void 0 : cur.left) !== null)
@@ -816,33 +675,23 @@ class AbstractBinaryTree {
816
675
  }
817
676
  }
818
677
  return this._getResultByPropertyName(nodeOrPropertyName);
819
- }
820
- /**
821
- * The DFS function performs a depth-first search traversal on a binary tree and returns the accumulated properties of
822
- * each node based on the specified pattern and property name.
823
- * @param {'in' | 'pre' | 'post'} [pattern] - The "pattern" parameter is used to specify the traversal order of the
824
- * binary tree. It can have three possible values:
825
- * @param {NodeOrPropertyName} [nodeOrPropertyName] - The `nodeOrPropertyName` parameter is a string that represents
826
- * the name of a property of the nodes in the binary tree. This property will be used to accumulate values during the
827
- * depth-first search traversal. If no `nodeOrPropertyName` is provided, the default value is `'id'`.
828
- * @returns an instance of the AbstractBinaryTreeNodeProperties class, which contains the accumulated properties of the
829
- * binary tree nodes based on the specified pattern and node or property name.
830
- */
831
- DFS(pattern, nodeOrPropertyName) {
678
+ };
679
+ AbstractBinaryTree.prototype.DFS = function (pattern, nodeOrPropertyName) {
680
+ var _this = this;
832
681
  pattern = pattern !== null && pattern !== void 0 ? pattern : 'in';
833
682
  nodeOrPropertyName = nodeOrPropertyName !== null && nodeOrPropertyName !== void 0 ? nodeOrPropertyName : 'id';
834
683
  this._clearResults();
835
- const _traverse = (node) => {
684
+ var _traverse = function (node) {
836
685
  switch (pattern) {
837
686
  case 'in':
838
687
  if (node.left)
839
688
  _traverse(node.left);
840
- this._accumulatedByPropertyName(node, nodeOrPropertyName);
689
+ _this._accumulatedByPropertyName(node, nodeOrPropertyName);
841
690
  if (node.right)
842
691
  _traverse(node.right);
843
692
  break;
844
693
  case 'pre':
845
- this._accumulatedByPropertyName(node, nodeOrPropertyName);
694
+ _this._accumulatedByPropertyName(node, nodeOrPropertyName);
846
695
  if (node.left)
847
696
  _traverse(node.left);
848
697
  if (node.right)
@@ -853,34 +702,22 @@ class AbstractBinaryTree {
853
702
  _traverse(node.left);
854
703
  if (node.right)
855
704
  _traverse(node.right);
856
- this._accumulatedByPropertyName(node, nodeOrPropertyName);
705
+ _this._accumulatedByPropertyName(node, nodeOrPropertyName);
857
706
  break;
858
707
  }
859
708
  };
860
709
  this.root && _traverse(this.root);
861
710
  return this._getResultByPropertyName(nodeOrPropertyName);
862
- }
863
- /**
864
- * The DFSIterative function performs an iterative depth-first search traversal on a binary tree, with the option to
865
- * specify the traversal pattern and the property name to accumulate results by.
866
- * @param {'in' | 'pre' | 'post'} [pattern] - The "pattern" parameter determines the order in which the nodes of the
867
- * binary tree are visited during the depth-first search. It can have one of the following values:
868
- * @param {NodeOrPropertyName} [nodeOrPropertyName] - The `nodeOrPropertyName` parameter is used to specify the
869
- * property of the nodes that you want to retrieve or perform operations on during the depth-first search traversal. By
870
- * default, it is set to `'id'`, which means that the traversal will accumulate results based on the `id` property of
871
- * the
872
- * @returns an object of type AbstractBinaryTreeNodeProperties<N>.
873
- */
874
- DFSIterative(pattern, nodeOrPropertyName) {
711
+ };
712
+ AbstractBinaryTree.prototype.DFSIterative = function (pattern, nodeOrPropertyName) {
875
713
  pattern = pattern || 'in';
876
714
  nodeOrPropertyName = nodeOrPropertyName || 'id';
877
715
  this._clearResults();
878
716
  if (!this.root)
879
717
  return this._getResultByPropertyName(nodeOrPropertyName);
880
- // 0: visit, 1: print
881
- const stack = [{ opt: 0, node: this.root }];
718
+ var stack = [{ opt: 0, node: this.root }];
882
719
  while (stack.length > 0) {
883
- const cur = stack.pop();
720
+ var cur = stack.pop();
884
721
  if (!cur || !cur.node)
885
722
  continue;
886
723
  if (cur.opt === 1) {
@@ -912,28 +749,16 @@ class AbstractBinaryTree {
912
749
  }
913
750
  }
914
751
  return this._getResultByPropertyName(nodeOrPropertyName);
915
- }
916
- /**
917
- * The `levelIterative` function performs a level-order traversal on a binary tree and returns the values of the nodes
918
- * in an array, based on a specified property name.
919
- * @param {N | null} node - The `node` parameter is a BinaryTreeNode object representing the starting
920
- * node for the level order traversal. It can be null if no specific node is provided, in which case the root node of
921
- * the tree is used as the starting node.
922
- * @param {NodeOrPropertyName} [nodeOrPropertyName] - The `nodeOrPropertyName` parameter is an optional parameter that
923
- * can be either a `BinaryTreeNode` property name or the string `'id'`. If a property name is provided, the function
924
- * will accumulate results based on that property. If no property name is provided, the function will default to
925
- * accumulating results
926
- * @returns The function `levelIterative` returns an object of type `AbstractBinaryTreeNodeProperties<N>`.
927
- */
928
- levelIterative(node, nodeOrPropertyName) {
752
+ };
753
+ AbstractBinaryTree.prototype.levelIterative = function (node, nodeOrPropertyName) {
929
754
  nodeOrPropertyName = nodeOrPropertyName || 'id';
930
755
  node = node || this.root;
931
756
  if (!node)
932
757
  return [];
933
758
  this._clearResults();
934
- const queue = [node];
759
+ var queue = [node];
935
760
  while (queue.length > 0) {
936
- const cur = queue.shift();
761
+ var cur = queue.shift();
937
762
  if (cur) {
938
763
  this._accumulatedByPropertyName(cur, nodeOrPropertyName);
939
764
  if (cur.left) {
@@ -945,23 +770,14 @@ class AbstractBinaryTree {
945
770
  }
946
771
  }
947
772
  return this._getResultByPropertyName(nodeOrPropertyName);
948
- }
949
- /**
950
- * The `listLevels` function collects nodes from a binary tree by a specified property and organizes them into levels.
951
- * @param {N | null} node - The `node` parameter is a BinaryTreeNode object or null. It represents the
952
- * root node of a binary tree. If it is null, the function will use the root node of the current binary tree instance.
953
- * @param {NodeOrPropertyName} [nodeOrPropertyName] - The `nodeOrPropertyName` parameter is an optional parameter that
954
- * specifies the property of the `BinaryTreeNode` object to collect at each level. It can be one of the following
955
- * values:
956
- * @returns The function `listLevels` returns a 2D array of `AbstractBinaryTreeNodeProperty<N>` objects.
957
- */
958
- listLevels(node, nodeOrPropertyName) {
773
+ };
774
+ AbstractBinaryTree.prototype.listLevels = function (node, nodeOrPropertyName) {
959
775
  nodeOrPropertyName = nodeOrPropertyName || 'id';
960
776
  node = node || this.root;
961
777
  if (!node)
962
778
  return [];
963
- const levelsNodes = [];
964
- const collectByProperty = (node, level) => {
779
+ var levelsNodes = [];
780
+ var collectByProperty = function (node, level) {
965
781
  switch (nodeOrPropertyName) {
966
782
  case 'id':
967
783
  levelsNodes[level].push(node.id);
@@ -978,42 +794,37 @@ class AbstractBinaryTree {
978
794
  }
979
795
  };
980
796
  if (this.loopType === types_1.LoopType.RECURSIVE) {
981
- const _recursive = (node, level) => {
797
+ var _recursive_1 = function (node, level) {
982
798
  if (!levelsNodes[level])
983
799
  levelsNodes[level] = [];
984
800
  collectByProperty(node, level);
985
801
  if (node.left)
986
- _recursive(node.left, level + 1);
802
+ _recursive_1(node.left, level + 1);
987
803
  if (node.right)
988
- _recursive(node.right, level + 1);
804
+ _recursive_1(node.right, level + 1);
989
805
  };
990
- _recursive(node, 0);
806
+ _recursive_1(node, 0);
991
807
  }
992
808
  else {
993
- const stack = [[node, 0]];
809
+ var stack = [[node, 0]];
994
810
  while (stack.length > 0) {
995
- const head = stack.pop();
996
- const [node, level] = head;
811
+ var head = stack.pop();
812
+ var _a = __read(head, 2), node_1 = _a[0], level = _a[1];
997
813
  if (!levelsNodes[level])
998
814
  levelsNodes[level] = [];
999
- collectByProperty(node, level);
1000
- if (node.right)
1001
- stack.push([node.right, level + 1]);
1002
- if (node.left)
1003
- stack.push([node.left, level + 1]);
815
+ collectByProperty(node_1, level);
816
+ if (node_1.right)
817
+ stack.push([node_1.right, level + 1]);
818
+ if (node_1.left)
819
+ stack.push([node_1.left, level + 1]);
1004
820
  }
1005
821
  }
1006
822
  return levelsNodes;
1007
- }
1008
- /**
1009
- * The function returns the predecessor of a given node in a binary tree.
1010
- * @param node - The parameter `node` is a BinaryTreeNode object, representing a node in a binary tree.
1011
- * @returns the predecessor of the given node in a binary tree.
1012
- */
1013
- getPredecessor(node) {
823
+ };
824
+ AbstractBinaryTree.prototype.getPredecessor = function (node) {
1014
825
  if (node.left) {
1015
- let predecessor = node.left;
1016
- while (!(predecessor) || predecessor.right && predecessor.right !== node) {
826
+ var predecessor = node.left;
827
+ while (!predecessor || (predecessor.right && predecessor.right !== node)) {
1017
828
  if (predecessor) {
1018
829
  predecessor = predecessor.right;
1019
830
  }
@@ -1023,27 +834,18 @@ class AbstractBinaryTree {
1023
834
  else {
1024
835
  return node;
1025
836
  }
1026
- }
1027
- /**
1028
- * The `morris` function performs an in-order, pre-order, or post-order traversal on a binary tree using the Morris
1029
- * traversal algorithm.
1030
- * @param {'in' | 'pre' | 'post'} [pattern] - The `pattern` parameter determines the traversal pattern for the binary
1031
- * tree. It can have one of three values:
1032
- * @param {NodeOrPropertyName} [nodeOrPropertyName] - The `nodeOrPropertyName` parameter is used to specify the
1033
- * property name of the nodes that you want to retrieve. It can be any valid property name of the nodes in the binary
1034
- * tree.
1035
- * @returns an array of AbstractBinaryTreeNodeProperties<N> objects.
1036
- */
1037
- morris(pattern, nodeOrPropertyName) {
837
+ };
838
+ AbstractBinaryTree.prototype.morris = function (pattern, nodeOrPropertyName) {
839
+ var _this = this;
1038
840
  if (this.root === null)
1039
841
  return [];
1040
842
  pattern = pattern || 'in';
1041
843
  nodeOrPropertyName = nodeOrPropertyName || 'id';
1042
844
  this._clearResults();
1043
- let cur = this.root;
1044
- const _reverseEdge = (node) => {
1045
- let pre = null;
1046
- let next = null;
845
+ var cur = this.root;
846
+ var _reverseEdge = function (node) {
847
+ var pre = null;
848
+ var next = null;
1047
849
  while (node) {
1048
850
  next = node.right;
1049
851
  node.right = pre;
@@ -1052,11 +854,11 @@ class AbstractBinaryTree {
1052
854
  }
1053
855
  return pre;
1054
856
  };
1055
- const _printEdge = (node) => {
1056
- const tail = _reverseEdge(node);
1057
- let cur = tail;
857
+ var _printEdge = function (node) {
858
+ var tail = _reverseEdge(node);
859
+ var cur = tail;
1058
860
  while (cur) {
1059
- this._accumulatedByPropertyName(cur, nodeOrPropertyName);
861
+ _this._accumulatedByPropertyName(cur, nodeOrPropertyName);
1060
862
  cur = cur.right;
1061
863
  }
1062
864
  _reverseEdge(tail);
@@ -1065,7 +867,7 @@ class AbstractBinaryTree {
1065
867
  case 'in':
1066
868
  while (cur) {
1067
869
  if (cur.left) {
1068
- const predecessor = this.getPredecessor(cur);
870
+ var predecessor = this.getPredecessor(cur);
1069
871
  if (!predecessor.right) {
1070
872
  predecessor.right = cur;
1071
873
  cur = cur.left;
@@ -1082,7 +884,7 @@ class AbstractBinaryTree {
1082
884
  case 'pre':
1083
885
  while (cur) {
1084
886
  if (cur.left) {
1085
- const predecessor = this.getPredecessor(cur);
887
+ var predecessor = this.getPredecessor(cur);
1086
888
  if (!predecessor.right) {
1087
889
  predecessor.right = cur;
1088
890
  this._accumulatedByPropertyName(cur, nodeOrPropertyName);
@@ -1102,7 +904,7 @@ class AbstractBinaryTree {
1102
904
  case 'post':
1103
905
  while (cur) {
1104
906
  if (cur.left) {
1105
- const predecessor = this.getPredecessor(cur);
907
+ var predecessor = this.getPredecessor(cur);
1106
908
  if (predecessor.right === null) {
1107
909
  predecessor.right = cur;
1108
910
  cur = cur.left;
@@ -1119,21 +921,9 @@ class AbstractBinaryTree {
1119
921
  break;
1120
922
  }
1121
923
  return this._getResultByPropertyName(nodeOrPropertyName);
1122
- }
1123
- /**
1124
- * The function adds a new node to a binary tree if there is an available position.
1125
- * @param {N | null} newNode - The `newNode` parameter is of type `N | null`, which means it can either be a node of
1126
- * type `N` or `null`. It represents the node that you want to add to the binary tree.
1127
- * @param {N} parent - The parent parameter is of type N, which represents a node in a binary tree.
1128
- * @returns either the left or right child node of the parent node, depending on which child is available for adding
1129
- * the new node. If a new node is added, the function also updates the size of the binary tree. If neither the left nor
1130
- * right child is available, the function returns undefined. If the parent node is null, the function also returns
1131
- * undefined.
1132
- */
1133
- _addTo(newNode, parent) {
924
+ };
925
+ AbstractBinaryTree.prototype._addTo = function (newNode, parent) {
1134
926
  if (parent) {
1135
- // When all leaf nodes are null, it will no longer be possible to add new entity nodes to this binary tree.
1136
- // In this scenario, null nodes serve as "sentinel nodes," "virtual nodes," or "placeholder nodes."
1137
927
  if (parent.left === undefined) {
1138
928
  parent.left = newNode;
1139
929
  if (newNode) {
@@ -1155,86 +945,38 @@ class AbstractBinaryTree {
1155
945
  else {
1156
946
  return;
1157
947
  }
1158
- }
1159
- /**
1160
- * The function sets the loop type for a protected variable.
1161
- * @param {LoopType} value - The value parameter is of type LoopType.
1162
- */
1163
- _setLoopType(value) {
948
+ };
949
+ AbstractBinaryTree.prototype._setLoopType = function (value) {
1164
950
  this._loopType = value;
1165
- }
1166
- /**
1167
- * The function sets the value of the `_visitedId` property in a protected manner.
1168
- * @param {BinaryTreeNodeId[]} value - value is an array of BinaryTreeNodeId values.
1169
- */
1170
- _setVisitedId(value) {
951
+ };
952
+ AbstractBinaryTree.prototype._setVisitedId = function (value) {
1171
953
  this._visitedId = value;
1172
- }
1173
- /**
1174
- * The function sets the value of the "_visitedVal" property to the given array.
1175
- * @param value - An array of type N.
1176
- */
1177
- _setVisitedVal(value) {
954
+ };
955
+ AbstractBinaryTree.prototype._setVisitedVal = function (value) {
1178
956
  this._visitedVal = value;
1179
- }
1180
- /**
1181
- * The function sets the value of the _visitedNode property.
1182
- * @param {N[]} value - N[] is an array of elements of type N.
1183
- */
1184
- _setVisitedNode(value) {
957
+ };
958
+ AbstractBinaryTree.prototype._setVisitedNode = function (value) {
1185
959
  this._visitedNode = value;
1186
- }
1187
- /**
1188
- * The function sets the value of the `_visitedLeftSum` property to the provided array.
1189
- * @param {number[]} value - An array of numbers that represents the visited left sum.
1190
- */
1191
- _setVisitedLeftSum(value) {
960
+ };
961
+ AbstractBinaryTree.prototype._setVisitedLeftSum = function (value) {
1192
962
  this._visitedLeftSum = value;
1193
- }
1194
- /**
1195
- * The function sets the root property of an object to a given value, and if the value is not null, it also sets the
1196
- * parent property of the value to undefined.
1197
- * @param {N | null} v - The parameter `v` is of type `N | null`, which means it can either be of type `N` or `null`.
1198
- */
1199
- _setRoot(v) {
963
+ };
964
+ AbstractBinaryTree.prototype._setRoot = function (v) {
1200
965
  if (v) {
1201
966
  v.parent = undefined;
1202
967
  }
1203
968
  this._root = v;
1204
- }
1205
- /**
1206
- * The function sets the size of a protected variable.
1207
- * @param {number} v - number
1208
- */
1209
- _setSize(v) {
969
+ };
970
+ AbstractBinaryTree.prototype._setSize = function (v) {
1210
971
  this._size = v;
1211
- }
1212
- /**
1213
- * The function `_clearResults` resets the values of several arrays used for tracking visited nodes and their
1214
- * properties.
1215
- */
1216
- _clearResults() {
972
+ };
973
+ AbstractBinaryTree.prototype._clearResults = function () {
1217
974
  this._visitedId = [];
1218
975
  this._visitedVal = [];
1219
976
  this._visitedNode = [];
1220
977
  this._visitedLeftSum = [];
1221
- }
1222
- /**
1223
- * The function checks if a given property of a binary tree node matches a specified value, and if so, adds the node to
1224
- * a result array.
1225
- * @param {N} cur - The current node being processed.
1226
- * @param {(N | null | undefined)[]} result - An array that stores the matching nodes.
1227
- * @param {BinaryTreeNodeId | N} nodeProperty - The `nodeProperty` parameter is either a `BinaryTreeNodeId` or a `N`
1228
- * type. It represents the property value that we are comparing against in the switch statement.
1229
- * @param {BinaryTreeNodePropertyName} [propertyName] - The `propertyName` parameter is an optional parameter that
1230
- * specifies the property name to compare against when pushing nodes into the `result` array. It can be either `'id'`
1231
- * or `'val'`. If it is not provided or is not equal to `'id'` or `'val'`, the
1232
- * @param {boolean} [onlyOne] - The `onlyOne` parameter is an optional boolean parameter that determines whether to
1233
- * stop after finding the first matching node or continue searching for all matching nodes. If `onlyOne` is set to
1234
- * `true`, the function will stop after finding the first matching node and return `true`. If `onlyOne
1235
- * @returns a boolean value indicating whether only one matching node should be pushed into the result array.
1236
- */
1237
- _pushByPropertyNameStopOrNot(cur, result, nodeProperty, propertyName, onlyOne) {
978
+ };
979
+ AbstractBinaryTree.prototype._pushByPropertyNameStopOrNot = function (cur, result, nodeProperty, propertyName, onlyOne) {
1238
980
  switch (propertyName) {
1239
981
  case 'id':
1240
982
  if (cur.id === nodeProperty) {
@@ -1255,15 +997,8 @@ class AbstractBinaryTree {
1255
997
  }
1256
998
  break;
1257
999
  }
1258
- }
1259
- /**
1260
- * The function `_accumulatedByPropertyName` accumulates values from a given node based on the specified property name.
1261
- * @param {N} node - The `node` parameter is of type `N`, which represents a node in a data structure.
1262
- * @param {NodeOrPropertyName} [nodeOrPropertyName] - The `nodeOrPropertyName` parameter is an optional parameter that
1263
- * can be either a string representing a property name or a reference to a `Node` object. If it is a string, it
1264
- * specifies the property name to be used for accumulating values. If it is a `Node` object, it specifies
1265
- */
1266
- _accumulatedByPropertyName(node, nodeOrPropertyName) {
1000
+ };
1001
+ AbstractBinaryTree.prototype._accumulatedByPropertyName = function (node, nodeOrPropertyName) {
1267
1002
  nodeOrPropertyName = nodeOrPropertyName !== null && nodeOrPropertyName !== void 0 ? nodeOrPropertyName : 'id';
1268
1003
  switch (nodeOrPropertyName) {
1269
1004
  case 'id':
@@ -1279,19 +1014,8 @@ class AbstractBinaryTree {
1279
1014
  this._visitedId.push(node.id);
1280
1015
  break;
1281
1016
  }
1282
- }
1283
- /**
1284
- * The time complexity of Morris traversal is O(n), it's may slower than others
1285
- * The space complexity Morris traversal is O(1) because no using stack
1286
- */
1287
- /**
1288
- * The function `_getResultByPropertyName` returns the corresponding property value based on the given node or property
1289
- * name.
1290
- * @param {NodeOrPropertyName} [nodeOrPropertyName] - The parameter `nodeOrPropertyName` is an optional parameter that
1291
- * can accept either a `NodeOrPropertyName` type or be undefined.
1292
- * @returns The method `_getResultByPropertyName` returns an instance of `AbstractBinaryTreeNodeProperties<N>`.
1293
- */
1294
- _getResultByPropertyName(nodeOrPropertyName) {
1017
+ };
1018
+ AbstractBinaryTree.prototype._getResultByPropertyName = function (nodeOrPropertyName) {
1295
1019
  nodeOrPropertyName = nodeOrPropertyName !== null && nodeOrPropertyName !== void 0 ? nodeOrPropertyName : 'id';
1296
1020
  switch (nodeOrPropertyName) {
1297
1021
  case 'id':
@@ -1303,6 +1027,8 @@ class AbstractBinaryTree {
1303
1027
  default:
1304
1028
  return this._visitedId;
1305
1029
  }
1306
- }
1307
- }
1030
+ };
1031
+ return AbstractBinaryTree;
1032
+ }());
1308
1033
  exports.AbstractBinaryTree = AbstractBinaryTree;
1034
+ //# sourceMappingURL=abstract-binary-tree.js.map