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

Function priority_queue_swap

priority_queue/priority_queue.c:704–725  ·  view source on GitHub ↗

* @brief Constant-time swap of two priority queues' internals. * * Only the underlying vector pointer AND the comparator are swapped * — no element-by-element copy. Rejects (no-op) when item sizes * differ, since `std::priority_queue::swap` is only well-defined * between same-type queues. * * @param pq1 First queue. * @param pq2 Second queue. */

Source from the content-addressed store, hash-verified

702 * between same-type queues.
703 *
704 * @param pq1 First queue.
705 * @param pq2 Second queue.
706 */
707void priority_queue_swap(PriorityQueue* pq1, PriorityQueue* pq2) {
708 PQUEUE_LOG("[priority_queue_swap]: enter pq1=%p pq2=%p", (void*)pq1, (void*)pq2);
709
710 if (!pq1 || !pq2 || !pq1->vec || !pq2->vec) {
711 PQUEUE_LOG("[priority_queue_swap]: NULL receiver, no-op");
712 return;
713 }
714 if (pq1->vec->itemSize != pq2->vec->itemSize) {
715 PQUEUE_LOG("[priority_queue_swap]: refused: item sizes differ (%zu vs %zu)", pq1->vec->itemSize, pq2->vec->itemSize);
716 return;
717 }
718
719 Vector* tv = pq1->vec;
720 pq1->vec = pq2->vec;
721 pq2->vec = tv;
722
723 PQCompareFunc tc = pq1->compare;
724 pq1->compare = pq2->compare;
725 pq2->compare = tc;
726
727 PQUEUE_LOG("[priority_queue_swap]: exit (pq1.size=%zu, pq2.size=%zu)", vector_size(pq1->vec), vector_size(pq2->vec));
728}

Callers

nothing calls this directly

Calls 1

vector_sizeFunction · 0.85

Tested by

no test coverage detected