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

Function priority_queue_create

priority_queue/priority_queue.c:202–231  ·  view source on GitHub ↗

* @brief Create an empty priority queue with the given element size * and comparator. * * Allocates a PriorityQueue header and an empty backing Vector. No * elements are allocated until you push. * * @param itemSize Size in bytes of one element (must be > 0). * @param compare Three-way comparator that returns `> 0` when `a` has * higher priority than `b`, `< 0` for

Source from the content-addressed store, hash-verified

200 * - underlying vector_create failure
201 */
202PriorityQueue* priority_queue_create(size_t itemSize, PQCompareFunc compare) {
203 PQUEUE_LOG("[priority_queue_create]: enter itemSize=%zu", itemSize);
204
205 if (itemSize == 0) {
206 PQUEUE_LOG("[priority_queue_create]: itemSize is zero -> NULL");
207 return NULL;
208 }
209 if (!compare) {
210 PQUEUE_LOG("[priority_queue_create]: compare is NULL -> NULL");
211 return NULL;
212 }
213
214 PriorityQueue* pq = (PriorityQueue*)malloc(sizeof(PriorityQueue));
215 if (!pq) {
216 PQUEUE_LOG("[priority_queue_create]: malloc(PriorityQueue) failed -> NULL");
217 return NULL;
218 }
219
220 pq->vec = vector_create(itemSize);
221 if (!pq->vec) {
222 PQUEUE_LOG("[priority_queue_create]: vector_create(%zu) failed -> NULL", itemSize);
223 free(pq);
224
225 return NULL;
226 }
227 pq->compare = compare;
228
229 PQUEUE_LOG("[priority_queue_create]: exit ok pq=%p vec=%p", (void*)pq, (void*)pq->vec);
230 return pq;
231}
232
233
234/**

Callers 1

priority_queue_copyFunction · 0.85

Calls 1

vector_createFunction · 0.85

Tested by

no test coverage detected