data-structure-typed 2.5.0 → 2.5.1

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 (222) hide show
  1. package/.vitepress/cache/deps_temp_51f5f1b0/chunk-7OIKW5WK.js +12984 -0
  2. package/.vitepress/cache/deps_temp_51f5f1b0/package.json +3 -0
  3. package/.vitepress/cache/deps_temp_51f5f1b0/vitepress___@vue_devtools-api.js +4505 -0
  4. package/.vitepress/cache/deps_temp_51f5f1b0/vitepress___@vueuse_core.js +9731 -0
  5. package/.vitepress/cache/deps_temp_51f5f1b0/vue.js +347 -0
  6. package/CHANGELOG.md +3 -1
  7. package/README.md +63 -26
  8. package/dist/cjs/binary-tree.cjs +23698 -0
  9. package/dist/cjs/graph.cjs +5236 -0
  10. package/dist/cjs/hash.cjs +1262 -0
  11. package/dist/cjs/heap.cjs +1540 -0
  12. package/dist/cjs/index.cjs +28244 -14795
  13. package/dist/cjs/linked-list.cjs +4370 -0
  14. package/dist/cjs/matrix.cjs +1042 -0
  15. package/dist/cjs/priority-queue.cjs +1314 -0
  16. package/dist/cjs/queue.cjs +4090 -0
  17. package/dist/cjs/stack.cjs +861 -0
  18. package/dist/cjs/trie.cjs +1173 -0
  19. package/dist/cjs-legacy/binary-tree.cjs +23730 -0
  20. package/dist/cjs-legacy/graph.cjs +5234 -0
  21. package/dist/cjs-legacy/hash.cjs +1262 -0
  22. package/dist/cjs-legacy/heap.cjs +1537 -0
  23. package/dist/cjs-legacy/index.cjs +28239 -14790
  24. package/dist/cjs-legacy/linked-list.cjs +4376 -0
  25. package/dist/cjs-legacy/matrix.cjs +1045 -0
  26. package/dist/cjs-legacy/priority-queue.cjs +1312 -0
  27. package/dist/cjs-legacy/queue.cjs +4088 -0
  28. package/dist/cjs-legacy/stack.cjs +861 -0
  29. package/dist/cjs-legacy/trie.cjs +1172 -0
  30. package/dist/esm/binary-tree.mjs +23683 -0
  31. package/dist/esm/graph.mjs +5223 -0
  32. package/dist/esm/hash.mjs +1259 -0
  33. package/dist/esm/heap.mjs +1534 -0
  34. package/dist/esm/index.mjs +28242 -14796
  35. package/dist/esm/linked-list.mjs +4363 -0
  36. package/dist/esm/matrix.mjs +1038 -0
  37. package/dist/esm/priority-queue.mjs +1310 -0
  38. package/dist/esm/queue.mjs +4086 -0
  39. package/dist/esm/stack.mjs +859 -0
  40. package/dist/esm/trie.mjs +1170 -0
  41. package/dist/esm-legacy/binary-tree.mjs +23715 -0
  42. package/dist/esm-legacy/graph.mjs +5221 -0
  43. package/dist/esm-legacy/hash.mjs +1259 -0
  44. package/dist/esm-legacy/heap.mjs +1531 -0
  45. package/dist/esm-legacy/index.mjs +28237 -14791
  46. package/dist/esm-legacy/linked-list.mjs +4369 -0
  47. package/dist/esm-legacy/matrix.mjs +1041 -0
  48. package/dist/esm-legacy/priority-queue.mjs +1308 -0
  49. package/dist/esm-legacy/queue.mjs +4084 -0
  50. package/dist/esm-legacy/stack.mjs +859 -0
  51. package/dist/esm-legacy/trie.mjs +1169 -0
  52. package/dist/types/data-structures/base/index.d.ts +1 -0
  53. package/dist/types/data-structures/base/iterable-entry-base.d.ts +8 -8
  54. package/dist/types/data-structures/base/linear-base.d.ts +3 -3
  55. package/dist/types/data-structures/binary-tree/avl-tree.d.ts +240 -0
  56. package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +280 -0
  57. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +502 -2
  58. package/dist/types/data-structures/binary-tree/bst.d.ts +481 -1
  59. package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +380 -0
  60. package/dist/types/data-structures/binary-tree/segment-tree.d.ts +120 -1
  61. package/dist/types/data-structures/binary-tree/tree-map.d.ts +2764 -384
  62. package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +2753 -353
  63. package/dist/types/data-structures/binary-tree/tree-multi-set.d.ts +2241 -321
  64. package/dist/types/data-structures/binary-tree/tree-set.d.ts +2554 -274
  65. package/dist/types/data-structures/graph/abstract-graph.d.ts +4 -4
  66. package/dist/types/data-structures/graph/directed-graph.d.ts +200 -0
  67. package/dist/types/data-structures/graph/undirected-graph.d.ts +180 -0
  68. package/dist/types/data-structures/hash/hash-map.d.ts +230 -10
  69. package/dist/types/data-structures/heap/heap.d.ts +280 -0
  70. package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +343 -3
  71. package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +303 -3
  72. package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +362 -2
  73. package/dist/types/data-structures/matrix/matrix.d.ts +160 -0
  74. package/dist/types/data-structures/queue/deque.d.ts +304 -4
  75. package/dist/types/data-structures/queue/queue.d.ts +240 -0
  76. package/dist/types/data-structures/stack/stack.d.ts +200 -0
  77. package/dist/types/data-structures/trie/trie.d.ts +244 -4
  78. package/dist/types/interfaces/graph.d.ts +1 -1
  79. package/dist/types/types/common.d.ts +2 -2
  80. package/dist/types/types/data-structures/heap/heap.d.ts +1 -0
  81. package/dist/types/types/data-structures/priority-queue/priority-queue.d.ts +1 -0
  82. package/dist/types/types/utils/validate-type.d.ts +4 -4
  83. package/dist/umd/data-structure-typed.js +28022 -14573
  84. package/dist/umd/data-structure-typed.min.js +9 -3
  85. package/docs-site-docusaurus/README.md +41 -0
  86. package/docs-site-docusaurus/docs/api/README.md +52 -0
  87. package/docs-site-docusaurus/docs/api/classes/AVLTree.md +6130 -0
  88. package/docs-site-docusaurus/docs/api/classes/AVLTreeNode.md +282 -0
  89. package/docs-site-docusaurus/docs/api/classes/AbstractGraph.md +2266 -0
  90. package/docs-site-docusaurus/docs/api/classes/BST.md +5831 -0
  91. package/docs-site-docusaurus/docs/api/classes/BSTNode.md +333 -0
  92. package/docs-site-docusaurus/docs/api/classes/BinaryIndexedTree.md +455 -0
  93. package/docs-site-docusaurus/docs/api/classes/BinaryTree.md +4647 -0
  94. package/docs-site-docusaurus/docs/api/classes/BinaryTreeNode.md +331 -0
  95. package/docs-site-docusaurus/docs/api/classes/Deque.md +2767 -0
  96. package/docs-site-docusaurus/docs/api/classes/DirectedGraph.md +2999 -0
  97. package/docs-site-docusaurus/docs/api/classes/DoublyLinkedList.md +2685 -0
  98. package/docs-site-docusaurus/docs/api/classes/DoublyLinkedListNode.md +221 -0
  99. package/docs-site-docusaurus/docs/api/classes/FibonacciHeap.md +253 -0
  100. package/docs-site-docusaurus/docs/api/classes/FibonacciHeapNode.md +21 -0
  101. package/docs-site-docusaurus/docs/api/classes/HashMap.md +1333 -0
  102. package/docs-site-docusaurus/docs/api/classes/Heap.md +1881 -0
  103. package/docs-site-docusaurus/docs/api/classes/IterableElementBase.md +800 -0
  104. package/docs-site-docusaurus/docs/api/classes/IterableEntryBase.md +644 -0
  105. package/docs-site-docusaurus/docs/api/classes/LinearBase.md +1632 -0
  106. package/docs-site-docusaurus/docs/api/classes/LinearLinkedBase.md +1853 -0
  107. package/docs-site-docusaurus/docs/api/classes/LinkedHashMap.md +1108 -0
  108. package/docs-site-docusaurus/docs/api/classes/LinkedListNode.md +156 -0
  109. package/docs-site-docusaurus/docs/api/classes/LinkedListQueue.md +2824 -0
  110. package/docs-site-docusaurus/docs/api/classes/MapGraph.md +2929 -0
  111. package/docs-site-docusaurus/docs/api/classes/Matrix.md +1026 -0
  112. package/docs-site-docusaurus/docs/api/classes/MaxHeap.md +1866 -0
  113. package/docs-site-docusaurus/docs/api/classes/MaxPriorityQueue.md +1883 -0
  114. package/docs-site-docusaurus/docs/api/classes/MinHeap.md +1879 -0
  115. package/docs-site-docusaurus/docs/api/classes/MinPriorityQueue.md +1882 -0
  116. package/docs-site-docusaurus/docs/api/classes/Navigator.md +109 -0
  117. package/docs-site-docusaurus/docs/api/classes/PriorityQueue.md +1839 -0
  118. package/docs-site-docusaurus/docs/api/classes/Queue.md +2244 -0
  119. package/docs-site-docusaurus/docs/api/classes/RedBlackTree.md +6374 -0
  120. package/docs-site-docusaurus/docs/api/classes/SegmentTree.md +372 -0
  121. package/docs-site-docusaurus/docs/api/classes/SinglyLinkedList.md +2897 -0
  122. package/docs-site-docusaurus/docs/api/classes/SinglyLinkedListNode.md +169 -0
  123. package/docs-site-docusaurus/docs/api/classes/SkipList.md +1229 -0
  124. package/docs-site-docusaurus/docs/api/classes/Stack.md +1573 -0
  125. package/docs-site-docusaurus/docs/api/classes/TreeMap.md +1257 -0
  126. package/docs-site-docusaurus/docs/api/classes/TreeMultiMap.md +1475 -0
  127. package/docs-site-docusaurus/docs/api/classes/TreeSet.md +1117 -0
  128. package/docs-site-docusaurus/docs/api/classes/Trie.md +1708 -0
  129. package/docs-site-docusaurus/docs/api/classes/TrieNode.md +199 -0
  130. package/docs-site-docusaurus/docs/api/classes/UndirectedGraph.md +2979 -0
  131. package/docs-site-docusaurus/docs/guide/_category_.json +6 -0
  132. package/docs-site-docusaurus/docs/guide/architecture.md +613 -0
  133. package/docs-site-docusaurus/docs/guide/concepts.md +420 -0
  134. package/docs-site-docusaurus/docs/guide/guides.md +611 -0
  135. package/docs-site-docusaurus/docs/guide/installation.md +60 -0
  136. package/docs-site-docusaurus/docs/guide/integrations.md +823 -0
  137. package/docs-site-docusaurus/docs/guide/overview.md +638 -0
  138. package/docs-site-docusaurus/docs/guide/performance.md +833 -0
  139. package/docs-site-docusaurus/docs/guide/quick-start.md +73 -0
  140. package/docs-site-docusaurus/docusaurus.config.ts +159 -0
  141. package/docs-site-docusaurus/fix-mdx-generics.mjs +75 -0
  142. package/docs-site-docusaurus/package-lock.json +18667 -0
  143. package/docs-site-docusaurus/package.json +50 -0
  144. package/docs-site-docusaurus/prefix-class-to-methods.mjs +48 -0
  145. package/docs-site-docusaurus/sidebars.ts +23 -0
  146. package/docs-site-docusaurus/sort-protected.mjs +87 -0
  147. package/docs-site-docusaurus/src/css/custom.css +96 -0
  148. package/docs-site-docusaurus/src/pages/index.module.css +13 -0
  149. package/docs-site-docusaurus/src/pages/index.tsx +71 -0
  150. package/docs-site-docusaurus/src/pages/markdown-page.md +7 -0
  151. package/docs-site-docusaurus/src/theme/TOCItems/index.tsx +34 -0
  152. package/docs-site-docusaurus/static/.nojekyll +0 -0
  153. package/docs-site-docusaurus/static/img/docusaurus-social-card.jpg +0 -0
  154. package/docs-site-docusaurus/static/img/docusaurus.png +0 -0
  155. package/docs-site-docusaurus/static/img/favicon.ico +0 -0
  156. package/docs-site-docusaurus/static/img/favicon.png +0 -0
  157. package/docs-site-docusaurus/static/img/logo-180.png +0 -0
  158. package/docs-site-docusaurus/static/img/logo.jpg +0 -0
  159. package/docs-site-docusaurus/static/img/logo.png +0 -0
  160. package/docs-site-docusaurus/static/img/logo.svg +1 -0
  161. package/docs-site-docusaurus/static/img/og-image.png +0 -0
  162. package/docs-site-docusaurus/static/img/undraw_docusaurus_mountain.svg +171 -0
  163. package/docs-site-docusaurus/static/img/undraw_docusaurus_react.svg +170 -0
  164. package/docs-site-docusaurus/static/img/undraw_docusaurus_tree.svg +40 -0
  165. package/docs-site-docusaurus/static/robots.txt +4 -0
  166. package/docs-site-docusaurus/typedoc.json +23 -0
  167. package/package.json +106 -10
  168. package/src/data-structures/base/index.ts +1 -0
  169. package/src/data-structures/base/iterable-entry-base.ts +8 -8
  170. package/src/data-structures/base/linear-base.ts +3 -3
  171. package/src/data-structures/binary-tree/avl-tree.ts +240 -0
  172. package/src/data-structures/binary-tree/binary-indexed-tree.ts +281 -1
  173. package/src/data-structures/binary-tree/binary-tree.ts +502 -2
  174. package/src/data-structures/binary-tree/bst.ts +481 -1
  175. package/src/data-structures/binary-tree/red-black-tree.ts +380 -0
  176. package/src/data-structures/binary-tree/segment-tree.ts +121 -2
  177. package/src/data-structures/binary-tree/tree-map.ts +2862 -482
  178. package/src/data-structures/binary-tree/tree-multi-map.ts +2963 -563
  179. package/src/data-structures/binary-tree/tree-multi-set.ts +2399 -479
  180. package/src/data-structures/binary-tree/tree-set.ts +2685 -405
  181. package/src/data-structures/graph/abstract-graph.ts +4 -4
  182. package/src/data-structures/graph/directed-graph.ts +200 -0
  183. package/src/data-structures/graph/undirected-graph.ts +180 -0
  184. package/src/data-structures/hash/hash-map.ts +235 -15
  185. package/src/data-structures/heap/heap.ts +280 -0
  186. package/src/data-structures/linked-list/doubly-linked-list.ts +343 -3
  187. package/src/data-structures/linked-list/singly-linked-list.ts +303 -3
  188. package/src/data-structures/linked-list/skip-linked-list.ts +362 -2
  189. package/src/data-structures/matrix/matrix.ts +161 -1
  190. package/src/data-structures/queue/deque.ts +305 -5
  191. package/src/data-structures/queue/queue.ts +240 -0
  192. package/src/data-structures/stack/stack.ts +200 -0
  193. package/src/data-structures/trie/trie.ts +245 -5
  194. package/src/interfaces/graph.ts +1 -1
  195. package/src/types/common.ts +2 -2
  196. package/src/types/data-structures/heap/heap.ts +1 -0
  197. package/src/types/data-structures/priority-queue/priority-queue.ts +1 -0
  198. package/src/types/utils/validate-type.ts +4 -4
  199. package/vercel.json +6 -0
  200. package/dist/leetcode/avl-tree-counter.mjs +0 -2957
  201. package/dist/leetcode/avl-tree-multi-map.mjs +0 -2889
  202. package/dist/leetcode/avl-tree.mjs +0 -2720
  203. package/dist/leetcode/binary-tree.mjs +0 -1594
  204. package/dist/leetcode/bst.mjs +0 -2398
  205. package/dist/leetcode/deque.mjs +0 -683
  206. package/dist/leetcode/directed-graph.mjs +0 -1733
  207. package/dist/leetcode/doubly-linked-list.mjs +0 -709
  208. package/dist/leetcode/hash-map.mjs +0 -493
  209. package/dist/leetcode/heap.mjs +0 -542
  210. package/dist/leetcode/max-heap.mjs +0 -375
  211. package/dist/leetcode/max-priority-queue.mjs +0 -383
  212. package/dist/leetcode/min-heap.mjs +0 -363
  213. package/dist/leetcode/min-priority-queue.mjs +0 -371
  214. package/dist/leetcode/priority-queue.mjs +0 -363
  215. package/dist/leetcode/queue.mjs +0 -943
  216. package/dist/leetcode/red-black-tree.mjs +0 -2765
  217. package/dist/leetcode/singly-linked-list.mjs +0 -754
  218. package/dist/leetcode/stack.mjs +0 -217
  219. package/dist/leetcode/tree-counter.mjs +0 -3039
  220. package/dist/leetcode/tree-multi-map.mjs +0 -2913
  221. package/dist/leetcode/trie.mjs +0 -413
  222. package/dist/leetcode/undirected-graph.mjs +0 -1650
