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