data-structure-typed 2.1.0 → 2.1.2

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 (711) hide show
  1. package/CHANGELOG.md +5 -1
  2. package/COMMANDS.md +13 -3
  3. package/README.md +21 -38
  4. package/benchmark/report.html +1 -1
  5. package/benchmark/report.json +101 -101
  6. package/dist/cjs/index.cjs +13062 -0
  7. package/dist/cjs/index.cjs.map +1 -0
  8. package/dist/esm/index.mjs +12984 -0
  9. package/dist/esm/index.mjs.map +1 -0
  10. package/dist/{cjs → types}/data-structures/binary-tree/avl-tree-counter.d.ts +5 -5
  11. package/dist/{esm → types}/data-structures/binary-tree/avl-tree-multi-map.d.ts +6 -6
  12. package/dist/{esm → types}/data-structures/binary-tree/avl-tree.d.ts +5 -5
  13. package/dist/{esm → types}/data-structures/binary-tree/binary-tree.d.ts +6 -6
  14. package/dist/{esm → types}/data-structures/binary-tree/bst.d.ts +6 -6
  15. package/dist/{esm → types}/data-structures/binary-tree/red-black-tree.d.ts +6 -6
  16. package/dist/{cjs → types}/data-structures/binary-tree/tree-counter.d.ts +5 -5
  17. package/dist/{cjs → types}/data-structures/binary-tree/tree-multi-map.d.ts +6 -6
  18. package/dist/{esm → types}/data-structures/heap/heap.d.ts +4 -4
  19. package/dist/{esm → types}/data-structures/linked-list/singly-linked-list.d.ts +1 -1
  20. package/dist/{esm → types}/interfaces/binary-tree.d.ts +3 -3
  21. package/dist/umd/data-structure-typed.js +97 -174
  22. package/dist/umd/data-structure-typed.js.map +1 -0
  23. package/dist/umd/data-structure-typed.min.js +2 -2
  24. package/dist/umd/data-structure-typed.min.js.map +1 -1
  25. package/jest.integration.config.js +8 -1
  26. package/package.json +20 -14
  27. package/src/data-structures/binary-tree/avl-tree-counter.ts +8 -11
  28. package/src/data-structures/binary-tree/avl-tree-multi-map.ts +6 -11
  29. package/src/data-structures/binary-tree/avl-tree.ts +6 -8
  30. package/src/data-structures/binary-tree/binary-tree.ts +18 -20
  31. package/src/data-structures/binary-tree/bst.ts +6 -11
  32. package/src/data-structures/binary-tree/red-black-tree.ts +6 -11
  33. package/src/data-structures/binary-tree/tree-counter.ts +8 -13
  34. package/src/data-structures/binary-tree/tree-multi-map.ts +6 -11
  35. package/src/data-structures/heap/heap.ts +5 -5
  36. package/src/data-structures/linked-list/singly-linked-list.ts +2 -2
  37. package/src/interfaces/binary-tree.ts +3 -3
  38. package/test/integration/all-in-one.test.ts +1 -1
  39. package/test/integration/compile.test.mjs +159 -0
  40. package/test/integration/compile.test.ts +176 -0
  41. package/test/integration/heap.test.js +1 -1
  42. package/test/integration/index.html +1 -1
  43. package/test/performance/data-structures/comparison/comparison.test.ts +27 -57
  44. package/test/unit/data-structures/binary-tree/binary-tree.test.ts +3 -3
  45. package/test/unit/data-structures/binary-tree/tree-multi-map.test.ts +109 -1
  46. package/tsconfig.base.json +23 -0
  47. package/tsconfig.test.json +9 -0
  48. package/tsconfig.types.json +15 -0
  49. package/tsup.config.js +12 -24
  50. package/tsup.node.config.js +37 -0
  51. package/dist/cjs/common/index.js +0 -29
  52. package/dist/cjs/common/index.js.map +0 -1
  53. package/dist/cjs/data-structures/base/index.js +0 -19
  54. package/dist/cjs/data-structures/base/index.js.map +0 -1
  55. package/dist/cjs/data-structures/base/iterable-element-base.js +0 -244
  56. package/dist/cjs/data-structures/base/iterable-element-base.js.map +0 -1
  57. package/dist/cjs/data-structures/base/iterable-entry-base.js +0 -184
  58. package/dist/cjs/data-structures/base/iterable-entry-base.js.map +0 -1
  59. package/dist/cjs/data-structures/base/linear-base.js +0 -416
  60. package/dist/cjs/data-structures/base/linear-base.js.map +0 -1
  61. package/dist/cjs/data-structures/binary-tree/avl-tree-counter.js +0 -375
  62. package/dist/cjs/data-structures/binary-tree/avl-tree-counter.js.map +0 -1
  63. package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.d.ts +0 -135
  64. package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.js +0 -251
  65. package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.js.map +0 -1
  66. package/dist/cjs/data-structures/binary-tree/avl-tree.d.ts +0 -291
  67. package/dist/cjs/data-structures/binary-tree/avl-tree.js +0 -612
  68. package/dist/cjs/data-structures/binary-tree/avl-tree.js.map +0 -1
  69. package/dist/cjs/data-structures/binary-tree/binary-indexed-tree.js +0 -295
  70. package/dist/cjs/data-structures/binary-tree/binary-indexed-tree.js.map +0 -1
  71. package/dist/cjs/data-structures/binary-tree/binary-tree.d.ts +0 -754
  72. package/dist/cjs/data-structures/binary-tree/binary-tree.js +0 -1926
  73. package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +0 -1
  74. package/dist/cjs/data-structures/binary-tree/bst.d.ts +0 -413
  75. package/dist/cjs/data-structures/binary-tree/bst.js +0 -904
  76. package/dist/cjs/data-structures/binary-tree/bst.js.map +0 -1
  77. package/dist/cjs/data-structures/binary-tree/index.js +0 -27
  78. package/dist/cjs/data-structures/binary-tree/index.js.map +0 -1
  79. package/dist/cjs/data-structures/binary-tree/red-black-tree.d.ts +0 -208
  80. package/dist/cjs/data-structures/binary-tree/red-black-tree.js +0 -547
  81. package/dist/cjs/data-structures/binary-tree/red-black-tree.js.map +0 -1
  82. package/dist/cjs/data-structures/binary-tree/segment-tree.js +0 -298
  83. package/dist/cjs/data-structures/binary-tree/segment-tree.js.map +0 -1
  84. package/dist/cjs/data-structures/binary-tree/tree-counter.js +0 -414
  85. package/dist/cjs/data-structures/binary-tree/tree-counter.js.map +0 -1
  86. package/dist/cjs/data-structures/binary-tree/tree-multi-map.js +0 -385
  87. package/dist/cjs/data-structures/binary-tree/tree-multi-map.js.map +0 -1
  88. package/dist/cjs/data-structures/graph/abstract-graph.js +0 -897
  89. package/dist/cjs/data-structures/graph/abstract-graph.js.map +0 -1
  90. package/dist/cjs/data-structures/graph/directed-graph.js +0 -526
  91. package/dist/cjs/data-structures/graph/directed-graph.js.map +0 -1
  92. package/dist/cjs/data-structures/graph/index.js +0 -21
  93. package/dist/cjs/data-structures/graph/index.js.map +0 -1
  94. package/dist/cjs/data-structures/graph/map-graph.js +0 -108
  95. package/dist/cjs/data-structures/graph/map-graph.js.map +0 -1
  96. package/dist/cjs/data-structures/graph/undirected-graph.js +0 -425
  97. package/dist/cjs/data-structures/graph/undirected-graph.js.map +0 -1
  98. package/dist/cjs/data-structures/hash/hash-map.js +0 -693
  99. package/dist/cjs/data-structures/hash/hash-map.js.map +0 -1
  100. package/dist/cjs/data-structures/hash/index.js +0 -18
  101. package/dist/cjs/data-structures/hash/index.js.map +0 -1
  102. package/dist/cjs/data-structures/heap/heap.d.ts +0 -503
  103. package/dist/cjs/data-structures/heap/heap.js +0 -902
  104. package/dist/cjs/data-structures/heap/heap.js.map +0 -1
  105. package/dist/cjs/data-structures/heap/index.js +0 -20
  106. package/dist/cjs/data-structures/heap/index.js.map +0 -1
  107. package/dist/cjs/data-structures/heap/max-heap.js +0 -41
  108. package/dist/cjs/data-structures/heap/max-heap.js.map +0 -1
  109. package/dist/cjs/data-structures/heap/min-heap.js +0 -32
  110. package/dist/cjs/data-structures/heap/min-heap.js.map +0 -1
  111. package/dist/cjs/data-structures/index.js +0 -29
  112. package/dist/cjs/data-structures/index.js.map +0 -1
  113. package/dist/cjs/data-structures/linked-list/doubly-linked-list.js +0 -1112
  114. package/dist/cjs/data-structures/linked-list/doubly-linked-list.js.map +0 -1
  115. package/dist/cjs/data-structures/linked-list/index.js +0 -20
  116. package/dist/cjs/data-structures/linked-list/index.js.map +0 -1
  117. package/dist/cjs/data-structures/linked-list/singly-linked-list.d.ts +0 -451
  118. package/dist/cjs/data-structures/linked-list/singly-linked-list.js +0 -851
  119. package/dist/cjs/data-structures/linked-list/singly-linked-list.js.map +0 -1
  120. package/dist/cjs/data-structures/linked-list/skip-linked-list.js +0 -145
  121. package/dist/cjs/data-structures/linked-list/skip-linked-list.js.map +0 -1
  122. package/dist/cjs/data-structures/matrix/index.js +0 -19
  123. package/dist/cjs/data-structures/matrix/index.js.map +0 -1
  124. package/dist/cjs/data-structures/matrix/matrix.js +0 -449
  125. package/dist/cjs/data-structures/matrix/matrix.js.map +0 -1
  126. package/dist/cjs/data-structures/matrix/navigator.js +0 -112
  127. package/dist/cjs/data-structures/matrix/navigator.js.map +0 -1
  128. package/dist/cjs/data-structures/priority-queue/index.js +0 -20
  129. package/dist/cjs/data-structures/priority-queue/index.js.map +0 -1
  130. package/dist/cjs/data-structures/priority-queue/max-priority-queue.js +0 -35
  131. package/dist/cjs/data-structures/priority-queue/max-priority-queue.js.map +0 -1
  132. package/dist/cjs/data-structures/priority-queue/min-priority-queue.js +0 -25
  133. package/dist/cjs/data-structures/priority-queue/min-priority-queue.js.map +0 -1
  134. package/dist/cjs/data-structures/priority-queue/priority-queue.js +0 -21
  135. package/dist/cjs/data-structures/priority-queue/priority-queue.js.map +0 -1
  136. package/dist/cjs/data-structures/queue/deque.js +0 -880
  137. package/dist/cjs/data-structures/queue/deque.js.map +0 -1
  138. package/dist/cjs/data-structures/queue/index.js +0 -19
  139. package/dist/cjs/data-structures/queue/index.js.map +0 -1
  140. package/dist/cjs/data-structures/queue/queue.js +0 -474
  141. package/dist/cjs/data-structures/queue/queue.js.map +0 -1
  142. package/dist/cjs/data-structures/stack/index.js +0 -18
  143. package/dist/cjs/data-structures/stack/index.js.map +0 -1
  144. package/dist/cjs/data-structures/stack/stack.js +0 -402
  145. package/dist/cjs/data-structures/stack/stack.js.map +0 -1
  146. package/dist/cjs/data-structures/tree/index.js +0 -18
  147. package/dist/cjs/data-structures/tree/index.js.map +0 -1
  148. package/dist/cjs/data-structures/tree/tree.js +0 -108
  149. package/dist/cjs/data-structures/tree/tree.js.map +0 -1
  150. package/dist/cjs/data-structures/trie/index.js +0 -18
  151. package/dist/cjs/data-structures/trie/index.js.map +0 -1
  152. package/dist/cjs/data-structures/trie/trie.js +0 -611
  153. package/dist/cjs/data-structures/trie/trie.js.map +0 -1
  154. package/dist/cjs/index.js +0 -22
  155. package/dist/cjs/index.js.map +0 -1
  156. package/dist/cjs/interfaces/binary-tree.d.ts +0 -59
  157. package/dist/cjs/interfaces/binary-tree.js +0 -3
  158. package/dist/cjs/interfaces/binary-tree.js.map +0 -1
  159. package/dist/cjs/interfaces/doubly-linked-list.js +0 -3
  160. package/dist/cjs/interfaces/doubly-linked-list.js.map +0 -1
  161. package/dist/cjs/interfaces/graph.js +0 -3
  162. package/dist/cjs/interfaces/graph.js.map +0 -1
  163. package/dist/cjs/interfaces/heap.js +0 -3
  164. package/dist/cjs/interfaces/heap.js.map +0 -1
  165. package/dist/cjs/interfaces/index.js +0 -25
  166. package/dist/cjs/interfaces/index.js.map +0 -1
  167. package/dist/cjs/interfaces/navigator.js +0 -3
  168. package/dist/cjs/interfaces/navigator.js.map +0 -1
  169. package/dist/cjs/interfaces/priority-queue.js +0 -3
  170. package/dist/cjs/interfaces/priority-queue.js.map +0 -1
  171. package/dist/cjs/interfaces/segment-tree.js +0 -3
  172. package/dist/cjs/interfaces/segment-tree.js.map +0 -1
  173. package/dist/cjs/interfaces/singly-linked-list.js +0 -3
  174. package/dist/cjs/interfaces/singly-linked-list.js.map +0 -1
  175. package/dist/cjs/types/common.js +0 -3
  176. package/dist/cjs/types/common.js.map +0 -1
  177. package/dist/cjs/types/data-structures/base/base.js +0 -3
  178. package/dist/cjs/types/data-structures/base/base.js.map +0 -1
  179. package/dist/cjs/types/data-structures/base/index.js +0 -18
  180. package/dist/cjs/types/data-structures/base/index.js.map +0 -1
  181. package/dist/cjs/types/data-structures/binary-tree/avl-tree-counter.js +0 -3
  182. package/dist/cjs/types/data-structures/binary-tree/avl-tree-counter.js.map +0 -1
  183. package/dist/cjs/types/data-structures/binary-tree/avl-tree-multi-map.js +0 -3
  184. package/dist/cjs/types/data-structures/binary-tree/avl-tree-multi-map.js.map +0 -1
  185. package/dist/cjs/types/data-structures/binary-tree/avl-tree.js +0 -3
  186. package/dist/cjs/types/data-structures/binary-tree/avl-tree.js.map +0 -1
  187. package/dist/cjs/types/data-structures/binary-tree/binary-indexed-tree.js +0 -3
  188. package/dist/cjs/types/data-structures/binary-tree/binary-indexed-tree.js.map +0 -1
  189. package/dist/cjs/types/data-structures/binary-tree/binary-tree.js +0 -3
  190. package/dist/cjs/types/data-structures/binary-tree/binary-tree.js.map +0 -1
  191. package/dist/cjs/types/data-structures/binary-tree/bst.js +0 -3
  192. package/dist/cjs/types/data-structures/binary-tree/bst.js.map +0 -1
  193. package/dist/cjs/types/data-structures/binary-tree/index.js +0 -26
  194. package/dist/cjs/types/data-structures/binary-tree/index.js.map +0 -1
  195. package/dist/cjs/types/data-structures/binary-tree/red-black-tree.js +0 -3
  196. package/dist/cjs/types/data-structures/binary-tree/red-black-tree.js.map +0 -1
  197. package/dist/cjs/types/data-structures/binary-tree/segment-tree.js +0 -3
  198. package/dist/cjs/types/data-structures/binary-tree/segment-tree.js.map +0 -1
  199. package/dist/cjs/types/data-structures/binary-tree/tree-counter.js +0 -3
  200. package/dist/cjs/types/data-structures/binary-tree/tree-counter.js.map +0 -1
  201. package/dist/cjs/types/data-structures/binary-tree/tree-multi-map.js +0 -3
  202. package/dist/cjs/types/data-structures/binary-tree/tree-multi-map.js.map +0 -1
  203. package/dist/cjs/types/data-structures/graph/abstract-graph.js +0 -3
  204. package/dist/cjs/types/data-structures/graph/abstract-graph.js.map +0 -1
  205. package/dist/cjs/types/data-structures/graph/directed-graph.js +0 -3
  206. package/dist/cjs/types/data-structures/graph/directed-graph.js.map +0 -1
  207. package/dist/cjs/types/data-structures/graph/index.js +0 -20
  208. package/dist/cjs/types/data-structures/graph/index.js.map +0 -1
  209. package/dist/cjs/types/data-structures/graph/map-graph.js +0 -3
  210. package/dist/cjs/types/data-structures/graph/map-graph.js.map +0 -1
  211. package/dist/cjs/types/data-structures/graph/undirected-graph.js +0 -3
  212. package/dist/cjs/types/data-structures/graph/undirected-graph.js.map +0 -1
  213. package/dist/cjs/types/data-structures/hash/hash-map.js +0 -3
  214. package/dist/cjs/types/data-structures/hash/hash-map.js.map +0 -1
  215. package/dist/cjs/types/data-structures/hash/index.js +0 -18
  216. package/dist/cjs/types/data-structures/hash/index.js.map +0 -1
  217. package/dist/cjs/types/data-structures/heap/heap.js +0 -3
  218. package/dist/cjs/types/data-structures/heap/heap.js.map +0 -1
  219. package/dist/cjs/types/data-structures/heap/index.js +0 -18
  220. package/dist/cjs/types/data-structures/heap/index.js.map +0 -1
  221. package/dist/cjs/types/data-structures/heap/max-heap.js +0 -3
  222. package/dist/cjs/types/data-structures/heap/max-heap.js.map +0 -1
  223. package/dist/cjs/types/data-structures/heap/min-heap.js +0 -3
  224. package/dist/cjs/types/data-structures/heap/min-heap.js.map +0 -1
  225. package/dist/cjs/types/data-structures/index.js +0 -29
  226. package/dist/cjs/types/data-structures/index.js.map +0 -1
  227. package/dist/cjs/types/data-structures/linked-list/doubly-linked-list.js +0 -3
  228. package/dist/cjs/types/data-structures/linked-list/doubly-linked-list.js.map +0 -1
  229. package/dist/cjs/types/data-structures/linked-list/index.js +0 -20
  230. package/dist/cjs/types/data-structures/linked-list/index.js.map +0 -1
  231. package/dist/cjs/types/data-structures/linked-list/singly-linked-list.js +0 -3
  232. package/dist/cjs/types/data-structures/linked-list/singly-linked-list.js.map +0 -1
  233. package/dist/cjs/types/data-structures/linked-list/skip-linked-list.js +0 -3
  234. package/dist/cjs/types/data-structures/linked-list/skip-linked-list.js.map +0 -1
  235. package/dist/cjs/types/data-structures/matrix/index.js +0 -19
  236. package/dist/cjs/types/data-structures/matrix/index.js.map +0 -1
  237. package/dist/cjs/types/data-structures/matrix/matrix.js +0 -3
  238. package/dist/cjs/types/data-structures/matrix/matrix.js.map +0 -1
  239. package/dist/cjs/types/data-structures/matrix/navigator.js +0 -3
  240. package/dist/cjs/types/data-structures/matrix/navigator.js.map +0 -1
  241. package/dist/cjs/types/data-structures/priority-queue/index.js +0 -20
  242. package/dist/cjs/types/data-structures/priority-queue/index.js.map +0 -1
  243. package/dist/cjs/types/data-structures/priority-queue/max-priority-queue.js +0 -3
  244. package/dist/cjs/types/data-structures/priority-queue/max-priority-queue.js.map +0 -1
  245. package/dist/cjs/types/data-structures/priority-queue/min-priority-queue.js +0 -3
  246. package/dist/cjs/types/data-structures/priority-queue/min-priority-queue.js.map +0 -1
  247. package/dist/cjs/types/data-structures/priority-queue/priority-queue.js +0 -3
  248. package/dist/cjs/types/data-structures/priority-queue/priority-queue.js.map +0 -1
  249. package/dist/cjs/types/data-structures/queue/deque.js +0 -3
  250. package/dist/cjs/types/data-structures/queue/deque.js.map +0 -1
  251. package/dist/cjs/types/data-structures/queue/index.js +0 -19
  252. package/dist/cjs/types/data-structures/queue/index.js.map +0 -1
  253. package/dist/cjs/types/data-structures/queue/queue.js +0 -3
  254. package/dist/cjs/types/data-structures/queue/queue.js.map +0 -1
  255. package/dist/cjs/types/data-structures/stack/index.js +0 -18
  256. package/dist/cjs/types/data-structures/stack/index.js.map +0 -1
  257. package/dist/cjs/types/data-structures/stack/stack.js +0 -3
  258. package/dist/cjs/types/data-structures/stack/stack.js.map +0 -1
  259. package/dist/cjs/types/data-structures/tree/index.js +0 -18
  260. package/dist/cjs/types/data-structures/tree/index.js.map +0 -1
  261. package/dist/cjs/types/data-structures/tree/tree.js +0 -3
  262. package/dist/cjs/types/data-structures/tree/tree.js.map +0 -1
  263. package/dist/cjs/types/data-structures/trie/index.js +0 -18
  264. package/dist/cjs/types/data-structures/trie/index.js.map +0 -1
  265. package/dist/cjs/types/data-structures/trie/trie.js +0 -3
  266. package/dist/cjs/types/data-structures/trie/trie.js.map +0 -1
  267. package/dist/cjs/types/index.js +0 -20
  268. package/dist/cjs/types/index.js.map +0 -1
  269. package/dist/cjs/types/utils/index.js +0 -19
  270. package/dist/cjs/types/utils/index.js.map +0 -1
  271. package/dist/cjs/types/utils/utils.js +0 -3
  272. package/dist/cjs/types/utils/utils.js.map +0 -1
  273. package/dist/cjs/types/utils/validate-type.js +0 -3
  274. package/dist/cjs/types/utils/validate-type.js.map +0 -1
  275. package/dist/cjs/utils/index.js +0 -19
  276. package/dist/cjs/utils/index.js.map +0 -1
  277. package/dist/cjs/utils/number.js +0 -24
  278. package/dist/cjs/utils/number.js.map +0 -1
  279. package/dist/cjs/utils/utils.js +0 -354
  280. package/dist/cjs/utils/utils.js.map +0 -1
  281. package/dist/esm/common/index.d.ts +0 -12
  282. package/dist/esm/common/index.js +0 -29
  283. package/dist/esm/common/index.js.map +0 -1
  284. package/dist/esm/data-structures/base/index.d.ts +0 -2
  285. package/dist/esm/data-structures/base/index.js +0 -3
  286. package/dist/esm/data-structures/base/index.js.map +0 -1
  287. package/dist/esm/data-structures/base/iterable-element-base.d.ts +0 -219
  288. package/dist/esm/data-structures/base/iterable-element-base.js +0 -247
  289. package/dist/esm/data-structures/base/iterable-element-base.js.map +0 -1
  290. package/dist/esm/data-structures/base/iterable-entry-base.d.ts +0 -144
  291. package/dist/esm/data-structures/base/iterable-entry-base.js +0 -180
  292. package/dist/esm/data-structures/base/iterable-entry-base.js.map +0 -1
  293. package/dist/esm/data-structures/base/linear-base.d.ts +0 -335
  294. package/dist/esm/data-structures/base/linear-base.js +0 -412
  295. package/dist/esm/data-structures/base/linear-base.js.map +0 -1
  296. package/dist/esm/data-structures/binary-tree/avl-tree-counter.d.ts +0 -182
  297. package/dist/esm/data-structures/binary-tree/avl-tree-counter.js +0 -369
  298. package/dist/esm/data-structures/binary-tree/avl-tree-counter.js.map +0 -1
  299. package/dist/esm/data-structures/binary-tree/avl-tree-multi-map.js +0 -244
  300. package/dist/esm/data-structures/binary-tree/avl-tree-multi-map.js.map +0 -1
  301. package/dist/esm/data-structures/binary-tree/avl-tree.js +0 -607
  302. package/dist/esm/data-structures/binary-tree/avl-tree.js.map +0 -1
  303. package/dist/esm/data-structures/binary-tree/binary-indexed-tree.d.ts +0 -174
  304. package/dist/esm/data-structures/binary-tree/binary-indexed-tree.js +0 -296
  305. package/dist/esm/data-structures/binary-tree/binary-indexed-tree.js.map +0 -1
  306. package/dist/esm/data-structures/binary-tree/binary-tree.js +0 -1922
  307. package/dist/esm/data-structures/binary-tree/binary-tree.js.map +0 -1
  308. package/dist/esm/data-structures/binary-tree/bst.js +0 -901
  309. package/dist/esm/data-structures/binary-tree/bst.js.map +0 -1
  310. package/dist/esm/data-structures/binary-tree/index.d.ts +0 -10
  311. package/dist/esm/data-structures/binary-tree/index.js +0 -11
  312. package/dist/esm/data-structures/binary-tree/index.js.map +0 -1
  313. package/dist/esm/data-structures/binary-tree/red-black-tree.js +0 -540
  314. package/dist/esm/data-structures/binary-tree/red-black-tree.js.map +0 -1
  315. package/dist/esm/data-structures/binary-tree/segment-tree.d.ts +0 -160
  316. package/dist/esm/data-structures/binary-tree/segment-tree.js +0 -295
  317. package/dist/esm/data-structures/binary-tree/segment-tree.js.map +0 -1
  318. package/dist/esm/data-structures/binary-tree/tree-counter.d.ts +0 -190
  319. package/dist/esm/data-structures/binary-tree/tree-counter.js +0 -412
  320. package/dist/esm/data-structures/binary-tree/tree-counter.js.map +0 -1
  321. package/dist/esm/data-structures/binary-tree/tree-multi-map.d.ts +0 -270
  322. package/dist/esm/data-structures/binary-tree/tree-multi-map.js +0 -378
  323. package/dist/esm/data-structures/binary-tree/tree-multi-map.js.map +0 -1
  324. package/dist/esm/data-structures/graph/abstract-graph.d.ts +0 -340
  325. package/dist/esm/data-structures/graph/abstract-graph.js +0 -892
  326. package/dist/esm/data-structures/graph/abstract-graph.js.map +0 -1
  327. package/dist/esm/data-structures/graph/directed-graph.d.ts +0 -207
  328. package/dist/esm/data-structures/graph/directed-graph.js +0 -521
  329. package/dist/esm/data-structures/graph/directed-graph.js.map +0 -1
  330. package/dist/esm/data-structures/graph/index.d.ts +0 -4
  331. package/dist/esm/data-structures/graph/index.js +0 -5
  332. package/dist/esm/data-structures/graph/index.js.map +0 -1
  333. package/dist/esm/data-structures/graph/map-graph.d.ts +0 -78
  334. package/dist/esm/data-structures/graph/map-graph.js +0 -105
  335. package/dist/esm/data-structures/graph/map-graph.js.map +0 -1
  336. package/dist/esm/data-structures/graph/undirected-graph.d.ts +0 -188
  337. package/dist/esm/data-structures/graph/undirected-graph.js +0 -418
  338. package/dist/esm/data-structures/graph/undirected-graph.js.map +0 -1
  339. package/dist/esm/data-structures/hash/hash-map.d.ts +0 -345
  340. package/dist/esm/data-structures/hash/hash-map.js +0 -691
  341. package/dist/esm/data-structures/hash/hash-map.js.map +0 -1
  342. package/dist/esm/data-structures/hash/index.d.ts +0 -1
  343. package/dist/esm/data-structures/hash/index.js +0 -2
  344. package/dist/esm/data-structures/hash/index.js.map +0 -1
  345. package/dist/esm/data-structures/heap/heap.js +0 -894
  346. package/dist/esm/data-structures/heap/heap.js.map +0 -1
  347. package/dist/esm/data-structures/heap/index.d.ts +0 -3
  348. package/dist/esm/data-structures/heap/index.js +0 -4
  349. package/dist/esm/data-structures/heap/index.js.map +0 -1
  350. package/dist/esm/data-structures/heap/max-heap.d.ts +0 -32
  351. package/dist/esm/data-structures/heap/max-heap.js +0 -40
  352. package/dist/esm/data-structures/heap/max-heap.js.map +0 -1
  353. package/dist/esm/data-structures/heap/min-heap.d.ts +0 -33
  354. package/dist/esm/data-structures/heap/min-heap.js +0 -28
  355. package/dist/esm/data-structures/heap/min-heap.js.map +0 -1
  356. package/dist/esm/data-structures/index.d.ts +0 -12
  357. package/dist/esm/data-structures/index.js +0 -13
  358. package/dist/esm/data-structures/index.js.map +0 -1
  359. package/dist/esm/data-structures/linked-list/doubly-linked-list.d.ts +0 -769
  360. package/dist/esm/data-structures/linked-list/doubly-linked-list.js +0 -1109
  361. package/dist/esm/data-structures/linked-list/doubly-linked-list.js.map +0 -1
  362. package/dist/esm/data-structures/linked-list/index.d.ts +0 -3
  363. package/dist/esm/data-structures/linked-list/index.js +0 -4
  364. package/dist/esm/data-structures/linked-list/index.js.map +0 -1
  365. package/dist/esm/data-structures/linked-list/singly-linked-list.js +0 -847
  366. package/dist/esm/data-structures/linked-list/singly-linked-list.js.map +0 -1
  367. package/dist/esm/data-structures/linked-list/skip-linked-list.d.ts +0 -27
  368. package/dist/esm/data-structures/linked-list/skip-linked-list.js +0 -143
  369. package/dist/esm/data-structures/linked-list/skip-linked-list.js.map +0 -1
  370. package/dist/esm/data-structures/matrix/index.d.ts +0 -2
  371. package/dist/esm/data-structures/matrix/index.js +0 -3
  372. package/dist/esm/data-structures/matrix/index.js.map +0 -1
  373. package/dist/esm/data-structures/matrix/matrix.d.ts +0 -168
  374. package/dist/esm/data-structures/matrix/matrix.js +0 -444
  375. package/dist/esm/data-structures/matrix/matrix.js.map +0 -1
  376. package/dist/esm/data-structures/matrix/navigator.d.ts +0 -55
  377. package/dist/esm/data-structures/matrix/navigator.js +0 -114
  378. package/dist/esm/data-structures/matrix/navigator.js.map +0 -1
  379. package/dist/esm/data-structures/priority-queue/index.d.ts +0 -3
  380. package/dist/esm/data-structures/priority-queue/index.js +0 -4
  381. package/dist/esm/data-structures/priority-queue/index.js.map +0 -1
  382. package/dist/esm/data-structures/priority-queue/max-priority-queue.d.ts +0 -27
  383. package/dist/esm/data-structures/priority-queue/max-priority-queue.js +0 -34
  384. package/dist/esm/data-structures/priority-queue/max-priority-queue.js.map +0 -1
  385. package/dist/esm/data-structures/priority-queue/min-priority-queue.d.ts +0 -26
  386. package/dist/esm/data-structures/priority-queue/min-priority-queue.js +0 -21
  387. package/dist/esm/data-structures/priority-queue/min-priority-queue.js.map +0 -1
  388. package/dist/esm/data-structures/priority-queue/priority-queue.d.ts +0 -15
  389. package/dist/esm/data-structures/priority-queue/priority-queue.js +0 -17
  390. package/dist/esm/data-structures/priority-queue/priority-queue.js.map +0 -1
  391. package/dist/esm/data-structures/queue/deque.d.ts +0 -431
  392. package/dist/esm/data-structures/queue/deque.js +0 -880
  393. package/dist/esm/data-structures/queue/deque.js.map +0 -1
  394. package/dist/esm/data-structures/queue/index.d.ts +0 -2
  395. package/dist/esm/data-structures/queue/index.js +0 -3
  396. package/dist/esm/data-structures/queue/index.js.map +0 -1
  397. package/dist/esm/data-structures/queue/queue.d.ts +0 -308
  398. package/dist/esm/data-structures/queue/queue.js +0 -467
  399. package/dist/esm/data-structures/queue/queue.js.map +0 -1
  400. package/dist/esm/data-structures/stack/index.d.ts +0 -1
  401. package/dist/esm/data-structures/stack/index.js +0 -2
  402. package/dist/esm/data-structures/stack/index.js.map +0 -1
  403. package/dist/esm/data-structures/stack/stack.d.ts +0 -306
  404. package/dist/esm/data-structures/stack/stack.js +0 -398
  405. package/dist/esm/data-structures/stack/stack.js.map +0 -1
  406. package/dist/esm/data-structures/tree/index.d.ts +0 -1
  407. package/dist/esm/data-structures/tree/index.js +0 -2
  408. package/dist/esm/data-structures/tree/index.js.map +0 -1
  409. package/dist/esm/data-structures/tree/tree.d.ts +0 -62
  410. package/dist/esm/data-structures/tree/tree.js +0 -107
  411. package/dist/esm/data-structures/tree/tree.js.map +0 -1
  412. package/dist/esm/data-structures/trie/index.d.ts +0 -1
  413. package/dist/esm/data-structures/trie/index.js +0 -2
  414. package/dist/esm/data-structures/trie/index.js.map +0 -1
  415. package/dist/esm/data-structures/trie/trie.d.ts +0 -350
  416. package/dist/esm/data-structures/trie/trie.js +0 -613
  417. package/dist/esm/data-structures/trie/trie.js.map +0 -1
  418. package/dist/esm/index.d.ts +0 -5
  419. package/dist/esm/index.js +0 -6
  420. package/dist/esm/index.js.map +0 -1
  421. package/dist/esm/interfaces/binary-tree.js +0 -2
  422. package/dist/esm/interfaces/binary-tree.js.map +0 -1
  423. package/dist/esm/interfaces/doubly-linked-list.d.ts +0 -1
  424. package/dist/esm/interfaces/doubly-linked-list.js +0 -2
  425. package/dist/esm/interfaces/doubly-linked-list.js.map +0 -1
  426. package/dist/esm/interfaces/graph.d.ts +0 -21
  427. package/dist/esm/interfaces/graph.js +0 -2
  428. package/dist/esm/interfaces/graph.js.map +0 -1
  429. package/dist/esm/interfaces/heap.d.ts +0 -1
  430. package/dist/esm/interfaces/heap.js +0 -2
  431. package/dist/esm/interfaces/heap.js.map +0 -1
  432. package/dist/esm/interfaces/index.d.ts +0 -8
  433. package/dist/esm/interfaces/index.js +0 -9
  434. package/dist/esm/interfaces/index.js.map +0 -1
  435. package/dist/esm/interfaces/navigator.d.ts +0 -1
  436. package/dist/esm/interfaces/navigator.js +0 -2
  437. package/dist/esm/interfaces/navigator.js.map +0 -1
  438. package/dist/esm/interfaces/priority-queue.d.ts +0 -1
  439. package/dist/esm/interfaces/priority-queue.js +0 -2
  440. package/dist/esm/interfaces/priority-queue.js.map +0 -1
  441. package/dist/esm/interfaces/segment-tree.d.ts +0 -1
  442. package/dist/esm/interfaces/segment-tree.js +0 -2
  443. package/dist/esm/interfaces/segment-tree.js.map +0 -1
  444. package/dist/esm/interfaces/singly-linked-list.d.ts +0 -1
  445. package/dist/esm/interfaces/singly-linked-list.js +0 -2
  446. package/dist/esm/interfaces/singly-linked-list.js.map +0 -1
  447. package/dist/esm/types/common.d.ts +0 -15
  448. package/dist/esm/types/common.js +0 -2
  449. package/dist/esm/types/common.js.map +0 -1
  450. package/dist/esm/types/data-structures/base/base.d.ts +0 -13
  451. package/dist/esm/types/data-structures/base/base.js +0 -2
  452. package/dist/esm/types/data-structures/base/base.js.map +0 -1
  453. package/dist/esm/types/data-structures/base/index.d.ts +0 -1
  454. package/dist/esm/types/data-structures/base/index.js +0 -2
  455. package/dist/esm/types/data-structures/base/index.js.map +0 -1
  456. package/dist/esm/types/data-structures/binary-tree/avl-tree-counter.d.ts +0 -2
  457. package/dist/esm/types/data-structures/binary-tree/avl-tree-counter.js +0 -2
  458. package/dist/esm/types/data-structures/binary-tree/avl-tree-counter.js.map +0 -1
  459. package/dist/esm/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +0 -2
  460. package/dist/esm/types/data-structures/binary-tree/avl-tree-multi-map.js +0 -2
  461. package/dist/esm/types/data-structures/binary-tree/avl-tree-multi-map.js.map +0 -1
  462. package/dist/esm/types/data-structures/binary-tree/avl-tree.d.ts +0 -2
  463. package/dist/esm/types/data-structures/binary-tree/avl-tree.js +0 -2
  464. package/dist/esm/types/data-structures/binary-tree/avl-tree.js.map +0 -1
  465. package/dist/esm/types/data-structures/binary-tree/binary-indexed-tree.d.ts +0 -1
  466. package/dist/esm/types/data-structures/binary-tree/binary-indexed-tree.js +0 -2
  467. package/dist/esm/types/data-structures/binary-tree/binary-indexed-tree.js.map +0 -1
  468. package/dist/esm/types/data-structures/binary-tree/binary-tree.d.ts +0 -29
  469. package/dist/esm/types/data-structures/binary-tree/binary-tree.js +0 -2
  470. package/dist/esm/types/data-structures/binary-tree/binary-tree.js.map +0 -1
  471. package/dist/esm/types/data-structures/binary-tree/bst.d.ts +0 -12
  472. package/dist/esm/types/data-structures/binary-tree/bst.js +0 -2
  473. package/dist/esm/types/data-structures/binary-tree/bst.js.map +0 -1
  474. package/dist/esm/types/data-structures/binary-tree/index.d.ts +0 -9
  475. package/dist/esm/types/data-structures/binary-tree/index.js +0 -10
  476. package/dist/esm/types/data-structures/binary-tree/index.js.map +0 -1
  477. package/dist/esm/types/data-structures/binary-tree/red-black-tree.d.ts +0 -3
  478. package/dist/esm/types/data-structures/binary-tree/red-black-tree.js +0 -2
  479. package/dist/esm/types/data-structures/binary-tree/red-black-tree.js.map +0 -1
  480. package/dist/esm/types/data-structures/binary-tree/segment-tree.d.ts +0 -1
  481. package/dist/esm/types/data-structures/binary-tree/segment-tree.js +0 -2
  482. package/dist/esm/types/data-structures/binary-tree/segment-tree.js.map +0 -1
  483. package/dist/esm/types/data-structures/binary-tree/tree-counter.d.ts +0 -2
  484. package/dist/esm/types/data-structures/binary-tree/tree-counter.js +0 -2
  485. package/dist/esm/types/data-structures/binary-tree/tree-counter.js.map +0 -1
  486. package/dist/esm/types/data-structures/binary-tree/tree-multi-map.d.ts +0 -2
  487. package/dist/esm/types/data-structures/binary-tree/tree-multi-map.js +0 -2
  488. package/dist/esm/types/data-structures/binary-tree/tree-multi-map.js.map +0 -1
  489. package/dist/esm/types/data-structures/graph/abstract-graph.d.ts +0 -14
  490. package/dist/esm/types/data-structures/graph/abstract-graph.js +0 -2
  491. package/dist/esm/types/data-structures/graph/abstract-graph.js.map +0 -1
  492. package/dist/esm/types/data-structures/graph/directed-graph.d.ts +0 -1
  493. package/dist/esm/types/data-structures/graph/directed-graph.js +0 -2
  494. package/dist/esm/types/data-structures/graph/directed-graph.js.map +0 -1
  495. package/dist/esm/types/data-structures/graph/index.d.ts +0 -3
  496. package/dist/esm/types/data-structures/graph/index.js +0 -4
  497. package/dist/esm/types/data-structures/graph/index.js.map +0 -1
  498. package/dist/esm/types/data-structures/graph/map-graph.d.ts +0 -1
  499. package/dist/esm/types/data-structures/graph/map-graph.js +0 -2
  500. package/dist/esm/types/data-structures/graph/map-graph.js.map +0 -1
  501. package/dist/esm/types/data-structures/graph/undirected-graph.d.ts +0 -1
  502. package/dist/esm/types/data-structures/graph/undirected-graph.js +0 -2
  503. package/dist/esm/types/data-structures/graph/undirected-graph.js.map +0 -1
  504. package/dist/esm/types/data-structures/hash/hash-map.d.ts +0 -19
  505. package/dist/esm/types/data-structures/hash/hash-map.js +0 -2
  506. package/dist/esm/types/data-structures/hash/hash-map.js.map +0 -1
  507. package/dist/esm/types/data-structures/hash/index.d.ts +0 -2
  508. package/dist/esm/types/data-structures/hash/index.js +0 -2
  509. package/dist/esm/types/data-structures/hash/index.js.map +0 -1
  510. package/dist/esm/types/data-structures/heap/heap.d.ts +0 -5
  511. package/dist/esm/types/data-structures/heap/heap.js +0 -2
  512. package/dist/esm/types/data-structures/heap/heap.js.map +0 -1
  513. package/dist/esm/types/data-structures/heap/index.d.ts +0 -1
  514. package/dist/esm/types/data-structures/heap/index.js +0 -2
  515. package/dist/esm/types/data-structures/heap/index.js.map +0 -1
  516. package/dist/esm/types/data-structures/heap/max-heap.d.ts +0 -1
  517. package/dist/esm/types/data-structures/heap/max-heap.js +0 -2
  518. package/dist/esm/types/data-structures/heap/max-heap.js.map +0 -1
  519. package/dist/esm/types/data-structures/heap/min-heap.d.ts +0 -1
  520. package/dist/esm/types/data-structures/heap/min-heap.js +0 -2
  521. package/dist/esm/types/data-structures/heap/min-heap.js.map +0 -1
  522. package/dist/esm/types/data-structures/index.d.ts +0 -12
  523. package/dist/esm/types/data-structures/index.js +0 -13
  524. package/dist/esm/types/data-structures/index.js.map +0 -1
  525. package/dist/esm/types/data-structures/linked-list/doubly-linked-list.d.ts +0 -2
  526. package/dist/esm/types/data-structures/linked-list/doubly-linked-list.js +0 -2
  527. package/dist/esm/types/data-structures/linked-list/doubly-linked-list.js.map +0 -1
  528. package/dist/esm/types/data-structures/linked-list/index.d.ts +0 -3
  529. package/dist/esm/types/data-structures/linked-list/index.js +0 -4
  530. package/dist/esm/types/data-structures/linked-list/index.js.map +0 -1
  531. package/dist/esm/types/data-structures/linked-list/singly-linked-list.d.ts +0 -2
  532. package/dist/esm/types/data-structures/linked-list/singly-linked-list.js +0 -2
  533. package/dist/esm/types/data-structures/linked-list/singly-linked-list.js.map +0 -1
  534. package/dist/esm/types/data-structures/linked-list/skip-linked-list.d.ts +0 -4
  535. package/dist/esm/types/data-structures/linked-list/skip-linked-list.js +0 -2
  536. package/dist/esm/types/data-structures/linked-list/skip-linked-list.js.map +0 -1
  537. package/dist/esm/types/data-structures/matrix/index.d.ts +0 -2
  538. package/dist/esm/types/data-structures/matrix/index.js +0 -3
  539. package/dist/esm/types/data-structures/matrix/index.js.map +0 -1
  540. package/dist/esm/types/data-structures/matrix/matrix.d.ts +0 -7
  541. package/dist/esm/types/data-structures/matrix/matrix.js +0 -2
  542. package/dist/esm/types/data-structures/matrix/matrix.js.map +0 -1
  543. package/dist/esm/types/data-structures/matrix/navigator.d.ts +0 -14
  544. package/dist/esm/types/data-structures/matrix/navigator.js +0 -2
  545. package/dist/esm/types/data-structures/matrix/navigator.js.map +0 -1
  546. package/dist/esm/types/data-structures/priority-queue/index.d.ts +0 -3
  547. package/dist/esm/types/data-structures/priority-queue/index.js +0 -4
  548. package/dist/esm/types/data-structures/priority-queue/index.js.map +0 -1
  549. package/dist/esm/types/data-structures/priority-queue/max-priority-queue.d.ts +0 -1
  550. package/dist/esm/types/data-structures/priority-queue/max-priority-queue.js +0 -2
  551. package/dist/esm/types/data-structures/priority-queue/max-priority-queue.js.map +0 -1
  552. package/dist/esm/types/data-structures/priority-queue/min-priority-queue.d.ts +0 -1
  553. package/dist/esm/types/data-structures/priority-queue/min-priority-queue.js +0 -2
  554. package/dist/esm/types/data-structures/priority-queue/min-priority-queue.js.map +0 -1
  555. package/dist/esm/types/data-structures/priority-queue/priority-queue.d.ts +0 -2
  556. package/dist/esm/types/data-structures/priority-queue/priority-queue.js +0 -2
  557. package/dist/esm/types/data-structures/priority-queue/priority-queue.js.map +0 -1
  558. package/dist/esm/types/data-structures/queue/deque.d.ts +0 -4
  559. package/dist/esm/types/data-structures/queue/deque.js +0 -2
  560. package/dist/esm/types/data-structures/queue/deque.js.map +0 -1
  561. package/dist/esm/types/data-structures/queue/index.d.ts +0 -2
  562. package/dist/esm/types/data-structures/queue/index.js +0 -3
  563. package/dist/esm/types/data-structures/queue/index.js.map +0 -1
  564. package/dist/esm/types/data-structures/queue/queue.d.ts +0 -4
  565. package/dist/esm/types/data-structures/queue/queue.js +0 -2
  566. package/dist/esm/types/data-structures/queue/queue.js.map +0 -1
  567. package/dist/esm/types/data-structures/stack/index.d.ts +0 -1
  568. package/dist/esm/types/data-structures/stack/index.js +0 -2
  569. package/dist/esm/types/data-structures/stack/index.js.map +0 -1
  570. package/dist/esm/types/data-structures/stack/stack.d.ts +0 -2
  571. package/dist/esm/types/data-structures/stack/stack.js +0 -2
  572. package/dist/esm/types/data-structures/stack/stack.js.map +0 -1
  573. package/dist/esm/types/data-structures/tree/index.d.ts +0 -1
  574. package/dist/esm/types/data-structures/tree/index.js +0 -2
  575. package/dist/esm/types/data-structures/tree/index.js.map +0 -1
  576. package/dist/esm/types/data-structures/tree/tree.d.ts +0 -1
  577. package/dist/esm/types/data-structures/tree/tree.js +0 -2
  578. package/dist/esm/types/data-structures/tree/tree.js.map +0 -1
  579. package/dist/esm/types/data-structures/trie/index.d.ts +0 -1
  580. package/dist/esm/types/data-structures/trie/index.js +0 -2
  581. package/dist/esm/types/data-structures/trie/index.js.map +0 -1
  582. package/dist/esm/types/data-structures/trie/trie.d.ts +0 -4
  583. package/dist/esm/types/data-structures/trie/trie.js +0 -2
  584. package/dist/esm/types/data-structures/trie/trie.js.map +0 -1
  585. package/dist/esm/types/index.d.ts +0 -3
  586. package/dist/esm/types/index.js +0 -4
  587. package/dist/esm/types/index.js.map +0 -1
  588. package/dist/esm/types/utils/index.d.ts +0 -2
  589. package/dist/esm/types/utils/index.js +0 -3
  590. package/dist/esm/types/utils/index.js.map +0 -1
  591. package/dist/esm/types/utils/utils.d.ts +0 -22
  592. package/dist/esm/types/utils/utils.js +0 -2
  593. package/dist/esm/types/utils/utils.js.map +0 -1
  594. package/dist/esm/types/utils/validate-type.d.ts +0 -19
  595. package/dist/esm/types/utils/validate-type.js +0 -2
  596. package/dist/esm/types/utils/validate-type.js.map +0 -1
  597. package/dist/esm/utils/index.d.ts +0 -2
  598. package/dist/esm/utils/index.js +0 -3
  599. package/dist/esm/utils/index.js.map +0 -1
  600. package/dist/esm/utils/number.d.ts +0 -14
  601. package/dist/esm/utils/number.js +0 -21
  602. package/dist/esm/utils/number.js.map +0 -1
  603. package/dist/esm/utils/utils.d.ts +0 -209
  604. package/dist/esm/utils/utils.js +0 -325
  605. package/dist/esm/utils/utils.js.map +0 -1
  606. package/test/integration/compile.js +0 -144
  607. package/test/integration/compile.mjs +0 -135
  608. package/test/integration/compile.ts +0 -171
  609. package/tsconfig-base.json +0 -24
  610. package/tsconfig-cjs.json +0 -14
  611. package/tsconfig-esm.json +0 -14
  612. /package/dist/{cjs → types}/common/index.d.ts +0 -0
  613. /package/dist/{cjs → types}/data-structures/base/index.d.ts +0 -0
  614. /package/dist/{cjs → types}/data-structures/base/iterable-element-base.d.ts +0 -0
  615. /package/dist/{cjs → types}/data-structures/base/iterable-entry-base.d.ts +0 -0
  616. /package/dist/{cjs → types}/data-structures/base/linear-base.d.ts +0 -0
  617. /package/dist/{cjs → types}/data-structures/binary-tree/binary-indexed-tree.d.ts +0 -0
  618. /package/dist/{cjs → types}/data-structures/binary-tree/index.d.ts +0 -0
  619. /package/dist/{cjs → types}/data-structures/binary-tree/segment-tree.d.ts +0 -0
  620. /package/dist/{cjs → types}/data-structures/graph/abstract-graph.d.ts +0 -0
  621. /package/dist/{cjs → types}/data-structures/graph/directed-graph.d.ts +0 -0
  622. /package/dist/{cjs → types}/data-structures/graph/index.d.ts +0 -0
  623. /package/dist/{cjs → types}/data-structures/graph/map-graph.d.ts +0 -0
  624. /package/dist/{cjs → types}/data-structures/graph/undirected-graph.d.ts +0 -0
  625. /package/dist/{cjs → types}/data-structures/hash/hash-map.d.ts +0 -0
  626. /package/dist/{cjs → types}/data-structures/hash/index.d.ts +0 -0
  627. /package/dist/{cjs → types}/data-structures/heap/index.d.ts +0 -0
  628. /package/dist/{cjs → types}/data-structures/heap/max-heap.d.ts +0 -0
  629. /package/dist/{cjs → types}/data-structures/heap/min-heap.d.ts +0 -0
  630. /package/dist/{cjs → types}/data-structures/index.d.ts +0 -0
  631. /package/dist/{cjs → types}/data-structures/linked-list/doubly-linked-list.d.ts +0 -0
  632. /package/dist/{cjs → types}/data-structures/linked-list/index.d.ts +0 -0
  633. /package/dist/{cjs → types}/data-structures/linked-list/skip-linked-list.d.ts +0 -0
  634. /package/dist/{cjs → types}/data-structures/matrix/index.d.ts +0 -0
  635. /package/dist/{cjs → types}/data-structures/matrix/matrix.d.ts +0 -0
  636. /package/dist/{cjs → types}/data-structures/matrix/navigator.d.ts +0 -0
  637. /package/dist/{cjs → types}/data-structures/priority-queue/index.d.ts +0 -0
  638. /package/dist/{cjs → types}/data-structures/priority-queue/max-priority-queue.d.ts +0 -0
  639. /package/dist/{cjs → types}/data-structures/priority-queue/min-priority-queue.d.ts +0 -0
  640. /package/dist/{cjs → types}/data-structures/priority-queue/priority-queue.d.ts +0 -0
  641. /package/dist/{cjs → types}/data-structures/queue/deque.d.ts +0 -0
  642. /package/dist/{cjs → types}/data-structures/queue/index.d.ts +0 -0
  643. /package/dist/{cjs → types}/data-structures/queue/queue.d.ts +0 -0
  644. /package/dist/{cjs → types}/data-structures/stack/index.d.ts +0 -0
  645. /package/dist/{cjs → types}/data-structures/stack/stack.d.ts +0 -0
  646. /package/dist/{cjs → types}/data-structures/tree/index.d.ts +0 -0
  647. /package/dist/{cjs → types}/data-structures/tree/tree.d.ts +0 -0
  648. /package/dist/{cjs → types}/data-structures/trie/index.d.ts +0 -0
  649. /package/dist/{cjs → types}/data-structures/trie/trie.d.ts +0 -0
  650. /package/dist/{cjs → types}/index.d.ts +0 -0
  651. /package/dist/{cjs → types}/interfaces/doubly-linked-list.d.ts +0 -0
  652. /package/dist/{cjs → types}/interfaces/graph.d.ts +0 -0
  653. /package/dist/{cjs → types}/interfaces/heap.d.ts +0 -0
  654. /package/dist/{cjs → types}/interfaces/index.d.ts +0 -0
  655. /package/dist/{cjs → types}/interfaces/navigator.d.ts +0 -0
  656. /package/dist/{cjs → types}/interfaces/priority-queue.d.ts +0 -0
  657. /package/dist/{cjs → types}/interfaces/segment-tree.d.ts +0 -0
  658. /package/dist/{cjs → types}/interfaces/singly-linked-list.d.ts +0 -0
  659. /package/dist/{cjs → types}/types/common.d.ts +0 -0
  660. /package/dist/{cjs → types}/types/data-structures/base/base.d.ts +0 -0
  661. /package/dist/{cjs → types}/types/data-structures/base/index.d.ts +0 -0
  662. /package/dist/{cjs → types}/types/data-structures/binary-tree/avl-tree-counter.d.ts +0 -0
  663. /package/dist/{cjs → types}/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +0 -0
  664. /package/dist/{cjs → types}/types/data-structures/binary-tree/avl-tree.d.ts +0 -0
  665. /package/dist/{cjs → types}/types/data-structures/binary-tree/binary-indexed-tree.d.ts +0 -0
  666. /package/dist/{cjs → types}/types/data-structures/binary-tree/binary-tree.d.ts +0 -0
  667. /package/dist/{cjs → types}/types/data-structures/binary-tree/bst.d.ts +0 -0
  668. /package/dist/{cjs → types}/types/data-structures/binary-tree/index.d.ts +0 -0
  669. /package/dist/{cjs → types}/types/data-structures/binary-tree/red-black-tree.d.ts +0 -0
  670. /package/dist/{cjs → types}/types/data-structures/binary-tree/segment-tree.d.ts +0 -0
  671. /package/dist/{cjs → types}/types/data-structures/binary-tree/tree-counter.d.ts +0 -0
  672. /package/dist/{cjs → types}/types/data-structures/binary-tree/tree-multi-map.d.ts +0 -0
  673. /package/dist/{cjs → types}/types/data-structures/graph/abstract-graph.d.ts +0 -0
  674. /package/dist/{cjs → types}/types/data-structures/graph/directed-graph.d.ts +0 -0
  675. /package/dist/{cjs → types}/types/data-structures/graph/index.d.ts +0 -0
  676. /package/dist/{cjs → types}/types/data-structures/graph/map-graph.d.ts +0 -0
  677. /package/dist/{cjs → types}/types/data-structures/graph/undirected-graph.d.ts +0 -0
  678. /package/dist/{cjs → types}/types/data-structures/hash/hash-map.d.ts +0 -0
  679. /package/dist/{cjs → types}/types/data-structures/hash/index.d.ts +0 -0
  680. /package/dist/{cjs → types}/types/data-structures/heap/heap.d.ts +0 -0
  681. /package/dist/{cjs → types}/types/data-structures/heap/index.d.ts +0 -0
  682. /package/dist/{cjs → types}/types/data-structures/heap/max-heap.d.ts +0 -0
  683. /package/dist/{cjs → types}/types/data-structures/heap/min-heap.d.ts +0 -0
  684. /package/dist/{cjs → types}/types/data-structures/index.d.ts +0 -0
  685. /package/dist/{cjs → types}/types/data-structures/linked-list/doubly-linked-list.d.ts +0 -0
  686. /package/dist/{cjs → types}/types/data-structures/linked-list/index.d.ts +0 -0
  687. /package/dist/{cjs → types}/types/data-structures/linked-list/singly-linked-list.d.ts +0 -0
  688. /package/dist/{cjs → types}/types/data-structures/linked-list/skip-linked-list.d.ts +0 -0
  689. /package/dist/{cjs → types}/types/data-structures/matrix/index.d.ts +0 -0
  690. /package/dist/{cjs → types}/types/data-structures/matrix/matrix.d.ts +0 -0
  691. /package/dist/{cjs → types}/types/data-structures/matrix/navigator.d.ts +0 -0
  692. /package/dist/{cjs → types}/types/data-structures/priority-queue/index.d.ts +0 -0
  693. /package/dist/{cjs → types}/types/data-structures/priority-queue/max-priority-queue.d.ts +0 -0
  694. /package/dist/{cjs → types}/types/data-structures/priority-queue/min-priority-queue.d.ts +0 -0
  695. /package/dist/{cjs → types}/types/data-structures/priority-queue/priority-queue.d.ts +0 -0
  696. /package/dist/{cjs → types}/types/data-structures/queue/deque.d.ts +0 -0
  697. /package/dist/{cjs → types}/types/data-structures/queue/index.d.ts +0 -0
  698. /package/dist/{cjs → types}/types/data-structures/queue/queue.d.ts +0 -0
  699. /package/dist/{cjs → types}/types/data-structures/stack/index.d.ts +0 -0
  700. /package/dist/{cjs → types}/types/data-structures/stack/stack.d.ts +0 -0
  701. /package/dist/{cjs → types}/types/data-structures/tree/index.d.ts +0 -0
  702. /package/dist/{cjs → types}/types/data-structures/tree/tree.d.ts +0 -0
  703. /package/dist/{cjs → types}/types/data-structures/trie/index.d.ts +0 -0
  704. /package/dist/{cjs → types}/types/data-structures/trie/trie.d.ts +0 -0
  705. /package/dist/{cjs → types}/types/index.d.ts +0 -0
  706. /package/dist/{cjs → types}/types/utils/index.d.ts +0 -0
  707. /package/dist/{cjs → types}/types/utils/utils.d.ts +0 -0
  708. /package/dist/{cjs → types}/types/utils/validate-type.d.ts +0 -0
  709. /package/dist/{cjs → types}/utils/index.d.ts +0 -0
  710. /package/dist/{cjs → types}/utils/number.d.ts +0 -0
  711. /package/dist/{cjs → types}/utils/utils.d.ts +0 -0
