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
@@ -5,68 +5,22 @@
5
5
  * @copyright Copyright (c) 2022 Kirk Qi <qilinaus@gmail.com>
6
6
  * @license MIT License
7
7
  */
8
- import type { Comparator, ElementCallback, PriorityQueueOptions } from '../../types';
8
+ import type { PriorityQueueOptions } from '../../types';
9
9
  import { PriorityQueue } from './priority-queue';
10
10
  /**
11
- *
11
+ * Min-oriented priority queue (min-heap) built on {@link PriorityQueue}.
12
+ * The queue removes the smallest element first under the provided comparator.
13
+ * Provide a custom comparator if you store non-primitive objects.
14
+ * @template E Element type stored in the queue.
15
+ * @template R Extra record/metadata associated with each element.
16
+ * @example
12
17
  */
13
18
  export declare class MinPriorityQueue<E = any, R = any> extends PriorityQueue<E, R> {
14
19
  /**
15
- * The constructor initializes a PriorityQueue with optional elements and options, including a
16
- * comparator function.
17
- * @param elements - The `elements` parameter is an iterable object that contains the initial
18
- * elements to be added to the priority queue. It is optional and defaults to an empty array if not
19
- * provided.
20
- * @param options - The `options` parameter is an object that contains additional configuration
21
- * options for the priority queue. In this case, it has a property called `comparator,` which is a
22
- * function used to compare elements in the priority queue. The `comparator` function takes two
23
- * parameters `a` and `b`
20
+ * Creates a min-priority queue.
21
+ * @param elements Optional initial elements to insert.
22
+ * @param options Optional configuration (e.g., `comparator`, `toElementFn`).
23
+ * @remarks Complexity Time: O(n log n) when inserting n elements incrementally; Space: O(n).
24
24
  */
25
25
  constructor(elements?: Iterable<E> | Iterable<R>, options?: PriorityQueueOptions<E, R>);
26
- /**
27
- * The `clone` function returns a new instance of the `MinPriorityQueue` class with the same
28
- * comparator and toElementFn as the original instance.
29
- * @returns The method is returning a new instance of the `MinPriorityQueue` class with the same
30
- * properties as the current instance.
31
- */
32
- clone(): MinPriorityQueue<E, R>;
33
- /**
34
- * Time Complexity: O(n)
35
- * Space Complexity: O(n)
36
- *
37
- * The `filter` function creates a new MinPriorityQueue object containing elements that pass a given callback
38
- * function.
39
- * @param callback - The `callback` parameter is a function that will be called for each element in
40
- * the heap. It takes three arguments: the current element, the index of the current element, and the
41
- * heap itself. The callback function should return a boolean value indicating whether the current
42
- * element should be included in the filtered list
43
- * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
44
- * to be used as `this` when executing the `callback` function. If `thisArg` is provided, it will be
45
- * passed as the `this` value to the `callback` function. If `thisArg` is
46
- * @returns The `filter` method is returning a new `MinPriorityQueue` object that contains the elements that pass
47
- * the filter condition specified by the `callback` function.
48
- */
49
- filter(callback: ElementCallback<E, R, boolean>, thisArg?: any): MinPriorityQueue<E, R>;
50
- /**
51
- * Time Complexity: O(n log n)
52
- * Space Complexity: O(n)
53
- *
54
- * The `map` function creates a new heap by applying a callback function to each element of the
55
- * original heap.
56
- * @param callback - The `callback` parameter is a function that will be called for each element in
57
- * the heap. It takes three arguments: `el` (the current element), `index` (the index of the current
58
- * element), and `this` (the heap itself). The callback function should return a value of
59
- * @param comparator - The `comparator` parameter is a function that defines the order of the
60
- * elements in the heap. It takes two elements `a` and `b` as arguments and returns a negative number
61
- * if `a` should be placed before `b`, a positive number if `a` should be placed after
62
- * @param [toElementFn] - The `toElementFn` parameter is an optional function that converts the raw
63
- * element `RR` to the desired type `T`. It takes a single argument `rawElement` of type `RR` and
64
- * returns a value of type `T`. This function is used to transform the elements of the original
65
- * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that allows you to
66
- * specify the value of `this` within the callback function. It is used to set the context or scope
67
- * in which the callback function will be executed. If `thisArg` is provided, it will be used as the
68
- * value of
69
- * @returns a new instance of the `MinPriorityQueue` class with the mapped elements.
70
- */
71
- map<EM, RM>(callback: ElementCallback<E, R, EM>, comparator: Comparator<EM>, toElementFn?: (rawElement: RM) => EM, thisArg?: any): MinPriorityQueue<EM, RM>;
72
26
  }
