ts-data-forge 9.0.0 → 10.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (447) hide show
  1. package/README.md +1 -1
  2. package/dist/array/impl/array-utils-creation.d.mts +4 -4
  3. package/dist/array/impl/array-utils-creation.d.mts.map +1 -1
  4. package/dist/array/impl/array-utils-creation.mjs +17 -112
  5. package/dist/array/impl/array-utils-creation.mjs.map +1 -1
  6. package/dist/array/impl/array-utils-element-access.d.mts.map +1 -1
  7. package/dist/array/impl/array-utils-element-access.mjs +22 -61
  8. package/dist/array/impl/array-utils-element-access.mjs.map +1 -1
  9. package/dist/array/impl/array-utils-iterators.d.mts.map +1 -1
  10. package/dist/array/impl/array-utils-iterators.mjs +9 -63
  11. package/dist/array/impl/array-utils-iterators.mjs.map +1 -1
  12. package/dist/array/impl/array-utils-modification.d.mts +7 -7
  13. package/dist/array/impl/array-utils-modification.d.mts.map +1 -1
  14. package/dist/array/impl/array-utils-modification.mjs +78 -78
  15. package/dist/array/impl/array-utils-modification.mjs.map +1 -1
  16. package/dist/array/impl/array-utils-reducing-value.mjs +95 -89
  17. package/dist/array/impl/array-utils-reducing-value.mjs.map +1 -1
  18. package/dist/array/impl/array-utils-search.mjs +100 -92
  19. package/dist/array/impl/array-utils-search.mjs.map +1 -1
  20. package/dist/array/impl/array-utils-set-op.d.mts.map +1 -1
  21. package/dist/array/impl/array-utils-set-op.mjs +31 -141
  22. package/dist/array/impl/array-utils-set-op.mjs.map +1 -1
  23. package/dist/array/impl/array-utils-size.d.mts.map +1 -1
  24. package/dist/array/impl/array-utils-size.mjs +4 -8
  25. package/dist/array/impl/array-utils-size.mjs.map +1 -1
  26. package/dist/array/impl/array-utils-slice-clamped.mjs +11 -12
  27. package/dist/array/impl/array-utils-slice-clamped.mjs.map +1 -1
  28. package/dist/array/impl/array-utils-slicing.d.mts.map +1 -1
  29. package/dist/array/impl/array-utils-slicing.mjs +44 -96
  30. package/dist/array/impl/array-utils-slicing.mjs.map +1 -1
  31. package/dist/array/impl/array-utils-transformation.d.mts +4 -4
  32. package/dist/array/impl/array-utils-transformation.d.mts.map +1 -1
  33. package/dist/array/impl/array-utils-transformation.mjs +150 -292
  34. package/dist/array/impl/array-utils-transformation.mjs.map +1 -1
  35. package/dist/array/impl/array-utils-validation.d.mts +17 -17
  36. package/dist/array/impl/array-utils-validation.d.mts.map +1 -1
  37. package/dist/array/impl/array-utils-validation.mjs +23 -174
  38. package/dist/array/impl/array-utils-validation.mjs.map +1 -1
  39. package/dist/array/impl/index.mjs +1 -1
  40. package/dist/collections/imap-mapped.d.mts.map +1 -1
  41. package/dist/collections/imap-mapped.mjs +243 -330
  42. package/dist/collections/imap-mapped.mjs.map +1 -1
  43. package/dist/collections/imap.d.mts.map +1 -1
  44. package/dist/collections/imap.mjs +190 -275
  45. package/dist/collections/imap.mjs.map +1 -1
  46. package/dist/collections/iset-mapped.d.mts +1 -1
  47. package/dist/collections/iset-mapped.d.mts.map +1 -1
  48. package/dist/collections/iset-mapped.mjs +222 -444
  49. package/dist/collections/iset-mapped.mjs.map +1 -1
  50. package/dist/collections/iset.d.mts +1 -1
  51. package/dist/collections/iset.d.mts.map +1 -1
  52. package/dist/collections/iset.mjs +158 -324
  53. package/dist/collections/iset.mjs.map +1 -1
  54. package/dist/collections/queue.d.mts.map +1 -1
  55. package/dist/collections/queue.mjs +106 -178
  56. package/dist/collections/queue.mjs.map +1 -1
  57. package/dist/collections/stack.d.mts.map +1 -1
  58. package/dist/collections/stack.mjs +95 -165
  59. package/dist/collections/stack.mjs.map +1 -1
  60. package/dist/entry-point.mjs +2 -0
  61. package/dist/entry-point.mjs.map +1 -1
  62. package/dist/expect-type.d.mts +1 -1
  63. package/dist/expect-type.d.mts.map +1 -1
  64. package/dist/expect-type.mjs +1 -69
  65. package/dist/expect-type.mjs.map +1 -1
  66. package/dist/functional/match.mjs +9 -9
  67. package/dist/functional/match.mjs.map +1 -1
  68. package/dist/functional/optional/impl/optional-expect-to-be.mjs +13 -14
  69. package/dist/functional/optional/impl/optional-expect-to-be.mjs.map +1 -1
  70. package/dist/functional/optional/impl/optional-filter.mjs +14 -15
  71. package/dist/functional/optional/impl/optional-filter.mjs.map +1 -1
  72. package/dist/functional/optional/impl/optional-flat-map.mjs +10 -11
  73. package/dist/functional/optional/impl/optional-flat-map.mjs.map +1 -1
  74. package/dist/functional/optional/impl/optional-from-nullable.d.mts.map +1 -1
  75. package/dist/functional/optional/impl/optional-from-nullable.mjs +1 -25
  76. package/dist/functional/optional/impl/optional-from-nullable.mjs.map +1 -1
  77. package/dist/functional/optional/impl/optional-is-none.d.mts.map +1 -1
  78. package/dist/functional/optional/impl/optional-is-none.mjs +0 -19
  79. package/dist/functional/optional/impl/optional-is-none.mjs.map +1 -1
  80. package/dist/functional/optional/impl/optional-is-optional.d.mts.map +1 -1
  81. package/dist/functional/optional/impl/optional-is-optional.mjs +1 -23
  82. package/dist/functional/optional/impl/optional-is-optional.mjs.map +1 -1
  83. package/dist/functional/optional/impl/optional-is-some.d.mts.map +1 -1
  84. package/dist/functional/optional/impl/optional-is-some.mjs +0 -20
  85. package/dist/functional/optional/impl/optional-is-some.mjs.map +1 -1
  86. package/dist/functional/optional/impl/optional-map.mjs +13 -14
  87. package/dist/functional/optional/impl/optional-map.mjs.map +1 -1
  88. package/dist/functional/optional/impl/optional-none.mjs +0 -16
  89. package/dist/functional/optional/impl/optional-none.mjs.map +1 -1
  90. package/dist/functional/optional/impl/optional-or-else.mjs +10 -11
  91. package/dist/functional/optional/impl/optional-or-else.mjs.map +1 -1
  92. package/dist/functional/optional/impl/optional-some.d.mts.map +1 -1
  93. package/dist/functional/optional/impl/optional-some.mjs +2 -21
  94. package/dist/functional/optional/impl/optional-some.mjs.map +1 -1
  95. package/dist/functional/optional/impl/optional-to-nullable.d.mts.map +1 -1
  96. package/dist/functional/optional/impl/optional-to-nullable.mjs +1 -27
  97. package/dist/functional/optional/impl/optional-to-nullable.mjs.map +1 -1
  98. package/dist/functional/optional/impl/optional-unwrap-or.mjs +9 -10
  99. package/dist/functional/optional/impl/optional-unwrap-or.mjs.map +1 -1
  100. package/dist/functional/optional/impl/optional-unwrap-throw.d.mts.map +1 -1
  101. package/dist/functional/optional/impl/optional-unwrap-throw.mjs +4 -32
  102. package/dist/functional/optional/impl/optional-unwrap-throw.mjs.map +1 -1
  103. package/dist/functional/optional/impl/optional-unwrap.mjs +4 -4
  104. package/dist/functional/optional/impl/optional-unwrap.mjs.map +1 -1
  105. package/dist/functional/optional/impl/optional-zip.d.mts.map +1 -1
  106. package/dist/functional/optional/impl/optional-zip.mjs +1 -35
  107. package/dist/functional/optional/impl/optional-zip.mjs.map +1 -1
  108. package/dist/functional/optional/impl/tag.mjs +2 -3
  109. package/dist/functional/optional/impl/tag.mjs.map +1 -1
  110. package/dist/functional/pipe.d.mts.map +1 -1
  111. package/dist/functional/pipe.mjs +9 -34
  112. package/dist/functional/pipe.mjs.map +1 -1
  113. package/dist/functional/result/impl/result-err.d.mts.map +1 -1
  114. package/dist/functional/result/impl/result-err.mjs +2 -27
  115. package/dist/functional/result/impl/result-err.mjs.map +1 -1
  116. package/dist/functional/result/impl/result-expect-to-be.mjs +13 -15
  117. package/dist/functional/result/impl/result-expect-to-be.mjs.map +1 -1
  118. package/dist/functional/result/impl/result-flat-map.mjs +16 -16
  119. package/dist/functional/result/impl/result-flat-map.mjs.map +1 -1
  120. package/dist/functional/result/impl/result-fold.mjs +16 -16
  121. package/dist/functional/result/impl/result-fold.mjs.map +1 -1
  122. package/dist/functional/result/impl/result-from-promise.d.mts.map +1 -1
  123. package/dist/functional/result/impl/result-from-promise.mjs +4 -31
  124. package/dist/functional/result/impl/result-from-promise.mjs.map +1 -1
  125. package/dist/functional/result/impl/result-from-throwable.d.mts.map +1 -1
  126. package/dist/functional/result/impl/result-from-throwable.mjs +8 -38
  127. package/dist/functional/result/impl/result-from-throwable.mjs.map +1 -1
  128. package/dist/functional/result/impl/result-is-err.d.mts.map +1 -1
  129. package/dist/functional/result/impl/result-is-err.mjs +0 -19
  130. package/dist/functional/result/impl/result-is-err.mjs.map +1 -1
  131. package/dist/functional/result/impl/result-is-ok.d.mts.map +1 -1
  132. package/dist/functional/result/impl/result-is-ok.mjs +0 -19
  133. package/dist/functional/result/impl/result-is-ok.mjs.map +1 -1
  134. package/dist/functional/result/impl/result-is-result.d.mts.map +1 -1
  135. package/dist/functional/result/impl/result-is-result.mjs +1 -23
  136. package/dist/functional/result/impl/result-is-result.mjs.map +1 -1
  137. package/dist/functional/result/impl/result-map-err.mjs +16 -16
  138. package/dist/functional/result/impl/result-map-err.mjs.map +1 -1
  139. package/dist/functional/result/impl/result-map.mjs +16 -16
  140. package/dist/functional/result/impl/result-map.mjs.map +1 -1
  141. package/dist/functional/result/impl/result-ok.d.mts.map +1 -1
  142. package/dist/functional/result/impl/result-ok.mjs +2 -27
  143. package/dist/functional/result/impl/result-ok.mjs.map +1 -1
  144. package/dist/functional/result/impl/result-or-else.mjs +10 -12
  145. package/dist/functional/result/impl/result-or-else.mjs.map +1 -1
  146. package/dist/functional/result/impl/result-swap.d.mts.map +1 -1
  147. package/dist/functional/result/impl/result-swap.mjs +4 -22
  148. package/dist/functional/result/impl/result-swap.mjs.map +1 -1
  149. package/dist/functional/result/impl/result-to-optional.d.mts.map +1 -1
  150. package/dist/functional/result/impl/result-to-optional.mjs +0 -27
  151. package/dist/functional/result/impl/result-to-optional.mjs.map +1 -1
  152. package/dist/functional/result/impl/result-unwrap-err-or.mjs +9 -11
  153. package/dist/functional/result/impl/result-unwrap-err-or.mjs.map +1 -1
  154. package/dist/functional/result/impl/result-unwrap-err-throw.d.mts.map +1 -1
  155. package/dist/functional/result/impl/result-unwrap-err-throw.mjs +13 -40
  156. package/dist/functional/result/impl/result-unwrap-err-throw.mjs.map +1 -1
  157. package/dist/functional/result/impl/result-unwrap-err.d.mts.map +1 -1
  158. package/dist/functional/result/impl/result-unwrap-err.mjs +4 -32
  159. package/dist/functional/result/impl/result-unwrap-err.mjs.map +1 -1
  160. package/dist/functional/result/impl/result-unwrap-ok-or.mjs +9 -11
  161. package/dist/functional/result/impl/result-unwrap-ok-or.mjs.map +1 -1
  162. package/dist/functional/result/impl/result-unwrap-ok.mjs +4 -4
  163. package/dist/functional/result/impl/result-unwrap-ok.mjs.map +1 -1
  164. package/dist/functional/result/impl/result-unwrap-throw.d.mts.map +1 -1
  165. package/dist/functional/result/impl/result-unwrap-throw.mjs +4 -35
  166. package/dist/functional/result/impl/result-unwrap-throw.mjs.map +1 -1
  167. package/dist/functional/result/impl/result-zip.d.mts.map +1 -1
  168. package/dist/functional/result/impl/result-zip.mjs +1 -34
  169. package/dist/functional/result/impl/result-zip.mjs.map +1 -1
  170. package/dist/functional/result/impl/tag.mjs +2 -3
  171. package/dist/functional/result/impl/tag.mjs.map +1 -1
  172. package/dist/functional/ternary-result/impl/tag.mjs +3 -5
  173. package/dist/functional/ternary-result/impl/tag.mjs.map +1 -1
  174. package/dist/functional/ternary-result/impl/ternary-result-err.d.mts.map +1 -1
  175. package/dist/functional/ternary-result/impl/ternary-result-err.mjs +2 -15
  176. package/dist/functional/ternary-result/impl/ternary-result-err.mjs.map +1 -1
  177. package/dist/functional/ternary-result/impl/ternary-result-expect-to-be.mjs +13 -13
  178. package/dist/functional/ternary-result/impl/ternary-result-expect-to-be.mjs.map +1 -1
  179. package/dist/functional/ternary-result/impl/ternary-result-flat-map.mjs +27 -26
  180. package/dist/functional/ternary-result/impl/ternary-result-flat-map.mjs.map +1 -1
  181. package/dist/functional/ternary-result/impl/ternary-result-fold.mjs +21 -22
  182. package/dist/functional/ternary-result/impl/ternary-result-fold.mjs.map +1 -1
  183. package/dist/functional/ternary-result/impl/ternary-result-from-promise.d.mts.map +1 -1
  184. package/dist/functional/ternary-result/impl/ternary-result-from-promise.mjs +4 -20
  185. package/dist/functional/ternary-result/impl/ternary-result-from-promise.mjs.map +1 -1
  186. package/dist/functional/ternary-result/impl/ternary-result-from-throwable.d.mts.map +1 -1
  187. package/dist/functional/ternary-result/impl/ternary-result-from-throwable.mjs +7 -25
  188. package/dist/functional/ternary-result/impl/ternary-result-from-throwable.mjs.map +1 -1
  189. package/dist/functional/ternary-result/impl/ternary-result-is-err.d.mts.map +1 -1
  190. package/dist/functional/ternary-result/impl/ternary-result-is-err.mjs +0 -17
  191. package/dist/functional/ternary-result/impl/ternary-result-is-err.mjs.map +1 -1
  192. package/dist/functional/ternary-result/impl/ternary-result-is-ok.d.mts.map +1 -1
  193. package/dist/functional/ternary-result/impl/ternary-result-is-ok.mjs +0 -19
  194. package/dist/functional/ternary-result/impl/ternary-result-is-ok.mjs.map +1 -1
  195. package/dist/functional/ternary-result/impl/ternary-result-is-ternary-result.d.mts.map +1 -1
  196. package/dist/functional/ternary-result/impl/ternary-result-is-ternary-result.mjs +1 -25
  197. package/dist/functional/ternary-result/impl/ternary-result-is-ternary-result.mjs.map +1 -1
  198. package/dist/functional/ternary-result/impl/ternary-result-is-warn.d.mts.map +1 -1
  199. package/dist/functional/ternary-result/impl/ternary-result-is-warn.mjs +0 -18
  200. package/dist/functional/ternary-result/impl/ternary-result-is-warn.mjs.map +1 -1
  201. package/dist/functional/ternary-result/impl/ternary-result-map-err.mjs +13 -15
  202. package/dist/functional/ternary-result/impl/ternary-result-map-err.mjs.map +1 -1
  203. package/dist/functional/ternary-result/impl/ternary-result-map-warn.mjs +18 -18
  204. package/dist/functional/ternary-result/impl/ternary-result-map-warn.mjs.map +1 -1
  205. package/dist/functional/ternary-result/impl/ternary-result-map.mjs +21 -22
  206. package/dist/functional/ternary-result/impl/ternary-result-map.mjs.map +1 -1
  207. package/dist/functional/ternary-result/impl/ternary-result-ok.d.mts.map +1 -1
  208. package/dist/functional/ternary-result/impl/ternary-result-ok.mjs +2 -16
  209. package/dist/functional/ternary-result/impl/ternary-result-ok.mjs.map +1 -1
  210. package/dist/functional/ternary-result/impl/ternary-result-or-else.mjs +9 -9
  211. package/dist/functional/ternary-result/impl/ternary-result-or-else.mjs.map +1 -1
  212. package/dist/functional/ternary-result/impl/ternary-result-to-optional.d.mts.map +1 -1
  213. package/dist/functional/ternary-result/impl/ternary-result-to-optional.mjs +4 -22
  214. package/dist/functional/ternary-result/impl/ternary-result-to-optional.mjs.map +1 -1
  215. package/dist/functional/ternary-result/impl/ternary-result-unwrap-err-or.mjs +9 -9
  216. package/dist/functional/ternary-result/impl/ternary-result-unwrap-err-or.mjs.map +1 -1
  217. package/dist/functional/ternary-result/impl/ternary-result-unwrap-err-throw.d.mts.map +1 -1
  218. package/dist/functional/ternary-result/impl/ternary-result-unwrap-err-throw.mjs +12 -27
  219. package/dist/functional/ternary-result/impl/ternary-result-unwrap-err-throw.mjs.map +1 -1
  220. package/dist/functional/ternary-result/impl/ternary-result-unwrap-err.d.mts.map +1 -1
  221. package/dist/functional/ternary-result/impl/ternary-result-unwrap-err.mjs +4 -19
  222. package/dist/functional/ternary-result/impl/ternary-result-unwrap-err.mjs.map +1 -1
  223. package/dist/functional/ternary-result/impl/ternary-result-unwrap-ok-or.mjs +9 -9
  224. package/dist/functional/ternary-result/impl/ternary-result-unwrap-ok-or.mjs.map +1 -1
  225. package/dist/functional/ternary-result/impl/ternary-result-unwrap-ok.mjs +4 -5
  226. package/dist/functional/ternary-result/impl/ternary-result-unwrap-ok.mjs.map +1 -1
  227. package/dist/functional/ternary-result/impl/ternary-result-unwrap-throw.d.mts.map +1 -1
  228. package/dist/functional/ternary-result/impl/ternary-result-unwrap-throw.mjs +15 -27
  229. package/dist/functional/ternary-result/impl/ternary-result-unwrap-throw.mjs.map +1 -1
  230. package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn-or.mjs +9 -9
  231. package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn-or.mjs.map +1 -1
  232. package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn-throw.d.mts.map +1 -1
  233. package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn-throw.mjs +10 -24
  234. package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn-throw.mjs.map +1 -1
  235. package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn.d.mts.map +1 -1
  236. package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn.mjs +4 -19
  237. package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn.mjs.map +1 -1
  238. package/dist/functional/ternary-result/impl/ternary-result-warn.d.mts.map +1 -1
  239. package/dist/functional/ternary-result/impl/ternary-result-warn.mjs +3 -19
  240. package/dist/functional/ternary-result/impl/ternary-result-warn.mjs.map +1 -1
  241. package/dist/functional/ternary-result/impl/ternary-result-zip.d.mts.map +1 -1
  242. package/dist/functional/ternary-result/impl/ternary-result-zip.mjs +14 -45
  243. package/dist/functional/ternary-result/impl/ternary-result-zip.mjs.map +1 -1
  244. package/dist/functional/ternary-result/impl/variant-name.d.mts +1 -1
  245. package/dist/functional/ternary-result/impl/variant-name.d.mts.map +1 -1
  246. package/dist/functional/ternary-result/impl/variant-name.mjs +8 -9
  247. package/dist/functional/ternary-result/impl/variant-name.mjs.map +1 -1
  248. package/dist/guard/as-length-bounded-array.d.mts +117 -0
  249. package/dist/guard/as-length-bounded-array.d.mts.map +1 -0
  250. package/dist/guard/as-length-bounded-array.mjs +37 -0
  251. package/dist/guard/as-length-bounded-array.mjs.map +1 -0
  252. package/dist/guard/has-key.d.mts.map +1 -1
  253. package/dist/guard/has-key.mjs +0 -41
  254. package/dist/guard/has-key.mjs.map +1 -1
  255. package/dist/guard/index.d.mts +2 -0
  256. package/dist/guard/index.d.mts.map +1 -1
  257. package/dist/guard/index.mjs +2 -0
  258. package/dist/guard/index.mjs.map +1 -1
  259. package/dist/guard/is-length-bounded-array.d.mts +159 -0
  260. package/dist/guard/is-length-bounded-array.d.mts.map +1 -0
  261. package/dist/guard/is-length-bounded-array.mjs +7 -0
  262. package/dist/guard/is-length-bounded-array.mjs.map +1 -0
  263. package/dist/guard/is-length-bounded-string.d.mts +5 -6
  264. package/dist/guard/is-length-bounded-string.d.mts.map +1 -1
  265. package/dist/guard/is-length-bounded-string.mjs +0 -157
  266. package/dist/guard/is-length-bounded-string.mjs.map +1 -1
  267. package/dist/guard/is-non-empty-string.d.mts +1 -1
  268. package/dist/guard/is-non-empty-string.d.mts.map +1 -1
  269. package/dist/guard/is-non-empty-string.mjs +1 -38
  270. package/dist/guard/is-non-empty-string.mjs.map +1 -1
  271. package/dist/guard/is-non-null-object.d.mts.map +1 -1
  272. package/dist/guard/is-non-null-object.mjs +1 -35
  273. package/dist/guard/is-non-null-object.mjs.map +1 -1
  274. package/dist/guard/is-primitive.d.mts.map +1 -1
  275. package/dist/guard/is-primitive.mjs +12 -43
  276. package/dist/guard/is-primitive.mjs.map +1 -1
  277. package/dist/guard/is-record.d.mts.map +1 -1
  278. package/dist/guard/is-record.mjs +0 -86
  279. package/dist/guard/is-record.mjs.map +1 -1
  280. package/dist/guard/is-type.d.mts.map +1 -1
  281. package/dist/guard/is-type.mjs +12 -399
  282. package/dist/guard/is-type.mjs.map +1 -1
  283. package/dist/guard/key-is-in.d.mts.map +1 -1
  284. package/dist/guard/key-is-in.mjs +0 -40
  285. package/dist/guard/key-is-in.mjs.map +1 -1
  286. package/dist/index.mjs +2 -0
  287. package/dist/index.mjs.map +1 -1
  288. package/dist/iterator/range.mjs +16 -16
  289. package/dist/iterator/range.mjs.map +1 -1
  290. package/dist/json/json.d.mts.map +1 -1
  291. package/dist/json/json.mjs +52 -340
  292. package/dist/json/json.mjs.map +1 -1
  293. package/dist/number/branded-types/finite-number.d.mts +3 -3
  294. package/dist/number/branded-types/finite-number.mjs +135 -154
  295. package/dist/number/branded-types/finite-number.mjs.map +1 -1
  296. package/dist/number/branded-types/int.d.mts +4 -4
  297. package/dist/number/branded-types/int.mjs +205 -245
  298. package/dist/number/branded-types/int.mjs.map +1 -1
  299. package/dist/number/branded-types/int16.d.mts +15 -15
  300. package/dist/number/branded-types/int16.mjs +116 -123
  301. package/dist/number/branded-types/int16.mjs.map +1 -1
  302. package/dist/number/branded-types/int32.d.mts +11 -11
  303. package/dist/number/branded-types/int32.mjs +116 -123
  304. package/dist/number/branded-types/int32.mjs.map +1 -1
  305. package/dist/number/branded-types/negative-finite-number.d.mts +4 -4
  306. package/dist/number/branded-types/negative-finite-number.mjs +129 -144
  307. package/dist/number/branded-types/negative-finite-number.mjs.map +1 -1
  308. package/dist/number/branded-types/negative-int.d.mts +5 -5
  309. package/dist/number/branded-types/negative-int.mjs +94 -113
  310. package/dist/number/branded-types/negative-int.mjs.map +1 -1
  311. package/dist/number/branded-types/negative-safe-int.d.mts +5 -5
  312. package/dist/number/branded-types/negative-safe-int.mjs +103 -124
  313. package/dist/number/branded-types/negative-safe-int.mjs.map +1 -1
  314. package/dist/number/branded-types/non-negative-finite-number.d.mts +5 -5
  315. package/dist/number/branded-types/non-negative-finite-number.mjs +136 -142
  316. package/dist/number/branded-types/non-negative-finite-number.mjs.map +1 -1
  317. package/dist/number/branded-types/non-negative-int16.d.mts +16 -16
  318. package/dist/number/branded-types/non-negative-int16.mjs +109 -118
  319. package/dist/number/branded-types/non-negative-int16.mjs.map +1 -1
  320. package/dist/number/branded-types/non-negative-int32.d.mts +12 -12
  321. package/dist/number/branded-types/non-negative-int32.mjs +110 -119
  322. package/dist/number/branded-types/non-negative-int32.mjs.map +1 -1
  323. package/dist/number/branded-types/non-positive-finite-number.d.mts +3 -3
  324. package/dist/number/branded-types/non-positive-finite-number.mjs +120 -124
  325. package/dist/number/branded-types/non-positive-finite-number.mjs.map +1 -1
  326. package/dist/number/branded-types/non-positive-int.d.mts +4 -4
  327. package/dist/number/branded-types/non-positive-int.mjs +167 -212
  328. package/dist/number/branded-types/non-positive-int.mjs.map +1 -1
  329. package/dist/number/branded-types/non-positive-safe-int.d.mts +4 -4
  330. package/dist/number/branded-types/non-positive-safe-int.mjs +95 -106
  331. package/dist/number/branded-types/non-positive-safe-int.mjs.map +1 -1
  332. package/dist/number/branded-types/non-zero-finite-number.d.mts +4 -4
  333. package/dist/number/branded-types/non-zero-finite-number.mjs +114 -123
  334. package/dist/number/branded-types/non-zero-finite-number.mjs.map +1 -1
  335. package/dist/number/branded-types/non-zero-int.d.mts +2 -2
  336. package/dist/number/branded-types/non-zero-int.mjs +72 -83
  337. package/dist/number/branded-types/non-zero-int.mjs.map +1 -1
  338. package/dist/number/branded-types/non-zero-int16.d.mts +7 -7
  339. package/dist/number/branded-types/non-zero-int16.mjs +96 -107
  340. package/dist/number/branded-types/non-zero-int16.mjs.map +1 -1
  341. package/dist/number/branded-types/non-zero-int32.d.mts +5 -5
  342. package/dist/number/branded-types/non-zero-int32.mjs +97 -108
  343. package/dist/number/branded-types/non-zero-int32.mjs.map +1 -1
  344. package/dist/number/branded-types/non-zero-safe-int.d.mts +2 -2
  345. package/dist/number/branded-types/non-zero-safe-int.mjs +100 -111
  346. package/dist/number/branded-types/non-zero-safe-int.mjs.map +1 -1
  347. package/dist/number/branded-types/non-zero-uint16.d.mts +8 -8
  348. package/dist/number/branded-types/non-zero-uint16.mjs +96 -107
  349. package/dist/number/branded-types/non-zero-uint16.mjs.map +1 -1
  350. package/dist/number/branded-types/non-zero-uint32.d.mts +6 -6
  351. package/dist/number/branded-types/non-zero-uint32.mjs +96 -107
  352. package/dist/number/branded-types/non-zero-uint32.mjs.map +1 -1
  353. package/dist/number/branded-types/positive-finite-number.d.mts +8 -8
  354. package/dist/number/branded-types/positive-finite-number.mjs +139 -141
  355. package/dist/number/branded-types/positive-finite-number.mjs.map +1 -1
  356. package/dist/number/branded-types/positive-int.d.mts +11 -11
  357. package/dist/number/branded-types/positive-int.mjs +228 -271
  358. package/dist/number/branded-types/positive-int.mjs.map +1 -1
  359. package/dist/number/branded-types/positive-int16.d.mts +19 -19
  360. package/dist/number/branded-types/positive-int16.mjs +109 -118
  361. package/dist/number/branded-types/positive-int16.mjs.map +1 -1
  362. package/dist/number/branded-types/positive-int32.d.mts +15 -15
  363. package/dist/number/branded-types/positive-int32.mjs +109 -118
  364. package/dist/number/branded-types/positive-int32.mjs.map +1 -1
  365. package/dist/number/branded-types/positive-safe-int.d.mts +11 -11
  366. package/dist/number/branded-types/positive-safe-int.mjs +244 -275
  367. package/dist/number/branded-types/positive-safe-int.mjs.map +1 -1
  368. package/dist/number/branded-types/positive-uint16.d.mts +17 -17
  369. package/dist/number/branded-types/positive-uint16.mjs +109 -118
  370. package/dist/number/branded-types/positive-uint16.mjs.map +1 -1
  371. package/dist/number/branded-types/positive-uint32.d.mts +13 -13
  372. package/dist/number/branded-types/positive-uint32.mjs +110 -119
  373. package/dist/number/branded-types/positive-uint32.mjs.map +1 -1
  374. package/dist/number/branded-types/safe-int.d.mts +4 -4
  375. package/dist/number/branded-types/safe-int.mjs +251 -292
  376. package/dist/number/branded-types/safe-int.mjs.map +1 -1
  377. package/dist/number/branded-types/safe-uint.d.mts +8 -8
  378. package/dist/number/branded-types/safe-uint.mjs +111 -119
  379. package/dist/number/branded-types/safe-uint.mjs.map +1 -1
  380. package/dist/number/branded-types/uint.d.mts +8 -8
  381. package/dist/number/branded-types/uint.mjs +198 -225
  382. package/dist/number/branded-types/uint.mjs.map +1 -1
  383. package/dist/number/branded-types/uint16.d.mts +14 -14
  384. package/dist/number/branded-types/uint16.mjs +109 -119
  385. package/dist/number/branded-types/uint16.mjs.map +1 -1
  386. package/dist/number/branded-types/uint32.d.mts +10 -10
  387. package/dist/number/branded-types/uint32.mjs +110 -117
  388. package/dist/number/branded-types/uint32.mjs.map +1 -1
  389. package/dist/number/enum/int8.mjs +119 -145
  390. package/dist/number/enum/int8.mjs.map +1 -1
  391. package/dist/number/enum/uint8.mjs +107 -121
  392. package/dist/number/enum/uint8.mjs.map +1 -1
  393. package/dist/number/num.d.mts +2 -2
  394. package/dist/number/num.d.mts.map +1 -1
  395. package/dist/number/num.mjs +76 -537
  396. package/dist/number/num.mjs.map +1 -1
  397. package/dist/number/refined-number-utils.d.mts +1 -1
  398. package/dist/number/refined-number-utils.d.mts.map +1 -1
  399. package/dist/number/refined-number-utils.mjs +127 -263
  400. package/dist/number/refined-number-utils.mjs.map +1 -1
  401. package/dist/object/object.d.mts.map +1 -1
  402. package/dist/object/object.mjs +107 -222
  403. package/dist/object/object.mjs.map +1 -1
  404. package/dist/others/cast-mutable.d.mts.map +1 -1
  405. package/dist/others/cast-mutable.mjs +8 -37
  406. package/dist/others/cast-mutable.mjs.map +1 -1
  407. package/dist/others/cast-readonly.d.mts.map +1 -1
  408. package/dist/others/cast-readonly.mjs +8 -36
  409. package/dist/others/cast-readonly.mjs.map +1 -1
  410. package/dist/others/debounce-function.d.mts.map +1 -1
  411. package/dist/others/debounce-function.mjs +7 -16
  412. package/dist/others/debounce-function.mjs.map +1 -1
  413. package/dist/others/fast-deep-equal.d.mts.map +1 -1
  414. package/dist/others/fast-deep-equal.mjs +43 -59
  415. package/dist/others/fast-deep-equal.mjs.map +1 -1
  416. package/dist/others/if-then.d.mts.map +1 -1
  417. package/dist/others/if-then.mjs +0 -29
  418. package/dist/others/if-then.mjs.map +1 -1
  419. package/dist/others/map-nullable.mjs +9 -9
  420. package/dist/others/map-nullable.mjs.map +1 -1
  421. package/dist/others/memoize-function.mjs +12 -12
  422. package/dist/others/memoize-function.mjs.map +1 -1
  423. package/dist/others/tuple.d.mts.map +1 -1
  424. package/dist/others/tuple.mjs +0 -50
  425. package/dist/others/tuple.mjs.map +1 -1
  426. package/dist/others/unknown-to-string.d.mts.map +1 -1
  427. package/dist/others/unknown-to-string.mjs +41 -88
  428. package/dist/others/unknown-to-string.mjs.map +1 -1
  429. package/dist/promise/promise.d.mts.map +1 -1
  430. package/dist/promise/promise.mjs +4 -49
  431. package/dist/promise/promise.mjs.map +1 -1
  432. package/package.json +14 -13
  433. package/src/array/impl/array-utils-creation.mts +3 -3
  434. package/src/array/impl/array-utils-modification.mts +7 -7
  435. package/src/array/impl/array-utils-modification.test.mts +4 -4
  436. package/src/array/impl/array-utils-transformation.mts +4 -4
  437. package/src/array/impl/array-utils-transformation.test.mts +7 -7
  438. package/src/array/impl/array-utils-validation.mts +24 -24
  439. package/src/array/impl/array-utils-validation.test.mts +94 -92
  440. package/src/collections/queue.test.mts +1 -1
  441. package/src/guard/as-length-bounded-array.mts +190 -0
  442. package/src/guard/as-length-bounded-array.test.mts +118 -0
  443. package/src/guard/index.mts +2 -0
  444. package/src/guard/is-length-bounded-array.mts +195 -0
  445. package/src/guard/is-length-bounded-array.test.mts +169 -0
  446. package/src/guard/is-length-bounded-string.mts +6 -6
  447. package/src/object/object.test.mts +3 -3
