data-structure-typed 2.0.5 → 2.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (785) hide show
  1. package/CHANGELOG.md +5 -1
  2. package/COMMANDS.md +27 -0
  3. package/README.md +5 -34
  4. package/benchmark/report.html +13 -77
  5. package/benchmark/report.json +152 -184
  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/index.cjs +13091 -0
  11. package/dist/index.cjs.map +1 -0
  12. package/dist/index.js +13013 -0
  13. package/dist/index.js.map +1 -0
  14. package/dist/types/data-structures/base/iterable-element-base.d.ts +219 -0
  15. package/dist/types/data-structures/base/iterable-entry-base.d.ts +144 -0
  16. package/dist/types/data-structures/base/linear-base.d.ts +335 -0
  17. package/dist/types/data-structures/binary-tree/avl-tree-counter.d.ts +182 -0
  18. package/dist/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +135 -0
  19. package/dist/types/data-structures/binary-tree/avl-tree.d.ts +291 -0
  20. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +754 -0
  21. package/dist/types/data-structures/binary-tree/bst.d.ts +413 -0
  22. package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +208 -0
  23. package/dist/types/data-structures/binary-tree/tree-counter.d.ts +190 -0
  24. package/dist/{esm → types}/data-structures/binary-tree/tree-multi-map.d.ts +72 -69
  25. package/dist/types/data-structures/graph/abstract-graph.d.ts +340 -0
  26. package/dist/types/data-structures/graph/directed-graph.d.ts +207 -0
  27. package/dist/types/data-structures/graph/map-graph.d.ts +78 -0
  28. package/dist/types/data-structures/graph/undirected-graph.d.ts +188 -0
  29. package/dist/types/data-structures/hash/hash-map.d.ts +345 -0
  30. package/dist/types/data-structures/heap/heap.d.ts +503 -0
  31. package/dist/types/data-structures/heap/max-heap.d.ts +32 -0
  32. package/dist/types/data-structures/heap/min-heap.d.ts +33 -0
  33. package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +769 -0
  34. package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +451 -0
  35. package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +27 -0
  36. package/dist/types/data-structures/priority-queue/max-priority-queue.d.ts +27 -0
  37. package/dist/types/data-structures/priority-queue/min-priority-queue.d.ts +26 -0
  38. package/dist/types/data-structures/priority-queue/priority-queue.d.ts +15 -0
  39. package/dist/types/data-structures/queue/deque.d.ts +431 -0
  40. package/dist/types/data-structures/queue/queue.d.ts +308 -0
  41. package/dist/{cjs → types}/data-structures/stack/stack.d.ts +124 -102
  42. package/dist/types/data-structures/trie/trie.d.ts +350 -0
  43. package/dist/types/interfaces/binary-tree.d.ts +59 -0
  44. package/dist/types/interfaces/graph.d.ts +21 -0
  45. package/dist/{cjs → types}/types/data-structures/base/base.d.ts +1 -1
  46. package/dist/{esm → types}/types/data-structures/graph/abstract-graph.d.ts +4 -0
  47. package/dist/{cjs → types}/types/utils/utils.d.ts +1 -0
  48. package/dist/{esm → types}/utils/utils.d.ts +1 -1
  49. package/dist/umd/data-structure-typed.js +4693 -6484
  50. package/dist/umd/data-structure-typed.js.map +1 -0
  51. package/dist/umd/data-structure-typed.min.js +8 -6
  52. package/dist/umd/data-structure-typed.min.js.map +1 -1
  53. package/jest.integration.config.js +3 -0
  54. package/package.json +13 -12
  55. package/src/data-structures/base/iterable-element-base.ts +238 -115
  56. package/src/data-structures/base/iterable-entry-base.ts +96 -120
  57. package/src/data-structures/base/linear-base.ts +271 -277
  58. package/src/data-structures/binary-tree/avl-tree-counter.ts +196 -217
  59. package/src/data-structures/binary-tree/avl-tree-multi-map.ts +188 -102
  60. package/src/data-structures/binary-tree/avl-tree.ts +237 -206
  61. package/src/data-structures/binary-tree/binary-tree.ts +665 -896
  62. package/src/data-structures/binary-tree/bst.ts +565 -572
  63. package/src/data-structures/binary-tree/red-black-tree.ts +157 -223
  64. package/src/data-structures/binary-tree/tree-counter.ts +195 -219
  65. package/src/data-structures/binary-tree/tree-multi-map.ts +127 -98
  66. package/src/data-structures/graph/abstract-graph.ts +339 -264
  67. package/src/data-structures/graph/directed-graph.ts +146 -236
  68. package/src/data-structures/graph/map-graph.ts +63 -60
  69. package/src/data-structures/graph/undirected-graph.ts +129 -152
  70. package/src/data-structures/hash/hash-map.ts +274 -496
  71. package/src/data-structures/heap/heap.ts +389 -402
  72. package/src/data-structures/heap/max-heap.ts +12 -76
  73. package/src/data-structures/heap/min-heap.ts +13 -76
  74. package/src/data-structures/linked-list/doubly-linked-list.ts +426 -530
  75. package/src/data-structures/linked-list/singly-linked-list.ts +495 -517
  76. package/src/data-structures/linked-list/skip-linked-list.ts +1 -108
  77. package/src/data-structures/priority-queue/max-priority-queue.ts +12 -87
  78. package/src/data-structures/priority-queue/min-priority-queue.ts +11 -88
  79. package/src/data-structures/priority-queue/priority-queue.ts +3 -92
  80. package/src/data-structures/queue/deque.ts +381 -357
  81. package/src/data-structures/queue/queue.ts +310 -264
  82. package/src/data-structures/stack/stack.ts +217 -131
  83. package/src/data-structures/trie/trie.ts +240 -175
  84. package/src/interfaces/binary-tree.ts +240 -6
  85. package/src/interfaces/graph.ts +37 -0
  86. package/src/types/data-structures/base/base.ts +5 -5
  87. package/src/types/data-structures/graph/abstract-graph.ts +5 -0
  88. package/src/types/utils/utils.ts +2 -0
  89. package/src/utils/utils.ts +9 -14
  90. package/test/integration/all-in-one.test.ts +1 -1
  91. package/test/integration/index.html +1 -1
  92. package/test/performance/benchmark-runner.ts +528 -0
  93. package/test/performance/data-structures/comparison/comparison.test.ts +27 -57
  94. package/test/performance/reportor.mjs +43 -43
  95. package/test/performance/runner-config.json +39 -0
  96. package/test/performance/single-suite-runner.ts +69 -0
  97. package/test/unit/data-structures/binary-tree/avl-tree-counter.test.ts +3 -3
  98. package/test/unit/data-structures/binary-tree/avl-tree-multi-map.test.ts +5 -5
  99. package/test/unit/data-structures/binary-tree/avl-tree.test.ts +4 -4
  100. package/test/unit/data-structures/binary-tree/binary-tree.test.ts +350 -90
  101. package/test/unit/data-structures/binary-tree/bst.test.ts +12 -9
  102. package/test/unit/data-structures/binary-tree/red-black-tree.test.ts +2 -2
  103. package/test/unit/data-structures/binary-tree/tree-counter.test.ts +25 -24
  104. package/test/unit/data-structures/binary-tree/tree-multi-map.test.ts +112 -4
  105. package/test/unit/data-structures/graph/abstract-graph.test.ts +0 -4
  106. package/test/unit/data-structures/graph/directed-graph.test.ts +1 -1
  107. package/test/unit/data-structures/heap/heap.test.ts +14 -21
  108. package/test/unit/data-structures/heap/max-heap.test.ts +5 -9
  109. package/test/unit/data-structures/heap/min-heap.test.ts +1 -4
  110. package/test/unit/data-structures/linked-list/doubly-linked-list.test.ts +14 -14
  111. package/test/unit/data-structures/linked-list/singly-linked-list.test.ts +0 -7
  112. package/test/unit/data-structures/priority-queue/max-priority-queue.test.ts +8 -11
  113. package/test/unit/data-structures/priority-queue/min-priority-queue.test.ts +1 -4
  114. package/test/unit/data-structures/priority-queue/priority-queue.test.ts +1 -4
  115. package/test/unit/data-structures/queue/queue.test.ts +4 -5
  116. package/test/unit/utils/utils.test.ts +0 -1
  117. package/tsconfig-base.json +20 -20
  118. package/tsconfig-types.json +17 -0
  119. package/tsconfig.test.json +8 -0
  120. package/tsup.config.js +11 -22
  121. package/tsup.node.config.ts +37 -0
  122. package/dist/cjs/common/index.js +0 -29
  123. package/dist/cjs/common/index.js.map +0 -1
  124. package/dist/cjs/data-structures/base/index.js +0 -19
  125. package/dist/cjs/data-structures/base/index.js.map +0 -1
  126. package/dist/cjs/data-structures/base/iterable-element-base.d.ts +0 -116
  127. package/dist/cjs/data-structures/base/iterable-element-base.js +0 -202
  128. package/dist/cjs/data-structures/base/iterable-element-base.js.map +0 -1
  129. package/dist/cjs/data-structures/base/iterable-entry-base.d.ts +0 -168
  130. package/dist/cjs/data-structures/base/iterable-entry-base.js +0 -241
  131. package/dist/cjs/data-structures/base/iterable-entry-base.js.map +0 -1
  132. package/dist/cjs/data-structures/base/linear-base.d.ts +0 -277
  133. package/dist/cjs/data-structures/base/linear-base.js +0 -553
  134. package/dist/cjs/data-structures/base/linear-base.js.map +0 -1
  135. package/dist/cjs/data-structures/binary-tree/avl-tree-counter.d.ts +0 -214
  136. package/dist/cjs/data-structures/binary-tree/avl-tree-counter.js +0 -409
  137. package/dist/cjs/data-structures/binary-tree/avl-tree-counter.js.map +0 -1
  138. package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.d.ts +0 -104
  139. package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.js +0 -203
  140. package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.js.map +0 -1
  141. package/dist/cjs/data-structures/binary-tree/avl-tree.d.ts +0 -302
  142. package/dist/cjs/data-structures/binary-tree/avl-tree.js +0 -599
  143. package/dist/cjs/data-structures/binary-tree/avl-tree.js.map +0 -1
  144. package/dist/cjs/data-structures/binary-tree/binary-indexed-tree.js +0 -295
  145. package/dist/cjs/data-structures/binary-tree/binary-indexed-tree.js.map +0 -1
  146. package/dist/cjs/data-structures/binary-tree/binary-tree.d.ts +0 -910
  147. package/dist/cjs/data-structures/binary-tree/binary-tree.js +0 -2197
  148. package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +0 -1
  149. package/dist/cjs/data-structures/binary-tree/bst.d.ts +0 -461
  150. package/dist/cjs/data-structures/binary-tree/bst.js +0 -880
  151. package/dist/cjs/data-structures/binary-tree/bst.js.map +0 -1
  152. package/dist/cjs/data-structures/binary-tree/index.js +0 -27
  153. package/dist/cjs/data-structures/binary-tree/index.js.map +0 -1
  154. package/dist/cjs/data-structures/binary-tree/red-black-tree.d.ts +0 -280
  155. package/dist/cjs/data-structures/binary-tree/red-black-tree.js +0 -642
  156. package/dist/cjs/data-structures/binary-tree/red-black-tree.js.map +0 -1
  157. package/dist/cjs/data-structures/binary-tree/segment-tree.js +0 -298
  158. package/dist/cjs/data-structures/binary-tree/segment-tree.js.map +0 -1
  159. package/dist/cjs/data-structures/binary-tree/tree-counter.d.ts +0 -212
  160. package/dist/cjs/data-structures/binary-tree/tree-counter.js +0 -445
  161. package/dist/cjs/data-structures/binary-tree/tree-counter.js.map +0 -1
  162. package/dist/cjs/data-structures/binary-tree/tree-multi-map.d.ts +0 -267
  163. package/dist/cjs/data-structures/binary-tree/tree-multi-map.js +0 -365
  164. package/dist/cjs/data-structures/binary-tree/tree-multi-map.js.map +0 -1
  165. package/dist/cjs/data-structures/graph/abstract-graph.d.ts +0 -335
  166. package/dist/cjs/data-structures/graph/abstract-graph.js +0 -867
  167. package/dist/cjs/data-structures/graph/abstract-graph.js.map +0 -1
  168. package/dist/cjs/data-structures/graph/directed-graph.d.ts +0 -323
  169. package/dist/cjs/data-structures/graph/directed-graph.js +0 -613
  170. package/dist/cjs/data-structures/graph/directed-graph.js.map +0 -1
  171. package/dist/cjs/data-structures/graph/index.js +0 -21
  172. package/dist/cjs/data-structures/graph/index.js.map +0 -1
  173. package/dist/cjs/data-structures/graph/map-graph.d.ts +0 -84
  174. package/dist/cjs/data-structures/graph/map-graph.js +0 -111
  175. package/dist/cjs/data-structures/graph/map-graph.js.map +0 -1
  176. package/dist/cjs/data-structures/graph/undirected-graph.d.ts +0 -231
  177. package/dist/cjs/data-structures/graph/undirected-graph.js +0 -445
  178. package/dist/cjs/data-structures/graph/undirected-graph.js.map +0 -1
  179. package/dist/cjs/data-structures/hash/hash-map.d.ts +0 -519
  180. package/dist/cjs/data-structures/hash/hash-map.js +0 -880
  181. package/dist/cjs/data-structures/hash/hash-map.js.map +0 -1
  182. package/dist/cjs/data-structures/hash/index.js +0 -18
  183. package/dist/cjs/data-structures/hash/index.js.map +0 -1
  184. package/dist/cjs/data-structures/heap/heap.d.ts +0 -578
  185. package/dist/cjs/data-structures/heap/heap.js +0 -911
  186. package/dist/cjs/data-structures/heap/heap.js.map +0 -1
  187. package/dist/cjs/data-structures/heap/index.js +0 -20
  188. package/dist/cjs/data-structures/heap/index.js.map +0 -1
  189. package/dist/cjs/data-structures/heap/max-heap.d.ts +0 -68
  190. package/dist/cjs/data-structures/heap/max-heap.js +0 -96
  191. package/dist/cjs/data-structures/heap/max-heap.js.map +0 -1
  192. package/dist/cjs/data-structures/heap/min-heap.d.ts +0 -68
  193. package/dist/cjs/data-structures/heap/min-heap.js +0 -87
  194. package/dist/cjs/data-structures/heap/min-heap.js.map +0 -1
  195. package/dist/cjs/data-structures/index.js +0 -29
  196. package/dist/cjs/data-structures/index.js.map +0 -1
  197. package/dist/cjs/data-structures/linked-list/doubly-linked-list.d.ts +0 -885
  198. package/dist/cjs/data-structures/linked-list/doubly-linked-list.js +0 -1238
  199. package/dist/cjs/data-structures/linked-list/doubly-linked-list.js.map +0 -1
  200. package/dist/cjs/data-structures/linked-list/index.js +0 -20
  201. package/dist/cjs/data-structures/linked-list/index.js.map +0 -1
  202. package/dist/cjs/data-structures/linked-list/singly-linked-list.d.ts +0 -500
  203. package/dist/cjs/data-structures/linked-list/singly-linked-list.js +0 -870
  204. package/dist/cjs/data-structures/linked-list/singly-linked-list.js.map +0 -1
  205. package/dist/cjs/data-structures/linked-list/skip-linked-list.d.ts +0 -134
  206. package/dist/cjs/data-structures/linked-list/skip-linked-list.js +0 -245
  207. package/dist/cjs/data-structures/linked-list/skip-linked-list.js.map +0 -1
  208. package/dist/cjs/data-structures/matrix/index.js +0 -19
  209. package/dist/cjs/data-structures/matrix/index.js.map +0 -1
  210. package/dist/cjs/data-structures/matrix/matrix.js +0 -449
  211. package/dist/cjs/data-structures/matrix/matrix.js.map +0 -1
  212. package/dist/cjs/data-structures/matrix/navigator.js +0 -112
  213. package/dist/cjs/data-structures/matrix/navigator.js.map +0 -1
  214. package/dist/cjs/data-structures/priority-queue/index.js +0 -20
  215. package/dist/cjs/data-structures/priority-queue/index.js.map +0 -1
  216. package/dist/cjs/data-structures/priority-queue/max-priority-queue.d.ts +0 -71
  217. package/dist/cjs/data-structures/priority-queue/max-priority-queue.js +0 -102
  218. package/dist/cjs/data-structures/priority-queue/max-priority-queue.js.map +0 -1
  219. package/dist/cjs/data-structures/priority-queue/min-priority-queue.d.ts +0 -72
  220. package/dist/cjs/data-structures/priority-queue/min-priority-queue.js +0 -94
  221. package/dist/cjs/data-structures/priority-queue/min-priority-queue.js.map +0 -1
  222. package/dist/cjs/data-structures/priority-queue/priority-queue.d.ts +0 -74
  223. package/dist/cjs/data-structures/priority-queue/priority-queue.js +0 -96
  224. package/dist/cjs/data-structures/priority-queue/priority-queue.js.map +0 -1
  225. package/dist/cjs/data-structures/queue/deque.d.ts +0 -458
  226. package/dist/cjs/data-structures/queue/deque.js +0 -919
  227. package/dist/cjs/data-structures/queue/deque.js.map +0 -1
  228. package/dist/cjs/data-structures/queue/index.js +0 -19
  229. package/dist/cjs/data-structures/queue/index.js.map +0 -1
  230. package/dist/cjs/data-structures/queue/queue.d.ts +0 -329
  231. package/dist/cjs/data-structures/queue/queue.js +0 -457
  232. package/dist/cjs/data-structures/queue/queue.js.map +0 -1
  233. package/dist/cjs/data-structures/stack/index.js +0 -18
  234. package/dist/cjs/data-structures/stack/index.js.map +0 -1
  235. package/dist/cjs/data-structures/stack/stack.js +0 -346
  236. package/dist/cjs/data-structures/stack/stack.js.map +0 -1
  237. package/dist/cjs/data-structures/tree/index.js +0 -18
  238. package/dist/cjs/data-structures/tree/index.js.map +0 -1
  239. package/dist/cjs/data-structures/tree/tree.js +0 -108
  240. package/dist/cjs/data-structures/tree/tree.js.map +0 -1
  241. package/dist/cjs/data-structures/trie/index.js +0 -18
  242. package/dist/cjs/data-structures/trie/index.js.map +0 -1
  243. package/dist/cjs/data-structures/trie/trie.d.ts +0 -351
  244. package/dist/cjs/data-structures/trie/trie.js +0 -594
  245. package/dist/cjs/data-structures/trie/trie.js.map +0 -1
  246. package/dist/cjs/index.js +0 -22
  247. package/dist/cjs/index.js.map +0 -1
  248. package/dist/cjs/interfaces/binary-tree.d.ts +0 -9
  249. package/dist/cjs/interfaces/binary-tree.js +0 -3
  250. package/dist/cjs/interfaces/binary-tree.js.map +0 -1
  251. package/dist/cjs/interfaces/doubly-linked-list.js +0 -3
  252. package/dist/cjs/interfaces/doubly-linked-list.js.map +0 -1
  253. package/dist/cjs/interfaces/graph.d.ts +0 -5
  254. package/dist/cjs/interfaces/graph.js +0 -3
  255. package/dist/cjs/interfaces/graph.js.map +0 -1
  256. package/dist/cjs/interfaces/heap.js +0 -3
  257. package/dist/cjs/interfaces/heap.js.map +0 -1
  258. package/dist/cjs/interfaces/index.js +0 -25
  259. package/dist/cjs/interfaces/index.js.map +0 -1
  260. package/dist/cjs/interfaces/navigator.js +0 -3
  261. package/dist/cjs/interfaces/navigator.js.map +0 -1
  262. package/dist/cjs/interfaces/priority-queue.js +0 -3
  263. package/dist/cjs/interfaces/priority-queue.js.map +0 -1
  264. package/dist/cjs/interfaces/segment-tree.js +0 -3
  265. package/dist/cjs/interfaces/segment-tree.js.map +0 -1
  266. package/dist/cjs/interfaces/singly-linked-list.js +0 -3
  267. package/dist/cjs/interfaces/singly-linked-list.js.map +0 -1
  268. package/dist/cjs/types/common.js +0 -3
  269. package/dist/cjs/types/common.js.map +0 -1
  270. package/dist/cjs/types/data-structures/base/base.js +0 -3
  271. package/dist/cjs/types/data-structures/base/base.js.map +0 -1
  272. package/dist/cjs/types/data-structures/base/index.js +0 -18
  273. package/dist/cjs/types/data-structures/base/index.js.map +0 -1
  274. package/dist/cjs/types/data-structures/binary-tree/avl-tree-counter.js +0 -3
  275. package/dist/cjs/types/data-structures/binary-tree/avl-tree-counter.js.map +0 -1
  276. package/dist/cjs/types/data-structures/binary-tree/avl-tree-multi-map.js +0 -3
  277. package/dist/cjs/types/data-structures/binary-tree/avl-tree-multi-map.js.map +0 -1
  278. package/dist/cjs/types/data-structures/binary-tree/avl-tree.js +0 -3
  279. package/dist/cjs/types/data-structures/binary-tree/avl-tree.js.map +0 -1
  280. package/dist/cjs/types/data-structures/binary-tree/binary-indexed-tree.js +0 -3
  281. package/dist/cjs/types/data-structures/binary-tree/binary-indexed-tree.js.map +0 -1
  282. package/dist/cjs/types/data-structures/binary-tree/binary-tree.js +0 -3
  283. package/dist/cjs/types/data-structures/binary-tree/binary-tree.js.map +0 -1
  284. package/dist/cjs/types/data-structures/binary-tree/bst.js +0 -3
  285. package/dist/cjs/types/data-structures/binary-tree/bst.js.map +0 -1
  286. package/dist/cjs/types/data-structures/binary-tree/index.js +0 -26
  287. package/dist/cjs/types/data-structures/binary-tree/index.js.map +0 -1
  288. package/dist/cjs/types/data-structures/binary-tree/red-black-tree.js +0 -3
  289. package/dist/cjs/types/data-structures/binary-tree/red-black-tree.js.map +0 -1
  290. package/dist/cjs/types/data-structures/binary-tree/segment-tree.js +0 -3
  291. package/dist/cjs/types/data-structures/binary-tree/segment-tree.js.map +0 -1
  292. package/dist/cjs/types/data-structures/binary-tree/tree-counter.js +0 -3
  293. package/dist/cjs/types/data-structures/binary-tree/tree-counter.js.map +0 -1
  294. package/dist/cjs/types/data-structures/binary-tree/tree-multi-map.js +0 -3
  295. package/dist/cjs/types/data-structures/binary-tree/tree-multi-map.js.map +0 -1
  296. package/dist/cjs/types/data-structures/graph/abstract-graph.d.ts +0 -10
  297. package/dist/cjs/types/data-structures/graph/abstract-graph.js +0 -3
  298. package/dist/cjs/types/data-structures/graph/abstract-graph.js.map +0 -1
  299. package/dist/cjs/types/data-structures/graph/directed-graph.js +0 -3
  300. package/dist/cjs/types/data-structures/graph/directed-graph.js.map +0 -1
  301. package/dist/cjs/types/data-structures/graph/index.js +0 -20
  302. package/dist/cjs/types/data-structures/graph/index.js.map +0 -1
  303. package/dist/cjs/types/data-structures/graph/map-graph.js +0 -3
  304. package/dist/cjs/types/data-structures/graph/map-graph.js.map +0 -1
  305. package/dist/cjs/types/data-structures/graph/undirected-graph.js +0 -3
  306. package/dist/cjs/types/data-structures/graph/undirected-graph.js.map +0 -1
  307. package/dist/cjs/types/data-structures/hash/hash-map.js +0 -3
  308. package/dist/cjs/types/data-structures/hash/hash-map.js.map +0 -1
  309. package/dist/cjs/types/data-structures/hash/index.js +0 -18
  310. package/dist/cjs/types/data-structures/hash/index.js.map +0 -1
  311. package/dist/cjs/types/data-structures/heap/heap.js +0 -3
  312. package/dist/cjs/types/data-structures/heap/heap.js.map +0 -1
  313. package/dist/cjs/types/data-structures/heap/index.js +0 -18
  314. package/dist/cjs/types/data-structures/heap/index.js.map +0 -1
  315. package/dist/cjs/types/data-structures/heap/max-heap.js +0 -3
  316. package/dist/cjs/types/data-structures/heap/max-heap.js.map +0 -1
  317. package/dist/cjs/types/data-structures/heap/min-heap.js +0 -3
  318. package/dist/cjs/types/data-structures/heap/min-heap.js.map +0 -1
  319. package/dist/cjs/types/data-structures/index.js +0 -29
  320. package/dist/cjs/types/data-structures/index.js.map +0 -1
  321. package/dist/cjs/types/data-structures/linked-list/doubly-linked-list.js +0 -3
  322. package/dist/cjs/types/data-structures/linked-list/doubly-linked-list.js.map +0 -1
  323. package/dist/cjs/types/data-structures/linked-list/index.js +0 -20
  324. package/dist/cjs/types/data-structures/linked-list/index.js.map +0 -1
  325. package/dist/cjs/types/data-structures/linked-list/singly-linked-list.js +0 -3
  326. package/dist/cjs/types/data-structures/linked-list/singly-linked-list.js.map +0 -1
  327. package/dist/cjs/types/data-structures/linked-list/skip-linked-list.js +0 -3
  328. package/dist/cjs/types/data-structures/linked-list/skip-linked-list.js.map +0 -1
  329. package/dist/cjs/types/data-structures/matrix/index.js +0 -19
  330. package/dist/cjs/types/data-structures/matrix/index.js.map +0 -1
  331. package/dist/cjs/types/data-structures/matrix/matrix.js +0 -3
  332. package/dist/cjs/types/data-structures/matrix/matrix.js.map +0 -1
  333. package/dist/cjs/types/data-structures/matrix/navigator.js +0 -3
  334. package/dist/cjs/types/data-structures/matrix/navigator.js.map +0 -1
  335. package/dist/cjs/types/data-structures/priority-queue/index.js +0 -20
  336. package/dist/cjs/types/data-structures/priority-queue/index.js.map +0 -1
  337. package/dist/cjs/types/data-structures/priority-queue/max-priority-queue.js +0 -3
  338. package/dist/cjs/types/data-structures/priority-queue/max-priority-queue.js.map +0 -1
  339. package/dist/cjs/types/data-structures/priority-queue/min-priority-queue.js +0 -3
  340. package/dist/cjs/types/data-structures/priority-queue/min-priority-queue.js.map +0 -1
  341. package/dist/cjs/types/data-structures/priority-queue/priority-queue.js +0 -3
  342. package/dist/cjs/types/data-structures/priority-queue/priority-queue.js.map +0 -1
  343. package/dist/cjs/types/data-structures/queue/deque.js +0 -3
  344. package/dist/cjs/types/data-structures/queue/deque.js.map +0 -1
  345. package/dist/cjs/types/data-structures/queue/index.js +0 -19
  346. package/dist/cjs/types/data-structures/queue/index.js.map +0 -1
  347. package/dist/cjs/types/data-structures/queue/queue.js +0 -3
  348. package/dist/cjs/types/data-structures/queue/queue.js.map +0 -1
  349. package/dist/cjs/types/data-structures/stack/index.js +0 -18
  350. package/dist/cjs/types/data-structures/stack/index.js.map +0 -1
  351. package/dist/cjs/types/data-structures/stack/stack.js +0 -3
  352. package/dist/cjs/types/data-structures/stack/stack.js.map +0 -1
  353. package/dist/cjs/types/data-structures/tree/index.js +0 -18
  354. package/dist/cjs/types/data-structures/tree/index.js.map +0 -1
  355. package/dist/cjs/types/data-structures/tree/tree.js +0 -3
  356. package/dist/cjs/types/data-structures/tree/tree.js.map +0 -1
  357. package/dist/cjs/types/data-structures/trie/index.js +0 -18
  358. package/dist/cjs/types/data-structures/trie/index.js.map +0 -1
  359. package/dist/cjs/types/data-structures/trie/trie.js +0 -3
  360. package/dist/cjs/types/data-structures/trie/trie.js.map +0 -1
  361. package/dist/cjs/types/index.js +0 -20
  362. package/dist/cjs/types/index.js.map +0 -1
  363. package/dist/cjs/types/utils/index.js +0 -19
  364. package/dist/cjs/types/utils/index.js.map +0 -1
  365. package/dist/cjs/types/utils/utils.js +0 -3
  366. package/dist/cjs/types/utils/utils.js.map +0 -1
  367. package/dist/cjs/types/utils/validate-type.js +0 -3
  368. package/dist/cjs/types/utils/validate-type.js.map +0 -1
  369. package/dist/cjs/utils/index.js +0 -19
  370. package/dist/cjs/utils/index.js.map +0 -1
  371. package/dist/cjs/utils/number.js +0 -24
  372. package/dist/cjs/utils/number.js.map +0 -1
  373. package/dist/cjs/utils/utils.d.ts +0 -209
  374. package/dist/cjs/utils/utils.js +0 -353
  375. package/dist/cjs/utils/utils.js.map +0 -1
  376. package/dist/esm/common/index.d.ts +0 -12
  377. package/dist/esm/common/index.js +0 -29
  378. package/dist/esm/common/index.js.map +0 -1
  379. package/dist/esm/data-structures/base/index.d.ts +0 -2
  380. package/dist/esm/data-structures/base/index.js +0 -3
  381. package/dist/esm/data-structures/base/index.js.map +0 -1
  382. package/dist/esm/data-structures/base/iterable-element-base.d.ts +0 -116
  383. package/dist/esm/data-structures/base/iterable-element-base.js +0 -199
  384. package/dist/esm/data-structures/base/iterable-element-base.js.map +0 -1
  385. package/dist/esm/data-structures/base/iterable-entry-base.d.ts +0 -168
  386. package/dist/esm/data-structures/base/iterable-entry-base.js +0 -237
  387. package/dist/esm/data-structures/base/iterable-entry-base.js.map +0 -1
  388. package/dist/esm/data-structures/base/linear-base.d.ts +0 -277
  389. package/dist/esm/data-structures/base/linear-base.js +0 -549
  390. package/dist/esm/data-structures/base/linear-base.js.map +0 -1
  391. package/dist/esm/data-structures/binary-tree/avl-tree-counter.d.ts +0 -214
  392. package/dist/esm/data-structures/binary-tree/avl-tree-counter.js +0 -410
  393. package/dist/esm/data-structures/binary-tree/avl-tree-counter.js.map +0 -1
  394. package/dist/esm/data-structures/binary-tree/avl-tree-multi-map.d.ts +0 -104
  395. package/dist/esm/data-structures/binary-tree/avl-tree-multi-map.js +0 -205
  396. package/dist/esm/data-structures/binary-tree/avl-tree-multi-map.js.map +0 -1
  397. package/dist/esm/data-structures/binary-tree/avl-tree.d.ts +0 -302
  398. package/dist/esm/data-structures/binary-tree/avl-tree.js +0 -601
  399. package/dist/esm/data-structures/binary-tree/avl-tree.js.map +0 -1
  400. package/dist/esm/data-structures/binary-tree/binary-indexed-tree.d.ts +0 -174
  401. package/dist/esm/data-structures/binary-tree/binary-indexed-tree.js +0 -296
  402. package/dist/esm/data-structures/binary-tree/binary-indexed-tree.js.map +0 -1
  403. package/dist/esm/data-structures/binary-tree/binary-tree.d.ts +0 -910
  404. package/dist/esm/data-structures/binary-tree/binary-tree.js +0 -2198
  405. package/dist/esm/data-structures/binary-tree/binary-tree.js.map +0 -1
  406. package/dist/esm/data-structures/binary-tree/bst.d.ts +0 -461
  407. package/dist/esm/data-structures/binary-tree/bst.js +0 -881
  408. package/dist/esm/data-structures/binary-tree/bst.js.map +0 -1
  409. package/dist/esm/data-structures/binary-tree/index.d.ts +0 -10
  410. package/dist/esm/data-structures/binary-tree/index.js +0 -11
  411. package/dist/esm/data-structures/binary-tree/index.js.map +0 -1
  412. package/dist/esm/data-structures/binary-tree/red-black-tree.d.ts +0 -280
  413. package/dist/esm/data-structures/binary-tree/red-black-tree.js +0 -641
  414. package/dist/esm/data-structures/binary-tree/red-black-tree.js.map +0 -1
  415. package/dist/esm/data-structures/binary-tree/segment-tree.d.ts +0 -160
  416. package/dist/esm/data-structures/binary-tree/segment-tree.js +0 -295
  417. package/dist/esm/data-structures/binary-tree/segment-tree.js.map +0 -1
  418. package/dist/esm/data-structures/binary-tree/tree-counter.d.ts +0 -212
  419. package/dist/esm/data-structures/binary-tree/tree-counter.js +0 -446
  420. package/dist/esm/data-structures/binary-tree/tree-counter.js.map +0 -1
  421. package/dist/esm/data-structures/binary-tree/tree-multi-map.js +0 -367
  422. package/dist/esm/data-structures/binary-tree/tree-multi-map.js.map +0 -1
  423. package/dist/esm/data-structures/graph/abstract-graph.d.ts +0 -335
  424. package/dist/esm/data-structures/graph/abstract-graph.js +0 -862
  425. package/dist/esm/data-structures/graph/abstract-graph.js.map +0 -1
  426. package/dist/esm/data-structures/graph/directed-graph.d.ts +0 -323
  427. package/dist/esm/data-structures/graph/directed-graph.js +0 -609
  428. package/dist/esm/data-structures/graph/directed-graph.js.map +0 -1
  429. package/dist/esm/data-structures/graph/index.d.ts +0 -4
  430. package/dist/esm/data-structures/graph/index.js +0 -5
  431. package/dist/esm/data-structures/graph/index.js.map +0 -1
  432. package/dist/esm/data-structures/graph/map-graph.d.ts +0 -84
  433. package/dist/esm/data-structures/graph/map-graph.js +0 -108
  434. package/dist/esm/data-structures/graph/map-graph.js.map +0 -1
  435. package/dist/esm/data-structures/graph/undirected-graph.d.ts +0 -231
  436. package/dist/esm/data-structures/graph/undirected-graph.js +0 -439
  437. package/dist/esm/data-structures/graph/undirected-graph.js.map +0 -1
  438. package/dist/esm/data-structures/hash/hash-map.d.ts +0 -519
  439. package/dist/esm/data-structures/hash/hash-map.js +0 -878
  440. package/dist/esm/data-structures/hash/hash-map.js.map +0 -1
  441. package/dist/esm/data-structures/hash/index.d.ts +0 -1
  442. package/dist/esm/data-structures/hash/index.js +0 -2
  443. package/dist/esm/data-structures/hash/index.js.map +0 -1
  444. package/dist/esm/data-structures/heap/heap.d.ts +0 -578
  445. package/dist/esm/data-structures/heap/heap.js +0 -914
  446. package/dist/esm/data-structures/heap/heap.js.map +0 -1
  447. package/dist/esm/data-structures/heap/index.d.ts +0 -3
  448. package/dist/esm/data-structures/heap/index.js +0 -4
  449. package/dist/esm/data-structures/heap/index.js.map +0 -1
  450. package/dist/esm/data-structures/heap/max-heap.d.ts +0 -68
  451. package/dist/esm/data-structures/heap/max-heap.js +0 -95
  452. package/dist/esm/data-structures/heap/max-heap.js.map +0 -1
  453. package/dist/esm/data-structures/heap/min-heap.d.ts +0 -68
  454. package/dist/esm/data-structures/heap/min-heap.js +0 -83
  455. package/dist/esm/data-structures/heap/min-heap.js.map +0 -1
  456. package/dist/esm/data-structures/index.d.ts +0 -12
  457. package/dist/esm/data-structures/index.js +0 -13
  458. package/dist/esm/data-structures/index.js.map +0 -1
  459. package/dist/esm/data-structures/linked-list/doubly-linked-list.d.ts +0 -885
  460. package/dist/esm/data-structures/linked-list/doubly-linked-list.js +0 -1236
  461. package/dist/esm/data-structures/linked-list/doubly-linked-list.js.map +0 -1
  462. package/dist/esm/data-structures/linked-list/index.d.ts +0 -3
  463. package/dist/esm/data-structures/linked-list/index.js +0 -4
  464. package/dist/esm/data-structures/linked-list/index.js.map +0 -1
  465. package/dist/esm/data-structures/linked-list/singly-linked-list.d.ts +0 -500
  466. package/dist/esm/data-structures/linked-list/singly-linked-list.js +0 -866
  467. package/dist/esm/data-structures/linked-list/singly-linked-list.js.map +0 -1
  468. package/dist/esm/data-structures/linked-list/skip-linked-list.d.ts +0 -134
  469. package/dist/esm/data-structures/linked-list/skip-linked-list.js +0 -243
  470. package/dist/esm/data-structures/linked-list/skip-linked-list.js.map +0 -1
  471. package/dist/esm/data-structures/matrix/index.d.ts +0 -2
  472. package/dist/esm/data-structures/matrix/index.js +0 -3
  473. package/dist/esm/data-structures/matrix/index.js.map +0 -1
  474. package/dist/esm/data-structures/matrix/matrix.d.ts +0 -168
  475. package/dist/esm/data-structures/matrix/matrix.js +0 -444
  476. package/dist/esm/data-structures/matrix/matrix.js.map +0 -1
  477. package/dist/esm/data-structures/matrix/navigator.d.ts +0 -55
  478. package/dist/esm/data-structures/matrix/navigator.js +0 -114
  479. package/dist/esm/data-structures/matrix/navigator.js.map +0 -1
  480. package/dist/esm/data-structures/priority-queue/index.d.ts +0 -3
  481. package/dist/esm/data-structures/priority-queue/index.js +0 -4
  482. package/dist/esm/data-structures/priority-queue/index.js.map +0 -1
  483. package/dist/esm/data-structures/priority-queue/max-priority-queue.d.ts +0 -71
  484. package/dist/esm/data-structures/priority-queue/max-priority-queue.js +0 -101
  485. package/dist/esm/data-structures/priority-queue/max-priority-queue.js.map +0 -1
  486. package/dist/esm/data-structures/priority-queue/min-priority-queue.d.ts +0 -72
  487. package/dist/esm/data-structures/priority-queue/min-priority-queue.js +0 -90
  488. package/dist/esm/data-structures/priority-queue/min-priority-queue.js.map +0 -1
  489. package/dist/esm/data-structures/priority-queue/priority-queue.d.ts +0 -74
  490. package/dist/esm/data-structures/priority-queue/priority-queue.js +0 -92
  491. package/dist/esm/data-structures/priority-queue/priority-queue.js.map +0 -1
  492. package/dist/esm/data-structures/queue/deque.d.ts +0 -458
  493. package/dist/esm/data-structures/queue/deque.js +0 -915
  494. package/dist/esm/data-structures/queue/deque.js.map +0 -1
  495. package/dist/esm/data-structures/queue/index.d.ts +0 -2
  496. package/dist/esm/data-structures/queue/index.js +0 -3
  497. package/dist/esm/data-structures/queue/index.js.map +0 -1
  498. package/dist/esm/data-structures/queue/queue.d.ts +0 -329
  499. package/dist/esm/data-structures/queue/queue.js +0 -452
  500. package/dist/esm/data-structures/queue/queue.js.map +0 -1
  501. package/dist/esm/data-structures/stack/index.d.ts +0 -1
  502. package/dist/esm/data-structures/stack/index.js +0 -2
  503. package/dist/esm/data-structures/stack/index.js.map +0 -1
  504. package/dist/esm/data-structures/stack/stack.d.ts +0 -284
  505. package/dist/esm/data-structures/stack/stack.js +0 -342
  506. package/dist/esm/data-structures/stack/stack.js.map +0 -1
  507. package/dist/esm/data-structures/tree/index.d.ts +0 -1
  508. package/dist/esm/data-structures/tree/index.js +0 -2
  509. package/dist/esm/data-structures/tree/index.js.map +0 -1
  510. package/dist/esm/data-structures/tree/tree.d.ts +0 -62
  511. package/dist/esm/data-structures/tree/tree.js +0 -107
  512. package/dist/esm/data-structures/tree/tree.js.map +0 -1
  513. package/dist/esm/data-structures/trie/index.d.ts +0 -1
  514. package/dist/esm/data-structures/trie/index.js +0 -2
  515. package/dist/esm/data-structures/trie/index.js.map +0 -1
  516. package/dist/esm/data-structures/trie/trie.d.ts +0 -351
  517. package/dist/esm/data-structures/trie/trie.js +0 -592
  518. package/dist/esm/data-structures/trie/trie.js.map +0 -1
  519. package/dist/esm/index.d.ts +0 -5
  520. package/dist/esm/index.js +0 -6
  521. package/dist/esm/index.js.map +0 -1
  522. package/dist/esm/interfaces/binary-tree.d.ts +0 -9
  523. package/dist/esm/interfaces/binary-tree.js +0 -2
  524. package/dist/esm/interfaces/binary-tree.js.map +0 -1
  525. package/dist/esm/interfaces/doubly-linked-list.d.ts +0 -1
  526. package/dist/esm/interfaces/doubly-linked-list.js +0 -2
  527. package/dist/esm/interfaces/doubly-linked-list.js.map +0 -1
  528. package/dist/esm/interfaces/graph.d.ts +0 -5
  529. package/dist/esm/interfaces/graph.js +0 -2
  530. package/dist/esm/interfaces/graph.js.map +0 -1
  531. package/dist/esm/interfaces/heap.d.ts +0 -1
  532. package/dist/esm/interfaces/heap.js +0 -2
  533. package/dist/esm/interfaces/heap.js.map +0 -1
  534. package/dist/esm/interfaces/index.d.ts +0 -8
  535. package/dist/esm/interfaces/index.js +0 -9
  536. package/dist/esm/interfaces/index.js.map +0 -1
  537. package/dist/esm/interfaces/navigator.d.ts +0 -1
  538. package/dist/esm/interfaces/navigator.js +0 -2
  539. package/dist/esm/interfaces/navigator.js.map +0 -1
  540. package/dist/esm/interfaces/priority-queue.d.ts +0 -1
  541. package/dist/esm/interfaces/priority-queue.js +0 -2
  542. package/dist/esm/interfaces/priority-queue.js.map +0 -1
  543. package/dist/esm/interfaces/segment-tree.d.ts +0 -1
  544. package/dist/esm/interfaces/segment-tree.js +0 -2
  545. package/dist/esm/interfaces/segment-tree.js.map +0 -1
  546. package/dist/esm/interfaces/singly-linked-list.d.ts +0 -1
  547. package/dist/esm/interfaces/singly-linked-list.js +0 -2
  548. package/dist/esm/interfaces/singly-linked-list.js.map +0 -1
  549. package/dist/esm/types/common.d.ts +0 -15
  550. package/dist/esm/types/common.js +0 -2
  551. package/dist/esm/types/common.js.map +0 -1
  552. package/dist/esm/types/data-structures/base/base.d.ts +0 -13
  553. package/dist/esm/types/data-structures/base/base.js +0 -2
  554. package/dist/esm/types/data-structures/base/base.js.map +0 -1
  555. package/dist/esm/types/data-structures/base/index.d.ts +0 -1
  556. package/dist/esm/types/data-structures/base/index.js +0 -2
  557. package/dist/esm/types/data-structures/base/index.js.map +0 -1
  558. package/dist/esm/types/data-structures/binary-tree/avl-tree-counter.d.ts +0 -2
  559. package/dist/esm/types/data-structures/binary-tree/avl-tree-counter.js +0 -2
  560. package/dist/esm/types/data-structures/binary-tree/avl-tree-counter.js.map +0 -1
  561. package/dist/esm/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +0 -2
  562. package/dist/esm/types/data-structures/binary-tree/avl-tree-multi-map.js +0 -2
  563. package/dist/esm/types/data-structures/binary-tree/avl-tree-multi-map.js.map +0 -1
  564. package/dist/esm/types/data-structures/binary-tree/avl-tree.d.ts +0 -2
  565. package/dist/esm/types/data-structures/binary-tree/avl-tree.js +0 -2
  566. package/dist/esm/types/data-structures/binary-tree/avl-tree.js.map +0 -1
  567. package/dist/esm/types/data-structures/binary-tree/binary-indexed-tree.d.ts +0 -1
  568. package/dist/esm/types/data-structures/binary-tree/binary-indexed-tree.js +0 -2
  569. package/dist/esm/types/data-structures/binary-tree/binary-indexed-tree.js.map +0 -1
  570. package/dist/esm/types/data-structures/binary-tree/binary-tree.d.ts +0 -29
  571. package/dist/esm/types/data-structures/binary-tree/binary-tree.js +0 -2
  572. package/dist/esm/types/data-structures/binary-tree/binary-tree.js.map +0 -1
  573. package/dist/esm/types/data-structures/binary-tree/bst.d.ts +0 -12
  574. package/dist/esm/types/data-structures/binary-tree/bst.js +0 -2
  575. package/dist/esm/types/data-structures/binary-tree/bst.js.map +0 -1
  576. package/dist/esm/types/data-structures/binary-tree/index.d.ts +0 -9
  577. package/dist/esm/types/data-structures/binary-tree/index.js +0 -10
  578. package/dist/esm/types/data-structures/binary-tree/index.js.map +0 -1
  579. package/dist/esm/types/data-structures/binary-tree/red-black-tree.d.ts +0 -3
  580. package/dist/esm/types/data-structures/binary-tree/red-black-tree.js +0 -2
  581. package/dist/esm/types/data-structures/binary-tree/red-black-tree.js.map +0 -1
  582. package/dist/esm/types/data-structures/binary-tree/segment-tree.d.ts +0 -1
  583. package/dist/esm/types/data-structures/binary-tree/segment-tree.js +0 -2
  584. package/dist/esm/types/data-structures/binary-tree/segment-tree.js.map +0 -1
  585. package/dist/esm/types/data-structures/binary-tree/tree-counter.d.ts +0 -2
  586. package/dist/esm/types/data-structures/binary-tree/tree-counter.js +0 -2
  587. package/dist/esm/types/data-structures/binary-tree/tree-counter.js.map +0 -1
  588. package/dist/esm/types/data-structures/binary-tree/tree-multi-map.d.ts +0 -2
  589. package/dist/esm/types/data-structures/binary-tree/tree-multi-map.js +0 -2
  590. package/dist/esm/types/data-structures/binary-tree/tree-multi-map.js.map +0 -1
  591. package/dist/esm/types/data-structures/graph/abstract-graph.js +0 -2
  592. package/dist/esm/types/data-structures/graph/abstract-graph.js.map +0 -1
  593. package/dist/esm/types/data-structures/graph/directed-graph.d.ts +0 -1
  594. package/dist/esm/types/data-structures/graph/directed-graph.js +0 -2
  595. package/dist/esm/types/data-structures/graph/directed-graph.js.map +0 -1
  596. package/dist/esm/types/data-structures/graph/index.d.ts +0 -3
  597. package/dist/esm/types/data-structures/graph/index.js +0 -4
  598. package/dist/esm/types/data-structures/graph/index.js.map +0 -1
  599. package/dist/esm/types/data-structures/graph/map-graph.d.ts +0 -1
  600. package/dist/esm/types/data-structures/graph/map-graph.js +0 -2
  601. package/dist/esm/types/data-structures/graph/map-graph.js.map +0 -1
  602. package/dist/esm/types/data-structures/graph/undirected-graph.d.ts +0 -1
  603. package/dist/esm/types/data-structures/graph/undirected-graph.js +0 -2
  604. package/dist/esm/types/data-structures/graph/undirected-graph.js.map +0 -1
  605. package/dist/esm/types/data-structures/hash/hash-map.d.ts +0 -19
  606. package/dist/esm/types/data-structures/hash/hash-map.js +0 -2
  607. package/dist/esm/types/data-structures/hash/hash-map.js.map +0 -1
  608. package/dist/esm/types/data-structures/hash/index.d.ts +0 -2
  609. package/dist/esm/types/data-structures/hash/index.js +0 -2
  610. package/dist/esm/types/data-structures/hash/index.js.map +0 -1
  611. package/dist/esm/types/data-structures/heap/heap.d.ts +0 -5
  612. package/dist/esm/types/data-structures/heap/heap.js +0 -2
  613. package/dist/esm/types/data-structures/heap/heap.js.map +0 -1
  614. package/dist/esm/types/data-structures/heap/index.d.ts +0 -1
  615. package/dist/esm/types/data-structures/heap/index.js +0 -2
  616. package/dist/esm/types/data-structures/heap/index.js.map +0 -1
  617. package/dist/esm/types/data-structures/heap/max-heap.d.ts +0 -1
  618. package/dist/esm/types/data-structures/heap/max-heap.js +0 -2
  619. package/dist/esm/types/data-structures/heap/max-heap.js.map +0 -1
  620. package/dist/esm/types/data-structures/heap/min-heap.d.ts +0 -1
  621. package/dist/esm/types/data-structures/heap/min-heap.js +0 -2
  622. package/dist/esm/types/data-structures/heap/min-heap.js.map +0 -1
  623. package/dist/esm/types/data-structures/index.d.ts +0 -12
  624. package/dist/esm/types/data-structures/index.js +0 -13
  625. package/dist/esm/types/data-structures/index.js.map +0 -1
  626. package/dist/esm/types/data-structures/linked-list/doubly-linked-list.d.ts +0 -2
  627. package/dist/esm/types/data-structures/linked-list/doubly-linked-list.js +0 -2
  628. package/dist/esm/types/data-structures/linked-list/doubly-linked-list.js.map +0 -1
  629. package/dist/esm/types/data-structures/linked-list/index.d.ts +0 -3
  630. package/dist/esm/types/data-structures/linked-list/index.js +0 -4
  631. package/dist/esm/types/data-structures/linked-list/index.js.map +0 -1
  632. package/dist/esm/types/data-structures/linked-list/singly-linked-list.d.ts +0 -2
  633. package/dist/esm/types/data-structures/linked-list/singly-linked-list.js +0 -2
  634. package/dist/esm/types/data-structures/linked-list/singly-linked-list.js.map +0 -1
  635. package/dist/esm/types/data-structures/linked-list/skip-linked-list.d.ts +0 -4
  636. package/dist/esm/types/data-structures/linked-list/skip-linked-list.js +0 -2
  637. package/dist/esm/types/data-structures/linked-list/skip-linked-list.js.map +0 -1
  638. package/dist/esm/types/data-structures/matrix/index.d.ts +0 -2
  639. package/dist/esm/types/data-structures/matrix/index.js +0 -3
  640. package/dist/esm/types/data-structures/matrix/index.js.map +0 -1
  641. package/dist/esm/types/data-structures/matrix/matrix.d.ts +0 -7
  642. package/dist/esm/types/data-structures/matrix/matrix.js +0 -2
  643. package/dist/esm/types/data-structures/matrix/matrix.js.map +0 -1
  644. package/dist/esm/types/data-structures/matrix/navigator.d.ts +0 -14
  645. package/dist/esm/types/data-structures/matrix/navigator.js +0 -2
  646. package/dist/esm/types/data-structures/matrix/navigator.js.map +0 -1
  647. package/dist/esm/types/data-structures/priority-queue/index.d.ts +0 -3
  648. package/dist/esm/types/data-structures/priority-queue/index.js +0 -4
  649. package/dist/esm/types/data-structures/priority-queue/index.js.map +0 -1
  650. package/dist/esm/types/data-structures/priority-queue/max-priority-queue.d.ts +0 -1
  651. package/dist/esm/types/data-structures/priority-queue/max-priority-queue.js +0 -2
  652. package/dist/esm/types/data-structures/priority-queue/max-priority-queue.js.map +0 -1
  653. package/dist/esm/types/data-structures/priority-queue/min-priority-queue.d.ts +0 -1
  654. package/dist/esm/types/data-structures/priority-queue/min-priority-queue.js +0 -2
  655. package/dist/esm/types/data-structures/priority-queue/min-priority-queue.js.map +0 -1
  656. package/dist/esm/types/data-structures/priority-queue/priority-queue.d.ts +0 -2
  657. package/dist/esm/types/data-structures/priority-queue/priority-queue.js +0 -2
  658. package/dist/esm/types/data-structures/priority-queue/priority-queue.js.map +0 -1
  659. package/dist/esm/types/data-structures/queue/deque.d.ts +0 -4
  660. package/dist/esm/types/data-structures/queue/deque.js +0 -2
  661. package/dist/esm/types/data-structures/queue/deque.js.map +0 -1
  662. package/dist/esm/types/data-structures/queue/index.d.ts +0 -2
  663. package/dist/esm/types/data-structures/queue/index.js +0 -3
  664. package/dist/esm/types/data-structures/queue/index.js.map +0 -1
  665. package/dist/esm/types/data-structures/queue/queue.d.ts +0 -4
  666. package/dist/esm/types/data-structures/queue/queue.js +0 -2
  667. package/dist/esm/types/data-structures/queue/queue.js.map +0 -1
  668. package/dist/esm/types/data-structures/stack/index.d.ts +0 -1
  669. package/dist/esm/types/data-structures/stack/index.js +0 -2
  670. package/dist/esm/types/data-structures/stack/index.js.map +0 -1
  671. package/dist/esm/types/data-structures/stack/stack.d.ts +0 -2
  672. package/dist/esm/types/data-structures/stack/stack.js +0 -2
  673. package/dist/esm/types/data-structures/stack/stack.js.map +0 -1
  674. package/dist/esm/types/data-structures/tree/index.d.ts +0 -1
  675. package/dist/esm/types/data-structures/tree/index.js +0 -2
  676. package/dist/esm/types/data-structures/tree/index.js.map +0 -1
  677. package/dist/esm/types/data-structures/tree/tree.d.ts +0 -1
  678. package/dist/esm/types/data-structures/tree/tree.js +0 -2
  679. package/dist/esm/types/data-structures/tree/tree.js.map +0 -1
  680. package/dist/esm/types/data-structures/trie/index.d.ts +0 -1
  681. package/dist/esm/types/data-structures/trie/index.js +0 -2
  682. package/dist/esm/types/data-structures/trie/index.js.map +0 -1
  683. package/dist/esm/types/data-structures/trie/trie.d.ts +0 -4
  684. package/dist/esm/types/data-structures/trie/trie.js +0 -2
  685. package/dist/esm/types/data-structures/trie/trie.js.map +0 -1
  686. package/dist/esm/types/index.d.ts +0 -3
  687. package/dist/esm/types/index.js +0 -4
  688. package/dist/esm/types/index.js.map +0 -1
  689. package/dist/esm/types/utils/index.d.ts +0 -2
  690. package/dist/esm/types/utils/index.js +0 -3
  691. package/dist/esm/types/utils/index.js.map +0 -1
  692. package/dist/esm/types/utils/utils.d.ts +0 -21
  693. package/dist/esm/types/utils/utils.js +0 -2
  694. package/dist/esm/types/utils/utils.js.map +0 -1
  695. package/dist/esm/types/utils/validate-type.d.ts +0 -19
  696. package/dist/esm/types/utils/validate-type.js +0 -2
  697. package/dist/esm/types/utils/validate-type.js.map +0 -1
  698. package/dist/esm/utils/index.d.ts +0 -2
  699. package/dist/esm/utils/index.js +0 -3
  700. package/dist/esm/utils/index.js.map +0 -1
  701. package/dist/esm/utils/number.d.ts +0 -14
  702. package/dist/esm/utils/number.js +0 -21
  703. package/dist/esm/utils/number.js.map +0 -1
  704. package/dist/esm/utils/utils.js +0 -324
  705. package/dist/esm/utils/utils.js.map +0 -1
  706. package/test/performance/data-structures/binary-tree/avl-tree.test.mjs +0 -71
  707. package/test/performance/data-structures/binary-tree/red-black-tree.test.mjs +0 -81
  708. package/tsconfig-cjs.json +0 -14
  709. package/tsconfig-esm.json +0 -14
  710. /package/dist/{cjs → types}/common/index.d.ts +0 -0
  711. /package/dist/{cjs → types}/data-structures/base/index.d.ts +0 -0
  712. /package/dist/{cjs → types}/data-structures/binary-tree/binary-indexed-tree.d.ts +0 -0
  713. /package/dist/{cjs → types}/data-structures/binary-tree/index.d.ts +0 -0
  714. /package/dist/{cjs → types}/data-structures/binary-tree/segment-tree.d.ts +0 -0
  715. /package/dist/{cjs → types}/data-structures/graph/index.d.ts +0 -0
  716. /package/dist/{cjs → types}/data-structures/hash/index.d.ts +0 -0
  717. /package/dist/{cjs → types}/data-structures/heap/index.d.ts +0 -0
  718. /package/dist/{cjs → types}/data-structures/index.d.ts +0 -0
  719. /package/dist/{cjs → types}/data-structures/linked-list/index.d.ts +0 -0
  720. /package/dist/{cjs → types}/data-structures/matrix/index.d.ts +0 -0
  721. /package/dist/{cjs → types}/data-structures/matrix/matrix.d.ts +0 -0
  722. /package/dist/{cjs → types}/data-structures/matrix/navigator.d.ts +0 -0
  723. /package/dist/{cjs → types}/data-structures/priority-queue/index.d.ts +0 -0
  724. /package/dist/{cjs → types}/data-structures/queue/index.d.ts +0 -0
  725. /package/dist/{cjs → types}/data-structures/stack/index.d.ts +0 -0
  726. /package/dist/{cjs → types}/data-structures/tree/index.d.ts +0 -0
  727. /package/dist/{cjs → types}/data-structures/tree/tree.d.ts +0 -0
  728. /package/dist/{cjs → types}/data-structures/trie/index.d.ts +0 -0
  729. /package/dist/{cjs → types}/index.d.ts +0 -0
  730. /package/dist/{cjs → types}/interfaces/doubly-linked-list.d.ts +0 -0
  731. /package/dist/{cjs → types}/interfaces/heap.d.ts +0 -0
  732. /package/dist/{cjs → types}/interfaces/index.d.ts +0 -0
  733. /package/dist/{cjs → types}/interfaces/navigator.d.ts +0 -0
  734. /package/dist/{cjs → types}/interfaces/priority-queue.d.ts +0 -0
  735. /package/dist/{cjs → types}/interfaces/segment-tree.d.ts +0 -0
  736. /package/dist/{cjs → types}/interfaces/singly-linked-list.d.ts +0 -0
  737. /package/dist/{cjs → types}/types/common.d.ts +0 -0
  738. /package/dist/{cjs → types}/types/data-structures/base/index.d.ts +0 -0
  739. /package/dist/{cjs → types}/types/data-structures/binary-tree/avl-tree-counter.d.ts +0 -0
  740. /package/dist/{cjs → types}/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +0 -0
  741. /package/dist/{cjs → types}/types/data-structures/binary-tree/avl-tree.d.ts +0 -0
  742. /package/dist/{cjs → types}/types/data-structures/binary-tree/binary-indexed-tree.d.ts +0 -0
  743. /package/dist/{cjs → types}/types/data-structures/binary-tree/binary-tree.d.ts +0 -0
  744. /package/dist/{cjs → types}/types/data-structures/binary-tree/bst.d.ts +0 -0
  745. /package/dist/{cjs → types}/types/data-structures/binary-tree/index.d.ts +0 -0
  746. /package/dist/{cjs → types}/types/data-structures/binary-tree/red-black-tree.d.ts +0 -0
  747. /package/dist/{cjs → types}/types/data-structures/binary-tree/segment-tree.d.ts +0 -0
  748. /package/dist/{cjs → types}/types/data-structures/binary-tree/tree-counter.d.ts +0 -0
  749. /package/dist/{cjs → types}/types/data-structures/binary-tree/tree-multi-map.d.ts +0 -0
  750. /package/dist/{cjs → types}/types/data-structures/graph/directed-graph.d.ts +0 -0
  751. /package/dist/{cjs → types}/types/data-structures/graph/index.d.ts +0 -0
  752. /package/dist/{cjs → types}/types/data-structures/graph/map-graph.d.ts +0 -0
  753. /package/dist/{cjs → types}/types/data-structures/graph/undirected-graph.d.ts +0 -0
  754. /package/dist/{cjs → types}/types/data-structures/hash/hash-map.d.ts +0 -0
  755. /package/dist/{cjs → types}/types/data-structures/hash/index.d.ts +0 -0
  756. /package/dist/{cjs → types}/types/data-structures/heap/heap.d.ts +0 -0
  757. /package/dist/{cjs → types}/types/data-structures/heap/index.d.ts +0 -0
  758. /package/dist/{cjs → types}/types/data-structures/heap/max-heap.d.ts +0 -0
  759. /package/dist/{cjs → types}/types/data-structures/heap/min-heap.d.ts +0 -0
  760. /package/dist/{cjs → types}/types/data-structures/index.d.ts +0 -0
  761. /package/dist/{cjs → types}/types/data-structures/linked-list/doubly-linked-list.d.ts +0 -0
  762. /package/dist/{cjs → types}/types/data-structures/linked-list/index.d.ts +0 -0
  763. /package/dist/{cjs → types}/types/data-structures/linked-list/singly-linked-list.d.ts +0 -0
  764. /package/dist/{cjs → types}/types/data-structures/linked-list/skip-linked-list.d.ts +0 -0
  765. /package/dist/{cjs → types}/types/data-structures/matrix/index.d.ts +0 -0
  766. /package/dist/{cjs → types}/types/data-structures/matrix/matrix.d.ts +0 -0
  767. /package/dist/{cjs → types}/types/data-structures/matrix/navigator.d.ts +0 -0
  768. /package/dist/{cjs → types}/types/data-structures/priority-queue/index.d.ts +0 -0
  769. /package/dist/{cjs → types}/types/data-structures/priority-queue/max-priority-queue.d.ts +0 -0
  770. /package/dist/{cjs → types}/types/data-structures/priority-queue/min-priority-queue.d.ts +0 -0
  771. /package/dist/{cjs → types}/types/data-structures/priority-queue/priority-queue.d.ts +0 -0
  772. /package/dist/{cjs → types}/types/data-structures/queue/deque.d.ts +0 -0
  773. /package/dist/{cjs → types}/types/data-structures/queue/index.d.ts +0 -0
  774. /package/dist/{cjs → types}/types/data-structures/queue/queue.d.ts +0 -0
  775. /package/dist/{cjs → types}/types/data-structures/stack/index.d.ts +0 -0
  776. /package/dist/{cjs → types}/types/data-structures/stack/stack.d.ts +0 -0
  777. /package/dist/{cjs → types}/types/data-structures/tree/index.d.ts +0 -0
  778. /package/dist/{cjs → types}/types/data-structures/tree/tree.d.ts +0 -0
  779. /package/dist/{cjs → types}/types/data-structures/trie/index.d.ts +0 -0
  780. /package/dist/{cjs → types}/types/data-structures/trie/trie.d.ts +0 -0
  781. /package/dist/{cjs → types}/types/index.d.ts +0 -0
  782. /package/dist/{cjs → types}/types/utils/index.d.ts +0 -0
  783. /package/dist/{cjs → types}/types/utils/validate-type.d.ts +0 -0
  784. /package/dist/{cjs → types}/utils/index.d.ts +0 -0
  785. /package/dist/{cjs → types}/utils/number.d.ts +0 -0
