min-heap-typed 2.1.0 → 2.1.2

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 (281) hide show
  1. package/dist/cjs/index.cjs +987 -0
  2. package/dist/cjs/index.cjs.map +1 -0
  3. package/dist/esm/index.mjs +980 -0
  4. package/dist/esm/index.mjs.map +1 -0
  5. package/dist/types/data-structures/base/index.d.ts +2 -1
  6. package/dist/types/data-structures/binary-tree/avl-tree-counter.d.ts +182 -2
  7. package/dist/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +135 -2
  8. package/dist/types/data-structures/binary-tree/avl-tree.d.ts +291 -2
  9. package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +174 -1
  10. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +754 -29
  11. package/dist/types/data-structures/binary-tree/bst.d.ts +413 -12
  12. package/dist/types/data-structures/binary-tree/index.d.ts +3 -2
  13. package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +208 -3
  14. package/dist/types/data-structures/binary-tree/segment-tree.d.ts +160 -1
  15. package/dist/types/data-structures/binary-tree/tree-counter.d.ts +190 -2
  16. package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +270 -2
  17. package/dist/types/data-structures/graph/abstract-graph.d.ts +340 -14
  18. package/dist/types/data-structures/graph/directed-graph.d.ts +207 -1
  19. package/dist/types/data-structures/graph/index.d.ts +2 -1
  20. package/dist/types/data-structures/graph/map-graph.d.ts +78 -1
  21. package/dist/types/data-structures/graph/undirected-graph.d.ts +188 -1
  22. package/dist/types/data-structures/hash/hash-map.d.ts +345 -19
  23. package/dist/types/data-structures/hash/index.d.ts +0 -1
  24. package/dist/types/data-structures/heap/heap.d.ts +503 -5
  25. package/dist/types/data-structures/heap/index.d.ts +2 -0
  26. package/dist/types/data-structures/heap/max-heap.d.ts +32 -1
  27. package/dist/types/data-structures/heap/min-heap.d.ts +33 -1
  28. package/dist/types/data-structures/index.d.ts +7 -7
  29. package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +769 -2
  30. package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +451 -2
  31. package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +27 -4
  32. package/dist/types/data-structures/matrix/index.d.ts +1 -1
  33. package/dist/types/data-structures/matrix/matrix.d.ts +168 -7
  34. package/dist/types/data-structures/matrix/navigator.d.ts +54 -13
  35. package/dist/types/data-structures/priority-queue/max-priority-queue.d.ts +27 -1
  36. package/dist/types/data-structures/priority-queue/min-priority-queue.d.ts +26 -1
  37. package/dist/types/data-structures/priority-queue/priority-queue.d.ts +15 -2
  38. package/dist/types/data-structures/queue/deque.d.ts +431 -4
  39. package/dist/types/data-structures/queue/queue.d.ts +308 -4
  40. package/dist/types/data-structures/stack/stack.d.ts +306 -2
  41. package/dist/types/data-structures/tree/tree.d.ts +62 -1
  42. package/dist/types/data-structures/trie/trie.d.ts +350 -4
  43. package/dist/types/index.d.ts +13 -2
  44. package/dist/{interfaces → types/interfaces}/binary-tree.d.ts +3 -3
  45. package/dist/types/types/data-structures/base/index.d.ts +1 -0
  46. package/dist/types/types/data-structures/binary-tree/avl-tree-counter.d.ts +2 -0
  47. package/dist/types/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +2 -0
  48. package/dist/types/types/data-structures/binary-tree/avl-tree.d.ts +2 -0
  49. package/dist/types/types/data-structures/binary-tree/binary-indexed-tree.d.ts +1 -0
  50. package/dist/types/types/data-structures/binary-tree/binary-tree.d.ts +29 -0
  51. package/dist/types/types/data-structures/binary-tree/bst.d.ts +12 -0
  52. package/dist/{data-structures → types/types/data-structures}/binary-tree/index.d.ts +2 -3
  53. package/dist/types/types/data-structures/binary-tree/red-black-tree.d.ts +3 -0
  54. package/dist/types/types/data-structures/binary-tree/segment-tree.d.ts +1 -0
  55. package/dist/types/types/data-structures/binary-tree/tree-counter.d.ts +2 -0
  56. package/dist/types/types/data-structures/binary-tree/tree-multi-map.d.ts +2 -0
  57. package/dist/types/types/data-structures/graph/abstract-graph.d.ts +14 -0
  58. package/dist/types/types/data-structures/graph/directed-graph.d.ts +1 -0
  59. package/dist/{data-structures → types/types/data-structures}/graph/index.d.ts +1 -2
  60. package/dist/types/types/data-structures/graph/map-graph.d.ts +1 -0
  61. package/dist/types/types/data-structures/graph/undirected-graph.d.ts +1 -0
  62. package/dist/types/types/data-structures/hash/hash-map.d.ts +19 -0
  63. package/dist/types/types/data-structures/hash/index.d.ts +2 -0
  64. package/dist/types/types/data-structures/heap/heap.d.ts +5 -0
  65. package/dist/types/types/data-structures/heap/index.d.ts +1 -0
  66. package/dist/types/types/data-structures/heap/max-heap.d.ts +1 -0
  67. package/dist/types/types/data-structures/heap/min-heap.d.ts +1 -0
  68. package/dist/types/types/data-structures/linked-list/doubly-linked-list.d.ts +2 -0
  69. package/dist/types/types/data-structures/linked-list/singly-linked-list.d.ts +2 -0
  70. package/dist/types/types/data-structures/linked-list/skip-linked-list.d.ts +4 -0
  71. package/dist/types/types/data-structures/matrix/matrix.d.ts +7 -0
  72. package/dist/types/types/data-structures/matrix/navigator.d.ts +14 -0
  73. package/dist/types/types/data-structures/priority-queue/max-priority-queue.d.ts +1 -0
  74. package/dist/types/types/data-structures/priority-queue/min-priority-queue.d.ts +1 -0
  75. package/dist/types/types/data-structures/priority-queue/priority-queue.d.ts +2 -0
  76. package/dist/types/types/data-structures/queue/deque.d.ts +4 -0
  77. package/dist/types/types/data-structures/queue/queue.d.ts +4 -0
  78. package/dist/types/types/data-structures/stack/stack.d.ts +2 -0
  79. package/dist/types/types/data-structures/tree/tree.d.ts +1 -0
  80. package/dist/types/types/data-structures/trie/trie.d.ts +4 -0
  81. package/dist/types/types/index.d.ts +3 -0
  82. package/dist/types/types/utils/index.d.ts +2 -0
  83. package/dist/types/types/utils/utils.d.ts +22 -0
  84. package/dist/types/utils/index.d.ts +1 -1
  85. package/dist/types/utils/utils.d.ts +209 -22
  86. package/dist/umd/max-heap-typed.js +992 -0
  87. package/dist/umd/max-heap-typed.js.map +1 -0
  88. package/dist/umd/max-heap-typed.min.js +16 -0
  89. package/dist/umd/max-heap-typed.min.js.map +1 -0
  90. package/package.json +25 -5
  91. package/src/data-structures/binary-tree/avl-tree-counter.ts +8 -11
  92. package/src/data-structures/binary-tree/avl-tree-multi-map.ts +6 -11
  93. package/src/data-structures/binary-tree/avl-tree.ts +6 -8
  94. package/src/data-structures/binary-tree/binary-tree.ts +13 -15
  95. package/src/data-structures/binary-tree/bst.ts +6 -11
  96. package/src/data-structures/binary-tree/red-black-tree.ts +6 -11
  97. package/src/data-structures/binary-tree/tree-counter.ts +8 -13
  98. package/src/data-structures/binary-tree/tree-multi-map.ts +6 -11
  99. package/src/data-structures/heap/heap.ts +5 -5
  100. package/src/data-structures/linked-list/singly-linked-list.ts +2 -2
  101. package/src/interfaces/binary-tree.ts +3 -3
  102. package/tsconfig.base.json +23 -0
  103. package/tsconfig.json +8 -34
  104. package/tsconfig.test.json +8 -0
  105. package/tsconfig.types.json +15 -0
  106. package/tsup.config.js +28 -0
  107. package/tsup.node.config.js +37 -0
  108. package/dist/common/index.js +0 -28
  109. package/dist/constants/index.js +0 -8
  110. package/dist/data-structures/base/index.d.ts +0 -2
  111. package/dist/data-structures/base/index.js +0 -18
  112. package/dist/data-structures/base/iterable-element-base.js +0 -243
  113. package/dist/data-structures/base/iterable-entry-base.js +0 -183
  114. package/dist/data-structures/base/linear-base.js +0 -415
  115. package/dist/data-structures/binary-tree/avl-tree-counter.d.ts +0 -182
  116. package/dist/data-structures/binary-tree/avl-tree-counter.js +0 -374
  117. package/dist/data-structures/binary-tree/avl-tree-multi-map.d.ts +0 -135
  118. package/dist/data-structures/binary-tree/avl-tree-multi-map.js +0 -250
  119. package/dist/data-structures/binary-tree/avl-tree.d.ts +0 -291
  120. package/dist/data-structures/binary-tree/avl-tree.js +0 -611
  121. package/dist/data-structures/binary-tree/binary-indexed-tree.d.ts +0 -174
  122. package/dist/data-structures/binary-tree/binary-indexed-tree.js +0 -294
  123. package/dist/data-structures/binary-tree/binary-tree.d.ts +0 -754
  124. package/dist/data-structures/binary-tree/binary-tree.js +0 -1925
  125. package/dist/data-structures/binary-tree/bst.d.ts +0 -413
  126. package/dist/data-structures/binary-tree/bst.js +0 -903
  127. package/dist/data-structures/binary-tree/index.js +0 -26
  128. package/dist/data-structures/binary-tree/red-black-tree.d.ts +0 -208
  129. package/dist/data-structures/binary-tree/red-black-tree.js +0 -546
  130. package/dist/data-structures/binary-tree/segment-tree.d.ts +0 -160
  131. package/dist/data-structures/binary-tree/segment-tree.js +0 -297
  132. package/dist/data-structures/binary-tree/tree-counter.d.ts +0 -190
  133. package/dist/data-structures/binary-tree/tree-counter.js +0 -413
  134. package/dist/data-structures/binary-tree/tree-multi-map.d.ts +0 -270
  135. package/dist/data-structures/binary-tree/tree-multi-map.js +0 -384
  136. package/dist/data-structures/graph/abstract-graph.d.ts +0 -340
  137. package/dist/data-structures/graph/abstract-graph.js +0 -896
  138. package/dist/data-structures/graph/directed-graph.d.ts +0 -207
  139. package/dist/data-structures/graph/directed-graph.js +0 -525
  140. package/dist/data-structures/graph/index.js +0 -20
  141. package/dist/data-structures/graph/map-graph.d.ts +0 -78
  142. package/dist/data-structures/graph/map-graph.js +0 -107
  143. package/dist/data-structures/graph/undirected-graph.d.ts +0 -188
  144. package/dist/data-structures/graph/undirected-graph.js +0 -424
  145. package/dist/data-structures/hash/hash-map.d.ts +0 -345
  146. package/dist/data-structures/hash/hash-map.js +0 -692
  147. package/dist/data-structures/hash/index.d.ts +0 -1
  148. package/dist/data-structures/hash/index.js +0 -17
  149. package/dist/data-structures/heap/heap.d.ts +0 -503
  150. package/dist/data-structures/heap/heap.js +0 -901
  151. package/dist/data-structures/heap/index.d.ts +0 -3
  152. package/dist/data-structures/heap/index.js +0 -19
  153. package/dist/data-structures/heap/max-heap.d.ts +0 -32
  154. package/dist/data-structures/heap/max-heap.js +0 -40
  155. package/dist/data-structures/heap/min-heap.d.ts +0 -33
  156. package/dist/data-structures/heap/min-heap.js +0 -31
  157. package/dist/data-structures/index.js +0 -28
  158. package/dist/data-structures/linked-list/doubly-linked-list.d.ts +0 -769
  159. package/dist/data-structures/linked-list/doubly-linked-list.js +0 -1111
  160. package/dist/data-structures/linked-list/index.js +0 -19
  161. package/dist/data-structures/linked-list/singly-linked-list.d.ts +0 -451
  162. package/dist/data-structures/linked-list/singly-linked-list.js +0 -850
  163. package/dist/data-structures/linked-list/skip-linked-list.d.ts +0 -27
  164. package/dist/data-structures/linked-list/skip-linked-list.js +0 -144
  165. package/dist/data-structures/matrix/index.js +0 -18
  166. package/dist/data-structures/matrix/matrix.d.ts +0 -168
  167. package/dist/data-structures/matrix/matrix.js +0 -448
  168. package/dist/data-structures/matrix/navigator.d.ts +0 -55
  169. package/dist/data-structures/matrix/navigator.js +0 -111
  170. package/dist/data-structures/priority-queue/index.js +0 -19
  171. package/dist/data-structures/priority-queue/max-priority-queue.d.ts +0 -27
  172. package/dist/data-structures/priority-queue/max-priority-queue.js +0 -34
  173. package/dist/data-structures/priority-queue/min-priority-queue.d.ts +0 -26
  174. package/dist/data-structures/priority-queue/min-priority-queue.js +0 -24
  175. package/dist/data-structures/priority-queue/priority-queue.d.ts +0 -15
  176. package/dist/data-structures/priority-queue/priority-queue.js +0 -20
  177. package/dist/data-structures/queue/deque.d.ts +0 -431
  178. package/dist/data-structures/queue/deque.js +0 -879
  179. package/dist/data-structures/queue/index.js +0 -18
  180. package/dist/data-structures/queue/queue.d.ts +0 -308
  181. package/dist/data-structures/queue/queue.js +0 -473
  182. package/dist/data-structures/stack/index.js +0 -17
  183. package/dist/data-structures/stack/stack.d.ts +0 -306
  184. package/dist/data-structures/stack/stack.js +0 -401
  185. package/dist/data-structures/tree/index.js +0 -17
  186. package/dist/data-structures/tree/tree.d.ts +0 -62
  187. package/dist/data-structures/tree/tree.js +0 -107
  188. package/dist/data-structures/trie/index.js +0 -17
  189. package/dist/data-structures/trie/trie.d.ts +0 -350
  190. package/dist/data-structures/trie/trie.js +0 -610
  191. package/dist/index.d.ts +0 -14
  192. package/dist/index.js +0 -30
  193. package/dist/interfaces/binary-tree.js +0 -2
  194. package/dist/interfaces/doubly-linked-list.js +0 -2
  195. package/dist/interfaces/graph.js +0 -2
  196. package/dist/interfaces/heap.js +0 -2
  197. package/dist/interfaces/index.js +0 -24
  198. package/dist/interfaces/navigator.js +0 -2
  199. package/dist/interfaces/priority-queue.js +0 -2
  200. package/dist/interfaces/segment-tree.js +0 -2
  201. package/dist/interfaces/singly-linked-list.js +0 -2
  202. package/dist/types/common.js +0 -2
  203. package/dist/types/data-structures/base/base.js +0 -2
  204. package/dist/types/data-structures/base/index.js +0 -17
  205. package/dist/types/data-structures/binary-tree/avl-tree-counter.js +0 -2
  206. package/dist/types/data-structures/binary-tree/avl-tree-multi-map.js +0 -2
  207. package/dist/types/data-structures/binary-tree/avl-tree.js +0 -2
  208. package/dist/types/data-structures/binary-tree/binary-indexed-tree.js +0 -2
  209. package/dist/types/data-structures/binary-tree/binary-tree.js +0 -2
  210. package/dist/types/data-structures/binary-tree/bst.js +0 -2
  211. package/dist/types/data-structures/binary-tree/index.js +0 -25
  212. package/dist/types/data-structures/binary-tree/red-black-tree.js +0 -2
  213. package/dist/types/data-structures/binary-tree/segment-tree.js +0 -2
  214. package/dist/types/data-structures/binary-tree/tree-counter.js +0 -2
  215. package/dist/types/data-structures/binary-tree/tree-multi-map.js +0 -2
  216. package/dist/types/data-structures/graph/abstract-graph.js +0 -2
  217. package/dist/types/data-structures/graph/directed-graph.js +0 -2
  218. package/dist/types/data-structures/graph/index.js +0 -19
  219. package/dist/types/data-structures/graph/map-graph.js +0 -2
  220. package/dist/types/data-structures/graph/undirected-graph.js +0 -2
  221. package/dist/types/data-structures/hash/hash-map.js +0 -2
  222. package/dist/types/data-structures/hash/index.js +0 -17
  223. package/dist/types/data-structures/heap/heap.js +0 -2
  224. package/dist/types/data-structures/heap/index.js +0 -17
  225. package/dist/types/data-structures/heap/max-heap.js +0 -2
  226. package/dist/types/data-structures/heap/min-heap.js +0 -2
  227. package/dist/types/data-structures/index.js +0 -28
  228. package/dist/types/data-structures/linked-list/doubly-linked-list.js +0 -2
  229. package/dist/types/data-structures/linked-list/index.js +0 -19
  230. package/dist/types/data-structures/linked-list/singly-linked-list.js +0 -2
  231. package/dist/types/data-structures/linked-list/skip-linked-list.js +0 -2
  232. package/dist/types/data-structures/matrix/index.js +0 -18
  233. package/dist/types/data-structures/matrix/matrix.js +0 -2
  234. package/dist/types/data-structures/matrix/navigator.js +0 -2
  235. package/dist/types/data-structures/priority-queue/index.js +0 -19
  236. package/dist/types/data-structures/priority-queue/max-priority-queue.js +0 -2
  237. package/dist/types/data-structures/priority-queue/min-priority-queue.js +0 -2
  238. package/dist/types/data-structures/priority-queue/priority-queue.js +0 -2
  239. package/dist/types/data-structures/queue/deque.js +0 -2
  240. package/dist/types/data-structures/queue/index.js +0 -18
  241. package/dist/types/data-structures/queue/queue.js +0 -2
  242. package/dist/types/data-structures/stack/index.js +0 -17
  243. package/dist/types/data-structures/stack/stack.js +0 -2
  244. package/dist/types/data-structures/tree/index.js +0 -17
  245. package/dist/types/data-structures/tree/tree.js +0 -2
  246. package/dist/types/data-structures/trie/index.js +0 -17
  247. package/dist/types/data-structures/trie/trie.js +0 -2
  248. package/dist/types/index.js +0 -19
  249. package/dist/types/utils/index.js +0 -18
  250. package/dist/types/utils/utils.js +0 -2
  251. package/dist/types/utils/validate-type.js +0 -2
  252. package/dist/utils/index.d.ts +0 -2
  253. package/dist/utils/index.js +0 -18
  254. package/dist/utils/number.js +0 -24
  255. package/dist/utils/utils.d.ts +0 -209
  256. package/dist/utils/utils.js +0 -353
  257. package/dist/{common → types/common}/index.d.ts +0 -0
  258. package/dist/{constants → types/constants}/index.d.ts +0 -0
  259. package/dist/{data-structures → types/data-structures}/base/iterable-element-base.d.ts +0 -0
  260. package/dist/{data-structures → types/data-structures}/base/iterable-entry-base.d.ts +0 -0
  261. package/dist/{data-structures → types/data-structures}/base/linear-base.d.ts +0 -0
  262. package/dist/{interfaces → types/interfaces}/doubly-linked-list.d.ts +0 -0
  263. package/dist/{interfaces → types/interfaces}/graph.d.ts +0 -0
  264. package/dist/{interfaces → types/interfaces}/heap.d.ts +0 -0
  265. package/dist/{interfaces → types/interfaces}/index.d.ts +0 -0
  266. package/dist/{interfaces → types/interfaces}/navigator.d.ts +0 -0
  267. package/dist/{interfaces → types/interfaces}/priority-queue.d.ts +0 -0
  268. package/dist/{interfaces → types/interfaces}/segment-tree.d.ts +0 -0
  269. package/dist/{interfaces → types/interfaces}/singly-linked-list.d.ts +0 -0
  270. package/dist/types/{common.d.ts → types/common.d.ts} +0 -0
  271. package/dist/types/{data-structures → types/data-structures}/base/base.d.ts +0 -0
  272. package/dist/{data-structures → types/types/data-structures}/index.d.ts +7 -7
  273. package/dist/{data-structures → types/types/data-structures}/linked-list/index.d.ts +0 -0
  274. package/dist/{data-structures → types/types/data-structures}/matrix/index.d.ts +1 -1
  275. /package/dist/{data-structures → types/types/data-structures}/priority-queue/index.d.ts +0 -0
  276. /package/dist/{data-structures → types/types/data-structures}/queue/index.d.ts +0 -0
  277. /package/dist/{data-structures → types/types/data-structures}/stack/index.d.ts +0 -0
  278. /package/dist/{data-structures → types/types/data-structures}/tree/index.d.ts +0 -0
  279. /package/dist/{data-structures → types/types/data-structures}/trie/index.d.ts +0 -0
  280. /package/dist/types/{utils → types/utils}/validate-type.d.ts +0 -0
  281. /package/dist/{utils → types/utils}/number.d.ts +0 -0
