Path: blob/main/crypto/openssl/include/internal/priority_queue.h
102383 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) * ossl_pqueue_##type##_new(int (*compare)(const ctype *, const ctype *)) \21{ \22return (PRIORITY_QUEUE_OF(type) *)ossl_pqueue_new( \23(int (*)(const void *, const void *))compare); \24} \25static ossl_unused ossl_inline void \26ossl_pqueue_##type##_free(PRIORITY_QUEUE_OF(type) * pq) \27{ \28ossl_pqueue_free((OSSL_PQUEUE *)pq); \29} \30static ossl_unused ossl_inline void \31ossl_pqueue_##type##_pop_free(PRIORITY_QUEUE_OF(type) * pq, \32void (*freefunc)(ctype *)) \33{ \34ossl_pqueue_pop_free((OSSL_PQUEUE *)pq, (void (*)(void *))freefunc); \35} \36static ossl_unused ossl_inline int \37ossl_pqueue_##type##_reserve(PRIORITY_QUEUE_OF(type) * pq, size_t n) \38{ \39return ossl_pqueue_reserve((OSSL_PQUEUE *)pq, n); \40} \41static ossl_unused ossl_inline size_t \42ossl_pqueue_##type##_num(const PRIORITY_QUEUE_OF(type) * pq) \43{ \44return ossl_pqueue_num((OSSL_PQUEUE *)pq); \45} \46static ossl_unused ossl_inline int \47ossl_pqueue_##type##_push(PRIORITY_QUEUE_OF(type) * pq, \48ctype * data, size_t *elem) \49{ \50return ossl_pqueue_push((OSSL_PQUEUE *)pq, (void *)data, elem); \51} \52static ossl_unused ossl_inline ctype * \53ossl_pqueue_##type##_peek(const PRIORITY_QUEUE_OF(type) * pq) \54{ \55return (type *)ossl_pqueue_peek((OSSL_PQUEUE *)pq); \56} \57static ossl_unused ossl_inline ctype * \58ossl_pqueue_##type##_pop(PRIORITY_QUEUE_OF(type) * pq) \59{ \60return (type *)ossl_pqueue_pop((OSSL_PQUEUE *)pq); \61} \62static ossl_unused ossl_inline ctype * \63ossl_pqueue_##type##_remove(PRIORITY_QUEUE_OF(type) * pq, \64size_t elem) \65{ \66return (type *)ossl_pqueue_remove((OSSL_PQUEUE *)pq, elem); \67} \68struct ossl_priority_queue_st_##type6970#define DEFINE_PRIORITY_QUEUE_OF(type) \71DEFINE_PRIORITY_QUEUE_OF_INTERNAL(type, type)7273typedef struct ossl_pqueue_st OSSL_PQUEUE;7475OSSL_PQUEUE *ossl_pqueue_new(int (*compare)(const void *, const void *));76void ossl_pqueue_free(OSSL_PQUEUE *pq);77void ossl_pqueue_pop_free(OSSL_PQUEUE *pq, void (*freefunc)(void *));78int ossl_pqueue_reserve(OSSL_PQUEUE *pq, size_t n);7980size_t ossl_pqueue_num(const OSSL_PQUEUE *pq);81int ossl_pqueue_push(OSSL_PQUEUE *pq, void *data, size_t *elem);82void *ossl_pqueue_peek(const OSSL_PQUEUE *pq);83void *ossl_pqueue_pop(OSSL_PQUEUE *pq);84void *ossl_pqueue_remove(OSSL_PQUEUE *pq, size_t elem);8586#endif878889