* binaryheap_replace_first * * Replace the topmost element of a non-empty heap, preserving the heap * property. O(1) in the best case, or O(log n) if it must fall back to * sifting the new node down. */
| 201 | * sifting the new node down. |
| 202 | */ |
| 203 | void |
| 204 | binaryheap_replace_first(binaryheap *heap, Datum d) |
| 205 | { |
| 206 | Assert(!binaryheap_empty(heap) && heap->bh_has_heap_property); |
| 207 | |
| 208 | heap->bh_nodes[0] = d; |
| 209 | |
| 210 | if (heap->bh_size > 1) |
| 211 | sift_down(heap, 0); |
| 212 | } |
| 213 | |
| 214 | /* |
| 215 | * Swap the contents of two nodes. |
no test coverage detected