red-black-tree-typed 1.47.3

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 (341) hide show
  1. package/.eslintrc.js +61 -0
  2. package/.prettierignore +6 -0
  3. package/.prettierrc.js +16 -0
  4. package/LICENSE +21 -0
  5. package/README.md +713 -0
  6. package/coverage/clover.xml +13 -0
  7. package/coverage/coverage-final.json +96 -0
  8. package/coverage/coverage-summary.json +60 -0
  9. package/coverage/lcov-report/base.css +403 -0
  10. package/coverage/lcov-report/block-navigation.js +87 -0
  11. package/coverage/lcov-report/favicon.png +0 -0
  12. package/coverage/lcov-report/index.html +119 -0
  13. package/coverage/lcov-report/index.ts.html +109 -0
  14. package/coverage/lcov-report/prettify.css +1 -0
  15. package/coverage/lcov-report/prettify.js +2 -0
  16. package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
  17. package/coverage/lcov-report/sorter.js +206 -0
  18. package/coverage/lcov.info +14 -0
  19. package/dist/data-structures/binary-tree/avl-tree.d.ts +173 -0
  20. package/dist/data-structures/binary-tree/avl-tree.js +429 -0
  21. package/dist/data-structures/binary-tree/binary-indexed-tree.d.ts +149 -0
  22. package/dist/data-structures/binary-tree/binary-indexed-tree.js +269 -0
  23. package/dist/data-structures/binary-tree/binary-tree.d.ts +515 -0
  24. package/dist/data-structures/binary-tree/binary-tree.js +1665 -0
  25. package/dist/data-structures/binary-tree/bst.d.ts +253 -0
  26. package/dist/data-structures/binary-tree/bst.js +651 -0
  27. package/dist/data-structures/binary-tree/index.d.ts +7 -0
  28. package/dist/data-structures/binary-tree/index.js +23 -0
  29. package/dist/data-structures/binary-tree/rb-tree.d.ts +169 -0
  30. package/dist/data-structures/binary-tree/rb-tree.js +524 -0
  31. package/dist/data-structures/binary-tree/segment-tree.d.ts +67 -0
  32. package/dist/data-structures/binary-tree/segment-tree.js +180 -0
  33. package/dist/data-structures/binary-tree/tree-multimap.d.ts +162 -0
  34. package/dist/data-structures/binary-tree/tree-multimap.js +407 -0
  35. package/dist/data-structures/graph/abstract-graph.d.ts +450 -0
  36. package/dist/data-structures/graph/abstract-graph.js +1047 -0
  37. package/dist/data-structures/graph/directed-graph.d.ts +320 -0
  38. package/dist/data-structures/graph/directed-graph.js +530 -0
  39. package/dist/data-structures/graph/index.d.ts +4 -0
  40. package/dist/data-structures/graph/index.js +20 -0
  41. package/dist/data-structures/graph/map-graph.d.ts +73 -0
  42. package/dist/data-structures/graph/map-graph.js +93 -0
  43. package/dist/data-structures/graph/undirected-graph.d.ts +183 -0
  44. package/dist/data-structures/graph/undirected-graph.js +302 -0
  45. package/dist/data-structures/hash/hash-map.d.ts +186 -0
  46. package/dist/data-structures/hash/hash-map.js +367 -0
  47. package/dist/data-structures/hash/hash-table.d.ts +103 -0
  48. package/dist/data-structures/hash/hash-table.js +236 -0
  49. package/dist/data-structures/hash/index.d.ts +2 -0
  50. package/dist/data-structures/hash/index.js +18 -0
  51. package/dist/data-structures/heap/heap.d.ts +410 -0
  52. package/dist/data-structures/heap/heap.js +697 -0
  53. package/dist/data-structures/heap/index.d.ts +3 -0
  54. package/dist/data-structures/heap/index.js +19 -0
  55. package/dist/data-structures/heap/max-heap.d.ts +15 -0
  56. package/dist/data-structures/heap/max-heap.js +26 -0
  57. package/dist/data-structures/heap/min-heap.d.ts +15 -0
  58. package/dist/data-structures/heap/min-heap.js +26 -0
  59. package/dist/data-structures/index.d.ts +11 -0
  60. package/dist/data-structures/index.js +27 -0
  61. package/dist/data-structures/linked-list/doubly-linked-list.d.ts +456 -0
  62. package/dist/data-structures/linked-list/doubly-linked-list.js +772 -0
  63. package/dist/data-structures/linked-list/index.d.ts +3 -0
  64. package/dist/data-structures/linked-list/index.js +19 -0
  65. package/dist/data-structures/linked-list/singly-linked-list.d.ts +414 -0
  66. package/dist/data-structures/linked-list/singly-linked-list.js +715 -0
  67. package/dist/data-structures/linked-list/skip-linked-list.d.ts +144 -0
  68. package/dist/data-structures/linked-list/skip-linked-list.js +251 -0
  69. package/dist/data-structures/matrix/index.d.ts +4 -0
  70. package/dist/data-structures/matrix/index.js +20 -0
  71. package/dist/data-structures/matrix/matrix.d.ts +21 -0
  72. package/dist/data-structures/matrix/matrix.js +28 -0
  73. package/dist/data-structures/matrix/matrix2d.d.ts +107 -0
  74. package/dist/data-structures/matrix/matrix2d.js +199 -0
  75. package/dist/data-structures/matrix/navigator.d.ts +52 -0
  76. package/dist/data-structures/matrix/navigator.js +106 -0
  77. package/dist/data-structures/matrix/vector2d.d.ts +200 -0
  78. package/dist/data-structures/matrix/vector2d.js +290 -0
  79. package/dist/data-structures/priority-queue/index.d.ts +3 -0
  80. package/dist/data-structures/priority-queue/index.js +19 -0
  81. package/dist/data-structures/priority-queue/max-priority-queue.d.ts +15 -0
  82. package/dist/data-structures/priority-queue/max-priority-queue.js +26 -0
  83. package/dist/data-structures/priority-queue/min-priority-queue.d.ts +15 -0
  84. package/dist/data-structures/priority-queue/min-priority-queue.js +26 -0
  85. package/dist/data-structures/priority-queue/priority-queue.d.ts +15 -0
  86. package/dist/data-structures/priority-queue/priority-queue.js +17 -0
  87. package/dist/data-structures/queue/deque.d.ts +572 -0
  88. package/dist/data-structures/queue/deque.js +990 -0
  89. package/dist/data-structures/queue/index.d.ts +2 -0
  90. package/dist/data-structures/queue/index.js +18 -0
  91. package/dist/data-structures/queue/queue.d.ts +209 -0
  92. package/dist/data-structures/queue/queue.js +274 -0
  93. package/dist/data-structures/stack/index.d.ts +1 -0
  94. package/dist/data-structures/stack/index.js +17 -0
  95. package/dist/data-structures/stack/stack.d.ts +106 -0
  96. package/dist/data-structures/stack/stack.js +136 -0
  97. package/dist/data-structures/tree/index.d.ts +1 -0
  98. package/dist/data-structures/tree/index.js +17 -0
  99. package/dist/data-structures/tree/tree.d.ts +8 -0
  100. package/dist/data-structures/tree/tree.js +40 -0
  101. package/dist/data-structures/trie/index.d.ts +1 -0
  102. package/dist/data-structures/trie/index.js +17 -0
  103. package/dist/data-structures/trie/trie.d.ts +155 -0
  104. package/dist/data-structures/trie/trie.js +326 -0
  105. package/dist/index.d.ts +10 -0
  106. package/dist/index.js +27 -0
  107. package/dist/interfaces/binary-tree.d.ts +7 -0
  108. package/dist/interfaces/binary-tree.js +2 -0
  109. package/dist/interfaces/doubly-linked-list.d.ts +1 -0
  110. package/dist/interfaces/doubly-linked-list.js +2 -0
  111. package/dist/interfaces/graph.d.ts +5 -0
  112. package/dist/interfaces/graph.js +2 -0
  113. package/dist/interfaces/heap.d.ts +1 -0
  114. package/dist/interfaces/heap.js +2 -0
  115. package/dist/interfaces/index.d.ts +8 -0
  116. package/dist/interfaces/index.js +24 -0
  117. package/dist/interfaces/navigator.d.ts +1 -0
  118. package/dist/interfaces/navigator.js +2 -0
  119. package/dist/interfaces/priority-queue.d.ts +1 -0
  120. package/dist/interfaces/priority-queue.js +2 -0
  121. package/dist/interfaces/segment-tree.d.ts +1 -0
  122. package/dist/interfaces/segment-tree.js +2 -0
  123. package/dist/interfaces/singly-linked-list.d.ts +1 -0
  124. package/dist/interfaces/singly-linked-list.js +2 -0
  125. package/dist/types/common.d.ts +20 -0
  126. package/dist/types/common.js +9 -0
  127. package/dist/types/data-structures/binary-tree/avl-tree.d.ts +5 -0
  128. package/dist/types/data-structures/binary-tree/avl-tree.js +2 -0
  129. package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +1 -0
  130. package/dist/types/data-structures/binary-tree/binary-indexed-tree.js +2 -0
  131. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +31 -0
  132. package/dist/types/data-structures/binary-tree/binary-tree.js +24 -0
  133. package/dist/types/data-structures/binary-tree/bst.d.ts +8 -0
  134. package/dist/types/data-structures/binary-tree/bst.js +2 -0
  135. package/dist/types/data-structures/binary-tree/index.d.ts +6 -0
  136. package/dist/types/data-structures/binary-tree/index.js +22 -0
  137. package/dist/types/data-structures/binary-tree/rb-tree.d.ts +9 -0
  138. package/dist/types/data-structures/binary-tree/rb-tree.js +8 -0
  139. package/dist/types/data-structures/binary-tree/segment-tree.d.ts +1 -0
  140. package/dist/types/data-structures/binary-tree/segment-tree.js +2 -0
  141. package/dist/types/data-structures/binary-tree/tree-multimap.d.ts +5 -0
  142. package/dist/types/data-structures/binary-tree/tree-multimap.js +2 -0
  143. package/dist/types/data-structures/graph/abstract-graph.d.ts +10 -0
  144. package/dist/types/data-structures/graph/abstract-graph.js +2 -0
  145. package/dist/types/data-structures/graph/directed-graph.d.ts +1 -0
  146. package/dist/types/data-structures/graph/directed-graph.js +2 -0
  147. package/dist/types/data-structures/graph/index.d.ts +3 -0
  148. package/dist/types/data-structures/graph/index.js +19 -0
  149. package/dist/types/data-structures/graph/map-graph.d.ts +1 -0
  150. package/dist/types/data-structures/graph/map-graph.js +2 -0
  151. package/dist/types/data-structures/graph/undirected-graph.d.ts +1 -0
  152. package/dist/types/data-structures/graph/undirected-graph.js +2 -0
  153. package/dist/types/data-structures/hash/hash-map.d.ts +11 -0
  154. package/dist/types/data-structures/hash/hash-map.js +2 -0
  155. package/dist/types/data-structures/hash/hash-table.d.ts +1 -0
  156. package/dist/types/data-structures/hash/hash-table.js +2 -0
  157. package/dist/types/data-structures/hash/index.d.ts +3 -0
  158. package/dist/types/data-structures/hash/index.js +18 -0
  159. package/dist/types/data-structures/heap/heap.d.ts +1 -0
  160. package/dist/types/data-structures/heap/heap.js +2 -0
  161. package/dist/types/data-structures/heap/index.d.ts +1 -0
  162. package/dist/types/data-structures/heap/index.js +17 -0
  163. package/dist/types/data-structures/heap/max-heap.d.ts +1 -0
  164. package/dist/types/data-structures/heap/max-heap.js +2 -0
  165. package/dist/types/data-structures/heap/min-heap.d.ts +1 -0
  166. package/dist/types/data-structures/heap/min-heap.js +2 -0
  167. package/dist/types/data-structures/index.d.ts +11 -0
  168. package/dist/types/data-structures/index.js +27 -0
  169. package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +1 -0
  170. package/dist/types/data-structures/linked-list/doubly-linked-list.js +2 -0
  171. package/dist/types/data-structures/linked-list/index.d.ts +2 -0
  172. package/dist/types/data-structures/linked-list/index.js +18 -0
  173. package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +1 -0
  174. package/dist/types/data-structures/linked-list/singly-linked-list.js +2 -0
  175. package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +1 -0
  176. package/dist/types/data-structures/linked-list/skip-linked-list.js +2 -0
  177. package/dist/types/data-structures/matrix/index.d.ts +1 -0
  178. package/dist/types/data-structures/matrix/index.js +17 -0
  179. package/dist/types/data-structures/matrix/matrix.d.ts +1 -0
  180. package/dist/types/data-structures/matrix/matrix.js +2 -0
  181. package/dist/types/data-structures/matrix/matrix2d.d.ts +1 -0
  182. package/dist/types/data-structures/matrix/matrix2d.js +2 -0
  183. package/dist/types/data-structures/matrix/navigator.d.ts +14 -0
  184. package/dist/types/data-structures/matrix/navigator.js +2 -0
  185. package/dist/types/data-structures/matrix/vector2d.d.ts +1 -0
  186. package/dist/types/data-structures/matrix/vector2d.js +2 -0
  187. package/dist/types/data-structures/priority-queue/index.d.ts +3 -0
  188. package/dist/types/data-structures/priority-queue/index.js +19 -0
  189. package/dist/types/data-structures/priority-queue/max-priority-queue.d.ts +1 -0
  190. package/dist/types/data-structures/priority-queue/max-priority-queue.js +2 -0
  191. package/dist/types/data-structures/priority-queue/min-priority-queue.d.ts +1 -0
  192. package/dist/types/data-structures/priority-queue/min-priority-queue.js +2 -0
  193. package/dist/types/data-structures/priority-queue/priority-queue.d.ts +1 -0
  194. package/dist/types/data-structures/priority-queue/priority-queue.js +2 -0
  195. package/dist/types/data-structures/queue/deque.d.ts +1 -0
  196. package/dist/types/data-structures/queue/deque.js +2 -0
  197. package/dist/types/data-structures/queue/index.d.ts +2 -0
  198. package/dist/types/data-structures/queue/index.js +18 -0
  199. package/dist/types/data-structures/queue/queue.d.ts +1 -0
  200. package/dist/types/data-structures/queue/queue.js +2 -0
  201. package/dist/types/data-structures/stack/index.d.ts +1 -0
  202. package/dist/types/data-structures/stack/index.js +17 -0
  203. package/dist/types/data-structures/stack/stack.d.ts +1 -0
  204. package/dist/types/data-structures/stack/stack.js +2 -0
  205. package/dist/types/data-structures/tree/index.d.ts +1 -0
  206. package/dist/types/data-structures/tree/index.js +17 -0
  207. package/dist/types/data-structures/tree/tree.d.ts +1 -0
  208. package/dist/types/data-structures/tree/tree.js +2 -0
  209. package/dist/types/data-structures/trie/index.d.ts +1 -0
  210. package/dist/types/data-structures/trie/index.js +17 -0
  211. package/dist/types/data-structures/trie/trie.d.ts +1 -0
  212. package/dist/types/data-structures/trie/trie.js +2 -0
  213. package/dist/types/index.d.ts +3 -0
  214. package/dist/types/index.js +19 -0
  215. package/dist/types/utils/index.d.ts +2 -0
  216. package/dist/types/utils/index.js +18 -0
  217. package/dist/types/utils/utils.d.ts +7 -0
  218. package/dist/types/utils/utils.js +2 -0
  219. package/dist/types/utils/validate-type.d.ts +19 -0
  220. package/dist/types/utils/validate-type.js +2 -0
  221. package/dist/utils/index.d.ts +1 -0
  222. package/dist/utils/index.js +17 -0
  223. package/dist/utils/utils.d.ts +24 -0
  224. package/dist/utils/utils.js +89 -0
  225. package/docs/.nojekyll +1 -0
  226. package/docs/assets/highlight.css +92 -0
  227. package/docs/assets/main.js +59 -0
  228. package/docs/assets/navigation.js +1 -0
  229. package/docs/assets/search.js +1 -0
  230. package/docs/assets/style.css +1383 -0
  231. package/docs/classes/AVLTree.html +2046 -0
  232. package/docs/classes/AVLTreeNode.html +263 -0
  233. package/docs/index.html +523 -0
  234. package/docs/modules.html +45 -0
  235. package/jest.config.js +8 -0
  236. package/package.json +147 -0
  237. package/src/data-structures/binary-tree/avl-tree.ts +443 -0
  238. package/src/data-structures/binary-tree/binary-indexed-tree.ts +306 -0
  239. package/src/data-structures/binary-tree/binary-tree.ts +1974 -0
  240. package/src/data-structures/binary-tree/bst.ts +676 -0
  241. package/src/data-structures/binary-tree/index.ts +7 -0
  242. package/src/data-structures/binary-tree/rb-tree.ts +585 -0
  243. package/src/data-structures/binary-tree/segment-tree.ts +190 -0
  244. package/src/data-structures/binary-tree/tree-multimap.ts +435 -0
  245. package/src/data-structures/graph/abstract-graph.ts +1181 -0
  246. package/src/data-structures/graph/directed-graph.ts +593 -0
  247. package/src/data-structures/graph/index.ts +4 -0
  248. package/src/data-structures/graph/map-graph.ts +106 -0
  249. package/src/data-structures/graph/undirected-graph.ts +331 -0
  250. package/src/data-structures/hash/hash-map.ts +401 -0
  251. package/src/data-structures/hash/hash-table.ts +268 -0
  252. package/src/data-structures/hash/index.ts +2 -0
  253. package/src/data-structures/heap/heap.ts +790 -0
  254. package/src/data-structures/heap/index.ts +3 -0
  255. package/src/data-structures/heap/max-heap.ts +26 -0
  256. package/src/data-structures/heap/min-heap.ts +26 -0
  257. package/src/data-structures/index.ts +11 -0
  258. package/src/data-structures/linked-list/doubly-linked-list.ts +837 -0
  259. package/src/data-structures/linked-list/index.ts +3 -0
  260. package/src/data-structures/linked-list/singly-linked-list.ts +784 -0
  261. package/src/data-structures/linked-list/skip-linked-list.ts +295 -0
  262. package/src/data-structures/matrix/index.ts +4 -0
  263. package/src/data-structures/matrix/matrix.ts +27 -0
  264. package/src/data-structures/matrix/matrix2d.ts +211 -0
  265. package/src/data-structures/matrix/navigator.ts +121 -0
  266. package/src/data-structures/matrix/vector2d.ts +315 -0
  267. package/src/data-structures/priority-queue/index.ts +3 -0
  268. package/src/data-structures/priority-queue/max-priority-queue.ts +25 -0
  269. package/src/data-structures/priority-queue/min-priority-queue.ts +25 -0
  270. package/src/data-structures/priority-queue/priority-queue.ts +16 -0
  271. package/src/data-structures/queue/deque.ts +1073 -0
  272. package/src/data-structures/queue/index.ts +2 -0
  273. package/src/data-structures/queue/queue.ts +308 -0
  274. package/src/data-structures/stack/index.ts +1 -0
  275. package/src/data-structures/stack/stack.ts +150 -0
  276. package/src/data-structures/tree/index.ts +1 -0
  277. package/src/data-structures/tree/tree.ts +41 -0
  278. package/src/data-structures/trie/index.ts +1 -0
  279. package/src/data-structures/trie/trie.ts +345 -0
  280. package/src/index.ts +11 -0
  281. package/src/interfaces/binary-tree.ts +10 -0
  282. package/src/interfaces/doubly-linked-list.ts +1 -0
  283. package/src/interfaces/graph.ts +7 -0
  284. package/src/interfaces/heap.ts +1 -0
  285. package/src/interfaces/index.ts +8 -0
  286. package/src/interfaces/navigator.ts +1 -0
  287. package/src/interfaces/priority-queue.ts +1 -0
  288. package/src/interfaces/segment-tree.ts +1 -0
  289. package/src/interfaces/singly-linked-list.ts +1 -0
  290. package/src/types/common.ts +23 -0
  291. package/src/types/data-structures/binary-tree/avl-tree.ts +9 -0
  292. package/src/types/data-structures/binary-tree/binary-indexed-tree.ts +1 -0
  293. package/src/types/data-structures/binary-tree/binary-tree.ts +35 -0
  294. package/src/types/data-structures/binary-tree/bst.ts +13 -0
  295. package/src/types/data-structures/binary-tree/index.ts +6 -0
  296. package/src/types/data-structures/binary-tree/rb-tree.ts +10 -0
  297. package/src/types/data-structures/binary-tree/segment-tree.ts +1 -0
  298. package/src/types/data-structures/binary-tree/tree-multimap.ts +8 -0
  299. package/src/types/data-structures/graph/abstract-graph.ts +11 -0
  300. package/src/types/data-structures/graph/directed-graph.ts +2 -0
  301. package/src/types/data-structures/graph/index.ts +3 -0
  302. package/src/types/data-structures/graph/map-graph.ts +1 -0
  303. package/src/types/data-structures/graph/undirected-graph.ts +1 -0
  304. package/src/types/data-structures/hash/hash-map.ts +12 -0
  305. package/src/types/data-structures/hash/hash-table.ts +1 -0
  306. package/src/types/data-structures/hash/index.ts +4 -0
  307. package/src/types/data-structures/heap/heap.ts +1 -0
  308. package/src/types/data-structures/heap/index.ts +1 -0
  309. package/src/types/data-structures/heap/max-heap.ts +1 -0
  310. package/src/types/data-structures/heap/min-heap.ts +1 -0
  311. package/src/types/data-structures/index.ts +11 -0
  312. package/src/types/data-structures/linked-list/doubly-linked-list.ts +1 -0
  313. package/src/types/data-structures/linked-list/index.ts +2 -0
  314. package/src/types/data-structures/linked-list/singly-linked-list.ts +1 -0
  315. package/src/types/data-structures/linked-list/skip-linked-list.ts +1 -0
  316. package/src/types/data-structures/matrix/index.ts +1 -0
  317. package/src/types/data-structures/matrix/matrix.ts +1 -0
  318. package/src/types/data-structures/matrix/matrix2d.ts +1 -0
  319. package/src/types/data-structures/matrix/navigator.ts +14 -0
  320. package/src/types/data-structures/matrix/vector2d.ts +1 -0
  321. package/src/types/data-structures/priority-queue/index.ts +3 -0
  322. package/src/types/data-structures/priority-queue/max-priority-queue.ts +1 -0
  323. package/src/types/data-structures/priority-queue/min-priority-queue.ts +1 -0
  324. package/src/types/data-structures/priority-queue/priority-queue.ts +1 -0
  325. package/src/types/data-structures/queue/deque.ts +1 -0
  326. package/src/types/data-structures/queue/index.ts +2 -0
  327. package/src/types/data-structures/queue/queue.ts +1 -0
  328. package/src/types/data-structures/stack/index.ts +1 -0
  329. package/src/types/data-structures/stack/stack.ts +1 -0
  330. package/src/types/data-structures/tree/index.ts +1 -0
  331. package/src/types/data-structures/tree/tree.ts +1 -0
  332. package/src/types/data-structures/trie/index.ts +1 -0
  333. package/src/types/data-structures/trie/trie.ts +1 -0
  334. package/src/types/index.ts +3 -0
  335. package/src/types/utils/index.ts +2 -0
  336. package/src/types/utils/utils.ts +6 -0
  337. package/src/types/utils/validate-type.ts +35 -0
  338. package/src/utils/index.ts +1 -0
  339. package/src/utils/utils.ts +101 -0
  340. package/test/index.test.ts +111 -0
  341. package/tsconfig.json +38 -0
