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