@@ -1,90 +1,21 @@
1
1
  import { PriorityQueue } from './priority-queue';
2
2
  /**
3
- *
3
+ * Min-oriented priority queue (min-heap) built on {@link PriorityQueue}.
4
+ * The queue removes the smallest element first under the provided comparator.
5
+ * Provide a custom comparator if you store non-primitive objects.
6
+ * @template E Element type stored in the queue.
7
+ * @template R Extra record/metadata associated with each element.
8
+ * @example
4
9
  */
5
10
  export class MinPriorityQueue extends PriorityQueue {
6
11
  /**
7
- * The constructor initializes a PriorityQueue with optional elements and options, including a
8
- * comparator function.
9
- * @param elements - The `elements` parameter is an iterable object that contains the initial
10
- * elements to be added to the priority queue. It is optional and defaults to an empty array if not
11
- * provided.
12
- * @param options - The `options` parameter is an object that contains additional configuration
13
- * options for the priority queue. In this case, it has a property called `comparator,` which is a
14
- * function used to compare elements in the priority queue. The `comparator` function takes two
15
- * parameters `a` and `b`
12
+ * Creates a min-priority queue.
13
+ * @param elements Optional initial elements to insert.
14
+ * @param options Optional configuration (e.g., `comparator`, `toElementFn`).
15
+ * @remarks Complexity Time: O(n log n) when inserting n elements incrementally; Space: O(n).
16
16
  */
17
17
  constructor(elements = [], options) {
18
18
  super(elements, options);
19
19
  }
20
- /**
21
- * The `clone` function returns a new instance of the `MinPriorityQueue` class with the same
22
- * comparator and toElementFn as the original instance.
23
- * @returns The method is returning a new instance of the `MinPriorityQueue` class with the same
24
- * properties as the current instance.
25
- */
26
- clone() {
27
- return new MinPriorityQueue(this, { comparator: this.comparator, toElementFn: this.toElementFn });
28
- }
29
- /**
30
- * Time Complexity: O(n)
31
- * Space Complexity: O(n)
32
- *
33
- * The `filter` function creates a new MinPriorityQueue object containing elements that pass a given callback
34
- * function.
35
- * @param callback - The `callback` parameter is a function that will be called for each element in
36
- * the heap. It takes three arguments: the current element, the index of the current element, and the
37
- * heap itself. The callback function should return a boolean value indicating whether the current
38
- * element should be included in the filtered list
39
- * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
40
- * to be used as `this` when executing the `callback` function. If `thisArg` is provided, it will be
41
- * passed as the `this` value to the `callback` function. If `thisArg` is
42
- * @returns The `filter` method is returning a new `MinPriorityQueue` object that contains the elements that pass
43
- * the filter condition specified by the `callback` function.
44
- */
45
- filter(callback, thisArg) {
46
- const filteredPriorityQueue = new MinPriorityQueue([], {
47
- toElementFn: this.toElementFn,
48
- comparator: this.comparator
49
- });
50
- let index = 0;
51
- for (const current of this) {
52
- if (callback.call(thisArg, current, index, this)) {
53
- filteredPriorityQueue.add(current);
54
- }
55
- index++;
56
- }
57
- return filteredPriorityQueue;
58
- }
59
- /**
60
- * Time Complexity: O(n log n)
61
- * Space Complexity: O(n)
62
- *
63
- * The `map` function creates a new heap by applying a callback function to each element of the
64
- * original heap.
65
- * @param callback - The `callback` parameter is a function that will be called for each element in
66
- * the heap. It takes three arguments: `el` (the current element), `index` (the index of the current
67
- * element), and `this` (the heap itself). The callback function should return a value of
68
- * @param comparator - The `comparator` parameter is a function that defines the order of the
69
- * elements in the heap. It takes two elements `a` and `b` as arguments and returns a negative number
70
- * if `a` should be placed before `b`, a positive number if `a` should be placed after
71
- * @param [toElementFn] - The `toElementFn` parameter is an optional function that converts the raw
72
- * element `RR` to the desired type `T`. It takes a single argument `rawElement` of type `RR` and
73
- * returns a value of type `T`. This function is used to transform the elements of the original
74
- * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that allows you to
75
- * specify the value of `this` within the callback function. It is used to set the context or scope
76
- * in which the callback function will be executed. If `thisArg` is provided, it will be used as the
77
- * value of
78
- * @returns a new instance of the `MinPriorityQueue` class with the mapped elements.
79
- */
80
- map(callback, comparator, toElementFn, thisArg) {
81
- const mappedPriorityQueue = new MinPriorityQueue([], { comparator, toElementFn });
82
- let index = 0;
83
- for (const el of this) {
84
- mappedPriorityQueue.add(callback.call(thisArg, el, index, this));
85
- index++;
86
- }
87
- return mappedPriorityQueue;
88
- }
89
20
  }
