data-structure-typed 2.0.4 → 2.1.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 (261) hide show
  1. package/CHANGELOG.md +3 -1
  2. package/COMMANDS.md +17 -0
  3. package/README.md +11 -11
  4. package/benchmark/report.html +13 -77
  5. package/benchmark/report.json +158 -190
  6. package/dist/cjs/data-structures/base/iterable-element-base.d.ts +186 -83
  7. package/dist/cjs/data-structures/base/iterable-element-base.js +149 -107
  8. package/dist/cjs/data-structures/base/iterable-element-base.js.map +1 -1
  9. package/dist/cjs/data-structures/base/iterable-entry-base.d.ts +95 -119
  10. package/dist/cjs/data-structures/base/iterable-entry-base.js +59 -116
  11. package/dist/cjs/data-structures/base/iterable-entry-base.js.map +1 -1
  12. package/dist/cjs/data-structures/base/linear-base.d.ts +250 -192
  13. package/dist/cjs/data-structures/base/linear-base.js +137 -274
  14. package/dist/cjs/data-structures/base/linear-base.js.map +1 -1
  15. package/dist/cjs/data-structures/binary-tree/avl-tree-counter.d.ts +126 -158
  16. package/dist/cjs/data-structures/binary-tree/avl-tree-counter.js +171 -205
  17. package/dist/cjs/data-structures/binary-tree/avl-tree-counter.js.map +1 -1
  18. package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.d.ts +100 -69
  19. package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.js +135 -87
  20. package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.js.map +1 -1
  21. package/dist/cjs/data-structures/binary-tree/avl-tree.d.ts +138 -149
  22. package/dist/cjs/data-structures/binary-tree/avl-tree.js +208 -195
  23. package/dist/cjs/data-structures/binary-tree/avl-tree.js.map +1 -1
  24. package/dist/cjs/data-structures/binary-tree/binary-tree.d.ts +476 -632
  25. package/dist/cjs/data-structures/binary-tree/binary-tree.js +608 -875
  26. package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
  27. package/dist/cjs/data-structures/binary-tree/bst.d.ts +258 -306
  28. package/dist/cjs/data-structures/binary-tree/bst.js +505 -481
  29. package/dist/cjs/data-structures/binary-tree/bst.js.map +1 -1
  30. package/dist/cjs/data-structures/binary-tree/red-black-tree.d.ts +107 -179
  31. package/dist/cjs/data-structures/binary-tree/red-black-tree.js +114 -209
  32. package/dist/cjs/data-structures/binary-tree/red-black-tree.js.map +1 -1
  33. package/dist/cjs/data-structures/binary-tree/tree-counter.d.ts +132 -154
  34. package/dist/cjs/data-structures/binary-tree/tree-counter.js +172 -203
  35. package/dist/cjs/data-structures/binary-tree/tree-counter.js.map +1 -1
  36. package/dist/cjs/data-structures/binary-tree/tree-multi-map.d.ts +72 -69
  37. package/dist/cjs/data-structures/binary-tree/tree-multi-map.js +105 -85
  38. package/dist/cjs/data-structures/binary-tree/tree-multi-map.js.map +1 -1
  39. package/dist/cjs/data-structures/graph/abstract-graph.d.ts +238 -233
  40. package/dist/cjs/data-structures/graph/abstract-graph.js +267 -237
  41. package/dist/cjs/data-structures/graph/abstract-graph.js.map +1 -1
  42. package/dist/cjs/data-structures/graph/directed-graph.d.ts +108 -224
  43. package/dist/cjs/data-structures/graph/directed-graph.js +146 -233
  44. package/dist/cjs/data-structures/graph/directed-graph.js.map +1 -1
  45. package/dist/cjs/data-structures/graph/map-graph.d.ts +49 -55
  46. package/dist/cjs/data-structures/graph/map-graph.js +56 -59
  47. package/dist/cjs/data-structures/graph/map-graph.js.map +1 -1
  48. package/dist/cjs/data-structures/graph/undirected-graph.d.ts +103 -146
  49. package/dist/cjs/data-structures/graph/undirected-graph.js +129 -149
  50. package/dist/cjs/data-structures/graph/undirected-graph.js.map +1 -1
  51. package/dist/cjs/data-structures/hash/hash-map.d.ts +164 -338
  52. package/dist/cjs/data-structures/hash/hash-map.js +270 -457
  53. package/dist/cjs/data-structures/hash/hash-map.js.map +1 -1
  54. package/dist/cjs/data-structures/heap/heap.d.ts +214 -289
  55. package/dist/cjs/data-structures/heap/heap.js +340 -349
  56. package/dist/cjs/data-structures/heap/heap.js.map +1 -1
  57. package/dist/cjs/data-structures/heap/max-heap.d.ts +11 -47
  58. package/dist/cjs/data-structures/heap/max-heap.js +11 -66
  59. package/dist/cjs/data-structures/heap/max-heap.js.map +1 -1
  60. package/dist/cjs/data-structures/heap/min-heap.d.ts +12 -47
  61. package/dist/cjs/data-structures/heap/min-heap.js +11 -66
  62. package/dist/cjs/data-structures/heap/min-heap.js.map +1 -1
  63. package/dist/cjs/data-structures/linked-list/doubly-linked-list.d.ts +231 -347
  64. package/dist/cjs/data-structures/linked-list/doubly-linked-list.js +368 -494
  65. package/dist/cjs/data-structures/linked-list/doubly-linked-list.js.map +1 -1
  66. package/dist/cjs/data-structures/linked-list/singly-linked-list.d.ts +261 -310
  67. package/dist/cjs/data-structures/linked-list/singly-linked-list.js +447 -466
  68. package/dist/cjs/data-structures/linked-list/singly-linked-list.js.map +1 -1
  69. package/dist/cjs/data-structures/linked-list/skip-linked-list.d.ts +0 -107
  70. package/dist/cjs/data-structures/linked-list/skip-linked-list.js +0 -100
  71. package/dist/cjs/data-structures/linked-list/skip-linked-list.js.map +1 -1
  72. package/dist/cjs/data-structures/priority-queue/max-priority-queue.d.ts +12 -56
  73. package/dist/cjs/data-structures/priority-queue/max-priority-queue.js +11 -78
  74. package/dist/cjs/data-structures/priority-queue/max-priority-queue.js.map +1 -1
  75. package/dist/cjs/data-structures/priority-queue/min-priority-queue.d.ts +11 -57
  76. package/dist/cjs/data-structures/priority-queue/min-priority-queue.js +10 -79
  77. package/dist/cjs/data-structures/priority-queue/min-priority-queue.js.map +1 -1
  78. package/dist/cjs/data-structures/priority-queue/priority-queue.d.ts +2 -61
  79. package/dist/cjs/data-structures/priority-queue/priority-queue.js +8 -83
  80. package/dist/cjs/data-structures/priority-queue/priority-queue.js.map +1 -1
  81. package/dist/cjs/data-structures/queue/deque.d.ts +227 -254
  82. package/dist/cjs/data-structures/queue/deque.js +309 -348
  83. package/dist/cjs/data-structures/queue/deque.js.map +1 -1
  84. package/dist/cjs/data-structures/queue/queue.d.ts +180 -201
  85. package/dist/cjs/data-structures/queue/queue.js +265 -248
  86. package/dist/cjs/data-structures/queue/queue.js.map +1 -1
  87. package/dist/cjs/data-structures/stack/stack.d.ts +124 -102
  88. package/dist/cjs/data-structures/stack/stack.js +181 -125
  89. package/dist/cjs/data-structures/stack/stack.js.map +1 -1
  90. package/dist/cjs/data-structures/trie/trie.d.ts +164 -165
  91. package/dist/cjs/data-structures/trie/trie.js +189 -172
  92. package/dist/cjs/data-structures/trie/trie.js.map +1 -1
  93. package/dist/cjs/interfaces/binary-tree.d.ts +56 -6
  94. package/dist/cjs/interfaces/graph.d.ts +16 -0
  95. package/dist/cjs/types/data-structures/base/base.d.ts +1 -1
  96. package/dist/cjs/types/data-structures/graph/abstract-graph.d.ts +4 -0
  97. package/dist/cjs/types/utils/utils.d.ts +6 -6
  98. package/dist/cjs/utils/utils.d.ts +110 -49
  99. package/dist/cjs/utils/utils.js +148 -73
  100. package/dist/cjs/utils/utils.js.map +1 -1
  101. package/dist/esm/data-structures/base/iterable-element-base.d.ts +186 -83
  102. package/dist/esm/data-structures/base/iterable-element-base.js +155 -107
  103. package/dist/esm/data-structures/base/iterable-element-base.js.map +1 -1
  104. package/dist/esm/data-structures/base/iterable-entry-base.d.ts +95 -119
  105. package/dist/esm/data-structures/base/iterable-entry-base.js +59 -116
  106. package/dist/esm/data-structures/base/iterable-entry-base.js.map +1 -1
  107. package/dist/esm/data-structures/base/linear-base.d.ts +250 -192
  108. package/dist/esm/data-structures/base/linear-base.js +137 -274
  109. package/dist/esm/data-structures/base/linear-base.js.map +1 -1
  110. package/dist/esm/data-structures/binary-tree/avl-tree-counter.d.ts +126 -158
  111. package/dist/esm/data-structures/binary-tree/avl-tree-counter.js +171 -212
  112. package/dist/esm/data-structures/binary-tree/avl-tree-counter.js.map +1 -1
  113. package/dist/esm/data-structures/binary-tree/avl-tree-multi-map.d.ts +100 -69
  114. package/dist/esm/data-structures/binary-tree/avl-tree-multi-map.js +133 -94
  115. package/dist/esm/data-structures/binary-tree/avl-tree-multi-map.js.map +1 -1
  116. package/dist/esm/data-structures/binary-tree/avl-tree.d.ts +138 -149
  117. package/dist/esm/data-structures/binary-tree/avl-tree.js +206 -200
  118. package/dist/esm/data-structures/binary-tree/avl-tree.js.map +1 -1
  119. package/dist/esm/data-structures/binary-tree/binary-tree.d.ts +476 -632
  120. package/dist/esm/data-structures/binary-tree/binary-tree.js +613 -885
  121. package/dist/esm/data-structures/binary-tree/binary-tree.js.map +1 -1
  122. package/dist/esm/data-structures/binary-tree/bst.d.ts +258 -306
  123. package/dist/esm/data-structures/binary-tree/bst.js +507 -487
  124. package/dist/esm/data-structures/binary-tree/bst.js.map +1 -1
  125. package/dist/esm/data-structures/binary-tree/red-black-tree.d.ts +107 -179
  126. package/dist/esm/data-structures/binary-tree/red-black-tree.js +114 -215
  127. package/dist/esm/data-structures/binary-tree/red-black-tree.js.map +1 -1
  128. package/dist/esm/data-structures/binary-tree/tree-counter.d.ts +132 -154
  129. package/dist/esm/data-structures/binary-tree/tree-counter.js +175 -209
  130. package/dist/esm/data-structures/binary-tree/tree-counter.js.map +1 -1
  131. package/dist/esm/data-structures/binary-tree/tree-multi-map.d.ts +72 -69
  132. package/dist/esm/data-structures/binary-tree/tree-multi-map.js +103 -92
  133. package/dist/esm/data-structures/binary-tree/tree-multi-map.js.map +1 -1
  134. package/dist/esm/data-structures/graph/abstract-graph.d.ts +238 -233
  135. package/dist/esm/data-structures/graph/abstract-graph.js +267 -237
  136. package/dist/esm/data-structures/graph/abstract-graph.js.map +1 -1
  137. package/dist/esm/data-structures/graph/directed-graph.d.ts +108 -224
  138. package/dist/esm/data-structures/graph/directed-graph.js +145 -233
  139. package/dist/esm/data-structures/graph/directed-graph.js.map +1 -1
  140. package/dist/esm/data-structures/graph/map-graph.d.ts +49 -55
  141. package/dist/esm/data-structures/graph/map-graph.js +56 -59
  142. package/dist/esm/data-structures/graph/map-graph.js.map +1 -1
  143. package/dist/esm/data-structures/graph/undirected-graph.d.ts +103 -146
  144. package/dist/esm/data-structures/graph/undirected-graph.js +128 -149
  145. package/dist/esm/data-structures/graph/undirected-graph.js.map +1 -1
  146. package/dist/esm/data-structures/hash/hash-map.d.ts +164 -338
  147. package/dist/esm/data-structures/hash/hash-map.js +270 -457
  148. package/dist/esm/data-structures/hash/hash-map.js.map +1 -1
  149. package/dist/esm/data-structures/heap/heap.d.ts +214 -289
  150. package/dist/esm/data-structures/heap/heap.js +329 -349
  151. package/dist/esm/data-structures/heap/heap.js.map +1 -1
  152. package/dist/esm/data-structures/heap/max-heap.d.ts +11 -47
  153. package/dist/esm/data-structures/heap/max-heap.js +11 -66
  154. package/dist/esm/data-structures/heap/max-heap.js.map +1 -1
  155. package/dist/esm/data-structures/heap/min-heap.d.ts +12 -47
  156. package/dist/esm/data-structures/heap/min-heap.js +11 -66
  157. package/dist/esm/data-structures/heap/min-heap.js.map +1 -1
  158. package/dist/esm/data-structures/linked-list/doubly-linked-list.d.ts +231 -347
  159. package/dist/esm/data-structures/linked-list/doubly-linked-list.js +368 -495
  160. package/dist/esm/data-structures/linked-list/doubly-linked-list.js.map +1 -1
  161. package/dist/esm/data-structures/linked-list/singly-linked-list.d.ts +261 -310
  162. package/dist/esm/data-structures/linked-list/singly-linked-list.js +448 -467
  163. package/dist/esm/data-structures/linked-list/singly-linked-list.js.map +1 -1
  164. package/dist/esm/data-structures/linked-list/skip-linked-list.d.ts +0 -107
  165. package/dist/esm/data-structures/linked-list/skip-linked-list.js +0 -100
  166. package/dist/esm/data-structures/linked-list/skip-linked-list.js.map +1 -1
  167. package/dist/esm/data-structures/priority-queue/max-priority-queue.d.ts +12 -56
  168. package/dist/esm/data-structures/priority-queue/max-priority-queue.js +11 -78
  169. package/dist/esm/data-structures/priority-queue/max-priority-queue.js.map +1 -1
  170. package/dist/esm/data-structures/priority-queue/min-priority-queue.d.ts +11 -57
  171. package/dist/esm/data-structures/priority-queue/min-priority-queue.js +10 -79
  172. package/dist/esm/data-structures/priority-queue/min-priority-queue.js.map +1 -1
  173. package/dist/esm/data-structures/priority-queue/priority-queue.d.ts +2 -61
  174. package/dist/esm/data-structures/priority-queue/priority-queue.js +8 -83
  175. package/dist/esm/data-structures/priority-queue/priority-queue.js.map +1 -1
  176. package/dist/esm/data-structures/queue/deque.d.ts +227 -254
  177. package/dist/esm/data-structures/queue/deque.js +313 -348
  178. package/dist/esm/data-structures/queue/deque.js.map +1 -1
  179. package/dist/esm/data-structures/queue/queue.d.ts +180 -201
  180. package/dist/esm/data-structures/queue/queue.js +263 -248
  181. package/dist/esm/data-structures/queue/queue.js.map +1 -1
  182. package/dist/esm/data-structures/stack/stack.d.ts +124 -102
  183. package/dist/esm/data-structures/stack/stack.js +181 -125
  184. package/dist/esm/data-structures/stack/stack.js.map +1 -1
  185. package/dist/esm/data-structures/trie/trie.d.ts +164 -165
  186. package/dist/esm/data-structures/trie/trie.js +193 -172
  187. package/dist/esm/data-structures/trie/trie.js.map +1 -1
  188. package/dist/esm/interfaces/binary-tree.d.ts +56 -6
  189. package/dist/esm/interfaces/graph.d.ts +16 -0
  190. package/dist/esm/types/data-structures/base/base.d.ts +1 -1
  191. package/dist/esm/types/data-structures/graph/abstract-graph.d.ts +4 -0
  192. package/dist/esm/types/utils/utils.d.ts +6 -6
  193. package/dist/esm/utils/utils.d.ts +110 -49
  194. package/dist/esm/utils/utils.js +139 -68
  195. package/dist/esm/utils/utils.js.map +1 -1
  196. package/dist/umd/data-structure-typed.js +4737 -6525
  197. package/dist/umd/data-structure-typed.min.js +8 -6
  198. package/dist/umd/data-structure-typed.min.js.map +1 -1
  199. package/package.json +3 -4
  200. package/src/data-structures/base/iterable-element-base.ts +238 -115
  201. package/src/data-structures/base/iterable-entry-base.ts +96 -120
  202. package/src/data-structures/base/linear-base.ts +271 -277
  203. package/src/data-structures/binary-tree/avl-tree-counter.ts +198 -216
  204. package/src/data-structures/binary-tree/avl-tree-multi-map.ts +192 -101
  205. package/src/data-structures/binary-tree/avl-tree.ts +239 -206
  206. package/src/data-structures/binary-tree/binary-tree.ts +677 -901
  207. package/src/data-structures/binary-tree/bst.ts +568 -570
  208. package/src/data-structures/binary-tree/red-black-tree.ts +161 -222
  209. package/src/data-structures/binary-tree/tree-counter.ts +199 -218
  210. package/src/data-structures/binary-tree/tree-multi-map.ts +131 -97
  211. package/src/data-structures/graph/abstract-graph.ts +339 -264
  212. package/src/data-structures/graph/directed-graph.ts +146 -236
  213. package/src/data-structures/graph/map-graph.ts +63 -60
  214. package/src/data-structures/graph/undirected-graph.ts +129 -152
  215. package/src/data-structures/hash/hash-map.ts +274 -496
  216. package/src/data-structures/heap/heap.ts +389 -402
  217. package/src/data-structures/heap/max-heap.ts +12 -76
  218. package/src/data-structures/heap/min-heap.ts +13 -76
  219. package/src/data-structures/linked-list/doubly-linked-list.ts +426 -530
  220. package/src/data-structures/linked-list/singly-linked-list.ts +495 -517
  221. package/src/data-structures/linked-list/skip-linked-list.ts +1 -108
  222. package/src/data-structures/priority-queue/max-priority-queue.ts +12 -87
  223. package/src/data-structures/priority-queue/min-priority-queue.ts +11 -88
  224. package/src/data-structures/priority-queue/priority-queue.ts +3 -92
  225. package/src/data-structures/queue/deque.ts +381 -357
  226. package/src/data-structures/queue/queue.ts +310 -264
  227. package/src/data-structures/stack/stack.ts +217 -131
  228. package/src/data-structures/trie/trie.ts +240 -175
  229. package/src/interfaces/binary-tree.ts +240 -6
  230. package/src/interfaces/graph.ts +37 -0
  231. package/src/types/data-structures/base/base.ts +5 -5
  232. package/src/types/data-structures/graph/abstract-graph.ts +5 -0
  233. package/src/types/utils/utils.ts +9 -5
  234. package/src/utils/utils.ts +152 -86
  235. package/test/integration/index.html +1 -1
  236. package/test/performance/benchmark-runner.ts +528 -0
  237. package/test/performance/reportor.mjs +43 -43
  238. package/test/performance/runner-config.json +39 -0
  239. package/test/performance/single-suite-runner.ts +69 -0
  240. package/test/unit/data-structures/binary-tree/avl-tree-counter.test.ts +3 -3
  241. package/test/unit/data-structures/binary-tree/avl-tree-multi-map.test.ts +5 -5
  242. package/test/unit/data-structures/binary-tree/avl-tree.test.ts +4 -4
  243. package/test/unit/data-structures/binary-tree/binary-tree.test.ts +350 -90
  244. package/test/unit/data-structures/binary-tree/bst.test.ts +84 -5
  245. package/test/unit/data-structures/binary-tree/red-black-tree.test.ts +2 -2
  246. package/test/unit/data-structures/binary-tree/tree-counter.test.ts +25 -24
  247. package/test/unit/data-structures/binary-tree/tree-multi-map.test.ts +3 -3
  248. package/test/unit/data-structures/graph/abstract-graph.test.ts +0 -4
  249. package/test/unit/data-structures/graph/directed-graph.test.ts +1 -1
  250. package/test/unit/data-structures/heap/heap.test.ts +14 -21
  251. package/test/unit/data-structures/heap/max-heap.test.ts +5 -9
  252. package/test/unit/data-structures/heap/min-heap.test.ts +1 -4
  253. package/test/unit/data-structures/linked-list/doubly-linked-list.test.ts +14 -14
  254. package/test/unit/data-structures/linked-list/singly-linked-list.test.ts +0 -7
  255. package/test/unit/data-structures/priority-queue/max-priority-queue.test.ts +8 -11
  256. package/test/unit/data-structures/priority-queue/min-priority-queue.test.ts +1 -4
  257. package/test/unit/data-structures/priority-queue/priority-queue.test.ts +1 -4
  258. package/test/unit/data-structures/queue/queue.test.ts +4 -5
  259. package/test/unit/utils/utils.test.ts +0 -1
  260. package/test/performance/data-structures/binary-tree/avl-tree.test.mjs +0 -71
  261. package/test/performance/data-structures/binary-tree/red-black-tree.test.mjs +0 -81