@@ -1,901 +0,0 @@
1
- /**
2
- * data-structure-typed
3
- *
4
- * @author Pablo Zeng
5
- * @copyright Copyright (c) 2022 Pablo Zeng <zrwusa@gmail.com>
6
- * @license MIT License
7
- */
8
- import { BinaryTree, BinaryTreeNode } from './binary-tree';
9
- import { Queue } from '../queue';
10
- import { isComparable } from '../../utils';
11
- import { Range } from '../../common';
12
- /**
13
- * Represents a Node in a Binary Search Tree.
14
- *
15
- * @template K - The type of the key.
16
- * @template V - The type of the value.
17
- */
18
- export class BSTNode extends BinaryTreeNode {
19
- parent = undefined;
20
- /**
21
- * Creates an instance of BSTNode.
22
- * @remarks Time O(1), Space O(1)
23
- *
24
- * @param key - The key of the node.
25
- * @param [value] - The value associated with the key.
26
- */
27
- constructor(key, value) {
28
- super(key, value);
29
- }
30
- _left = undefined;
31
- /**
32
- * Gets the left child of the node.
33
- * @remarks Time O(1), Space O(1)
34
- *
35
- * @returns The left child.
36
- */
37
- get left() {
38
- return this._left;
39
- }
40
- /**
41
- * Sets the left child of the node and updates its parent reference.
42
- * @remarks Time O(1), Space O(1)
43
- *
44
- * @param v - The node to set as the left child.
45
- */
46
- set left(v) {
47
- if (v)
48
- v.parent = this;
49
- this._left = v;
50
- }
51
- _right = undefined;
52
- /**
53
- * Gets the right child of the node.
54
- * @remarks Time O(1), Space O(1)
55
- *
56
- * @returns The right child.
57
- */
58
- get right() {
59
- return this._right;
60
- }
61
- /**
62
- * Sets the right child of the node and updates its parent reference.
63
- * @remarks Time O(1), Space O(1)
64
- *
65
- * @param v - The node to set as the right child.
66
- */
67
- set right(v) {
68
- if (v)
69
- v.parent = this;
70
- this._right = v;
71
- }
72
- }
73
- /**
74
- * Represents a Binary Search Tree (BST).
75
- * Keys are ordered, allowing for faster search operations compared to a standard Binary Tree.
76
- * @template K - The type of the key.
77
- * @template V - The type of the value.
78
- * @template R - The type of the raw data object (if using `toEntryFn`).
79
- *
80
- * 1. Node Order: Each node's left child has a lesser value, and the right child has a greater value.
81
- * 2. Unique Keys: No duplicate keys in a standard BST.
82
- * 3. Efficient Search: Enables quick search, minimum, and maximum operations.
83
- * 4. Inorder Traversal: Yields nodes in ascending order.
84
- * 5. Logarithmic Operations: Ideal operations like insertion, deletion, and searching are O(log n) time-efficient.
85
- * 6. Balance Variability: Can become unbalanced; special types maintain balance.
86
- * 7. No Auto-Balancing: Standard BSTs don't automatically balance themselves.
87
- * @example
88
- * // Merge 3 sorted datasets
89
- * const dataset1 = new BST<number, string>([
90
- * [1, 'A'],
91
- * [7, 'G']
92
- * ]);
93
- * const dataset2 = [
94
- * [2, 'B'],
95
- * [6, 'F']
96
- * ];
97
- * const dataset3 = new BST<number, string>([
98
- * [3, 'C'],
99
- * [5, 'E'],
100
- * [4, 'D']
101
- * ]);
102
- *
103
- * // Merge datasets into a single BinarySearchTree
104
- * const merged = new BST<number, string>(dataset1);
105
- * merged.addMany(dataset2);
106
- * merged.merge(dataset3);
107
- *
108
- * // Verify merged dataset is in sorted order
109
- * console.log([...merged.values()]); // ['A', 'B', 'C', 'D', 'E', 'F', 'G']
110
- * @example
111
- * // Find elements in a range
112
- * const bst = new BST<number>([10, 5, 15, 3, 7, 12, 18]);
113
- * console.log(bst.search(new Range(5, 10))); // [5, 7, 10]
114
- * console.log(bst.rangeSearch([4, 12], node => node.key.toString())); // ['5', '7', '10', '12']
115
- * console.log(bst.search(new Range(4, 12, true, false))); // [5, 7, 10]
116
- * console.log(bst.rangeSearch([15, 20])); // [15, 18]
117
- * console.log(bst.search(new Range(15, 20, false))); // [18]
118
- * @example
119
- * // Find lowest common ancestor
120
- * const bst = new BST<number>([20, 10, 30, 5, 15, 25, 35, 3, 7, 12, 18]);
121
- *
122
- * // LCA helper function
123
- * const findLCA = (num1: number, num2: number): number | undefined => {
124
- * const path1 = bst.getPathToRoot(num1);
125
- * const path2 = bst.getPathToRoot(num2);
126
- * // Find the first common ancestor
127
- * return findFirstCommon(path1, path2);
128
- * };
129
- *
130
- * function findFirstCommon(arr1: number[], arr2: number[]): number | undefined {
131
- * for (const num of arr1) {
132
- * if (arr2.indexOf(num) !== -1) {
133
- * return num;
134
- * }
135
- * }
136
- * return undefined;
137
- * }
138
- *
139
- * // Assertions
140
- * console.log(findLCA(3, 10)); // 7
141
- * console.log(findLCA(5, 35)); // 15
142
- * console.log(findLCA(20, 30)); // 25
143
- */
144
- export class BST extends BinaryTree {
145
- /**
146
- * Creates an instance of BST.
147
- * @remarks Time O(N log N) or O(N^2) depending on `isBalanceAdd` in `addMany` and input order. Space O(N).
148
- *
149
- * @param [keysNodesEntriesOrRaws=[]] - An iterable of items to add.
150
- * @param [options] - Configuration options for the BST, including comparator.
151
- */
152
- constructor(keysNodesEntriesOrRaws = [], options) {
153
- super([], options);
154
- if (options) {
155
- const { specifyComparable, isReverse } = options;
156
- if (typeof specifyComparable === 'function')
157
- this._specifyComparable = specifyComparable;
158
- if (isReverse !== undefined)
159
- this._isReverse = isReverse;
160
- }
161
- if (keysNodesEntriesOrRaws)
162
- this.addMany(keysNodesEntriesOrRaws);
163
- }
164
- _root = undefined;
165
- /**
166
- * Gets the root node of the tree.
167
- * @remarks Time O(1)
168
- *
169
- * @returns The root node.
170
- */
171
- get root() {
172
- return this._root;
173
- }
174
- _isReverse = false;
175
- /**
176
- * Gets whether the tree's comparison logic is reversed.
177
- * @remarks Time O(1)
178
- *
179
- * @returns True if the tree is reversed (e.g., a max-heap logic).
180
- */
181
- get isReverse() {
182
- return this._isReverse;
183
- }
184
- /**
185
- * The default comparator function.
186
- * @remarks Time O(1) (or O(C) if `specifyComparable` is used, C is complexity of that function).
187
- */
188
- _comparator = (a, b) => {
189
- if (isComparable(a) && isComparable(b)) {
190
- if (a > b)
191
- return 1;
192
- if (a < b)
193
- return -1;
194
- return 0;
195
- }
196
- if (this._specifyComparable) {
197
- const va = this._specifyComparable(a);
198
- const vb = this._specifyComparable(b);
199
- if (va > vb)
200
- return 1;
201
- if (va < vb)
202
- return -1;
203
- return 0;
204
- }
205
- if (typeof a === 'object' || typeof b === 'object') {
206
- throw TypeError(`When comparing object types, a custom specifyComparable must be defined in the constructor's options.`);
207
- }
208
- return 0;
209
- };
210
- /**
211
- * Gets the comparator function used by the tree.
212
- * @remarks Time O(1)
213
- *
214
- * @returns The comparator function.
215
- */
216
- get comparator() {
217
- return this._comparator;
218
- }
219
- _specifyComparable;
220
- /**
221
- * Gets the function used to extract a comparable value from a complex key.
222
- * @remarks Time O(1)
223
- *
224
- * @returns The key-to-comparable conversion function.
225
- */
226
- get specifyComparable() {
227
- return this._specifyComparable;
228
- }
229
- /**
230
- * (Protected) Creates a new BST node.
231
- * @remarks Time O(1), Space O(1)
232
- *
233
- * @param key - The key for the new node.
234
- * @param [value] - The value for the new node (used if not in Map mode).
235
- * @returns The newly created BSTNode.
236
- */
237
- _createNode(key, value) {
238
- return new BSTNode(key, this._isMapMode ? undefined : value);
239
- }
240
- /**
241
- * Ensures the input is a node. If it's a key or entry, it searches for the node.
242
- * @remarks Time O(log N) (height of the tree), O(N) worst-case.
243
- *
244
- * @param keyNodeOrEntry - The item to resolve to a node.
245
- * @param [iterationType=this.iterationType] - The traversal method to use if searching.
246
- * @returns The resolved node, or undefined if not found.
247
- */
248
- ensureNode(keyNodeOrEntry, iterationType = this.iterationType) {
249
- return super.ensureNode(keyNodeOrEntry, iterationType) ?? undefined;
250
- }
251
- /**
252
- * Checks if the given item is a `BSTNode` instance.
253
- * @remarks Time O(1), Space O(1)
254
- *
255
- * @param keyNodeOrEntry - The item to check.
256
- * @returns True if it's a BSTNode, false otherwise.
257
- */
258
- isNode(keyNodeOrEntry) {
259
- return keyNodeOrEntry instanceof BSTNode;
260
- }
261
- /**
262
- * Checks if the given key is valid (comparable).
263
- * @remarks Time O(1)
264
- *
265
- * @param key - The key to validate.
266
- * @returns True if the key is valid, false otherwise.
267
- */
268
- isValidKey(key) {
269
- return isComparable(key, this._specifyComparable !== undefined);
270
- }
271
- /**
272
- * Performs a Depth-First Search (DFS) traversal.
273
- * @remarks Time O(N), visits every node. Space O(log N) for the call/explicit stack. O(N) worst-case.
274
- *
275
- * @template C - The type of the callback function.
276
- * @param [callback=this._DEFAULT_NODE_CALLBACK] - Function to call on each node.
277
- * @param [pattern='IN'] - The traversal order ('IN', 'PRE', 'POST').
278
- * @param [onlyOne=false] - If true, stops after the first callback.
279
- * @param [startNode=this._root] - The node to start from.
280
- * @param [iterationType=this.iterationType] - The traversal method.
281
- * @returns An array of callback results.
282
- */
283
- dfs(callback = this._DEFAULT_NODE_CALLBACK, pattern = 'IN', onlyOne = false, startNode = this._root, iterationType = this.iterationType) {
284
- return super.dfs(callback, pattern, onlyOne, startNode, iterationType);
285
- }
286
- /**
287
- * Performs a Breadth-First Search (BFS) or Level-Order traversal.
288
- * @remarks Time O(N), visits every node. Space O(N) in the worst case for the queue.
289
- *
290
- * @template C - The type of the callback function.
291
- * @param [callback=this._DEFAULT_NODE_CALLBACK] - Function to call on each node.
292
- * @param [startNode=this._root] - The node to start from.
293
- * @param [iterationType=this.iterationType] - The traversal method.
294
- * @returns An array of callback results.
295
- */
296
- bfs(callback = this._DEFAULT_NODE_CALLBACK, startNode = this._root, iterationType = this.iterationType) {
297
- return super.bfs(callback, startNode, iterationType, false);
298
- }
299
- /**
300
- * Returns a 2D array of nodes, grouped by level.
301
- * @remarks Time O(N), visits every node. Space O(N) for the result array and the queue/stack.
302
- *
303
- * @template C - The type of the callback function.
304
- * @param [callback=this._DEFAULT_NODE_CALLBACK] - Function to call on each node.
305
- * @param [startNode=this._root] - The node to start from.
306
- * @param [iterationType=this.iterationType] - The traversal method.
307
- * @returns A 2D array of callback results.
308
- */
309
- listLevels(callback = this._DEFAULT_NODE_CALLBACK, startNode = this._root, iterationType = this.iterationType) {
310
- return super.listLevels(callback, startNode, iterationType, false);
311
- }
312
- /**
313
- * Gets the first node matching a predicate.
314
- * @remarks Time O(log N) if searching by key, O(N) if searching by predicate. Space O(log N) or O(N).
315
- *
316
- * @param keyNodeEntryOrPredicate - The key, node, entry, or predicate function to search for.
317
- * @param [startNode=this._root] - The node to start the search from.
318
- * @param [iterationType=this.iterationType] - The traversal method.
319
- * @returns The first matching node, or undefined if not found.
320
- */
321
- getNode(keyNodeEntryOrPredicate, startNode = this._root, iterationType = this.iterationType) {
322
- return this.getNodes(keyNodeEntryOrPredicate, true, startNode, iterationType)[0] ?? undefined;
323
- }
324
- /**
325
- * Searches the tree for nodes matching a predicate, key, or range.
326
- * @remarks This is an optimized search for a BST. If searching by key or range, it prunes branches.
327
- * Time O(H + M) for key/range search (H=height, M=matches). O(N) for predicate search.
328
- * Space O(log N) for the stack.
329
- *
330
- * @template C - The type of the callback function.
331
- * @param keyNodeEntryOrPredicate - The key, node, entry, predicate, or range to search for.
332
- * @param [onlyOne=false] - If true, stops after finding the first match.
333
- * @param [callback=this._DEFAULT_NODE_CALLBACK] - A function to call on matching nodes.
334
- * @param [startNode=this._root] - The node to start the search from.
335
- * @param [iterationType=this.iterationType] - Whether to use 'RECURSIVE' or 'ITERATIVE' search.
336
- * @returns An array of results from the callback function for each matching node.
337
- */
338
- search(keyNodeEntryOrPredicate, onlyOne = false, callback = this._DEFAULT_NODE_CALLBACK, startNode = this._root, iterationType = this.iterationType) {
339
- if (keyNodeEntryOrPredicate === undefined)
340
- return [];
341
- if (keyNodeEntryOrPredicate === null)
342
- return [];
343
- startNode = this.ensureNode(startNode);
344
- if (!startNode)
345
- return [];
346
- let predicate;
347
- const isRange = this.isRange(keyNodeEntryOrPredicate);
348
- if (isRange) {
349
- predicate = node => {
350
- if (!node)
351
- return false;
352
- return keyNodeEntryOrPredicate.isInRange(node.key, this._comparator);
353
- };
354
- }
355
- else {
356
- predicate = this._ensurePredicate(keyNodeEntryOrPredicate);
357
- }
358
- // Optimization: Pruning logic
359
- const shouldVisitLeft = (cur) => {
360
- if (!cur)
361
- return false;
362
- if (!this.isRealNode(cur.left))
363
- return false;
364
- if (isRange) {
365
- // Range search: Only go left if the current key is >= the lower bound
366
- const range = keyNodeEntryOrPredicate;
367
- const leftS = this.isReverse ? range.high : range.low;
368
- const leftI = this.isReverse ? range.includeHigh : range.includeLow;
369
- return (leftI && this._compare(cur.key, leftS) >= 0) || (!leftI && this._compare(cur.key, leftS) > 0);
370
- }
371
- if (!isRange && !this._isPredicate(keyNodeEntryOrPredicate)) {
372
- // Key search: Only go left if current key > target key
373
- const benchmarkKey = this._extractKey(keyNodeEntryOrPredicate);
374
- return benchmarkKey !== null && benchmarkKey !== undefined && this._compare(cur.key, benchmarkKey) > 0;
375
- }
376
- return true; // Predicate search: must visit all
377
- };
378
- const shouldVisitRight = (cur) => {
379
- if (!cur)
380
- return false;
381
- if (!this.isRealNode(cur.right))
382
- return false;
383
- if (isRange) {
384
- // Range search: Only go right if current key <= upper bound
385
- const range = keyNodeEntryOrPredicate;
386
- const rightS = this.isReverse ? range.low : range.high;
387
- const rightI = this.isReverse ? range.includeLow : range.includeHigh;
388
- return (rightI && this._compare(cur.key, rightS) <= 0) || (!rightI && this._compare(cur.key, rightS) < 0);
389
- }
390
- if (!isRange && !this._isPredicate(keyNodeEntryOrPredicate)) {
391
- // Key search: Only go right if current key < target key
392
- const benchmarkKey = this._extractKey(keyNodeEntryOrPredicate);
393
- return benchmarkKey !== null && benchmarkKey !== undefined && this._compare(cur.key, benchmarkKey) < 0;
394
- }
395
- return true; // Predicate search: must visit all
396
- };
397
- return super._dfs(callback, 'IN', // In-order is efficient for range/key search
398
- onlyOne, startNode, iterationType, false, shouldVisitLeft, shouldVisitRight, () => true, // shouldVisitRoot (always visit)
399
- // shouldVisitRoot (always visit)
400
- cur => !!cur && predicate(cur) // shouldProcessRoot (only process if predicate matches)
401
- );
402
- }
403
- /**
404
- * Performs an optimized search for nodes within a given key range.
405
- * @remarks Time O(H + M), where H is tree height and M is the number of matches.
406
- *
407
- * @template C - The type of the callback function.
408
- * @param range - A `Range` object or a `[low, high]` tuple.
409
- * @param [callback=this._DEFAULT_NODE_CALLBACK] - A function to call on matching nodes.
410
- * @param [startNode=this._root] - The node to start the search from.
411
- * @param [iterationType=this.iterationType] - The traversal method.
412
- * @returns An array of callback results.
413
- */
414
- rangeSearch(range, callback = this._DEFAULT_NODE_CALLBACK, startNode = this._root, iterationType = this.iterationType) {
415
- const searchRange = range instanceof Range ? range : new Range(range[0], range[1]);
416
- return this.search(searchRange, false, callback, startNode, iterationType);
417
- }
418
- /**
419
- * Adds a new node to the BST based on key comparison.
420
- * @remarks Time O(log N), where H is tree height. O(N) worst-case (unbalanced tree), O(log N) average. Space O(1).
421
- *
422
- * @param keyNodeOrEntry - The key, node, or entry to add.
423
- * @param [value] - The value, if providing just a key.
424
- * @returns True if the addition was successful, false otherwise.
425
- */
426
- add(keyNodeOrEntry, value) {
427
- const [newNode, newValue] = this._keyValueNodeOrEntryToNodeAndValue(keyNodeOrEntry, value);
428
- if (newNode === undefined)
429
- return false;
430
- if (this._root === undefined) {
431
- this._setRoot(newNode);
432
- if (this._isMapMode)
433
- this._setValue(newNode?.key, newValue);
434
- this._size++;
435
- return true;
436
- }
437
- let current = this._root;
438
- while (current !== undefined) {
439
- if (this._compare(current.key, newNode.key) === 0) {
440
- // Key exists, replace node
441
- this._replaceNode(current, newNode);
442
- if (this._isMapMode)
443
- this._setValue(current.key, newValue);
444
- return true;
445
- }
446
- else if (this._compare(current.key, newNode.key) > 0) {
447
- // Go left
448
- if (current.left === undefined) {
449
- current.left = newNode;
450
- if (this._isMapMode)
451
- this._setValue(newNode?.key, newValue);
452
- this._size++;
453
- return true;
454
- }
455
- if (current.left !== null)
456
- current = current.left;
457
- }
458
- else {
459
- // Go right
460
- if (current.right === undefined) {
461
- current.right = newNode;
462
- if (this._isMapMode)
463
- this._setValue(newNode?.key, newValue);
464
- this._size++;
465
- return true;
466
- }
467
- if (current.right !== null)
468
- current = current.right;
469
- }
470
- }
471
- return false;
472
- }
473
- /**
474
- * Adds multiple items to the tree.
475
- * @remarks If `isBalanceAdd` is true, sorts the input and builds a balanced tree. Time O(N log N) (due to sort and balanced add).
476
- * If false, adds items one by one. Time O(N * H), which is O(N^2) worst-case.
477
- * Space O(N) for sorting and recursion/iteration stack.
478
- *
479
- * @param keysNodesEntriesOrRaws - An iterable of items to add.
480
- * @param [values] - An optional parallel iterable of values.
481
- * @param [isBalanceAdd=true] - If true, builds a balanced tree from the items.
482
- * @param [iterationType=this.iterationType] - The traversal method for balanced add (recursive or iterative).
483
- * @returns An array of booleans indicating the success of each individual `add` operation.
484
- */
485
- addMany(keysNodesEntriesOrRaws, values, isBalanceAdd = true, iterationType = this.iterationType) {
486
- const inserted = [];
487
- const valuesIterator = values?.[Symbol.iterator]();
488
- if (!isBalanceAdd) {
489
- // Standard O(N*H) insertion
490
- for (let kve of keysNodesEntriesOrRaws) {
491
- const val = valuesIterator?.next().value;
492
- if (this.isRaw(kve))
493
- kve = this._toEntryFn(kve);
494
- inserted.push(this.add(kve, val));
495
- }
496
- return inserted;
497
- }
498
- // Balanced O(N log N) insertion
499
- const realBTNExemplars = [];
500
- let i = 0;
501
- for (const kve of keysNodesEntriesOrRaws) {
502
- realBTNExemplars.push({ key: kve, value: valuesIterator?.next().value, orgIndex: i++ });
503
- }
504
- // Sort items by key
505
- const sorted = realBTNExemplars.sort(({ key: a }, { key: b }) => {
506
- let keyA, keyB;
507
- if (this.isRaw(a))
508
- keyA = this._toEntryFn(a)[0];
509
- else if (this.isEntry(a))
510
- keyA = a[0];
511
- else if (this.isRealNode(a))
512
- keyA = a.key;
513
- else
514
- keyA = a;
515
- if (this.isRaw(b))
516
- keyB = this._toEntryFn(b)[0];
517
- else if (this.isEntry(b))
518
- keyB = b[0];
519
- else if (this.isRealNode(b))
520
- keyB = b.key;
521
- else
522
- keyB = b;
523
- if (keyA != null && keyB != null)
524
- return this._compare(keyA, keyB);
525
- return 0;
526
- });
527
- // Recursive balanced build
528
- const _dfs = (arr) => {
529
- if (arr.length === 0)
530
- return;
531
- const mid = Math.floor((arr.length - 1) / 2);
532
- const { key, value, orgIndex } = arr[mid];
533
- if (this.isRaw(key)) {
534
- const entry = this._toEntryFn(key);
535
- inserted[orgIndex] = this.add(entry);
536
- }
537
- else {
538
- inserted[orgIndex] = this.add(key, value);
539
- }
540
- _dfs(arr.slice(0, mid));
541
- _dfs(arr.slice(mid + 1));
542
- };
543
- // Iterative balanced build
544
- const _iterate = () => {
545
- const n = sorted.length;
546
- const stack = [[0, n - 1]];
547
- while (stack.length > 0) {
548
- const popped = stack.pop();
549
- if (!popped)
550
- continue;
551
- const [l, r] = popped;
552
- if (l > r)
553
- continue;
554
- const m = l + Math.floor((r - l) / 2);
555
- const { key, value, orgIndex } = sorted[m];
556
- if (this.isRaw(key)) {
557
- const entry = this._toEntryFn(key);
558
- inserted[orgIndex] = this.add(entry);
559
- }
560
- else {
561
- inserted[orgIndex] = this.add(key, value);
562
- }
563
- stack.push([m + 1, r]);
564
- stack.push([l, m - 1]);
565
- }
566
- };
567
- if (iterationType === 'RECURSIVE')
568
- _dfs(sorted);
569
- else
570
- _iterate();
571
- return inserted;
572
- }
573
- /**
574
- * Traverses the tree and returns nodes that are lesser or greater than a target node.
575
- * @remarks Time O(N), as it performs a full traversal. Space O(log N) or O(N).
576
- *
577
- * @template C - The type of the callback function.
578
- * @param [callback=this._DEFAULT_NODE_CALLBACK] - Function to call on matching nodes.
579
- * @param [lesserOrGreater=-1] - -1 for lesser, 1 for greater, 0 for equal.
580
- * @param [targetNode=this._root] - The node to compare against.
581
- * @param [iterationType=this.iterationType] - The traversal method.
582
- * @returns An array of callback results.
583
- */
584
- lesserOrGreaterTraverse(callback = this._DEFAULT_NODE_CALLBACK, lesserOrGreater = -1, targetNode = this._root, iterationType = this.iterationType) {
585
- const targetNodeEnsured = this.ensureNode(targetNode);
586
- const ans = [];
587
- if (!this._root || !targetNodeEnsured)
588
- return ans;
589
- const targetKey = targetNodeEnsured.key;
590
- if (iterationType === 'RECURSIVE') {
591
- const dfs = (cur) => {
592
- const compared = this._compare(cur.key, targetKey);
593
- if (Math.sign(compared) == lesserOrGreater)
594
- ans.push(callback(cur));
595
- if (this.isRealNode(cur.left))
596
- dfs(cur.left);
597
- if (this.isRealNode(cur.right))
598
- dfs(cur.right);
599
- };
600
- dfs(this._root);
601
- return ans;
602
- }
603
- else {
604
- const queue = new Queue([this._root]);
605
- while (queue.length > 0) {
606
- const cur = queue.shift();
607
- if (this.isRealNode(cur)) {
608
- const compared = this._compare(cur.key, targetKey);
609
- if (Math.sign(compared) == lesserOrGreater)
610
- ans.push(callback(cur));
611
- if (this.isRealNode(cur.left))
612
- queue.push(cur.left);
613
- if (this.isRealNode(cur.right))
614
- queue.push(cur.right);
615
- }
616
- }
617
- return ans;
618
- }
619
- }
620
- /**
621
- * Rebuilds the tree to be perfectly balanced.
622
- * @remarks Time O(N) (O(N) for DFS, O(N) for sorted build). Space O(N) for node array and recursion stack.
623
- *
624
- * @param [iterationType=this.iterationType] - The traversal method for the initial node export.
625
- * @returns True if successful, false if the tree was empty.
626
- */
627
- perfectlyBalance(iterationType = this.iterationType) {
628
- const nodes = this.dfs(node => node, 'IN', false, this._root, iterationType);
629
- const n = nodes.length;
630
- this._clearNodes();
631
- if (n === 0)
632
- return false;
633
- // Build balanced tree from sorted array
634
- const build = (l, r, parent) => {
635
- if (l > r)
636
- return undefined;
637
- const m = l + ((r - l) >> 1);
638
- const root = nodes[m];
639
- const leftChild = build(l, m - 1, root);
640
- const rightChild = build(m + 1, r, root);
641
- root.left = leftChild;
642
- root.right = rightChild;
643
- root.parent = parent;
644
- return root;
645
- };
646
- const newRoot = build(0, n - 1, undefined);
647
- this._setRoot(newRoot);
648
- this._size = n;
649
- return true;
650
- }
651
- /**
652
- * Checks if the tree meets the AVL balance condition (height difference <= 1).
653
- * @remarks Time O(N), as it must visit every node to compute height. Space O(log N) for recursion or O(N) for iterative map.
654
- *
655
- * @param [iterationType=this.iterationType] - The traversal method.
656
- * @returns True if the tree is AVL balanced, false otherwise.
657
- */
658
- isAVLBalanced(iterationType = this.iterationType) {
659
- if (!this._root)
660
- return true;
661
- let balanced = true;
662
- if (iterationType === 'RECURSIVE') {
663
- // Recursive height check
664
- const _height = (cur) => {
665
- if (!cur)
666
- return 0;
667
- const leftHeight = _height(cur.left);
668
- const rightHeight = _height(cur.right);
669
- if (Math.abs(leftHeight - rightHeight) > 1)
670
- balanced = false;
671
- return Math.max(leftHeight, rightHeight) + 1;
672
- };
673
- _height(this._root);
674
- }
675
- else {
676
- // Iterative post-order height check
677
- const stack = [];
678
- let node = this._root, last = undefined;
679
- const depths = new Map();
680
- while (stack.length > 0 || node) {
681
- if (node) {
682
- stack.push(node);
683
- if (node.left !== null)
684
- node = node.left;
685
- }
686
- else {
687
- node = stack[stack.length - 1];
688
- if (!node.right || last === node.right) {
689
- node = stack.pop();
690
- if (node) {
691
- const left = node.left ? depths.get(node.left) : -1;
692
- const right = node.right ? depths.get(node.right) : -1;
693
- if (Math.abs(left - right) > 1)
694
- return false;
695
- depths.set(node, 1 + Math.max(left, right));
696
- last = node;
697
- node = undefined;
698
- }
699
- }
700
- else
701
- node = node.right;
702
- }
703
- }
704
- }
705
- return balanced;
706
- }
707
- /**
708
- * Creates a new BST by mapping each [key, value] pair to a new entry.
709
- * @remarks Time O(N * H), where N is nodes in this tree, and H is height of the new tree during insertion.
710
- * Space O(N) for the new tree.
711
- *
712
- * @template MK - New key type.
713
- * @template MV - New value type.
714
- * @template MR - New raw type.
715
- * @param callback - A function to map each [key, value] pair.
716
- * @param [options] - Options for the new BST.
717
- * @param [thisArg] - `this` context for the callback.
718
- * @returns A new, mapped BST.
719
- */
720
- map(callback, options, thisArg) {
721
- const out = this._createLike([], options);
722
- let index = 0;
723
- // Iterates in-order
724
- for (const [key, value] of this) {
725
- out.add(callback.call(thisArg, key, value, index++, this));
726
- }
727
- return out;
728
- }
729
- /**
730
- * Deletes the first node found that satisfies the predicate.
731
- * @remarks Performs an in-order traversal. Time O(N) worst-case (O(log N) to find + O(log N) to delete). Space O(log N) for stack.
732
- *
733
- * @param predicate - A function to test each [key, value] pair.
734
- * @returns True if a node was deleted, false otherwise.
735
- */
736
- deleteWhere(predicate) {
737
- const stack = [];
738
- let cur = this._root;
739
- let index = 0;
740
- // In-order traversal to find the node
741
- while (stack.length > 0 || cur !== undefined) {
742
- while (cur !== undefined && cur !== null) {
743
- stack.push(cur);
744
- cur = cur.left;
745
- }
746
- const node = stack.pop();
747
- if (!node)
748
- break;
749
- const key = node.key;
750
- const val = node.value;
751
- if (predicate(key, val, index++, this)) {
752
- return this._deleteByKey(key); // Found, now delete
753
- }
754
- cur = node.right;
755
- }
756
- return false;
757
- }
758
- /**
759
- * (Protected) Creates a new, empty instance of the same BST constructor.
760
- * @remarks Time O(1)
761
- *
762
- * @template TK, TV, TR - Generic types for the new instance.
763
- * @param [options] - Options for the new BST.
764
- * @returns A new, empty BST.
765
- */
766
- _createInstance(options) {
767
- const Ctor = this.constructor;
768
- return new Ctor([], { ...this._snapshotOptions(), ...(options ?? {}) });
769
- }
770
- /**
771
- * (Protected) Creates a new instance of the same BST constructor, potentially with different generic types.
772
- * @remarks Time O(N log N) or O(N^2) (from constructor) due to processing the iterable.
773
- *
774
- * @template TK, TV, TR - Generic types for the new instance.
775
- * @param [iter=[]] - An iterable to populate the new BST.
776
- * @param [options] - Options for the new BST.
777
- * @returns A new BST.
778
- */
779
- _createLike(iter = [], options) {
780
- const Ctor = this.constructor;
781
- return new Ctor(iter, { ...this._snapshotOptions(), ...(options ?? {}) });
782
- }
783
- /**
784
- * (Protected) Snapshots the current BST's configuration options.
785
- * @remarks Time O(1)
786
- *
787
- * @template TK, TV, TR - Generic types for the options.
788
- * @returns The options object.
789
- */
790
- _snapshotOptions() {
791
- return {
792
- ...super._snapshotOptions(),
793
- specifyComparable: this.specifyComparable,
794
- isReverse: this.isReverse
795
- };
796
- }
797
- /**
798
- * (Protected) Converts a key, node, or entry into a standardized [node, value] tuple.
799
- * @remarks Time O(1)
800
- *
801
- * @param keyNodeOrEntry - The input item.
802
- * @param [value] - An optional value (used if input is just a key).
803
- * @returns A tuple of [node, value].
804
- */
805
- _keyValueNodeOrEntryToNodeAndValue(keyNodeOrEntry, value) {
806
- const [node, entryValue] = super._keyValueNodeOrEntryToNodeAndValue(keyNodeOrEntry, value);
807
- if (node === null)
808
- return [undefined, undefined]; // BST handles null differently (as undefined)
809
- return [node, value ?? entryValue];
810
- }
811
- /**
812
- * (Protected) Sets the root node and clears its parent reference.
813
- * @remarks Time O(1)
814
- *
815
- * @param v - The node to set as root.
816
- */
817
- _setRoot(v) {
818
- if (v)
819
- v.parent = undefined;
820
- this._root = v;
821
- }
822
- /**
823
- * (Protected) Compares two keys using the tree's comparator and reverse setting.
824
- * @remarks Time O(1) (or O(C) if `specifyComparable` is used).
825
- *
826
- * @param a - The first key.
827
- * @param b - The second key.
828
- * @returns A number (1, -1, or 0) representing the comparison.
829
- */
830
- _compare(a, b) {
831
- return this._isReverse ? -this._comparator(a, b) : this._comparator(a, b);
832
- }
833
- /**
834
- * (Private) Deletes a node by its key.
835
- * @remarks Standard BST deletion algorithm. Time O(log N), O(N) worst-case. Space O(1).
836
- *
837
- * @param key - The key of the node to delete.
838
- * @returns True if the node was found and deleted, false otherwise.
839
- */
840
- _deleteByKey(key) {
841
- let node = this._root;
842
- // 1. Find the node
843
- while (node) {
844
- const cmp = this._compare(node.key, key);
845
- if (cmp === 0)
846
- break;
847
- node = cmp > 0 ? node.left : node.right;
848
- }
849
- if (!node)
850
- return false; // Not found
851
- // Helper to replace node `u` with node `v`
852
- const transplant = (u, v) => {
853
- const p = u?.parent;
854
- if (!p) {
855
- this._setRoot(v);
856
- }
857
- else if (p.left === u) {
858
- p.left = v;
859
- }
860
- else {
861
- p.right = v;
862
- }
863
- if (v)
864
- v.parent = p;
865
- };
866
- // Helper to find the minimum node in a subtree
867
- const minNode = (x) => {
868
- if (!x)
869
- return undefined;
870
- while (x.left !== undefined && x.left !== null)
871
- x = x.left;
872
- return x;
873
- };
874
- // 2. Perform deletion
875
- if (node.left === undefined) {
876
- // Case 1: No left child
877
- transplant(node, node.right);
878
- }
879
- else if (node.right === undefined) {
880
- // Case 2: No right child
881
- transplant(node, node.left);
882
- }
883
- else {
884
- // Case 3: Two children
885
- const succ = minNode(node.right); // Find successor
886
- if (succ.parent !== node) {
887
- transplant(succ, succ.right);
888
- succ.right = node.right;
889
- if (succ.right)
890
- succ.right.parent = succ;
891
- }
892
- transplant(node, succ);
893
- succ.left = node.left;
894
- if (succ.left)
895
- succ.left.parent = succ;
896
- }
897
- this._size = Math.max(0, (this._size ?? 0) - 1);
898
- return true;
899
- }
900
- }
901
- //# sourceMappingURL=bst.js.map