@@ -39,190 +39,118 @@ import '../number/enum/uint8.mjs';
39
39
  import '../number/num.mjs';
40
40
  import '../number/refined-number-utils.mjs';
41
41
 
42
- /**
43
- * Class implementation for a queue with FIFO (First-In, First-Out) behavior
44
- * using a circular buffer. This implementation provides O(1) enqueue and
45
- * dequeue operations by using a fixed-size buffer with head and tail pointers
46
- * that wrap around when they reach the buffer boundary.
47
- *
48
- * The circular buffer automatically resizes when it becomes full, ensuring that
49
- * the queue can grow to accommodate any number of elements while maintaining
50
- * efficient operations.
51
- *
52
- * @template T The type of elements in the queue.
53
- * @implements Queue
54
- */
55
42
  class QueueClass {
56
- /** @internal Initial capacity for new queues. */
57
- static #INITIAL_CAPACITY = 8;
58
- /** @internal Circular buffer to store queue elements. */
59
- #mut_buffer;
60
- /** @internal Index of the first element (front of queue). */
61
- #mut_head;
62
- /** @internal Index where the next element will be added (back of queue). */
63
- #mut_tail;
64
- /** @internal Current number of elements in the queue. */
65
- #mut_size;
66
- /** @internal Current capacity of the buffer. */
67
- #mut_capacity;
68
- /**
69
- * Constructs a new QueueClass instance.
70
- *
71
- * @param initialValues Optional initial values to populate the queue.
72
- */
73
- constructor(initialValues = []) {
74
- const initialCapacity = asUint32(Math.max(QueueClass.#INITIAL_CAPACITY, initialValues.length * 2));
75
- this.#mut_buffer = Array.from({ length: initialCapacity }, () => undefined);
76
- this.#mut_head = 0;
77
- this.#mut_tail = 0;
78
- this.#mut_size = 0;
79
- this.#mut_capacity = initialCapacity;
80
- // Add initial values
81
- for (const value of initialValues) {
82
- this.enqueue(value);
83
- }
43
+ /** @internal Initial capacity for new queues. */
44
+ static #INITIAL_CAPACITY = 8;
45
+ /** @internal Circular buffer to store queue elements. */
46
+ #mut_buffer;
47
+ /** @internal Index of the first element (front of queue). */
48
+ #mut_head;
49
+ /** @internal Index where the next element will be added (back of queue). */
50
+ #mut_tail;
51
+ /** @internal Current number of elements in the queue. */
52
+ #mut_size;
53
+ /** @internal Current capacity of the buffer. */
54
+ #mut_capacity;
55
+ /**
56
+ * Constructs a new QueueClass instance.
57
+ *
58
+ * @param initialValues Optional initial values to populate the queue.
59
+ */
60
+ constructor(initialValues = []) {
61
+ const initialCapacity = asUint32(
62
+ Math.max(QueueClass.#INITIAL_CAPACITY, initialValues.length * 2)
63
+ );
64
+ this.#mut_buffer = Array.from(
65
+ { length: initialCapacity },
66
+ () => void 0
67
+ );
68
+ this.#mut_head = 0;
69
+ this.#mut_tail = 0;
70
+ this.#mut_size = 0;
71
+ this.#mut_capacity = initialCapacity;
72
+ for (const value of initialValues) {
73
+ this.enqueue(value);
84
74
  }
85
- /**
86
- * @internal
87
- * Resizes the circular buffer when it becomes full.
88
- * Doubles the capacity and reorganizes elements to maintain queue order.
89
- */
90
- #resize() {
91
- const newCapacity = asUint32(this.#mut_capacity * 2);
92
- const newBuffer = Array.from({ length: newCapacity }, () => undefined);
93
- // Copy elements in order from head to tail
94
- for (const i of range(asSafeUint(this.#mut_size))) {
95
- const sourceIndex = (this.#mut_head + i) % this.#mut_capacity;
96
- newBuffer[i] = this.#mut_buffer[sourceIndex];
97
- }
98
- this.#mut_buffer = newBuffer;
99
- this.#mut_head = 0;
100
- this.#mut_tail = this.#mut_size;
101
- this.#mut_capacity = newCapacity;
75
+ }
76
+ /**
77
+ * @internal
78
+ * Resizes the circular buffer when it becomes full.
79
+ * Doubles the capacity and reorganizes elements to maintain queue order.
80
+ */
81
+ #resize() {
82
+ const newCapacity = asUint32(this.#mut_capacity * 2);
83
+ const newBuffer = Array.from(
84
+ { length: newCapacity },
85
+ () => void 0
86
+ );
87
+ for (const i of range(asSafeUint(this.#mut_size))) {
88
+ const sourceIndex = (this.#mut_head + i) % this.#mut_capacity;
89
+ newBuffer[i] = this.#mut_buffer[sourceIndex];
102
90
  }
103
- /** @inheritdoc */
104
- get isEmpty() {
105
- return this.#mut_size === 0;
91
+ this.#mut_buffer = newBuffer;
92
+ this.#mut_head = 0;
93
+ this.#mut_tail = this.#mut_size;
94
+ this.#mut_capacity = newCapacity;
95
+ }
96
+ /** @inheritdoc */
97
+ get isEmpty() {
98
+ return this.#mut_size === 0;
99
+ }
100
+ /** @inheritdoc */
101
+ get size() {
102
+ return asUint32(this.#mut_size);
103
+ }
104
+ /**
105
+ * Removes and returns the element at the front of the queue (FIFO).
106
+ *
107
+ * This operation removes the element that was added earliest (first-in) and
108
+ * returns it. If the queue is empty, returns `Optional.none`. The operation
109
+ * is guaranteed to be O(1) and does not require any array shifting or
110
+ * copying.
111
+ *
112
+ * **Time Complexity:** O(1) - constant time operation **Space Complexity:**
113
+ * O(1) - no additional memory allocation
114
+ *
115
+ * @returns An Optional containing the removed element, or `Optional.none` if
116
+ * the queue is empty.
117
+ */
118
+ dequeue() {
119
+ if (this.isEmpty) {
120
+ return none;
106
121
  }
107
- /** @inheritdoc */
108
- get size() {
109
- return asUint32(this.#mut_size);
110
- }
111
- /**
112
- * Removes and returns the element at the front of the queue (FIFO).
113
- *
114
- * This operation removes the element that was added earliest (first-in) and
115
- * returns it. If the queue is empty, returns `Optional.none`. The operation
116
- * is guaranteed to be O(1) and does not require any array shifting or
117
- * copying.
118
- *
119
- * **Time Complexity:** O(1) - constant time operation **Space Complexity:**
120
- * O(1) - no additional memory allocation
121
- *
122
- * @returns An Optional containing the removed element, or `Optional.none` if
123
- * the queue is empty.
124
- */
125
- dequeue() {
126
- if (this.isEmpty) {
127
- return none;
128
- }
129
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
130
- const element = this.#mut_buffer[this.#mut_head];
131
- this.#mut_buffer[this.#mut_head] = undefined; // Clear reference for garbage collection
132
- this.#mut_head = (this.#mut_head + 1) % this.#mut_capacity;
133
- this.#mut_size -= 1;
134
- return some(element);
135
- }
136
- /**
137
- * Adds an element to the back of the queue (FIFO).
138
- *
139
- * This operation adds the element to the end of the queue, where it will be
140
- * the last to be dequeued (first-in, first-out ordering). The operation is
141
- * amortized O(1), meaning it's O(1) for most operations with occasional O(n)
142
- * when the buffer needs resizing.
143
- *
144
- * **Time Complexity:** O(1) amortized - O(n) only when buffer resize is
145
- * needed **Space Complexity:** O(1) - constant additional memory per element
146
- *
147
- * **Buffer Resizing:** When the internal buffer becomes full, it
148
- * automatically doubles in size and reorganizes elements to maintain the
149
- * circular buffer structure.
150
- *
151
- * @param value The element to add to the back of the queue.
152
- */
153
- enqueue(value) {
154
- // Resize if buffer is full
155
- if (this.#mut_size === this.#mut_capacity) {
156
- this.#resize();
157
- }
158
- this.#mut_buffer[this.#mut_tail] = value;
159
- this.#mut_tail = (this.#mut_tail + 1) % this.#mut_capacity;
160
- this.#mut_size += 1;
122
+ const element = this.#mut_buffer[this.#mut_head];
123
+ this.#mut_buffer[this.#mut_head] = void 0;
124
+ this.#mut_head = (this.#mut_head + 1) % this.#mut_capacity;
125
+ this.#mut_size -= 1;
126
+ return some(element);
127
+ }
128
+ /**
129
+ * Adds an element to the back of the queue (FIFO).
130
+ *
131
+ * This operation adds the element to the end of the queue, where it will be
132
+ * the last to be dequeued (first-in, first-out ordering). The operation is
133
+ * amortized O(1), meaning it's O(1) for most operations with occasional O(n)
134
+ * when the buffer needs resizing.
135
+ *
136
+ * **Time Complexity:** O(1) amortized - O(n) only when buffer resize is
137
+ * needed **Space Complexity:** O(1) - constant additional memory per element
138
+ *
139
+ * **Buffer Resizing:** When the internal buffer becomes full, it
140
+ * automatically doubles in size and reorganizes elements to maintain the
141
+ * circular buffer structure.
142
+ *
143
+ * @param value The element to add to the back of the queue.
144
+ */
145
+ enqueue(value) {
146
+ if (this.#mut_size === this.#mut_capacity) {
147
+ this.#resize();
161
148
  }
149
+ this.#mut_buffer[this.#mut_tail] = value;
150
+ this.#mut_tail = (this.#mut_tail + 1) % this.#mut_capacity;
151
+ this.#mut_size += 1;
152
+ }
162
153
  }
163
- /**
164
- * Creates a new Queue instance with FIFO (First-In, First-Out) behavior using a
165
- * high-performance circular buffer.
166
- *
167
- * This factory function creates an optimized queue implementation that
168
- * maintains excellent performance characteristics for both enqueue and dequeue
169
- * operations. The underlying circular buffer automatically resizes to
170
- * accommodate growing workloads while providing predictable O(1) operations.
171
- *
172
- * **Implementation Features:**
173
- *
174
- * - **O(1) enqueue operations** (amortized - occasionally O(n) when resizing)
175
- * - **O(1) dequeue operations** (always)
176
- * - **Automatic buffer resizing** - starts at 8 elements, doubles when full
177
- * - **Memory efficient** - garbage collects removed elements immediately
178
- * - **Circular buffer design** - eliminates need for array shifting operations
179
- *
180
- * **Performance Benefits:**
181
- *
182
- * - No array copying during normal operations
183
- * - Minimal memory allocation overhead
184
- * - Predictable performance under high load
185
- * - Efficient memory usage with automatic cleanup
186
- *
187
- * @example
188
- *
189
- * ```ts
190
- * const queue = createQueue<number>();
191
- *
192
- * assert.isTrue(queue.isEmpty);
193
- *
194
- * assert.isTrue(queue.size === 0);
195
- *
196
- * queue.enqueue(1);
197
- *
198
- * queue.enqueue(2);
199
- *
200
- * assert.isFalse(queue.isEmpty);
201
- *
202
- * assert.isTrue(queue.size === 2);
203
- *
204
- * assert.deepStrictEqual(queue.dequeue(), Optional.some(1));
205
- *
206
- * assert.deepStrictEqual(queue.dequeue(), Optional.some(2));
207
- *
208
- * assert.deepStrictEqual(queue.dequeue(), Optional.none);
209
- *
210
- * const seededQueue = createQueue(['first', 'second']);
211
- *
212
- * assert.isTrue(seededQueue.size === 2);
213
- *
214
- * assert.deepStrictEqual(seededQueue.dequeue(), Optional.some('first'));
215
- *
216
- * assert.deepStrictEqual(seededQueue.dequeue(), Optional.some('second'));
217
- * ```
218
- *
219
- * @template T The type of elements stored in the queue.
220
- * @param initialValues Optional array of initial elements to populate the
221
- * queue. Elements will be dequeued in the same order they appear in the
222
- * array. If provided, the initial buffer capacity will be at least twice the
223
- * array length.
224
- * @returns A new Queue instance optimized for high-performance FIFO operations.
225
- */
226
154
  const createQueue = (initialValues) => new QueueClass(initialValues);
227
155
 
228
156
  export { createQueue };
@@ -1 +1 @@
1
- {"version":3,"file":"queue.mjs","sources":["../../src/collections/queue.mts"],"sourcesContent":[null],"names":["Optional.none","Optional.some"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiMA;;;;;;;;;;;;AAYG;AACH,MAAM,UAAU,CAAA;;AAEd,IAAA,OAAgB,iBAAiB,GAAG,CAAC;;AAGrC,IAAA,WAAW;;AAGX,IAAA,SAAS;;AAGT,IAAA,SAAS;;AAGT,IAAA,SAAS;;AAGT,IAAA,aAAa;AAEb;;;;AAIG;AACH,IAAA,WAAA,CAAY,gBAA8B,EAAE,EAAA;AAC1C,QAAA,MAAM,eAAe,GAAG,QAAQ,CAC9B,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,iBAAiB,EAAE,aAAa,CAAC,MAAM,GAAG,CAAC,CAAC,CACjE;AAED,QAAA,IAAI,CAAC,WAAW,GAAG,KAAK,CAAC,IAAI,CAC3B,EAAE,MAAM,EAAE,eAAe,EAAE,EAC3B,MAAM,SAAS,CAChB;AAED,QAAA,IAAI,CAAC,SAAS,GAAG,CAAC;AAElB,QAAA,IAAI,CAAC,SAAS,GAAG,CAAC;AAElB,QAAA,IAAI,CAAC,SAAS,GAAG,CAAC;AAElB,QAAA,IAAI,CAAC,aAAa,GAAG,eAAe;;AAGpC,QAAA,KAAK,MAAM,KAAK,IAAI,aAAa,EAAE;AACjC,YAAA,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC;QACrB;IACF;AAEA;;;;AAIG;IACH,OAAO,GAAA;QACL,MAAM,WAAW,GAAG,QAAQ,CAAC,IAAI,CAAC,aAAa,GAAG,CAAC,CAAC;AAEpD,QAAA,MAA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AAQ,EAAA;;QAEd,IAAI,IAAI,CAAC,SAAS,KAAK,IAAI,CAAC,aAAa,EAAE;YACzC,IAAI,CAAC,OAAO,EAAE;QAChB;QAEA,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,KAAK;AAExC,QAAA,IAAI,CAAC,SAAS,GAAG,CAAC,IAAI,CAAC,SAAS,GAAG,CAAC,IAAI,IAAI,CAAC,aAAa;AAE1D,QAAA,IAAI,CAAC,SAAS,IAAI,CAAC;IACrB;;AAGF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8DG;AACI,MAAM,WAAW,GAAG,CAAK,aAA4B,KAC1D,IAAI,UAAU,CAAI,aAAa;;;;"}
1
+ {"version":3,"file":"queue.mjs","sources":["../../src/collections/queue.mts"],"sourcesContent":["import { Optional } from '../functional/index.mjs';\nimport { range } from '../iterator/index.mjs';\nimport { asSafeUint, asUint32 } from '../number/index.mjs';\nimport { type SizeType } from '../types.mjs';\n\n/**\n * Interface for a high-performance queue with FIFO (First-In, First-Out)\n * behavior.\n *\n * This interface defines a mutable queue data structure where elements are\n * added to the back and removed from the front, maintaining the order in which\n * they were added. The implementation uses a circular buffer for optimal\n * performance, providing O(1) operations for both enqueue and dequeue\n * operations.\n *\n * **FIFO Behavior:**\n *\n * - **enqueue**: Adds elements to the back of the queue\n * - **dequeue**: Removes and returns elements from the front of the queue\n * - Elements are processed in the exact order they were added\n *\n * **Performance Characteristics:**\n *\n * - Enqueue: O(1) amortized (O(n) when buffer needs resizing)\n * - Dequeue: O(1) always\n * - Size/isEmpty: O(1) always\n * - Memory efficient with automatic garbage collection of removed elements\n *\n * **Use Cases:**\n *\n * - Task scheduling and job queues\n * - Breadth-first search algorithms\n * - Event processing systems\n * - Producer-consumer patterns\n * - Buffer management for streaming data\n *\n * @template T The type of elements stored in the queue.\n */\nexport type Queue<T> = Readonly<{\n /**\n * Checks if the queue is empty.\n *\n * @example\n *\n * ```ts\n * const queue = createQueue<number>();\n *\n * assert.isTrue(queue.isEmpty);\n *\n * assert.isTrue(queue.size === 0);\n *\n * queue.enqueue(1);\n *\n * queue.enqueue(2);\n *\n * assert.isFalse(queue.isEmpty);\n *\n * assert.isTrue(queue.size === 2);\n *\n * assert.deepStrictEqual(queue.dequeue(), Optional.some(1));\n *\n * assert.deepStrictEqual(queue.dequeue(), Optional.some(2));\n *\n * assert.deepStrictEqual(queue.dequeue(), Optional.none);\n *\n * const seededQueue = createQueue(['first', 'second']);\n *\n * assert.isTrue(seededQueue.size === 2);\n *\n * assert.deepStrictEqual(seededQueue.dequeue(), Optional.some('first'));\n *\n * assert.deepStrictEqual(seededQueue.dequeue(), Optional.some('second'));\n * ```\n */\n isEmpty: boolean;\n\n /**\n * The number of elements in the queue.\n *\n * @example\n *\n * ```ts\n * const queue = createQueue<number>();\n *\n * assert.isTrue(queue.isEmpty);\n *\n * assert.isTrue(queue.size === 0);\n *\n * queue.enqueue(1);\n *\n * queue.enqueue(2);\n *\n * assert.isFalse(queue.isEmpty);\n *\n * assert.isTrue(queue.size === 2);\n *\n * assert.deepStrictEqual(queue.dequeue(), Optional.some(1));\n *\n * assert.deepStrictEqual(queue.dequeue(), Optional.some(2));\n *\n * assert.deepStrictEqual(queue.dequeue(), Optional.none);\n *\n * const seededQueue = createQueue(['first', 'second']);\n *\n * assert.isTrue(seededQueue.size === 2);\n *\n * assert.deepStrictEqual(seededQueue.dequeue(), Optional.some('first'));\n *\n * assert.deepStrictEqual(seededQueue.dequeue(), Optional.some('second'));\n * ```\n */\n size: SizeType.Arr;\n\n /**\n * Removes and returns the element at the front of the queue.\n *\n * @example\n *\n * ```ts\n * const queue = createQueue<number>();\n *\n * assert.isTrue(queue.isEmpty);\n *\n * assert.isTrue(queue.size === 0);\n *\n * queue.enqueue(1);\n *\n * queue.enqueue(2);\n *\n * assert.isFalse(queue.isEmpty);\n *\n * assert.isTrue(queue.size === 2);\n *\n * assert.deepStrictEqual(queue.dequeue(), Optional.some(1));\n *\n * assert.deepStrictEqual(queue.dequeue(), Optional.some(2));\n *\n * assert.deepStrictEqual(queue.dequeue(), Optional.none);\n *\n * const seededQueue = createQueue(['first', 'second']);\n *\n * assert.isTrue(seededQueue.size === 2);\n *\n * assert.deepStrictEqual(seededQueue.dequeue(), Optional.some('first'));\n *\n * assert.deepStrictEqual(seededQueue.dequeue(), Optional.some('second'));\n * ```\n *\n * @returns The element at the front of the queue, or `Optional.none` if the\n * queue is empty.\n */\n dequeue: () => Optional<T>;\n\n /**\n * Adds an element to the back of the queue.\n *\n * @example\n *\n * ```ts\n * const queue = createQueue<number>();\n *\n * assert.isTrue(queue.isEmpty);\n *\n * assert.isTrue(queue.size === 0);\n *\n * queue.enqueue(1);\n *\n * queue.enqueue(2);\n *\n * assert.isFalse(queue.isEmpty);\n *\n * assert.isTrue(queue.size === 2);\n *\n * assert.deepStrictEqual(queue.dequeue(), Optional.some(1));\n *\n * assert.deepStrictEqual(queue.dequeue(), Optional.some(2));\n *\n * assert.deepStrictEqual(queue.dequeue(), Optional.none);\n *\n * const seededQueue = createQueue(['first', 'second']);\n *\n * assert.isTrue(seededQueue.size === 2);\n *\n * assert.deepStrictEqual(seededQueue.dequeue(), Optional.some('first'));\n *\n * assert.deepStrictEqual(seededQueue.dequeue(), Optional.some('second'));\n * ```\n *\n * @param value The element to add.\n */\n enqueue: (value: T) => void;\n}>;\n\n/**\n * Class implementation for a queue with FIFO (First-In, First-Out) behavior\n * using a circular buffer. This implementation provides O(1) enqueue and\n * dequeue operations by using a fixed-size buffer with head and tail pointers\n * that wrap around when they reach the buffer boundary.\n *\n * The circular buffer automatically resizes when it becomes full, ensuring that\n * the queue can grow to accommodate any number of elements while maintaining\n * efficient operations.\n *\n * @template T The type of elements in the queue.\n * @implements Queue\n */\nclass QueueClass<T> implements Queue<T> {\n /** @internal Initial capacity for new queues. */\n static readonly #INITIAL_CAPACITY = 8;\n\n /** @internal Circular buffer to store queue elements. */\n #mut_buffer: (T | undefined)[];\n\n /** @internal Index of the first element (front of queue). */\n #mut_head: number;\n\n /** @internal Index where the next element will be added (back of queue). */\n #mut_tail: number;\n\n /** @internal Current number of elements in the queue. */\n #mut_size: number;\n\n /** @internal Current capacity of the buffer. */\n #mut_capacity: number;\n\n /**\n * Constructs a new QueueClass instance.\n *\n * @param initialValues Optional initial values to populate the queue.\n */\n constructor(initialValues: readonly T[] = []) {\n const initialCapacity = asUint32(\n Math.max(QueueClass.#INITIAL_CAPACITY, initialValues.length * 2),\n );\n\n this.#mut_buffer = Array.from<unknown, T | undefined>(\n { length: initialCapacity },\n () => undefined,\n );\n\n this.#mut_head = 0;\n\n this.#mut_tail = 0;\n\n this.#mut_size = 0;\n\n this.#mut_capacity = initialCapacity;\n\n // Add initial values\n for (const value of initialValues) {\n this.enqueue(value);\n }\n }\n\n /**\n * @internal\n * Resizes the circular buffer when it becomes full.\n * Doubles the capacity and reorganizes elements to maintain queue order.\n */\n #resize(): void {\n const newCapacity = asUint32(this.#mut_capacity * 2);\n\n const newBuffer = Array.from<unknown, T | undefined>(\n { length: newCapacity },\n () => undefined,\n );\n\n // Copy elements in order from head to tail\n for (const i of range(asSafeUint(this.#mut_size))) {\n const sourceIndex = (this.#mut_head + i) % this.#mut_capacity;\n\n newBuffer[i] = this.#mut_buffer[sourceIndex];\n }\n\n this.#mut_buffer = newBuffer;\n\n this.#mut_head = 0;\n\n this.#mut_tail = this.#mut_size;\n\n this.#mut_capacity = newCapacity;\n }\n\n /** @inheritdoc */\n get isEmpty(): boolean {\n return this.#mut_size === 0;\n }\n\n /** @inheritdoc */\n get size(): SizeType.Arr {\n return asUint32(this.#mut_size);\n }\n\n /**\n * Removes and returns the element at the front of the queue (FIFO).\n *\n * This operation removes the element that was added earliest (first-in) and\n * returns it. If the queue is empty, returns `Optional.none`. The operation\n * is guaranteed to be O(1) and does not require any array shifting or\n * copying.\n *\n * **Time Complexity:** O(1) - constant time operation **Space Complexity:**\n * O(1) - no additional memory allocation\n *\n * @returns An Optional containing the removed element, or `Optional.none` if\n * the queue is empty.\n */\n dequeue(): Optional<T> {\n if (this.isEmpty) {\n return Optional.none;\n }\n\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const element = this.#mut_buffer[this.#mut_head]!;\n\n this.#mut_buffer[this.#mut_head] = undefined; // Clear reference for garbage collection\n\n this.#mut_head = (this.#mut_head + 1) % this.#mut_capacity;\n\n this.#mut_size -= 1;\n\n return Optional.some(element);\n }\n\n /**\n * Adds an element to the back of the queue (FIFO).\n *\n * This operation adds the element to the end of the queue, where it will be\n * the last to be dequeued (first-in, first-out ordering). The operation is\n * amortized O(1), meaning it's O(1) for most operations with occasional O(n)\n * when the buffer needs resizing.\n *\n * **Time Complexity:** O(1) amortized - O(n) only when buffer resize is\n * needed **Space Complexity:** O(1) - constant additional memory per element\n *\n * **Buffer Resizing:** When the internal buffer becomes full, it\n * automatically doubles in size and reorganizes elements to maintain the\n * circular buffer structure.\n *\n * @param value The element to add to the back of the queue.\n */\n enqueue(value: T): void {\n // Resize if buffer is full\n if (this.#mut_size === this.#mut_capacity) {\n this.#resize();\n }\n\n this.#mut_buffer[this.#mut_tail] = value;\n\n this.#mut_tail = (this.#mut_tail + 1) % this.#mut_capacity;\n\n this.#mut_size += 1;\n }\n}\n\n/**\n * Creates a new Queue instance with FIFO (First-In, First-Out) behavior using a\n * high-performance circular buffer.\n *\n * This factory function creates an optimized queue implementation that\n * maintains excellent performance characteristics for both enqueue and dequeue\n * operations. The underlying circular buffer automatically resizes to\n * accommodate growing workloads while providing predictable O(1) operations.\n *\n * **Implementation Features:**\n *\n * - **O(1) enqueue operations** (amortized - occasionally O(n) when resizing)\n * - **O(1) dequeue operations** (always)\n * - **Automatic buffer resizing** - starts at 8 elements, doubles when full\n * - **Memory efficient** - garbage collects removed elements immediately\n * - **Circular buffer design** - eliminates need for array shifting operations\n *\n * **Performance Benefits:**\n *\n * - No array copying during normal operations\n * - Minimal memory allocation overhead\n * - Predictable performance under high load\n * - Efficient memory usage with automatic cleanup\n *\n * @example\n *\n * ```ts\n * const queue = createQueue<number>();\n *\n * assert.isTrue(queue.isEmpty);\n *\n * assert.isTrue(queue.size === 0);\n *\n * queue.enqueue(1);\n *\n * queue.enqueue(2);\n *\n * assert.isFalse(queue.isEmpty);\n *\n * assert.isTrue(queue.size === 2);\n *\n * assert.deepStrictEqual(queue.dequeue(), Optional.some(1));\n *\n * assert.deepStrictEqual(queue.dequeue(), Optional.some(2));\n *\n * assert.deepStrictEqual(queue.dequeue(), Optional.none);\n *\n * const seededQueue = createQueue(['first', 'second']);\n *\n * assert.isTrue(seededQueue.size === 2);\n *\n * assert.deepStrictEqual(seededQueue.dequeue(), Optional.some('first'));\n *\n * assert.deepStrictEqual(seededQueue.dequeue(), Optional.some('second'));\n * ```\n *\n * @template T The type of elements stored in the queue.\n * @param initialValues Optional array of initial elements to populate the\n * queue. Elements will be dequeued in the same order they appear in the\n * array. If provided, the initial buffer capacity will be at least twice the\n * array length.\n * @returns A new Queue instance optimized for high-performance FIFO operations.\n */\nexport const createQueue = <T,>(initialValues?: readonly T[]): Queue<T> =>\n new QueueClass<T>(initialValues);\n"],"names":["Optional.none","Optional.some"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8MA,MAAM,UAAA,CAAkC;AAAA;AAAA,EAEtC,OAAgB,iBAAA,GAAoB,CAAA;AAAA;AAAA,EAGpC,WAAA;AAAA;AAAA,EAGA,SAAA;AAAA;AAAA,EAGA,SAAA;AAAA;AAAA,EAGA,SAAA;AAAA;AAAA,EAGA,aAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,WAAA,CAAY,aAAA,GAA8B,EAAC,EAAG;AAC5C,IAAA,MAAM,eAAA,GAAkB,QAAA;AAAA,MACtB,KAAK,GAAA,CAAI,UAAA,CAAW,iBAAA,EAAmB,aAAA,CAAc,SAAS,CAAC;AAAA,KACjE;AAEA,IAAA,IAAA,CAAK,cAAc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,QAAQ,CAAC,GAAG,CAAC;IAEnB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAoCG;IACH,GAAG,EAAE,MAAM,QAAQ,CAAC,CAAC,CAAC,CAAC;IAEvB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAmCG;IACH,IAAI,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,CAAC;CAC1B,CAAC,CAAC;AA+IH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6DG;AACH,eAAO,MAAM,WAAW,GAAI,CAAC,kBAAmB,SAAS,CAAC,EAAE,KAAG,KAAK,CAAC,CAAC,CACpC,CAAC"}
@@ -39,177 +39,107 @@ import '../number/enum/uint8.mjs';
39
39
  import '../number/num.mjs';
40
40
  import '../number/refined-number-utils.mjs';
41
41
 
42
- /**
43
- * Class implementation for a stack with LIFO (Last-In, First-Out) behavior
44
- * using a dynamic array. This implementation provides O(1) amortized push and
45
- * O(1) pop operations by using a resizable buffer that grows as needed.
46
- *
47
- * The underlying array automatically resizes when it becomes full, ensuring
48
- * that the stack can grow to accommodate any number of elements while
49
- * maintaining efficient operations.
50
- *
51
- * @template T The type of elements in the stack.
52
- * @implements Stack
53
- */
54
42
  class StackClass {
55
- /** @internal Initial capacity for new stacks. */
56
- static #INITIAL_CAPACITY = 8;
57
- /** @internal Dynamic array to store stack elements. */
58
- #mut_buffer;
59
- /** @internal Current number of elements in the stack. */
60
- #mut_size;
61
- /** @internal Current capacity of the buffer. */
62
- #mut_capacity;
63
- /**
64
- * Constructs a new StackClass instance.
65
- *
66
- * @param initialValues Optional initial values to populate the stack.
67
- */
68
- constructor(initialValues = []) {
69
- const initialCapacity = asUint32(Math.max(StackClass.#INITIAL_CAPACITY, initialValues.length * 2));
70
- this.#mut_buffer = Array.from({ length: initialCapacity }, () => undefined);
71
- this.#mut_size = asUint32(0);
72
- this.#mut_capacity = initialCapacity;
73
- // Add initial values
74
- for (const value of initialValues) {
75
- this.push(value);
76
- }
43
+ /** @internal Initial capacity for new stacks. */
44
+ static #INITIAL_CAPACITY = 8;
45
+ /** @internal Dynamic array to store stack elements. */
46
+ #mut_buffer;
47
+ /** @internal Current number of elements in the stack. */
48
+ #mut_size;
49
+ /** @internal Current capacity of the buffer. */
50
+ #mut_capacity;
51
+ /**
52
+ * Constructs a new StackClass instance.
53
+ *
54
+ * @param initialValues Optional initial values to populate the stack.
55
+ */
56
+ constructor(initialValues = []) {
57
+ const initialCapacity = asUint32(
58
+ Math.max(StackClass.#INITIAL_CAPACITY, initialValues.length * 2)
59
+ );
60
+ this.#mut_buffer = Array.from(
61
+ { length: initialCapacity },
62
+ () => void 0
63
+ );
64
+ this.#mut_size = asUint32(0);
65
+ this.#mut_capacity = initialCapacity;
66
+ for (const value of initialValues) {
67
+ this.push(value);
77
68
  }
78
- /**
79
- * @internal
80
- * Resizes the buffer when it becomes full.
81
- * Doubles the capacity while preserving all elements.
82
- */
83
- #resize() {
84
- const newCapacity = asUint32(this.#mut_capacity * 2);
85
- const newBuffer = Array.from({ length: newCapacity }, () => undefined);
86
- // Copy existing elements
87
- for (const i of range(this.#mut_size)) {
88
- newBuffer[i] = this.#mut_buffer[i];
89
- }
90
- this.#mut_buffer = newBuffer;
91
- this.#mut_capacity = newCapacity;
69
+ }
70
+ /**
71
+ * @internal
72
+ * Resizes the buffer when it becomes full.
73
+ * Doubles the capacity while preserving all elements.
74
+ */
75
+ #resize() {
76
+ const newCapacity = asUint32(this.#mut_capacity * 2);
77
+ const newBuffer = Array.from(
78
+ { length: newCapacity },
79
+ () => void 0
80
+ );
81
+ for (const i of range(this.#mut_size)) {
82
+ newBuffer[i] = this.#mut_buffer[i];
92
83
  }
93
- /** @inheritdoc */
94
- get isEmpty() {
95
- return this.#mut_size === 0;
84
+ this.#mut_buffer = newBuffer;
85
+ this.#mut_capacity = newCapacity;
86
+ }
87
+ /** @inheritdoc */
88
+ get isEmpty() {
89
+ return this.#mut_size === 0;
90
+ }
91
+ /** @inheritdoc */
92
+ get size() {
93
+ return asUint32(this.#mut_size);
94
+ }
95
+ /**
96
+ * Removes and returns the element at the top of the stack (LIFO).
97
+ *
98
+ * This operation removes the element that was added most recently (last-in)
99
+ * and returns it. If the stack is empty, returns `Optional.none`. The
100
+ * operation is guaranteed to be O(1) and does not require any array resizing
101
+ * or memory reallocation.
102
+ *
103
+ * **Time Complexity:** O(1) - constant time operation **Space Complexity:**
104
+ * O(1) - no additional memory allocation
105
+ *
106
+ * @returns An Optional containing the removed element, or `Optional.none` if
107
+ * the stack is empty.
108
+ */
109
+ pop() {
110
+ if (this.isEmpty) {
111
+ return none;
96
112
  }
97
- /** @inheritdoc */
98
- get size() {
99
- return asUint32(this.#mut_size);
100
- }
101
- /**
102
- * Removes and returns the element at the top of the stack (LIFO).
103
- *
104
- * This operation removes the element that was added most recently (last-in)
105
- * and returns it. If the stack is empty, returns `Optional.none`. The
106
- * operation is guaranteed to be O(1) and does not require any array resizing
107
- * or memory reallocation.
108
- *
109
- * **Time Complexity:** O(1) - constant time operation **Space Complexity:**
110
- * O(1) - no additional memory allocation
111
- *
112
- * @returns An Optional containing the removed element, or `Optional.none` if
113
- * the stack is empty.
114
- */
115
- pop() {
116
- if (this.isEmpty) {
117
- return none;
118
- }
119
- this.#mut_size = Uint32.sub(this.#mut_size, 1);
120
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
121
- const element = this.#mut_buffer[this.#mut_size];
122
- this.#mut_buffer[this.#mut_size] = undefined; // Clear reference for garbage collection
123
- return some(element);
124
- }
125
- /**
126
- * Adds an element to the top of the stack (LIFO).
127
- *
128
- * This operation adds the element to the top of the stack, where it will be
129
- * the first to be popped (last-in, first-out ordering). The operation is
130
- * amortized O(1), meaning it's O(1) for most operations with occasional O(n)
131
- * when the buffer needs resizing.
132
- *
133
- * **Time Complexity:** O(1) amortized - O(n) only when buffer resize is
134
- * needed **Space Complexity:** O(1) - constant additional memory per element
135
- *
136
- * **Buffer Resizing:** When the internal buffer becomes full, it
137
- * automatically doubles in size and copies existing elements to maintain the
138
- * stack structure.
139
- *
140
- * @param value The element to add to the top of the stack.
141
- */
142
- push(value) {
143
- // Resize if buffer is full
144
- if (this.#mut_size === this.#mut_capacity) {
145
- this.#resize();
146
- }
147
- this.#mut_buffer[this.#mut_size] = value;
148
- this.#mut_size = Uint32.add(this.#mut_size, 1);
113
+ this.#mut_size = Uint32.sub(this.#mut_size, 1);
114
+ const element = this.#mut_buffer[this.#mut_size];
115
+ this.#mut_buffer[this.#mut_size] = void 0;
116
+ return some(element);
117
+ }
118
+ /**
119
+ * Adds an element to the top of the stack (LIFO).
120
+ *
121
+ * This operation adds the element to the top of the stack, where it will be
122
+ * the first to be popped (last-in, first-out ordering). The operation is
123
+ * amortized O(1), meaning it's O(1) for most operations with occasional O(n)
124
+ * when the buffer needs resizing.
125
+ *
126
+ * **Time Complexity:** O(1) amortized - O(n) only when buffer resize is
127
+ * needed **Space Complexity:** O(1) - constant additional memory per element
128
+ *
129
+ * **Buffer Resizing:** When the internal buffer becomes full, it
130
+ * automatically doubles in size and copies existing elements to maintain the
131
+ * stack structure.
132
+ *
133
+ * @param value The element to add to the top of the stack.
134
+ */
135
+ push(value) {
136
+ if (this.#mut_size === this.#mut_capacity) {
137
+ this.#resize();
149
138
  }
139
+ this.#mut_buffer[this.#mut_size] = value;
140
+ this.#mut_size = Uint32.add(this.#mut_size, 1);
141
+ }
150
142
  }
151
- /**
152
- * Creates a new Stack instance with LIFO (Last-In, First-Out) behavior using a
153
- * high-performance dynamic array.
154
- *
155
- * This factory function creates an optimized stack implementation that
156
- * maintains excellent performance characteristics for both push and pop
157
- * operations. The underlying dynamic array automatically resizes to accommodate
158
- * growing workloads while providing predictable O(1) operations.
159
- *
160
- * **Implementation Features:**
161
- *
162
- * - **O(1) push operations** (amortized - occasionally O(n) when resizing)
163
- * - **O(1) pop operations** (always)
164
- * - **Automatic buffer resizing** - starts at 8 elements, doubles when full
165
- * - **Memory efficient** - garbage collects removed elements immediately
166
- * - **Dynamic array design** - eliminates need for complex memory management
167
- *
168
- * **Performance Benefits:**
169
- *
170
- * - No array shifting required for stack operations
171
- * - Minimal memory allocation overhead
172
- * - Predictable performance under high load
173
- * - Efficient memory usage with automatic cleanup
174
- *
175
- * @example
176
- *
177
- * ```ts
178
- * const stack = createStack<string>();
179
- *
180
- * assert.isTrue(stack.isEmpty);
181
- *
182
- * assert.isTrue(stack.size === 0);
183
- *
184
- * stack.push('first');
185
- *
186
- * // eslint-disable-next-line unicorn/prefer-single-call
187
- * stack.push('second');
188
- *
189
- * assert.isFalse(stack.isEmpty);
190
- *
191
- * assert.isTrue(stack.size === 2);
192
- *
193
- * assert.deepStrictEqual(stack.pop(), Optional.some('second'));
194
- *
195
- * assert.deepStrictEqual(stack.pop(), Optional.some('first'));
196
- *
197
- * assert.deepStrictEqual(stack.pop(), Optional.none);
198
- *
199
- * const seededStack = createStack([10, 20, 30]);
200
- *
201
- * assert.isTrue(seededStack.size === 3);
202
- *
203
- * assert.deepStrictEqual(seededStack.pop(), Optional.some(30));
204
- * ```
205
- *
206
- * @template T The type of elements stored in the stack.
207
- * @param initialValues Optional array of initial elements to populate the
208
- * stack. Elements will be popped in reverse order of how they appear in the
209
- * array (last array element will be popped first). If provided, the initial
210
- * buffer capacity will be at least twice the array length.
211
- * @returns A new Stack instance optimized for high-performance LIFO operations.
212
- */
213
143
  const createStack = (initialValues) => new StackClass(initialValues);
214
144
 
215
145
  export { createStack };