Home | History | Annotate | Line # | Download | only in man3
      1 =pod
      2 
      3 =head1 NAME
      4 
      5 DEFINE_PRIORITY_QUEUE_OF, PRIORITY_QUEUE_OF,
      6 ossl_pqueue_TYPE_num,
      7 ossl_pqueue_TYPE_new, ossl_pqueue_TYPE_free, ossl_pqueue_TYPE_pop_free,
      8 ossl_pqueue_TYPE_reserve,
      9 ossl_pqueue_TYPE_push, ossl_pqueue_TYPE_peek,
     10 ossl_pqueue_TYPE_pop, ossl_pqueue_TYPE_remove
     11 - priority queue container
     12 
     13 =head1 SYNOPSIS
     14 
     15 =for openssl generic
     16 
     17  #include "internal/priority_queue.h"
     18 
     19  PRIORITY_QUEUE_OF(type);
     20 
     21  DEFINE_PRIORITY_QUEUE_OF(NAME, TYPE)
     22 
     23  size_t ossl_pqueue_TYPE_num(const PRIORITY_QUEUE_OF(type) *pq);
     24  PRIORITY_QUEUE_OF(type) *ossl_pqueue_TYPE_new(int (*compare)(const type *,
     25                                                               const type *));
     26  void ossl_pqueue_TYPE_free(PRIORITY_QUEUE_OF(type) *pq);
     27  void ossl_pqueue_TYPE_pop_free(PRIORITY_QUEUE_OF(type) *pq,
     28                                 void (*free_func)(type *));
     29  int ossl_pqueue_TYPE_reserve(PRIORITY_QUEUE_OF(type) *pq, size_t n);
     30  int ossl_pqueue_TYPE_push(PRIORITY_QUEUE_OF(type) *pq, type *data,
     31                            size_t *elem);
     32  type *ossl_pqueue_TYPE_peek(const PRIORITY_QUEUE_OF(type) *pq);
     33  type *ossl_pqueue_TYPE_pop(const PRIORITY_QUEUE_OF(type) *pq);
     34  type *ossl_pqueue_TYPE_remove(const PRIORITY_QUEUE_OF(type) *pq, size_t elem);
     35 
     36 =head1 DESCRIPTION
     37 
     38 Create a type safe priority queue container.  These macros define typesafe
     39 inline functions that wrap internal routines. In the description here,
     40 B<I<TYPE>> is used as a placeholder for any datatype.
     41 
     42 The PRIORITY_QUEUE_OF() macro returns the name for a priority queue
     43 of the specified B<I<TYPE>>.  This is an opaque pointer to a structure
     44 declaration.
     45 
     46 DEFINE_PRIORITY_QUEUE_OF() creates a set of functions for a
     47 priority queue of B<I<TYPE>> elements.  The type is represented by
     48 B<PRIORITY_QUEUE_OF>(B<I<TYPE>>) and each function name begins with
     49 B<ossl_pqueue_I<TYPE>_>.
     50 
     51 B<ossl_pqueue_I<TYPE>_num>() returns the number of elements in I<pq>
     52 or B<0> if I<pq> is NULL.
     53 
     54 B<ossl_pqueue_I<TYPE>_new>() allocates a new priority queue using
     55 comparison function I<compare>. It is an error for I<compare> to be NULL.
     56 The I<compare> function is called to order two elements, it should return
     57 B<-1> if the first element is less than the second, B<0> if they are
     58 equal and B<1> otherwise.
     59 
     60 B<ossl_pqueue_I<TYPE>_free>() frees up the I<pq> structure. It does I<not>
     61 free up any elements of I<pq>. After this call I<pq> is no longer valid.
     62 
     63 B<ossl_pqueue_I<TYPE>_pop_free>() frees up all elements of I<pq> and I<pq>
     64 itself. The free function freefunc() is called on each element to free it.
     65 After this call I<pq> is no longer valid.
     66 
     67 B<ossl_pqueue_I<TYPE>_reserve>() allocates additional memory in the I<pq>
     68 structure such that the next I<n> calls to B<ossl_pqueue_I<TYPE>_push>()
     69 will not fail or cause memory to be allocated or reallocated. If I<n>
     70 is zero, no additional space is reserved. On error I<pq> is unchanged.
     71 
     72 B<ossl_pqueue_I<TYPE>_push>() inserts a new element with value I<data>
     73 into the priority queue I<pq>. If not NULL, the function returns an index
     74 in B<*elem> which can be used to identify the element when calling
     75 B<ossl_pqueue_I<TYPE>_remove>().
     76 
     77 B<ossl_pqueue_I<TYPE>_peek>() returns the data from the smallest element
     78 in I<pq>.
     79 
     80 B<ossl_pqueue_I<TYPE>_pop>() returns the data from the smallest element
     81 in I<pq> and removes that element from the priority queue.
     82 
     83 B<ossl_pqueue_I<TYPE>_remove>() returns and removes the specified element
     84 I<elem> from I<pq>. The index I<elem> must have been obtained from
     85 an earlier call made to B<ossl_pqueue_I<TYPE>_push>() with the same I<pq>
     86 argument.  The index I<elem> is invalidated by this function.  It is undefined
     87 what happens if an attempt to remove an element that isn't in the queue is
     88 made.
     89 
     90 =head1 RETURN VALUES
     91 
     92 B<ossl_pqueue_I<TYPE>_num>() returns the number of elements in the
     93 priority queue or B<0> if the passed priority queue is NULL.
     94 
     95 B<ossl_pqueue_I<TYPE>_new>() returns an empty priority queue or NULL if
     96 an error occurs.
     97 
     98 B<ossl_pqueue_I<TYPE>_free>() and B<ossl_pqueue_I<TYPE>_pop_free>()
     99 do not return values.
    100 
    101 B<ossl_pqueue_I<TYPE>_reserve>() returns B<1> on successful allocation
    102 of the required memory or B<0> on error.
    103 
    104 B<ossl_pqueue_I<TYPE>_push>() returns B<1> on success or B<0> on error.
    105 
    106 B<ossl_pqueue_I<TYPE>_peek>() and B<ossl_pqueue_I<TYPE>_pop>() return
    107 the data from the smallest element in the priority queue.
    108 
    109 B<ossl_pqueue_I<TYPE>_remove>() returns the data from the specified
    110 element.
    111 
    112 =head1 HISTORY
    113 
    114 The functions described here were all added in OpenSSL 3.2.
    115 
    116 =head1 COPYRIGHT
    117 
    118 Copyright 2022 The OpenSSL Project Authors. All Rights Reserved.
    119 
    120 Licensed under the Apache License 2.0 (the "License").  You may not use
    121 this file except in compliance with the License.  You can obtain a copy
    122 in the file LICENSE in the source distribution or at
    123 L<https://www.openssl.org/source/license.html>.
    124 
    125 =cut
    126