@@ -0,0 +1,790 @@
1
+ /**
2
+ * data-structure-typed
3
+ * @author Kirk Qi
4
+ * @copyright Copyright (c) 2022 Kirk Qi <qilinaus@gmail.com>
5
+ * @license MIT License
6
+ */
7
+
8
+ import type { Comparator, DFSOrderPattern } from '../../types';
9
+
10
+ export class Heap<E = any> {
11
+ constructor(options: { comparator: Comparator<E>; elements?: E[] }) {
12
+ this._comparator = options.comparator;
13
+ if (options.elements && options.elements.length > 0) {
14
+ this._elements = options.elements;
15
+ this.fix();
16
+ }
17
+ }
18
+
19
+ protected _elements: E[] = [];
20
+
21
+ get elements(): E[] {
22
+ return this._elements;
23
+ }
24
+
25
+ protected _comparator: Comparator<E>;
26
+
27
+ get comparator(): Comparator<E> {
28
+ return this._comparator;
29
+ }
30
+
31
+ /**
32
+ * Get the size (number of elements) of the heap.
33
+ */
34
+ get size(): number {
35
+ return this.elements.length;
36
+ }
37
+
38
+ /**
39
+ * Get the last element in the heap, which is not necessarily a leaf node.
40
+ * @returns The last element or undefined if the heap is empty.
41
+ */
42
+ get leaf(): E | undefined {
43
+ return this.elements[this.size - 1] ?? undefined;
44
+ }
45
+
46
+ /**
47
+ * Static method that creates a binary heap from an array of elements and a comparison function.
48
+ * @returns A new Heap instance.
49
+ * @param options
50
+ */
51
+ static heapify<E>(options: { elements: E[]; comparator: Comparator<E> }): Heap<E> {
52
+ return new Heap<E>(options);
53
+ }
54
+
55
+ /**
56
+ * Time Complexity: O(log n), where n is the number of elements in the heap.
57
+ * Space Complexity: O(1)
58
+ */
59
+
60
+ /**
61
+ * Time Complexity: O(log n), where n is the number of elements in the heap.
62
+ * Space Complexity: O(1)
63
+ *
64
+ * Insert an element into the heap and maintain the heap properties.
65
+ * @param element - The element to be inserted.
66
+ */
67
+ add(element: E): Heap<E> {
68
+ return this.push(element);
69
+ }
70
+
71
+ /**
72
+ * Time Complexity: O(log n), where n is the number of elements in the heap.
73
+ * Space Complexity: O(1)
74
+ */
75
+
76
+ /**
77
+ * Time Complexity: O(log n), where n is the number of elements in the heap.
78
+ * Space Complexity: O(1)
79
+ *
80
+ * Insert an element into the heap and maintain the heap properties.
81
+ * @param element - The element to be inserted.
82
+ */
83
+ push(element: E): Heap<E> {
84
+ this._elements.push(element);
85
+ this._bubbleUp(this.elements.length - 1);
86
+ return this;
87
+ }
88
+
89
+ /**
90
+ * Time Complexity: O(log n), where n is the number of elements in the heap.
91
+ * Space Complexity: O(1)
92
+ */
93
+
94
+ /**
95
+ * Time Complexity: O(log n), where n is the number of elements in the heap.
96
+ * Space Complexity: O(1)
97
+ *
98
+ * Remove and return the top element (smallest or largest element) from the heap.
99
+ * @returns The top element or undefined if the heap is empty.
100
+ */
101
+ poll(): E | undefined {
102
+ if (this.elements.length === 0) return;
103
+ const value = this.elements[0];
104
+ const last = this.elements.pop()!;
105
+ if (this.elements.length) {
106
+ this.elements[0] = last;
107
+ this._sinkDown(0, this.elements.length >> 1);
108
+ }
109
+ return value;
110
+ }
111
+
112
+ /**
113
+ * Time Complexity: O(log n), where n is the number of elements in the heap.
114
+ * Space Complexity: O(1)
115
+ */
116
+
117
+ /**
118
+ * Time Complexity: O(log n), where n is the number of elements in the heap.
119
+ * Space Complexity: O(1)
120
+ *
121
+ * Remove and return the top element (smallest or largest element) from the heap.
122
+ * @returns The top element or undefined if the heap is empty.
123
+ */
124
+ pop(): E | undefined {
125
+ return this.poll();
126
+ }
127
+
128
+ /**
129
+ * Peek at the top element of the heap without removing it.
130
+ * @returns The top element or undefined if the heap is empty.
131
+ */
132
+ peek(): E | undefined {
133
+ return this.elements[0];
134
+ }
135
+
136
+ /**
137
+ * Check if the heap is empty.
138
+ * @returns True if the heap is empty, otherwise false.
139
+ */
140
+ isEmpty() {
141
+ return this.size === 0;
142
+ }
143
+
144
+ /**
145
+ * Reset the elements of the heap. Make the elements empty.
146
+ */
147
+ clear() {
148
+ this._elements = [];
149
+ }
150
+
151
+ /**
152
+ * Time Complexity: O(n), where n is the number of elements in the elements array.
153
+ * Space Complexity: O(n)
154
+ */
155
+
156
+ /**
157
+ * Time Complexity: O(n), where n is the number of elements in the elements array.
158
+ * Space Complexity: O(n)
159
+ *
160
+ * Clear and add elements of the heap
161
+ * @param elements
162
+ */
163
+ refill(elements: E[]) {
164
+ this._elements = elements;
165
+ this.fix();
166
+ }
167
+
168
+ /**
169
+ * Time Complexity: O(n), where n is the number of elements in the heap.
170
+ * Space Complexity: O(1)
171
+ */
172
+
173
+ /**
174
+ * Time Complexity: O(n), where n is the number of elements in the heap.
175
+ * Space Complexity: O(1)
176
+ *
177
+ * Use a comparison function to check whether a binary heap contains a specific element.
178
+ * @param element - the element to check.
179
+ * @returns Returns true if the specified element is contained; otherwise, returns false.
180
+ */
181
+ has(element: E): boolean {
182
+ return this.elements.includes(element);
183
+ }
184
+
185
+ /**
186
+ * Time Complexity: O(n). The worst-case O(n), where n is the number of elements in the heap. This is because, in the worst case, the element to be deleted is located at the end of the heap (not the root), and after deletion, we may need to reorganize the elements by performing a sinkDown operation.
187
+ * Space Complexity: O(1)
188
+ */
189
+
190
+ /**
191
+ * Time Complexity: O(n). The worst-case O(n), where n is the number of elements in the heap. This is because, in the worst case, the element to be deleted is located at the end of the heap (not the root), and after deletion, we may need to reorganize the elements by performing a sinkDown operation.
192
+ * Space Complexity: O(1)
193
+ *
194
+ * The `delete` function removes an element from an array-like data structure, maintaining the order
195
+ * and structure of the remaining elements.
196
+ * @param {E} element - The `element` parameter represents the element that you want to delete from
197
+ * the array `this.elements`.
198
+ * @returns The `delete` function is returning a boolean value. It returns `true` if the element was
199
+ * successfully deleted from the array, and `false` if the element was not found in the array.
200
+ */
201
+ delete(element: E) {
202
+ const index = this.elements.indexOf(element);
203
+ if (index < 0) return false;
204
+ if (index === 0) {
205
+ this.pop();
206
+ } else if (index === this.elements.length - 1) {
207
+ this.elements.pop();
208
+ } else {
209
+ this.elements.splice(index, 1, this.elements.pop()!);
210
+ this._bubbleUp(index);
211
+ this._sinkDown(index, this.elements.length >> 1);
212
+ }
213
+ return true;
214
+ }
215
+
216
+ /**
217
+ * Time Complexity: O(n), where n is the number of elements in the heap.
218
+ * Space Complexity: O(h), where h is the height of the heap.
219
+ */
220
+
221
+ /**
222
+ * Time Complexity: O(n), where n is the number of elements in the heap.
223
+ * Space Complexity: O(h), where h is the height of the heap.
224
+ *
225
+ * Depth-first search (DFS) method, different traversal orders can be selected。
226
+ * @param order - Traverse order parameter: 'in' (in-order), 'pre' (pre-order) or 'post' (post-order).
227
+ * @returns An array containing elements traversed in the specified order.
228
+ */
229
+ dfs(order: DFSOrderPattern): E[] {
230
+ const result: E[] = [];
231
+
232
+ // Auxiliary recursive function, traverses the binary heap according to the traversal order
233
+ const dfsHelper = (index: number) => {
234
+ if (index < this.size) {
235
+ if (order === 'in') {
236
+ dfsHelper(2 * index + 1);
237
+ result.push(this.elements[index]);
238
+ dfsHelper(2 * index + 2);
239
+ } else if (order === 'pre') {
240
+ result.push(this.elements[index]);
241
+ dfsHelper(2 * index + 1);
242
+ dfsHelper(2 * index + 2);
243
+ } else if (order === 'post') {
244
+ dfsHelper(2 * index + 1);
245
+ dfsHelper(2 * index + 2);
246
+ result.push(this.elements[index]);
247
+ }
248
+ }
249
+ };
250
+
251
+ dfsHelper(0); // Traverse starting from the root node
252
+
253
+ return result;
254
+ }
255
+
256
+ /**
257
+ * Time Complexity: O(n)
258
+ * Space Complexity: O(n)
259
+ */
260
+
261
+ /**
262
+ * Time Complexity: O(n)
263
+ * Space Complexity: O(n)
264
+ *
265
+ * Convert the heap to an array.
266
+ * @returns An array containing the elements of the heap.
267
+ */
268
+ toArray(): E[] {
269
+ return [...this.elements];
270
+ }
271
+
272
+ /**
273
+ * Time Complexity: O(n)
274
+ * Space Complexity: O(n)
275
+ */
276
+
277
+ /**
278
+ * Time Complexity: O(n)
279
+ * Space Complexity: O(n)
280
+ *
281
+ * Clone the heap, creating a new heap with the same elements.
282
+ * @returns A new Heap instance containing the same elements.
283
+ */
284
+ clone(): Heap<E> {
285
+ const clonedHeap = new Heap<E>({ comparator: this.comparator });
286
+ clonedHeap._elements = [...this.elements];
287
+ return clonedHeap;
288
+ }
289
+
290
+ /**
291
+ * Time Complexity: O(n log n)
292
+ * Space Complexity: O(n)
293
+ */
294
+
295
+ /**
296
+ * Time Complexity: O(n log n)
297
+ * Space Complexity: O(n)
298
+ *
299
+ * Sort the elements in the heap and return them as an array.
300
+ * @returns An array containing the elements sorted in ascending order.
301
+ */
302
+ sort(): E[] {
303
+ const visitedNode: E[] = [];
304
+ const cloned = this.clone();
305
+ while (cloned.size !== 0) {
306
+ const top = cloned.poll();
307
+ if (top) visitedNode.push(top);
308
+ }
309
+ return visitedNode;
310
+ }
311
+
312
+ /**
313
+ * Time Complexity: O(log n)
314
+ * Space Complexity: O(1)
315
+ */
316
+
317
+ /**
318
+ * Time Complexity: O(n)
319
+ * Space Complexity: O(1)
320
+ *
321
+ * Fix the entire heap to maintain heap properties.
322
+ */
323
+ fix() {
324
+ for (let i = Math.floor(this.size / 2); i >= 0; i--) this._sinkDown(i, this.elements.length >> 1);
325
+ }
326
+
327
+ /**
328
+ * Time Complexity: O(log n)
329
+ * Space Complexity: O(1)
330
+ */
331
+
332
+ /**
333
+ * Time Complexity: O(log n)
334
+ * Space Complexity: O(1)
335
+ *
336
+ * Float operation to maintain heap properties after adding an element.
337
+ * @param index - The index of the newly added element.
338
+ */
339
+ protected _bubbleUp(index: number) {
340
+ const element = this.elements[index];
341
+ while (index > 0) {
342
+ const parent = (index - 1) >> 1;
343
+ const parentItem = this.elements[parent];
344
+ if (this._comparator(parentItem, element) <= 0) break;
345
+ this.elements[index] = parentItem;
346
+ index = parent;
347
+ }
348
+ this.elements[index] = element;
349
+ }
350
+
351
+ /**
352
+ * Time Complexity: O(n)
353
+ * Space Complexity: O(1)
354
+ */
355
+
356
+ /**
357
+ * Time Complexity: O(log n)
358
+ * Space Complexity: O(1)
359
+ *
360
+ * Sinking operation to maintain heap properties after removing the top element.
361
+ * @param index - The index from which to start sinking.
362
+ * @param halfLength
363
+ */
364
+ protected _sinkDown(index: number, halfLength: number) {
365
+ const element = this.elements[index];
366
+ while (index < halfLength) {
367
+ let left = index << 1 | 1;
368
+ const right = left + 1;
369
+ let minItem = this.elements[left];
370
+ if (
371
+ right < this.elements.length &&
372
+ this._comparator(minItem, this.elements[right]) > 0
373
+ ) {
374
+ left = right;
375
+ minItem = this.elements[right];
376
+ }
377
+ if (this._comparator(minItem, element) >= 0) break;
378
+ this.elements[index] = minItem;
379
+ index = left;
380
+ }
381
+ this.elements[index] = element;
382
+ }
383
+ }
384
+
385
+ export class FibonacciHeapNode<E> {
386
+ element: E;
387
+ degree: number;
388
+ left?: FibonacciHeapNode<E>;
389
+ right?: FibonacciHeapNode<E>;
390
+ child?: FibonacciHeapNode<E>;
391
+ parent?: FibonacciHeapNode<E>;
392
+ marked: boolean;
393
+
394
+ constructor(element: E, degree = 0) {
395
+ this.element = element;
396
+ this.degree = degree;
397
+ this.marked = false;
398
+ }
399
+ }
400
+
401
+ export class FibonacciHeap<E> {
402
+ constructor(comparator?: Comparator<E>) {
403
+ this.clear();
404
+ this._comparator = comparator || this.defaultComparator;
405
+
406
+ if (typeof this.comparator !== 'function') {
407
+ throw new Error('FibonacciHeap constructor: given comparator should be a function.');
408
+ }
409
+ }
410
+
411
+ protected _root?: FibonacciHeapNode<E>;
412
+
413
+ get root(): FibonacciHeapNode<E> | undefined {
414
+ return this._root;
415
+ }
416
+
417
+ protected _size = 0;
418
+
419
+ get size(): number {
420
+ return this._size;
421
+ }
422
+
423
+ protected _min?: FibonacciHeapNode<E>;
424
+
425
+ get min(): FibonacciHeapNode<E> | undefined {
426
+ return this._min;
427
+ }
428
+
429
+ protected _comparator: Comparator<E>;
430
+
431
+ get comparator(): Comparator<E> {
432
+ return this._comparator;
433
+ }
434
+
435
+ /**
436
+ * Get the size (number of elements) of the heap.
437
+ * @returns {number} The size of the heap. Returns 0 if the heap is empty. Returns -1 if the heap is invalid.
438
+ */
439
+ clear(): void {
440
+ this._root = undefined;
441
+ this._min = undefined;
442
+ this._size = 0;
443
+ }
444
+
445
+ /**
446
+ * Time Complexity: O(1)
447
+ * Space Complexity: O(1)
448
+ */
449
+
450
+ /**
451
+ * Time Complexity: O(1)
452
+ * Space Complexity: O(1)
453
+ *
454
+ * Insert an element into the heap and maintain the heap properties.
455
+ * @param element
456
+ * @returns {FibonacciHeap<E>} FibonacciHeap<E> - The heap itself.
457
+ */
458
+ add(element: E): FibonacciHeap<E> {
459
+ return this.push(element);
460
+ }
461
+
462
+ /**
463
+ * Time Complexity: O(1)
464
+ * Space Complexity: O(1)
465
+ */
466
+
467
+ /**
468
+ * Time Complexity: O(1)
469
+ * Space Complexity: O(1)
470
+ *
471
+ * Insert an element into the heap and maintain the heap properties.
472
+ * @param element
473
+ * @returns {FibonacciHeap<E>} FibonacciHeap<E> - The heap itself.
474
+ */
475
+ push(element: E): FibonacciHeap<E> {
476
+ const node = this.createNode(element);
477
+ node.left = node;
478
+ node.right = node;
479
+ this.mergeWithRoot(node);
480
+
481
+ if (!this.min || this.comparator(node.element, this.min.element) <= 0) {
482
+ this._min = node;
483
+ }
484
+
485
+ this._size++;
486
+ return this;
487
+ }
488
+
489
+ /**
490
+ * Time Complexity: O(1)
491
+ * Space Complexity: O(1)
492
+ */
493
+
494
+ /**
495
+ * Time Complexity: O(1)
496
+ * Space Complexity: O(1)
497
+ *
498
+ * Peek at the top element of the heap without removing it.
499
+ * @returns The top element or undefined if the heap is empty.
500
+ * @protected
501
+ */
502
+ peek(): E | undefined {
503
+ return this.min ? this.min.element : undefined;
504
+ }
505
+
506
+ /**
507
+ * Time Complexity: O(n), where n is the number of elements in the linked list.
508
+ * Space Complexity: O(1)
509
+ */
510
+
511
+ /**
512
+ * Time Complexity: O(n), where n is the number of elements in the linked list.
513
+ * Space Complexity: O(1)
514
+ *
515
+ * Get the size (number of elements) of the heap.
516
+ * @param {FibonacciHeapNode<E>} head - The head of the linked list.
517
+ * @protected
518
+ * @returns FibonacciHeapNode<E>[] - An array containing the elements of the linked list.
519
+ */
520
+ consumeLinkedList(head?: FibonacciHeapNode<E>): FibonacciHeapNode<E>[] {
521
+ const elements: FibonacciHeapNode<E>[] = [];
522
+ if (!head) return elements;
523
+
524
+ let node: FibonacciHeapNode<E> | undefined = head;
525
+ let flag = false;
526
+
527
+ while (true) {
528
+ if (node === head && flag) break;
529
+ else if (node === head) flag = true;
530
+
531
+ if (node) {
532
+ elements.push(node);
533
+ node = node.right;
534
+ }
535
+ }
536
+
537
+ return elements;
538
+ }
539
+
540
+ /**
541
+ * Time Complexity: O(1)
542
+ * Space Complexity: O(1)
543
+ *
544
+ * @param parent
545
+ * @param node
546
+ */
547
+ mergeWithChild(parent: FibonacciHeapNode<E>, node: FibonacciHeapNode<E>): void {
548
+ if (!parent.child) {
549
+ parent.child = node;
550
+ } else {
551
+ node.right = parent.child.right;
552
+ node.left = parent.child;
553
+ parent.child.right!.left = node;
554
+ parent.child.right = node;
555
+ }
556
+ }
557
+
558
+ /**
559
+ * Time Complexity: O(log n), where n is the number of elements in the heap.
560
+ * Space Complexity: O(1)
561
+ */
562
+
563
+ /**
564
+ * Time Complexity: O(log n), where n is the number of elements in the heap.
565
+ * Space Complexity: O(1)
566
+ *
567
+ * Remove and return the top element (smallest or largest element) from the heap.
568
+ * @returns The top element or undefined if the heap is empty.
569
+ */
570
+ poll(): E | undefined {
571
+ return this.pop();
572
+ }
573
+
574
+ /**
575
+ * Time Complexity: O(log n), where n is the number of elements in the heap.
576
+ * Space Complexity: O(1)
577
+ */
578
+
579
+ /**
580
+ * Time Complexity: O(log n), where n is the number of elements in the heap.
581
+ * Space Complexity: O(1)
582
+ *
583
+ * Remove and return the top element (smallest or largest element) from the heap.
584
+ * @returns The top element or undefined if the heap is empty.
585
+ */
586
+ pop(): E | undefined {
587
+ if (this.size === 0) return undefined;
588
+
589
+ const z = this.min!;
590
+ if (z.child) {
591
+ const elements = this.consumeLinkedList(z.child);
592
+ for (const node of elements) {
593
+ this.mergeWithRoot(node);
594
+ node.parent = undefined;
595
+ }
596
+ }
597
+
598
+ this.removeFromRoot(z);
599
+
600
+ if (z === z.right) {
601
+ this._min = undefined;
602
+ this._root = undefined;
603
+ } else {
604
+ this._min = z.right;
605
+ this.consolidate();
606
+ }
607
+
608
+ this._size--;
609
+
610
+ return z.element;
611
+ }
612
+
613
+ /**
614
+ * Time Complexity: O(1)
615
+ * Space Complexity: O(1)
616
+ */
617
+
618
+ /**
619
+ * Time Complexity: O(1)
620
+ * Space Complexity: O(1)
621
+ *
622
+ * merge two heaps. The heap that is merged will be cleared. The heap that is merged into will remain.
623
+ * @param heapToMerge
624
+ */
625
+ merge(heapToMerge: FibonacciHeap<E>): void {
626
+ if (heapToMerge.size === 0) {
627
+ return; // Nothing to merge
628
+ }
629
+
630
+ // Merge the root lists of the two heaps
631
+ if (this.root && heapToMerge.root) {
632
+ const thisRoot = this.root;
633
+ const otherRoot = heapToMerge.root;
634
+
635
+ const thisRootRight = thisRoot.right!;
636
+ const otherRootLeft = otherRoot.left!;
637
+
638
+ thisRoot.right = otherRoot;
639
+ otherRoot.left = thisRoot;
640
+
641
+ thisRootRight.left = otherRootLeft;
642
+ otherRootLeft.right = thisRootRight;
643
+ }
644
+
645
+ // Update the minimum node
646
+ if (!this.min || (heapToMerge.min && this.comparator(heapToMerge.min.element, this.min.element) < 0)) {
647
+ this._min = heapToMerge.min;
648
+ }
649
+
650
+ // Update the size
651
+ this._size += heapToMerge.size;
652
+
653
+ // Clear the heap that was merged
654
+ heapToMerge.clear();
655
+ }
656
+
657
+ /**
658
+ * Default comparator function used by the heap.
659
+ * @param {E} a
660
+ * @param {E} b
661
+ * @protected
662
+ */
663
+ protected defaultComparator(a: E, b: E): number {
664
+ if (a < b) return -1;
665
+ if (a > b) return 1;
666
+ return 0;
667
+ }
668
+
669
+ /**
670
+ * Create a new node.
671
+ * @param element
672
+ * @protected
673
+ */
674
+ protected createNode(element: E): FibonacciHeapNode<E> {
675
+ return new FibonacciHeapNode<E>(element);
676
+ }
677
+
678
+ /**
679
+ * Time Complexity: O(1)
680
+ * Space Complexity: O(1)
681
+ */
682
+
683
+ /**
684
+ * Time Complexity: O(1)
685
+ * Space Complexity: O(1)
686
+ *
687
+ * Merge the given node with the root list.
688
+ * @param node - The node to be merged.
689
+ */
690
+ protected mergeWithRoot(node: FibonacciHeapNode<E>): void {
691
+ if (!this.root) {
692
+ this._root = node;
693
+ } else {
694
+ node.right = this.root.right;
695
+ node.left = this.root;
696
+ this.root.right!.left = node;
697
+ this.root.right = node;
698
+ }
699
+ }
700
+
701
+ /**
702
+ * Time Complexity: O(1)
703
+ * Space Complexity: O(1)
704
+ */
705
+
706
+ /**
707
+ * Time Complexity: O(1)
708
+ * Space Complexity: O(1)
709
+ *.
710
+ * Remove and return the top element (smallest or largest element) from the heap.
711
+ * @param node - The node to be removed.
712
+ * @protected
713
+ */
714
+ protected removeFromRoot(node: FibonacciHeapNode<E>): void {
715
+ if (this.root === node) this._root = node.right;
716
+ if (node.left) node.left.right = node.right;
717
+ if (node.right) node.right.left = node.left;
718
+ }
719
+
720
+ /**
721
+ * Time Complexity: O(1)
722
+ * Space Complexity: O(1)
723
+ */
724
+
725
+ /**
726
+ * Time Complexity: O(1)
727
+ * Space Complexity: O(1)
728
+ *
729
+ * Remove and return the top element (smallest or largest element) from the heap.
730
+ * @param y
731
+ * @param x
732
+ * @protected
733
+ */
734
+ protected link(y: FibonacciHeapNode<E>, x: FibonacciHeapNode<E>): void {
735
+ this.removeFromRoot(y);
736
+ y.left = y;
737
+ y.right = y;
738
+ this.mergeWithChild(x, y);
739
+ x.degree++;
740
+ y.parent = x;
741
+ }
742
+
743
+ /**
744
+ * Time Complexity: O(n log n), where n is the number of elements in the heap.
745
+ * Space Complexity: O(n)
746
+ */
747
+
748
+ /**
749
+ * Time Complexity: O(n log n), where n is the number of elements in the heap.
750
+ * Space Complexity: O(n)
751
+ *
752
+ * Remove and return the top element (smallest or largest element) from the heap.
753
+ * @protected
754
+ */
755
+ protected consolidate(): void {
756
+ const A: (FibonacciHeapNode<E> | undefined)[] = new Array(this.size);
757
+ const elements = this.consumeLinkedList(this.root);
758
+ let x: FibonacciHeapNode<E> | undefined,
759
+ y: FibonacciHeapNode<E> | undefined,
760
+ d: number,
761
+ t: FibonacciHeapNode<E> | undefined;
762
+
763
+ for (const node of elements) {
764
+ x = node;
765
+ d = x.degree;
766
+
767
+ while (A[d]) {
768
+ y = A[d] as FibonacciHeapNode<E>;
769
+
770
+ if (this.comparator(x.element, y.element) > 0) {
771
+ t = x;
772
+ x = y;
773
+ y = t;
774
+ }
775
+
776
+ this.link(y, x);
777
+ A[d] = undefined;
778
+ d++;
779
+ }
780
+
781
+ A[d] = x;
782
+ }
783
+
784
+ for (let i = 0; i < this.size; i++) {
785
+ if (A[i] && this.comparator(A[i]!.element, this.min!.element) <= 0) {
786
+ this._min = A[i]!;
787
+ }
788
+ }
789
+ }
790
+ }