DEFINE_PRIORITY_QUEUE_OF.pod 4.7 KB

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