data-structure-typed 1.37.3 → 1.37.5

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 (346) hide show
  1. package/dist/data-structures/binary-tree/avl-tree.d.ts +42 -34
  2. package/dist/data-structures/binary-tree/avl-tree.js +42 -34
  3. package/dist/data-structures/binary-tree/avl-tree.js.map +1 -1
  4. package/dist/data-structures/binary-tree/binary-indexed-tree.d.ts +141 -43
  5. package/dist/data-structures/binary-tree/binary-indexed-tree.js +230 -42
  6. package/dist/data-structures/binary-tree/binary-indexed-tree.js.map +1 -1
  7. package/dist/data-structures/binary-tree/binary-tree.d.ts +265 -168
  8. package/dist/data-structures/binary-tree/binary-tree.js +257 -170
  9. package/dist/data-structures/binary-tree/binary-tree.js.map +1 -1
  10. package/dist/data-structures/binary-tree/bst.d.ts +104 -59
  11. package/dist/data-structures/binary-tree/bst.js +105 -60
  12. package/dist/data-structures/binary-tree/bst.js.map +1 -1
  13. package/dist/data-structures/binary-tree/tree-multiset.d.ts +47 -39
  14. package/dist/data-structures/binary-tree/tree-multiset.js +47 -39
  15. package/dist/data-structures/binary-tree/tree-multiset.js.map +1 -1
  16. package/{lib/types/data-structures → dist/types/data-structures/binary-tree}/avl-tree.d.ts +1 -1
  17. package/dist/types/data-structures/binary-tree/avl-tree.js.map +1 -0
  18. package/dist/types/data-structures/binary-tree/binary-indexed-tree.js +3 -0
  19. package/dist/types/data-structures/binary-tree/binary-indexed-tree.js.map +1 -0
  20. package/dist/types/data-structures/{binary-tree.d.ts → binary-tree/binary-tree.d.ts} +1 -5
  21. package/dist/types/data-structures/binary-tree/binary-tree.js.map +1 -0
  22. package/dist/types/data-structures/{bst.d.ts → binary-tree/bst.d.ts} +1 -1
  23. package/dist/types/data-structures/binary-tree/bst.js.map +1 -0
  24. package/dist/types/data-structures/binary-tree/index.d.ts +6 -0
  25. package/dist/types/data-structures/binary-tree/index.js +23 -0
  26. package/dist/types/data-structures/binary-tree/index.js.map +1 -0
  27. package/dist/types/data-structures/{rb-tree.d.ts → binary-tree/rb-tree.d.ts} +1 -1
  28. package/dist/types/data-structures/binary-tree/rb-tree.js.map +1 -0
  29. package/dist/types/data-structures/binary-tree/segment-tree.js.map +1 -0
  30. package/dist/types/data-structures/{tree-multiset.d.ts → binary-tree/tree-multiset.d.ts} +1 -1
  31. package/dist/types/data-structures/binary-tree/tree-multiset.js.map +1 -0
  32. package/dist/types/data-structures/graph/abstract-graph.js.map +1 -0
  33. package/dist/types/data-structures/graph/directed-graph.js.map +1 -0
  34. package/dist/types/data-structures/graph/index.d.ts +3 -0
  35. package/dist/types/data-structures/graph/index.js +20 -0
  36. package/dist/types/data-structures/graph/index.js.map +1 -0
  37. package/dist/types/data-structures/graph/map-graph.js.map +1 -0
  38. package/dist/types/data-structures/graph/undirected-graph.js +3 -0
  39. package/dist/types/data-structures/graph/undirected-graph.js.map +1 -0
  40. package/dist/types/data-structures/hash/coordinate-map.js +3 -0
  41. package/dist/types/data-structures/hash/coordinate-map.js.map +1 -0
  42. package/dist/types/data-structures/hash/coordinate-set.js +3 -0
  43. package/dist/types/data-structures/hash/coordinate-set.js.map +1 -0
  44. package/dist/types/data-structures/hash/hash-map.js +3 -0
  45. package/dist/types/data-structures/hash/hash-map.js.map +1 -0
  46. package/dist/types/data-structures/hash/hash-table.js +3 -0
  47. package/dist/types/data-structures/hash/hash-table.js.map +1 -0
  48. package/dist/types/data-structures/hash/index.js +3 -0
  49. package/dist/types/data-structures/hash/index.js.map +1 -0
  50. package/dist/types/data-structures/hash/tree-map.js +3 -0
  51. package/dist/types/data-structures/hash/tree-map.js.map +1 -0
  52. package/dist/types/data-structures/hash/tree-set.js +3 -0
  53. package/dist/types/data-structures/hash/tree-set.js.map +1 -0
  54. package/dist/types/data-structures/heap/heap.js.map +1 -0
  55. package/dist/types/data-structures/heap/index.d.ts +1 -0
  56. package/dist/types/data-structures/heap/index.js +18 -0
  57. package/dist/types/data-structures/heap/index.js.map +1 -0
  58. package/dist/types/data-structures/heap/max-heap.js +3 -0
  59. package/dist/types/data-structures/heap/max-heap.js.map +1 -0
  60. package/dist/types/data-structures/heap/min-heap.js +3 -0
  61. package/dist/types/data-structures/heap/min-heap.js.map +1 -0
  62. package/dist/types/data-structures/index.d.ts +8 -13
  63. package/dist/types/data-structures/index.js +8 -11
  64. package/dist/types/data-structures/index.js.map +1 -1
  65. package/dist/types/data-structures/linked-list/doubly-linked-list.js.map +1 -0
  66. package/dist/types/data-structures/linked-list/index.d.ts +2 -0
  67. package/dist/types/data-structures/linked-list/index.js +19 -0
  68. package/dist/types/data-structures/linked-list/index.js.map +1 -0
  69. package/dist/types/data-structures/linked-list/singly-linked-list.js.map +1 -0
  70. package/dist/types/data-structures/linked-list/skip-linked-list.js +3 -0
  71. package/dist/types/data-structures/linked-list/skip-linked-list.js.map +1 -0
  72. package/dist/types/data-structures/matrix/index.d.ts +1 -0
  73. package/dist/types/data-structures/matrix/index.js +18 -0
  74. package/dist/types/data-structures/matrix/index.js.map +1 -0
  75. package/dist/types/data-structures/matrix/matrix.js +3 -0
  76. package/dist/types/data-structures/matrix/matrix.js.map +1 -0
  77. package/dist/types/data-structures/matrix/matrix2d.js +3 -0
  78. package/dist/types/data-structures/matrix/matrix2d.js.map +1 -0
  79. package/dist/types/data-structures/matrix/navigator.js.map +1 -0
  80. package/dist/types/data-structures/matrix/vector2d.js +3 -0
  81. package/dist/types/data-structures/matrix/vector2d.js.map +1 -0
  82. package/dist/types/data-structures/priority-queue/index.d.ts +3 -0
  83. package/dist/types/data-structures/priority-queue/index.js +20 -0
  84. package/dist/types/data-structures/priority-queue/index.js.map +1 -0
  85. package/dist/types/data-structures/priority-queue/max-priority-queue.js +3 -0
  86. package/dist/types/data-structures/priority-queue/max-priority-queue.js.map +1 -0
  87. package/dist/types/data-structures/priority-queue/min-priority-queue.js +3 -0
  88. package/dist/types/data-structures/priority-queue/min-priority-queue.js.map +1 -0
  89. package/dist/types/data-structures/priority-queue/priority-queue.d.ts +1 -0
  90. package/dist/types/data-structures/priority-queue/priority-queue.js +3 -0
  91. package/dist/types/data-structures/priority-queue/priority-queue.js.map +1 -0
  92. package/dist/types/data-structures/queue/deque.d.ts +1 -0
  93. package/dist/types/data-structures/queue/deque.js +3 -0
  94. package/dist/types/data-structures/queue/deque.js.map +1 -0
  95. package/dist/types/data-structures/queue/index.d.ts +2 -0
  96. package/dist/types/data-structures/queue/index.js +19 -0
  97. package/dist/types/data-structures/queue/index.js.map +1 -0
  98. package/dist/types/data-structures/queue/queue.d.ts +1 -0
  99. package/dist/types/data-structures/queue/queue.js +3 -0
  100. package/dist/types/data-structures/queue/queue.js.map +1 -0
  101. package/dist/types/data-structures/stack/index.d.ts +1 -0
  102. package/dist/types/data-structures/stack/index.js +18 -0
  103. package/dist/types/data-structures/stack/index.js.map +1 -0
  104. package/dist/types/data-structures/stack/stack.d.ts +1 -0
  105. package/dist/types/data-structures/stack/stack.js +3 -0
  106. package/dist/types/data-structures/stack/stack.js.map +1 -0
  107. package/dist/types/data-structures/tree/index.d.ts +1 -0
  108. package/dist/types/data-structures/tree/index.js +18 -0
  109. package/dist/types/data-structures/tree/index.js.map +1 -0
  110. package/dist/types/data-structures/tree/tree.d.ts +1 -0
  111. package/dist/types/data-structures/{hash.js → tree/tree.js} +1 -1
  112. package/dist/types/data-structures/tree/tree.js.map +1 -0
  113. package/dist/types/data-structures/trie/index.d.ts +1 -0
  114. package/dist/types/data-structures/trie/index.js +18 -0
  115. package/dist/types/data-structures/trie/index.js.map +1 -0
  116. package/dist/types/data-structures/trie/trie.d.ts +1 -0
  117. package/dist/types/data-structures/trie/trie.js +3 -0
  118. package/dist/types/data-structures/trie/trie.js.map +1 -0
  119. package/dist/types/helpers.d.ts +2 -0
  120. package/dist/utils/utils.d.ts +1 -0
  121. package/dist/utils/utils.js +8 -1
  122. package/dist/utils/utils.js.map +1 -1
  123. package/lib/data-structures/binary-tree/avl-tree.d.ts +42 -34
  124. package/lib/data-structures/binary-tree/avl-tree.js +42 -34
  125. package/lib/data-structures/binary-tree/binary-indexed-tree.d.ts +141 -43
  126. package/lib/data-structures/binary-tree/binary-indexed-tree.js +230 -42
  127. package/lib/data-structures/binary-tree/binary-tree.d.ts +265 -168
  128. package/lib/data-structures/binary-tree/binary-tree.js +257 -170
  129. package/lib/data-structures/binary-tree/bst.d.ts +104 -59
  130. package/lib/data-structures/binary-tree/bst.js +105 -60
  131. package/lib/data-structures/binary-tree/tree-multiset.d.ts +47 -39
  132. package/lib/data-structures/binary-tree/tree-multiset.js +47 -39
  133. package/{dist/types/data-structures → lib/types/data-structures/binary-tree}/avl-tree.d.ts +1 -1
  134. package/lib/types/data-structures/binary-tree/avl-tree.js +1 -0
  135. package/lib/types/data-structures/binary-tree/binary-indexed-tree.d.ts +1 -0
  136. package/lib/types/data-structures/binary-tree/binary-indexed-tree.js +1 -0
  137. package/lib/types/data-structures/{binary-tree.d.ts → binary-tree/binary-tree.d.ts} +1 -5
  138. package/lib/types/data-structures/{bst.d.ts → binary-tree/bst.d.ts} +1 -1
  139. package/lib/types/data-structures/binary-tree/index.d.ts +6 -0
  140. package/lib/types/data-structures/binary-tree/index.js +6 -0
  141. package/lib/types/data-structures/{rb-tree.d.ts → binary-tree/rb-tree.d.ts} +1 -1
  142. package/lib/types/data-structures/binary-tree/segment-tree.js +1 -0
  143. package/lib/types/data-structures/{tree-multiset.d.ts → binary-tree/tree-multiset.d.ts} +1 -1
  144. package/lib/types/data-structures/binary-tree/tree-multiset.js +1 -0
  145. package/lib/types/data-structures/graph/abstract-graph.js +1 -0
  146. package/lib/types/data-structures/graph/index.d.ts +3 -0
  147. package/lib/types/data-structures/graph/index.js +3 -0
  148. package/lib/types/data-structures/graph/map-graph.js +1 -0
  149. package/lib/types/data-structures/graph/undirected-graph.d.ts +1 -0
  150. package/lib/types/data-structures/graph/undirected-graph.js +1 -0
  151. package/lib/types/data-structures/hash/coordinate-map.d.ts +1 -0
  152. package/lib/types/data-structures/hash/coordinate-map.js +1 -0
  153. package/lib/types/data-structures/hash/coordinate-set.d.ts +1 -0
  154. package/lib/types/data-structures/hash/coordinate-set.js +1 -0
  155. package/lib/types/data-structures/hash/hash-map.d.ts +1 -0
  156. package/lib/types/data-structures/hash/hash-map.js +1 -0
  157. package/lib/types/data-structures/hash/hash-table.d.ts +1 -0
  158. package/lib/types/data-structures/hash/hash-table.js +1 -0
  159. package/lib/types/data-structures/hash/index.js +1 -0
  160. package/lib/types/data-structures/hash/tree-map.d.ts +1 -0
  161. package/lib/types/data-structures/hash/tree-map.js +1 -0
  162. package/lib/types/data-structures/hash/tree-set.d.ts +1 -0
  163. package/lib/types/data-structures/hash/tree-set.js +1 -0
  164. package/lib/types/data-structures/heap/heap.d.ts +1 -0
  165. package/lib/types/data-structures/heap/heap.js +1 -0
  166. package/lib/types/data-structures/heap/index.d.ts +1 -0
  167. package/lib/types/data-structures/heap/index.js +1 -0
  168. package/lib/types/data-structures/heap/max-heap.d.ts +1 -0
  169. package/lib/types/data-structures/heap/max-heap.js +1 -0
  170. package/lib/types/data-structures/heap/min-heap.d.ts +1 -0
  171. package/lib/types/data-structures/heap/min-heap.js +1 -0
  172. package/lib/types/data-structures/index.d.ts +8 -13
  173. package/lib/types/data-structures/index.js +8 -11
  174. package/lib/types/data-structures/linked-list/doubly-linked-list.d.ts +1 -0
  175. package/lib/types/data-structures/linked-list/doubly-linked-list.js +1 -0
  176. package/lib/types/data-structures/linked-list/index.d.ts +2 -0
  177. package/lib/types/data-structures/linked-list/index.js +2 -0
  178. package/lib/types/data-structures/linked-list/singly-linked-list.d.ts +1 -0
  179. package/lib/types/data-structures/linked-list/singly-linked-list.js +1 -0
  180. package/lib/types/data-structures/linked-list/skip-linked-list.d.ts +1 -0
  181. package/lib/types/data-structures/linked-list/skip-linked-list.js +1 -0
  182. package/lib/types/data-structures/matrix/index.d.ts +1 -0
  183. package/lib/types/data-structures/matrix/index.js +1 -0
  184. package/lib/types/data-structures/matrix/matrix.d.ts +1 -0
  185. package/lib/types/data-structures/matrix/matrix.js +1 -0
  186. package/lib/types/data-structures/matrix/matrix2d.d.ts +1 -0
  187. package/lib/types/data-structures/matrix/matrix2d.js +1 -0
  188. package/lib/types/data-structures/matrix/navigator.js +1 -0
  189. package/lib/types/data-structures/matrix/vector2d.d.ts +1 -0
  190. package/lib/types/data-structures/matrix/vector2d.js +1 -0
  191. package/lib/types/data-structures/priority-queue/index.d.ts +3 -0
  192. package/lib/types/data-structures/priority-queue/index.js +3 -0
  193. package/lib/types/data-structures/priority-queue/max-priority-queue.d.ts +1 -0
  194. package/lib/types/data-structures/priority-queue/max-priority-queue.js +1 -0
  195. package/lib/types/data-structures/priority-queue/min-priority-queue.d.ts +1 -0
  196. package/lib/types/data-structures/priority-queue/min-priority-queue.js +1 -0
  197. package/lib/types/data-structures/priority-queue/priority-queue.d.ts +1 -0
  198. package/lib/types/data-structures/priority-queue/priority-queue.js +1 -0
  199. package/lib/types/data-structures/queue/deque.d.ts +1 -0
  200. package/lib/types/data-structures/queue/deque.js +1 -0
  201. package/lib/types/data-structures/queue/index.d.ts +2 -0
  202. package/lib/types/data-structures/queue/index.js +2 -0
  203. package/lib/types/data-structures/queue/queue.d.ts +1 -0
  204. package/lib/types/data-structures/queue/queue.js +1 -0
  205. package/lib/types/data-structures/stack/index.d.ts +1 -0
  206. package/lib/types/data-structures/stack/index.js +1 -0
  207. package/lib/types/data-structures/stack/stack.d.ts +1 -0
  208. package/lib/types/data-structures/stack/stack.js +1 -0
  209. package/lib/types/data-structures/tree/index.d.ts +1 -0
  210. package/lib/types/data-structures/tree/index.js +1 -0
  211. package/lib/types/data-structures/tree/tree.d.ts +1 -0
  212. package/lib/types/data-structures/tree/tree.js +1 -0
  213. package/lib/types/data-structures/trie/index.d.ts +1 -0
  214. package/lib/types/data-structures/trie/index.js +1 -0
  215. package/lib/types/data-structures/trie/trie.d.ts +1 -0
  216. package/lib/types/data-structures/trie/trie.js +1 -0
  217. package/lib/types/helpers.d.ts +2 -0
  218. package/lib/utils/utils.d.ts +1 -0
  219. package/lib/utils/utils.js +6 -0
  220. package/package.json +6 -6
  221. package/src/data-structures/binary-tree/avl-tree.ts +42 -34
  222. package/src/data-structures/binary-tree/binary-indexed-tree.ts +264 -42
  223. package/src/data-structures/binary-tree/binary-tree.ts +267 -172
  224. package/src/data-structures/binary-tree/bst.ts +111 -60
  225. package/src/data-structures/binary-tree/tree-multiset.ts +47 -39
  226. package/src/types/data-structures/{avl-tree.ts → binary-tree/avl-tree.ts} +1 -1
  227. package/src/types/data-structures/binary-tree/binary-indexed-tree.ts +1 -0
  228. package/src/types/data-structures/{binary-tree.ts → binary-tree/binary-tree.ts} +1 -13
  229. package/src/types/data-structures/{bst.ts → binary-tree/bst.ts} +1 -1
  230. package/src/types/data-structures/binary-tree/index.ts +6 -0
  231. package/src/types/data-structures/{rb-tree.ts → binary-tree/rb-tree.ts} +2 -2
  232. package/src/types/data-structures/{tree-multiset.ts → binary-tree/tree-multiset.ts} +1 -1
  233. package/src/types/data-structures/graph/index.ts +3 -0
  234. package/src/types/data-structures/graph/undirected-graph.ts +1 -0
  235. package/src/types/data-structures/hash/coordinate-map.ts +1 -0
  236. package/src/types/data-structures/hash/coordinate-set.ts +1 -0
  237. package/src/types/data-structures/hash/hash-map.ts +1 -0
  238. package/src/types/data-structures/hash/hash-table.ts +1 -0
  239. package/src/types/data-structures/hash/tree-map.ts +1 -0
  240. package/src/types/data-structures/hash/tree-set.ts +1 -0
  241. package/src/types/data-structures/heap/heap.ts +1 -0
  242. package/src/types/data-structures/heap/index.ts +1 -0
  243. package/src/types/data-structures/heap/max-heap.ts +1 -0
  244. package/src/types/data-structures/heap/min-heap.ts +1 -0
  245. package/src/types/data-structures/index.ts +8 -14
  246. package/src/types/data-structures/linked-list/doubly-linked-list.ts +1 -0
  247. package/src/types/data-structures/linked-list/index.ts +2 -0
  248. package/src/types/data-structures/linked-list/singly-linked-list.ts +1 -0
  249. package/src/types/data-structures/linked-list/skip-linked-list.ts +1 -0
  250. package/src/types/data-structures/matrix/index.ts +1 -0
  251. package/src/types/data-structures/matrix/matrix.ts +1 -0
  252. package/src/types/data-structures/matrix/matrix2d.ts +1 -0
  253. package/src/types/data-structures/matrix/vector2d.ts +1 -0
  254. package/src/types/data-structures/priority-queue/index.ts +3 -0
  255. package/src/types/data-structures/priority-queue/max-priority-queue.ts +1 -0
  256. package/src/types/data-structures/priority-queue/min-priority-queue.ts +1 -0
  257. package/src/types/data-structures/priority-queue/priority-queue.ts +1 -0
  258. package/src/types/data-structures/queue/deque.ts +1 -0
  259. package/src/types/data-structures/queue/index.ts +2 -0
  260. package/src/types/data-structures/queue/queue.ts +1 -0
  261. package/src/types/data-structures/stack/index.ts +1 -0
  262. package/src/types/data-structures/stack/stack.ts +1 -0
  263. package/src/types/data-structures/tree/index.ts +1 -0
  264. package/src/types/data-structures/tree/tree.ts +1 -0
  265. package/src/types/data-structures/trie/index.ts +1 -0
  266. package/src/types/data-structures/trie/trie.ts +1 -0
  267. package/src/types/helpers.ts +4 -1
  268. package/src/utils/utils.ts +7 -0
  269. package/test/config.js +4 -0
  270. package/test/types/index.js +29 -0
  271. package/test/types/utils/big-o.js +2 -0
  272. package/test/types/utils/index.js +29 -0
  273. package/test/unit/data-structures/binary-tree/binary-index-tree.test.ts +284 -0
  274. package/test/utils/big-o.js +212 -0
  275. package/test/utils/index.js +30 -0
  276. package/test/utils/number.js +14 -0
  277. package/umd/bundle.min.js +1 -1
  278. package/umd/bundle.min.js.map +1 -1
  279. package/dist/types/data-structures/abstract-graph.js.map +0 -1
  280. package/dist/types/data-structures/avl-tree.js.map +0 -1
  281. package/dist/types/data-structures/binary-tree.js.map +0 -1
  282. package/dist/types/data-structures/bst.js.map +0 -1
  283. package/dist/types/data-structures/directed-graph.js.map +0 -1
  284. package/dist/types/data-structures/doubly-linked-list.js.map +0 -1
  285. package/dist/types/data-structures/hash.js.map +0 -1
  286. package/dist/types/data-structures/heap.js.map +0 -1
  287. package/dist/types/data-structures/map-graph.js.map +0 -1
  288. package/dist/types/data-structures/navigator.js.map +0 -1
  289. package/dist/types/data-structures/rb-tree.js.map +0 -1
  290. package/dist/types/data-structures/segment-tree.js.map +0 -1
  291. package/dist/types/data-structures/singly-linked-list.js.map +0 -1
  292. package/dist/types/data-structures/tree-multiset.js.map +0 -1
  293. /package/dist/types/data-structures/{avl-tree.js → binary-tree/avl-tree.js} +0 -0
  294. /package/dist/types/data-structures/{doubly-linked-list.d.ts → binary-tree/binary-indexed-tree.d.ts} +0 -0
  295. /package/dist/types/data-structures/{binary-tree.js → binary-tree/binary-tree.js} +0 -0
  296. /package/dist/types/data-structures/{bst.js → binary-tree/bst.js} +0 -0
  297. /package/dist/types/data-structures/{rb-tree.js → binary-tree/rb-tree.js} +0 -0
  298. /package/dist/types/data-structures/{segment-tree.d.ts → binary-tree/segment-tree.d.ts} +0 -0
  299. /package/dist/types/data-structures/{segment-tree.js → binary-tree/segment-tree.js} +0 -0
  300. /package/dist/types/data-structures/{tree-multiset.js → binary-tree/tree-multiset.js} +0 -0
  301. /package/dist/types/data-structures/{abstract-graph.d.ts → graph/abstract-graph.d.ts} +0 -0
  302. /package/dist/types/data-structures/{abstract-graph.js → graph/abstract-graph.js} +0 -0
  303. /package/dist/types/data-structures/{directed-graph.d.ts → graph/directed-graph.d.ts} +0 -0
  304. /package/dist/types/data-structures/{directed-graph.js → graph/directed-graph.js} +0 -0
  305. /package/dist/types/data-structures/{map-graph.d.ts → graph/map-graph.d.ts} +0 -0
  306. /package/dist/types/data-structures/{map-graph.js → graph/map-graph.js} +0 -0
  307. /package/dist/types/data-structures/{heap.d.ts → graph/undirected-graph.d.ts} +0 -0
  308. /package/dist/types/data-structures/{singly-linked-list.d.ts → hash/coordinate-map.d.ts} +0 -0
  309. /package/{lib/types/data-structures/abstract-graph.js → dist/types/data-structures/hash/coordinate-set.d.ts} +0 -0
  310. /package/{lib/types/data-structures/avl-tree.js → dist/types/data-structures/hash/hash-map.d.ts} +0 -0
  311. /package/{lib/types/data-structures/doubly-linked-list.d.ts → dist/types/data-structures/hash/hash-table.d.ts} +0 -0
  312. /package/dist/types/data-structures/{hash.d.ts → hash/index.d.ts} +0 -0
  313. /package/{lib/types/data-structures/doubly-linked-list.js → dist/types/data-structures/hash/tree-map.d.ts} +0 -0
  314. /package/{lib/types/data-structures/hash.js → dist/types/data-structures/hash/tree-set.d.ts} +0 -0
  315. /package/{lib/types/data-structures → dist/types/data-structures/heap}/heap.d.ts +0 -0
  316. /package/dist/types/data-structures/{heap.js → heap/heap.js} +0 -0
  317. /package/{lib/types/data-structures/heap.js → dist/types/data-structures/heap/max-heap.d.ts} +0 -0
  318. /package/{lib/types/data-structures/map-graph.js → dist/types/data-structures/heap/min-heap.d.ts} +0 -0
  319. /package/{lib/types/data-structures/navigator.js → dist/types/data-structures/linked-list/doubly-linked-list.d.ts} +0 -0
  320. /package/dist/types/data-structures/{doubly-linked-list.js → linked-list/doubly-linked-list.js} +0 -0
  321. /package/{lib/types/data-structures → dist/types/data-structures/linked-list}/singly-linked-list.d.ts +0 -0
  322. /package/dist/types/data-structures/{singly-linked-list.js → linked-list/singly-linked-list.js} +0 -0
  323. /package/{lib/types/data-structures/segment-tree.js → dist/types/data-structures/linked-list/skip-linked-list.d.ts} +0 -0
  324. /package/{lib/types/data-structures/singly-linked-list.js → dist/types/data-structures/matrix/matrix.d.ts} +0 -0
  325. /package/{lib/types/data-structures/tree-multiset.js → dist/types/data-structures/matrix/matrix2d.d.ts} +0 -0
  326. /package/dist/types/data-structures/{navigator.d.ts → matrix/navigator.d.ts} +0 -0
  327. /package/dist/types/data-structures/{navigator.js → matrix/navigator.js} +0 -0
  328. /package/{src/types/data-structures/doubly-linked-list.ts → dist/types/data-structures/matrix/vector2d.d.ts} +0 -0
  329. /package/{src/types/data-structures/heap.ts → dist/types/data-structures/priority-queue/max-priority-queue.d.ts} +0 -0
  330. /package/{src/types/data-structures/singly-linked-list.ts → dist/types/data-structures/priority-queue/min-priority-queue.d.ts} +0 -0
  331. /package/lib/types/data-structures/{binary-tree.js → binary-tree/binary-tree.js} +0 -0
  332. /package/lib/types/data-structures/{bst.js → binary-tree/bst.js} +0 -0
  333. /package/lib/types/data-structures/{rb-tree.js → binary-tree/rb-tree.js} +0 -0
  334. /package/lib/types/data-structures/{segment-tree.d.ts → binary-tree/segment-tree.d.ts} +0 -0
  335. /package/lib/types/data-structures/{abstract-graph.d.ts → graph/abstract-graph.d.ts} +0 -0
  336. /package/lib/types/data-structures/{directed-graph.d.ts → graph/directed-graph.d.ts} +0 -0
  337. /package/lib/types/data-structures/{directed-graph.js → graph/directed-graph.js} +0 -0
  338. /package/lib/types/data-structures/{map-graph.d.ts → graph/map-graph.d.ts} +0 -0
  339. /package/lib/types/data-structures/{hash.d.ts → hash/index.d.ts} +0 -0
  340. /package/lib/types/data-structures/{navigator.d.ts → matrix/navigator.d.ts} +0 -0
  341. /package/src/types/data-structures/{segment-tree.ts → binary-tree/segment-tree.ts} +0 -0
  342. /package/src/types/data-structures/{abstract-graph.ts → graph/abstract-graph.ts} +0 -0
  343. /package/src/types/data-structures/{directed-graph.ts → graph/directed-graph.ts} +0 -0
  344. /package/src/types/data-structures/{map-graph.ts → graph/map-graph.ts} +0 -0
  345. /package/src/types/data-structures/{hash.ts → hash/index.ts} +0 -0
  346. /package/src/types/data-structures/{navigator.ts → matrix/navigator.ts} +0 -0
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export * from './stack';
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export * from './tree';
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export * from './trie';
@@ -0,0 +1 @@
1
+ export {};
@@ -1,4 +1,7 @@
1
1
  export type Comparator<T> = (a: T, b: T) => number;
