* @brief Borrowed pointer to the highest-priority element (heap root). * * This is the element that @ref priority_queue_pop will remove next. * The returned pointer becomes stale the moment the underlying buffer * is reallocated (any push / emplace / pop / reserve / clear / swap / * assign can invalidate it). * * @param pq Queue pointer. * @return Pointer to the root element, or NULL if @p
| 459 | * assign can invalidate it). |
| 460 | * |
| 461 | * @param pq Queue pointer. |
| 462 | * @return Pointer to the root element, or NULL if @p pq is NULL or empty. |
| 463 | */ |
| 464 | void* priority_queue_top(const PriorityQueue* pq) { |
| 465 | PQUEUE_LOG("[priority_queue_top]: enter pq=%p", (const void*)pq); |
| 466 | if (!pq || !pq->vec) { |
| 467 | PQUEUE_LOG("[priority_queue_top]: NULL receiver -> NULL"); |
| 468 | return NULL; |
| 469 | } |
| 470 | if (vector_is_empty(pq->vec)) { |
| 471 | PQUEUE_LOG("[priority_queue_top]: empty queue -> NULL"); |
| 472 | return NULL; |
| 473 | } |
| 474 | |
| 475 | void* out = vector_front(pq->vec); |
| 476 | PQUEUE_LOG("[priority_queue_top]: exit -> %p", out); |
| 477 | |
| 478 | return out; |
| 479 | } |
no test coverage detected