Path: blob/main/crypto/openssl/include/internal/priority_queue.h
34879 views
/*1* Copyright 2022 The OpenSSL Project Authors. All Rights Reserved.2*3* Licensed under the Apache License 2.0 (the "License"). You may not use4* this file except in compliance with the License. You can obtain a copy5* in the file LICENSE in the source distribution or at6* https://www.openssl.org/source/license.html7*/89#ifndef OSSL_INTERNAL_PRIORITY_QUEUE_H10# define OSSL_INTERNAL_PRIORITY_QUEUE_H11# pragma once1213# include <stdlib.h>14# include <openssl/e_os2.h>1516# define PRIORITY_QUEUE_OF(type) OSSL_PRIORITY_QUEUE_ ## type1718# define DEFINE_PRIORITY_QUEUE_OF_INTERNAL(type, ctype) \19typedef struct ossl_priority_queue_st_ ## type PRIORITY_QUEUE_OF(type); \20static ossl_unused ossl_inline PRIORITY_QUEUE_OF(type) * \21ossl_pqueue_##type##_new(int (*compare)(const ctype *, const ctype *)) \22{ \23return (PRIORITY_QUEUE_OF(type) *)ossl_pqueue_new( \24(int (*)(const void *, const void *))compare); \25} \26static ossl_unused ossl_inline void \27ossl_pqueue_##type##_free(PRIORITY_QUEUE_OF(type) *pq) \28{ \29ossl_pqueue_free((OSSL_PQUEUE *)pq); \30} \31static ossl_unused ossl_inline void \32ossl_pqueue_##type##_pop_free(PRIORITY_QUEUE_OF(type) *pq, \33void (*freefunc)(ctype *)) \34{ \35ossl_pqueue_pop_free((OSSL_PQUEUE *)pq, (void (*)(void *))freefunc);\36} \37static ossl_unused ossl_inline int \38ossl_pqueue_##type##_reserve(PRIORITY_QUEUE_OF(type) *pq, size_t n) \39{ \40return ossl_pqueue_reserve((OSSL_PQUEUE *)pq, n); \41} \42static ossl_unused ossl_inline size_t \43ossl_pqueue_##type##_num(const PRIORITY_QUEUE_OF(type) *pq) \44{ \45return ossl_pqueue_num((OSSL_PQUEUE *)pq); \46} \47static ossl_unused ossl_inline int \48ossl_pqueue_##type##_push(PRIORITY_QUEUE_OF(type) *pq, \49ctype *data, size_t *elem) \50{ \51return ossl_pqueue_push((OSSL_PQUEUE *)pq, (void *)data, elem); \52} \53static ossl_unused ossl_inline ctype * \54ossl_pqueue_##type##_peek(const PRIORITY_QUEUE_OF(type) *pq) \55{ \56return (type *)ossl_pqueue_peek((OSSL_PQUEUE *)pq); \57} \58static ossl_unused ossl_inline ctype * \59ossl_pqueue_##type##_pop(PRIORITY_QUEUE_OF(type) *pq) \60{ \61return (type *)ossl_pqueue_pop((OSSL_PQUEUE *)pq); \62} \63static ossl_unused ossl_inline ctype * \64ossl_pqueue_##type##_remove(PRIORITY_QUEUE_OF(type) *pq, \65size_t elem) \66{ \67return (type *)ossl_pqueue_remove((OSSL_PQUEUE *)pq, elem); \68} \69struct ossl_priority_queue_st_ ## type7071# define DEFINE_PRIORITY_QUEUE_OF(type) \72DEFINE_PRIORITY_QUEUE_OF_INTERNAL(type, type)7374typedef struct ossl_pqueue_st OSSL_PQUEUE;7576OSSL_PQUEUE *ossl_pqueue_new(int (*compare)(const void *, const void *));77void ossl_pqueue_free(OSSL_PQUEUE *pq);78void ossl_pqueue_pop_free(OSSL_PQUEUE *pq, void (*freefunc)(void *));79int ossl_pqueue_reserve(OSSL_PQUEUE *pq, size_t n);8081size_t ossl_pqueue_num(const OSSL_PQUEUE *pq);82int ossl_pqueue_push(OSSL_PQUEUE *pq, void *data, size_t *elem);83void *ossl_pqueue_peek(const OSSL_PQUEUE *pq);84void *ossl_pqueue_pop(OSSL_PQUEUE *pq);85void *ossl_pqueue_remove(OSSL_PQUEUE *pq, size_t elem);8687#endif888990