* @brief Remove the highest-priority element (the heap root). * * Swaps the root with the last element, drops the last slot, then * sifts the new root down. O(log n). No-op on NULL or empty queue. * * Iterator / pointer invalidation: any borrowed pointer obtained from * @ref priority_queue_top / `_front` / `_back` / `_emplace` BEFORE * this call should be considered stale afterwards. * *
| 613 | * @ref priority_queue_top / `_front` / `_back` / `_emplace` BEFORE |
| 614 | * this call should be considered stale afterwards. |
| 615 | * |
| 616 | * @param pq Queue to mutate. |
| 617 | */ |
| 618 | void priority_queue_pop(PriorityQueue* pq) { |
| 619 | PQUEUE_LOG("[priority_queue_pop]: enter pq=%p", (void*)pq); |
| 620 | |
| 621 | if (!pq || !pq->vec || !pq->compare) { |
| 622 | PQUEUE_LOG("[priority_queue_pop]: NULL receiver, no-op"); |
| 623 | return; |
| 624 | } |
| 625 | size_t n = vector_size(pq->vec); |
| 626 | if (n == 0) { |
| 627 | PQUEUE_LOG("[priority_queue_pop]: empty queue, no-op"); |
| 628 | return; |
| 629 | } |
| 630 | if (n > 1) { |
| 631 | char* base = (char*)pq->vec->items; |
| 632 | size_t isz = pq->vec->itemSize; |
| 633 | |
| 634 | pq_move(base, base + (n - 1) * isz, isz); |
| 635 | } |
| 636 | pq->vec->size--; /* inlined vector_pop_back: size > 0 already checked above */ |
| 637 | pq_sift_down(pq->vec, 0, pq->compare); |
| 638 | |
| 639 | PQUEUE_LOG("[priority_queue_pop]: exit (size %zu -> %zu)", n, vector_size(pq->vec)); |
| 640 | } |
nothing calls this directly
no test coverage detected