@@ -0,0 +1,980 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
4
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
5
+
6
+ // src/data-structures/base/iterable-element-base.ts
7
+ var _IterableElementBase = class _IterableElementBase {
8
+ /**
9
+ * Create a new iterable base.
10
+ *
11
+ * @param options Optional behavior overrides. When provided, a `toElementFn`
12
+ * is used to convert a raw element (`R`) into a public element (`E`).
13
+ *
14
+ * @remarks
15
+ * Time O(1), Space O(1).
16
+ */
17
+ constructor(options) {
18
+ /**
19
+ * The converter used to transform a raw element (`R`) into a public element (`E`).
20
+ *
21
+ * @remarks
22
+ * Time O(1), Space O(1).
23
+ */
24
+ __publicField(this, "_toElementFn");
25
+ if (options) {
26
+ const { toElementFn } = options;
27
+ if (typeof toElementFn === "function") this._toElementFn = toElementFn;
28
+ else if (toElementFn) throw new TypeError("toElementFn must be a function type");
29
+ }
30
+ }
31
+ /**
32
+ * Exposes the current `toElementFn`, if configured.
33
+ *
34
+ * @returns The converter function or `undefined` when not set.
35
+ * @remarks
36
+ * Time O(1), Space O(1).
37
+ */
38
+ get toElementFn() {
39
+ return this._toElementFn;
40
+ }
41
+ /**
42
+ * Returns an iterator over the structure's elements.
43
+ *
44
+ * @param args Optional iterator arguments forwarded to the internal iterator.
45
+ * @returns An `IterableIterator<E>` that yields the elements in traversal order.
46
+ *
47
+ * @remarks
48
+ * Producing the iterator is O(1); consuming the entire iterator is Time O(n) with O(1) extra space.
49
+ */
50
+ *[Symbol.iterator](...args) {
51
+ yield* this._getIterator(...args);
52
+ }
53
+ /**
54
+ * Returns an iterator over the values (alias of the default iterator).
55
+ *
56
+ * @returns An `IterableIterator<E>` over all elements.
57
+ * @remarks
58
+ * Creating the iterator is O(1); full iteration is Time O(n), Space O(1).
59
+ */
60
+ *values() {
61
+ for (const item of this) yield item;
62
+ }
63
+ /**
64
+ * Tests whether all elements satisfy the predicate.
65
+ *
66
+ * @template TReturn
67
+ * @param predicate Function invoked for each element with signature `(value, index, self)`.
68
+ * @param thisArg Optional `this` binding for the predicate.
69
+ * @returns `true` if every element passes; otherwise `false`.
70
+ *
71
+ * @remarks
72
+ * Time O(n) in the worst case; may exit early when the first failure is found. Space O(1).
73
+ */
74
+ every(predicate, thisArg) {
75
+ let index = 0;
76
+ for (const item of this) {
77
+ if (thisArg === void 0) {
78
+ if (!predicate(item, index++, this)) return false;
79
+ } else {
80
+ const fn = predicate;
81
+ if (!fn.call(thisArg, item, index++, this)) return false;
82
+ }
83
+ }
84
+ return true;
85
+ }
86
+ /**
87
+ * Tests whether at least one element satisfies the predicate.
88
+ *
89
+ * @param predicate Function invoked for each element with signature `(value, index, self)`.
90
+ * @param thisArg Optional `this` binding for the predicate.
91
+ * @returns `true` if any element passes; otherwise `false`.
92
+ *
93
+ * @remarks
94
+ * Time O(n) in the worst case; may exit early on first success. Space O(1).
95
+ */
96
+ some(predicate, thisArg) {
97
+ let index = 0;
98
+ for (const item of this) {
99
+ if (thisArg === void 0) {
100
+ if (predicate(item, index++, this)) return true;
101
+ } else {
102
+ const fn = predicate;
103
+ if (fn.call(thisArg, item, index++, this)) return true;
104
+ }
105
+ }
106
+ return false;
107
+ }
108
+ /**
109
+ * Invokes a callback for each element in iteration order.
110
+ *
111
+ * @param callbackfn Function invoked per element with signature `(value, index, self)`.
112
+ * @param thisArg Optional `this` binding for the callback.
113
+ * @returns `void`.
114
+ *
115
+ * @remarks
116
+ * Time O(n), Space O(1).
117
+ */
118
+ forEach(callbackfn, thisArg) {
119
+ let index = 0;
120
+ for (const item of this) {
121
+ if (thisArg === void 0) {
122
+ callbackfn(item, index++, this);
123
+ } else {
124
+ const fn = callbackfn;
125
+ fn.call(thisArg, item, index++, this);
126
+ }
127
+ }
128
+ }
129
+ // Implementation signature
130
+ find(predicate, thisArg) {
131
+ let index = 0;
132
+ for (const item of this) {
133
+ if (thisArg === void 0) {
134
+ if (predicate(item, index++, this)) return item;
135
+ } else {
136
+ const fn = predicate;
137
+ if (fn.call(thisArg, item, index++, this)) return item;
138
+ }
139
+ }
140
+ return;
141
+ }
142
+ /**
143
+ * Checks whether a strictly-equal element exists in the structure.
144
+ *
145
+ * @param element The element to test with `===` equality.
146
+ * @returns `true` if an equal element is found; otherwise `false`.
147
+ *
148
+ * @remarks
149
+ * Time O(n) in the worst case. Space O(1).
150
+ */
151
+ has(element) {
152
+ for (const ele of this) if (ele === element) return true;
153
+ return false;
154
+ }
155
+ /**
156
+ * Reduces all elements to a single accumulated value.
157
+ *
158
+ * @overload
159
+ * @param callbackfn Reducer of signature `(acc, value, index, self) => nextAcc`. The first element is used as the initial accumulator.
160
+ * @returns The final accumulated value typed as `E`.
161
+ *
162
+ * @overload
163
+ * @param callbackfn Reducer of signature `(acc, value, index, self) => nextAcc`.
164
+ * @param initialValue The initial accumulator value of type `E`.
165
+ * @returns The final accumulated value typed as `E`.
166
+ *
167
+ * @overload
168
+ * @template U The accumulator type when it differs from `E`.
169
+ * @param callbackfn Reducer of signature `(acc: U, value, index, self) => U`.
170
+ * @param initialValue The initial accumulator value of type `U`.
171
+ * @returns The final accumulated value typed as `U`.
172
+ *
173
+ * @remarks
174
+ * Time O(n), Space O(1). Throws if called on an empty structure without `initialValue`.
175
+ */
176
+ reduce(callbackfn, initialValue) {
177
+ let index = 0;
178
+ const iter = this[Symbol.iterator]();
179
+ let acc;
180
+ if (arguments.length >= 2) {
181
+ acc = initialValue;
182
+ } else {
183
+ const first = iter.next();
184
+ if (first.done) throw new TypeError("Reduce of empty structure with no initial value");
185
+ acc = first.value;
186
+ index = 1;
187
+ }
188
+ for (const value of iter) {
189
+ acc = callbackfn(acc, value, index++, this);
190
+ }
191
+ return acc;
192
+ }
193
+ /**
194
+ * Materializes the elements into a new array.
195
+ *
196
+ * @returns A shallow array copy of the iteration order.
197
+ * @remarks
198
+ * Time O(n), Space O(n).
199
+ */
200
+ toArray() {
201
+ return [...this];
202
+ }
203
+ /**
204
+ * Returns a representation of the structure suitable for quick visualization.
205
+ * Defaults to an array of elements; subclasses may override to provide richer visuals.
206
+ *
207
+ * @returns A visual representation (array by default).
208
+ * @remarks
209
+ * Time O(n), Space O(n).
210
+ */
211
+ toVisual() {
212
+ return [...this];
213
+ }
214
+ /**
215
+ * Prints `toVisual()` to the console. Intended for quick debugging.
216
+ *
217
+ * @returns `void`.
218
+ * @remarks
219
+ * Time O(n) due to materialization, Space O(n) for the intermediate representation.
220
+ */
221
+ print() {
222
+ console.log(this.toVisual());
223
+ }
224
+ };
225
+ __name(_IterableElementBase, "IterableElementBase");
226
+ var IterableElementBase = _IterableElementBase;
227
+
228
+ // src/data-structures/heap/heap.ts
229
+ var _Heap = class _Heap extends IterableElementBase {
230
+ /**
231
+ * Create a Heap and optionally bulk-insert elements.
232
+ * @remarks Time O(N), Space O(N)
233
+ * @param [elements] - Iterable of elements (or raw values if toElementFn is set).
234
+ * @param [options] - Options such as comparator and toElementFn.
235
+ * @returns New Heap instance.
236
+ */
237
+ constructor(elements = [], options) {
238
+ super(options);
239
+ __publicField(this, "_equals", Object.is);
240
+ __publicField(this, "_elements", []);
241
+ __publicField(this, "_DEFAULT_COMPARATOR", /* @__PURE__ */ __name((a, b) => {
242
+ if (typeof a === "object" || typeof b === "object") {
243
+ throw TypeError("When comparing object types, define a custom comparator in options.");
244
+ }
245
+ if (a > b) return 1;
246
+ if (a < b) return -1;
247
+ return 0;
248
+ }, "_DEFAULT_COMPARATOR"));
249
+ __publicField(this, "_comparator", this._DEFAULT_COMPARATOR);
250
+ if (options) {
251
+ const { comparator } = options;
252
+ if (comparator) this._comparator = comparator;
253
+ }
254
+ this.addMany(elements);
255
+ }
256
+ /**
257
+ * Get the backing array of the heap.
258
+ * @remarks Time O(1), Space O(1)
259
+ * @returns Internal elements array.
260
+ */
261
+ get elements() {
262
+ return this._elements;
263
+ }
264
+ /**
265
+ * Get the number of elements.
266
+ * @remarks Time O(1), Space O(1)
267
+ * @returns Heap size.
268
+ */
269
+ get size() {
270
+ return this.elements.length;
271
+ }
272
+ /**
273
+ * Get the last leaf element.
274
+ * @remarks Time O(1), Space O(1)
275
+ * @returns Last element or undefined.
276
+ */
277
+ get leaf() {
278
+ var _a;
279
+ return (_a = this.elements[this.size - 1]) != null ? _a : void 0;
280
+ }
281
+ /**
282
+ * Create a heap of the same class from an iterable.
283
+ * @remarks Time O(N), Space O(N)
284
+ * @template T
285
+ * @template R
286
+ * @template S
287
+ * @param [elements] - Iterable of elements or raw records.
288
+ * @param [options] - Heap options including comparator.
289
+ * @returns A new heap instance of this class.
290
+ */
291
+ static from(elements, options) {
292
+ return new this(elements, options);
293
+ }
294
+ /**
295
+ * Build a Heap from an iterable in linear time given a comparator.
296
+ * @remarks Time O(N), Space O(N)
297
+ * @template EE
298
+ * @template RR
299
+ * @param elements - Iterable of elements.
300
+ * @param options - Heap options including comparator.
301
+ * @returns A new Heap built from elements.
302
+ */
303
+ static heapify(elements, options) {
304
+ return new _Heap(elements, options);
305
+ }
306
+ /**
307
+ * Insert an element.
308
+ * @remarks Time O(1) amortized, Space O(1)
309
+ * @param element - Element to insert.
310
+ * @returns True.
311
+ */
312
+ add(element) {
313
+ this._elements.push(element);
314
+ return this._bubbleUp(this.elements.length - 1);
315
+ }
316
+ /**
317
+ * Insert many elements from an iterable.
318
+ * @remarks Time O(N log N), Space O(1)
319
+ * @param elements - Iterable of elements or raw values.
320
+ * @returns Array of per-element success flags.
321
+ */
322
+ addMany(elements) {
323
+ const flags = [];
324
+ for (const el of elements) {
325
+ if (this.toElementFn) {
326
+ const ok = this.add(this.toElementFn(el));
327
+ flags.push(ok);
328
+ } else {
329
+ const ok = this.add(el);
330
+ flags.push(ok);
331
+ }
332
+ }
333
+ return flags;
334
+ }
335
+ /**
336
+ * Remove and return the top element.
337
+ * @remarks Time O(log N), Space O(1)
338
+ * @returns Top element or undefined.
339
+ */
340
+ poll() {
341
+ if (this.elements.length === 0) return;
342
+ const value = this.elements[0];
343
+ const last = this.elements.pop();
344
+ if (this.elements.length) {
345
+ this.elements[0] = last;
346
+ this._sinkDown(0, this.elements.length >> 1);
347
+ }
348
+ return value;
349
+ }
350
+ /**
351
+ * Get the current top element without removing it.
352
+ * @remarks Time O(1), Space O(1)
353
+ * @returns Top element or undefined.
354
+ */
355
+ peek() {
356
+ return this.elements[0];
357
+ }
358
+ /**
359
+ * Check whether the heap is empty.
360
+ * @remarks Time O(1), Space O(1)
361
+ * @returns True if size is 0.
362
+ */
363
+ isEmpty() {
364
+ return this.size === 0;
365
+ }
366
+ /**
367
+ * Remove all elements.
368
+ * @remarks Time O(1), Space O(1)
369
+ * @returns void
370
+ */
371
+ clear() {
372
+ this._elements = [];
373
+ }
374
+ /**
375
+ * Replace the backing array and rebuild the heap.
376
+ * @remarks Time O(N), Space O(N)
377
+ * @param elements - Iterable used to refill the heap.
378
+ * @returns Array of per-node results from fixing steps.
379
+ */
380
+ refill(elements) {
381
+ this._elements = Array.from(elements);
382
+ return this.fix();
383
+ }
384
+ /**
385
+ * Check if an equal element exists in the heap.
386
+ * @remarks Time O(N), Space O(1)
387
+ * @param element - Element to search for.
388
+ * @returns True if found.
389
+ */
390
+ has(element) {
391
+ for (const el of this.elements) if (this._equals(el, element)) return true;
392
+ return false;
393
+ }
394
+ /**
395
+ * Delete one occurrence of an element.
396
+ * @remarks Time O(N), Space O(1)
397
+ * @param element - Element to delete.
398
+ * @returns True if an element was removed.
399
+ */
400
+ delete(element) {
401
+ let index = -1;
402
+ for (let i = 0; i < this.elements.length; i++) {
403
+ if (this._equals(this.elements[i], element)) {
404
+ index = i;
405
+ break;
406
+ }
407
+ }
408
+ if (index < 0) return false;
409
+ if (index === 0) {
410
+ this.poll();
411
+ } else if (index === this.elements.length - 1) {
412
+ this.elements.pop();
413
+ } else {
414
+ this.elements.splice(index, 1, this.elements.pop());
415
+ this._bubbleUp(index);
416
+ this._sinkDown(index, this.elements.length >> 1);
417
+ }
418
+ return true;
419
+ }
420
+ /**
421
+ * Delete the first element that matches a predicate.
422
+ * @remarks Time O(N), Space O(1)
423
+ * @param predicate - Function (element, index, heap) → boolean.
424
+ * @returns True if an element was removed.
425
+ */
426
+ deleteBy(predicate) {
427
+ let idx = -1;
428
+ for (let i = 0; i < this.elements.length; i++) {
429
+ if (predicate(this.elements[i], i, this)) {
430
+ idx = i;
431
+ break;
432
+ }
433
+ }
434
+ if (idx < 0) return false;
435
+ if (idx === 0) {
436
+ this.poll();
437
+ } else if (idx === this.elements.length - 1) {
438
+ this.elements.pop();
439
+ } else {
440
+ this.elements.splice(idx, 1, this.elements.pop());
441
+ this._bubbleUp(idx);
442
+ this._sinkDown(idx, this.elements.length >> 1);
443
+ }
444
+ return true;
445
+ }
446
+ /**
447
+ * Set the equality comparator used by has/delete operations.
448
+ * @remarks Time O(1), Space O(1)
449
+ * @param equals - Equality predicate (a, b) → boolean.
450
+ * @returns This heap.
451
+ */
452
+ setEquality(equals) {
453
+ this._equals = equals;
454
+ return this;
455
+ }
456
+ /**
457
+ * Traverse the binary heap as a complete binary tree and collect elements.
458
+ * @remarks Time O(N), Space O(H)
459
+ * @param [order] - Traversal order: 'PRE' | 'IN' | 'POST'.
460
+ * @returns Array of visited elements.
461
+ */
462
+ dfs(order = "PRE") {
463
+ const result = [];
464
+ const _dfs = /* @__PURE__ */ __name((index) => {
465
+ const left = 2 * index + 1, right = left + 1;
466
+ if (index < this.size) {
467
+ if (order === "IN") {
468
+ _dfs(left);
469
+ result.push(this.elements[index]);
470
+ _dfs(right);
471
+ } else if (order === "PRE") {
472
+ result.push(this.elements[index]);
473
+ _dfs(left);
474
+ _dfs(right);
475
+ } else if (order === "POST") {
476
+ _dfs(left);
477
+ _dfs(right);
478
+ result.push(this.elements[index]);
479
+ }
480
+ }
481
+ }, "_dfs");
482
+ _dfs(0);
483
+ return result;
484
+ }
485
+ /**
486
+ * Restore heap order bottom-up (heapify in-place).
487
+ * @remarks Time O(N), Space O(1)
488
+ * @returns Array of per-node results from fixing steps.
489
+ */
490
+ fix() {
491
+ const results = [];
492
+ for (let i = Math.floor(this.size / 2) - 1; i >= 0; i--) {
493
+ results.push(this._sinkDown(i, this.elements.length >> 1));
494
+ }
495
+ return results;
496
+ }
497
+ /**
498
+ * Return all elements in ascending order by repeatedly polling.
499
+ * @remarks Time O(N log N), Space O(N)
500
+ * @returns Sorted array of elements.
501
+ */
502
+ sort() {
503
+ const visited = [];
504
+ const cloned = this._createInstance();
505
+ for (const x of this.elements) cloned.add(x);
506
+ while (!cloned.isEmpty()) {
507
+ const top = cloned.poll();
508
+ if (top !== void 0) visited.push(top);
509
+ }
510
+ return visited;
511
+ }
512
+ /**
513
+ * Deep clone this heap.
514
+ * @remarks Time O(N), Space O(N)
515
+ * @returns A new heap with the same elements.
516
+ */
517
+ clone() {
518
+ const next = this._createInstance();
519
+ for (const x of this.elements) next.add(x);
520
+ return next;
521
+ }
522
+ /**
523
+ * Filter elements into a new heap of the same class.
524
+ * @remarks Time O(N log N), Space O(N)
525
+ * @param callback - Predicate (element, index, heap) → boolean to keep element.
526
+ * @param [thisArg] - Value for `this` inside the callback.
527
+ * @returns A new heap with the kept elements.
528
+ */
529
+ filter(callback, thisArg) {
530
+ const out = this._createInstance();
531
+ let i = 0;
532
+ for (const x of this) {
533
+ if (thisArg === void 0 ? callback(x, i++, this) : callback.call(thisArg, x, i++, this)) {
534
+ out.add(x);
535
+ } else {
536
+ i++;
537
+ }
538
+ }
539
+ return out;
540
+ }
541
+ /**
542
+ * Map elements into a new heap of possibly different element type.
543
+ * @remarks Time O(N log N), Space O(N)
544
+ * @template EM
545
+ * @template RM
546
+ * @param callback - Mapping function (element, index, heap) → newElement.
547
+ * @param options - Options for the output heap, including comparator for EM.
548
+ * @param [thisArg] - Value for `this` inside the callback.
549
+ * @returns A new heap with mapped elements.
550
+ */
551
+ map(callback, options, thisArg) {
552
+ const { comparator, toElementFn, ...rest } = options != null ? options : {};
553
+ if (!comparator) throw new TypeError("Heap.map requires options.comparator for EM");
554
+ const out = this._createLike([], { ...rest, comparator, toElementFn });
555
+ let i = 0;
556
+ for (const x of this) {
557
+ const v = thisArg === void 0 ? callback(x, i++, this) : callback.call(thisArg, x, i++, this);
558
+ out.add(v);
559
+ }
560
+ return out;
561
+ }
562
+ /**
563
+ * Map elements into a new heap of the same element type.
564
+ * @remarks Time O(N log N), Space O(N)
565
+ * @param callback - Mapping function (element, index, heap) → element.
566
+ * @param [thisArg] - Value for `this` inside the callback.
567
+ * @returns A new heap with mapped elements.
568
+ */
569
+ mapSame(callback, thisArg) {
570
+ const out = this._createInstance();
571
+ let i = 0;
572
+ for (const x of this) {
573
+ const v = thisArg === void 0 ? callback(x, i++, this) : callback.call(thisArg, x, i++, this);
574
+ out.add(v);
575
+ }
576
+ return out;
577
+ }
578
+ /**
579
+ * Get the comparator used to order elements.
580
+ * @remarks Time O(1), Space O(1)
581
+ * @returns Comparator function.
582
+ */
583
+ /**
584
+ * Get the comparator used to order elements.
585
+ * @remarks Time O(1), Space O(1)
586
+ * @returns Comparator function.
587
+ */
588
+ get comparator() {
589
+ return this._comparator;
590
+ }
591
+ *_getIterator() {
592
+ for (const element of this.elements) yield element;
593
+ }
594
+ _bubbleUp(index) {
595
+ const element = this.elements[index];
596
+ while (index > 0) {
597
+ const parent = index - 1 >> 1;
598
+ const parentItem = this.elements[parent];
599
+ if (this.comparator(parentItem, element) <= 0) break;
600
+ this.elements[index] = parentItem;
601
+ index = parent;
602
+ }
603
+ this.elements[index] = element;
604
+ return true;
605
+ }
606
+ _sinkDown(index, halfLength) {
607
+ const element = this.elements[index];
608
+ while (index < halfLength) {
609
+ let left = index << 1 | 1;
610
+ const right = left + 1;
611
+ let minItem = this.elements[left];
612
+ if (right < this.elements.length && this.comparator(minItem, this.elements[right]) > 0) {
613
+ left = right;
614
+ minItem = this.elements[right];
615
+ }
616
+ if (this.comparator(minItem, element) >= 0) break;
617
+ this.elements[index] = minItem;
618
+ index = left;
619
+ }
620
+ this.elements[index] = element;
621
+ return true;
622
+ }
623
+ /**
624
+ * (Protected) Create an empty instance of the same concrete class.
625
+ * @remarks Time O(1), Space O(1)
626
+ * @param [options] - Options to override comparator or toElementFn.
627
+ * @returns A like-kind empty heap instance.
628
+ */
629
+ _createInstance(options) {
630
+ const Ctor = this.constructor;
631
+ const next = new Ctor([], { comparator: this.comparator, toElementFn: this.toElementFn, ...options != null ? options : {} });
632
+ return next;
633
+ }
634
+ /**
635
+ * (Protected) Create a like-kind instance seeded by elements.
636
+ * @remarks Time O(N log N), Space O(N)
637
+ * @template EM
638
+ * @template RM
639
+ * @param [elements] - Iterable of elements or raw values to seed.
640
+ * @param [options] - Options forwarded to the constructor.
641
+ * @returns A like-kind heap instance.
642
+ */
643
+ _createLike(elements = [], options) {
644
+ const Ctor = this.constructor;
645
+ return new Ctor(elements, options);
646
+ }
647
+ /**
648
+ * (Protected) Spawn an empty like-kind heap instance.
649
+ * @remarks Time O(1), Space O(1)
650
+ * @template EM
651
+ * @template RM
652
+ * @param [options] - Options forwarded to the constructor.
653
+ * @returns An empty like-kind heap instance.
654
+ */
655
+ _spawnLike(options) {
656
+ return this._createLike([], options);
657
+ }
658
+ };
659
+ __name(_Heap, "Heap");
660
+ var Heap = _Heap;
661
+ var _FibonacciHeapNode = class _FibonacciHeapNode {
662
+ constructor(element, degree = 0) {
663
+ __publicField(this, "element");
664
+ __publicField(this, "degree");
665
+ __publicField(this, "left");
666
+ __publicField(this, "right");
667
+ __publicField(this, "child");
668
+ __publicField(this, "parent");
669
+ __publicField(this, "marked");
670
+ this.element = element;
671
+ this.degree = degree;
672
+ this.marked = false;
673
+ }
674
+ };
675
+ __name(_FibonacciHeapNode, "FibonacciHeapNode");
676
+ var FibonacciHeapNode = _FibonacciHeapNode;
677
+ var _FibonacciHeap = class _FibonacciHeap {
678
+ /**
679
+ * Create a FibonacciHeap.
680
+ * @remarks Time O(1), Space O(1)
681
+ * @param [comparator] - Comparator to order elements (min-heap by default).
682
+ * @returns New FibonacciHeap instance.
683
+ */
684
+ constructor(comparator) {
685
+ __publicField(this, "_root");
686
+ __publicField(this, "_size", 0);
687
+ __publicField(this, "_min");
688
+ __publicField(this, "_comparator");
689
+ this.clear();
690
+ this._comparator = comparator || this._defaultComparator;
691
+ if (typeof this.comparator !== "function") throw new Error("FibonacciHeap: comparator must be a function.");
692
+ }
693
+ /**
694
+ * Get the circular root list head.
695
+ * @remarks Time O(1), Space O(1)
696
+ * @returns Root node or undefined.
697
+ */
698
+ get root() {
699
+ return this._root;
700
+ }
701
+ get size() {
702
+ return this._size;
703
+ }
704
+ /**
705
+ * Get the current minimum node.
706
+ * @remarks Time O(1), Space O(1)
707
+ * @returns Min node or undefined.
708
+ */
709
+ get min() {
710
+ return this._min;
711
+ }
712
+ get comparator() {
713
+ return this._comparator;
714
+ }
715
+ clear() {
716
+ this._root = void 0;
717
+ this._min = void 0;
718
+ this._size = 0;
719
+ }
720
+ add(element) {
721
+ this.push(element);
722
+ return true;
723
+ }
724
+ /**
725
+ * Push an element into the root list.
726
+ * @remarks Time O(1) amortized, Space O(1)
727
+ * @param element - Element to insert.
728
+ * @returns This heap.
729
+ */
730
+ push(element) {
731
+ const node = this.createNode(element);
732
+ node.left = node;
733
+ node.right = node;
734
+ this.mergeWithRoot(node);
735
+ if (!this.min || this.comparator(node.element, this.min.element) <= 0) this._min = node;
736
+ this._size++;
737
+ return this;
738
+ }
739
+ peek() {
740
+ return this.min ? this.min.element : void 0;
741
+ }
742
+ /**
743
+ * Collect nodes from a circular doubly linked list starting at head.
744
+ * @remarks Time O(K), Space O(K)
745
+ * @param [head] - Start node of the circular list.
746
+ * @returns Array of nodes from the list.
747
+ */
748
+ consumeLinkedList(head) {
749
+ const elements = [];
750
+ if (!head) return elements;
751
+ let node = head;
752
+ let started = false;
753
+ while (true) {
754
+ if (node === head && started) break;
755
+ else if (node === head) started = true;
756
+ elements.push(node);
757
+ node = node.right;
758
+ }
759
+ return elements;
760
+ }
761
+ /**
762
+ * Insert a node into a parent's child list (circular).
763
+ * @remarks Time O(1), Space O(1)
764
+ * @param parent - Parent node.
765
+ * @param node - Child node to insert.
766
+ * @returns void
767
+ */
768
+ mergeWithChild(parent, node) {
769
+ if (!parent.child) parent.child = node;
770
+ else {
771
+ node.right = parent.child.right;
772
+ node.left = parent.child;
773
+ parent.child.right.left = node;
774
+ parent.child.right = node;
775
+ }
776
+ }
777
+ poll() {
778
+ return this.pop();
779
+ }
780
+ /**
781
+ * Remove and return the minimum element, consolidating the root list.
782
+ * @remarks Time O(log N) amortized, Space O(1)
783
+ * @returns Minimum element or undefined.
784
+ */
785
+ pop() {
786
+ if (this._size === 0) return void 0;
787
+ const z = this.min;
788
+ if (z.child) {
789
+ const elements = this.consumeLinkedList(z.child);
790
+ for (const node of elements) {
791
+ this.mergeWithRoot(node);
792
+ node.parent = void 0;
793
+ }
794
+ }
795
+ this.removeFromRoot(z);
796
+ if (z === z.right) {
797
+ this._min = void 0;
798
+ this._root = void 0;
799
+ } else {
800
+ this._min = z.right;
801
+ this._consolidate();
802
+ }
803
+ this._size--;
804
+ return z.element;
805
+ }
806
+ /**
807
+ * Meld another heap into this heap.
808
+ * @remarks Time O(1), Space O(1)
809
+ * @param heapToMerge - Another FibonacciHeap to meld into this one.
810
+ * @returns void
811
+ */
812
+ merge(heapToMerge) {
813
+ if (heapToMerge.size === 0) return;
814
+ if (this.root && heapToMerge.root) {
815
+ const thisRoot = this.root, otherRoot = heapToMerge.root;
816
+ const thisRootRight = thisRoot.right, otherRootLeft = otherRoot.left;
817
+ thisRoot.right = otherRoot;
818
+ otherRoot.left = thisRoot;
819
+ thisRootRight.left = otherRootLeft;
820
+ otherRootLeft.right = thisRootRight;
821
+ } else if (!this.root && heapToMerge.root) {
822
+ this._root = heapToMerge.root;
823
+ }
824
+ if (!this.min || heapToMerge.min && this.comparator(heapToMerge.min.element, this.min.element) < 0) {
825
+ this._min = heapToMerge.min;
826
+ }
827
+ this._size += heapToMerge.size;
828
+ heapToMerge.clear();
829
+ }
830
+ createNode(element) {
831
+ return new FibonacciHeapNode(element);
832
+ }
833
+ isEmpty() {
834
+ return this._size === 0;
835
+ }
836
+ _defaultComparator(a, b) {
837
+ if (a < b) return -1;
838
+ if (a > b) return 1;
839
+ return 0;
840
+ }
841
+ mergeWithRoot(node) {
842
+ if (!this.root) this._root = node;
843
+ else {
844
+ node.right = this.root.right;
845
+ node.left = this.root;
846
+ this.root.right.left = node;
847
+ this.root.right = node;
848
+ }
849
+ }
850
+ removeFromRoot(node) {
851
+ if (this.root === node) this._root = node.right;
852
+ if (node.left) node.left.right = node.right;
853
+ if (node.right) node.right.left = node.left;
854
+ }
855
+ _link(y, x) {
856
+ this.removeFromRoot(y);
857
+ y.left = y;
858
+ y.right = y;
859
+ this.mergeWithChild(x, y);
860
+ x.degree++;
861
+ y.parent = x;
862
+ }
863
+ _consolidate() {
864
+ const A = new Array(this._size);
865
+ const elements = this.consumeLinkedList(this.root);
866
+ let x, y, d, t;
867
+ for (const node of elements) {
868
+ x = node;
869
+ d = x.degree;
870
+ while (A[d]) {
871
+ y = A[d];
872
+ if (this.comparator(x.element, y.element) > 0) {
873
+ t = x;
874
+ x = y;
875
+ y = t;
876
+ }
877
+ this._link(y, x);
878
+ A[d] = void 0;
879
+ d++;
880
+ }
881
+ A[d] = x;
882
+ }
883
+ for (let i = 0; i < A.length; i++) {
884
+ if (A[i] && (!this.min || this.comparator(A[i].element, this.min.element) <= 0)) this._min = A[i];
885
+ }
886
+ }
887
+ };
888
+ __name(_FibonacciHeap, "FibonacciHeap");
889
+ var FibonacciHeap = _FibonacciHeap;
890
+
891
+ // src/data-structures/heap/min-heap.ts
892
+ var _MinHeap = class _MinHeap extends Heap {
893
+ /**
894
+ * Create a min-heap.
895
+ * @param elements Optional initial elements.
896
+ * @param options Optional configuration.
897
+ */
898
+ constructor(elements = [], options) {
899
+ super(elements, options);
900
+ }
901
+ };
902
+ __name(_MinHeap, "MinHeap");
903
+ var MinHeap = _MinHeap;
904
+
905
+ // src/utils/utils.ts
906
+ function isPrimitiveComparable(value) {
907
+ const valueType = typeof value;
908
+ if (valueType === "number") return true;
909
+ return valueType === "bigint" || valueType === "string" || valueType === "boolean";
910
+ }
911
+ __name(isPrimitiveComparable, "isPrimitiveComparable");
912
+ function tryObjectToPrimitive(obj) {
913
+ if (typeof obj.valueOf === "function") {
914
+ const valueOfResult = obj.valueOf();
915
+ if (valueOfResult !== obj) {
916
+ if (isPrimitiveComparable(valueOfResult)) return valueOfResult;
917
+ if (typeof valueOfResult === "object" && valueOfResult !== null) return tryObjectToPrimitive(valueOfResult);
918
+ }
919
+ }
920
+ if (typeof obj.toString === "function") {
921
+ const stringResult = obj.toString();
922
+ if (stringResult !== "[object Object]") return stringResult;
923
+ }
924
+ return null;
925
+ }
926
+ __name(tryObjectToPrimitive, "tryObjectToPrimitive");
927
+ function isComparable(value, isForceObjectComparable = false) {
928
+ if (value === null || value === void 0) return false;
929
+ if (isPrimitiveComparable(value)) return true;
930
+ if (typeof value !== "object") return false;
931
+ if (value instanceof Date) return true;
932
+ if (isForceObjectComparable) return true;
933
+ const comparableValue = tryObjectToPrimitive(value);
934
+ if (comparableValue === null || comparableValue === void 0) return false;
935
+ return isPrimitiveComparable(comparableValue);
936
+ }
937
+ __name(isComparable, "isComparable");
938
+
939
+ // src/common/index.ts
940
+ var DFSOperation = /* @__PURE__ */ ((DFSOperation2) => {
941
+ DFSOperation2[DFSOperation2["VISIT"] = 0] = "VISIT";
942
+ DFSOperation2[DFSOperation2["PROCESS"] = 1] = "PROCESS";
943
+ return DFSOperation2;
944
+ })(DFSOperation || {});
945
+ var _Range = class _Range {
946
+ constructor(low, high, includeLow = true, includeHigh = true) {
947
+ this.low = low;
948
+ this.high = high;
949
+ this.includeLow = includeLow;
950
+ this.includeHigh = includeHigh;
951
+ if (!(isComparable(low) && isComparable(high))) throw new RangeError("low or high is not comparable");
952
+ if (low > high) throw new RangeError("low must be less than or equal to high");
953
+ }
954
+ // Determine whether a key is within the range
955
+ isInRange(key, comparator) {
956
+ const lowCheck = this.includeLow ? comparator(key, this.low) >= 0 : comparator(key, this.low) > 0;
957
+ const highCheck = this.includeHigh ? comparator(key, this.high) <= 0 : comparator(key, this.high) < 0;
958
+ return lowCheck && highCheck;
959
+ }
960
+ };
961
+ __name(_Range, "Range");
962
+ var Range = _Range;
963
+ /**
964
+ * data-structure-typed
965
+ *
966
+ * @author Pablo Zeng
967
+ * @copyright Copyright (c) 2022 Pablo Zeng <zrwusa@gmail.com>
968
+ * @license MIT License
969
+ */
970
+ /**
971
+ * @remarks Time O(n log n), Space O(n).
972
+ * data-structure-typed
973
+ * @author Kirk Qi
974
+ * @copyright Copyright (c) 2022 Kirk Qi <qilinaus@gmail.com>
975
+ * @license MIT License
976
+ */
977
+
978
+ export { DFSOperation, FibonacciHeap, FibonacciHeapNode, Heap, MinHeap, Range };
979
+ //# sourceMappingURL=index.mjs.map
980
+ //# sourceMappingURL=index.mjs.map