data-structure-typed 2.5.0 → 2.5.2

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