MCPcopy Create free account
hub / github.com/KaisenAmin/c_std / priority_queue_push

Function priority_queue_push

priority_queue/priority_queue.c:543–559  ·  view source on GitHub ↗

* @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). *

Source from the content-addressed store, hash-verified

541 * @code
542 * int x = 42;
543 * priority_queue_push(pq, &x);
544 * @endcode
545 */
546bool 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}

Callers

nothing calls this directly

Calls 3

vector_push_backFunction · 0.85
pq_sift_upFunction · 0.85
vector_sizeFunction · 0.85

Tested by

no test coverage detected