@@ -0,0 +1,1882 @@
1
+ [**data-structure-typed**](../README.md)
2
+
3
+ ***
4
+
5
+ [data-structure-typed](../README.md) / MinPriorityQueue
6
+
7
+ # Class: MinPriorityQueue\<E, R\>
8
+
9
+ Defined in: [data-structures/priority-queue/min-priority-queue.ts:79](https://github.com/zrwusa/data-structure-typed/blob/2f6ceb3aee852228efc88b111e19c0809753e805/src/data-structures/priority-queue/min-priority-queue.ts#L79)
10
+
11
+ Min-oriented priority queue (min-heap) built on [PriorityQueue](PriorityQueue.md).
12
+ The queue removes the smallest element first under the provided comparator.
13
+ Provide a custom comparator if you store non-primitive objects.
14
+
15
+ ## Examples
16
+
17
+ ```ts
18
+ // Shortest job first scheduling
19
+ const jobs = new MinPriorityQueue<number>();
20
+
21
+ jobs.add(8); // 8 seconds
22
+ jobs.add(2); // 2 seconds
23
+ jobs.add(5); // 5 seconds
24
+ jobs.add(1); // 1 second
25
+
26
+ // Shortest job first
27
+ console.log(jobs.poll()); // 1;
28
+ console.log(jobs.poll()); // 2;
29
+ console.log(jobs.poll()); // 5;
30
+ console.log(jobs.poll()); // 8;
31
+ ```
32
+
33
+ ```ts
34
+ // Event-driven simulation with timestamps
35
+ interface Event {
36
+ time: number;
37
+ action: string;
38
+ }
39
+
40
+ const timeline = new MinPriorityQueue<Event>([], {
41
+ comparator: (a, b) => a.time - b.time
42
+ });
43
+
44
+ timeline.add({ time: 300, action: 'Timeout' });
45
+ timeline.add({ time: 100, action: 'Request received' });
46
+ timeline.add({ time: 200, action: 'Processing done' });
47
+ timeline.add({ time: 150, action: 'Cache hit' });
48
+
49
+ const order = [];
50
+ while (timeline.size > 0) {
51
+ order.push(timeline.poll()!.action);
52
+ }
53
+ console.log(order); // [
54
+ // 'Request received',
55
+ // 'Cache hit',
56
+ // 'Processing done',
57
+ // 'Timeout'
58
+ // ];
59
+ ```
60
+
61
+ ```ts
62
+ // Huffman coding frequency selection
63
+ // Character frequencies for Huffman tree building
64
+ const freq = new MinPriorityQueue<[number, string]>([], {
65
+ comparator: (a, b) => a[0] - b[0]
66
+ });
67
+
68
+ freq.add([5, 'a']);
69
+ freq.add([9, 'b']);
70
+ freq.add([12, 'c']);
71
+ freq.add([2, 'd']);
72
+
73
+ // Always pick two lowest frequencies
74
+ const first = freq.poll()!;
75
+ const second = freq.poll()!;
76
+ console.log(first[1]); // 'd'; // freq 2
77
+ console.log(second[1]); // 'a'; // freq 5
78
+
79
+ // Combined node goes back
80
+ freq.add([first[0] + second[0], first[1] + second[1]]);
81
+ console.log(freq.peek()![0]); // 7;
82
+ ```
83
+
84
+ ## Extends
85
+
86
+ - [`PriorityQueue`](PriorityQueue.md)\<`E`, `R`\>
87
+
88
+ ## Type Parameters
89
+
90
+ ### E
91
+
92
+ `E` = `any`
93
+
94
+ Element type stored in the queue.
95
+
96
+ ### R
97
+
98
+ `R` = `any`
99
+
100
+ Extra record/metadata associated with each element.
101
+
102
+ ## Constructors
103
+
104
+ ### Constructor
105
+
106
+ ```ts
107
+ new MinPriorityQueue<E, R>(elements?, options?): MinPriorityQueue<E, R>;
108
+ ```
109
+
110
+ Defined in: [data-structures/priority-queue/min-priority-queue.ts:86](https://github.com/zrwusa/data-structure-typed/blob/2f6ceb3aee852228efc88b111e19c0809753e805/src/data-structures/priority-queue/min-priority-queue.ts#L86)
111
+
112
+ Creates a min-priority queue.
113
+
114
+ #### Parameters
115
+
116
+ ##### elements?
117
+
118
+ `Iterable`\<`E`, `any`, `any`\> \| `Iterable`\<`R`, `any`, `any`\>
119
+
120
+ Optional initial elements to insert.
121
+
122
+ ##### options?
123
+
124
+ `PriorityQueueOptions`\<`E`, `R`\>
125
+
126
+ Optional configuration (e.g., `comparator`, `toElementFn`).
127
+
128
+ #### Returns
129
+
130
+ `MinPriorityQueue`\<`E`, `R`\>
131
+
132
+ #### Remarks
133
+
134
+ Complexity — Time: O(n log n) when inserting n elements incrementally; Space: O(n).
135
+
136
+ #### Overrides
137
+
138
+ ```ts
139
+ PriorityQueue<E, R>.constructor
140
+ ```
141
+
142
+ ## Properties
143
+
144
+ ### comparator
145
+
146
+ #### Get Signature
147
+
148
+ ```ts
149
+ get comparator(): Comparator<E>;
150
+ ```
151
+
152
+ Defined in: [data-structures/heap/heap.ts:1086](https://github.com/zrwusa/data-structure-typed/blob/2f6ceb3aee852228efc88b111e19c0809753e805/src/data-structures/heap/heap.ts#L1086)
153
+
154
+ Get the comparator used to order elements.
155
+
156
+ ##### Remarks
157
+
158
+ Time O(1), Space O(1)
159
+
160
+ ##### Returns
161
+
162
+ `Comparator`\<`E`\>
163
+
164
+ Comparator function.
165
+
166
+ #### Inherited from
167
+
168
+ [`PriorityQueue`](PriorityQueue.md).[`comparator`](PriorityQueue.md#comparator)
169
+
170
+ ***
171
+
172
+ ### elements
173
+
174
+ #### Get Signature
175
+
176
+ ```ts
177
+ get elements(): E[];
178
+ ```
179
+
180
+ Defined in: [data-structures/heap/heap.ts:180](https://github.com/zrwusa/data-structure-typed/blob/2f6ceb3aee852228efc88b111e19c0809753e805/src/data-structures/heap/heap.ts#L180)
181
+
182
+ Get the backing array of the heap.
183
+
184
+ ##### Remarks
185
+
186
+ Time O(1), Space O(1)
187
+
188
+ ##### Returns
189
+
190
+ `E`[]
191
+
192
+ Internal elements array.
193
+
194
+ #### Inherited from
195
+
196
+ [`PriorityQueue`](PriorityQueue.md).[`elements`](PriorityQueue.md#elements)
197
+
198
+ ***
199
+
200
+ ### leaf
201
+
202
+ #### Get Signature
203
+
204
+ ```ts
205
+ get leaf(): E | undefined;
206
+ ```
207
+
208
+ Defined in: [data-structures/heap/heap.ts:237](https://github.com/zrwusa/data-structure-typed/blob/2f6ceb3aee852228efc88b111e19c0809753e805/src/data-structures/heap/heap.ts#L237)
209
+
210
+ Get the last leaf element.
211
+
212
+ ##### Remarks
213
+
214
+ Time O(1), Space O(1)
215
+
216
+ ##### Returns
217
+
218
+ `E` \| `undefined`
219
+
220
+ Last element or undefined.
221
+
222
+ #### Inherited from
223
+
224
+ [`PriorityQueue`](PriorityQueue.md).[`leaf`](PriorityQueue.md#leaf)
225
+
226
+ ***
227
+
228
+ ### size
229
+
230
+ #### Get Signature
231
+
232
+ ```ts
233
+ get size(): number;
234
+ ```
235
+
236
+ Defined in: [data-structures/heap/heap.ts:227](https://github.com/zrwusa/data-structure-typed/blob/2f6ceb3aee852228efc88b111e19c0809753e805/src/data-structures/heap/heap.ts#L227)
237
+
238
+ Get the number of elements.
239
+
240
+ ##### Remarks
241
+
242
+ Time O(1), Space O(1)
243
+
244
+ ##### Example
245
+
246
+ ```ts
247
+ // Track heap capacity
248
+ const heap = new Heap<number>();
249
+ console.log(heap.size); // 0;
250
+ heap.add(10);
251
+ heap.add(20);
252
+ console.log(heap.size); // 2;
253
+ heap.poll();
254
+ console.log(heap.size); // 1;
255
+ ```
256
+
257
+ ##### Returns
258
+
259
+ `number`
260
+
261
+ Heap size.
262
+
263
+ *
264
+
265
+ #### Inherited from
266
+
267
+ [`PriorityQueue`](PriorityQueue.md).[`size`](PriorityQueue.md#size)
268
+
269
+ ***
270
+
271
+ ### toElementFn
272
+
273
+ #### Get Signature
274
+
275
+ ```ts
276
+ get toElementFn(): ((rawElement) => E) | undefined;
277
+ ```
278
+
279
+ Defined in: [data-structures/base/iterable-element-base.ts:47](https://github.com/zrwusa/data-structure-typed/blob/2f6ceb3aee852228efc88b111e19c0809753e805/src/data-structures/base/iterable-element-base.ts#L47)
280
+
281
+ Exposes the current `toElementFn`, if configured.
282
+
283
+ ##### Remarks
284
+
285
+ Time O(1), Space O(1).
286
+
287
+ ##### Returns
288
+
289
+ ((`rawElement`) => `E`) \| `undefined`
290
+
291
+ The converter function or `undefined` when not set.
292
+
293
+ #### Inherited from
294
+
295
+ [`PriorityQueue`](PriorityQueue.md).[`toElementFn`](PriorityQueue.md#toelementfn)
296
+
297
+ ## Methods
298
+
299
+ ### \[iterator\]()
300
+
301
+ ```ts
302
+ iterator: IterableIterator<E>;
303
+ ```
304
+
305
+ Defined in: [data-structures/base/iterable-element-base.ts:60](https://github.com/zrwusa/data-structure-typed/blob/2f6ceb3aee852228efc88b111e19c0809753e805/src/data-structures/base/iterable-element-base.ts#L60)
306
+
307
+ Returns an iterator over the structure's elements.
308
+
309
+ #### Parameters
310
+
311
+ ##### args
312
+
313
+ ...`unknown`[]
314
+
315
+ Optional iterator arguments forwarded to the internal iterator.
316
+
317
+ #### Returns
318
+
319
+ `IterableIterator`\<`E`\>
320
+
321
+ An `IterableIterator<E>` that yields the elements in traversal order.
322
+
323
+ #### Remarks
324
+
325
+ Producing the iterator is O(1); consuming the entire iterator is Time O(n) with O(1) extra space.
326
+
327
+ #### Inherited from
328
+
329
+ [`PriorityQueue`](PriorityQueue.md).[`[iterator]`](PriorityQueue.md#iterator)
330
+
331
+ ***
332
+
333
+ ### add()
334
+
335
+ ```ts
336
+ add(element): boolean;
337
+ ```
338
+
339
+ Defined in: [data-structures/heap/heap.ts:324](https://github.com/zrwusa/data-structure-typed/blob/2f6ceb3aee852228efc88b111e19c0809753e805/src/data-structures/heap/heap.ts#L324)
340
+
341
+ Insert an element.
342
+
343
+ #### Parameters
344
+
345
+ ##### element
346
+
347
+ `E`
348
+
349
+ Element to insert.
350
+
351
+ #### Returns
352
+
353
+ `boolean`
354
+
355
+ True.
356
+
357
+ *
358
+
359
+ #### Remarks
360
+
361
+ Time O(1) amortized, Space O(1)
362
+
363
+ #### Example
364
+
365
+ ```ts
366
+ // basic Heap creation and add operation
367
+ // Create a min heap (default)
368
+ const minHeap = new Heap([5, 3, 7, 1, 9, 2]);
369
+
370
+ // Verify size
371
+ console.log(minHeap.size); // 6;
372
+
373
+ // Add new element
374
+ minHeap.add(4);
375
+ console.log(minHeap.size); // 7;
376
+
377
+ // Min heap property: smallest element at root
378
+ const min = minHeap.peek();
379
+ console.log(min); // 1;
380
+ ```
381
+
382
+ #### Inherited from
383
+
384
+ [`PriorityQueue`](PriorityQueue.md).[`add`](PriorityQueue.md#add)
385
+
386
+ ***
387
+
388
+ ### addMany()
389
+
390
+ ```ts
391
+ addMany(elements): boolean[];
392
+ ```
393
+
394
+ Defined in: [data-structures/heap/heap.ts:367](https://github.com/zrwusa/data-structure-typed/blob/2f6ceb3aee852228efc88b111e19c0809753e805/src/data-structures/heap/heap.ts#L367)
395
+
396
+ Insert many elements from an iterable.
397
+
398
+ #### Parameters
399
+
400
+ ##### elements
401
+
402
+ `Iterable`\<`E` \| `R`\>
403
+
404
+ Iterable of elements or raw values.
405
+
406
+ #### Returns
407
+
408
+ `boolean`[]
409
+
410
+ Array of per-element success flags.
411
+
412
+ *
413
+
414
+ #### Remarks
415
+
416
+ Time O(N log N), Space O(1)
417
+
418
+ #### Example
419
+
420
+ ```ts
421
+ // Add multiple elements
422
+ const heap = new Heap<number>([], { comparator: (a, b) => a - b });
423
+ heap.addMany([5, 3, 7, 1]);
424
+ console.log(heap.peek()); // 1;
425
+ console.log(heap.size); // 4;
426
+ ```
427
+
428
+ #### Inherited from
429
+
430
+ [`PriorityQueue`](PriorityQueue.md).[`addMany`](PriorityQueue.md#addmany)
431
+
432
+ ***
433
+
434
+ ### clear()
435
+
436
+ ```ts
437
+ clear(): void;
438
+ ```
439
+
440
+ Defined in: [data-structures/heap/heap.ts:627](https://github.com/zrwusa/data-structure-typed/blob/2f6ceb3aee852228efc88b111e19c0809753e805/src/data-structures/heap/heap.ts#L627)
441
+
442
+ Remove all elements.
443
+
444
+ #### Returns
445
+
446
+ `void`
447
+
448
+ void
449
+
450
+ *
451
+
452
+ #### Remarks
453
+
454
+ Time O(1), Space O(1)
455
+
456
+ #### Example
457
+
458
+ ```ts
459
+ // Remove all elements
460
+ const heap = new Heap<number>([1, 2, 3], { comparator: (a, b) => a - b });
461
+ heap.clear();
462
+ console.log(heap.isEmpty()); // true;
463
+ ```
464
+
465
+ #### Inherited from
466
+
467
+ [`PriorityQueue`](PriorityQueue.md).[`clear`](PriorityQueue.md#clear)
468
+
469
+ ***
470
+
471
+ ### clone()
472
+
473
+ ```ts
474
+ clone(): this;
475
+ ```
476
+
477
+ Defined in: [data-structures/heap/heap.ts:936](https://github.com/zrwusa/data-structure-typed/blob/2f6ceb3aee852228efc88b111e19c0809753e805/src/data-structures/heap/heap.ts#L936)
478
+
479
+ Deep clone this heap.
480
+
481
+ #### Returns
482
+
483
+ `this`
484
+
485
+ A new heap with the same elements.
486
+
487
+ *
488
+
489
+ #### Remarks
490
+
491
+ Time O(N), Space O(N)
492
+
493
+ #### Example
494
+
495
+ ```ts
496
+ // Create independent copy
497
+ const heap = new Heap<number>([3, 1, 4], { comparator: (a, b) => a - b });
498
+ const copy = heap.clone();
499
+ copy.poll();
500
+ console.log(heap.size); // 3;
501
+ console.log(copy.size); // 2;
502
+ ```
503
+
504
+ #### Inherited from
505
+
506
+ [`PriorityQueue`](PriorityQueue.md).[`clone`](PriorityQueue.md#clone)
507
+
508
+ ***
509
+
510
+ ### delete()
511
+
512
+ ```ts
513
+ delete(element): boolean;
514
+ ```
515
+
516
+ Defined in: [data-structures/heap/heap.ts:716](https://github.com/zrwusa/data-structure-typed/blob/2f6ceb3aee852228efc88b111e19c0809753e805/src/data-structures/heap/heap.ts#L716)
517
+
518
+ Delete one occurrence of an element.
519
+
520
+ #### Parameters
521
+
522
+ ##### element
523
+
524
+ `E`
525
+
526
+ Element to delete.
527
+
528
+ #### Returns
529
+
530
+ `boolean`
531
+
532
+ True if an element was removed.
533
+
534
+ *
535
+
536
+ #### Remarks
537
+
538
+ Time O(N), Space O(1)
539
+
540
+ #### Example
541
+
542
+ ```ts
543
+ // Remove specific element
544
+ const heap = new Heap<number>([3, 1, 4, 1, 5], { comparator: (a, b) => a - b });
545
+ heap.delete(4);
546
+ console.log(heap.toArray().includes(4)); // false;
547
+ ```
548
+
549
+ #### Inherited from
550
+
551
+ [`PriorityQueue`](PriorityQueue.md).[`delete`](PriorityQueue.md#delete)
552
+
553
+ ***
554
+
555
+ ### deleteBy()
556
+
557
+ ```ts
558
+ deleteBy(predicate): boolean;
559
+ ```
560
+
561
+ Defined in: [data-structures/heap/heap.ts:744](https://github.com/zrwusa/data-structure-typed/blob/2f6ceb3aee852228efc88b111e19c0809753e805/src/data-structures/heap/heap.ts#L744)
562
+
563
+ Delete the first element that matches a predicate.
564
+
565
+ #### Parameters
566
+
567
+ ##### predicate
568
+
569
+ (`element`, `index`, `heap`) => `boolean`
570
+
571
+ Function (element, index, heap) → boolean.
572
+
573
+ #### Returns
574
+
575
+ `boolean`
576
+
577
+ True if an element was removed.
578
+
579
+ #### Remarks
580
+
581
+ Time O(N), Space O(1)
582
+
583
+ #### Inherited from
584
+
585
+ [`PriorityQueue`](PriorityQueue.md).[`deleteBy`](PriorityQueue.md#deleteby)
586
+
587
+ ***
588
+
589
+ ### dfs()
590
+
591
+ ```ts
592
+ dfs(order?): E[];
593
+ ```
594
+
595
+ Defined in: [data-structures/heap/heap.ts:808](https://github.com/zrwusa/data-structure-typed/blob/2f6ceb3aee852228efc88b111e19c0809753e805/src/data-structures/heap/heap.ts#L808)
596
+
597
+ Traverse the binary heap as a complete binary tree and collect elements.
598
+
599
+ #### Parameters
600
+
601
+ ##### order?
602
+
603
+ `DFSOrderPattern` = `'PRE'`
604
+
605
+ Traversal order: 'PRE' | 'IN' | 'POST'.
606
+
607
+ #### Returns
608
+
609
+ `E`[]
610
+
611
+ Array of visited elements.
612
+
613
+ *
614
+
615
+ #### Remarks
616
+
617
+ Time O(N), Space O(H)
618
+
619
+ #### Example
620
+
621
+ ```ts
622
+ // Depth-first traversal
623
+ const heap = new Heap<number>([3, 1, 2], { comparator: (a, b) => a - b });
624
+ const result = heap.dfs('IN');
625
+ console.log(result.length); // 3;
626
+ ```
627
+
628
+ #### Inherited from
629
+
630
+ [`PriorityQueue`](PriorityQueue.md).[`dfs`](PriorityQueue.md#dfs)
631
+
632
+ ***
633
+
634
+ ### every()
635
+
636
+ ```ts
637
+ every(predicate, thisArg?): boolean;
638
+ ```
639
+
640
+ Defined in: [data-structures/base/iterable-element-base.ts:86](https://github.com/zrwusa/data-structure-typed/blob/2f6ceb3aee852228efc88b111e19c0809753e805/src/data-structures/base/iterable-element-base.ts#L86)
641
+
642
+ Tests whether all elements satisfy the predicate.
643
+
644
+ #### Parameters
645
+
646
+ ##### predicate
647
+
648
+ `ElementCallback`\<`E`, `R`, `boolean`\>
649
+
650
+ Function invoked for each element with signature `(value, index, self)`.
651
+
652
+ ##### thisArg?
653
+
654
+ `unknown`
655
+
656
+ Optional `this` binding for the predicate.
657
+
658
+ #### Returns
659
+
660
+ `boolean`
661
+
662
+ `true` if every element passes; otherwise `false`.
663
+
664
+ #### Remarks
665
+
666
+ Time O(n) in the worst case; may exit early when the first failure is found. Space O(1).
667
+
668
+ #### Inherited from
669
+
670
+ [`PriorityQueue`](PriorityQueue.md).[`every`](PriorityQueue.md#every)
671
+
672
+ ***
673
+
674
+ ### filter()
675
+
676
+ ```ts
677
+ filter(callback, thisArg?): this;
678
+ ```
679
+
680
+ Defined in: [data-structures/heap/heap.ts:981](https://github.com/zrwusa/data-structure-typed/blob/2f6ceb3aee852228efc88b111e19c0809753e805/src/data-structures/heap/heap.ts#L981)
681
+
682
+ Filter elements into a new heap of the same class.
683
+
684
+ #### Parameters
685
+
686
+ ##### callback
687
+
688
+ `ElementCallback`\<`E`, `R`, `boolean`\>
689
+
690
+ Predicate (element, index, heap) → boolean to keep element.
691
+
692
+ ##### thisArg?
693
+
694
+ `unknown`
695
+
696
+ Value for `this` inside the callback.
697
+
698
+ #### Returns
699
+
700
+ `this`
701
+
702
+ A new heap with the kept elements.
703
+
704
+ *
705
+
706
+ #### Remarks
707
+
708
+ Time O(N log N), Space O(N)
709
+
710
+ #### Example
711
+
712
+ ```ts
713
+ // Filter elements
714
+ const heap = new Heap<number>([1, 2, 3, 4, 5], { comparator: (a, b) => a - b });
715
+ const evens = heap.filter(x => x % 2 === 0);
716
+ console.log(evens.size); // 2;
717
+ ```
718
+
719
+ #### Inherited from
720
+
721
+ [`PriorityQueue`](PriorityQueue.md).[`filter`](PriorityQueue.md#filter)
722
+
723
+ ***
724
+
725
+ ### find()
726
+
727
+ #### Call Signature
728
+
729
+ ```ts
730
+ find<S>(predicate, thisArg?): S | undefined;
731
+ ```
732
+
733
+ Defined in: [data-structures/base/iterable-element-base.ts:162](https://github.com/zrwusa/data-structure-typed/blob/2f6ceb3aee852228efc88b111e19c0809753e805/src/data-structures/base/iterable-element-base.ts#L162)
734
+
735
+ Finds the first element that satisfies the predicate and returns it.
736
+
737
+ Finds the first element of type `S` (a subtype of `E`) that satisfies the predicate and returns it.
738
+
739
+ ##### Type Parameters
740
+
741
+ ###### S
742
+
743
+ `S`
744
+
745
+ ##### Parameters
746
+
747
+ ###### predicate
748
+
749
+ `ElementCallback`\<`E`, `R`, `S`\>
750
+
751
+ Type-guard predicate: `(value, index, self) => value is S`.
752
+
753
+ ###### thisArg?
754
+
755
+ `unknown`
756
+
757
+ Optional `this` binding for the predicate.
758
+
759
+ ##### Returns
760
+
761
+ `S` \| `undefined`
762
+
763
+ The matched element typed as `S`, or `undefined` if not found.
764
+
765
+ ##### Remarks
766
+
767
+ Time O(n) in the worst case; may exit early on the first match. Space O(1).
768
+
769
+ ##### Inherited from
770
+
771
+ [`PriorityQueue`](PriorityQueue.md).[`find`](PriorityQueue.md#find)
772
+
773
+ #### Call Signature
774
+
775
+ ```ts
776
+ find(predicate, thisArg?): E | undefined;
777
+ ```
778
+
779
+ Defined in: [data-structures/base/iterable-element-base.ts:163](https://github.com/zrwusa/data-structure-typed/blob/2f6ceb3aee852228efc88b111e19c0809753e805/src/data-structures/base/iterable-element-base.ts#L163)
780
+
781
+ Finds the first element that satisfies the predicate and returns it.
782
+
783
+ Finds the first element of type `S` (a subtype of `E`) that satisfies the predicate and returns it.
784
+
785
+ ##### Parameters
786
+
787
+ ###### predicate
788
+
789
+ `ElementCallback`\<`E`, `R`, `unknown`\>
790
+
791
+ Type-guard predicate: `(value, index, self) => value is S`.
792
+
793
+ ###### thisArg?
794
+
795
+ `unknown`
796
+
797
+ Optional `this` binding for the predicate.
798
+
799
+ ##### Returns
800
+
801
+ `E` \| `undefined`
802
+
803
+ The matched element typed as `S`, or `undefined` if not found.
804
+
805
+ ##### Remarks
806
+
807
+ Time O(n) in the worst case; may exit early on the first match. Space O(1).
808
+
809
+ ##### Inherited from
810
+
811
+ [`PriorityQueue`](PriorityQueue.md).[`find`](PriorityQueue.md#find)
812
+
813
+ ***
814
+
815
+ ### fix()
816
+
817
+ ```ts
818
+ fix(): boolean[];
819
+ ```
820
+
821
+ Defined in: [data-structures/heap/heap.ts:839](https://github.com/zrwusa/data-structure-typed/blob/2f6ceb3aee852228efc88b111e19c0809753e805/src/data-structures/heap/heap.ts#L839)
822
+
823
+ Restore heap order bottom-up (heapify in-place).
824
+
825
+ #### Returns
826
+
827
+ `boolean`[]
828
+
829
+ Array of per-node results from fixing steps.
830
+
831
+ #### Remarks
832
+
833
+ Time O(N), Space O(1)
834
+
835
+ #### Inherited from
836
+
837
+ [`PriorityQueue`](PriorityQueue.md).[`fix`](PriorityQueue.md#fix)
838
+
839
+ ***
840
+
841
+ ### forEach()
842
+
843
+ ```ts
844
+ forEach(callbackfn, thisArg?): void;
845
+ ```
846
+
847
+ Defined in: [data-structures/base/iterable-element-base.ts:132](https://github.com/zrwusa/data-structure-typed/blob/2f6ceb3aee852228efc88b111e19c0809753e805/src/data-structures/base/iterable-element-base.ts#L132)
848
+
849
+ Invokes a callback for each element in iteration order.
850
+
851
+ #### Parameters
852
+
853
+ ##### callbackfn
854
+
855
+ `ElementCallback`\<`E`, `R`, `void`\>
856
+
857
+ Function invoked per element with signature `(value, index, self)`.
858
+
859
+ ##### thisArg?
860
+
861
+ `unknown`
862
+
863
+ Optional `this` binding for the callback.
864
+
865
+ #### Returns
866
+
867
+ `void`
868
+
869
+ `void`.
870
+
871
+ #### Remarks
872
+
873
+ Time O(n), Space O(1).
874
+
875
+ #### Inherited from
876
+
877
+ [`PriorityQueue`](PriorityQueue.md).[`forEach`](PriorityQueue.md#foreach)
878
+
879
+ ***
880
+
881
+ ### has()
882
+
883
+ ```ts
884
+ has(element): boolean;
885
+ ```
886
+
887
+ Defined in: [data-structures/heap/heap.ts:674](https://github.com/zrwusa/data-structure-typed/blob/2f6ceb3aee852228efc88b111e19c0809753e805/src/data-structures/heap/heap.ts#L674)
888
+
889
+ Check if an equal element exists in the heap.
890
+
891
+ #### Parameters
892
+
893
+ ##### element
894
+
895
+ `E`
896
+
897
+ Element to search for.
898
+
899
+ #### Returns
900
+
901
+ `boolean`
902
+
903
+ True if found.
904
+
905
+ *
906
+
907
+ #### Remarks
908
+
909
+ Time O(N), Space O(1)
910
+
911
+ #### Example
912
+
913
+ ```ts
914
+ // Check element existence
915
+ const heap = new Heap<number>([3, 1, 2], { comparator: (a, b) => a - b });
916
+ console.log(heap.has(1)); // true;
917
+ console.log(heap.has(99)); // false;
918
+ ```
919
+
920
+ #### Inherited from
921
+
922
+ [`PriorityQueue`](PriorityQueue.md).[`has`](PriorityQueue.md#has)
923
+
924
+ ***
925
+
926
+ ### isEmpty()
927
+
928
+ ```ts
929
+ isEmpty(): boolean;
930
+ ```
931
+
932
+ Defined in: [data-structures/heap/heap.ts:586](https://github.com/zrwusa/data-structure-typed/blob/2f6ceb3aee852228efc88b111e19c0809753e805/src/data-structures/heap/heap.ts#L586)
933
+
934
+ Check whether the heap is empty.
935
+
936
+ #### Returns
937
+
938
+ `boolean`
939
+
940
+ True if size is 0.
941
+
942
+ *
943
+
944
+ #### Remarks
945
+
946
+ Time O(1), Space O(1)
947
+
948
+ #### Example
949
+
950
+ ```ts
951
+ // Check if heap is empty
952
+ const heap = new Heap<number>([], { comparator: (a, b) => a - b });
953
+ console.log(heap.isEmpty()); // true;
954
+ heap.add(1);
955
+ console.log(heap.isEmpty()); // false;
956
+ ```
957
+
958
+ #### Inherited from
959
+
960
+ [`PriorityQueue`](PriorityQueue.md).[`isEmpty`](PriorityQueue.md#isempty)
961
+
962
+ ***
963
+
964
+ ### map()
965
+
966
+ ```ts
967
+ map<EM, RM>(
968
+ callback,
969
+ options,
970
+ thisArg?): Heap<EM, RM>;
971
+ ```
972
+
973
+ Defined in: [data-structures/heap/heap.ts:1035](https://github.com/zrwusa/data-structure-typed/blob/2f6ceb3aee852228efc88b111e19c0809753e805/src/data-structures/heap/heap.ts#L1035)
974
+
975
+ Map elements into a new heap of possibly different element type.
976
+
977
+ #### Type Parameters
978
+
979
+ ##### EM
980
+
981
+ `EM`
982
+
983
+ ##### RM
984
+
985
+ `RM`
986
+
987
+ #### Parameters
988
+
989
+ ##### callback
990
+
991
+ `ElementCallback`\<`E`, `R`, `EM`\>
992
+
993
+ Mapping function (element, index, heap) → newElement.
994
+
995
+ ##### options
996
+
997
+ `IterableElementBaseOptions`\<`EM`, `RM`\> & `object` & `object`
998
+
999
+ Options for the output heap, including comparator for EM.
1000
+
1001
+ ##### thisArg?
1002
+
1003
+ `unknown`
1004
+
1005
+ Value for `this` inside the callback.
1006
+
1007
+ #### Returns
1008
+
1009
+ [`Heap`](Heap.md)\<`EM`, `RM`\>
1010
+
1011
+ A new heap with mapped elements.
1012
+
1013
+ *
1014
+
1015
+ #### Remarks
1016
+
1017
+ Time O(N log N), Space O(N)
1018
+
1019
+ #### Example
1020
+
1021
+ ```ts
1022
+ // Transform elements
1023
+ const heap = new Heap<number>([1, 2, 3], { comparator: (a, b) => a - b });
1024
+ const doubled = heap.map(x => x * 2, { comparator: (a, b) => a - b });
1025
+ console.log(doubled.peek()); // 2;
1026
+ ```
1027
+
1028
+ #### Inherited from
1029
+
1030
+ [`PriorityQueue`](PriorityQueue.md).[`map`](PriorityQueue.md#map)
1031
+
1032
+ ***
1033
+
1034
+ ### mapSame()
1035
+
1036
+ ```ts
1037
+ mapSame(callback, thisArg?): this;
1038
+ ```
1039
+
1040
+ Defined in: [data-structures/heap/heap.ts:1059](https://github.com/zrwusa/data-structure-typed/blob/2f6ceb3aee852228efc88b111e19c0809753e805/src/data-structures/heap/heap.ts#L1059)
1041
+
1042
+ Map elements into a new heap of the same element type.
1043
+
1044
+ #### Parameters
1045
+
1046
+ ##### callback
1047
+
1048
+ `ElementCallback`\<`E`, `R`, `E`\>
1049
+
1050
+ Mapping function (element, index, heap) → element.
1051
+
1052
+ ##### thisArg?
1053
+
1054
+ `unknown`
1055
+
1056
+ Value for `this` inside the callback.
1057
+
1058
+ #### Returns
1059
+
1060
+ `this`
1061
+
1062
+ A new heap with mapped elements.
1063
+
1064
+ #### Remarks
1065
+
1066
+ Time O(N log N), Space O(N)
1067
+
1068
+ #### Inherited from
1069
+
1070
+ [`PriorityQueue`](PriorityQueue.md).[`mapSame`](PriorityQueue.md#mapsame)
1071
+
1072
+ ***
1073
+
1074
+ ### peek()
1075
+
1076
+ ```ts
1077
+ peek(): E | undefined;
1078
+ ```
1079
+
1080
+ Defined in: [data-structures/heap/heap.ts:544](https://github.com/zrwusa/data-structure-typed/blob/2f6ceb3aee852228efc88b111e19c0809753e805/src/data-structures/heap/heap.ts#L544)
1081
+
1082
+ Get the current top element without removing it.
1083
+
1084
+ #### Returns
1085
+
1086
+ `E` \| `undefined`
1087
+
1088
+ Top element or undefined.
1089
+
1090
+ *
1091
+
1092
+ #### Remarks
1093
+
1094
+ Time O(1), Space O(1)
1095
+
1096
+ #### Example
1097
+
1098
+ ```ts
1099
+ // Heap for event processing with priority
1100
+ interface Event {
1101
+ id: number;
1102
+ type: 'critical' | 'warning' | 'info';
1103
+ timestamp: number;
1104
+ message: string;
1105
+ }
1106
+
1107
+ // Custom priority: critical > warning > info
1108
+ const priorityMap = { critical: 3, warning: 2, info: 1 };
1109
+
1110
+ const eventHeap = new Heap<Event>([], {
1111
+ comparator: (a: Event, b: Event) => {
1112
+ const priorityA = priorityMap[a.type];
1113
+ const priorityB = priorityMap[b.type];
1114
+ return priorityB - priorityA; // Higher priority first
1115
+ }
1116
+ });
1117
+
1118
+ // Add events in random order
1119
+ eventHeap.add({ id: 1, type: 'info', timestamp: 100, message: 'User logged in' });
1120
+ eventHeap.add({ id: 2, type: 'critical', timestamp: 101, message: 'Server down' });
1121
+ eventHeap.add({ id: 3, type: 'warning', timestamp: 102, message: 'High memory' });
1122
+ eventHeap.add({ id: 4, type: 'info', timestamp: 103, message: 'Cache cleared' });
1123
+ eventHeap.add({ id: 5, type: 'critical', timestamp: 104, message: 'Database error' });
1124
+
1125
+ console.log(eventHeap.size); // 5;
1126
+
1127
+ // Process events by priority (critical first)
1128
+ const processedOrder: Event[] = [];
1129
+ while (eventHeap.size > 0) {
1130
+ const event = eventHeap.poll();
1131
+ if (event) {
1132
+ processedOrder.push(event);
1133
+ }
1134
+ }
1135
+
1136
+ // Verify critical events came first
1137
+ console.log(processedOrder[0].type); // 'critical';
1138
+ console.log(processedOrder[1].type); // 'critical';
1139
+ console.log(processedOrder[2].type); // 'warning';
1140
+ console.log(processedOrder[3].type); // 'info';
1141
+ console.log(processedOrder[4].type); // 'info';
1142
+
1143
+ // Verify O(log n) operations
1144
+ const newHeap = new Heap<number>([5, 3, 7, 1]);
1145
+
1146
+ // Add - O(log n)
1147
+ newHeap.add(2);
1148
+ console.log(newHeap.size); // 5;
1149
+
1150
+ // Poll - O(log n)
1151
+ const removed = newHeap.poll();
1152
+ console.log(removed); // 1;
1153
+
1154
+ // Peek - O(1)
1155
+ const top = newHeap.peek();
1156
+ console.log(top); // 2;
1157
+ ```
1158
+
1159
+ #### Inherited from
1160
+
1161
+ [`PriorityQueue`](PriorityQueue.md).[`peek`](PriorityQueue.md#peek)
1162
+
1163
+ ***
1164
+
1165
+ ### poll()
1166
+
1167
+ ```ts
1168
+ poll(): E | undefined;
1169
+ ```
1170
+
1171
+ Defined in: [data-structures/heap/heap.ts:440](https://github.com/zrwusa/data-structure-typed/blob/2f6ceb3aee852228efc88b111e19c0809753e805/src/data-structures/heap/heap.ts#L440)
1172
+
1173
+ Remove and return the top element.
1174
+
1175
+ #### Returns
1176
+
1177
+ `E` \| `undefined`
1178
+
1179
+ Top element or undefined.
1180
+
1181
+ *
1182
+
1183
+ #### Remarks
1184
+
1185
+ Time O(log N), Space O(1)
1186
+
1187
+ #### Example
1188
+
1189
+ ```ts
1190
+ // Heap with custom comparator (MaxHeap behavior)
1191
+ interface Task {
1192
+ id: number;
1193
+ priority: number;
1194
+ name: string;
1195
+ }
1196
+
1197
+ // Custom comparator for max heap behavior (higher priority first)
1198
+ const tasks: Task[] = [
1199
+ { id: 1, priority: 5, name: 'Email' },
1200
+ { id: 2, priority: 3, name: 'Chat' },
1201
+ { id: 3, priority: 8, name: 'Alert' }
1202
+ ];
1203
+
1204
+ const maxHeap = new Heap(tasks, {
1205
+ comparator: (a: Task, b: Task) => b.priority - a.priority
1206
+ });
1207
+
1208
+ console.log(maxHeap.size); // 3;
1209
+
1210
+ // Peek returns highest priority task
1211
+ const topTask = maxHeap.peek();
1212
+ console.log(topTask?.priority); // 8;
1213
+ console.log(topTask?.name); // 'Alert';
1214
+ ```
1215
+
1216
+ #### Inherited from
1217
+
1218
+ [`PriorityQueue`](PriorityQueue.md).[`poll`](PriorityQueue.md#poll)
1219
+
1220
+ ***
1221
+
1222
+ ### print()
1223
+
1224
+ ```ts
1225
+ print(): void;
1226
+ ```
1227
+
1228
+ Defined in: [data-structures/base/iterable-element-base.ts:268](https://github.com/zrwusa/data-structure-typed/blob/2f6ceb3aee852228efc88b111e19c0809753e805/src/data-structures/base/iterable-element-base.ts#L268)
1229
+
1230
+ Prints `toVisual()` to the console. Intended for quick debugging.
1231
+
1232
+ #### Returns
1233
+
1234
+ `void`
1235
+
1236
+ `void`.
1237
+
1238
+ #### Remarks
1239
+
1240
+ Time O(n) due to materialization, Space O(n) for the intermediate representation.
1241
+
1242
+ #### Inherited from
1243
+
1244
+ [`PriorityQueue`](PriorityQueue.md).[`print`](PriorityQueue.md#print)
1245
+
1246
+ ***
1247
+
1248
+ ### reduce()
1249
+
1250
+ Reduces all elements to a single accumulated value.
1251
+
1252
+ #### Param
1253
+
1254
+ Reducer of signature `(acc, value, index, self) => nextAcc`. The first element is used as the initial accumulator.
1255
+
1256
+ #### Param
1257
+
1258
+ Reducer of signature `(acc, value, index, self) => nextAcc`.
1259
+
1260
+ #### Param
1261
+
1262
+ The initial accumulator value of type `E`.
1263
+
1264
+ #### Template
1265
+
1266
+ The accumulator type when it differs from `E`.
1267
+
1268
+ #### Param
1269
+
1270
+ Reducer of signature `(acc: U, value, index, self) => U`.
1271
+
1272
+ #### Param
1273
+
1274
+ The initial accumulator value of type `U`.
1275
+
1276
+ #### Remarks
1277
+
1278
+ Time O(n), Space O(1). Throws if called on an empty structure without `initialValue`.
1279
+
1280
+ #### Call Signature
1281
+
1282
+ ```ts
1283
+ reduce(callbackfn): E;
1284
+ ```
1285
+
1286
+ Defined in: [data-structures/base/iterable-element-base.ts:193](https://github.com/zrwusa/data-structure-typed/blob/2f6ceb3aee852228efc88b111e19c0809753e805/src/data-structures/base/iterable-element-base.ts#L193)
1287
+
1288
+ ##### Parameters
1289
+
1290
+ ###### callbackfn
1291
+
1292
+ `ReduceElementCallback`\<`E`, `R`\>
1293
+
1294
+ ##### Returns
1295
+
1296
+ `E`
1297
+
1298
+ ##### Inherited from
1299
+
1300
+ [`PriorityQueue`](PriorityQueue.md).[`reduce`](PriorityQueue.md#reduce)
1301
+
1302
+ #### Call Signature
1303
+
1304
+ ```ts
1305
+ reduce(callbackfn, initialValue): E;
1306
+ ```
1307
+
1308
+ Defined in: [data-structures/base/iterable-element-base.ts:194](https://github.com/zrwusa/data-structure-typed/blob/2f6ceb3aee852228efc88b111e19c0809753e805/src/data-structures/base/iterable-element-base.ts#L194)
1309
+
1310
+ ##### Parameters
1311
+
1312
+ ###### callbackfn
1313
+
1314
+ `ReduceElementCallback`\<`E`, `R`\>
1315
+
1316
+ ###### initialValue
1317
+
1318
+ `E`
1319
+
1320
+ ##### Returns
1321
+
1322
+ `E`
1323
+
1324
+ ##### Inherited from
1325
+
1326
+ [`PriorityQueue`](PriorityQueue.md).[`reduce`](PriorityQueue.md#reduce)
1327
+
1328
+ #### Call Signature
1329
+
1330
+ ```ts
1331
+ reduce<U>(callbackfn, initialValue): U;
1332
+ ```
1333
+
1334
+ Defined in: [data-structures/base/iterable-element-base.ts:195](https://github.com/zrwusa/data-structure-typed/blob/2f6ceb3aee852228efc88b111e19c0809753e805/src/data-structures/base/iterable-element-base.ts#L195)
1335
+
1336
+ ##### Type Parameters
1337
+
1338
+ ###### U
1339
+
1340
+ `U`
1341
+
1342
+ ##### Parameters
1343
+
1344
+ ###### callbackfn
1345
+
1346
+ `ReduceElementCallback`\<`E`, `R`, `U`\>
1347
+
1348
+ ###### initialValue
1349
+
1350
+ `U`
1351
+
1352
+ ##### Returns
1353
+
1354
+ `U`
1355
+
1356
+ ##### Inherited from
1357
+
1358
+ [`PriorityQueue`](PriorityQueue.md).[`reduce`](PriorityQueue.md#reduce)
1359
+
1360
+ ***
1361
+
1362
+ ### refill()
1363
+
1364
+ ```ts
1365
+ refill(elements): boolean[];
1366
+ ```
1367
+
1368
+ Defined in: [data-structures/heap/heap.ts:638](https://github.com/zrwusa/data-structure-typed/blob/2f6ceb3aee852228efc88b111e19c0809753e805/src/data-structures/heap/heap.ts#L638)
1369
+
1370
+ Replace the backing array and rebuild the heap.
1371
+
1372
+ #### Parameters
1373
+
1374
+ ##### elements
1375
+
1376
+ `Iterable`\<`E`\>
1377
+
1378
+ Iterable used to refill the heap.
1379
+
1380
+ #### Returns
1381
+
1382
+ `boolean`[]
1383
+
1384
+ Array of per-node results from fixing steps.
1385
+
1386
+ #### Remarks
1387
+
1388
+ Time O(N), Space O(N)
1389
+
1390
+ #### Inherited from
1391
+
1392
+ [`PriorityQueue`](PriorityQueue.md).[`refill`](PriorityQueue.md#refill)
1393
+
1394
+ ***
1395
+
1396
+ ### setEquality()
1397
+
1398
+ ```ts
1399
+ setEquality(equals): this;
1400
+ ```
1401
+
1402
+ Defined in: [data-structures/heap/heap.ts:772](https://github.com/zrwusa/data-structure-typed/blob/2f6ceb3aee852228efc88b111e19c0809753e805/src/data-structures/heap/heap.ts#L772)
1403
+
1404
+ Set the equality comparator used by has/delete operations.
1405
+
1406
+ #### Parameters
1407
+
1408
+ ##### equals
1409
+
1410
+ (`a`, `b`) => `boolean`
1411
+
1412
+ Equality predicate (a, b) → boolean.
1413
+
1414
+ #### Returns
1415
+
1416
+ `this`
1417
+
1418
+ This heap.
1419
+
1420
+ #### Remarks
1421
+
1422
+ Time O(1), Space O(1)
1423
+
1424
+ #### Inherited from
1425
+
1426
+ [`PriorityQueue`](PriorityQueue.md).[`setEquality`](PriorityQueue.md#setequality)
1427
+
1428
+ ***
1429
+
1430
+ ### some()
1431
+
1432
+ ```ts
1433
+ some(predicate, thisArg?): boolean;
1434
+ ```
1435
+
1436
+ Defined in: [data-structures/base/iterable-element-base.ts:109](https://github.com/zrwusa/data-structure-typed/blob/2f6ceb3aee852228efc88b111e19c0809753e805/src/data-structures/base/iterable-element-base.ts#L109)
1437
+
1438
+ Tests whether at least one element satisfies the predicate.
1439
+
1440
+ #### Parameters
1441
+
1442
+ ##### predicate
1443
+
1444
+ `ElementCallback`\<`E`, `R`, `boolean`\>
1445
+
1446
+ Function invoked for each element with signature `(value, index, self)`.
1447
+
1448
+ ##### thisArg?
1449
+
1450
+ `unknown`
1451
+
1452
+ Optional `this` binding for the predicate.
1453
+
1454
+ #### Returns
1455
+
1456
+ `boolean`
1457
+
1458
+ `true` if any element passes; otherwise `false`.
1459
+
1460
+ #### Remarks
1461
+
1462
+ Time O(n) in the worst case; may exit early on first success. Space O(1).
1463
+
1464
+ #### Inherited from
1465
+
1466
+ [`PriorityQueue`](PriorityQueue.md).[`some`](PriorityQueue.md#some)
1467
+
1468
+ ***
1469
+
1470
+ ### sort()
1471
+
1472
+ ```ts
1473
+ sort(): E[];
1474
+ ```
1475
+
1476
+ Defined in: [data-structures/heap/heap.ts:886](https://github.com/zrwusa/data-structure-typed/blob/2f6ceb3aee852228efc88b111e19c0809753e805/src/data-structures/heap/heap.ts#L886)
1477
+
1478
+ Return all elements in ascending order by repeatedly polling.
1479
+
1480
+ #### Returns
1481
+
1482
+ `E`[]
1483
+
1484
+ Sorted array of elements.
1485
+
1486
+ *
1487
+
1488
+ #### Remarks
1489
+
1490
+ Time O(N log N), Space O(N)
1491
+
1492
+ #### Example
1493
+
1494
+ ```ts
1495
+ // Sort elements using heap
1496
+ const heap = new Heap<number>([5, 1, 3, 2, 4]);
1497
+ const sorted = heap.sort();
1498
+ console.log(sorted); // [1, 2, 3, 4, 5];
1499
+ ```
1500
+
1501
+ #### Inherited from
1502
+
1503
+ [`PriorityQueue`](PriorityQueue.md).[`sort`](PriorityQueue.md#sort)
1504
+
1505
+ ***
1506
+
1507
+ ### toArray()
1508
+
1509
+ ```ts
1510
+ toArray(): E[];
1511
+ ```
1512
+
1513
+ Defined in: [data-structures/base/iterable-element-base.ts:245](https://github.com/zrwusa/data-structure-typed/blob/2f6ceb3aee852228efc88b111e19c0809753e805/src/data-structures/base/iterable-element-base.ts#L245)
1514
+
1515
+ Materializes the elements into a new array.
1516
+
1517
+ #### Returns
1518
+
1519
+ `E`[]
1520
+
1521
+ A shallow array copy of the iteration order.
1522
+
1523
+ #### Remarks
1524
+
1525
+ Time O(n), Space O(n).
1526
+
1527
+ #### Inherited from
1528
+
1529
+ [`PriorityQueue`](PriorityQueue.md).[`toArray`](PriorityQueue.md#toarray)
1530
+
1531
+ ***
1532
+
1533
+ ### toVisual()
1534
+
1535
+ ```ts
1536
+ toVisual(): E[];
1537
+ ```
1538
+
1539
+ Defined in: [data-structures/base/iterable-element-base.ts:257](https://github.com/zrwusa/data-structure-typed/blob/2f6ceb3aee852228efc88b111e19c0809753e805/src/data-structures/base/iterable-element-base.ts#L257)
1540
+
1541
+ Returns a representation of the structure suitable for quick visualization.
1542
+ Defaults to an array of elements; subclasses may override to provide richer visuals.
1543
+
1544
+ #### Returns
1545
+
1546
+ `E`[]
1547
+
1548
+ A visual representation (array by default).
1549
+
1550
+ #### Remarks
1551
+
1552
+ Time O(n), Space O(n).
1553
+
1554
+ #### Inherited from
1555
+
1556
+ [`PriorityQueue`](PriorityQueue.md).[`toVisual`](PriorityQueue.md#tovisual)
1557
+
1558
+ ***
1559
+
1560
+ ### values()
1561
+
1562
+ ```ts
1563
+ values(): IterableIterator<E>;
1564
+ ```
1565
+
1566
+ Defined in: [data-structures/base/iterable-element-base.ts:71](https://github.com/zrwusa/data-structure-typed/blob/2f6ceb3aee852228efc88b111e19c0809753e805/src/data-structures/base/iterable-element-base.ts#L71)
1567
+
1568
+ Returns an iterator over the values (alias of the default iterator).
1569
+
1570
+ #### Returns
1571
+
1572
+ `IterableIterator`\<`E`\>
1573
+
1574
+ An `IterableIterator<E>` over all elements.
1575
+
1576
+ #### Remarks
1577
+
1578
+ Creating the iterator is O(1); full iteration is Time O(n), Space O(1).
1579
+
1580
+ #### Inherited from
1581
+
1582
+ [`PriorityQueue`](PriorityQueue.md).[`values`](PriorityQueue.md#values)
1583
+
1584
+ ***
1585
+
1586
+ ### from()
1587
+
1588
+ ```ts
1589
+ static from<T, R, S>(
1590
+ this,
1591
+ elements?,
1592
+ options?): S;
1593
+ ```
1594
+
1595
+ Defined in: [data-structures/heap/heap.ts:252](https://github.com/zrwusa/data-structure-typed/blob/2f6ceb3aee852228efc88b111e19c0809753e805/src/data-structures/heap/heap.ts#L252)
1596
+
1597
+ Create a heap of the same class from an iterable.
1598
+
1599
+ #### Type Parameters
1600
+
1601
+ ##### T
1602
+
1603
+ `T`
1604
+
1605
+ ##### R
1606
+
1607
+ `R` = `any`
1608
+
1609
+ ##### S
1610
+
1611
+ `S` *extends* [`Heap`](Heap.md)\<`T`, `R`\> = [`Heap`](Heap.md)\<`T`, `R`\>
1612
+
1613
+ #### Parameters
1614
+
1615
+ ##### this
1616
+
1617
+ `Object`
1618
+
1619
+ ##### elements?
1620
+
1621
+ `Iterable`\<`T` \| `R`, `any`, `any`\>
1622
+
1623
+ Iterable of elements or raw records.
1624
+
1625
+ ##### options?
1626
+
1627
+ `HeapOptions`\<`T`, `R`\>
1628
+
1629
+ Heap options including comparator.
1630
+
1631
+ #### Returns
1632
+
1633
+ `S`
1634
+
1635
+ A new heap instance of this class.
1636
+
1637
+ #### Remarks
1638
+
1639
+ Time O(N), Space O(N)
1640
+
1641
+ #### Inherited from
1642
+
1643
+ [`PriorityQueue`](PriorityQueue.md).[`from`](PriorityQueue.md#from)
1644
+
1645
+ ***
1646
+
1647
+ ### heapify()
1648
+
1649
+ ```ts
1650
+ static heapify<EE, RR>(elements, options): Heap<EE, RR>;
1651
+ ```
1652
+
1653
+ Defined in: [data-structures/heap/heap.ts:270](https://github.com/zrwusa/data-structure-typed/blob/2f6ceb3aee852228efc88b111e19c0809753e805/src/data-structures/heap/heap.ts#L270)
1654
+
1655
+ Build a Heap from an iterable in linear time given a comparator.
1656
+
1657
+ #### Type Parameters
1658
+
1659
+ ##### EE
1660
+
1661
+ `EE` = `any`
1662
+
1663
+ ##### RR
1664
+
1665
+ `RR` = `any`
1666
+
1667
+ #### Parameters
1668
+
1669
+ ##### elements
1670
+
1671
+ `Iterable`\<`EE`\>
1672
+
1673
+ Iterable of elements.
1674
+
1675
+ ##### options
1676
+
1677
+ `HeapOptions`\<`EE`, `RR`\>
1678
+
1679
+ Heap options including comparator.
1680
+
1681
+ #### Returns
1682
+
1683
+ [`Heap`](Heap.md)\<`EE`, `RR`\>
1684
+
1685
+ A new Heap built from elements.
1686
+
1687
+ #### Remarks
1688
+
1689
+ Time O(N), Space O(N)
1690
+
1691
+ #### Inherited from
1692
+
1693
+ [`PriorityQueue`](PriorityQueue.md).[`heapify`](PriorityQueue.md#heapify)
1694
+
1695
+
1696
+ ---
1697
+
1698
+ ## Protected Members
1699
+
1700
+ ### \_toElementFn?
1701
+
1702
+ ```ts
1703
+ protected optional _toElementFn?: (rawElement) => E;
1704
+ ```
1705
+
1706
+ Defined in: [data-structures/base/iterable-element-base.ts:38](https://github.com/zrwusa/data-structure-typed/blob/2f6ceb3aee852228efc88b111e19c0809753e805/src/data-structures/base/iterable-element-base.ts#L38)
1707
+
1708
+ The converter used to transform a raw element (`R`) into a public element (`E`).
1709
+
1710
+ #### Parameters
1711
+
1712
+ ##### rawElement
1713
+
1714
+ `R`
1715
+
1716
+ #### Returns
1717
+
1718
+ `E`
1719
+
1720
+ #### Remarks
1721
+
1722
+ Time O(1), Space O(1).
1723
+
1724
+ #### Inherited from
1725
+
1726
+ [`PriorityQueue`](PriorityQueue.md).[`_toElementFn`](PriorityQueue.md#_toelementfn)
1727
+
1728
+ ## Accessors
1729
+
1730
+ ### \_createInstance()
1731
+
1732
+ ```ts
1733
+ protected _createInstance(options?): this;
1734
+ ```
1735
+
1736
+ Defined in: [data-structures/heap/heap.ts:1132](https://github.com/zrwusa/data-structure-typed/blob/2f6ceb3aee852228efc88b111e19c0809753e805/src/data-structures/heap/heap.ts#L1132)
1737
+
1738
+ (Protected) Create an empty instance of the same concrete class.
1739
+
1740
+ #### Parameters
1741
+
1742
+ ##### options?
1743
+
1744
+ `HeapOptions`\<`E`, `R`\>
1745
+
1746
+ Options to override comparator or toElementFn.
1747
+
1748
+ #### Returns
1749
+
1750
+ `this`
1751
+
1752
+ A like-kind empty heap instance.
1753
+
1754
+ #### Remarks
1755
+
1756
+ Time O(1), Space O(1)
1757
+
1758
+ #### Inherited from
1759
+
1760
+ [`PriorityQueue`](PriorityQueue.md).[`_createInstance`](PriorityQueue.md#_createinstance)
1761
+
1762
+ ***
1763
+
1764
+ ### \_createLike()
1765
+
1766
+ ```ts
1767
+ protected _createLike<EM, RM>(elements?, options?): Heap<EM, RM>;
1768
+ ```
1769
+
1770
+ Defined in: [data-structures/heap/heap.ts:1150](https://github.com/zrwusa/data-structure-typed/blob/2f6ceb3aee852228efc88b111e19c0809753e805/src/data-structures/heap/heap.ts#L1150)
1771
+
1772
+ (Protected) Create a like-kind instance seeded by elements.
1773
+
1774
+ #### Type Parameters
1775
+
1776
+ ##### EM
1777
+
1778
+ `EM`
1779
+
1780
+ ##### RM
1781
+
1782
+ `RM`
1783
+
1784
+ #### Parameters
1785
+
1786
+ ##### elements?
1787
+
1788
+ `Iterable`\<`EM`, `any`, `any`\> \| `Iterable`\<`RM`, `any`, `any`\>
1789
+
1790
+ Iterable of elements or raw values to seed.
1791
+
1792
+ ##### options?
1793
+
1794
+ `HeapOptions`\<`EM`, `RM`\>
1795
+
1796
+ Options forwarded to the constructor.
1797
+
1798
+ #### Returns
1799
+
1800
+ [`Heap`](Heap.md)\<`EM`, `RM`\>
1801
+
1802
+ A like-kind heap instance.
1803
+
1804
+ #### Remarks
1805
+
1806
+ Time O(N log N), Space O(N)
1807
+
1808
+ #### Inherited from
1809
+
1810
+ [`PriorityQueue`](PriorityQueue.md).[`_createLike`](PriorityQueue.md#_createlike)
1811
+
1812
+ ***
1813
+
1814
+ ### \_getIterator()
1815
+
1816
+ ```ts
1817
+ protected _getIterator(): IterableIterator<E>;
1818
+ ```
1819
+
1820
+ Defined in: [data-structures/heap/heap.ts:1090](https://github.com/zrwusa/data-structure-typed/blob/2f6ceb3aee852228efc88b111e19c0809753e805/src/data-structures/heap/heap.ts#L1090)
1821
+
1822
+ Internal iterator factory used by the default iterator.
1823
+
1824
+ #### Returns
1825
+
1826
+ `IterableIterator`\<`E`\>
1827
+
1828
+ An iterator over elements.
1829
+
1830
+ #### Remarks
1831
+
1832
+ Implementations should yield in O(1) per element with O(1) extra space when possible.
1833
+
1834
+ #### Inherited from
1835
+
1836
+ [`PriorityQueue`](PriorityQueue.md).[`_getIterator`](PriorityQueue.md#_getiterator)
1837
+
1838
+ ***
1839
+
1840
+ ### \_spawnLike()
1841
+
1842
+ ```ts
1843
+ protected _spawnLike<EM, RM>(options?): Heap<EM, RM>;
1844
+ ```
1845
+
1846
+ Defined in: [data-structures/heap/heap.ts:1170](https://github.com/zrwusa/data-structure-typed/blob/2f6ceb3aee852228efc88b111e19c0809753e805/src/data-structures/heap/heap.ts#L1170)
1847
+
1848
+ (Protected) Spawn an empty like-kind heap instance.
1849
+
1850
+ #### Type Parameters
1851
+
1852
+ ##### EM
1853
+
1854
+ `EM`
1855
+
1856
+ ##### RM
1857
+
1858
+ `RM`
1859
+
1860
+ #### Parameters
1861
+
1862
+ ##### options?
1863
+
1864
+ `HeapOptions`\<`EM`, `RM`\>
1865
+
1866
+ Options forwarded to the constructor.
1867
+
1868
+ #### Returns
1869
+
1870
+ [`Heap`](Heap.md)\<`EM`, `RM`\>
1871
+
1872
+ An empty like-kind heap instance.
1873
+
1874
+ #### Remarks
1875
+
1876
+ Time O(1), Space O(1)
1877
+
1878
+ #### Inherited from
1879
+
1880
+ [`PriorityQueue`](PriorityQueue.md).[`_spawnLike`](PriorityQueue.md#_spawnlike)
1881
+
1882
+ ***