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,8 +1,23 @@
1
+ /**
2
+ * Base class that makes a data structure iterable and provides common
3
+ * element-wise utilities (e.g., map/filter/reduce/find).
4
+ *
5
+ * @template E The public element type yielded by the structure.
6
+ * @template R The underlying "raw" element type used internally or by converters.
7
+ *
8
+ * @remarks
9
+ * This class implements the JavaScript iteration protocol (via `Symbol.iterator`)
10
+ * and offers array-like helpers with predictable time/space complexity.
11
+ */
1
12
  export class IterableElementBase {
2
13
  /**
3
- * The protected constructor initializes the options for the IterableElementBase class, including the
4
- * toElementFn function.
5
- * @param [options] - An optional object that contains the following properties:
14
+ * Create a new iterable base.
15
+ *
16
+ * @param options Optional behavior overrides. When provided, a `toElementFn`
17
+ * is used to convert a raw element (`R`) into a public element (`E`).
18
+ *
19
+ * @remarks
20
+ * Time O(1), Space O(1).
6
21
  */
7
22
  constructor(options) {
8
23
  if (options) {
@@ -13,184 +28,217 @@ export class IterableElementBase {
13
28
  throw new TypeError('toElementFn must be a function type');
14
29
  }
15
30
  }
31
+ /**
32
+ * The converter used to transform a raw element (`R`) into a public element (`E`).
33
+ *
34
+ * @remarks
35
+ * Time O(1), Space O(1).
36
+ */
16
37
  _toElementFn;
38
+ /**
39
+ * Exposes the current `toElementFn`, if configured.
40
+ *
41
+ * @returns The converter function or `undefined` when not set.
42
+ * @remarks
43
+ * Time O(1), Space O(1).
44
+ */
17
45
  get toElementFn() {
18
46
  return this._toElementFn;
19
47
  }
20
48
  /**
21
- * Time Complexity: O(n)
22
- * Space Complexity: O(1)
49
+ * Returns an iterator over the structure's elements.
50
+ *
51
+ * @param args Optional iterator arguments forwarded to the internal iterator.
52
+ * @returns An `IterableIterator<E>` that yields the elements in traversal order.
23
53
  *
24
- * The function is an implementation of the Symbol.iterator method that returns an IterableIterator.
25
- * @param {any[]} args - The `args` parameter in the code snippet represents a rest parameter. It
26
- * allows the function to accept any number of arguments as an array. In this case, the `args`
27
- * parameter is used to pass any number of arguments to the `_getIterator` method.
54
+ * @remarks
55
+ * Producing the iterator is O(1); consuming the entire iterator is Time O(n) with O(1) extra space.
28
56
  */
29
57
  *[Symbol.iterator](...args) {
30
58
  yield* this._getIterator(...args);
31
59
  }
32
60
  /**
33
- * Time Complexity: O(n)
34
- * Space Complexity: O(n)
61
+ * Returns an iterator over the values (alias of the default iterator).
35
62
  *
36
- * The function returns an iterator that yields all the values in the object.
63
+ * @returns An `IterableIterator<E>` over all elements.
64
+ * @remarks
65
+ * Creating the iterator is O(1); full iteration is Time O(n), Space O(1).
37
66
  */
38
67
  *values() {
39
- for (const item of this) {
68
+ for (const item of this)
40
69
  yield item;
41
- }
42
70
  }
43
71
  /**
44
- * Time Complexity: O(n)
45
- * Space Complexity: O(1)
46
- *
47
- * The `every` function checks if every element in the array satisfies a given predicate.
48
- * @param predicate - The `predicate` parameter is a callback function that takes three arguments:
49
- * the current element being processed, its index, and the array it belongs to. It should return a
50
- * boolean value indicating whether the element satisfies a certain condition or not.
51
- * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
52
- * to be used as `this` when executing the `predicate` function. If `thisArg` is provided, it will be
53
- * passed as the `this` value to the `predicate` function. If `thisArg` is
54
- * @returns The `every` method is returning a boolean value. It returns `true` if every element in
55
- * the array satisfies the provided predicate function, and `false` otherwise.
72
+ * Tests whether all elements satisfy the predicate.
73
+ *
74
+ * @template TReturn
75
+ * @param predicate Function invoked for each element with signature `(value, index, self)`.
76
+ * @param thisArg Optional `this` binding for the predicate.
77
+ * @returns `true` if every element passes; otherwise `false`.
78
+ *
79
+ * @remarks
80
+ * Time O(n) in the worst case; may exit early when the first failure is found. Space O(1).
56
81
  */
57
82
  every(predicate, thisArg) {
58
83
  let index = 0;
59
84
  for (const item of this) {
60
- if (!predicate.call(thisArg, item, index++, this)) {
61
- return false;
85
+ if (thisArg === undefined) {
86
+ if (!predicate(item, index++, this))
87
+ return false;
88
+ }
89
+ else {
90
+ const fn = predicate;
91
+ if (!fn.call(thisArg, item, index++, this))
92
+ return false;
62
93
  }
63
94
  }
64
95
  return true;
65
96
  }
66
97
  /**
67
- * Time Complexity: O(n)
68
- * Space Complexity: O(1)
69
- *
70
- * The "some" function checks if at least one element in a collection satisfies a given predicate.
71
- * @param predicate - The `predicate` parameter is a callback function that takes three arguments:
72
- * `value`, `index`, and `array`. It should return a boolean value indicating whether the current
73
- * element satisfies the condition.
74
- * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
75
- * to be used as the `this` value when executing the `predicate` function. If `thisArg` is provided,
76
- * it will be passed as the `this` value to the `predicate` function. If `thisArg
77
- * @returns a boolean value. It returns true if the predicate function returns true for any element
78
- * in the collection, and false otherwise.
98
+ * Tests whether at least one element satisfies the predicate.
99
+ *
100
+ * @param predicate Function invoked for each element with signature `(value, index, self)`.
101
+ * @param thisArg Optional `this` binding for the predicate.
102
+ * @returns `true` if any element passes; otherwise `false`.
103
+ *
104
+ * @remarks
105
+ * Time O(n) in the worst case; may exit early on first success. Space O(1).
79
106
  */
80
107
  some(predicate, thisArg) {
81
108
  let index = 0;
82
109
  for (const item of this) {
83
- if (predicate.call(thisArg, item, index++, this)) {
84
- return true;
110
+ if (thisArg === undefined) {
111
+ if (predicate(item, index++, this))
112
+ return true;
113
+ }
114
+ else {
115
+ const fn = predicate;
116
+ if (fn.call(thisArg, item, index++, this))
117
+ return true;
85
118
  }
86
119
  }
87
120
  return false;
88
121
  }
89
122
  /**
90
- * Time Complexity: O(n)
91
- * Space Complexity: O(1)
92
- *
93
- * The `forEach` function iterates over each element in an array-like object and calls a callback
94
- * function for each element.
95
- * @param callbackfn - The callbackfn parameter is a function that will be called for each element in
96
- * the array. It takes three arguments: the current element being processed, the index of the current
97
- * element, and the array that forEach was called upon.
98
- * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
99
- * to be used as `this` when executing the `callbackfn` function. If `thisArg` is provided, it will
100
- * be passed as the `this` value to the `callbackfn` function. If `thisArg
123
+ * Invokes a callback for each element in iteration order.
124
+ *
125
+ * @param callbackfn Function invoked per element with signature `(value, index, self)`.
126
+ * @param thisArg Optional `this` binding for the callback.
127
+ * @returns `void`.
128
+ *
129
+ * @remarks
130
+ * Time O(n), Space O(1).
101
131
  */
102
132
  forEach(callbackfn, thisArg) {
103
133
  let index = 0;
104
134
  for (const item of this) {
105
- callbackfn.call(thisArg, item, index++, this);
135
+ if (thisArg === undefined) {
136
+ callbackfn(item, index++, this);
137
+ }
138
+ else {
139
+ const fn = callbackfn;
140
+ fn.call(thisArg, item, index++, this);
141
+ }
106
142
  }
107
143
  }
108
- /**
109
- * Time Complexity: O(n)
110
- * Space Complexity: O(1)
111
- *
112
- * The `find` function iterates over the elements of an array-like object and returns the first
113
- * element that satisfies the provided callback function.
114
- * @param predicate - The predicate parameter is a function that will be called for each element in
115
- * the array. It takes three arguments: the current element being processed, the index of the current
116
- * element, and the array itself. The function should return a boolean value indicating whether the
117
- * current element matches the desired condition.
118
- * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
119
- * to be used as `this` when executing the `callbackfn` function. If `thisArg` is provided, it will
120
- * be passed as the `this` value to the `callbackfn` function. If `thisArg
121
- * @returns The `find` method returns the first element in the array that satisfies the provided
122
- * callback function. If no element satisfies the callback function, `undefined` is returned.
123
- */
144
+ // Implementation signature
124
145
  find(predicate, thisArg) {
125
146
  let index = 0;
126
147
  for (const item of this) {
127
- if (predicate.call(thisArg, item, index++, this))
128
- return item;
148
+ if (thisArg === undefined) {
149
+ if (predicate(item, index++, this))
150
+ return item;
151
+ }
152
+ else {
153
+ const fn = predicate;
154
+ if (fn.call(thisArg, item, index++, this))
155
+ return item;
156
+ }
129
157
  }
130
158
  return;
131
159
  }
132
160
  /**
133
- * Time Complexity: O(n)
134
- * Space Complexity: O(1)
135
- *
136
- * The function checks if a given element exists in a collection.
137
- * @param {E} element - The parameter "element" is of type E, which means it can be any type. It
138
- * represents the element that we want to check for existence in the collection.
139
- * @returns a boolean value. It returns true if the element is found in the collection, and false
140
- * otherwise.
161
+ * Checks whether a strictly-equal element exists in the structure.
162
+ *
163
+ * @param element The element to test with `===` equality.
164
+ * @returns `true` if an equal element is found; otherwise `false`.
165
+ *
166
+ * @remarks
167
+ * Time O(n) in the worst case. Space O(1).
141
168
  */
142
169
  has(element) {
143
- for (const ele of this) {
170
+ for (const ele of this)
144
171
  if (ele === element)
145
172
  return true;
146
- }
147
173
  return false;
148
174
  }
149
175
  /**
150
- * Time Complexity: O(n)
151
- * Space Complexity: O(1)
152
- *
153
- * The `reduce` function iterates over the elements of an array-like object and applies a callback
154
- * function to reduce them into a single value.
155
- * @param callbackfn - The callbackfn parameter is a function that will be called for each element in
156
- * the array. It takes four arguments:
157
- * @param {U} initialValue - The initialValue parameter is the initial value of the accumulator. It
158
- * is the value that the accumulator starts with before the reduction operation begins.
159
- * @returns The `reduce` method is returning the final value of the accumulator after iterating over
160
- * all the elements in the array and applying the callback function to each element.
176
+ * Reduces all elements to a single accumulated value.
177
+ *
178
+ * @overload
179
+ * @param callbackfn Reducer of signature `(acc, value, index, self) => nextAcc`. The first element is used as the initial accumulator.
180
+ * @returns The final accumulated value typed as `E`.
181
+ *
182
+ * @overload
183
+ * @param callbackfn Reducer of signature `(acc, value, index, self) => nextAcc`.
184
+ * @param initialValue The initial accumulator value of type `E`.
185
+ * @returns The final accumulated value typed as `E`.
186
+ *
187
+ * @overload
188
+ * @template U The accumulator type when it differs from `E`.
189
+ * @param callbackfn Reducer of signature `(acc: U, value, index, self) => U`.
190
+ * @param initialValue The initial accumulator value of type `U`.
191
+ * @returns The final accumulated value typed as `U`.
192
+ *
193
+ * @remarks
194
+ * Time O(n), Space O(1). Throws if called on an empty structure without `initialValue`.
161
195
  */
162
196
  reduce(callbackfn, initialValue) {
163
- let accumulator = initialValue ?? 0;
164
197
  let index = 0;
165
- for (const item of this) {
166
- accumulator = callbackfn(accumulator, item, index++, this);
198
+ const iter = this[Symbol.iterator]();
199
+ let acc;
200
+ if (arguments.length >= 2) {
201
+ acc = initialValue;
202
+ }
203
+ else {
204
+ const first = iter.next();
205
+ if (first.done)
206
+ throw new TypeError('Reduce of empty structure with no initial value');
207
+ acc = first.value;
208
+ index = 1;
209
+ }
210
+ for (const value of iter) {
211
+ acc = callbackfn(acc, value, index++, this);
167
212
  }
168
- return accumulator;
213
+ return acc;
169
214
  }
170
215
  /**
171
- * Time Complexity: O(n)
172
- * Space Complexity: O(n)
216
+ * Materializes the elements into a new array.
173
217
  *
174
- * The `toArray` function converts a linked list into an array.
175
- * @returns The `toArray()` method is returning an array of type `E[]`.
218
+ * @returns A shallow array copy of the iteration order.
219
+ * @remarks
220
+ * Time O(n), Space O(n).
176
221
  */
177
222
  toArray() {
178
223
  return [...this];
179
224
  }
180
225
  /**
181
- * Time Complexity: O(n)
182
- * Space Complexity: O(n)
226
+ * Returns a representation of the structure suitable for quick visualization.
227
+ * Defaults to an array of elements; subclasses may override to provide richer visuals.
183
228
  *
184
- * The print function logs the elements of an array to the console.
229
+ * @returns A visual representation (array by default).
230
+ * @remarks
231
+ * Time O(n), Space O(n).
185
232
  */
186
233
  toVisual() {
187
234
  return [...this];
188
235
  }
189
236
  /**
190
- * Time Complexity: O(n)
191
- * Space Complexity: O(n)
237
+ * Prints `toVisual()` to the console. Intended for quick debugging.
192
238
  *
193
- * The print function logs the elements of an array to the console.
239
+ * @returns `void`.
240
+ * @remarks
241
+ * Time O(n) due to materialization, Space O(n) for the intermediate representation.
194
242
  */
195
243
  print() {
196
244
  console.log(this.toVisual());
@@ -1 +1 @@
1
- {"version":3,"file":"iterable-element-base.js","sourceRoot":"","sources":["../../../../src/data-structures/base/iterable-element-base.ts"],"names":[],"mappings":"AAEA,MAAM,OAAgB,mBAAmB;IACvC;;;;OAIG;IACH,YAAsB,OAA0C;QAC9D,IAAI,OAAO,EAAE,CAAC;YACZ,MAAM,EAAE,WAAW,EAAE,GAAG,OAAO,CAAC;YAChC,IAAI,OAAO,WAAW,KAAK,UAAU;gBAAE,IAAI,CAAC,YAAY,GAAG,WAAW,CAAC;iBAClE,IAAI,WAAW;gBAAE,MAAM,IAAI,SAAS,CAAC,qCAAqC,CAAC,CAAC;QACnF,CAAC;IACH,CAAC;IAES,YAAY,CAAwB;IAE9C,IAAI,WAAW;QACb,OAAO,IAAI,CAAC,YAAY,CAAC;IAC3B,CAAC;IAED;;;;;;;;OAQG;IACH,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,GAAG,IAAW;QAC/B,KAAK,CAAC,CAAC,IAAI,CAAC,YAAY,CAAC,GAAG,IAAI,CAAC,CAAC;IACpC,CAAC;IAED;;;;;OAKG;IACH,CAAC,MAAM;QACL,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AE,IAAI,CAAC;gBAAE,OAAO,IAAI,CAAC;QAChE,CAAC;QAED,OAAO;IACT,CAAC;IAED;;;;;;;;;OASG;IACH,GAAG,CAAC,OAAU;QACZ,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;YACvB,IAAI,GAAG,KAAK,OAAO;gBAAE,OAAO,IAAI,CAAC;QACnC,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;IAMD;;;;;;;;;;;;OAYG;IACH,MAAM,CAAI,UAA0C,EAAE,YAAgB;QACpE,IAAI,WAAW,GAAG,YAAY,IAAK,CAAO,CAAC;QAC3C,IAAI,KAAK,GAAG,CAAC,CAAC;QACd,KAAK,MAAM,IAAI,IAAI,IAAI,EAAE,CAAC;YACxB,WAAW,GAAG,UAAU,CAAC,WAAW,EAAE,IAAI,EAAE,KAAK,EAAE,EAAE,IAAI,CAAC,CAAC;QAC7D,CAAC;QACD,OAAO,WAAW,CAAC;IACrB,CAAC;IAED;;;;;;OAMG;IACH,OAAO;QACL,OAAO,CAAC,GAAG,IAAI,CAAC,CAAC;IACnB,CAAC;IAED;;;;;OAKG;IACH,QAAQ;QACN,OAAO,CAAC,GAAG,IAAI,CAAC,CAAC;IACnB,CAAC;IAED;;;;;OAKG;IACH,KAAK;QACH,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC;IAC/B,CAAC;CAaF"}
1
+ {"version":3,"file":"iterable-element-base.js","sourceRoot":"","sources":["../../../../src/data-structures/base/iterable-element-base.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;GAUG;AACH,MAAM,OAAgB,mBAAmB;IACvC;;;;;;;;OAQG;IACH,YAAsB,OAA0C;QAC9D,IAAI,OAAO,EAAE,CAAC;YACZ,MAAM,EAAE,WAAW,EAAE,GAAG,OAAO,CAAC;YAChC,IAAI,OAAO,WAAW,KAAK,UAAU;gBAAE,IAAI,CAAC,YAAY,GAAG,WAAW,CAAC;iBAClE,IAAI,WAAW;gB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'../../types';
2
+ /**
3
+ * Iterable view over key-value entries.
4
+ * @template K - Key type.
5
+ * @template V - Value type.
6
+ * @remarks Time O(1), Space O(1)
7
+ */
2
8
  export declare abstract class IterableEntryBase<K = any, V = any> {
9
+ /**
10
+ * Total number of entries.
11
+ * @returns Entry count.
12
+ * @remarks Time O(1), Space O(1)
13
+ */
3
14
  abstract get size(): number;
4
15
  /**
5
- * Time Complexity: O(n)
6
- * Space Complexity: O(1)
7
- *
8
- * The function is an implementation of the Symbol.iterator method that returns an iterable iterator.
9
- * @param {any[]} args - The `args` parameter in the code snippet represents a rest parameter. It
10
- * allows the function to accept any number of arguments as an array. In this case, the `args`
11
- * parameter is used to pass any additional arguments to the `_getIterator` method.
16
+ * Default iterator yielding `[key, value]` entries.
17
+ * @returns Iterator of `[K, V]`.
18
+ * @remarks Time O(n) to iterate, Space O(1)
12
19
  */
13
20
  [Symbol.iterator](...args: any[]): IterableIterator<[K, V]>;
14
21
  /**
15
- * Time Complexity: O(n)
16
- * Space Complexity: O(n)
17
- *
18
- * The function returns an iterator that yields key-value pairs from the object, where the value can
19
- * be undefined.
22
+ * Iterate over `[key, value]` pairs (may yield `undefined` values).
23
+ * @returns Iterator of `[K, V | undefined]`.
24
+ * @remarks Time O(n), Space O(1)
20
25
  */
21
26
  entries(): IterableIterator<[K, V | undefined]>;
22
27
  /**
23
- * Time Complexity: O(n)
24
- * Space Complexity: O(n)
25
- *
26
- * The function returns an iterator that yields the keys of a data structure.
28
+ * Iterate over keys only.
29
+ * @returns Iterator of keys.
30
+ * @remarks Time O(n), Space O(1)
27
31
  */
28
32
  keys(): IterableIterator<K>;
29
33
  /**
30
- * Time Complexity: O(n)
31
- * Space Complexity: O(n)
32
- *
33
- * The function returns an iterator that yields the values of a collection.
34
+ * Iterate over values only.
35
+ * @returns Iterator of values.
36
+ * @remarks Time O(n), Space O(1)
34
37
  */
35
38
  values(): IterableIterator<V>;
36
39
  /**
37
- * Time Complexity: O(n)
38
- * Space Complexity: O(1)
39
- *
40
- * The `every` function checks if every element in a collection satisfies a given condition.
41
- * @param predicate - The `predicate` parameter is a callback function that takes three arguments:
42
- * `value`, `key`, and `index`. It should return a boolean value indicating whether the condition is
43
- * met for the current element in the iteration.
44
- * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
45
- * to be used as `this` when executing the `predicate` function. If `thisArg` is provided, it will be
46
- * passed as the first argument to the `predicate` function. If `thisArg` is not provided
47
- * @returns The `every` method is returning a boolean value. It returns `true` if every element in
48
- * the collection satisfies the provided predicate function, and `false` otherwise.
40
+ * Test whether all entries satisfy the predicate.
41
+ * @param predicate - `(key, value, index, self) => boolean`.
42
+ * @param thisArg - Optional `this` for callback.
43
+ * @returns `true` if all pass; otherwise `false`.
44
+ * @remarks Time O(n), Space O(1)
49
45
  */
50
46
  every(predicate: EntryCallback<K, V, boolean>, thisArg?: any): boolean;
51
47
  /**
52
- * Time Complexity: O(n)
53
- * Space Complexity: O(1)
54
- *
55
- * The "some" function iterates over a collection and returns true if at least one element satisfies
56
- * a given predicate.
57
- * @param predicate - The `predicate` parameter is a callback function that takes three arguments:
58
- * `value`, `key`, and `index`. It should return a boolean value indicating whether the condition is
59
- * met for the current element in the iteration.
60
- * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
61
- * to be used as the `this` value when executing the `predicate` function. If `thisArg` is provided,
62
- * it will be passed as the first argument to the `predicate` function. If `thisArg` is
63
- * @returns a boolean value. It returns true if the predicate function returns true for any pair in
64
- * the collection, and false otherwise.
48
+ * Test whether any entry satisfies the predicate.
49
+ * @param predicate - `(key, value, index, self) => boolean`.
50
+ * @param thisArg - Optional `this` for callback.
51
+ * @returns `true` if any passes; otherwise `false`.
52
+ * @remarks Time O(n), Space O(1)
65
53
  */
66
54
  some(predicate: EntryCallback<K, V, boolean>, thisArg?: any): boolean;
67
55
  /**
68
- * Time Complexity: O(n)
69
- * Space Complexity: O(1)
70
- *
71
- * The `forEach` function iterates over each key-value pair in a collection and executes a callback
72
- * function for each pair.
73
- * @param callbackfn - The callback function that will be called for each element in the collection.
74
- * It takes four parameters: the value of the current element, the key of the current element, the
75
- * index of the current element, and the collection itself.
76
- * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that allows you to
77
- * specify the value of `this` within the callback function. If `thisArg` is provided, it will be
78
- * used as the `this` value when calling the callback function. If `thisArg` is not provided, `
56
+ * Visit each entry, left-to-right.
57
+ * @param callbackfn - `(key, value, index, self) => void`.
58
+ * @param thisArg - Optional `this` for callback.
59
+ * @remarks Time O(n), Space O(1)
79
60
  */
80
61
  forEach(callbackfn: EntryCallback<K, V, void>, thisArg?: any): void;
81
62
  /**
82
- * Time Complexity: O(n)
83
- * Space Complexity: O(1)
84
- *
85
- * The `find` function iterates over the entries of a collection and returns the first value for
86
- * which the callback function returns true.
87
- * @param callbackfn - The callback function that will be called for each entry in the collection. It
88
- * takes three arguments: the value of the entry, the key of the entry, and the index of the entry in
89
- * the collection. It should return a boolean value indicating whether the current entry matches the
90
- * desired condition.
91
- * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
92
- * to be used as `this` when executing the `callbackfn` function. If `thisArg` is provided, it will
93
- * be passed as the `this` value to the `callbackfn` function. If `thisArg
94
- * @returns The method `find` returns the value of the first element in the iterable that satisfies
95
- * the provided callback function. If no element satisfies the callback function, `undefined` is
96
- * returned.
63
+ * Find the first entry that matches a predicate.
64
+ * @param callbackfn - `(key, value, index, self) => boolean`.
65
+ * @param thisArg - Optional `this` for callback.
66
+ * @returns Matching `[key, value]` or `undefined`.
67
+ * @remarks Time O(n), Space O(1)
97
68
  */
98
69
  find(callbackfn: EntryCallback<K, V, boolean>, thisArg?: any): [K, V] | undefined;
99
70
  /**
100
- * Time Complexity: O(n)
101
- * Space Complexity: O(1)
102
- *
103
- * The function checks if a given key exists in a collection.
104
- * @param {K} key - The parameter "key" is of type K, which means it can be any type. It represents
105
- * the key that we want to check for existence in the data structure.
106
- * @returns a boolean value. It returns true if the key is found in the collection, and false
107
- * otherwise.
71
+ * Whether the given key exists.
72
+ * @param key - Key to test.
73
+ * @returns `true` if found; otherwise `false`.
74
+ * @remarks Time O(n) generic, Space O(1)
108
75
  */
109
76
  has(key: K): boolean;
110
77
  /**
111
- * Time Complexity: O(n)
112
- * Space Complexity: O(1)
113
- *
114
- * The function checks if a given value exists in a collection.
115
- * @param {V} value - The parameter "value" is the value that we want to check if it exists in the
116
- * collection.
117
- * @returns a boolean value, either true or false.
78
+ * Whether there exists an entry with the given value.
79
+ * @param value - Value to test.
80
+ * @returns `true` if found; otherwise `false`.
81
+ * @remarks Time O(n), Space O(1)
118
82
  */
119
83
  hasValue(value: V): boolean;
120
84
  /**
121
- * Time Complexity: O(n)
122
- * Space Complexity: O(1)
123
- *
124
- * The `get` function retrieves the value associated with a given key from a collection.
125
- * @param {K} key - K (the type of the key) - This parameter represents the key that is being
126
- * searched for in the collection.
127
- * @returns The `get` method returns the value associated with the specified key if it exists in the
128
- * collection, otherwise it returns `undefined`.
85
+ * Get the value under a key.
86
+ * @param key - Key to look up.
87
+ * @returns Value or `undefined`.
88
+ * @remarks Time O(n) generic, Space O(1)
129
89
  */
130
90
  get(key: K): V | undefined;
131
91
  /**
132
- * Time Complexity: O(n)
133
- * Space Complexity: O(1)
134
- *
135
- * The `reduce` function iterates over key-value pairs and applies a callback function to each pair,
136
- * accumulating a single value.
137
- * @param callbackfn - The callback function that will be called for each element in the collection.
138
- * It takes four arguments: the current accumulator value, the current value of the element, the key
139
- * of the element, and the index of the element in the collection. It should return the updated
140
- * accumulator value.
141
- * @param {U} initialValue - The `initialValue` parameter is the initial value of the accumulator. It
142
- * is the value that will be used as the first argument to the `callbackfn` function when reducing
143
- * the elements of the collection.
144
- * @returns The `reduce` method is returning the final value of the accumulator after iterating over
145
- * all the elements in the collection.
92
+ * Reduce entries into a single accumulator.
93
+ * @param callbackfn - `(acc, value, key, index, self) => acc`.
94
+ * @param initialValue - Initial accumulator.
95
+ * @returns Final accumulator.
96
+ * @remarks Time O(n), Space O(1)
146
97
  */
147
98
  reduce<U>(callbackfn: ReduceEntryCallback<K, V, U>, initialValue: U): U;
148
99
  /**
149
- * Time Complexity: O(n)
150
- * Space Complexity: O(n)
151
- *
152
- * The print function logs the elements of an array to the console.
100
+ * Visualize the iterable as an array of `[key, value]` pairs (or a custom string).
101
+ * @returns Array of entries (default) or a string.
102
+ * @remarks Time O(n), Space O(n)
153
103
  */
154
104
  toVisual(): [K, V][] | string;
155
105
  /**
156
- * Time Complexity: O(n)
157
- * Space Complexity: O(n)
158
- *
159
- * The print function logs the elements of an array to the console.
106
+ * Print a human-friendly representation to the console.
107
+ * @remarks Time O(n), Space O(n)
160
108
  */
161
109
  print(): void;
110
+ /**
111
+ * Whether there are no entries.
112
+ * @returns `true` if empty; `false` otherwise.
113
+ * @remarks Time O(1) typical, Space O(1)
114
+ */
162
115
  abstract isEmpty(): boolean;
116
+ /**
117
+ * Remove all entries.
118
+ * @remarks Time O(n) typical, Space O(1)
119
+ */
163
120
  abstract clear(): void;
164
- abstract clone(): any;
121
+ /**
122
+ * Deep clone preserving the concrete subtype.
123
+ * @returns A new instance of the same concrete class (`this` type).
124
+ * @remarks Time O(n) typical, Space O(n)
125
+ */
126
+ abstract clone(): this;
127
+ /**
128
+ * Map entries using an implementation-specific strategy.
129
+ * @remarks Time O(n), Space O(n)
130
+ */
165
131
  abstract map(...args: any[]): any;
166
- abstract filter(...args: any[]): any;
132
+ /**
133
+ * Filter entries and return the same-species structure.
134
+ * @returns A new instance of the same concrete class (`this` type).
135
+ * @remarks Time O(n), Space O(n)
136
+ */
137
+ abstract filter(...args: any[]): this;
138
+ /**
139
+ * Underlying iterator for the default iteration protocol.
140
+ * @returns Iterator of `[K, V]`.
141
+ * @remarks Time O(n), Space O(1)
142
+ */
167
143
  protected abstract _getIterator(...args: any[]): IterableIterator<[K, V]>;
168
144
  }