=pod =head1 NAME DEFINE_PRIORITY_QUEUE_OF, PRIORITY_QUEUE_OF, ossl_pqueue_TYPE_num, ossl_pqueue_TYPE_new, ossl_pqueue_TYPE_free, ossl_pqueue_TYPE_pop_free, ossl_pqueue_TYPE_reserve, ossl_pqueue_TYPE_push, ossl_pqueue_TYPE_peek, ossl_pqueue_TYPE_pop, ossl_pqueue_TYPE_remove - priority queue container =head1 SYNOPSIS =for openssl generic #include "internal/priority_queue.h" PRIORITY_QUEUE_OF(type); DEFINE_PRIORITY_QUEUE_OF(NAME, TYPE) size_t ossl_pqueue_TYPE_num(const PRIORITY_QUEUE_OF(type) *pq); PRIORITY_QUEUE_OF(type) *ossl_pqueue_TYPE_new(int (*compare)(const type *, const type *)); void ossl_pqueue_TYPE_free(PRIORITY_QUEUE_OF(type) *pq); void ossl_pqueue_TYPE_pop_free(PRIORITY_QUEUE_OF(type) *pq, void (*free_func)(type *)); int ossl_pqueue_TYPE_reserve(PRIORITY_QUEUE_OF(type) *pq, size_t n); int ossl_pqueue_TYPE_push(PRIORITY_QUEUE_OF(type) *pq, type *data, size_t *elem); type *ossl_pqueue_TYPE_peek(const PRIORITY_QUEUE_OF(type) *pq); type *ossl_pqueue_TYPE_pop(const PRIORITY_QUEUE_OF(type) *pq); type *ossl_pqueue_TYPE_remove(const PRIORITY_QUEUE_OF(type) *pq, size_t elem); =head1 DESCRIPTION Create a type safe priority queue container. These macros define typesafe inline functions that wrap internal routines. In the description here, B> is used as a placeholder for any datatype. The PRIORITY_QUEUE_OF() macro returns the name for a priority queue of the specified B>. This is an opaque pointer to a structure declaration. DEFINE_PRIORITY_QUEUE_OF() creates a set of functions for a priority queue of B> elements. The type is represented by B(B>) and each function name begins with B_>. B_num>() returns the number of elements in I or B<0> if I is NULL. B_new>() allocates a new priority queue using comparison function I. It is an error for I to be NULL. The I function is called to order two elements, it should return B<-1> if the first element is less than the second, B<0> if they are equal and B<1> otherwise. B_free>() frees up the I structure. It does I free up any elements of I. After this call I is no longer valid. B_pop_free>() frees up all elements of I and I itself. The free function freefunc() is called on each element to free it. After this call I is no longer valid. B_reserve>() allocates additional memory in the I structure such that the next I calls to B_push>() will not fail or cause memory to be allocated or reallocated. If I is zero, no additional space is reserved. On error I is unchanged. B_push>() inserts a new element with value I into the priority queue I. If not NULL, the function returns an index in B<*elem> which can be used to identify the element when calling B_remove>(). B_peek>() returns the data from the smallest element in I. B_pop>() returns the data from the smallest element in I and removes that element from the priority queue. B_remove>() returns and removes the specified element I from I. The index I must have been obtained from an earlier call made to B_push>() with the same I argument. The index I is invalidated by this function. It is undefined what happens if an attempt to remove an element that isn't in the queue is made. =head1 RETURN VALUES B_num>() returns the number of elements in the priority queue or B<0> if the passed priority queue is NULL. B_new>() returns an empty priority queue or NULL if an error occurs. B_free>() and B_pop_free>() do not return values. B_reserve>() returns B<1> on successful allocation of the required memory or B<0> on error. B_push>() returns B<1> on success or B<0> on error. B_peek>() and B_pop>() return the data from the smallest element in the priority queue. B_remove>() returns the data from the specified element. =head1 HISTORY The functions described here were all added in OpenSSL 3.2. =head1 COPYRIGHT Copyright 2022 The OpenSSL Project Authors. All Rights Reserved. Licensed under the Apache License 2.0 (the "License"). You may not use this file except in compliance with the License. You can obtain a copy in the file LICENSE in the source distribution or at L. =cut