90
21
  //# sourceMappingURL=min-priority-queue.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"min-priority-queue.js","sourceRoot":"","sources":["../../../../src/data-structures/priority-queue/min-priority-queue.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAEjD;;GAEG;AACH,MAAM,OAAO,gBAAmC,SAAQ,aAAmB;IACzE;;;;;;;;;;OAUG;IACH,YAAY,WAAsC,EAAE,EAAE,OAAoC;QACxF,KAAK,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IAC3B,CAAC;IAED;;;;;OAKG;IACM,KAAK;QACZ,OAAO,IAAI,gBAAgB,CAAO,IAAI,EAAE,EAAE,UAAU,EAAE,IAAI,CAAC,UAAU,EAAE,WAAW,EAAE,IAAI,CAAC,WAAW,EAAE,CAAC,CAAC;IAC1G,CAAC;IAED;;;;;;;;;;;;;;;OAeG;IACM,MAAM,CAAC,QAAwC,EAAE,OAAa;QACrE,MAAM,qBAAqB,GAAG,IAAI,gBAAgB,CAAO,EAAE,EAAE;YAC3D,WAAW,EAAE,IAAI,CAAC,WAAW;YAC7B,UAAU,EAAE,IAAI,CAAC,UAAU;SAC5B,CAAC,CAAC;QACH,IAAI,KAAK,GAAG,CAAC,CAAC;QACd,KAAK,MAAM,OAAO,IAAI,IAAI,EAAE,CAAC;YAC3B,IAAI,QAAQ,CAAC,IAAI,CAAC,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,IAAI,CAAC,EAAE,CAAC;gBACjD,qBAAqB,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;YACrC,CAAC;YACD,KAAK,EAAE,CAAC;QACV,CAAC;QACD,OAAO,qBAAqB,CAAC;IAC/B,CAAC;IAED;;;;;;;;;;;;;;;;;;;;OAoBG;IACM,GAAG,CACV,QAAmC,EACnC,UAA0B,EAC1B,WAAoC,EACpC,OAAa;QAEb,MAAM,mBAAmB,GAA6B,IAAI,gBAAgB,CAAS,EAAE,EAAE,EAAE,UAAU,EAAE,WAAW,EAAE,CAAC,CAAC;QACpH,IAAI,KAAK,GAAG,CAAC,CAAC;QACd,KAAK,MAAM,EAAE,IAAI,IAAI,EAAE,CAAC;YACtB,mBAAmB,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC,CAAC;YACjE,KAAK,EAAE,CAAC;QACV,CAAC;QACD,OAAO,mBAAmB,CAAC;IAC7B,CAAC;CACF"}
