* Bubbles up a value from the specified index to maintain the heap property. * @param {number} currIdx - The index of the value to be bubbled up. * @private
(currIdx)
| 56 | * @private |
| 57 | */ |
| 58 | #bubbleUp(currIdx) { |
| 59 | let parentIdx = Math.floor((currIdx - 1) / 2) |
| 60 | |
| 61 | while ( |
| 62 | currIdx > 0 && |
| 63 | this.comparator(this.heap[currIdx], this.heap[parentIdx]) |
| 64 | ) { |
| 65 | this.#swap(currIdx, parentIdx) |
| 66 | currIdx = parentIdx |
| 67 | parentIdx = Math.floor((currIdx - 1) / 2) |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | /** |
| 72 | * Sinks down a value from the specified index to maintain the heap property. |