* @zh 上浮操作 * @en Bubble up operation
(index: number)
| 105 | * @en Bubble up operation |
| 106 | */ |
| 107 | private bubbleUp(index: number): void { |
| 108 | const item = this.heap[index]; |
| 109 | |
| 110 | while (index > 0) { |
| 111 | const parentIndex = Math.floor((index - 1) / 2); |
| 112 | const parent = this.heap[parentIndex]; |
| 113 | |
| 114 | if (this.compare(item, parent) >= 0) { |
| 115 | break; |
| 116 | } |
| 117 | |
| 118 | this.heap[index] = parent; |
| 119 | index = parentIndex; |
| 120 | } |
| 121 | |
| 122 | this.heap[index] = item; |
| 123 | } |
| 124 | |
| 125 | /** |
| 126 | * @zh 下沉操作 |