| 5010 | } |
| 5011 | |
| 5012 | private bubbleDown(index: number): void { |
| 5013 | while (true) { |
| 5014 | let minIndex = index; |
| 5015 | const leftChild = 2 * index + 1; |
| 5016 | const rightChild = 2 * index + 2; |
| 5017 | |
| 5018 | if ( |
| 5019 | leftChild < this.heap.length && |
| 5020 | this.compareFn(this.heap[leftChild]!, this.heap[minIndex]!) < 0 |
| 5021 | ) { |
| 5022 | minIndex = leftChild; |
| 5023 | } |
| 5024 | |
| 5025 | if ( |
| 5026 | rightChild < this.heap.length && |
| 5027 | this.compareFn(this.heap[rightChild]!, this.heap[minIndex]!) < 0 |
| 5028 | ) { |
| 5029 | minIndex = rightChild; |
| 5030 | } |
| 5031 | |
| 5032 | if (minIndex === index) break; |
| 5033 | |
| 5034 | [this.heap[index], this.heap[minIndex]] = [this.heap[minIndex]!, this.heap[index]!]; |
| 5035 | index = minIndex; |
| 5036 | } |
| 5037 | } |
| 5038 | } |
| 5039 | |
| 5040 | /** |