* @brief Insert a copy of @p item at the appropriate heap position. * * Copies exactly `priority_queue_item_size(pq)` bytes from @p item * into the heap then sifts it up until the heap property is restored. * The caller's buffer can be reused or freed afterwards — the heap * owns the copy. * * @param pq Destination queue. * @param item Pointer to the value to copy (must be non-NULL). *
| 541 | * @code |
| 542 | * int x = 42; |
| 543 | * priority_queue_push(pq, &x); |
| 544 | * @endcode |
| 545 | */ |
| 546 | bool priority_queue_push(PriorityQueue* pq, const void* item) { |
| 547 | PQUEUE_LOG("[priority_queue_push]: enter pq=%p item=%p", (void*)pq, item); |
| 548 | |
| 549 | if (!pq || !pq->vec || !pq->compare || !item) { |
| 550 | PQUEUE_LOG("[priority_queue_push]: NULL receiver / item -> false"); |
| 551 | return false; |
| 552 | } |
| 553 | if (!vector_push_back(pq->vec, item)) { |
| 554 | PQUEUE_LOG("[priority_queue_push]: vector_push_back failed -> false"); |
| 555 | return false; |
| 556 | } |
| 557 | size_t final_idx = pq_sift_up(pq->vec, vector_size(pq->vec) - 1, pq->compare); |
| 558 | (void)final_idx; |
| 559 | PQUEUE_LOG("[priority_queue_push]: exit ok (new size = %zu, final idx = %zu)", vector_size(pq->vec), final_idx); |
| 560 | |
| 561 | return true; |
| 562 | } |
nothing calls this directly
no test coverage detected