2
2
 
3
- // export enum DFSOrderPattern {'pre' = 'pre', 'in' = 'in', 'post' = 'post'}
4
3
  export type DFSOrderPattern = 'pre' | 'in' | 'post';
4
+
5
+ export type MapCallback<N> = (node: N) => any;
6
+
7
+ export type MapCallbackReturn<N> = ReturnType<MapCallback<N>>;
@@ -77,3 +77,10 @@ export const trampolineAsync = (fn: TrlAsyncFn) => {
77
77
  {cont}
78
78
  );
79
79
  };
80
+
81
+ export const getMSB = (value: number): number => {
82
+ if (value <= 0) {
83
+ return 0;
84
+ }
85
+ return 1 << (31 - Math.clz32(value));
86
+ };
package/test/config.js ADDED
@@ -0,0 +1,4 @@
1
+ 'use strict';
2
+ Object.defineProperty(exports, '__esModule', {value: true});
3
+ exports.isDebugTest = void 0;
4
+ exports.isDebugTest = false;
@@ -0,0 +1,29 @@
1
+ 'use strict';
2
+ var __createBinding =
3
+ (this && this.__createBinding) ||
4
+ (Object.create
5
+ ? function (o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ var desc = Object.getOwnPropertyDescriptor(m, k);
8
+ if (!desc || ('get' in desc ? !m.__esModule : desc.writable || desc.configurable)) {
9
+ desc = {
10
+ enumerable: true,
11
+ get: function () {
12
+ return m[k];
13
+ }
14
+ };
15
+ }
16
+ Object.defineProperty(o, k2, desc);
17
+ }
18
+ : function (o, m, k, k2) {
19
+ if (k2 === undefined) k2 = k;
20
+ o[k2] = m[k];
21
+ });
22
+ var __exportStar =
23
+ (this && this.__exportStar) ||
24
+ function (m, exports) {
25
+ for (var p in m)
26
+ if (p !== 'default' && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
27
+ };
28
+ Object.defineProperty(exports, '__esModule', {value: true});
29
+ __exportStar(require('./utils'), exports);
@@ -0,0 +1,2 @@
1
+ 'use strict';
2
+ Object.defineProperty(exports, '__esModule', {value: true});
@@ -0,0 +1,29 @@
1
+ 'use strict';
2
+ var __createBinding =
3
+ (this && this.__createBinding) ||
4
+ (Object.create
5
+ ? function (o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ var desc = Object.getOwnPropertyDescriptor(m, k);
8
+ if (!desc || ('get' in desc ? !m.__esModule : desc.writable || desc.configurable)) {
9
+ desc = {
10
+ enumerable: true,
11
+ get: function () {
12
+ return m[k];
13
+ }
14
+ };
15
+ }
16
+ Object.defineProperty(o, k2, desc);
17
+ }
18
+ : function (o, m, k, k2) {
19
+ if (k2 === undefined) k2 = k;
20
+ o[k2] = m[k];
21
+ });
22
+ var __exportStar =
23
+ (this && this.__exportStar) ||
24
+ function (m, exports) {
25
+ for (var p in m)
26
+ if (p !== 'default' && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
27
+ };
28
+ Object.defineProperty(exports, '__esModule', {value: true});
29
+ __exportStar(require('./big-o'), exports);
@@ -0,0 +1,284 @@
1
+ import {BinaryIndexedTree} from '../../../../src';
2
+ import {isDebugTest} from '../../../config';
3
+
4
+ const isDebug = isDebugTest;
5
+
6
+ describe('BinaryIndexedTree simple', () => {
7
+ let bit: BinaryIndexedTree;
8
+
9
+ beforeEach(() => {
10
+ //Create a new BinaryIndexedTree instance before each test case
11
+ bit = new BinaryIndexedTree({frequency: 0, max: 10}); // Modify the value of max as needed
12
+ });
13
+
14
+ it('should initialize correctly', () => {
15
+ expect(bit.freq).toBe(0);
16
+ expect(bit.max).toBe(10);
17
+ expect(bit.freqMap).toEqual({0: 0}); // Modify the initialized record value according to the actual situation
18
+ // More initialization checks can be added
19
+ });
20
+
21
+ it('should read a single value correctly', () => {
22
+ // Test the function of reading a single value
23
+ bit.writeSingle(5, 5); //Write test data
24
+ expect(bit.readSingle(5)).toBe(5); // Read and verify
25
+ });
26
+
27
+ it('should update a value correctly', () => {
28
+ // Test the ability to update a single value
29
+ bit.writeSingle(5, 5); //Write test data
30
+ bit.update(5, 2); // update value
31
+ expect(bit.readSingle(5)).toBe(7); // Verify the updated value
32
+ });
33
+
34
+ it('should find lower bound correctly', () => {
35
+ //Test the function of finding the lower bound
36
+ bit.writeSingle(2, 10);
37
+ bit.writeSingle(5, 20);
38
+ bit.writeSingle(8, 30);
39
+ expect(bit.lowerBound(15)).toBe(5); // Find and verify the lower bound
40
+ });
41
+
42
+ it('should find upper bound correctly', () => {
43
+ //Test the function of finding the upper bound
44
+ bit.writeSingle(2, 10);
45
+ bit.writeSingle(5, 20);
46
+ bit.writeSingle(8, 30);
47
+ expect(bit.upperBound(25)).toBe(5); // Find and verify the upper bound
48
+ });
49
+ });
50
+
51
+ describe('BinaryIndexedTree', () => {
52
+ const frequency = 999;
53
+ const max = 10;
54
+ let bit: BinaryIndexedTree;
55
+
56
+ beforeEach(function () {
57
+ bit = new BinaryIndexedTree({frequency, max});
58
+ });
59
+ it('should validate the index', function () {
60
+ expect(() => bit.readSingle(-1)).toThrow('Index out of range');
61
+ expect(() => bit.readSingle(10)).toThrow('Index out of range');
62
+ });
63
+
64
+ it('should read a single frequency correctly', function () {
65
+ for (let i = 0; i < max; i++) {
66
+ expect(bit.readSingle(i)).toBe(frequency);
67
+ }
68
+ });
69
+ it('should validate the index', function () {
70
+ expect(() => bit.update(-1, 100)).toThrow('Index out of range');
71
+ expect(() => bit.update(10, 100)).toThrow('Index out of range');
72
+ });
73
+ it('should frequency and max', function () {
74
+ const frequency = 200;
75
+ const max = 1000;
76
+ const bit = new BinaryIndexedTree({frequency, max});
77
+
78
+ expect(bit.freq).toBe(frequency);
79
+ expect(bit.max).toBe(max);
80
+ });
81
+
82
+ it('should update the frequency with the given delta', function () {
83
+ for (let i = 0; i < max; i++) {
84
+ bit.update(i, i * 2);
85
+ }
86
+ for (let i = 0; i < max; i++) {
87
+ expect(bit.readSingle(i)).toBe(i * 2 + frequency);
88
+ }
89
+ });
90
+ it('should validate the index', function () {
91
+ expect(() => bit.writeSingle(-1, 100)).toThrow('Index out of range');
92
+ expect(() => bit.writeSingle(10, 100)).toThrow('Index out of range');
93
+ });
94
+
95
+ it('should writeSingle to be correctly invoked', function () {
96
+ for (let i = 0; i < max; i++) {
97
+ bit.writeSingle(i, i * 2);
98
+ }
99
+ for (let i = 0; i < max; i++) {
100
+ expect(bit.readSingle(i)).toBe(i * 2);
101
+ }
102
+ });
103
+
104
+ it('should read the frequency', function () {
105
+ for (let c = 0; c <= max; c++) {
106
+ expect(bit.read(c)).toBe(c * frequency);
107
+ }
108
+ });
109
+
110
+ const values = [-5, 0, 5, 10, 95, 100, 1000];
111
+ it('should find the upper-bound index', function () {
112
+ loopUpperBoundTests(bit, values);
113
+ });
114
+
115
+ it('should find the lower-bound index', function () {
116
+ loopLowerBoundTests(bit, values);
117
+ });
118
+ });
119
+
120
+ describe('designated values', function () {
121
+ const array = [1, 8, 6, 10, 7, 9, 0, 2, 6, 3];
122
+ const sumArray = (sum => array.map(value => (sum += value)))(0);
123
+ let bit: BinaryIndexedTree;
124
+
125
+ beforeEach(function () {
126
+ bit = new BinaryIndexedTree({max: array.length});
127
+ array.forEach((value, i) => bit.writeSingle(i, value));
128
+ });
129
+
130
+ describe('readSingle', function () {
131
+ it('should read a single frequency correctly', function () {
132
+ array.forEach((value, i) => {
133
+ expect(bit.readSingle(i)).toBe(array[i]);
134
+ });
135
+ });
136
+ });
137
+
138
+ describe('update', function () {
139
+ it('should update the frequency with the given delta', function () {
140
+ array.forEach((value, i) => bit.update(i, value + i));
141
+ array.forEach((value, i) => {
142
+ expect(bit.readSingle(i)).toBe(array[i] * 2 + i);
143
+ });
144
+ });
145
+ });
146
+
147
+ describe('writeSingle', function () {
148
+ it('should write a single frequency correctly', function () {
149
+ array.forEach((value, i) => bit.writeSingle(i, value + i));
150
+ array.forEach((value, i) => {
151
+ expect(bit.readSingle(i)).toBe(array[i] + i);
152
+ });
153
+ });
154
+ });
155
+
156
+ describe('read', function () {
157
+ it('should read the cumulative frequency correctly', function () {
158
+ expect(bit.read(0)).toBe(0);
159
+ sumArray.forEach((sum, i) => {
160
+ expect(bit.read(i + 1)).toBe(sum);
161
+ });
162
+ });
163
+ });
164
+
165
+ const values = [-5, 0, 15, 25, 43, 53, 100];
166
+
167
+ describe('upperBound', function () {
168
+ it('should find the upper-bound index', function () {
169
+ loopUpperBoundTests(bit, values);
170
+ });
171
+ });
172
+
173
+ describe('lowerBound', function () {
174
+ it('should find the lower-bound index', function () {
175
+ loopLowerBoundTests(bit, values);
176
+ });
177
+ });
178
+ });
179
+
180
+ describe('descending sequence', function () {
181
+ const array = [1, 8, -6, 10, 7, 9, 0, -2, 6, 3];
182
+ let bit: BinaryIndexedTree;
183
+
184
+ beforeEach(function () {
185
+ bit = new BinaryIndexedTree({max: array.length});
186
+ array.forEach((value, i) => bit.writeSingle(i, value));
187
+ });
188
+
189
+ it('should have a correct negativeCount property', function () {
190
+ expect(bit.negativeCount).toBe(2);
191
+ bit.update(2, 6);
192
+ expect(bit.negativeCount).toBe(1);
193
+ bit.update(7, 3);
194
+ expect(bit.negativeCount).toBe(0);
195
+ bit.update(8, -7);
196
+ expect(bit.negativeCount).toBe(1);
197
+ });
198
+
199
+ const values = [-5, 0, 15, 25, 43, 53, 100];
200
+
201
+ describe('upperBound', function () {
202
+ it('should validate the non-descending', function () {
203
+ expect(() => bit.upperBound(20)).toThrow('Must not be descending');
204
+ bit.update(2, 12);
205
+ bit.update(7, 4);
206
+ loopUpperBoundTests(bit, values);
207
+ });
208
+ });
209
+
210
+ describe('BinaryIndexedTree lowerBound', function () {
211
+ it('should validate the non-descending', function () {
212
+ expect(() => bit.lowerBound(20)).toThrow('Sequence is not non-descending');
213
+ bit.update(2, 12);
214
+ bit.update(7, 4);
215
+ loopLowerBoundTests(bit, values);
216
+ });
217
+ });
218
+ });
219
+
220
+ describe('BinaryIndexedTree additional tests', () => {
221
+ it('should handle read method correctly', () => {
222
+ const bit = new BinaryIndexedTree({max: 10});
223
+ bit.writeSingle(2, 10);
224
+ bit.writeSingle(5, 20);
225
+ bit.writeSingle(8, 30);
226
+ expect(bit.read(5)).toBe(10); // Ensure read method accumulates correctly
227
+ });
228
+
229
+ it('should handle consecutive operations', () => {
230
+ const bit = new BinaryIndexedTree({max: 10});
231
+ bit.writeSingle(2, 10);
232
+ bit.update(2, 5);
233
+ expect(bit.readSingle(2)).toBe(15);
234
+ bit.writeSingle(5, 20);
235
+ expect(bit.readSingle(5)).toBe(20);
236
+ expect(bit.lowerBound(15)).toBe(2);
237
+ });
238
+
239
+ it('should handle frequent increment updates', () => {
240
+ const bit = new BinaryIndexedTree({max: 10});
241
+ for (let i = 0; i < 10; i++) {
242
+ bit.update(2, 5);
243
+ }
244
+ expect(bit.readSingle(2)).toBe(50);
245
+ });
246
+
247
+ it('should handle edge cases', () => {
248
+ const bit = new BinaryIndexedTree({max: 10});
249
+ bit.writeSingle(9, 100);
250
+ expect(bit.readSingle(9)).toBe(100);
251
+ expect(bit.lowerBound(200)).toBe(10);
252
+ });
253
+ });
254
+ function loopUpperBoundTests(bit: BinaryIndexedTree, values: number[]) {
255
+ for (const value of values) {
256
+ const index = bit.upperBound(value);
257
+ if (index > 0) {
258
+ expect(bit.read(index)).toBeLessThanOrEqual(value);
259
+ } else {
260
+ expect(index).toBe(0);
261
+ }
262
+ if (index < bit.max) {
263
+ expect(bit.read(index + 1)).toBeGreaterThan(value);
264
+ } else {
265
+ expect(index).toBe(bit.max);
266
+ }
267
+ }
268
+ }
269
+
270
+ function loopLowerBoundTests(bit: BinaryIndexedTree, values: number[]) {
271
+ for (const value of values) {
272
+ const index = bit.lowerBound(value);
273
+ if (index > 0) {
274
+ expect(bit.read(index)).toBeLessThan(value);
275
+ } else {
276
+ expect(index).toBe(0);
277
+ }
278
+ if (index < bit.max) {
279
+ expect(bit.read(index + 1)).toBeGreaterThanOrEqual(value);
280
+ } else {
281
+ expect(index).toBe(bit.max);
282
+ }
283
+ }
284
+ }
@@ -0,0 +1,212 @@
1
+ 'use strict';
2
+ Object.defineProperty(exports, '__esModule', {value: true});
3
+ exports.logBigOMetrics = exports.logBigOMetricsWrap = exports.bigO = exports.magnitude = void 0;
4
+ var config_1 = require('../config');
5
+
6
+ var isDebug = config_1.isDebugTest;
7
+ var orderReducedBy = 2; // reduction of bigO's order compared to the baseline bigO
8
+ exports.magnitude = {
9
+ CONSTANT: Math.floor(Number.MAX_SAFE_INTEGER / Math.pow(10, orderReducedBy)),
10
+ LOG_N: Math.pow(10, 9 - orderReducedBy),
11
+ LINEAR: Math.pow(10, 6 - orderReducedBy),
12
+ N_LOG_N: Math.pow(10, 5 - orderReducedBy),
13
+ SQUARED: Math.pow(10, 4 - orderReducedBy),
14
+ CUBED: Math.pow(10, 3 - orderReducedBy),
15
+ FACTORIAL: 20 - orderReducedBy
16
+ };
17
+ exports.bigO = {
18
+ CONSTANT: exports.magnitude.CONSTANT / 100000,
19
+ LOG_N: Math.log2(exports.magnitude.LOG_N) / 1000,
20
+ LINEAR: exports.magnitude.LINEAR / 1000,
21
+ N_LOG_N: (exports.magnitude.N_LOG_N * Math.log2(exports.magnitude.LOG_N)) / 1000,
22
+ SQUARED: Math.pow(exports.magnitude.SQUARED, 2) / 1000,
23
+ CUBED: Math.pow(exports.magnitude.SQUARED, 3) / 1000,
24
+ FACTORIAL: 10000
25
+ };
26
+ function findPotentialN(input) {
27
+ var longestArray = [];
28
+ var mostProperties = {};
29
+ function recurse(obj) {
30
+ if (Array.isArray(obj)) {
31
+ if (obj.length > longestArray.length) {
32
+ longestArray = obj;
33
+ }
34
+ } else if (typeof obj === 'object' && obj !== null) {
35
+ var keys = Object.keys(obj);
36
+ if (keys.length > Object.keys(mostProperties).length) {
37
+ mostProperties = obj;
38
+ }
39
+ keys.forEach(function (key) {
40
+ recurse(obj[key]);
41
+ });
42
+ }
43
+ }
44
+ if (Array.isArray(input)) {
45
+ input.forEach(function (item) {
46
+ recurse(item);
47
+ });
48
+ } else {
49
+ recurse(input);
50
+ }
51
+ // return [longestArray, mostProperties] : [any[], { [key: string]: any }];
52
+ return Math.max(longestArray.length, Object.keys(mostProperties).length);
53
+ }
54
+ function linearRegression(x, y) {
55
+ var n = x.length;
56
+ var sumX = x.reduce(function (acc, val) {
57
+ return acc + val;
58
+ }, 0);
59
+ var sumY = y.reduce(function (acc, val) {
60
+ return acc + val;
61
+ }, 0);
62
+ var sumXSquared = x.reduce(function (acc, val) {
63
+ return acc + Math.pow(val, 2);
64
+ }, 0);
65
+ var sumXY = x.reduce(function (acc, val, i) {
66
+ return acc + val * y[i];
67
+ }, 0);
68
+ var slope = (n * sumXY - sumX * sumY) / (n * sumXSquared - Math.pow(sumX, 2));
69
+ var intercept = (sumY - slope * sumX) / n;
70
+ var yHat = x.map(function (val) {
71
+ return slope * val + intercept;
72
+ });
73
+ var totalVariation = y
74
+ .map(function (val, i) {
75
+ return Math.pow(val - yHat[i], 2);
76
+ })
77
+ .reduce(function (acc, val) {
78
+ return acc + val;
79
+ }, 0);
80
+ var explainedVariation = y
81
+ .map(function (val) {
82
+ return Math.pow(val - sumY / n, 2);
83
+ })
84
+ .reduce(function (acc, val) {
85
+ return acc + val;
86
+ }, 0);
87
+ var rSquared = 1 - totalVariation / explainedVariation;
88
+ return {slope: slope, intercept: intercept, rSquared: rSquared};
89
+ }
90
+ function estimateBigO(runtimes, dataSizes) {
91
+ // Make sure the input runtimes and data sizes have the same length
92
+ if (runtimes.length !== dataSizes.length) {
93
+ return 'Lengths of input arrays do not match';
94
+ }
95
+ // Create an array to store the computational complexity of each data point
96
+ var complexities = [];
97
+ // Traverse different possible complexities
98
+ var complexitiesToCheck = [
99
+ 'O(1)',
100
+ 'O(log n)',
101
+ 'O(n)',
102
+ 'O(n log n)',
103
+ 'O(n^2)' // squared time complexity
104
+ ];
105
+ var _loop_1 = function (complexity) {
106
+ // Calculate data points for fitting
107
+ var fittedData = dataSizes.map(function (size) {
108
+ if (complexity === 'O(1)') {
109
+ return 1; // constant time complexity
110
+ } else if (complexity === 'O(log n)') {
111
+ return Math.log(size);
112
+ } else if (complexity === 'O(n)') {
113
+ return size;
114
+ } else if (complexity === 'O(n log n)') {
115
+ return size * Math.log(size);
116
+ } else if (complexity === 'O(n^2)') {
117
+ return Math.pow(size, 2);
118
+ } else {
119
+ return Math.pow(size, 10);
120
+ }
121
+ });
122
+ // Fit the data points using linear regression analysis
123
+ var regressionResult = linearRegression(fittedData, runtimes);
124
+ // Check the R-squared value of the fit. It is usually considered a valid fit if it is greater than 0.9.
125
+ if (regressionResult.rSquared >= 0.9) {
126
+ complexities.push(complexity);
127
+ }
128
+ };
129
+ for (var _i = 0, complexitiesToCheck_1 = complexitiesToCheck; _i < complexitiesToCheck_1.length; _i++) {
130
+ var complexity = complexitiesToCheck_1[_i];
131
+ _loop_1(complexity);
132
+ }
133
+ // If there is no valid fitting result, return "cannot estimate", otherwise return the estimated time complexity
134
+ if (complexities.length === 0) {
135
+ return 'Unable to estimate';
136
+ } else {
137
+ return complexities.join(' or ');
138
+ }
139
+ }
140
+ var methodLogs = new Map();
141
+ function logBigOMetricsWrap(fn, args, fnName) {
142
+ var startTime = performance.now();
143
+ var result = fn(args);
144
+ var endTime = performance.now();
145
+ var runTime = endTime - startTime;
146
+ var methodName = ''.concat(fnName);
147
+ if (!methodLogs.has(methodName)) {
148
+ methodLogs.set(methodName, []);
149
+ }
150
+ var methodLog = methodLogs.get(methodName);
151
+ var maxDataSize = args.length === 1 && typeof args[0] === 'number' ? args[0] : findPotentialN(args);
152
+ if (methodLog) {
153
+ methodLog.push([runTime, maxDataSize]);
154
+ if (methodLog.length >= 20) {
155
+ isDebug && console.log('triggered', methodName, methodLog);
156
+ var bigO_1 = estimateBigO(
157
+ methodLog.map(function (_a) {
158
+ var runTime = _a[0];
159
+ return runTime;
160
+ }),
161
+ methodLog.map(function (_a) {
162
+ var runTime = _a[0];
163
+ return runTime;
164
+ })
165
+ );
166
+ isDebug && console.log('Estimated Big O: '.concat(bigO_1));
167
+ methodLogs.delete(methodName);
168
+ }
169
+ }
170
+ return result;
171
+ }
172
+ exports.logBigOMetricsWrap = logBigOMetricsWrap;
173
+ function logBigOMetrics(target, propertyKey, descriptor) {
174
+ var originalMethod = descriptor.value;
175
+ descriptor.value = function () {
176
+ var args = [];
177
+ for (var _i = 0; _i < arguments.length; _i++) {
178
+ args[_i] = arguments[_i];
179
+ }
180
+ var startTime = performance.now();
181
+ var result = originalMethod.apply(this, args);
182
+ var endTime = performance.now();
183
+ var runTime = endTime - startTime;
184
+ var methodName = ''.concat(target.constructor.name, '.').concat(propertyKey);
185
+ if (!methodLogs.has(methodName)) {
186
+ methodLogs.set(methodName, []);
187
+ }
188
+ var methodLog = methodLogs.get(methodName);
189
+ var maxDataSize = args.length === 1 && typeof args[0] === 'number' ? args[0] : findPotentialN(args);
190
+ if (methodLog) {
191
+ methodLog.push([runTime, maxDataSize]);
192
+ if (methodLog.length >= 20) {
193
+ isDebug && console.log('triggered', methodName, methodLog);
194
+ var bigO_2 = estimateBigO(
195
+ methodLog.map(function (_a) {
196
+ var runTime = _a[0];
197
+ return runTime;
198
+ }),
199
+ methodLog.map(function (_a) {
200
+ var runTime = _a[0];
201
+ return runTime;
202
+ })
203
+ );
204
+ isDebug && console.log('Estimated Big O: '.concat(bigO_2));
205
+ methodLogs.delete(methodName);
206
+ }
207
+ }
208
+ return result;
209
+ };
210
+ return descriptor;
211
+ }
212
+ exports.logBigOMetrics = logBigOMetrics;
@@ -0,0 +1,30 @@
1
+ 'use strict';
2
+ var __createBinding =
3
+ (this && this.__createBinding) ||
4
+ (Object.create
5
+ ? function (o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ var desc = Object.getOwnPropertyDescriptor(m, k);
8
+ if (!desc || ('get' in desc ? !m.__esModule : desc.writable || desc.configurable)) {
9
+ desc = {
10
+ enumerable: true,
11
+ get: function () {
12
+ return m[k];
13
+ }
14
+ };
15
+ }
16
+ Object.defineProperty(o, k2, desc);
17
+ }
18
+ : function (o, m, k, k2) {
19
+ if (k2 === undefined) k2 = k;
20
+ o[k2] = m[k];
21
+ });
22
+ var __exportStar =
23
+ (this && this.__exportStar) ||
24
+ function (m, exports) {
25
+ for (var p in m)
26
+ if (p !== 'default' && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
27
+ };
28
+ Object.defineProperty(exports, '__esModule', {value: true});
29
+ __exportStar(require('./number'), exports);
30
+ __exportStar(require('./big-o'), exports);
@@ -0,0 +1,14 @@
1
+ 'use strict';
2
+ Object.defineProperty(exports, '__esModule', {value: true});
3
+ exports.getMSB = exports.getRandomInt = void 0;
4
+ function getRandomInt(min, max) {
5
+ return Math.floor(Math.random() * (max - min + 1)) + min;
6
+ }
7
+ exports.getRandomInt = getRandomInt;
8
+ var getMSB = function (value) {
9
+ if (value <= 0) {
10
+ return 0;
11
+ }
12
+ return 1 << (31 - Math.clz32(value));
13
+ };
14
+ exports.getMSB = getMSB;