@@ -1,881 +0,0 @@
1
- import { BinaryTree, BinaryTreeNode } from './binary-tree';
2
- import { Queue } from '../queue';
3
- import { isComparable } from '../../utils';
4
- import { Range } from '../../common';
5
- export class BSTNode extends BinaryTreeNode {
6
- parent = undefined;
7
- /**
8
- * This TypeScript constructor function initializes an instance with a key and an optional value.
9
- * @param {K} key - The `key` parameter is typically used to uniquely identify an object or element
10
- * within a data structure. It serves as a reference or identifier for accessing or manipulating the
11
- * associated value.
12
- * @param {V} [value] - The `value` parameter in the constructor is optional, meaning it does not
13
- * have to be provided when creating an instance of the class. If a value is not provided, it will
14
- * default to `undefined`.
15
- */
16
- constructor(key, value) {
17
- super(key, value);
18
- }
19
- _left = undefined;
20
- get left() {
21
- return this._left;
22
- }
23
- set left(v) {
24
- if (v) {
25
- v.parent = this;
26
- }
27
- this._left = v;
28
- }
29
- _right = undefined;
30
- get right() {
31
- return this._right;
32
- }
33
- set right(v) {
34
- if (v) {
35
- v.parent = this;
36
- }
37
- this._right = v;
38
- }
39
- }
40
- /**
41
- * 1. Node Order: Each node's left child has a lesser value, and the right child has a greater value.
42
- * 2. Unique Keys: No duplicate keys in a standard BST.
43
- * 3. Efficient Search: Enables quick search, minimum, and maximum operations.
44
- * 4. Inorder Traversal: Yields nodes in ascending order.
45
- * 5. Logarithmic Operations: Ideal operations like insertion, deletion, and searching are O(log n) time-efficient.
46
- * 6. Balance Variability: Can become unbalanced; special types maintain balance.
47
- * 7. No Auto-Balancing: Standard BSTs don't automatically balance themselves.
48
- * @example
49
- * // Merge 3 sorted datasets
50
- * const dataset1 = new BST<number, string>([
51
- * [1, 'A'],
52
- * [7, 'G']
53
- * ]);
54
- * const dataset2 = [
55
- * [2, 'B'],
56
- * [6, 'F']
57
- * ];
58
- * const dataset3 = new BST<number, string>([
59
- * [3, 'C'],
60
- * [5, 'E'],
61
- * [4, 'D']
62
- * ]);
63
- *
64
- * // Merge datasets into a single BinarySearchTree
65
- * const merged = new BST<number, string>(dataset1);
66
- * merged.addMany(dataset2);
67
- * merged.merge(dataset3);
68
- *
69
- * // Verify merged dataset is in sorted order
70
- * console.log([...merged.values()]); // ['A', 'B', 'C', 'D', 'E', 'F', 'G']
71
- * @example
72
- * // Find elements in a range
73
- * const bst = new BST<number>([10, 5, 15, 3, 7, 12, 18]);
74
- * console.log(bst.search(new Range(5, 10))); // [5, 7, 10]
75
- * console.log(bst.rangeSearch([4, 12], node => node.key.toString())); // ['5', '7', '10', '12']
76
- * console.log(bst.search(new Range(4, 12, true, false))); // [5, 7, 10]
77
- * console.log(bst.rangeSearch([15, 20])); // [15, 18]
78
- * console.log(bst.search(new Range(15, 20, false))); // [18]
79
- * @example
80
- * // Find lowest common ancestor
81
- * const bst = new BST<number>([20, 10, 30, 5, 15, 25, 35, 3, 7, 12, 18]);
82
- *
83
- * // LCA helper function
84
- * const findLCA = (num1: number, num2: number): number | undefined => {
85
- * const path1 = bst.getPathToRoot(num1);
86
- * const path2 = bst.getPathToRoot(num2);
87
- * // Find the first common ancestor
88
- * return findFirstCommon(path1, path2);
89
- * };
90
- *
91
- * function findFirstCommon(arr1: number[], arr2: number[]): number | undefined {
92
- * for (const num of arr1) {
93
- * if (arr2.indexOf(num) !== -1) {
94
- * return num;
95
- * }
96
- * }
97
- * return undefined;
98
- * }
99
- *
100
- * // Assertions
101
- * console.log(findLCA(3, 10)); // 7
102
- * console.log(findLCA(5, 35)); // 15
103
- * console.log(findLCA(20, 30)); // 25
104
- */
105
- export class BST extends BinaryTree {
106
- /**
107
- * This TypeScript constructor initializes a binary search tree with optional options and adds
108
- * elements if provided.
109
- * @param keysNodesEntriesOrRaws - The `keysNodesEntriesOrRaws` parameter in the constructor is an
110
- * iterable that can contain elements of type `K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined ` or `R`. It is used to
111
- * initialize the binary search tree with keys, nodes, entries, or raw data.
112
- * @param [options] - The `options` parameter is an optional object that can contain the following
113
- * properties:
114
- */
115
- constructor(keysNodesEntriesOrRaws = [], options) {
116
- super([], options);
117
- if (options) {
118
- const { specifyComparable, isReverse } = options;
119
- if (typeof specifyComparable === 'function')
120
- this._specifyComparable = specifyComparable;
121
- if (isReverse !== undefined)
122
- this._isReverse = isReverse;
123
- }
124
- if (keysNodesEntriesOrRaws)
125
- this.addMany(keysNodesEntriesOrRaws);
126
- }
127
- _root = undefined;
128
- get root() {
129
- return this._root;
130
- }
131
- _isReverse = false;
132
- get isReverse() {
133
- return this._isReverse;
134
- }
135
- _comparator = (a, b) => {
136
- if (isComparable(a) && isComparable(b)) {
137
- if (a > b)
138
- return 1;
139
- if (a < b)
140
- return -1;
141
- return 0;
142
- }
143
- if (this._specifyComparable) {
144
- if (this._specifyComparable(a) > this._specifyComparable(b))
145
- return 1;
146
- if (this._specifyComparable(a) < this._specifyComparable(b))
147
- return -1;
148
- return 0;
149
- }
150
- if (typeof a === 'object' || typeof b === 'object') {
151
- throw TypeError(`When comparing object types, a custom specifyComparable must be defined in the constructor's options parameter.`);
152
- }
153
- return 0;
154
- };
155
- get comparator() {
156
- return this._comparator;
157
- }
158
- _specifyComparable;
159
- get specifyComparable() {
160
- return this._specifyComparable;
161
- }
162
- /**
163
- * Time Complexity: O(1)
164
- * Space Complexity: O(1)
165
- *
166
- * The function creates a new BSTNode with the given key and value and returns it.
167
- * @param {K} key - The key parameter is of type K, which represents the type of the key for the node
168
- * being created.
169
- * @param {V} [value] - The "value" parameter is an optional parameter of type V. It represents the
170
- * value associated with the key in the node being created.
171
- * @returns The method is returning a new instance of the BSTNode class, casted as the BSTNode<K, V> type.
172
- */
173
- createNode(key, value) {
174
- return new BSTNode(key, this._isMapMode ? undefined : value);
175
- }
176
- /**
177
- * Time Complexity: O(1)
178
- * Space Complexity: O(1)
179
- *
180
- * The function creates a new binary search tree with the specified options.
181
- * @param [options] - The `options` parameter is an optional object that allows you to customize the
182
- * behavior of the `createTree` method. It accepts a partial `BSTOptions` object, which has the
183
- * following properties:
184
- * @returns a new instance of the BST class with the provided options.
185
- */
186
- createTree(options) {
187
- return new BST([], {
188
- iterationType: this.iterationType,
189
- isMapMode: this._isMapMode,
190
- specifyComparable: this._specifyComparable,
191
- toEntryFn: this._toEntryFn,
192
- isReverse: this._isReverse,
193
- ...options
194
- });
195
- }
196
- /**
197
- * Time Complexity: O(log n)
198
- * Space Complexity: O(log n)
199
- *
200
- * The function ensures the existence of a node in a data structure and returns it, or undefined if
201
- * it doesn't exist.
202
- * @param {K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined } keyNodeOrEntry - The parameter
203
- * `keyNodeOrEntry` can accept a value of type `R`, which represents the key, node,
204
- * entry, or raw element that needs to be ensured in the tree.
205
- * @param {IterationType} [iterationType=ITERATIVE] - The `iterationType` parameter is an optional
206
- * parameter that specifies the type of iteration to be used when ensuring a node. It has a default
207
- * value of `'ITERATIVE'`.
208
- * @returns The method is returning either the node that was ensured or `undefined` if the node could
209
- * not be ensured.
210
- */
211
- ensureNode(keyNodeOrEntry, iterationType = this.iterationType) {
212
- return super.ensureNode(keyNodeOrEntry, iterationType) ?? undefined;
213
- }
214
- /**
215
- * Time Complexity: O(1)
216
- * Space Complexity: O(1)
217
- *
218
- * The function checks if the input is an instance of the BSTNode class.
219
- * @param {K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined } keyNodeOrEntry - The parameter
220
- * `keyNodeOrEntry` can be of type `R` or `K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined `.
221
- * @returns a boolean value indicating whether the input parameter `keyNodeOrEntry` is
222
- * an instance of the `BSTNode` class.
223
- */
224
- isNode(keyNodeOrEntry) {
225
- return keyNodeOrEntry instanceof BSTNode;
226
- }
227
- /**
228
- * Time Complexity: O(1)
229
- * Space Complexity: O(1)
230
- *
231
- * The function "override isValidKey" checks if a key is comparable based on a given comparator.
232
- * @param {any} key - The `key` parameter is a value that will be checked to determine if it is of
233
- * type `K`.
234
- * @returns The `override isValidKey(key: any): key is K` function is returning a boolean value based on
235
- * the result of the `isComparable` function with the condition `this._compare !==
236
- * this._DEFAULT_COMPARATOR`.
237
- */
238
- isValidKey(key) {
239
- return isComparable(key, this._specifyComparable !== undefined);
240
- }
241
- /**
242
- * Time Complexity: O(log n)
243
- * Space Complexity: O(log n)
244
- *
245
- * The `add` function in TypeScript adds a new node to a binary search tree based on the key value.
246
- * @param {K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined } keyNodeOrEntry - The parameter
247
- * `keyNodeOrEntry` can accept a value of type `R` or `K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined `.
248
- * @param {V} [value] - The `value` parameter is an optional value that can be associated with the
249
- * key in the binary search tree. If provided, it will be stored in the node along with the key.
250
- * @returns a boolean value.
251
- */
252
- add(keyNodeOrEntry, value) {
253
- const [newNode, newValue] = this._keyValueNodeOrEntryToNodeAndValue(keyNodeOrEntry, value);
254
- if (newNode === undefined)
255
- return false;
256
- if (this._root === undefined) {
257
- this._setRoot(newNode);
258
- if (this._isMapMode)
259
- this._setValue(newNode?.key, newValue);
260
- this._size++;
261
- return true;
262
- }
263
- let current = this._root;
264
- while (current !== undefined) {
265
- if (this._compare(current.key, newNode.key) === 0) {
266
- this._replaceNode(current, newNode);
267
- if (this._isMapMode)
268
- this._setValue(current.key, newValue);
269
- return true;
270
- }
271
- else if (this._compare(current.key, newNode.key) > 0) {
272
- if (current.left === undefined) {
273
- current.left = newNode;
274
- if (this._isMapMode)
275
- this._setValue(newNode?.key, newValue);
276
- this._size++;
277
- return true;
278
- }
279
- if (current.left !== null)
280
- current = current.left;
281
- }
282
- else {
283
- if (current.right === undefined) {
284
- current.right = newNode;
285
- if (this._isMapMode)
286
- this._setValue(newNode?.key, newValue);
287
- this._size++;
288
- return true;
289
- }
290
- if (current.right !== null)
291
- current = current.right;
292
- }
293
- }
294
- return false;
295
- }
296
- /**
297
- * Time Complexity: O(k log n)
298
- * Space Complexity: O(k + log n)
299
- *
300
- * The `addMany` function in TypeScript adds multiple keys or nodes to a data structure and returns
301
- * an array indicating whether each key or node was successfully inserted.
302
- * @param keysNodesEntriesOrRaws - An iterable containing keys, nodes, entries, or raw
303
- * elements to be added to the data structure.
304
- * @param [values] - An optional iterable of values to be associated with the keys or nodes being
305
- * added. If provided, the values will be assigned to the corresponding keys or nodes in the same
306
- * order. If not provided, undefined will be assigned as the value for each key or node.
307
- * @param [isBalanceAdd=true] - A boolean flag indicating whether the tree should be balanced after
308
- * adding the elements. If set to true, the tree will be balanced using a binary search tree
309
- * algorithm. If set to false, the elements will be added without balancing the tree. The default
310
- * value is true.
311
- * @param {IterationType} iterationType - The `iterationType` parameter is an optional parameter that
312
- * specifies the type of iteration to use when adding multiple keys or nodes to the binary search
313
- * tree. It can have two possible values:
314
- * @returns The function `addMany` returns an array of booleans indicating whether each element was
315
- * successfully inserted into the data structure.
316
- */
317
- addMany(keysNodesEntriesOrRaws, values, isBalanceAdd = true, iterationType = this.iterationType) {
318
- const inserted = [];
319
- let valuesIterator;
320
- if (values) {
321
- valuesIterator = values[Symbol.iterator]();
322
- }
323
- if (!isBalanceAdd) {
324
- for (let kve of keysNodesEntriesOrRaws) {
325
- const value = valuesIterator?.next().value;
326
- if (this.isRaw(kve))
327
- kve = this._toEntryFn(kve);
328
- inserted.push(this.add(kve, value));
329
- }
330
- return inserted;
331
- }
332
- const realBTNExemplars = [];
333
- let i = 0;
334
- for (const kve of keysNodesEntriesOrRaws) {
335
- realBTNExemplars.push({ key: kve, value: valuesIterator?.next().value, orgIndex: i });
336
- i++;
337
- }
338
- let sorted = [];
339
- sorted = realBTNExemplars.sort(({ key: a }, { key: b }) => {
340
- let keyA, keyB;
341
- if (this.isRaw(a))
342
- keyA = this._toEntryFn(a)[0];
343
- else if (this.isEntry(a))
344
- keyA = a[0];
345
- else if (this.isRealNode(a))
346
- keyA = a.key;
347
- else {
348
- keyA = a;
349
- }
350
- if (this.isRaw(b))
351
- keyB = this._toEntryFn(b)[0];
352
- else if (this.isEntry(b))
353
- keyB = b[0];
354
- else if (this.isRealNode(b))
355
- keyB = b.key;
356
- else {
357
- keyB = b;
358
- }
359
- if (keyA !== undefined && keyA !== null && keyB !== undefined && keyB !== null) {
360
- return this._compare(keyA, keyB);
361
- }
362
- return 0;
363
- });
364
- const _dfs = (arr) => {
365
- if (arr.length === 0)
366
- return;
367
- const mid = Math.floor((arr.length - 1) / 2);
368
- const { key, value } = arr[mid];
369
- const { orgIndex } = arr[mid];
370
- if (this.isRaw(key)) {
371
- const entry = this._toEntryFn(key);
372
- inserted[orgIndex] = this.add(entry);
373
- }
374
- else {
375
- inserted[orgIndex] = this.add(key, value);
376
- }
377
- _dfs(arr.slice(0, mid));
378
- _dfs(arr.slice(mid + 1));
379
- };
380
- const _iterate = () => {
381
- const n = sorted.length;
382
- const stack = [[0, n - 1]];
383
- while (stack.length > 0) {
384
- const popped = stack.pop();
385
- if (popped) {
386
- const [l, r] = popped;
387
- if (l <= r) {
388
- const m = l + Math.floor((r - l) / 2);
389
- const { key, value } = sorted[m];
390
- const { orgIndex } = sorted[m];
391
- if (this.isRaw(key)) {
392
- const entry = this._toEntryFn(key);
393
- inserted[orgIndex] = this.add(entry);
394
- }
395
- else {
396
- inserted[orgIndex] = this.add(key, value);
397
- }
398
- stack.push([m + 1, r]);
399
- stack.push([l, m - 1]);
400
- }
401
- }
402
- }
403
- };
404
- if (iterationType === 'RECURSIVE') {
405
- _dfs(sorted);
406
- }
407
- else {
408
- _iterate();
409
- }
410
- return inserted;
411
- }
412
- /**
413
- * Time Complexity: O(log n)
414
- * Space Complexity: O(k + log n)
415
- *
416
- * The function `search` in TypeScript overrides the search behavior in a binary tree structure based
417
- * on specified criteria.
418
- * @param {K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined | NodePredicate<BSTNode<K, V>>} keyNodeEntryOrPredicate - The
419
- * `keyNodeEntryOrPredicate` parameter in the `override search` method can accept one of the
420
- * following types:
421
- * @param [onlyOne=false] - The `onlyOne` parameter is a boolean flag that determines whether the
422
- * search should stop after finding the first matching node. If `onlyOne` is set to `true`, the
423
- * search will return as soon as a matching node is found. If `onlyOne` is set to `false`, the
424
- * @param {C} callback - The `callback` parameter in the `override search` function is a function
425
- * that will be called on each node that matches the search criteria. It is of type `C`, which
426
- * extends `NodeCallback<BSTNode<K, V> | null>`. The callback function should accept a node of type `BSTNode<K, V>` as its
427
- * argument and
428
- * @param {K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined } startNode - The `startNode` parameter in the `override search`
429
- * method represents the node from which the search operation will begin. It is the starting point
430
- * for searching within the tree data structure. The method ensures that the `startNode` is a valid
431
- * node before proceeding with the search operation. If the `
432
- * @param {IterationType} iterationType - The `iterationType` parameter in the `override search`
433
- * function determines the type of iteration to be used during the search operation. It can have two
434
- * possible values:
435
- * @returns The `override search` method returns an array of values that match the search criteria
436
- * specified by the input parameters. The method performs a search operation on a binary tree
437
- * structure based on the provided key, predicate, and other options. The search results are
438
- * collected in an array and returned as the output of the method.
439
- */
440
- search(keyNodeEntryOrPredicate, onlyOne = false, callback = this._DEFAULT_NODE_CALLBACK, startNode = this._root, iterationType = this.iterationType) {
441
- if (keyNodeEntryOrPredicate === undefined)
442
- return [];
443
- if (keyNodeEntryOrPredicate === null)
444
- return [];
445
- startNode = this.ensureNode(startNode);
446
- if (!startNode)
447
- return [];
448
- let predicate;
449
- const isRange = this.isRange(keyNodeEntryOrPredicate);
450
- // Set predicate based on parameter type
451
- if (isRange) {
452
- predicate = node => {
453
- if (!node)
454
- return false;
455
- return keyNodeEntryOrPredicate.isInRange(node.key, this._comparator);
456
- };
457
- }
458
- else {
459
- predicate = this._ensurePredicate(keyNodeEntryOrPredicate);
460
- }
461
- const shouldVisitLeft = (cur) => {
462
- if (!cur)
463
- return false;
464
- if (!this.isRealNode(cur.left))
465
- return false;
466
- if (isRange) {
467
- const range = keyNodeEntryOrPredicate;
468
- const leftS = this.isReverse ? range.high : range.low;
469
- const leftI = this.isReverse ? range.includeHigh : range.includeLow;
470
- return (leftI && this._compare(cur.key, leftS) >= 0) || (!leftI && this._compare(cur.key, leftS) > 0);
471
- }
472
- if (!isRange && !this._isPredicate(keyNodeEntryOrPredicate)) {
473
- const benchmarkKey = this._extractKey(keyNodeEntryOrPredicate);
474
- return benchmarkKey !== null && benchmarkKey !== undefined && this._compare(cur.key, benchmarkKey) > 0;
475
- }
476
- return true;
477
- };
478
- const shouldVisitRight = (cur) => {
479
- if (!cur)
480
- return false;
481
- if (!this.isRealNode(cur.right))
482
- return false;
483
- if (isRange) {
484
- const range = keyNodeEntryOrPredicate;
485
- const rightS = this.isReverse ? range.low : range.high;
486
- const rightI = this.isReverse ? range.includeLow : range.includeLow;
487
- return (rightI && this._compare(cur.key, rightS) <= 0) || (!rightI && this._compare(cur.key, rightS) < 0);
488
- }
489
- if (!isRange && !this._isPredicate(keyNodeEntryOrPredicate)) {
490
- const benchmarkKey = this._extractKey(keyNodeEntryOrPredicate);
491
- return benchmarkKey !== null && benchmarkKey !== undefined && this._compare(cur.key, benchmarkKey) < 0;
492
- }
493
- return true;
494
- };
495
- return super._dfs(callback, 'IN', onlyOne, startNode, iterationType, false, shouldVisitLeft, shouldVisitRight, () => true, cur => {
496
- if (cur)
497
- return predicate(cur);
498
- return false;
499
- });
500
- }
501
- /**
502
- * Time Complexity: O(log n)
503
- * Space Complexity: O(k + log n)
504
- *
505
- * The `rangeSearch` function searches for nodes within a specified range in a binary search tree.
506
- * @param {Range<K> | [K, K]} range - The `range` parameter in the `rangeSearch` function can be
507
- * either a `Range` object or an array of two elements representing the range boundaries.
508
- * @param {C} callback - The `callback` parameter in the `rangeSearch` function is a callback
509
- * function that is used to process each node that is found within the specified range during the
510
- * search operation. It is of type `NodeCallback<BSTNode<K, V> | null>`, where `BSTNode<K, V>` is the type of nodes in the
511
- * data structure.
512
- * @param {K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined } startNode - The `startNode` parameter in the `rangeSearch`
513
- * function represents the node from which the search for nodes within the specified range will
514
- * begin. It is the starting point for the range search operation.
515
- * @param {IterationType} iterationType - The `iterationType` parameter in the `rangeSearch` function
516
- * is used to specify the type of iteration to be performed during the search operation. It has a
517
- * default value of `this.iterationType`, which suggests that it is likely a property of the class or
518
- * object that the `rangeSearch`
519
- * @returns The `rangeSearch` function is returning the result of calling the `search` method with
520
- * the specified parameters.
521
- */
522
- rangeSearch(range, callback = this._DEFAULT_NODE_CALLBACK, startNode = this._root, iterationType = this.iterationType) {
523
- const searchRange = range instanceof Range ? range : new Range(range[0], range[1]);
524
- return this.search(searchRange, false, callback, startNode, iterationType);
525
- }
526
- /**
527
- * Time Complexity: O(log n)
528
- * Space Complexity: O(log n)
529
- *
530
- * This function retrieves a node based on a given keyNodeEntryOrPredicate within a binary search tree structure.
531
- * @param {K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined | NodePredicate<BSTNode<K, V>>} keyNodeEntryOrPredicate - The `keyNodeEntryOrPredicate`
532
- * parameter can be of type `K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined `, `R`, or `NodePredicate<BSTNode<K, V>>`.
533
- * @param {BSTNOptKeyOrNode<K, BSTNode<K, V>>} startNode - The `startNode` parameter in the `getNode` method
534
- * is used to specify the starting point for searching nodes in the binary search tree. If no
535
- * specific starting point is provided, the default value is set to `this._root`, which is the root
536
- * node of the binary search tree.
537
- * @param {IterationType} iterationType - The `iterationType` parameter in the `getNode` method is a
538
- * parameter that specifies the type of iteration to be used. It has a default value of
539
- * `this.iterationType`, which means it will use the iteration type defined in the class instance if
540
- * no value is provided when calling the method.
541
- * @returns The `getNode` method is returning an optional binary search tree node (`OptNode<BSTNode<K, V>>`).
542
- * It is using the `getNodes` method to find the node based on the provided keyNodeEntryOrPredicate, beginning at
543
- * the specified root node (`startNode`) and using the specified iteration type. The method then
544
- * returns the first node found or `undefined` if no node is found.
545
- */
546
- getNode(keyNodeEntryOrPredicate, startNode = this._root, iterationType = this.iterationType) {
547
- return this.getNodes(keyNodeEntryOrPredicate, true, startNode, iterationType)[0] ?? undefined;
548
- }
549
- /**
550
- * Time complexity: O(n)
551
- * Space complexity: O(n)
552
- *
553
- * The function `dfs` in TypeScript overrides the base class method with default parameters and
554
- * returns the result of the super class `dfs` method.
555
- * @param {C} callback - The `callback` parameter is a function that will be called for each node
556
- * visited during the Depth-First Search traversal. It is a generic type `C` that extends the
557
- * `NodeCallback` interface for `BSTNode<K, V>`. The default value for `callback` is `this._
558
- * @param {DFSOrderPattern} [pattern=IN] - The `pattern` parameter in the `override dfs` method
559
- * specifies the order in which the Depth-First Search (DFS) traversal should be performed on the
560
- * Binary Search Tree (BST). The possible values for the `pattern` parameter are:
561
- * @param {boolean} [onlyOne=false] - The `onlyOne` parameter in the `override dfs` method is a
562
- * boolean flag that indicates whether you want to stop the depth-first search traversal after
563
- * finding the first matching node or continue searching for all matching nodes. If `onlyOne` is set
564
- * to `true`, the traversal will stop after finding
565
- * @param {K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined} startNode -
566
- * The `startNode` parameter in the `override dfs` method can be one of the following types:
567
- * @param {IterationType} iterationType - The `iterationType` parameter in the `override dfs` method
568
- * specifies the type of iteration to be performed during the Depth-First Search (DFS) traversal of a
569
- * Binary Search Tree (BST). It is used to determine the order in which nodes are visited during the
570
- * traversal. The possible values for `
571
- * @returns The `override` function is returning the result of calling the `dfs` method from the
572
- * superclass, with the provided arguments `callback`, `pattern`, `onlyOne`, `startNode`, and
573
- * `iterationType`. The return type is an array of the return type of the callback function `C`.
574
- */
575
- dfs(callback = this._DEFAULT_NODE_CALLBACK, pattern = 'IN', onlyOne = false, startNode = this._root, iterationType = this.iterationType) {
576
- return super.dfs(callback, pattern, onlyOne, startNode, iterationType);
577
- }
578
- /**
579
- * Time complexity: O(n)
580
- * Space complexity: O(n)
581
- *
582
- * The function overrides the breadth-first search method and returns an array of the return types of
583
- * the callback function.
584
- * @param {C} callback - The `callback` parameter is a function that will be called for each node
585
- * visited during the breadth-first search. It should take a single argument, which is the current
586
- * node being visited, and it can return a value of any type.
587
- * @param {K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined } startNode - The `startNode` parameter is the starting
588
- * point for the breadth-first search. It can be either a root node, a key-value pair, or an entry
589
- * object. If no value is provided, the default value is the root of the tree.
590
- * @param {IterationType} iterationType - The `iterationType` parameter is used to specify the type
591
- * of iteration to be performed during the breadth-first search (BFS) traversal. It can have one of
592
- * the following values:
593
- * @returns an array of the return type of the callback function.
594
- */
595
- bfs(callback = this._DEFAULT_NODE_CALLBACK, startNode = this._root, iterationType = this.iterationType) {
596
- return super.bfs(callback, startNode, iterationType, false);
597
- }
598
- /**
599
- * Time complexity: O(n)
600
- * Space complexity: O(n)
601
- *
602
- * The function overrides the listLevels method from the superclass and returns an array of arrays
603
- * containing the results of the callback function applied to each level of the tree.
604
- * @param {C} callback - The `callback` parameter is a generic type `C` that extends
605
- * `NodeCallback<BSTNode<K, V> | null>`. It represents a callback function that will be called for each node in the
606
- * tree during the iteration process.
607
- * @param {K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined } startNode - The `startNode` parameter is the starting
608
- * point for listing the levels of the binary tree. It can be either a root node of the tree, a
609
- * key-value pair representing a node in the tree, or a key representing a node in the tree. If no
610
- * value is provided, the root of
611
- * @param {IterationType} iterationType - The `iterationType` parameter is used to specify the type
612
- * of iteration to be performed on the tree. It can have one of the following values:
613
- * @returns The method is returning a two-dimensional array of the return type of the callback
614
- * function.
615
- */
616
- listLevels(callback = this._DEFAULT_NODE_CALLBACK, startNode = this._root, iterationType = this.iterationType) {
617
- return super.listLevels(callback, startNode, iterationType, false);
618
- }
619
- /**
620
- * Time complexity: O(n)
621
- * Space complexity: O(n)
622
- *
623
- * The `lesserOrGreaterTraverse` function traverses a binary tree and applies a callback function to
624
- * each node that meets a certain condition based on a target node and a comparison value.
625
- * @param {C} callback - The `callback` parameter is a function that will be called for each node
626
- * that meets the condition specified by the `lesserOrGreater` parameter. It takes a single argument,
627
- * which is the current node being traversed, and returns a value of any type.
628
- * @param {CP} lesserOrGreater - The `lesserOrGreater` parameter is used to determine whether to
629
- * traverse nodes that are lesser, greater, or both than the `targetNode`. It accepts the values -1,
630
- * 0, or 1, where:
631
- * @param {K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined } targetNode - The `targetNode` parameter is the node in
632
- * the binary tree that you want to start traversing from. It can be specified either by providing
633
- * the key of the node, the node itself, or an entry containing the key and value of the node. If no
634
- * `targetNode` is provided,
635
- * @param {IterationType} iterationType - The `iterationType` parameter determines the type of
636
- * traversal to be performed on the binary tree. It can have two possible values:
637
- * @returns The function `lesserOrGreaterTraverse` returns an array of values of type
638
- * `ReturnType<C>`, which is the return type of the callback function passed as an argument.
639
- */
640
- lesserOrGreaterTraverse(callback = this._DEFAULT_NODE_CALLBACK, lesserOrGreater = -1, targetNode = this._root, iterationType = this.iterationType) {
641
- const targetNodeEnsured = this.ensureNode(targetNode);
642
- const ans = [];
643
- if (!this._root)
644
- return ans;
645
- if (!targetNodeEnsured)
646
- return ans;
647
- const targetKey = targetNodeEnsured.key;
648
- if (iterationType === 'RECURSIVE') {
649
- const dfs = (cur) => {
650
- const compared = this._compare(cur.key, targetKey);
651
- if (Math.sign(compared) === lesserOrGreater)
652
- ans.push(callback(cur));
653
- // TODO here can be optimized to O(log n)
654
- if (this.isRealNode(cur.left))
655
- dfs(cur.left);
656
- if (this.isRealNode(cur.right))
657
- dfs(cur.right);
658
- };
659
- dfs(this._root);
660
- return ans;
661
- }
662
- else {
663
- const queue = new Queue([this._root]);
664
- while (queue.length > 0) {
665
- const cur = queue.shift();
666
- if (this.isRealNode(cur)) {
667
- const compared = this._compare(cur.key, targetKey);
668
- if (Math.sign(compared) === lesserOrGreater)
669
- ans.push(callback(cur));
670
- if (this.isRealNode(cur.left))
671
- queue.push(cur.left);
672
- if (this.isRealNode(cur.right))
673
- queue.push(cur.right);
674
- }
675
- }
676
- return ans;
677
- }
678
- }
679
- /**
680
- * Time complexity: O(n)
681
- * Space complexity: O(n)
682
- *
683
- * The `perfectlyBalance` function takes an optional `iterationType` parameter and returns `true` if
684
- * the binary search tree is perfectly balanced, otherwise it returns `false`.
685
- * @param {IterationType} iterationType - The `iterationType` parameter is an optional parameter that
686
- * specifies the type of iteration to use when building a balanced binary search tree. It has a
687
- * default value of `this.iterationType`, which means it will use the iteration type specified in the
688
- * current instance of the class.
689
- * @returns The function `perfectlyBalance` returns a boolean value.
690
- */
691
- perfectlyBalance(iterationType = this.iterationType) {
692
- const sorted = this.dfs(node => node, 'IN'), n = sorted.length;
693
- this._clearNodes();
694
- if (sorted.length < 1)
695
- return false;
696
- if (iterationType === 'RECURSIVE') {
697
- const buildBalanceBST = (l, r) => {
698
- if (l > r)
699
- return;
700
- const m = l + Math.floor((r - l) / 2);
701
- const midNode = sorted[m];
702
- if (this._isMapMode && midNode !== null)
703
- this.add(midNode.key);
704
- else if (midNode !== null)
705
- this.add([midNode.key, midNode.value]);
706
- buildBalanceBST(l, m - 1);
707
- buildBalanceBST(m + 1, r);
708
- };
709
- buildBalanceBST(0, n - 1);
710
- return true;
711
- }
712
- else {
713
- const stack = [[0, n - 1]];
714
- while (stack.length > 0) {
715
- const popped = stack.pop();
716
- if (popped) {
717
- const [l, r] = popped;
718
- if (l <= r) {
719
- const m = l + Math.floor((r - l) / 2);
720
- const midNode = sorted[m];
721
- if (this._isMapMode && midNode !== null)
722
- this.add(midNode.key);
723
- else if (midNode !== null)
724
- this.add([midNode.key, midNode.value]);
725
- stack.push([m + 1, r]);
726
- stack.push([l, m - 1]);
727
- }
728
- }
729
- }
730
- return true;
731
- }
732
- }
733
- /**
734
- * Time Complexity: O(n)
735
- * Space Complexity: O(log n)
736
- *
737
- * The function `isAVLBalanced` checks if a binary tree is AVL balanced using either a recursive or
738
- * iterative approach.
739
- * @param {IterationType} iterationType - The `iterationType` parameter is an optional parameter that
740
- * specifies the type of iteration to use when checking if the AVL tree is balanced. It has a default
741
- * value of `this.iterationType`, which means it will use the iteration type specified in the current
742
- * instance of the AVL tree.
743
- * @returns a boolean value.
744
- */
745
- isAVLBalanced(iterationType = this.iterationType) {
746
- if (!this._root)
747
- return true;
748
- let balanced = true;
749
- if (iterationType === 'RECURSIVE') {
750
- const _height = (cur) => {
751
- if (!cur)
752
- return 0;
753
- const leftHeight = _height(cur.left), rightHeight = _height(cur.right);
754
- if (Math.abs(leftHeight - rightHeight) > 1)
755
- balanced = false;
756
- return Math.max(leftHeight, rightHeight) + 1;
757
- };
758
- _height(this._root);
759
- }
760
- else {
761
- const stack = [];
762
- let node = this._root, last = undefined;
763
- const depths = new Map();
764
- while (stack.length > 0 || node) {
765
- if (node) {
766
- stack.push(node);
767
- if (node.left !== null)
768
- node = node.left;
769
- }
770
- else {
771
- node = stack[stack.length - 1];
772
- if (!node.right || last === node.right) {
773
- node = stack.pop();
774
- if (node) {
775
- const left = node.left ? depths.get(node.left) : -1;
776
- const right = node.right ? depths.get(node.right) : -1;
777
- if (Math.abs(left - right) > 1)
778
- return false;
779
- depths.set(node, 1 + Math.max(left, right));
780
- last = node;
781
- node = undefined;
782
- }
783
- }
784
- else
785
- node = node.right;
786
- }
787
- }
788
- }
789
- return balanced;
790
- }
791
- /**
792
- * Time complexity: O(n)
793
- * Space complexity: O(n)
794
- *
795
- * The `map` function in TypeScript overrides the default map behavior for a binary search tree by
796
- * applying a callback function to each entry and creating a new tree with the results.
797
- * @param callback - A function that will be called for each entry in the BST. It takes four
798
- * arguments: the key, the value (which can be undefined), the index of the entry, and a reference to
799
- * the BST itself.
800
- * @param [options] - The `options` parameter in the `override map` method is of type `BSTOptions<MK,
801
- * MV, MR>`. It is an optional parameter that allows you to specify additional options for the Binary
802
- * Search Tree (BST) being created in the `map` method. These options could include configuration
803
- * @param {any} [thisArg] - The `thisArg` parameter in the `override map` method is used to specify
804
- * the value of `this` that should be used when executing the `callback` function. It allows you to
805
- * set the context or scope in which the callback function will be called. This can be useful when
806
- * you want
807
- * @returns The `map` method is returning a new Binary Search Tree (`BST`) instance with the entries
808
- * transformed by the provided callback function.
809
- */
810
- map(callback, options, thisArg) {
811
- const newTree = new BST([], options);
812
- let index = 0;
813
- for (const [key, value] of this) {
814
- newTree.add(callback.call(thisArg, key, value, index++, this));
815
- }
816
- return newTree;
817
- }
818
- /**
819
- * Time complexity: O(n)
820
- * Space complexity: O(n)
821
- *
822
- * The function `clone` overrides the default cloning behavior to create a deep copy of a tree
823
- * structure.
824
- * @returns The `cloned` object is being returned.
825
- */
826
- clone() {
827
- const cloned = this.createTree();
828
- this._clone(cloned);
829
- return cloned;
830
- }
831
- /**
832
- * Time Complexity: O(1)
833
- * Space Complexity: O(1)
834
- *
835
- * The function overrides a method and converts a key, value pair or entry or raw element to a node.
836
- * @param {K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined } keyNodeOrEntry - A variable that can be of
837
- * type R or K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined . It represents either a key, a node, an entry, or a raw
838
- * element.
839
- * @param {V} [value] - The `value` parameter is an optional value of type `V`. It represents the
840
- * value associated with a key in a key-value pair.
841
- * @returns either a BSTNode<K, V> object or undefined.
842
- */
843
- _keyValueNodeOrEntryToNodeAndValue(keyNodeOrEntry, value) {
844
- const [node, entryValue] = super._keyValueNodeOrEntryToNodeAndValue(keyNodeOrEntry, value);
845
- if (node === null)
846
- return [undefined, undefined];
847
- return [node, value ?? entryValue];
848
- }
849
- /**
850
- * Time Complexity: O(1)
851
- * Space Complexity: O(1)
852
- *
853
- * The function sets the root of a tree-like structure and updates the parent property of the new
854
- * root.
855
- * @param {OptNode<BSTNode<K, V>>} v - v is a parameter of type BSTNode<K, V> or undefined.
856
- */
857
- _setRoot(v) {
858
- if (v) {
859
- v.parent = undefined;
860
- }
861
- this._root = v;
862
- }
863
- /**
864
- * Time Complexity: O(1)
865
- * Space Complexity: O(1)
866
- *
867
- * The _compare function compares two values using a specified comparator function and optionally
868
- * reverses the result.
869
- * @param {K} a - The parameter `a` is of type `K`, which is used as an input for comparison in the
870
- * `_compare` method.
871
- * @param {K} b - The parameter `b` in the `_compare` function is of type `K`.
872
- * @returns The `_compare` method is returning the result of the ternary expression. If `_isReverse`
873
- * is true, it returns the negation of the result of calling the `_comparator` function with
874
- * arguments `a` and `b`. If `_isReverse` is false, it returns the result of calling the
875
- * `_comparator` function with arguments `a` and `b`.
876
- */
877
- _compare(a, b) {
878
- return this._isReverse ? -this._comparator(a, b) : this._comparator(a, b);
879
- }
880
- }
881
- //# sourceMappingURL=bst.js.map