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