Coverage Report

Created: 2025-08-28 07:07

/src/openssl33/include/internal/priority_queue.h
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright 2022 The OpenSSL Project Authors. All Rights Reserved.
3
 *
4
 * Licensed under the Apache License 2.0 (the "License").  You may not use
5
 * this file except in compliance with the License.  You can obtain a copy
6
 * in the file LICENSE in the source distribution or at
7
 * https://www.openssl.org/source/license.html
8
 */
9
10
#ifndef OSSL_INTERNAL_PRIORITY_QUEUE_H
11
# define OSSL_INTERNAL_PRIORITY_QUEUE_H
12
# pragma once
13
14
# include <stdlib.h>
15
# include <openssl/e_os2.h>
16
17
# define PRIORITY_QUEUE_OF(type) OSSL_PRIORITY_QUEUE_ ## type
18
19
# define DEFINE_PRIORITY_QUEUE_OF_INTERNAL(type, ctype)                     \
20
    typedef struct ossl_priority_queue_st_ ## type PRIORITY_QUEUE_OF(type); \
21
    static ossl_unused ossl_inline PRIORITY_QUEUE_OF(type) *                \
22
    ossl_pqueue_##type##_new(int (*compare)(const ctype *, const ctype *))  \
23
3.20M
    {                                                                       \
24
3.20M
        return (PRIORITY_QUEUE_OF(type) *)ossl_pqueue_new(                  \
25
3.20M
                    (int (*)(const void *, const void *))compare);          \
26
3.20M
    }                                                                       \
27
    static ossl_unused ossl_inline void                                     \
28
    ossl_pqueue_##type##_free(PRIORITY_QUEUE_OF(type) *pq)                  \
29
3.20M
    {                                                                       \
30
3.20M
        ossl_pqueue_free((OSSL_PQUEUE *)pq);                                \
31
3.20M
    }                                                                       \
32
    static ossl_unused ossl_inline void                                     \
33
    ossl_pqueue_##type##_pop_free(PRIORITY_QUEUE_OF(type) *pq,              \
34
                                  void (*freefunc)(ctype *))                \
35
0
    {                                                                       \
36
0
        ossl_pqueue_pop_free((OSSL_PQUEUE *)pq, (void (*)(void *))freefunc);\
37
0
    }                                                                       \
38
    static ossl_unused ossl_inline int                                      \
39
    ossl_pqueue_##type##_reserve(PRIORITY_QUEUE_OF(type) *pq, size_t n)     \
40
0
    {                                                                       \
41
0
        return ossl_pqueue_reserve((OSSL_PQUEUE *)pq, n);                   \
42
0
    }                                                                       \
43
    static ossl_unused ossl_inline size_t                                   \
44
    ossl_pqueue_##type##_num(const PRIORITY_QUEUE_OF(type) *pq)             \
45
4.79M
    {                                                                       \
46
4.79M
        return ossl_pqueue_num((OSSL_PQUEUE *)pq);                          \
47
4.79M
    }                                                                       \
48
    static ossl_unused ossl_inline int                                      \
49
    ossl_pqueue_##type##_push(PRIORITY_QUEUE_OF(type) *pq,                  \
50
                              ctype *data, size_t *elem)                    \
51
3.64M
    {                                                                       \
52
3.64M
        return ossl_pqueue_push((OSSL_PQUEUE *)pq, (void *)data, elem);     \
53
3.64M
    }                                                                       \
54
    static ossl_unused ossl_inline ctype *                                  \
55
    ossl_pqueue_##type##_peek(const PRIORITY_QUEUE_OF(type) *pq)            \
56
10.6M
    {                                                                       \
57
10.6M
        return (type *)ossl_pqueue_peek((OSSL_PQUEUE *)pq);                 \
58
10.6M
    }                                                                       \
59
    static ossl_unused ossl_inline ctype *                                  \
60
    ossl_pqueue_##type##_pop(PRIORITY_QUEUE_OF(type) *pq)                   \
61
4.43M
    {                                                                       \
62
4.43M
        return (type *)ossl_pqueue_pop((OSSL_PQUEUE *)pq);                  \
63
4.43M
    }                                                                       \
64
    static ossl_unused ossl_inline ctype *                                  \
65
    ossl_pqueue_##type##_remove(PRIORITY_QUEUE_OF(type) *pq,                \
66
                                size_t elem)                                \
67
2.41M
    {                                                                       \
68
2.41M
        return (type *)ossl_pqueue_remove((OSSL_PQUEUE *)pq, elem);         \
69
2.41M
    }                                                                       \
70
    struct ossl_priority_queue_st_ ## type
71
72
# define DEFINE_PRIORITY_QUEUE_OF(type) \
73
    DEFINE_PRIORITY_QUEUE_OF_INTERNAL(type, type)
74
75
typedef struct ossl_pqueue_st OSSL_PQUEUE;
76
77
OSSL_PQUEUE *ossl_pqueue_new(int (*compare)(const void *, const void *));
78
void ossl_pqueue_free(OSSL_PQUEUE *pq);
79
void ossl_pqueue_pop_free(OSSL_PQUEUE *pq, void (*freefunc)(void *));
80
int ossl_pqueue_reserve(OSSL_PQUEUE *pq, size_t n);
81
82
size_t ossl_pqueue_num(const OSSL_PQUEUE *pq);
83
int ossl_pqueue_push(OSSL_PQUEUE *pq, void *data, size_t *elem);
84
void *ossl_pqueue_peek(const OSSL_PQUEUE *pq);
85
void *ossl_pqueue_pop(OSSL_PQUEUE *pq);
86
void *ossl_pqueue_remove(OSSL_PQUEUE *pq, size_t elem);
87
88
#endif