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

Function priority_queue_reserve

priority_queue/priority_queue.c:652–666  ·  view source on GitHub ↗

* @brief Pre-allocate underlying storage for at least @p n elements. * * Useful before a tight bulk-push loop to avoid mid-loop reallocations * (each of which would invalidate any outstanding borrowed pointers). * * @param pq Queue to grow. * @param n Target minimum capacity. * * @return true on success, false on NULL queue or underlying * vector_reserve failure (e.g. OOM). */

Source from the content-addressed store, hash-verified

650 * @param n Target minimum capacity.
651 *
652 * @return true on success, false on NULL queue or underlying
653 * vector_reserve failure (e.g. OOM).
654 */
655bool priority_queue_reserve(PriorityQueue* pq, size_t n) {
656 PQUEUE_LOG("[priority_queue_reserve]: enter pq=%p n=%zu", (void*)pq, n);
657
658 if (!pq || !pq->vec) {
659 PQUEUE_LOG("[priority_queue_reserve]: NULL receiver -> false");
660 return false;
661 }
662 if (!vector_reserve(pq->vec, n)) {
663 PQUEUE_LOG("[priority_queue_reserve]: vector_reserve(%zu) failed -> false", n);
664 return false;
665 }
666
667 PQUEUE_LOG("[priority_queue_reserve]: exit ok (capacity = %zu)", vector_capacity(pq->vec));
668 return true;
669}

Callers

nothing calls this directly

Calls 2

vector_reserveFunction · 0.85
vector_capacityFunction · 0.85

Tested by

no test coverage detected