data-structure-typed 2.0.5 → 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 (260) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/COMMANDS.md +17 -0
  3. package/benchmark/report.html +13 -77
  4. package/benchmark/report.json +145 -177
  5. package/dist/cjs/data-structures/base/iterable-element-base.d.ts +186 -83
  6. package/dist/cjs/data-structures/base/iterable-element-base.js +149 -107
  7. package/dist/cjs/data-structures/base/iterable-element-base.js.map +1 -1
  8. package/dist/cjs/data-structures/base/iterable-entry-base.d.ts +95 -119
  9. package/dist/cjs/data-structures/base/iterable-entry-base.js +59 -116
  10. package/dist/cjs/data-structures/base/iterable-entry-base.js.map +1 -1
  11. package/dist/cjs/data-structures/base/linear-base.d.ts +250 -192
  12. package/dist/cjs/data-structures/base/linear-base.js +137 -274
  13. package/dist/cjs/data-structures/base/linear-base.js.map +1 -1
  14. package/dist/cjs/data-structures/binary-tree/avl-tree-counter.d.ts +126 -158
  15. package/dist/cjs/data-structures/binary-tree/avl-tree-counter.js +171 -205
  16. package/dist/cjs/data-structures/binary-tree/avl-tree-counter.js.map +1 -1
  17. package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.d.ts +100 -69
  18. package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.js +135 -87
  19. package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.js.map +1 -1
  20. package/dist/cjs/data-structures/binary-tree/avl-tree.d.ts +138 -149
  21. package/dist/cjs/data-structures/binary-tree/avl-tree.js +208 -195
  22. package/dist/cjs/data-structures/binary-tree/avl-tree.js.map +1 -1
  23. package/dist/cjs/data-structures/binary-tree/binary-tree.d.ts +476 -632
  24. package/dist/cjs/data-structures/binary-tree/binary-tree.js +594 -865
  25. package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
  26. package/dist/cjs/data-structures/binary-tree/bst.d.ts +258 -306
  27. package/dist/cjs/data-structures/binary-tree/bst.js +505 -481
  28. package/dist/cjs/data-structures/binary-tree/bst.js.map +1 -1
  29. package/dist/cjs/data-structures/binary-tree/red-black-tree.d.ts +107 -179
  30. package/dist/cjs/data-structures/binary-tree/red-black-tree.js +114 -209
  31. package/dist/cjs/data-structures/binary-tree/red-black-tree.js.map +1 -1
  32. package/dist/cjs/data-structures/binary-tree/tree-counter.d.ts +132 -154
  33. package/dist/cjs/data-structures/binary-tree/tree-counter.js +172 -203
  34. package/dist/cjs/data-structures/binary-tree/tree-counter.js.map +1 -1
  35. package/dist/cjs/data-structures/binary-tree/tree-multi-map.d.ts +72 -69
  36. package/dist/cjs/data-structures/binary-tree/tree-multi-map.js +105 -85
  37. package/dist/cjs/data-structures/binary-tree/tree-multi-map.js.map +1 -1
  38. package/dist/cjs/data-structures/graph/abstract-graph.d.ts +238 -233
  39. package/dist/cjs/data-structures/graph/abstract-graph.js +267 -237
  40. package/dist/cjs/data-structures/graph/abstract-graph.js.map +1 -1
  41. package/dist/cjs/data-structures/graph/directed-graph.d.ts +108 -224
  42. package/dist/cjs/data-structures/graph/directed-graph.js +146 -233
  43. package/dist/cjs/data-structures/graph/directed-graph.js.map +1 -1
  44. package/dist/cjs/data-structures/graph/map-graph.d.ts +49 -55
  45. package/dist/cjs/data-structures/graph/map-graph.js +56 -59
  46. package/dist/cjs/data-structures/graph/map-graph.js.map +1 -1
  47. package/dist/cjs/data-structures/graph/undirected-graph.d.ts +103 -146
  48. package/dist/cjs/data-structures/graph/undirected-graph.js +129 -149
  49. package/dist/cjs/data-structures/graph/undirected-graph.js.map +1 -1
  50. package/dist/cjs/data-structures/hash/hash-map.d.ts +164 -338
  51. package/dist/cjs/data-structures/hash/hash-map.js +270 -457
  52. package/dist/cjs/data-structures/hash/hash-map.js.map +1 -1
  53. package/dist/cjs/data-structures/heap/heap.d.ts +214 -289
  54. package/dist/cjs/data-structures/heap/heap.js +340 -349
  55. package/dist/cjs/data-structures/heap/heap.js.map +1 -1
  56. package/dist/cjs/data-structures/heap/max-heap.d.ts +11 -47
  57. package/dist/cjs/data-structures/heap/max-heap.js +11 -66
  58. package/dist/cjs/data-structures/heap/max-heap.js.map +1 -1
  59. package/dist/cjs/data-structures/heap/min-heap.d.ts +12 -47
  60. package/dist/cjs/data-structures/heap/min-heap.js +11 -66
  61. package/dist/cjs/data-structures/heap/min-heap.js.map +1 -1
  62. package/dist/cjs/data-structures/linked-list/doubly-linked-list.d.ts +231 -347
  63. package/dist/cjs/data-structures/linked-list/doubly-linked-list.js +368 -494
  64. package/dist/cjs/data-structures/linked-list/doubly-linked-list.js.map +1 -1
  65. package/dist/cjs/data-structures/linked-list/singly-linked-list.d.ts +261 -310
  66. package/dist/cjs/data-structures/linked-list/singly-linked-list.js +447 -466
  67. package/dist/cjs/data-structures/linked-list/singly-linked-list.js.map +1 -1
  68. package/dist/cjs/data-structures/linked-list/skip-linked-list.d.ts +0 -107
  69. package/dist/cjs/data-structures/linked-list/skip-linked-list.js +0 -100
  70. package/dist/cjs/data-structures/linked-list/skip-linked-list.js.map +1 -1
  71. package/dist/cjs/data-structures/priority-queue/max-priority-queue.d.ts +12 -56
  72. package/dist/cjs/data-structures/priority-queue/max-priority-queue.js +11 -78
  73. package/dist/cjs/data-structures/priority-queue/max-priority-queue.js.map +1 -1
  74. package/dist/cjs/data-structures/priority-queue/min-priority-queue.d.ts +11 -57
  75. package/dist/cjs/data-structures/priority-queue/min-priority-queue.js +10 -79
  76. package/dist/cjs/data-structures/priority-queue/min-priority-queue.js.map +1 -1
  77. package/dist/cjs/data-structures/priority-queue/priority-queue.d.ts +2 -61
  78. package/dist/cjs/data-structures/priority-queue/priority-queue.js +8 -83
  79. package/dist/cjs/data-structures/priority-queue/priority-queue.js.map +1 -1
  80. package/dist/cjs/data-structures/queue/deque.d.ts +227 -254
  81. package/dist/cjs/data-structures/queue/deque.js +309 -348
  82. package/dist/cjs/data-structures/queue/deque.js.map +1 -1
  83. package/dist/cjs/data-structures/queue/queue.d.ts +180 -201
  84. package/dist/cjs/data-structures/queue/queue.js +265 -248
  85. package/dist/cjs/data-structures/queue/queue.js.map +1 -1
  86. package/dist/cjs/data-structures/stack/stack.d.ts +124 -102
  87. package/dist/cjs/data-structures/stack/stack.js +181 -125
  88. package/dist/cjs/data-structures/stack/stack.js.map +1 -1
  89. package/dist/cjs/data-structures/trie/trie.d.ts +164 -165
  90. package/dist/cjs/data-structures/trie/trie.js +189 -172
  91. package/dist/cjs/data-structures/trie/trie.js.map +1 -1
  92. package/dist/cjs/interfaces/binary-tree.d.ts +56 -6
  93. package/dist/cjs/interfaces/graph.d.ts +16 -0
  94. package/dist/cjs/types/data-structures/base/base.d.ts +1 -1
  95. package/dist/cjs/types/data-structures/graph/abstract-graph.d.ts +4 -0
  96. package/dist/cjs/types/utils/utils.d.ts +1 -0
  97. package/dist/cjs/utils/utils.d.ts +1 -1
  98. package/dist/cjs/utils/utils.js +2 -1
  99. package/dist/cjs/utils/utils.js.map +1 -1
  100. package/dist/esm/data-structures/base/iterable-element-base.d.ts +186 -83
  101. package/dist/esm/data-structures/base/iterable-element-base.js +155 -107
  102. package/dist/esm/data-structures/base/iterable-element-base.js.map +1 -1
  103. package/dist/esm/data-structures/base/iterable-entry-base.d.ts +95 -119
  104. package/dist/esm/data-structures/base/iterable-entry-base.js +59 -116
  105. package/dist/esm/data-structures/base/iterable-entry-base.js.map +1 -1
  106. package/dist/esm/data-structures/base/linear-base.d.ts +250 -192
  107. package/dist/esm/data-structures/base/linear-base.js +137 -274
  108. package/dist/esm/data-structures/base/linear-base.js.map +1 -1
  109. package/dist/esm/data-structures/binary-tree/avl-tree-counter.d.ts +126 -158
  110. package/dist/esm/data-structures/binary-tree/avl-tree-counter.js +171 -212
  111. package/dist/esm/data-structures/binary-tree/avl-tree-counter.js.map +1 -1
  112. package/dist/esm/data-structures/binary-tree/avl-tree-multi-map.d.ts +100 -69
  113. package/dist/esm/data-structures/binary-tree/avl-tree-multi-map.js +133 -94
  114. package/dist/esm/data-structures/binary-tree/avl-tree-multi-map.js.map +1 -1
  115. package/dist/esm/data-structures/binary-tree/avl-tree.d.ts +138 -149
  116. package/dist/esm/data-structures/binary-tree/avl-tree.js +206 -200
  117. package/dist/esm/data-structures/binary-tree/avl-tree.js.map +1 -1
  118. package/dist/esm/data-structures/binary-tree/binary-tree.d.ts +476 -632
  119. package/dist/esm/data-structures/binary-tree/binary-tree.js +598 -874
  120. package/dist/esm/data-structures/binary-tree/binary-tree.js.map +1 -1
  121. package/dist/esm/data-structures/binary-tree/bst.d.ts +258 -306
  122. package/dist/esm/data-structures/binary-tree/bst.js +507 -487
  123. package/dist/esm/data-structures/binary-tree/bst.js.map +1 -1
  124. package/dist/esm/data-structures/binary-tree/red-black-tree.d.ts +107 -179
  125. package/dist/esm/data-structures/binary-tree/red-black-tree.js +114 -215
  126. package/dist/esm/data-structures/binary-tree/red-black-tree.js.map +1 -1
  127. package/dist/esm/data-structures/binary-tree/tree-counter.d.ts +132 -154
  128. package/dist/esm/data-structures/binary-tree/tree-counter.js +175 -209
  129. package/dist/esm/data-structures/binary-tree/tree-counter.js.map +1 -1
  130. package/dist/esm/data-structures/binary-tree/tree-multi-map.d.ts +72 -69
  131. package/dist/esm/data-structures/binary-tree/tree-multi-map.js +103 -92
  132. package/dist/esm/data-structures/binary-tree/tree-multi-map.js.map +1 -1
  133. package/dist/esm/data-structures/graph/abstract-graph.d.ts +238 -233
  134. package/dist/esm/data-structures/graph/abstract-graph.js +267 -237
  135. package/dist/esm/data-structures/graph/abstract-graph.js.map +1 -1
  136. package/dist/esm/data-structures/graph/directed-graph.d.ts +108 -224
  137. package/dist/esm/data-structures/graph/directed-graph.js +145 -233
  138. package/dist/esm/data-structures/graph/directed-graph.js.map +1 -1
  139. package/dist/esm/data-structures/graph/map-graph.d.ts +49 -55
  140. package/dist/esm/data-structures/graph/map-graph.js +56 -59
  141. package/dist/esm/data-structures/graph/map-graph.js.map +1 -1
  142. package/dist/esm/data-structures/graph/undirected-graph.d.ts +103 -146
  143. package/dist/esm/data-structures/graph/undirected-graph.js +128 -149
  144. package/dist/esm/data-structures/graph/undirected-graph.js.map +1 -1
  145. package/dist/esm/data-structures/hash/hash-map.d.ts +164 -338
  146. package/dist/esm/data-structures/hash/hash-map.js +270 -457
  147. package/dist/esm/data-structures/hash/hash-map.js.map +1 -1
  148. package/dist/esm/data-structures/heap/heap.d.ts +214 -289
  149. package/dist/esm/data-structures/heap/heap.js +329 -349
  150. package/dist/esm/data-structures/heap/heap.js.map +1 -1
  151. package/dist/esm/data-structures/heap/max-heap.d.ts +11 -47
  152. package/dist/esm/data-structures/heap/max-heap.js +11 -66
  153. package/dist/esm/data-structures/heap/max-heap.js.map +1 -1
  154. package/dist/esm/data-structures/heap/min-heap.d.ts +12 -47
  155. package/dist/esm/data-structures/heap/min-heap.js +11 -66
  156. package/dist/esm/data-structures/heap/min-heap.js.map +1 -1
  157. package/dist/esm/data-structures/linked-list/doubly-linked-list.d.ts +231 -347
  158. package/dist/esm/data-structures/linked-list/doubly-linked-list.js +368 -495
  159. package/dist/esm/data-structures/linked-list/doubly-linked-list.js.map +1 -1
  160. package/dist/esm/data-structures/linked-list/singly-linked-list.d.ts +261 -310
  161. package/dist/esm/data-structures/linked-list/singly-linked-list.js +448 -467
  162. package/dist/esm/data-structures/linked-list/singly-linked-list.js.map +1 -1
  163. package/dist/esm/data-structures/linked-list/skip-linked-list.d.ts +0 -107
  164. package/dist/esm/data-structures/linked-list/skip-linked-list.js +0 -100
  165. package/dist/esm/data-structures/linked-list/skip-linked-list.js.map +1 -1
  166. package/dist/esm/data-structures/priority-queue/max-priority-queue.d.ts +12 -56
  167. package/dist/esm/data-structures/priority-queue/max-priority-queue.js +11 -78
  168. package/dist/esm/data-structures/priority-queue/max-priority-queue.js.map +1 -1
  169. package/dist/esm/data-structures/priority-queue/min-priority-queue.d.ts +11 -57
  170. package/dist/esm/data-structures/priority-queue/min-priority-queue.js +10 -79
  171. package/dist/esm/data-structures/priority-queue/min-priority-queue.js.map +1 -1
  172. package/dist/esm/data-structures/priority-queue/priority-queue.d.ts +2 -61
  173. package/dist/esm/data-structures/priority-queue/priority-queue.js +8 -83
  174. package/dist/esm/data-structures/priority-queue/priority-queue.js.map +1 -1
  175. package/dist/esm/data-structures/queue/deque.d.ts +227 -254
  176. package/dist/esm/data-structures/queue/deque.js +313 -348
  177. package/dist/esm/data-structures/queue/deque.js.map +1 -1
  178. package/dist/esm/data-structures/queue/queue.d.ts +180 -201
  179. package/dist/esm/data-structures/queue/queue.js +263 -248
  180. package/dist/esm/data-structures/queue/queue.js.map +1 -1
  181. package/dist/esm/data-structures/stack/stack.d.ts +124 -102
  182. package/dist/esm/data-structures/stack/stack.js +181 -125
  183. package/dist/esm/data-structures/stack/stack.js.map +1 -1
  184. package/dist/esm/data-structures/trie/trie.d.ts +164 -165
  185. package/dist/esm/data-structures/trie/trie.js +193 -172
  186. package/dist/esm/data-structures/trie/trie.js.map +1 -1
  187. package/dist/esm/interfaces/binary-tree.d.ts +56 -6
  188. package/dist/esm/interfaces/graph.d.ts +16 -0
  189. package/dist/esm/types/data-structures/base/base.d.ts +1 -1
  190. package/dist/esm/types/data-structures/graph/abstract-graph.d.ts +4 -0
  191. package/dist/esm/types/utils/utils.d.ts +1 -0
  192. package/dist/esm/utils/utils.d.ts +1 -1
  193. package/dist/esm/utils/utils.js +2 -1
  194. package/dist/esm/utils/utils.js.map +1 -1
  195. package/dist/umd/data-structure-typed.js +4685 -6477
  196. package/dist/umd/data-structure-typed.min.js +8 -6
  197. package/dist/umd/data-structure-typed.min.js.map +1 -1
  198. package/package.json +3 -4
  199. package/src/data-structures/base/iterable-element-base.ts +238 -115
  200. package/src/data-structures/base/iterable-entry-base.ts +96 -120
  201. package/src/data-structures/base/linear-base.ts +271 -277
  202. package/src/data-structures/binary-tree/avl-tree-counter.ts +198 -216
  203. package/src/data-structures/binary-tree/avl-tree-multi-map.ts +192 -101
  204. package/src/data-structures/binary-tree/avl-tree.ts +239 -206
  205. package/src/data-structures/binary-tree/binary-tree.ts +660 -889
  206. package/src/data-structures/binary-tree/bst.ts +568 -570
  207. package/src/data-structures/binary-tree/red-black-tree.ts +161 -222
  208. package/src/data-structures/binary-tree/tree-counter.ts +199 -218
  209. package/src/data-structures/binary-tree/tree-multi-map.ts +131 -97
  210. package/src/data-structures/graph/abstract-graph.ts +339 -264
  211. package/src/data-structures/graph/directed-graph.ts +146 -236
  212. package/src/data-structures/graph/map-graph.ts +63 -60
  213. package/src/data-structures/graph/undirected-graph.ts +129 -152
  214. package/src/data-structures/hash/hash-map.ts +274 -496
  215. package/src/data-structures/heap/heap.ts +389 -402
  216. package/src/data-structures/heap/max-heap.ts +12 -76
  217. package/src/data-structures/heap/min-heap.ts +13 -76
  218. package/src/data-structures/linked-list/doubly-linked-list.ts +426 -530
  219. package/src/data-structures/linked-list/singly-linked-list.ts +495 -517
  220. package/src/data-structures/linked-list/skip-linked-list.ts +1 -108
  221. package/src/data-structures/priority-queue/max-priority-queue.ts +12 -87
  222. package/src/data-structures/priority-queue/min-priority-queue.ts +11 -88
  223. package/src/data-structures/priority-queue/priority-queue.ts +3 -92
  224. package/src/data-structures/queue/deque.ts +381 -357
  225. package/src/data-structures/queue/queue.ts +310 -264
  226. package/src/data-structures/stack/stack.ts +217 -131
  227. package/src/data-structures/trie/trie.ts +240 -175
  228. package/src/interfaces/binary-tree.ts +240 -6
  229. package/src/interfaces/graph.ts +37 -0
  230. package/src/types/data-structures/base/base.ts +5 -5
  231. package/src/types/data-structures/graph/abstract-graph.ts +5 -0
  232. package/src/types/utils/utils.ts +2 -0
  233. package/src/utils/utils.ts +9 -14
  234. package/test/integration/index.html +1 -1
  235. package/test/performance/benchmark-runner.ts +528 -0
  236. package/test/performance/reportor.mjs +43 -43
  237. package/test/performance/runner-config.json +39 -0
  238. package/test/performance/single-suite-runner.ts +69 -0
  239. package/test/unit/data-structures/binary-tree/avl-tree-counter.test.ts +3 -3
  240. package/test/unit/data-structures/binary-tree/avl-tree-multi-map.test.ts +5 -5
  241. package/test/unit/data-structures/binary-tree/avl-tree.test.ts +4 -4
  242. package/test/unit/data-structures/binary-tree/binary-tree.test.ts +350 -90
  243. package/test/unit/data-structures/binary-tree/bst.test.ts +12 -9
  244. package/test/unit/data-structures/binary-tree/red-black-tree.test.ts +2 -2
  245. package/test/unit/data-structures/binary-tree/tree-counter.test.ts +25 -24
  246. package/test/unit/data-structures/binary-tree/tree-multi-map.test.ts +3 -3
  247. package/test/unit/data-structures/graph/abstract-graph.test.ts +0 -4
  248. package/test/unit/data-structures/graph/directed-graph.test.ts +1 -1
  249. package/test/unit/data-structures/heap/heap.test.ts +14 -21
  250. package/test/unit/data-structures/heap/max-heap.test.ts +5 -9
  251. package/test/unit/data-structures/heap/min-heap.test.ts +1 -4
  252. package/test/unit/data-structures/linked-list/doubly-linked-list.test.ts +14 -14
  253. package/test/unit/data-structures/linked-list/singly-linked-list.test.ts +0 -7
  254. package/test/unit/data-structures/priority-queue/max-priority-queue.test.ts +8 -11
  255. package/test/unit/data-structures/priority-queue/min-priority-queue.test.ts +1 -4
  256. package/test/unit/data-structures/priority-queue/priority-queue.test.ts +1 -4
  257. package/test/unit/data-structures/queue/queue.test.ts +4 -5
  258. package/test/unit/utils/utils.test.ts +0 -1
  259. package/test/performance/data-structures/binary-tree/avl-tree.test.mjs +0 -71
  260. 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,6 +1,7 @@