1
+ {"version":3,"file":"min-priority-queue.js","sourceRoot":"","sources":["../../../../src/data-structures/priority-queue/min-priority-queue.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAEjD;;;;;;;GAOG;AACH,MAAM,OAAO,gBAAmC,SAAQ,aAAmB;IACzE;;;;;OAKG;IACH,YAAY,WAAsC,EAAE,EAAE,OAAoC;QACxF,KAAK,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IAC3B,CAAC;CACF"}
@@ -5,70 +5,11 @@
5
5
  * @copyright Copyright (c) 2022 Kirk Qi <qilinaus@gmail.com>
6
6
  * @license MIT License
7
7
  */
8
- import type { Comparator, ElementCallback, PriorityQueueOptions } from '../../types';
8
+ import type { PriorityQueueOptions } from '../../types';
9
9
  import { Heap } from '../heap';
10
10
  /**
11
- * 1. Element Priority: In a PriorityQueue, elements are sorted according to their priority. Each dequeue (element removal) operation removes the element with the highest priority. The priority can be determined based on the natural ordering of the elements or through a provided comparator (Comparator).
12
- * 2. Heap-Based Implementation: PriorityQueue is typically implemented using a binary heap, allowing both insertion and removal operations to be completed in O(log n) time, where n is the number of elements in the queue.
13
- * 3. Task Scheduling: In systems where tasks need to be processed based on the urgency of tasks rather than the order of arrival.
14
- * 4. Dijkstra's Algorithm: In shortest path algorithms for graphs, used to select the next shortest edge to visit.
15
- * 5. Huffman Coding: Used to select the smallest node combination when constructing a Huffman tree.
16
- * 6. Kth Largest Element in a Data Stream: Used to maintain a min-heap of size K for quickly finding the Kth largest element in stream data
11
+ * @example
17
12
  */
18
13
  export declare class PriorityQueue<E = any, R = any> extends Heap<E, R> {
19
- /**
20
- * The constructor initializes a priority queue with optional elements and options.
21
- * @param elements - The `elements` parameter is an iterable object that contains the initial
22
- * elements to be added to the priority queue. It is an optional parameter, and if not provided, the
23
- * priority queue will be initialized as empty.
24
- * @param [options] - The `options` parameter is an optional object that can be used to customize the
25
- * behavior of the priority queue. It can contain the following properties:
26
- */
27
14
  constructor(elements?: Iterable<E> | Iterable<R>, options?: PriorityQueueOptions<E, R>);
28
- /**
29
- * The `clone` function returns a new instance of the `PriorityQueue` class with the same comparator
30
- * and toElementFn as the original instance.
31
- * @returns The method is returning a new instance of the `PriorityQueue` class with the same
32
- * elements and properties as the current instance.
33
- */
34
- clone(): PriorityQueue<E, R>;
35
- /**
36
- * Time Complexity: O(n)
37
- * Space Complexity: O(n)
38
- *
39
- * The `filter` function creates a new PriorityQueue object containing elements that pass a given callback
40
- * function.
41
- * @param callback - The `callback` parameter is a function that will be called for each element in
42
- * the heap. It takes three arguments: the current element, the index of the current element, and the
43
- * heap itself. The callback function should return a boolean value indicating whether the current
44
- * element should be included in the filtered list
45
- * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
46
- * to be used as `this` when executing the `callback` function. If `thisArg` is provided, it will be
47
- * passed as the `this` value to the `callback` function. If `thisArg` is
48
- * @returns The `filter` method is returning a new `PriorityQueue` object that contains the elements that pass
49
- * the filter condition specified by the `callback` function.
50
- */
51
- filter(callback: ElementCallback<E, R, boolean>, thisArg?: any): PriorityQueue<E, R>;
52
- /**
53
- * Time Complexity: O(n log n)
54
- * Space Complexity: O(n)
55
- *
56
- * The `map` function creates a new heap by applying a callback function to each element of the
57
- * original heap.
58
- * @param callback - The `callback` parameter is a function that will be called for each element in
59
- * the heap. It takes three arguments: `el` (the current element), `index` (the index of the current
60
- * element), and `this` (the heap itself). The callback function should return a value of
61
- * @param comparator - The `comparator` parameter is a function that defines the order of the
62
- * elements in the heap. It takes two elements `a` and `b` as arguments and returns a negative number
63
- * if `a` should be placed before `b`, a positive number if `a` should be placed after
64
- * @param [toElementFn] - The `toElementFn` parameter is an optional function that converts the raw
65
- * element `RR` to the desired type `T`. It takes a single argument `rawElement` of type `RR` and
66
- * returns a value of type `T`. This function is used to transform the elements of the original
67
- * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that allows you to
68
- * specify the value of `this` within the callback function. It is used to set the context or scope
69
- * in which the callback function will be executed. If `thisArg` is provided, it will be used as the
70
- * value of
71
- * @returns a new instance of the `PriorityQueue` class with the mapped elements.
72
- */
73
- map<EM, RM>(callback: ElementCallback<E, R, EM>, comparator: Comparator<EM>, toElementFn?: (rawElement: RM) => EM, thisArg?: any): PriorityQueue<EM, RM>;
74
15
  }
@@ -1,92 +1,17 @@
1
+ /**
2
+ * data-structure-typed
3
+ *
4
+ * @author Kirk Qi
5
+ * @copyright Copyright (c) 2022 Kirk Qi <qilinaus@gmail.com>
6
+ * @license MIT License
7
+ */
1
8
  import { Heap } from '../heap';
2
9
  /**
3
- * 1. Element Priority: In a PriorityQueue, elements are sorted according to their priority. Each dequeue (element removal) operation removes the element with the highest priority. The priority can be determined based on the natural ordering of the elements or through a provided comparator (Comparator).
4
- * 2. Heap-Based Implementation: PriorityQueue is typically implemented using a binary heap, allowing both insertion and removal operations to be completed in O(log n) time, where n is the number of elements in the queue.
5
- * 3. Task Scheduling: In systems where tasks need to be processed based on the urgency of tasks rather than the order of arrival.
6
- * 4. Dijkstra's Algorithm: In shortest path algorithms for graphs, used to select the next shortest edge to visit.
7
- * 5. Huffman Coding: Used to select the smallest node combination when constructing a Huffman tree.
8
- * 6. Kth Largest Element in a Data Stream: Used to maintain a min-heap of size K for quickly finding the Kth largest element in stream data
10
+ * @example
9
11
  */
10
12
  export class PriorityQueue extends Heap {
11
- /**
12
- * The constructor initializes a priority queue with optional elements and options.
13
- * @param elements - The `elements` parameter is an iterable object that contains the initial
14
- * elements to be added to the priority queue. It is an optional parameter, and if not provided, the
15
- * priority queue will be initialized as empty.
16
- * @param [options] - The `options` parameter is an optional object that can be used to customize the
17
- * behavior of the priority queue. It can contain the following properties:
18
- */
19
13
  constructor(elements = [], options) {
20
14
  super(elements, options);
21
15
  }
22
- /**
23
- * The `clone` function returns a new instance of the `PriorityQueue` class with the same comparator
24
- * and toElementFn as the original instance.
25
- * @returns The method is returning a new instance of the `PriorityQueue` class with the same
26
- * elements and properties as the current instance.
27
- */
28
- clone() {
29
- return new PriorityQueue(this, { comparator: this.comparator, toElementFn: this.toElementFn });
30
- }
31
- /**
32
- * Time Complexity: O(n)
33
- * Space Complexity: O(n)
34
- *
35
- * The `filter` function creates a new PriorityQueue object containing elements that pass a given callback
36
- * function.
37
- * @param callback - The `callback` parameter is a function that will be called for each element in
38
- * the heap. It takes three arguments: the current element, the index of the current element, and the
39
- * heap itself. The callback function should return a boolean value indicating whether the current
40
- * element should be included in the filtered list
41
- * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
42
- * to be used as `this` when executing the `callback` function. If `thisArg` is provided, it will be
43
- * passed as the `this` value to the `callback` function. If `thisArg` is
44
- * @returns The `filter` method is returning a new `PriorityQueue` object that contains the elements that pass
45
- * the filter condition specified by the `callback` function.
46
- */
47
- filter(callback, thisArg) {
48
- const filteredPriorityQueue = new PriorityQueue([], {
49
- toElementFn: this.toElementFn,
50
- comparator: this.comparator
51
- });
52
- let index = 0;
53
- for (const current of this) {
54
- if (callback.call(thisArg, current, index, this)) {
55
- filteredPriorityQueue.add(current);
56
- }
57
- index++;
58
- }
59
- return filteredPriorityQueue;
60
- }
61
- /**
62
- * Time Complexity: O(n log n)
63
- * Space Complexity: O(n)
64
- *
65
- * The `map` function creates a new heap by applying a callback function to each element of the
66
- * original heap.
67
- * @param callback - The `callback` parameter is a function that will be called for each element in
68
- * the heap. It takes three arguments: `el` (the current element), `index` (the index of the current
69
- * element), and `this` (the heap itself). The callback function should return a value of
70
- * @param comparator - The `comparator` parameter is a function that defines the order of the
71
- * elements in the heap. It takes two elements `a` and `b` as arguments and returns a negative number
72
- * if `a` should be placed before `b`, a positive number if `a` should be placed after
73
- * @param [toElementFn] - The `toElementFn` parameter is an optional function that converts the raw
74
- * element `RR` to the desired type `T`. It takes a single argument `rawElement` of type `RR` and
75
- * returns a value of type `T`. This function is used to transform the elements of the original
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. It is used to set the context or scope
78
- * in which the callback function will be executed. If `thisArg` is provided, it will be used as the
79
- * value of
80
- * @returns a new instance of the `PriorityQueue` class with the mapped elements.
81
- */
82
- map(callback, comparator, toElementFn, thisArg) {
83
- const mappedPriorityQueue = new PriorityQueue([], { comparator, toElementFn });
84
- let index = 0;
85
- for (const el of this) {
86
- mappedPriorityQueue.add(callback.call(thisArg, el, index, this));
87
- index++;
88
- }
89
- return mappedPriorityQueue;
90
- }
91
16
  }
92
17
  //# sourceMappingURL=priority-queue.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"priority-queue.js","sourceRoot":"","sources":["../../../../src/data-structures/priority-queue/priority-queue.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAE/B;;;;;;;GAOG;AACH,MAAM,OAAO,aAAgC,SAAQ,IAAU;IAC7D;;;;;;;OAOG;IACH,YAAY,WAAsC,EAAE,EAAE,OAAoC;QACxF,KAAK,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IAC3B,CAAC;IAED;;;;;OAKG;IACM,KAAK;QACZ,OAAO,IAAI,aAAa,CAAO,IAAI,EAAE,EAAE,UAAU,EAAE,IAAI,CAAC,UAAU,EAAE,WAAW,EAAE,IAAI,CAAC,WAAW,EAAE,CAAC,CAAC;IACvG,CAAC;IAED;;;;;;;;;;;;;;;OAeG;IACM,MAAM,CAAC,QAAwC,EAAE,OAAa;QACrE,MAAM,qBAAqB,GAAG,IAAI,aAAa,CAAO,EAAE,EAAE;YACxD,WAAW,EAAE,IAAI,CAAC,WAAW;YAC7B,UAAU,EAAE,IAAI,CAAC,UAAU;SAC5B,CAAC,CAAC;QACH,IAAI,KAAK,GAAG,CAAC,CAAC;QACd,KAAK,MAAM,OAAO,IAAI,IAAI,EAAE,CAAC;YAC3B,IAAI,QAAQ,CAAC,IAAI,CAAC,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,IAAI,CAAC,EAAE,CAAC;gBACjD,qBAAqB,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;YACrC,CAAC;YACD,KAAK,EAAE,CAAC;QACV,CAAC;QACD,OAAO,qBAAqB,CAAC;IAC/B,CAAC;IAED;;;;;;;;;;;;;;;;;;;;OAoBG;IACM,GAAG,CACV,QAAmC,EACnC,UAA0B,EAC1B,WAAoC,EACpC,OAAa;QAEb,MAAM,mBAAmB,GAA0B,IAAI,aAAa,CAAS,EAAE,EAAE,EAAE,UAAU,EAAE,WAAW,EAAE,CAAC,CAAC;QAC9G,IAAI,KAAK,GAAG,CAAC,CAAC;QACd,KAAK,MAAM,EAAE,IAAI,IAAI,EAAE,CAAC;YACtB,mBAAmB,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC,CAAC;YACjE,KAAK,EAAE,CAAC;QACV,CAAC;QACD,OAAO,mBAAmB,CAAC;IAC7B,CAAC;CACF"}
1
+ {"version":3,"file":"priority-queue.js","sourceRoot":"","sources":["../../../../src/data-structures/priority-queue/priority-queue.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAE/B;;GAEG;AACH,MAAM,OAAO,aAAgC,SAAQ,IAAU;IAC7D,YAAY,WAAsC,EAAE,EAAE,OAAoC;QACxF,KAAK,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IAC3B,CAAC;CACF"}