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,27 +1,32 @@
1
- import { EntryCallback, ReduceEntryCallback } from '../../types';
2
-
1
+ import type { EntryCallback, ReduceEntryCallback } from '../../types';
2
+
3
+ /**
4
+ * Iterable view over key-value entries.
5
+ * @template K - Key type.
6
+ * @template V - Value type.
7
+ * @remarks Time O(1), Space O(1)
8
+ */
3
9
  export abstract class IterableEntryBase<K = any, V = any> {
10
+ /**
11
+ * Total number of entries.
12
+ * @returns Entry count.
13
+ * @remarks Time O(1), Space O(1)
14
+ */
4
15
  abstract get size(): number;
5
16
 
6
17
  /**
7
- * Time Complexity: O(n)
8
- * Space Complexity: O(1)
9
- *
10
- * The function is an implementation of the Symbol.iterator method that returns an iterable iterator.
11
- * @param {any[]} args - The `args` parameter in the code snippet represents a rest parameter. It
12
- * allows the function to accept any number of arguments as an array. In this case, the `args`
13
- * parameter is used to pass any additional arguments to the `_getIterator` method.
18
+ * Default iterator yielding `[key, value]` entries.
19
+ * @returns Iterator of `[K, V]`.
20
+ * @remarks Time O(n) to iterate, Space O(1)
14
21
  */
15
22
  *[Symbol.iterator](...args: any[]): IterableIterator<[K, V]> {
16
23
  yield* this._getIterator(...args);
17
24
  }
18
25
 
19
26
  /**
20
- * Time Complexity: O(n)
21
- * Space Complexity: O(n)
22
- *
23
- * The function returns an iterator that yields key-value pairs from the object, where the value can
24
- * be undefined.
27
+ * Iterate over `[key, value]` pairs (may yield `undefined` values).
28
+ * @returns Iterator of `[K, V | undefined]`.
29
+ * @remarks Time O(n), Space O(1)
25
30
  */
26
31
  *entries(): IterableIterator<[K, V | undefined]> {
27
32
  for (const item of this) {
@@ -30,10 +35,9 @@ export abstract class IterableEntryBase<K = any, V = any> {
30
35
  }
31
36
 
32
37
  /**
33
- * Time Complexity: O(n)
34
- * Space Complexity: O(n)
35
- *
36
- * The function returns an iterator that yields the keys of a data structure.
38
+ * Iterate over keys only.
39
+ * @returns Iterator of keys.
40
+ * @remarks Time O(n), Space O(1)
37
41
  */
38
42
  *keys(): IterableIterator<K> {
39
43
  for (const item of this) {
@@ -42,10 +46,9 @@ export abstract class IterableEntryBase<K = any, V = any> {
42
46
  }
43
47
 
44
48
  /**
45
- * Time Complexity: O(n)
46
- * Space Complexity: O(n)
47
- *
48
- * The function returns an iterator that yields the values of a collection.
49
+ * Iterate over values only.
50
+ * @returns Iterator of values.
51
+ * @remarks Time O(n), Space O(1)
49
52
  */
50
53
  *values(): IterableIterator<V> {
51
54
  for (const item of this) {
@@ -54,18 +57,11 @@ export abstract class IterableEntryBase<K = any, V = any> {
54
57
  }
55
58
 
56
59
  /**
57
- * Time Complexity: O(n)
58
- * Space Complexity: O(1)
59
- *
60
- * The `every` function checks if every element in a collection satisfies a given condition.
61
- * @param predicate - The `predicate` parameter is a callback function that takes three arguments:
62
- * `value`, `key`, and `index`. It should return a boolean value indicating whether the condition is
63
- * met for the current element in the iteration.
64
- * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
65
- * to be used as `this` when executing the `predicate` function. If `thisArg` is provided, it will be
66
- * passed as the first argument to the `predicate` function. If `thisArg` is not provided
67
- * @returns The `every` method is returning a boolean value. It returns `true` if every element in
68
- * the collection satisfies the provided predicate function, and `false` otherwise.
60
+ * Test whether all entries satisfy the predicate.
61
+ * @param predicate - `(key, value, index, self) => boolean`.
62
+ * @param thisArg - Optional `this` for callback.
63
+ * @returns `true` if all pass; otherwise `false`.
64
+ * @remarks Time O(n), Space O(1)
69
65
  */
70
66
  every(predicate: EntryCallback<K, V, boolean>, thisArg?: any): boolean {
71
67
  let index = 0;
@@ -78,19 +74,11 @@ export abstract class IterableEntryBase<K = any, V = any> {
78
74
  }
79
75
 
80
76
  /**
81
- * Time Complexity: O(n)
82
- * Space Complexity: O(1)
83
- *
84
- * The "some" function iterates over a collection and returns true if at least one element satisfies
85
- * a given predicate.
86
- * @param predicate - The `predicate` parameter is a callback function that takes three arguments:
87
- * `value`, `key`, and `index`. It should return a boolean value indicating whether the condition is
88
- * met for the current element in the iteration.
89
- * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
90
- * to be used as the `this` value when executing the `predicate` function. If `thisArg` is provided,
91
- * it will be passed as the first argument to the `predicate` function. If `thisArg` is
92
- * @returns a boolean value. It returns true if the predicate function returns true for any pair in
93
- * the collection, and false otherwise.
77
+ * Test whether any entry satisfies the predicate.
78
+ * @param predicate - `(key, value, index, self) => boolean`.
79
+ * @param thisArg - Optional `this` for callback.
80
+ * @returns `true` if any passes; otherwise `false`.
81
+ * @remarks Time O(n), Space O(1)
94
82
  */
95
83
  some(predicate: EntryCallback<K, V, boolean>, thisArg?: any): boolean {
96
84
  let index = 0;
@@ -103,17 +91,10 @@ export abstract class IterableEntryBase<K = any, V = any> {
103
91
  }
104
92
 
105
93
  /**
106
- * Time Complexity: O(n)
107
- * Space Complexity: O(1)
108
- *
109
- * The `forEach` function iterates over each key-value pair in a collection and executes a callback
110
- * function for each pair.
111
- * @param callbackfn - The callback function that will be called for each element in the collection.
112
- * It takes four parameters: the value of the current element, the key of the current element, the
113
- * index of the current element, and the collection itself.
114
- * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that allows you to
115
- * specify the value of `this` within the callback function. If `thisArg` is provided, it will be
116
- * used as the `this` value when calling the callback function. If `thisArg` is not provided, `
94
+ * Visit each entry, left-to-right.
95
+ * @param callbackfn - `(key, value, index, self) => void`.
96
+ * @param thisArg - Optional `this` for callback.
97
+ * @remarks Time O(n), Space O(1)
117
98
  */
118
99
  forEach(callbackfn: EntryCallback<K, V, void>, thisArg?: any): void {
119
100
  let index = 0;
@@ -124,21 +105,11 @@ export abstract class IterableEntryBase<K = any, V = any> {
124
105
  }
125
106
 
126
107
  /**
127
- * Time Complexity: O(n)
128
- * Space Complexity: O(1)
129
- *
130
- * The `find` function iterates over the entries of a collection and returns the first value for
131
- * which the callback function returns true.
132
- * @param callbackfn - The callback function that will be called for each entry in the collection. It
133
- * takes three arguments: the value of the entry, the key of the entry, and the index of the entry in
134
- * the collection. It should return a boolean value indicating whether the current entry matches the
135
- * desired condition.
136
- * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
137
- * to be used as `this` when executing the `callbackfn` function. If `thisArg` is provided, it will
138
- * be passed as the `this` value to the `callbackfn` function. If `thisArg
139
- * @returns The method `find` returns the value of the first element in the iterable that satisfies
140
- * the provided callback function. If no element satisfies the callback function, `undefined` is
141
- * returned.
108
+ * Find the first entry that matches a predicate.
109
+ * @param callbackfn - `(key, value, index, self) => boolean`.
110
+ * @param thisArg - Optional `this` for callback.
111
+ * @returns Matching `[key, value]` or `undefined`.
112
+ * @remarks Time O(n), Space O(1)
142
113
  */
143
114
  find(callbackfn: EntryCallback<K, V, boolean>, thisArg?: any): [K, V] | undefined {
144
115
  let index = 0;
@@ -150,14 +121,10 @@ export abstract class IterableEntryBase<K = any, V = any> {
150
121
  }
151
122
 
152
123
  /**
153
- * Time Complexity: O(n)
154
- * Space Complexity: O(1)
155
- *
156
- * The function checks if a given key exists in a collection.
157
- * @param {K} key - The parameter "key" is of type K, which means it can be any type. It represents
158
- * the key that we want to check for existence in the data structure.
159
- * @returns a boolean value. It returns true if the key is found in the collection, and false
160
- * otherwise.
124
+ * Whether the given key exists.
125
+ * @param key - Key to test.
126
+ * @returns `true` if found; otherwise `false`.
127
+ * @remarks Time O(n) generic, Space O(1)
161
128
  */
162
129
  has(key: K): boolean {
163
130
  for (const item of this) {
@@ -168,13 +135,10 @@ export abstract class IterableEntryBase<K = any, V = any> {
168
135
  }
169
136
 
170
137
  /**
171
- * Time Complexity: O(n)
172
- * Space Complexity: O(1)
173
- *
174
- * The function checks if a given value exists in a collection.
175
- * @param {V} value - The parameter "value" is the value that we want to check if it exists in the
176
- * collection.
177
- * @returns a boolean value, either true or false.
138
+ * Whether there exists an entry with the given value.
139
+ * @param value - Value to test.
140
+ * @returns `true` if found; otherwise `false`.
141
+ * @remarks Time O(n), Space O(1)
178
142
  */
179
143
  hasValue(value: V): boolean {
180
144
  for (const [, elementValue] of this) {
@@ -184,14 +148,10 @@ export abstract class IterableEntryBase<K = any, V = any> {
184
148
  }
185
149
 
186
150
  /**
187
- * Time Complexity: O(n)
188
- * Space Complexity: O(1)
189
- *
190
- * The `get` function retrieves the value associated with a given key from a collection.
191
- * @param {K} key - K (the type of the key) - This parameter represents the key that is being
192
- * searched for in the collection.
193
- * @returns The `get` method returns the value associated with the specified key if it exists in the
194
- * collection, otherwise it returns `undefined`.
151
+ * Get the value under a key.
152
+ * @param key - Key to look up.
153
+ * @returns Value or `undefined`.
154
+ * @remarks Time O(n) generic, Space O(1)
195
155
  */
196
156
  get(key: K): V | undefined {
197
157
  for (const item of this) {
@@ -202,20 +162,11 @@ export abstract class IterableEntryBase<K = any, V = any> {
202
162
  }
203
163
 
204
164
  /**
205
- * Time Complexity: O(n)
206
- * Space Complexity: O(1)
207
- *
208
- * The `reduce` function iterates over key-value pairs and applies a callback function to each pair,
209
- * accumulating a single value.
210
- * @param callbackfn - The callback function that will be called for each element in the collection.
211
- * It takes four arguments: the current accumulator value, the current value of the element, the key
212
- * of the element, and the index of the element in the collection. It should return the updated
213
- * accumulator value.
214
- * @param {U} initialValue - The `initialValue` parameter is the initial value of the accumulator. It
215
- * is the value that will be used as the first argument to the `callbackfn` function when reducing
216
- * the elements of the collection.
217
- * @returns The `reduce` method is returning the final value of the accumulator after iterating over
218
- * all the elements in the collection.
165
+ * Reduce entries into a single accumulator.
166
+ * @param callbackfn - `(acc, value, key, index, self) => acc`.
167
+ * @param initialValue - Initial accumulator.
168
+ * @returns Final accumulator.
169
+ * @remarks Time O(n), Space O(1)
219
170
  */
220
171
  reduce<U>(callbackfn: ReduceEntryCallback<K, V, U>, initialValue: U): U {
221
172
  let accumulator = initialValue;
@@ -228,34 +179,59 @@ export abstract class IterableEntryBase<K = any, V = any> {
228
179
  }
229
180
 
230
181
  /**
231
- * Time Complexity: O(n)
232
- * Space Complexity: O(n)
233
- *
234
- * The print function logs the elements of an array to the console.
182
+ * Visualize the iterable as an array of `[key, value]` pairs (or a custom string).
183
+ * @returns Array of entries (default) or a string.
184
+ * @remarks Time O(n), Space O(n)
235
185
  */
236
186
  toVisual(): [K, V][] | string {
237
187
  return [...this];
238
188
  }
239
189
 
240
190
  /**
241
- * Time Complexity: O(n)
242
- * Space Complexity: O(n)
243
- *
244
- * The print function logs the elements of an array to the console.
191
+ * Print a human-friendly representation to the console.
192
+ * @remarks Time O(n), Space O(n)
245
193
  */
246
194
  print(): void {
247
195
  console.log(this.toVisual());
248
196
  }
249
197
 
198
+ /**
199
+ * Whether there are no entries.
200
+ * @returns `true` if empty; `false` otherwise.
201
+ * @remarks Time O(1) typical, Space O(1)
202
+ */
250
203
  abstract isEmpty(): boolean;
251
204
 
205
+ /**
206
+ * Remove all entries.
207
+ * @remarks Time O(n) typical, Space O(1)
208
+ */
252
209
  abstract clear(): void;
253
210
 
254
- abstract clone(): any;
211
+ /**
212
+ * Deep clone preserving the concrete subtype.
213
+ * @returns A new instance of the same concrete class (`this` type).
214
+ * @remarks Time O(n) typical, Space O(n)
215
+ */
216
+ abstract clone(): this;
255
217
 
218
+ /**
219
+ * Map entries using an implementation-specific strategy.
220
+ * @remarks Time O(n), Space O(n)
221
+ */
256
222
  abstract map(...args: any[]): any;
257
223
 
258
- abstract filter(...args: any[]): any;
224
+ /**
225
+ * Filter entries and return the same-species structure.
226
+ * @returns A new instance of the same concrete class (`this` type).
227
+ * @remarks Time O(n), Space O(n)
228
+ */
229
+ abstract filter(...args: any[]): this;
259
230
 
231
+ /**
232
+ * Underlying iterator for the default iteration protocol.
233
+ * @returns Iterator of `[K, V]`.
234
+ * @remarks Time O(n), Space O(1)
235
+ */
260
236
  protected abstract _getIterator(...args: any[]): IterableIterator<[K, V]>;
261
237
  }