1
1
  export type SpecifyOptional<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
2
2
  export type Any = string | number | bigint | boolean | symbol | undefined | object;
3
3
  export type Arithmetic = number | bigint;
4
+ export type ElemOf<T> = T extends (infer U)[] ? U : never;
4
5
  export type ComparablePrimitive = number | bigint | string | boolean;
5
6
  export interface BaseComparableObject {
6
7
  [key: string]: unknown;
@@ -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, TrampolineThunk, Trampoline } 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
@@ -252,7 +252,8 @@ exports.isTrampolineThunk = isTrampolineThunk;
252
252
  */
253
253
  function trampoline(initial) {
254
254
  let current = initial; // Start with the initial trampoline value
255
- while ((0, exports.isTrampolineThunk)(current)) { // Keep unwrapping while we have thunks
255
+ while ((0, exports.isTrampolineThunk)(current)) {
256
+ // Keep unwrapping while we have thunks
256
257
  current = current.fn(); // Execute the deferred function to get the next step
257
258
  }
258
259
  return current; // Once no thunks remain, return the final result
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/utils/utils.ts"],"names":[],"mappings":";;;;;;;;;;;;AA2LA,oCAWC;AAiDD,gCAMC;AA+BD,wCAKC;AAeD,0CAYC;AA+BD,kDAOC;AAzVD;;;;;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,CA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C,OAAO,CAAC,CAAC,wBAAwB;AAJ5B,QAAA,iBAAiB,qBAId;AAEhB;;;;;;;;;;GAUG;AACH,SAAgB,UAAU,CAAI,OAAsB;IAClD,IAAI,OAAO,GAAG,OAAO,CAAC,CAAC,0CAA0C;IACjE,OAAO,IAAA,yBAAiB,EAAC,OAAO,CAAC,EAAE,CAAC;QAClC,uCAAuC;QACvC,OAAO,GAAG,OAAO,CAAC,EAAE,EAAE,CAAC,CAAC,qDAAqD;IAC/E,CAAC;IACD,OAAO,OAAO,CAAC,CAAC,iDAAiD;AACnE,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,SAAgB,cAAc,CAC5B,EAAyC,CAAC,4CAA4C;;IAEtF,kFAAkF;IAClF,OAAO,CAAC,GAAG,IAAU,EAAE,EAAE,CAAC,UAAU,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC;AACpD,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,SAAsB,eAAe,CAAI,OAA+C;;QACtF,IAAI,OAAO,GAAG,MAAM,OAAO,CAAC,CAAC,yDAAyD;QAEtF,iEAAiE;QACjE,OAAO,IAAA,yBAAiB,EAAC,OAAO,CAAC,EAAE,CAAC;YAClC,OAAO,GAAG,MAAM,OAAO,CAAC,EAAE,EAAE,CAAC,CAAC,4CAA4C;QAC5E,CAAC;QAED,6CAA6C;QAC7C,OAAO,OAAO,CAAC;IACjB,CAAC;CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,SAAgB,mBAAmB,CACjC,EAAuE;IAEvE,8EAA8E;IAC9E,OAAO,CAAO,GAAG,IAAU,EAAmB,EAAE;QAC9C,OAAO,eAAe,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC;IACtC,CAAC,CAAA,CAAC;AACJ,CAAC"}
@@ -1,116 +1,219 @@
1
- import { ElementCallback, IterableElementBaseOptions, ReduceElementCallback } from '../../types';
2
- export declare abstract class IterableElementBase<E, R> {
1
+ import type { ElementCallback, IterableElementBaseOptions, ReduceElementCallback } from '../../types';
2
+ /**
3
+ * Base class that makes a data structure iterable and provides common
4
+ * element-wise utilities (e.g., map/filter/reduce/find).
5
+ *
6
+ * @template E The public element type yielded by the structure.
7
+ * @template R The underlying "raw" element type used internally or by converters.
8
+ *
9
+ * @remarks
10
+ * This class implements the JavaScript iteration protocol (via `Symbol.iterator`)
11
+ * and offers array-like helpers with predictable time/space complexity.
12
+ */
13
+ export declare abstract class IterableElementBase<E, R> implements Iterable<E> {
3
14
  /**
4
- * The protected constructor initializes the options for the IterableElementBase class, including the
5
- * toElementFn function.
6
- * @param [options] - An optional object that contains the following properties:
15
+ * Create a new iterable base.
16
+ *
17
+ * @param options Optional behavior overrides. When provided, a `toElementFn`
18
+ * is used to convert a raw element (`R`) into a public element (`E`).
19
+ *
20
+ * @remarks
21
+ * Time O(1), Space O(1).
7
22
  */
8
23
  protected constructor(options?: IterableElementBaseOptions<E, R>);
24
+ /**
25
+ * The converter used to transform a raw element (`R`) into a public element (`E`).
26
+ *
27
+ * @remarks
28
+ * Time O(1), Space O(1).
29
+ */
9
30
  protected _toElementFn?: (rawElement: R) => E;
31
+ /**
32
+ * Exposes the current `toElementFn`, if configured.
33
+ *
34
+ * @returns The converter function or `undefined` when not set.
35
+ * @remarks
36
+ * Time O(1), Space O(1).
37
+ */
10
38
  get toElementFn(): ((rawElement: R) => E) | undefined;
11
39
  /**
12
- * Time Complexity: O(n)
13
- * Space Complexity: O(1)
40
+ * Returns an iterator over the structure's elements.
41
+ *
42
+ * @param args Optional iterator arguments forwarded to the internal iterator.
43
+ * @returns An `IterableIterator<E>` that yields the elements in traversal order.
14
44
  *
15
- * The function is an implementation of the Symbol.iterator method that returns an IterableIterator.
16
- * @param {any[]} args - The `args` parameter in the code snippet represents a rest parameter. It
17
- * allows the function to accept any number of arguments as an array. In this case, the `args`
18
- * parameter is used to pass any number of arguments to the `_getIterator` method.
45
+ * @remarks
46
+ * Producing the iterator is O(1); consuming the entire iterator is Time O(n) with O(1) extra space.
19
47
  */
20
- [Symbol.iterator](...args: any[]): IterableIterator<E>;
48
+ [Symbol.iterator](...args: unknown[]): IterableIterator<E>;
21
49
  /**
22
- * Time Complexity: O(n)
23
- * Space Complexity: O(n)
50
+ * Returns an iterator over the values (alias of the default iterator).
24
51
  *
25
- * The function returns an iterator that yields all the values in the object.
52
+ * @returns An `IterableIterator<E>` over all elements.
53
+ * @remarks
54
+ * Creating the iterator is O(1); full iteration is Time O(n), Space O(1).
26
55
  */
27
56
  values(): IterableIterator<E>;
28
57
  /**
29
- * Time Complexity: O(n)
30
- * Space Complexity: O(1)
31
- *
32
- * The `every` function checks if every element in the array satisfies a given predicate.
33
- * @param predicate - The `predicate` parameter is a callback function that takes three arguments:
34
- * the current element being processed, its index, and the array it belongs to. It should return a
35
- * boolean value indicating whether the element satisfies a certain condition or not.
36
- * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
37
- * to be used as `this` when executing the `predicate` function. If `thisArg` is provided, it will be
38
- * passed as the `this` value to the `predicate` function. If `thisArg` is
39
- * @returns The `every` method is returning a boolean value. It returns `true` if every element in
40
- * the array satisfies the provided predicate function, and `false` otherwise.
41
- */
42
- every(predicate: ElementCallback<E, R, boolean>, thisArg?: any): boolean;
43
- /**
44
- * Time Complexity: O(n)
45
- * Space Complexity: O(1)
46
- *
47
- * The "some" function checks if at least one element in a collection satisfies a given predicate.
48
- * @param predicate - The `predicate` parameter is a callback function that takes three arguments:
49
- * `value`, `index`, and `array`. It should return a boolean value indicating whether the current
50
- * element satisfies the condition.
51
- * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
52
- * to be used as the `this` value when executing the `predicate` function. If `thisArg` is provided,
53
- * it will be passed as the `this` value to the `predicate` function. If `thisArg
54
- * @returns a boolean value. It returns true if the predicate function returns true for any element
55
- * in the collection, and false otherwise.
56
- */
57
- some(predicate: ElementCallback<E, R, boolean>, thisArg?: any): boolean;
58
- /**
59
- * Time Complexity: O(n)
60
- * Space Complexity: O(1)
61
- *
62
- * The `forEach` function iterates over each element in an array-like object and calls a callback
63
- * function for each element.
64
- * @param callbackfn - The callbackfn parameter is a function that will be called for each element in
65
- * the array. It takes three arguments: the current element being processed, the index of the current
66
- * element, and the array that forEach was called upon.
67
- * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
68
- * to be used as `this` when executing the `callbackfn` function. If `thisArg` is provided, it will
69
- * be passed as the `this` value to the `callbackfn` function. If `thisArg
70
- */
71
- forEach(callbackfn: ElementCallback<E, R, void>, thisArg?: any): void;
72
- find<S extends E>(predicate: ElementCallback<E, R, S>, thisArg?: any): S | undefined;
73
- find(predicate: ElementCallback<E, R, unknown>, thisArg?: any): E | undefined;
74
- /**
75
- * Time Complexity: O(n)
76
- * Space Complexity: O(1)
77
- *
78
- * The function checks if a given element exists in a collection.
79
- * @param {E} element - The parameter "element" is of type E, which means it can be any type. It
80
- * represents the element that we want to check for existence in the collection.
81
- * @returns a boolean value. It returns true if the element is found in the collection, and false
82
- * otherwise.
58
+ * Tests whether all elements satisfy the predicate.
59
+ *
60
+ * @template TReturn
61
+ * @param predicate Function invoked for each element with signature `(value, index, self)`.
62
+ * @param thisArg Optional `this` binding for the predicate.
63
+ * @returns `true` if every element passes; otherwise `false`.
64
+ *
65
+ * @remarks
66
+ * Time O(n) in the worst case; may exit early when the first failure is found. Space O(1).
67
+ */
68
+ every(predicate: ElementCallback<E, R, boolean>, thisArg?: unknown): boolean;
69
+ /**
70
+ * Tests whether at least one element satisfies the predicate.
71
+ *
72
+ * @param predicate Function invoked for each element with signature `(value, index, self)`.
73
+ * @param thisArg Optional `this` binding for the predicate.
74
+ * @returns `true` if any element passes; otherwise `false`.
75
+ *
76
+ * @remarks
77
+ * Time O(n) in the worst case; may exit early on first success. Space O(1).
78
+ */
79
+ some(predicate: ElementCallback<E, R, boolean>, thisArg?: unknown): boolean;
80
+ /**
81
+ * Invokes a callback for each element in iteration order.
82
+ *
83
+ * @param callbackfn Function invoked per element with signature `(value, index, self)`.
84
+ * @param thisArg Optional `this` binding for the callback.
85
+ * @returns `void`.
86
+ *
87
+ * @remarks
88
+ * Time O(n), Space O(1).
89
+ */
90
+ forEach(callbackfn: ElementCallback<E, R, void>, thisArg?: unknown): void;
91
+ /**
92
+ * Finds the first element that satisfies the predicate and returns it.
93
+ *
94
+ * @overload
95
+ * Finds the first element of type `S` (a subtype of `E`) that satisfies the predicate and returns it.
96
+ * @template S
97
+ * @param predicate Type-guard predicate: `(value, index, self) => value is S`.
98
+ * @param thisArg Optional `this` binding for the predicate.
99
+ * @returns The matched element typed as `S`, or `undefined` if not found.
100
+ *
101
+ * @overload
102
+ * @param predicate Boolean predicate: `(value, index, self) => boolean`.
103
+ * @param thisArg Optional `this` binding for the predicate.
104
+ * @returns The first matching element as `E`, or `undefined` if not found.
105
+ *
106
+ * @remarks
107
+ * Time O(n) in the worst case; may exit early on the first match. Space O(1).
108
+ */
109
+ find<S extends E>(predicate: ElementCallback<E, R, S>, thisArg?: unknown): S | undefined;
110
+ find(predicate: ElementCallback<E, R, unknown>, thisArg?: unknown): E | undefined;
111
+ /**
112
+ * Checks whether a strictly-equal element exists in the structure.
113
+ *
114
+ * @param element The element to test with `===` equality.
115
+ * @returns `true` if an equal element is found; otherwise `false`.
116
+ *
117
+ * @remarks
118
+ * Time O(n) in the worst case. Space O(1).
83
119
  */
84
120
  has(element: E): boolean;
85
121
  reduce(callbackfn: ReduceElementCallback<E, R>): E;
86
122
  reduce(callbackfn: ReduceElementCallback<E, R>, initialValue: E): E;
87
123
  reduce<U>(callbackfn: ReduceElementCallback<E, R, U>, initialValue: U): U;
88
124
  /**
89
- * Time Complexity: O(n)
90
- * Space Complexity: O(n)
125
+ * Materializes the elements into a new array.
91
126
  *
92
- * The `toArray` function converts a linked list into an array.
93
- * @returns The `toArray()` method is returning an array of type `E[]`.
127
+ * @returns A shallow array copy of the iteration order.
128
+ * @remarks
129
+ * Time O(n), Space O(n).
94
130
  */
95
131
  toArray(): E[];
96
132
  /**
97
- * Time Complexity: O(n)
98
- * Space Complexity: O(n)
133
+ * Returns a representation of the structure suitable for quick visualization.
134
+ * Defaults to an array of elements; subclasses may override to provide richer visuals.
99
135
  *
100
- * The print function logs the elements of an array to the console.
136
+ * @returns A visual representation (array by default).
137
+ * @remarks
138
+ * Time O(n), Space O(n).
101
139
  */
102
140
  toVisual(): E[];
103
141
  /**
104
- * Time Complexity: O(n)
105
- * Space Complexity: O(n)
142
+ * Prints `toVisual()` to the console. Intended for quick debugging.
106
143
  *
107
- * The print function logs the elements of an array to the console.
144
+ * @returns `void`.
145
+ * @remarks
146
+ * Time O(n) due to materialization, Space O(n) for the intermediate representation.
108
147
  */
109
148
  print(): void;
149
+ /**
150
+ * Indicates whether the structure currently contains no elements.
151
+ *
152
+ * @returns `true` if empty; otherwise `false`.
153
+ * @remarks
154
+ * Expected Time O(1), Space O(1) for most implementations.
155
+ */
110
156
  abstract isEmpty(): boolean;
157
+ /**
158
+ * Removes all elements from the structure.
159
+ *
160
+ * @returns `void`.
161
+ * @remarks
162
+ * Expected Time O(1) or O(n) depending on the implementation; Space O(1).
163
+ */
111
164
  abstract clear(): void;
112
- abstract clone(): IterableElementBase<E, R>;
113
- abstract map(...args: any[]): any;
114
- abstract filter(...args: any[]): any;
115
- protected abstract _getIterator(...args: any[]): IterableIterator<E>;
165
+ /**
166
+ * Creates a structural copy with the same element values and configuration.
167
+ *
168
+ * @returns A clone of the current instance (same concrete type).
169
+ * @remarks
170
+ * Expected Time O(n) to copy elements; Space O(n).
171
+ */
172
+ abstract clone(): this;
173
+ /**
174
+ * Maps each element to a new element and returns a new iterable structure.
175
+ *
176
+ * @template EM The mapped element type.
177
+ * @template RM The mapped raw element type used internally by the target structure.
178
+ * @param callback Function with signature `(value, index, self) => mapped`.
179
+ * @param options Optional options for the returned structure, including its `toElementFn`.
180
+ * @param thisArg Optional `this` binding for the callback.
181
+ * @returns A new `IterableElementBase<EM, RM>` containing mapped elements.
182
+ *
183
+ * @remarks
184
+ * Time O(n), Space O(n).
185
+ */
186
+ abstract map<EM, RM>(callback: ElementCallback<E, R, EM>, options?: IterableElementBaseOptions<EM, RM>, thisArg?: unknown): IterableElementBase<EM, RM>;
187
+ /**
188
+ * Maps each element to the same element type and returns the same concrete structure type.
189
+ *
190
+ * @param callback Function with signature `(value, index, self) => mappedValue`.
191
+ * @param thisArg Optional `this` binding for the callback.
192
+ * @returns A new instance of the same concrete type with mapped elements.
193
+ *
194
+ * @remarks
195
+ * Time O(n), Space O(n).
196
+ */
197
+ abstract mapSame(callback: ElementCallback<E, R, E>, thisArg?: unknown): this;
198
+ /**
199
+ * Filters elements using the provided predicate and returns the same concrete structure type.
200
+ *
201
+ * @param predicate Function with signature `(value, index, self) => boolean`.
202
+ * @param thisArg Optional `this` binding for the predicate.
203
+ * @returns A new instance of the same concrete type containing only elements that pass the predicate.
204
+ *
205
+ * @remarks
206
+ * Time O(n), Space O(k) where `k` is the number of kept elements.
207
+ */
208
+ abstract filter(predicate: ElementCallback<E, R, boolean>, thisArg?: unknown): this;
209
+ /**
210
+ * Internal iterator factory used by the default iterator.
211
+ *
212
+ * @param args Optional iterator arguments.
213
+ * @returns An iterator over elements.
214
+ *
215
+ * @remarks
216
+ * Implementations should yield in O(1) per element with O(1) extra space when possible.
217
+ */
218
+ protected abstract _getIterator(...args: unknown[]): IterableIterator<E>;
116
219
  }