@@ -1,9 +1,59 @@
1
1
  import { BinaryTreeNode } from '../data-structures';
2
- import type { BinaryTreeDeleteResult, BinaryTreeOptions, BTNRep, NodePredicate } from '../types';
3
- export interface IBinaryTree<K = any, V = any, R = object, MK = any, MV = any, MR = object> {
4
- createNode(key: K, value?: BinaryTreeNode['value']): BinaryTreeNode;
5
- createTree(options?: Partial<BinaryTreeOptions<K, V, R>>): IBinaryTree<K, V, R, MK, MV, MR>;
2
+ import type { BinaryTreeDeleteResult, BinaryTreeOptions, BTNRep, DFSOrderPattern, EntryCallback, IterationType, NodeCallback, NodePredicate, OptNodeOrNull, ReduceEntryCallback, ToEntryFn } from '../types';
3
+ /**
4
+ * Public, implementation-agnostic binary tree API.
5
+ * K = key, V = value, R = raw/record used with toEntryFn (optional).
6
+ * Transforming methods like `map` use method-level generics MK/MV/MR.
7
+ */
8
+ export interface IBinaryTree<K = any, V = any, R extends object = object> {
9
+ readonly size: number;
10
+ readonly root: BinaryTreeNode<K, V> | null | undefined;
11
+ readonly isMapMode: boolean;
12
+ iterationType: IterationType;
13
+ readonly NIL: BinaryTreeNode<K, V>;
14
+ readonly store: Map<K, V | undefined>;
15
+ readonly toEntryFn?: ToEntryFn<K, V, R>;
16
+ readonly isDuplicate: boolean;
17
+ _createNode(key: K, value?: BinaryTreeNode<K, V>['value']): BinaryTreeNode<K, V>;
18
+ createTree(options?: Partial<BinaryTreeOptions<K, V, R>>): IBinaryTree<K, V, R>;
6
19
  add(keyOrNodeOrEntryOrRawElement: BTNRep<K, V, BinaryTreeNode<K, V>>, value?: V, count?: number): boolean;
7
- addMany(nodes: Iterable<BTNRep<K, V, BinaryTreeNode<K, V>>>, values?: Iterable<V | undefined>): boolean[];
8
- delete(predicate: R | BTNRep<K, V, BinaryTreeNode<K, V>> | NodePredicate<BinaryTreeNode<K, V>>): BinaryTreeDeleteResult<BinaryTreeNode<K, V>>[];
20
+ addMany(keysNodesEntriesOrRaws: Iterable<K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined | R>, values?: Iterable<V | undefined>): boolean[];
21
+ delete(keyNodeEntryRawOrPredicate: R | BTNRep<K, V, BinaryTreeNode<K, V>> | NodePredicate<BinaryTreeNode<K, V> | null>): BinaryTreeDeleteResult<BinaryTreeNode<K, V>>[];
22
+ clear(): void;
23
+ isEmpty(): boolean;
24
+ get(keyNodeEntryOrPredicate: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, startNode?: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, iterationType?: IterationType): V | undefined;
25
+ has(keyNodeEntryOrPredicate?: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined | NodePredicate<BinaryTreeNode<K, V> | null>, startNode?: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, iterationType?: IterationType): boolean;
26
+ hasValue(value: V): boolean;
27
+ find(predicate: EntryCallback<K, V | undefined, boolean>, thisArg?: unknown): [K, V | undefined] | undefined;
28
+ [Symbol.iterator](): IterableIterator<[K, V | undefined]>;
29
+ entries(): IterableIterator<[K, V | undefined]>;
30
+ keys(): IterableIterator<K>;
31
+ values(): IterableIterator<V | undefined>;
32
+ forEach(callbackfn: EntryCallback<K, V | undefined, void>, thisArg?: unknown): void;
33
+ every(callbackfn: EntryCallback<K, V | undefined, boolean>, thisArg?: unknown): boolean;
34
+ some(callbackfn: EntryCallback<K, V | undefined, boolean>, thisArg?: unknown): boolean;
35
+ reduce<U>(reducer: ReduceEntryCallback<K, V | undefined, U>, initialValue: U): U;
36
+ getNode(keyNodeEntryOrPredicate: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined | NodePredicate<BinaryTreeNode<K, V> | null>, startNode?: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, iterationType?: IterationType): OptNodeOrNull<BinaryTreeNode<K, V>>;
37
+ getLeftMost<C extends NodeCallback<OptNodeOrNull<BinaryTreeNode<K, V>>>>(callback?: C, startNode?: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, iterationType?: IterationType): ReturnType<C>;
38
+ getRightMost<C extends NodeCallback<BinaryTreeNode<K, V> | undefined>>(callback?: C, startNode?: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, iterationType?: IterationType): ReturnType<C>;
39
+ dfs<C extends NodeCallback<BinaryTreeNode<K, V>>>(callback?: C, pattern?: DFSOrderPattern, onlyOne?: boolean, startNode?: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, iterationType?: IterationType): ReturnType<C>[];
40
+ dfs<C extends NodeCallback<BinaryTreeNode<K, V> | null>>(callback?: C, pattern?: DFSOrderPattern, onlyOne?: boolean, startNode?: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, iterationType?: IterationType, includeNull?: boolean): ReturnType<C>[];
41
+ bfs<C extends NodeCallback<BinaryTreeNode<K, V>>>(callback?: C, startNode?: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, iterationType?: IterationType, includeNull?: false): ReturnType<C>[];
42
+ bfs<C extends NodeCallback<BinaryTreeNode<K, V> | null>>(callback?: C, startNode?: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, iterationType?: IterationType, includeNull?: true): ReturnType<C>[];
43
+ morris<C extends NodeCallback<BinaryTreeNode<K, V> | null>>(callback?: C, pattern?: DFSOrderPattern, startNode?: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined): ReturnType<C>[];
44
+ leaves<C extends NodeCallback<BinaryTreeNode<K, V> | null>>(callback?: C, startNode?: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, iterationType?: IterationType): ReturnType<C>[];
45
+ listLevels<C extends NodeCallback<BinaryTreeNode<K, V>>>(callback?: C, startNode?: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, iterationType?: IterationType, includeNull?: false): ReturnType<C>[][];
46
+ listLevels<C extends NodeCallback<BinaryTreeNode<K, V> | null>>(callback?: C, startNode?: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, iterationType?: IterationType, includeNull?: true): ReturnType<C>[][];
47
+ getPathToRoot<C extends NodeCallback<OptNodeOrNull<BinaryTreeNode<K, V>>>>(beginNode: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, callback?: C, isReverse?: boolean): ReturnType<C>[];
48
+ getDepth(dist: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, startNode?: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined): number;
49
+ getHeight(startNode?: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, iterationType?: IterationType): number;
50
+ getMinHeight(startNode?: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, iterationType?: IterationType): number;
51
+ isPerfectlyBalanced(startNode?: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined): boolean;
52
+ isBST(startNode?: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, iterationType?: IterationType): boolean;
53
+ search<C extends NodeCallback<BinaryTreeNode<K, V> | null>>(keyNodeEntryOrPredicate: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined | NodePredicate<BinaryTreeNode<K, V> | null>, onlyOne?: boolean, callback?: C, startNode?: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, iterationType?: IterationType): ReturnType<C>[];
54
+ clone(): this;
55
+ filter(predicate: EntryCallback<K, V | undefined, boolean>, thisArg?: unknown): this;
56
+ map<MK = K, MV = V, MR extends object = object>(callback: EntryCallback<K, V | undefined, [MK, MV]>, options?: Partial<BinaryTreeOptions<MK, MV, MR>>, thisArg?: unknown): IBinaryTree<MK, MV, MR>;
57
+ merge(anotherTree: IBinaryTree<K, V, R>): void;
58
+ refill(keysNodesEntriesOrRaws: Iterable<K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined | R>, values?: Iterable<V | undefined>): void;
9
59
  }
@@ -2,4 +2,20 @@ import { VertexKey } from '../types';
2
2
  export interface IGraph<V, E, VO, EO> {
3
3
  createVertex(key: VertexKey, value?: V): VO;
4
4
  createEdge(srcOrV1: VertexKey, destOrV2: VertexKey, weight?: number, value?: E): EO;
5
+ getVertex(vertexKey: VertexKey): VO | undefined;
6
+ hasVertex(vertexOrKey: VO | VertexKey): boolean;
7
+ addVertex(vertex: VO): boolean;
8
+ addVertex(key: VertexKey, value?: V): boolean;
9
+ deleteVertex(vertexOrKey: VO | VertexKey): boolean;
10
+ deleteEdge(edge: EO): EO | undefined;
11
+ getEdge(srcOrKey: VO | VertexKey, destOrKey: VO | VertexKey): EO | undefined;
12
+ degreeOf(vertexOrKey: VO | VertexKey): number;
13
+ edgeSet(): EO[];
14
+ edgesOf(vertexOrKey: VO | VertexKey): EO[];
15
+ getNeighbors(vertexOrKey: VO | VertexKey): VO[];
16
+ getEndsOfEdge(edge: EO): [VO, VO] | undefined;
17
+ isEmpty(): boolean;
18
+ clear(): void;
19
+ clone(): this;
20
+ filter(...args: any[]): this;
5
21
  }
@@ -3,7 +3,7 @@ import { LinearBase } from '../../../data-structures/base/linear-base';
3
3
  export type EntryCallback<K, V, R> = (key: K, value: V, index: number, original: IterableEntryBase<K, V>) => R;
4
4
  export type ElementCallback<E, R, RT> = (element: E, index: number, original: IterableElementBase<E, R>) => RT;
5
5
  export type ReduceEntryCallback<K, V, R> = (accumulator: R, value: V, key: K, index: number, original: IterableEntryBase<K, V>) => R;
6
- export type ReduceElementCallback<E, R, RT = E> = (accumulator: RT, element: E, index: number, original: IterableElementBase<E, R>) => RT;
6
+ export type ReduceElementCallback<E, R, U = E> = (accumulator: U, value: E, index: number, self: IterableElementBase<E, R>) => U;
7
7
  export type ReduceLinearCallback<E, RT = E> = (accumulator: RT, element: E, index: number, original: LinearBase<E>) => RT;
8
8
  export type IterableElementBaseOptions<E, R> = {
9
9
  toElementFn?: (rawElement: R) => E;
@@ -8,3 +8,7 @@ export type DijkstraResult<V> = {
8
8
  minDist: number;
9
9
  minPath: V[];
10
10
  } | undefined;
11
+ export type GraphOptions<V = any> = {
12
+ vertexValueInitializer?: (key: VertexKey) => V;
13
+ defaultEdgeWeight?: number;
14
+ };
@@ -1,12 +1,7 @@
1
- export type ToThunkFn<R = any> = () => R;
2
- export type Thunk<R = any> = ToThunkFn<R> & {
3
- __THUNK__?: symbol;
4
- };
5
- export type TrlFn<A extends any[] = any[], R = any> = (...args: A) => R;
6
- export type TrlAsyncFn = (...args: any[]) => any;
7
1
  export type SpecifyOptional<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
8
2
  export type Any = string | number | bigint | boolean | symbol | undefined | object;
9
3
  export type Arithmetic = number | bigint;
4
+ export type ElemOf<T> = T extends (infer U)[] ? U : never;
10
5
  export type ComparablePrimitive = number | bigint | string | boolean;
11
6
  export interface BaseComparableObject {
12
7
  [key: string]: unknown;
@@ -20,3 +15,8 @@ export interface StringComparableObject extends BaseComparableObject {
20
15
  }
21
16
  export type ComparableObject = ValueComparableObject | StringComparableObject;
22
17
  export type Comparable = ComparablePrimitive | Date | ComparableObject;
18
+ export type TrampolineThunk<T> = {
19
+ readonly isThunk: true;
20
+ readonly fn: () => Trampoline<T>;
21
+ };
22
+ export type Trampoline<T> = T | TrampolineThunk<T>;
@@ -5,7 +5,7 @@
5
5
  * @copyright Copyright (c) 2022 Pablo Zeng <zrwusa@gmail.com>
6
6
  * @license MIT License
7
7
  */
8
- import type { Comparable, Thunk, ToThunkFn, TrlAsyncFn, TrlFn } from '../types';
8
+ import type { Comparable, Trampoline, TrampolineThunk } from '../types';
9
9
  /**
10
10
  * The function generates a random UUID (Universally Unique Identifier) in TypeScript.
11
11
  * @returns A randomly generated UUID (Universally Unique Identifier) in the format
@@ -23,54 +23,6 @@ export declare const uuidV4: () => string;
23
23
  * `predicate` function.
24
24
  */
25
25
  export declare const arrayRemove: <T>(array: T[], predicate: (item: T, index: number, array: T[]) => boolean) => T[];
26
- export declare const THUNK_SYMBOL: unique symbol;
27
- /**
28
- * The function `isThunk` checks if a given value is a function with a specific symbol property.
29
- * @param {any} fnOrValue - The `fnOrValue` parameter in the `isThunk` function can be either a
30
- * function or a value that you want to check if it is a thunk. Thunks are functions that are wrapped
31
- * around a value or computation for lazy evaluation. The function checks if the `fnOrValue` is
32
- * @returns The function `isThunk` is checking if the input `fnOrValue` is a function and if it has a
33
- * property `__THUNK__` equal to `THUNK_SYMBOL`. The return value will be `true` if both conditions are
34
- * met, otherwise it will be `false`.
35
- */
36
- export declare const isThunk: (fnOrValue: any) => boolean;
37
- /**
38
- * The `toThunk` function in TypeScript converts a function into a thunk by wrapping it in a closure.
39
- * @param {ToThunkFn} fn - `fn` is a function that will be converted into a thunk.
40
- * @returns A thunk function is being returned. Thunk functions are functions that delay the evaluation
41
- * of an expression or operation until it is explicitly called or invoked. In this case, the `toThunk`
42
- * function takes a function `fn` as an argument and returns a thunk function that, when called, will
43
- * execute the `fn` function provided as an argument.
44
- */
45
- export declare const toThunk: (fn: ToThunkFn) => Thunk;
46
- /**
47
- * The `trampoline` function in TypeScript enables tail call optimization by using thunks to avoid
48
- * stack overflow.
49
- * @param {TrlFn} fn - The `fn` parameter in the `trampoline` function is a function that takes any
50
- * number of arguments and returns a value.
51
- * @returns The `trampoline` function returns an object with two properties:
52
- * 1. A function that executes the provided function `fn` and continues to execute any thunks returned
53
- * by `fn` until a non-thunk value is returned.
54
- * 2. A `cont` property that is a function which creates a thunk for the provided function `fn`.
55
- */
56
- export declare const trampoline: (fn: TrlFn) => ((...args: [...Parameters<TrlFn>]) => any) & {
57
- cont: (...args: [...Parameters<TrlFn>]) => ReturnType<TrlFn>;
58
- };
59
- /**
60
- * The `trampolineAsync` function in TypeScript allows for asynchronous trampolining of a given
61
- * function.
62
- * @param {TrlAsyncFn} fn - The `fn` parameter in the `trampolineAsync` function is expected to be a
63
- * function that returns a Promise. This function will be called recursively until a non-thunk value is
64
- * returned.
65
- * @returns The `trampolineAsync` function returns an object with two properties:
66
- * 1. An async function that executes the provided `TrlAsyncFn` function and continues to execute any
67
- * thunks returned by the function until a non-thunk value is returned.
68
- * 2. A `cont` property that is a function which wraps the provided `TrlAsyncFn` function in a thunk
69
- * and returns it.
70
- */
71
- export declare const trampolineAsync: (fn: TrlAsyncFn) => ((...args: [...Parameters<TrlAsyncFn>]) => Promise<any>) & {
72
- cont: (...args: [...Parameters<TrlAsyncFn>]) => ReturnType<TrlAsyncFn>;
73
- };
74
26
  /**
75
27
  * The function `getMSB` returns the most significant bit of a given number.
76
28
  * @param {number} value - The `value` parameter is a number for which we want to find the position of
@@ -146,3 +98,112 @@ export declare const roundFixed: (num: number, digit?: number) => number;
146
98
  * considered comparable or not.
147
99
  */
148
100
  export declare function isComparable(value: unknown, isForceObjectComparable?: boolean): value is Comparable;
101
+ /**
102
+ * Creates a trampoline thunk object.
103
+ *
104
+ * A "thunk" is a deferred computation — instead of performing a recursive call immediately,
105
+ * it wraps the next step of the computation in a function. This allows recursive processes
106
+ * to be executed iteratively, preventing stack overflows.
107
+ *
108
+ * @template T - The type of the final computation result.
109
+ * @param computation - A function that, when executed, returns the next trampoline step.
110
+ * @returns A TrampolineThunk object containing the deferred computation.
111
+ */
112
+ export declare const makeTrampolineThunk: <T>(computation: () => Trampoline<T>) => TrampolineThunk<T>;
113
+ /**
114
+ * Type guard to check whether a given value is a TrampolineThunk.
115
+ *
116
+ * This function is used to distinguish between a final computation result (value)
117
+ * and a deferred computation (thunk).
118
+ *
119
+ * @template T - The type of the value being checked.
120
+ * @param value - The value to test.
121
+ * @returns True if the value is a valid TrampolineThunk, false otherwise.
122
+ */
123
+ export declare const isTrampolineThunk: <T>(value: Trampoline<T>) => value is TrampolineThunk<T>;
124
+ /**
125
+ * Executes a trampoline computation until a final (non-thunk) result is obtained.
126
+ *
127
+ * The trampoline function repeatedly invokes the deferred computations (thunks)
128
+ * in an iterative loop. This avoids deep recursive calls and prevents stack overflow,
129
+ * which is particularly useful for implementing recursion in a stack-safe manner.
130
+ *
131
+ * @template T - The type of the final result.
132
+ * @param initial - The initial Trampoline value or thunk to start execution from.
133
+ * @returns The final result of the computation (a non-thunk value).
134
+ */
135
+ export declare function trampoline<T>(initial: Trampoline<T>): T;
136
+ /**
137
+ * Wraps a recursive function inside a trampoline executor.
138
+ *
139
+ * This function transforms a potentially recursive function (that returns a Trampoline<Result>)
140
+ * into a *stack-safe* function that executes iteratively using the `trampoline` runner.
141
+ *
142
+ * In other words, it allows you to write functions that look recursive,
143
+ * but actually run in constant stack space.
144
+ *
145
+ * @template Args - The tuple type representing the argument list of the original function.
146
+ * @template Result - The final return type after all trampoline steps are resolved.
147
+ *
148
+ * @param fn - A function that performs a single step of computation
149
+ * and returns a Trampoline (either a final value or a deferred thunk).
150
+ *
151
+ * @returns A new function with the same arguments, but which automatically
152
+ * runs the trampoline process and returns the *final result* instead
153
+ * of a Trampoline.
154
+ *
155
+ * @example
156
+ * // Example: Computing factorial in a stack-safe way
157
+ * const factorial = makeTrampoline(function fact(n: number, acc: number = 1): Trampoline<number> {
158
+ * return n === 0
159
+ * ? acc
160
+ * : makeTrampolineThunk(() => fact(n - 1, acc * n));
161
+ * });
162
+ *
163
+ * console.log(factorial(100000)); // Works without stack overflow
164
+ */
165
+ export declare function makeTrampoline<Args extends any[], Result>(fn: (...args: Args) => Trampoline<Result>): (...args: Args) => Result;
166
+ /**
167
+ * Executes an asynchronous trampoline computation until a final (non-thunk) result is obtained.
168
+ *
169
+ * This function repeatedly invokes asynchronous deferred computations (thunks)
170
+ * in an iterative loop. Each thunk may return either a Trampoline<T> or a Promise<Trampoline<T>>.
171
+ *
172
+ * It ensures that asynchronous recursive functions can run without growing the call stack,
173
+ * making it suitable for stack-safe async recursion.
174
+ *
175
+ * @template T - The type of the final result.
176
+ * @param initial - The initial Trampoline or Promise of Trampoline to start execution from.
177
+ * @returns A Promise that resolves to the final result (a non-thunk value).
178
+ */
179
+ export declare function asyncTrampoline<T>(initial: Trampoline<T> | Promise<Trampoline<T>>): Promise<T>;
180
+ /**
181
+ * Wraps an asynchronous recursive function inside an async trampoline executor.
182
+ *
183
+ * This helper transforms a recursive async function that returns a Trampoline<Result>
184
+ * (or Promise<Trampoline<Result>>) into a *stack-safe* async function that executes
185
+ * iteratively via the `asyncTrampoline` runner.
186
+ *
187
+ * @template Args - The tuple type representing the argument list of the original function.
188
+ * @template Result - The final return type after all async trampoline steps are resolved.
189
+ *
190
+ * @param fn - An async or sync function that performs a single step of computation
191
+ * and returns a Trampoline (either a final value or a deferred thunk).
192
+ *
193
+ * @returns An async function with the same arguments, but which automatically
194
+ * runs the trampoline process and resolves to the *final result*.
195
+ *
196
+ * @example
197
+ * // Example: Async factorial using trampoline
198
+ * const asyncFactorial = makeAsyncTrampoline(async function fact(
199
+ * n: number,
200
+ * acc: number = 1
201
+ * ): Promise<Trampoline<number>> {
202
+ * return n === 0
203
+ * ? acc
204
+ * : makeTrampolineThunk(() => fact(n - 1, acc * n));
205
+ * });
206
+ *
207
+ * asyncFactorial(100000).then(console.log); // Works without stack overflow
208
+ */
209
+ export declare function makeAsyncTrampoline<Args extends any[], Result>(fn: (...args: Args) => Trampoline<Result> | Promise<Trampoline<Result>>): (...args: Args) => Promise<Result>;
@@ -9,8 +9,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.roundFixed = exports.calcMinUnitsRequired = exports.isWeakKey = exports.throwRangeError = exports.rangeCheck = exports.getMSB = exports.trampolineAsync = exports.trampoline = exports.toThunk = exports.isThunk = exports.THUNK_SYMBOL = exports.arrayRemove = exports.uuidV4 = void 0;
12
+ exports.isTrampolineThunk = exports.makeTrampolineThunk = exports.roundFixed = exports.calcMinUnitsRequired = exports.isWeakKey = exports.throwRangeError = exports.rangeCheck = exports.getMSB = exports.arrayRemove = exports.uuidV4 = void 0;
13
13
  exports.isComparable = isComparable;
14
+ exports.trampoline = trampoline;
15
+ exports.makeTrampoline = makeTrampoline;
16
+ exports.asyncTrampoline = asyncTrampoline;
17
+ exports.makeAsyncTrampoline = makeAsyncTrampoline;
14
18
  /**
15
19
  * The function generates a random UUID (Universally Unique Identifier) in TypeScript.
16
20
  * @returns A randomly generated UUID (Universally Unique Identifier) in the format
@@ -47,78 +51,6 @@ const arrayRemove = function (array, predicate) {
47
51
  return result;
48
52
  };
49
53
  exports.arrayRemove = arrayRemove;
50
- exports.THUNK_SYMBOL = Symbol('thunk');
51
- /**
52
- * The function `isThunk` checks if a given value is a function with a specific symbol property.
53
- * @param {any} fnOrValue - The `fnOrValue` parameter in the `isThunk` function can be either a
54
- * function or a value that you want to check if it is a thunk. Thunks are functions that are wrapped
55
- * around a value or computation for lazy evaluation. The function checks if the `fnOrValue` is
56
- * @returns The function `isThunk` is checking if the input `fnOrValue` is a function and if it has a
57
- * property `__THUNK__` equal to `THUNK_SYMBOL`. The return value will be `true` if both conditions are
58
- * met, otherwise it will be `false`.
59
- */
60
- const isThunk = (fnOrValue) => {
61
- return typeof fnOrValue === 'function' && fnOrValue.__THUNK__ === exports.THUNK_SYMBOL;
62
- };
63
- exports.isThunk = isThunk;
64
- /**
65
- * The `toThunk` function in TypeScript converts a function into a thunk by wrapping it in a closure.
66
- * @param {ToThunkFn} fn - `fn` is a function that will be converted into a thunk.
67
- * @returns A thunk function is being returned. Thunk functions are functions that delay the evaluation
68
- * of an expression or operation until it is explicitly called or invoked. In this case, the `toThunk`
69
- * function takes a function `fn` as an argument and returns a thunk function that, when called, will
70
- * execute the `fn` function provided as an argument.
71
- */
72
- const toThunk = (fn) => {
73
- const thunk = () => fn();
74
- thunk.__THUNK__ = exports.THUNK_SYMBOL;
75
- return thunk;
76
- };
77
- exports.toThunk = toThunk;
78
- /**
79
- * The `trampoline` function in TypeScript enables tail call optimization by using thunks to avoid
80
- * stack overflow.
81
- * @param {TrlFn} fn - The `fn` parameter in the `trampoline` function is a function that takes any
82
- * number of arguments and returns a value.
83
- * @returns The `trampoline` function returns an object with two properties:
84
- * 1. A function that executes the provided function `fn` and continues to execute any thunks returned
85
- * by `fn` until a non-thunk value is returned.
86
- * 2. A `cont` property that is a function which creates a thunk for the provided function `fn`.
87
- */
88
- const trampoline = (fn) => {
89
- const cont = (...args) => (0, exports.toThunk)(() => fn(...args));
90
- return Object.assign((...args) => {
91
- let result = fn(...args);
92
- while ((0, exports.isThunk)(result) && typeof result === 'function') {
93
- result = result();
94
- }
95
- return result;
96
- }, { cont });
97
- };
98
- exports.trampoline = trampoline;
99
- /**
100
- * The `trampolineAsync` function in TypeScript allows for asynchronous trampolining of a given
101
- * function.
102
- * @param {TrlAsyncFn} fn - The `fn` parameter in the `trampolineAsync` function is expected to be a
103
- * function that returns a Promise. This function will be called recursively until a non-thunk value is
104
- * returned.
105
- * @returns The `trampolineAsync` function returns an object with two properties:
106
- * 1. An async function that executes the provided `TrlAsyncFn` function and continues to execute any
107
- * thunks returned by the function until a non-thunk value is returned.
108
- * 2. A `cont` property that is a function which wraps the provided `TrlAsyncFn` function in a thunk
109
- * and returns it.
110
- */
111
- const trampolineAsync = (fn) => {
112
- const cont = (...args) => (0, exports.toThunk)(() => fn(...args));
113
- return Object.assign((...args) => __awaiter(void 0, void 0, void 0, function* () {
114
- let result = yield fn(...args);
115
- while ((0, exports.isThunk)(result) && typeof result === 'function') {
116
- result = yield result();
117
- }
118
- return result;
119
- }), { cont });
120
- };
121
- exports.trampolineAsync = trampolineAsync;
122
54
  /**
123
55
  * The function `getMSB` returns the most significant bit of a given number.
124
56
  * @param {number} value - The `value` parameter is a number for which we want to find the position of
@@ -276,4 +208,147 @@ function isComparable(value, isForceObjectComparable = false) {
276
208
  return false;
277
209
  return isPrimitiveComparable(comparableValue);
278
210
  }
211
+ /**
212
+ * Creates a trampoline thunk object.
213
+ *
214
+ * A "thunk" is a deferred computation — instead of performing a recursive call immediately,
215
+ * it wraps the next step of the computation in a function. This allows recursive processes
216
+ * to be executed iteratively, preventing stack overflows.
217
+ *
218
+ * @template T - The type of the final computation result.
219
+ * @param computation - A function that, when executed, returns the next trampoline step.
220
+ * @returns A TrampolineThunk object containing the deferred computation.
221
+ */
222
+ const makeTrampolineThunk = (computation) => ({
223
+ isThunk: true, // Marker indicating this is a thunk
224
+ fn: computation // The deferred computation function
225
+ });
226
+ exports.makeTrampolineThunk = makeTrampolineThunk;
227
+ /**
228
+ * Type guard to check whether a given value is a TrampolineThunk.
229
+ *
230
+ * This function is used to distinguish between a final computation result (value)
231
+ * and a deferred computation (thunk).
232
+ *
233
+ * @template T - The type of the value being checked.
234
+ * @param value - The value to test.
235
+ * @returns True if the value is a valid TrampolineThunk, false otherwise.
236
+ */
237
+ const isTrampolineThunk = (value) => typeof value === 'object' && // Must be an object
238
+ value !== null && // Must not be null
239
+ 'isThunk' in value && // Must have the 'isThunk' property
240
+ value.isThunk; // The flag must be true
241
+ exports.isTrampolineThunk = isTrampolineThunk;
242
+ /**
243
+ * Executes a trampoline computation until a final (non-thunk) result is obtained.
244
+ *
245
+ * The trampoline function repeatedly invokes the deferred computations (thunks)
246
+ * in an iterative loop. This avoids deep recursive calls and prevents stack overflow,
247
+ * which is particularly useful for implementing recursion in a stack-safe manner.
248
+ *
249
+ * @template T - The type of the final result.
250
+ * @param initial - The initial Trampoline value or thunk to start execution from.
251
+ * @returns The final result of the computation (a non-thunk value).
252
+ */
253
+ function trampoline(initial) {
254
+ let current = initial; // Start with the initial trampoline value
255
+ while ((0, exports.isTrampolineThunk)(current)) {
256
+ // Keep unwrapping while we have thunks
257
+ current = current.fn(); // Execute the deferred function to get the next step
258
+ }
259
+ return current; // Once no thunks remain, return the final result
260
+ }
261
+ /**
262
+ * Wraps a recursive function inside a trampoline executor.
263
+ *
264
+ * This function transforms a potentially recursive function (that returns a Trampoline<Result>)
265
+ * into a *stack-safe* function that executes iteratively using the `trampoline` runner.
266
+ *
267
+ * In other words, it allows you to write functions that look recursive,
268
+ * but actually run in constant stack space.
269
+ *
270
+ * @template Args - The tuple type representing the argument list of the original function.
271
+ * @template Result - The final return type after all trampoline steps are resolved.
272
+ *
273
+ * @param fn - A function that performs a single step of computation
274
+ * and returns a Trampoline (either a final value or a deferred thunk).
275
+ *
276
+ * @returns A new function with the same arguments, but which automatically
277
+ * runs the trampoline process and returns the *final result* instead
278
+ * of a Trampoline.
279
+ *
280
+ * @example
281
+ * // Example: Computing factorial in a stack-safe way
282
+ * const factorial = makeTrampoline(function fact(n: number, acc: number = 1): Trampoline<number> {
283
+ * return n === 0
284
+ * ? acc
285
+ * : makeTrampolineThunk(() => fact(n - 1, acc * n));
286
+ * });
287
+ *
288
+ * console.log(factorial(100000)); // Works without stack overflow
289
+ */
290
+ function makeTrampoline(fn // A function that returns a trampoline step
291
+ ) {
292
+ // Return a wrapped function that automatically runs the trampoline execution loop
293
+ return (...args) => trampoline(fn(...args));
294
+ }
295
+ /**
296
+ * Executes an asynchronous trampoline computation until a final (non-thunk) result is obtained.
297
+ *
298
+ * This function repeatedly invokes asynchronous deferred computations (thunks)
299
+ * in an iterative loop. Each thunk may return either a Trampoline<T> or a Promise<Trampoline<T>>.
300
+ *
301
+ * It ensures that asynchronous recursive functions can run without growing the call stack,
302
+ * making it suitable for stack-safe async recursion.
303
+ *
304
+ * @template T - The type of the final result.
305
+ * @param initial - The initial Trampoline or Promise of Trampoline to start execution from.
306
+ * @returns A Promise that resolves to the final result (a non-thunk value).
307
+ */
308
+ function asyncTrampoline(initial) {
309
+ return __awaiter(this, void 0, void 0, function* () {
310
+ let current = yield initial; // Wait for the initial step to resolve if it's a Promise
311
+ // Keep executing thunks until we reach a non-thunk (final) value
312
+ while ((0, exports.isTrampolineThunk)(current)) {
313
+ current = yield current.fn(); // Execute the thunk function (may be async)
314
+ }
315
+ // Once the final value is reached, return it
316
+ return current;
317
+ });
318
+ }
319
+ /**
320
+ * Wraps an asynchronous recursive function inside an async trampoline executor.
321
+ *
322
+ * This helper transforms a recursive async function that returns a Trampoline<Result>
323
+ * (or Promise<Trampoline<Result>>) into a *stack-safe* async function that executes
324
+ * iteratively via the `asyncTrampoline` runner.
325
+ *
326
+ * @template Args - The tuple type representing the argument list of the original function.
327
+ * @template Result - The final return type after all async trampoline steps are resolved.
328
+ *
329
+ * @param fn - An async or sync function that performs a single step of computation
330
+ * and returns a Trampoline (either a final value or a deferred thunk).
331
+ *
332
+ * @returns An async function with the same arguments, but which automatically
333
+ * runs the trampoline process and resolves to the *final result*.
334
+ *
335
+ * @example
336
+ * // Example: Async factorial using trampoline
337
+ * const asyncFactorial = makeAsyncTrampoline(async function fact(
338
+ * n: number,
339
+ * acc: number = 1
340
+ * ): Promise<Trampoline<number>> {
341
+ * return n === 0
342
+ * ? acc
343
+ * : makeTrampolineThunk(() => fact(n - 1, acc * n));
344
+ * });
345
+ *
346
+ * asyncFactorial(100000).then(console.log); // Works without stack overflow
347
+ */
348
+ function makeAsyncTrampoline(fn) {
349
+ // Return a wrapped async function that runs through the async trampoline loop
350
+ return (...args) => __awaiter(this, void 0, void 0, function* () {
351
+ return asyncTrampoline(fn(...args));
352
+ });
353
+ }
279
354
  //# sourceMappingURL=utils.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/utils/utils.ts"],"names":[],"mappings":";;;;;;;;;;;;AAgRA,oCAWC;AAlRD;;;;;GAKG;AACI,MAAM,MAAM,GAAG;IACpB,OAAO,sCAAsC,CAAC,OAAO,CAAC,MAAM,EAAE,UAAU,CAAC;QACvE,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,EAChC,CAAC,GAAG,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,GAAG,GAAG,CAAC;QACrC,OAAO,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;IACxB,CAAC,CAAC,CAAC;AACL,CAAC,CAAC;AANW,QAAA,MAAM,UAMjB;AAEF;;;;;;;;GAQG;AACI,MAAM,WAAW,GAAG,UAAa,KAAU,EAAE,SAA0D;IAC5G,IAAI,CAAC,GAAG,CAAC,CAAC,EACR,GAAG,GAAG,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;IACjC,MAAM,MAAM,GAAG,EAAE,CAAC;IAElB,OAAO,EAAE,CAAC,GAAG,GAAG,EAAE,CAAC;QACjB,MAAM,KAAK,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