/src/freeradius-server/src/freeradius-devel/util/heap.h
Line | Count | Source |
1 | | #pragma once |
2 | | /* |
3 | | * This program is free software; you can redistribute it and/or modify |
4 | | * it under the terms of the GNU General Public License as published by |
5 | | * the Free Software Foundation; either version 2 of the License, or |
6 | | * (at your option) any later version. |
7 | | * |
8 | | * This program is distributed in the hope that it will be useful, |
9 | | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
10 | | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
11 | | * GNU General Public License for more details. |
12 | | * |
13 | | * You should have received a copy of the GNU General Public License |
14 | | * along with this program; if not, write to the Free Software |
15 | | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA |
16 | | */ |
17 | | |
18 | | /** Structures and prototypes for binary heaps |
19 | | * |
20 | | * @file src/lib/util/heap.h |
21 | | * |
22 | | * @copyright 2007 Alan DeKok |
23 | | */ |
24 | | RCSIDH(heap_h, "$Id: 83d2e03cfe3b19fb85f38547def39ae7d4ed7652 $") |
25 | | |
26 | | #ifdef __cplusplus |
27 | | extern "C" { |
28 | | #endif |
29 | | |
30 | | #include <freeradius-devel/build.h> |
31 | | #include <freeradius-devel/missing.h> |
32 | | #include <freeradius-devel/util/misc.h> |
33 | | #include <freeradius-devel/util/talloc.h> |
34 | | |
35 | | #include <stdint.h> |
36 | | #include <sys/types.h> |
37 | | |
38 | | /* |
39 | | * Allow public and private versions of the same structures |
40 | | */ |
41 | | #ifdef _CONST |
42 | | # error _CONST can only be defined in the local header |
43 | | #endif |
44 | | #ifndef _HEAP_PRIVATE |
45 | | # define _CONST const |
46 | | #else |
47 | | # define _CONST |
48 | | #endif |
49 | | |
50 | | /** Comparator to order heap elements |
51 | | * |
52 | | * Return CMP_LT to put 'a' at the top of the heap. |
53 | | * Return CMP_GT to put 'b' at the top of the heap. |
54 | | * Return CMP_ERR when the comparison itself failed. |
55 | | */ |
56 | | typedef fr_cmp_ret_t (*fr_heap_cmp_t)(void const *a, void const *b); |
57 | | |
58 | | /** The main heap structure |
59 | | * |
60 | | * A heap entry is made of a pointer to the object, which |
61 | | * contains the key. The heap itself is an array of pointers. |
62 | | * |
63 | | * Heaps normally support only ordered insert, and extraction |
64 | | * of the minimum element. The heap entry can contain an "int" |
65 | | * field that holds the entries position in the heap. The offset |
66 | | * of the field is held inside of the heap structure. |
67 | | */ |
68 | | typedef struct { |
69 | | unsigned int _CONST size; //!< Number of nodes allocated. |
70 | | unsigned int _CONST min; //!< Minimum number of elements we allow |
71 | | ///< the heap to reduce down to. |
72 | | size_t _CONST offset; //!< Offset of heap index in element structure. |
73 | | |
74 | | unsigned int _CONST num_elements; //!< Number of nodes used. |
75 | | |
76 | | char const * _CONST type; //!< Talloc type of elements. |
77 | | fr_heap_cmp_t _CONST cmp; //!< Comparator function. |
78 | | |
79 | | void * _CONST p[]; //!< Array of nodes. |
80 | | } fr_heap_t; |
81 | | |
82 | | typedef unsigned int fr_heap_index_t; |
83 | | typedef unsigned int fr_heap_iter_t; |
84 | | |
85 | 394k | #define FR_HEAP_INDEX_INVALID (0) |
86 | | |
87 | | /** How many talloc headers need to be pre-allocated for a heap |
88 | | */ |
89 | | #define FR_HEAP_TALLOC_HEADERS 2 |
90 | | |
91 | | size_t fr_heap_pre_alloc_size(unsigned int count); |
92 | | |
93 | | /** Creates a heap that can be used with non-talloced elements |
94 | | * |
95 | | * @param[in] _ctx Talloc ctx to allocate heap in. |
96 | | * @param[in] _cmp Comparator used to compare elements. |
97 | | * @param[in] _type Of elements. |
98 | | * @param[in] _field to store heap indexes in. |
99 | | * @param[in] _init the initial number of elements to allocate. |
100 | | * Pass 0 to use the default. |
101 | | */ |
102 | | #define fr_heap_alloc(_ctx, _cmp, _type, _field, _init) \ |
103 | 0 | _fr_heap_alloc(_ctx, _cmp, NULL, (size_t)offsetof(_type, _field), _init) |
104 | | |
105 | | /** Creates a heap that verifies elements are of a specific talloc type |
106 | | * |
107 | | * @param[in] _ctx Talloc ctx to allocate heap in. |
108 | | * @param[in] _cmp Comparator used to compare elements. |
109 | | * @param[in] _talloc_type of elements. |
110 | | * @param[in] _field to store heap indexes in. |
111 | | * @param[in] _init the initial number of elements to allocate. |
112 | | * Pass 0 to use the default. |
113 | | * @return |
114 | | * - A new heap. |
115 | | * - NULL on error. |
116 | | */ |
117 | | #define fr_heap_talloc_alloc(_ctx, _cmp, _talloc_type, _field, _init) \ |
118 | 4.92k | _fr_heap_alloc(_ctx, _cmp, #_talloc_type, (size_t)offsetof(_talloc_type, _field), _init) |
119 | | fr_heap_t *_fr_heap_alloc(TALLOC_CTX *ctx, fr_heap_cmp_t cmp, char const *talloc_type, |
120 | | size_t offset, unsigned int init) CC_HINT(nonnull(2)); |
121 | | |
122 | | /** Check if an entry is inserted into a heap |
123 | | * |
124 | | * @param[in] heap_idx from object to check. |
125 | | */ |
126 | | static inline bool fr_heap_entry_inserted(fr_heap_index_t heap_idx) |
127 | 394k | { |
128 | 394k | return (heap_idx != FR_HEAP_INDEX_INVALID); |
129 | 394k | } Unexecuted instantiation: fuzzer_cf.c:fr_heap_entry_inserted Unexecuted instantiation: fuzzer_xlat.c:fr_heap_entry_inserted Unexecuted instantiation: fuzzer_tmpl.c:fr_heap_entry_inserted Unexecuted instantiation: dl.c:fr_heap_entry_inserted heap.c:fr_heap_entry_inserted Line | Count | Source | 127 | 197k | { | 128 | 197k | return (heap_idx != FR_HEAP_INDEX_INVALID); | 129 | 197k | } |
Unexecuted instantiation: alpn.c:fr_heap_entry_inserted Unexecuted instantiation: base.c:fr_heap_entry_inserted Unexecuted instantiation: cert.c:fr_heap_entry_inserted Unexecuted instantiation: conf.c:fr_heap_entry_inserted Unexecuted instantiation: connection.c:fr_heap_entry_inserted Unexecuted instantiation: ctx.c:fr_heap_entry_inserted Unexecuted instantiation: dtls.c:fr_heap_entry_inserted Unexecuted instantiation: log.c:fr_heap_entry_inserted Unexecuted instantiation: pairs.c:fr_heap_entry_inserted Unexecuted instantiation: session.c:fr_heap_entry_inserted Unexecuted instantiation: strerror.c:fr_heap_entry_inserted Unexecuted instantiation: ticket.c:fr_heap_entry_inserted Unexecuted instantiation: ticket_stateful.c:fr_heap_entry_inserted Unexecuted instantiation: ticket_stateless.c:fr_heap_entry_inserted Unexecuted instantiation: utils.c:fr_heap_entry_inserted Unexecuted instantiation: verify.c:fr_heap_entry_inserted Unexecuted instantiation: version.c:fr_heap_entry_inserted Unexecuted instantiation: virtual_server.c:fr_heap_entry_inserted Unexecuted instantiation: auth.c:fr_heap_entry_inserted Unexecuted instantiation: cf_file.c:fr_heap_entry_inserted Unexecuted instantiation: cf_parse.c:fr_heap_entry_inserted Unexecuted instantiation: cf_util.c:fr_heap_entry_inserted Unexecuted instantiation: client.c:fr_heap_entry_inserted Unexecuted instantiation: command.c:fr_heap_entry_inserted Unexecuted instantiation: dependency.c:fr_heap_entry_inserted Unexecuted instantiation: dl_module.c:fr_heap_entry_inserted Unexecuted instantiation: exec.c:fr_heap_entry_inserted Unexecuted instantiation: exec_legacy.c:fr_heap_entry_inserted Unexecuted instantiation: exfile.c:fr_heap_entry_inserted Unexecuted instantiation: global_lib.c:fr_heap_entry_inserted Unexecuted instantiation: main_config.c:fr_heap_entry_inserted Unexecuted instantiation: main_loop.c:fr_heap_entry_inserted Unexecuted instantiation: map.c:fr_heap_entry_inserted Unexecuted instantiation: map_proc.c:fr_heap_entry_inserted Unexecuted instantiation: module.c:fr_heap_entry_inserted Unexecuted instantiation: module_method.c:fr_heap_entry_inserted Unexecuted instantiation: module_rlm.c:fr_heap_entry_inserted Unexecuted instantiation: paircmp.c:fr_heap_entry_inserted Unexecuted instantiation: pairmove.c:fr_heap_entry_inserted Unexecuted instantiation: password.c:fr_heap_entry_inserted Unexecuted instantiation: pool.c:fr_heap_entry_inserted Unexecuted instantiation: regex.c:fr_heap_entry_inserted Unexecuted instantiation: request.c:fr_heap_entry_inserted Unexecuted instantiation: request_data.c:fr_heap_entry_inserted Unexecuted instantiation: snmp.c:fr_heap_entry_inserted Unexecuted instantiation: state.c:fr_heap_entry_inserted Unexecuted instantiation: stats.c:fr_heap_entry_inserted Unexecuted instantiation: tmpl_dcursor.c:fr_heap_entry_inserted Unexecuted instantiation: tmpl_eval.c:fr_heap_entry_inserted Unexecuted instantiation: tmpl_tokenize.c:fr_heap_entry_inserted Unexecuted instantiation: trigger.c:fr_heap_entry_inserted Unexecuted instantiation: trunk.c:fr_heap_entry_inserted Unexecuted instantiation: users_file.c:fr_heap_entry_inserted Unexecuted instantiation: util.c:fr_heap_entry_inserted Unexecuted instantiation: virtual_servers.c:fr_heap_entry_inserted Unexecuted instantiation: call.c:fr_heap_entry_inserted Unexecuted instantiation: call_env.c:fr_heap_entry_inserted Unexecuted instantiation: caller.c:fr_heap_entry_inserted Unexecuted instantiation: catch.c:fr_heap_entry_inserted Unexecuted instantiation: child_request.c:fr_heap_entry_inserted Unexecuted instantiation: compile.c:fr_heap_entry_inserted Unexecuted instantiation: condition.c:fr_heap_entry_inserted Unexecuted instantiation: detach.c:fr_heap_entry_inserted Unexecuted instantiation: edit.c:fr_heap_entry_inserted Unexecuted instantiation: finally.c:fr_heap_entry_inserted Unexecuted instantiation: foreach.c:fr_heap_entry_inserted Unexecuted instantiation: function.c:fr_heap_entry_inserted Unexecuted instantiation: group.c:fr_heap_entry_inserted Unexecuted instantiation: interpret.c:fr_heap_entry_inserted Unexecuted instantiation: interpret_synchronous.c:fr_heap_entry_inserted Unexecuted instantiation: io.c:fr_heap_entry_inserted Unexecuted instantiation: limit.c:fr_heap_entry_inserted Unexecuted instantiation: load_balance.c:fr_heap_entry_inserted Unexecuted instantiation: map_builtin.c:fr_heap_entry_inserted Unexecuted instantiation: module.c:fr_heap_entry_inserted Unexecuted instantiation: parallel.c:fr_heap_entry_inserted Unexecuted instantiation: return.c:fr_heap_entry_inserted Unexecuted instantiation: subrequest.c:fr_heap_entry_inserted Unexecuted instantiation: switch.c:fr_heap_entry_inserted Unexecuted instantiation: timeout.c:fr_heap_entry_inserted Unexecuted instantiation: tmpl.c:fr_heap_entry_inserted Unexecuted instantiation: try.c:fr_heap_entry_inserted Unexecuted instantiation: transaction.c:fr_heap_entry_inserted Unexecuted instantiation: xlat.c:fr_heap_entry_inserted Unexecuted instantiation: xlat_alloc.c:fr_heap_entry_inserted Unexecuted instantiation: xlat_builtin.c:fr_heap_entry_inserted Unexecuted instantiation: xlat_eval.c:fr_heap_entry_inserted Unexecuted instantiation: xlat_expr.c:fr_heap_entry_inserted Unexecuted instantiation: xlat_func.c:fr_heap_entry_inserted xlat_inst.c:fr_heap_entry_inserted Line | Count | Source | 127 | 197k | { | 128 | 197k | return (heap_idx != FR_HEAP_INDEX_INVALID); | 129 | 197k | } |
Unexecuted instantiation: xlat_pair.c:fr_heap_entry_inserted Unexecuted instantiation: xlat_profiling.c:fr_heap_entry_inserted Unexecuted instantiation: xlat_purify.c:fr_heap_entry_inserted Unexecuted instantiation: xlat_redundant.c:fr_heap_entry_inserted Unexecuted instantiation: xlat_tokenize.c:fr_heap_entry_inserted Unexecuted instantiation: json.c:fr_heap_entry_inserted Unexecuted instantiation: jpath.c:fr_heap_entry_inserted Unexecuted instantiation: app_io.c:fr_heap_entry_inserted Unexecuted instantiation: channel.c:fr_heap_entry_inserted Unexecuted instantiation: coord.c:fr_heap_entry_inserted Unexecuted instantiation: coord_pair.c:fr_heap_entry_inserted Unexecuted instantiation: master.c:fr_heap_entry_inserted Unexecuted instantiation: network.c:fr_heap_entry_inserted Unexecuted instantiation: schedule.c:fr_heap_entry_inserted Unexecuted instantiation: thread.c:fr_heap_entry_inserted Unexecuted instantiation: worker.c:fr_heap_entry_inserted |
130 | | |
131 | | /** Return the item from the top of the heap but don't pop it |
132 | | * |
133 | | * @param[in] h to return element from. |
134 | | * @return |
135 | | * - Element at the top of the heap. |
136 | | * - NULL if no elements remain in the heap. |
137 | | */ |
138 | | static inline void *fr_heap_peek(fr_heap_t *h) |
139 | 0 | { |
140 | 0 | if (h->num_elements == 0) return NULL; |
141 | | |
142 | 0 | return h->p[1]; |
143 | 0 | } Unexecuted instantiation: fuzzer_cf.c:fr_heap_peek Unexecuted instantiation: fuzzer_xlat.c:fr_heap_peek Unexecuted instantiation: fuzzer_tmpl.c:fr_heap_peek Unexecuted instantiation: dl.c:fr_heap_peek Unexecuted instantiation: heap.c:fr_heap_peek Unexecuted instantiation: alpn.c:fr_heap_peek Unexecuted instantiation: base.c:fr_heap_peek Unexecuted instantiation: cert.c:fr_heap_peek Unexecuted instantiation: conf.c:fr_heap_peek Unexecuted instantiation: connection.c:fr_heap_peek Unexecuted instantiation: ctx.c:fr_heap_peek Unexecuted instantiation: dtls.c:fr_heap_peek Unexecuted instantiation: log.c:fr_heap_peek Unexecuted instantiation: pairs.c:fr_heap_peek Unexecuted instantiation: session.c:fr_heap_peek Unexecuted instantiation: strerror.c:fr_heap_peek Unexecuted instantiation: ticket.c:fr_heap_peek Unexecuted instantiation: ticket_stateful.c:fr_heap_peek Unexecuted instantiation: ticket_stateless.c:fr_heap_peek Unexecuted instantiation: utils.c:fr_heap_peek Unexecuted instantiation: verify.c:fr_heap_peek Unexecuted instantiation: version.c:fr_heap_peek Unexecuted instantiation: virtual_server.c:fr_heap_peek Unexecuted instantiation: auth.c:fr_heap_peek Unexecuted instantiation: cf_file.c:fr_heap_peek Unexecuted instantiation: cf_parse.c:fr_heap_peek Unexecuted instantiation: cf_util.c:fr_heap_peek Unexecuted instantiation: client.c:fr_heap_peek Unexecuted instantiation: command.c:fr_heap_peek Unexecuted instantiation: dependency.c:fr_heap_peek Unexecuted instantiation: dl_module.c:fr_heap_peek Unexecuted instantiation: exec.c:fr_heap_peek Unexecuted instantiation: exec_legacy.c:fr_heap_peek Unexecuted instantiation: exfile.c:fr_heap_peek Unexecuted instantiation: global_lib.c:fr_heap_peek Unexecuted instantiation: main_config.c:fr_heap_peek Unexecuted instantiation: main_loop.c:fr_heap_peek Unexecuted instantiation: map.c:fr_heap_peek Unexecuted instantiation: map_proc.c:fr_heap_peek Unexecuted instantiation: module.c:fr_heap_peek Unexecuted instantiation: module_method.c:fr_heap_peek Unexecuted instantiation: module_rlm.c:fr_heap_peek Unexecuted instantiation: paircmp.c:fr_heap_peek Unexecuted instantiation: pairmove.c:fr_heap_peek Unexecuted instantiation: password.c:fr_heap_peek Unexecuted instantiation: pool.c:fr_heap_peek Unexecuted instantiation: regex.c:fr_heap_peek Unexecuted instantiation: request.c:fr_heap_peek Unexecuted instantiation: request_data.c:fr_heap_peek Unexecuted instantiation: snmp.c:fr_heap_peek Unexecuted instantiation: state.c:fr_heap_peek Unexecuted instantiation: stats.c:fr_heap_peek Unexecuted instantiation: tmpl_dcursor.c:fr_heap_peek Unexecuted instantiation: tmpl_eval.c:fr_heap_peek Unexecuted instantiation: tmpl_tokenize.c:fr_heap_peek Unexecuted instantiation: trigger.c:fr_heap_peek Unexecuted instantiation: trunk.c:fr_heap_peek Unexecuted instantiation: users_file.c:fr_heap_peek Unexecuted instantiation: util.c:fr_heap_peek Unexecuted instantiation: virtual_servers.c:fr_heap_peek Unexecuted instantiation: call.c:fr_heap_peek Unexecuted instantiation: call_env.c:fr_heap_peek Unexecuted instantiation: caller.c:fr_heap_peek Unexecuted instantiation: catch.c:fr_heap_peek Unexecuted instantiation: child_request.c:fr_heap_peek Unexecuted instantiation: compile.c:fr_heap_peek Unexecuted instantiation: condition.c:fr_heap_peek Unexecuted instantiation: detach.c:fr_heap_peek Unexecuted instantiation: edit.c:fr_heap_peek Unexecuted instantiation: finally.c:fr_heap_peek Unexecuted instantiation: foreach.c:fr_heap_peek Unexecuted instantiation: function.c:fr_heap_peek Unexecuted instantiation: group.c:fr_heap_peek Unexecuted instantiation: interpret.c:fr_heap_peek Unexecuted instantiation: interpret_synchronous.c:fr_heap_peek Unexecuted instantiation: io.c:fr_heap_peek Unexecuted instantiation: limit.c:fr_heap_peek Unexecuted instantiation: load_balance.c:fr_heap_peek Unexecuted instantiation: map_builtin.c:fr_heap_peek Unexecuted instantiation: parallel.c:fr_heap_peek Unexecuted instantiation: return.c:fr_heap_peek Unexecuted instantiation: subrequest.c:fr_heap_peek Unexecuted instantiation: switch.c:fr_heap_peek Unexecuted instantiation: timeout.c:fr_heap_peek Unexecuted instantiation: tmpl.c:fr_heap_peek Unexecuted instantiation: try.c:fr_heap_peek Unexecuted instantiation: transaction.c:fr_heap_peek Unexecuted instantiation: xlat.c:fr_heap_peek Unexecuted instantiation: xlat_alloc.c:fr_heap_peek Unexecuted instantiation: xlat_builtin.c:fr_heap_peek Unexecuted instantiation: xlat_eval.c:fr_heap_peek Unexecuted instantiation: xlat_expr.c:fr_heap_peek Unexecuted instantiation: xlat_func.c:fr_heap_peek Unexecuted instantiation: xlat_inst.c:fr_heap_peek Unexecuted instantiation: xlat_pair.c:fr_heap_peek Unexecuted instantiation: xlat_profiling.c:fr_heap_peek Unexecuted instantiation: xlat_purify.c:fr_heap_peek Unexecuted instantiation: xlat_redundant.c:fr_heap_peek Unexecuted instantiation: xlat_tokenize.c:fr_heap_peek Unexecuted instantiation: json.c:fr_heap_peek Unexecuted instantiation: jpath.c:fr_heap_peek Unexecuted instantiation: app_io.c:fr_heap_peek Unexecuted instantiation: channel.c:fr_heap_peek Unexecuted instantiation: coord.c:fr_heap_peek Unexecuted instantiation: coord_pair.c:fr_heap_peek Unexecuted instantiation: master.c:fr_heap_peek Unexecuted instantiation: network.c:fr_heap_peek Unexecuted instantiation: schedule.c:fr_heap_peek Unexecuted instantiation: thread.c:fr_heap_peek Unexecuted instantiation: worker.c:fr_heap_peek |
144 | | |
145 | | /** Peek at a specific index in the heap |
146 | | * |
147 | | * @param[in] h to return element from. |
148 | | * @param[in] idx to lookup |
149 | | * @return |
150 | | * - Element at the top of the heap. |
151 | | * - NULL if index outside of the range of the heap. |
152 | | */ |
153 | | static inline void *fr_heap_peek_at(fr_heap_t *h, fr_heap_index_t idx) |
154 | 0 | { |
155 | 0 | if (unlikely(idx > h->num_elements)) return NULL; |
156 | | |
157 | 0 | return h->p[idx]; |
158 | 0 | } Unexecuted instantiation: fuzzer_cf.c:fr_heap_peek_at Unexecuted instantiation: fuzzer_xlat.c:fr_heap_peek_at Unexecuted instantiation: fuzzer_tmpl.c:fr_heap_peek_at Unexecuted instantiation: dl.c:fr_heap_peek_at Unexecuted instantiation: heap.c:fr_heap_peek_at Unexecuted instantiation: alpn.c:fr_heap_peek_at Unexecuted instantiation: base.c:fr_heap_peek_at Unexecuted instantiation: cert.c:fr_heap_peek_at Unexecuted instantiation: conf.c:fr_heap_peek_at Unexecuted instantiation: connection.c:fr_heap_peek_at Unexecuted instantiation: ctx.c:fr_heap_peek_at Unexecuted instantiation: dtls.c:fr_heap_peek_at Unexecuted instantiation: log.c:fr_heap_peek_at Unexecuted instantiation: pairs.c:fr_heap_peek_at Unexecuted instantiation: session.c:fr_heap_peek_at Unexecuted instantiation: strerror.c:fr_heap_peek_at Unexecuted instantiation: ticket.c:fr_heap_peek_at Unexecuted instantiation: ticket_stateful.c:fr_heap_peek_at Unexecuted instantiation: ticket_stateless.c:fr_heap_peek_at Unexecuted instantiation: utils.c:fr_heap_peek_at Unexecuted instantiation: verify.c:fr_heap_peek_at Unexecuted instantiation: version.c:fr_heap_peek_at Unexecuted instantiation: virtual_server.c:fr_heap_peek_at Unexecuted instantiation: auth.c:fr_heap_peek_at Unexecuted instantiation: cf_file.c:fr_heap_peek_at Unexecuted instantiation: cf_parse.c:fr_heap_peek_at Unexecuted instantiation: cf_util.c:fr_heap_peek_at Unexecuted instantiation: client.c:fr_heap_peek_at Unexecuted instantiation: command.c:fr_heap_peek_at Unexecuted instantiation: dependency.c:fr_heap_peek_at Unexecuted instantiation: dl_module.c:fr_heap_peek_at Unexecuted instantiation: exec.c:fr_heap_peek_at Unexecuted instantiation: exec_legacy.c:fr_heap_peek_at Unexecuted instantiation: exfile.c:fr_heap_peek_at Unexecuted instantiation: global_lib.c:fr_heap_peek_at Unexecuted instantiation: main_config.c:fr_heap_peek_at Unexecuted instantiation: main_loop.c:fr_heap_peek_at Unexecuted instantiation: map.c:fr_heap_peek_at Unexecuted instantiation: map_proc.c:fr_heap_peek_at Unexecuted instantiation: module.c:fr_heap_peek_at Unexecuted instantiation: module_method.c:fr_heap_peek_at Unexecuted instantiation: module_rlm.c:fr_heap_peek_at Unexecuted instantiation: paircmp.c:fr_heap_peek_at Unexecuted instantiation: pairmove.c:fr_heap_peek_at Unexecuted instantiation: password.c:fr_heap_peek_at Unexecuted instantiation: pool.c:fr_heap_peek_at Unexecuted instantiation: regex.c:fr_heap_peek_at Unexecuted instantiation: request.c:fr_heap_peek_at Unexecuted instantiation: request_data.c:fr_heap_peek_at Unexecuted instantiation: snmp.c:fr_heap_peek_at Unexecuted instantiation: state.c:fr_heap_peek_at Unexecuted instantiation: stats.c:fr_heap_peek_at Unexecuted instantiation: tmpl_dcursor.c:fr_heap_peek_at Unexecuted instantiation: tmpl_eval.c:fr_heap_peek_at Unexecuted instantiation: tmpl_tokenize.c:fr_heap_peek_at Unexecuted instantiation: trigger.c:fr_heap_peek_at Unexecuted instantiation: trunk.c:fr_heap_peek_at Unexecuted instantiation: users_file.c:fr_heap_peek_at Unexecuted instantiation: util.c:fr_heap_peek_at Unexecuted instantiation: virtual_servers.c:fr_heap_peek_at Unexecuted instantiation: call.c:fr_heap_peek_at Unexecuted instantiation: call_env.c:fr_heap_peek_at Unexecuted instantiation: caller.c:fr_heap_peek_at Unexecuted instantiation: catch.c:fr_heap_peek_at Unexecuted instantiation: child_request.c:fr_heap_peek_at Unexecuted instantiation: compile.c:fr_heap_peek_at Unexecuted instantiation: condition.c:fr_heap_peek_at Unexecuted instantiation: detach.c:fr_heap_peek_at Unexecuted instantiation: edit.c:fr_heap_peek_at Unexecuted instantiation: finally.c:fr_heap_peek_at Unexecuted instantiation: foreach.c:fr_heap_peek_at Unexecuted instantiation: function.c:fr_heap_peek_at Unexecuted instantiation: group.c:fr_heap_peek_at Unexecuted instantiation: interpret.c:fr_heap_peek_at Unexecuted instantiation: interpret_synchronous.c:fr_heap_peek_at Unexecuted instantiation: io.c:fr_heap_peek_at Unexecuted instantiation: limit.c:fr_heap_peek_at Unexecuted instantiation: load_balance.c:fr_heap_peek_at Unexecuted instantiation: map_builtin.c:fr_heap_peek_at Unexecuted instantiation: parallel.c:fr_heap_peek_at Unexecuted instantiation: return.c:fr_heap_peek_at Unexecuted instantiation: subrequest.c:fr_heap_peek_at Unexecuted instantiation: switch.c:fr_heap_peek_at Unexecuted instantiation: timeout.c:fr_heap_peek_at Unexecuted instantiation: tmpl.c:fr_heap_peek_at Unexecuted instantiation: try.c:fr_heap_peek_at Unexecuted instantiation: transaction.c:fr_heap_peek_at Unexecuted instantiation: xlat.c:fr_heap_peek_at Unexecuted instantiation: xlat_alloc.c:fr_heap_peek_at Unexecuted instantiation: xlat_builtin.c:fr_heap_peek_at Unexecuted instantiation: xlat_eval.c:fr_heap_peek_at Unexecuted instantiation: xlat_expr.c:fr_heap_peek_at Unexecuted instantiation: xlat_func.c:fr_heap_peek_at Unexecuted instantiation: xlat_inst.c:fr_heap_peek_at Unexecuted instantiation: xlat_pair.c:fr_heap_peek_at Unexecuted instantiation: xlat_profiling.c:fr_heap_peek_at Unexecuted instantiation: xlat_purify.c:fr_heap_peek_at Unexecuted instantiation: xlat_redundant.c:fr_heap_peek_at Unexecuted instantiation: xlat_tokenize.c:fr_heap_peek_at Unexecuted instantiation: json.c:fr_heap_peek_at Unexecuted instantiation: jpath.c:fr_heap_peek_at Unexecuted instantiation: app_io.c:fr_heap_peek_at Unexecuted instantiation: channel.c:fr_heap_peek_at Unexecuted instantiation: coord.c:fr_heap_peek_at Unexecuted instantiation: coord_pair.c:fr_heap_peek_at Unexecuted instantiation: master.c:fr_heap_peek_at Unexecuted instantiation: network.c:fr_heap_peek_at Unexecuted instantiation: schedule.c:fr_heap_peek_at Unexecuted instantiation: thread.c:fr_heap_peek_at Unexecuted instantiation: worker.c:fr_heap_peek_at |
159 | | |
160 | | /** Peek at the last element in the heap (not necessarily the bottom) |
161 | | * |
162 | | * @param[in] h to return element from. |
163 | | * @return |
164 | | * - Last element in the heap. |
165 | | * - NULL if no elements remain in the heap. |
166 | | */ |
167 | | static inline void *fr_heap_peek_tail(fr_heap_t *h) |
168 | 0 | { |
169 | 0 | if (h->num_elements == 0) return NULL; |
170 | 0 |
|
171 | 0 | /* |
172 | 0 | * If this is NULL, we have a problem. |
173 | 0 | */ |
174 | 0 | return h->p[h->num_elements]; |
175 | 0 | } Unexecuted instantiation: fuzzer_cf.c:fr_heap_peek_tail Unexecuted instantiation: fuzzer_xlat.c:fr_heap_peek_tail Unexecuted instantiation: fuzzer_tmpl.c:fr_heap_peek_tail Unexecuted instantiation: dl.c:fr_heap_peek_tail Unexecuted instantiation: heap.c:fr_heap_peek_tail Unexecuted instantiation: alpn.c:fr_heap_peek_tail Unexecuted instantiation: base.c:fr_heap_peek_tail Unexecuted instantiation: cert.c:fr_heap_peek_tail Unexecuted instantiation: conf.c:fr_heap_peek_tail Unexecuted instantiation: connection.c:fr_heap_peek_tail Unexecuted instantiation: ctx.c:fr_heap_peek_tail Unexecuted instantiation: dtls.c:fr_heap_peek_tail Unexecuted instantiation: log.c:fr_heap_peek_tail Unexecuted instantiation: pairs.c:fr_heap_peek_tail Unexecuted instantiation: session.c:fr_heap_peek_tail Unexecuted instantiation: strerror.c:fr_heap_peek_tail Unexecuted instantiation: ticket.c:fr_heap_peek_tail Unexecuted instantiation: ticket_stateful.c:fr_heap_peek_tail Unexecuted instantiation: ticket_stateless.c:fr_heap_peek_tail Unexecuted instantiation: utils.c:fr_heap_peek_tail Unexecuted instantiation: verify.c:fr_heap_peek_tail Unexecuted instantiation: version.c:fr_heap_peek_tail Unexecuted instantiation: virtual_server.c:fr_heap_peek_tail Unexecuted instantiation: auth.c:fr_heap_peek_tail Unexecuted instantiation: cf_file.c:fr_heap_peek_tail Unexecuted instantiation: cf_parse.c:fr_heap_peek_tail Unexecuted instantiation: cf_util.c:fr_heap_peek_tail Unexecuted instantiation: client.c:fr_heap_peek_tail Unexecuted instantiation: command.c:fr_heap_peek_tail Unexecuted instantiation: dependency.c:fr_heap_peek_tail Unexecuted instantiation: dl_module.c:fr_heap_peek_tail Unexecuted instantiation: exec.c:fr_heap_peek_tail Unexecuted instantiation: exec_legacy.c:fr_heap_peek_tail Unexecuted instantiation: exfile.c:fr_heap_peek_tail Unexecuted instantiation: global_lib.c:fr_heap_peek_tail Unexecuted instantiation: main_config.c:fr_heap_peek_tail Unexecuted instantiation: main_loop.c:fr_heap_peek_tail Unexecuted instantiation: map.c:fr_heap_peek_tail Unexecuted instantiation: map_proc.c:fr_heap_peek_tail Unexecuted instantiation: module.c:fr_heap_peek_tail Unexecuted instantiation: module_method.c:fr_heap_peek_tail Unexecuted instantiation: module_rlm.c:fr_heap_peek_tail Unexecuted instantiation: paircmp.c:fr_heap_peek_tail Unexecuted instantiation: pairmove.c:fr_heap_peek_tail Unexecuted instantiation: password.c:fr_heap_peek_tail Unexecuted instantiation: pool.c:fr_heap_peek_tail Unexecuted instantiation: regex.c:fr_heap_peek_tail Unexecuted instantiation: request.c:fr_heap_peek_tail Unexecuted instantiation: request_data.c:fr_heap_peek_tail Unexecuted instantiation: snmp.c:fr_heap_peek_tail Unexecuted instantiation: state.c:fr_heap_peek_tail Unexecuted instantiation: stats.c:fr_heap_peek_tail Unexecuted instantiation: tmpl_dcursor.c:fr_heap_peek_tail Unexecuted instantiation: tmpl_eval.c:fr_heap_peek_tail Unexecuted instantiation: tmpl_tokenize.c:fr_heap_peek_tail Unexecuted instantiation: trigger.c:fr_heap_peek_tail Unexecuted instantiation: trunk.c:fr_heap_peek_tail Unexecuted instantiation: users_file.c:fr_heap_peek_tail Unexecuted instantiation: util.c:fr_heap_peek_tail Unexecuted instantiation: virtual_servers.c:fr_heap_peek_tail Unexecuted instantiation: call.c:fr_heap_peek_tail Unexecuted instantiation: call_env.c:fr_heap_peek_tail Unexecuted instantiation: caller.c:fr_heap_peek_tail Unexecuted instantiation: catch.c:fr_heap_peek_tail Unexecuted instantiation: child_request.c:fr_heap_peek_tail Unexecuted instantiation: compile.c:fr_heap_peek_tail Unexecuted instantiation: condition.c:fr_heap_peek_tail Unexecuted instantiation: detach.c:fr_heap_peek_tail Unexecuted instantiation: edit.c:fr_heap_peek_tail Unexecuted instantiation: finally.c:fr_heap_peek_tail Unexecuted instantiation: foreach.c:fr_heap_peek_tail Unexecuted instantiation: function.c:fr_heap_peek_tail Unexecuted instantiation: group.c:fr_heap_peek_tail Unexecuted instantiation: interpret.c:fr_heap_peek_tail Unexecuted instantiation: interpret_synchronous.c:fr_heap_peek_tail Unexecuted instantiation: io.c:fr_heap_peek_tail Unexecuted instantiation: limit.c:fr_heap_peek_tail Unexecuted instantiation: load_balance.c:fr_heap_peek_tail Unexecuted instantiation: map_builtin.c:fr_heap_peek_tail Unexecuted instantiation: parallel.c:fr_heap_peek_tail Unexecuted instantiation: return.c:fr_heap_peek_tail Unexecuted instantiation: subrequest.c:fr_heap_peek_tail Unexecuted instantiation: switch.c:fr_heap_peek_tail Unexecuted instantiation: timeout.c:fr_heap_peek_tail Unexecuted instantiation: tmpl.c:fr_heap_peek_tail Unexecuted instantiation: try.c:fr_heap_peek_tail Unexecuted instantiation: transaction.c:fr_heap_peek_tail Unexecuted instantiation: xlat.c:fr_heap_peek_tail Unexecuted instantiation: xlat_alloc.c:fr_heap_peek_tail Unexecuted instantiation: xlat_builtin.c:fr_heap_peek_tail Unexecuted instantiation: xlat_eval.c:fr_heap_peek_tail Unexecuted instantiation: xlat_expr.c:fr_heap_peek_tail Unexecuted instantiation: xlat_func.c:fr_heap_peek_tail Unexecuted instantiation: xlat_inst.c:fr_heap_peek_tail Unexecuted instantiation: xlat_pair.c:fr_heap_peek_tail Unexecuted instantiation: xlat_profiling.c:fr_heap_peek_tail Unexecuted instantiation: xlat_purify.c:fr_heap_peek_tail Unexecuted instantiation: xlat_redundant.c:fr_heap_peek_tail Unexecuted instantiation: xlat_tokenize.c:fr_heap_peek_tail Unexecuted instantiation: json.c:fr_heap_peek_tail Unexecuted instantiation: jpath.c:fr_heap_peek_tail Unexecuted instantiation: app_io.c:fr_heap_peek_tail Unexecuted instantiation: channel.c:fr_heap_peek_tail Unexecuted instantiation: coord.c:fr_heap_peek_tail Unexecuted instantiation: coord_pair.c:fr_heap_peek_tail Unexecuted instantiation: master.c:fr_heap_peek_tail Unexecuted instantiation: network.c:fr_heap_peek_tail Unexecuted instantiation: schedule.c:fr_heap_peek_tail Unexecuted instantiation: thread.c:fr_heap_peek_tail Unexecuted instantiation: worker.c:fr_heap_peek_tail |
176 | | |
177 | | /** Return the number of elements in the heap |
178 | | * |
179 | | * @param[in] h to return the number of elements from. |
180 | | */ |
181 | | static inline unsigned int fr_heap_num_elements(fr_heap_t *h) |
182 | 197k | { |
183 | 197k | return h->num_elements; |
184 | 197k | } Unexecuted instantiation: fuzzer_cf.c:fr_heap_num_elements Unexecuted instantiation: fuzzer_xlat.c:fr_heap_num_elements Unexecuted instantiation: fuzzer_tmpl.c:fr_heap_num_elements Unexecuted instantiation: dl.c:fr_heap_num_elements Unexecuted instantiation: heap.c:fr_heap_num_elements Unexecuted instantiation: alpn.c:fr_heap_num_elements Unexecuted instantiation: base.c:fr_heap_num_elements Unexecuted instantiation: cert.c:fr_heap_num_elements Unexecuted instantiation: conf.c:fr_heap_num_elements Unexecuted instantiation: connection.c:fr_heap_num_elements Unexecuted instantiation: ctx.c:fr_heap_num_elements Unexecuted instantiation: dtls.c:fr_heap_num_elements Unexecuted instantiation: log.c:fr_heap_num_elements Unexecuted instantiation: pairs.c:fr_heap_num_elements Unexecuted instantiation: session.c:fr_heap_num_elements Unexecuted instantiation: strerror.c:fr_heap_num_elements Unexecuted instantiation: ticket.c:fr_heap_num_elements Unexecuted instantiation: ticket_stateful.c:fr_heap_num_elements Unexecuted instantiation: ticket_stateless.c:fr_heap_num_elements Unexecuted instantiation: utils.c:fr_heap_num_elements Unexecuted instantiation: verify.c:fr_heap_num_elements Unexecuted instantiation: version.c:fr_heap_num_elements Unexecuted instantiation: virtual_server.c:fr_heap_num_elements Unexecuted instantiation: auth.c:fr_heap_num_elements Unexecuted instantiation: cf_file.c:fr_heap_num_elements Unexecuted instantiation: cf_parse.c:fr_heap_num_elements Unexecuted instantiation: cf_util.c:fr_heap_num_elements Unexecuted instantiation: client.c:fr_heap_num_elements Unexecuted instantiation: command.c:fr_heap_num_elements Unexecuted instantiation: dependency.c:fr_heap_num_elements Unexecuted instantiation: dl_module.c:fr_heap_num_elements Unexecuted instantiation: exec.c:fr_heap_num_elements Unexecuted instantiation: exec_legacy.c:fr_heap_num_elements Unexecuted instantiation: exfile.c:fr_heap_num_elements Unexecuted instantiation: global_lib.c:fr_heap_num_elements Unexecuted instantiation: main_config.c:fr_heap_num_elements Unexecuted instantiation: main_loop.c:fr_heap_num_elements Unexecuted instantiation: map.c:fr_heap_num_elements Unexecuted instantiation: map_proc.c:fr_heap_num_elements Unexecuted instantiation: module.c:fr_heap_num_elements Unexecuted instantiation: module_method.c:fr_heap_num_elements Unexecuted instantiation: module_rlm.c:fr_heap_num_elements Unexecuted instantiation: paircmp.c:fr_heap_num_elements Unexecuted instantiation: pairmove.c:fr_heap_num_elements Unexecuted instantiation: password.c:fr_heap_num_elements Unexecuted instantiation: pool.c:fr_heap_num_elements Unexecuted instantiation: regex.c:fr_heap_num_elements Unexecuted instantiation: request.c:fr_heap_num_elements Unexecuted instantiation: request_data.c:fr_heap_num_elements Unexecuted instantiation: snmp.c:fr_heap_num_elements Unexecuted instantiation: state.c:fr_heap_num_elements Unexecuted instantiation: stats.c:fr_heap_num_elements Unexecuted instantiation: tmpl_dcursor.c:fr_heap_num_elements Unexecuted instantiation: tmpl_eval.c:fr_heap_num_elements Unexecuted instantiation: tmpl_tokenize.c:fr_heap_num_elements Unexecuted instantiation: trigger.c:fr_heap_num_elements Unexecuted instantiation: trunk.c:fr_heap_num_elements Unexecuted instantiation: users_file.c:fr_heap_num_elements Unexecuted instantiation: util.c:fr_heap_num_elements Unexecuted instantiation: virtual_servers.c:fr_heap_num_elements Unexecuted instantiation: call.c:fr_heap_num_elements Unexecuted instantiation: call_env.c:fr_heap_num_elements Unexecuted instantiation: caller.c:fr_heap_num_elements Unexecuted instantiation: catch.c:fr_heap_num_elements Unexecuted instantiation: child_request.c:fr_heap_num_elements Unexecuted instantiation: compile.c:fr_heap_num_elements Unexecuted instantiation: condition.c:fr_heap_num_elements Unexecuted instantiation: detach.c:fr_heap_num_elements Unexecuted instantiation: edit.c:fr_heap_num_elements Unexecuted instantiation: finally.c:fr_heap_num_elements Unexecuted instantiation: foreach.c:fr_heap_num_elements Unexecuted instantiation: function.c:fr_heap_num_elements Unexecuted instantiation: group.c:fr_heap_num_elements Unexecuted instantiation: interpret.c:fr_heap_num_elements Unexecuted instantiation: interpret_synchronous.c:fr_heap_num_elements Unexecuted instantiation: io.c:fr_heap_num_elements Unexecuted instantiation: limit.c:fr_heap_num_elements Unexecuted instantiation: load_balance.c:fr_heap_num_elements Unexecuted instantiation: map_builtin.c:fr_heap_num_elements Unexecuted instantiation: parallel.c:fr_heap_num_elements Unexecuted instantiation: return.c:fr_heap_num_elements Unexecuted instantiation: subrequest.c:fr_heap_num_elements Unexecuted instantiation: switch.c:fr_heap_num_elements Unexecuted instantiation: timeout.c:fr_heap_num_elements Unexecuted instantiation: tmpl.c:fr_heap_num_elements Unexecuted instantiation: try.c:fr_heap_num_elements Unexecuted instantiation: transaction.c:fr_heap_num_elements Unexecuted instantiation: xlat.c:fr_heap_num_elements Unexecuted instantiation: xlat_alloc.c:fr_heap_num_elements Unexecuted instantiation: xlat_builtin.c:fr_heap_num_elements Unexecuted instantiation: xlat_eval.c:fr_heap_num_elements Unexecuted instantiation: xlat_expr.c:fr_heap_num_elements Unexecuted instantiation: xlat_func.c:fr_heap_num_elements xlat_inst.c:fr_heap_num_elements Line | Count | Source | 182 | 197k | { | 183 | 197k | return h->num_elements; | 184 | 197k | } |
Unexecuted instantiation: xlat_pair.c:fr_heap_num_elements Unexecuted instantiation: xlat_profiling.c:fr_heap_num_elements Unexecuted instantiation: xlat_purify.c:fr_heap_num_elements Unexecuted instantiation: xlat_redundant.c:fr_heap_num_elements Unexecuted instantiation: xlat_tokenize.c:fr_heap_num_elements Unexecuted instantiation: json.c:fr_heap_num_elements Unexecuted instantiation: jpath.c:fr_heap_num_elements Unexecuted instantiation: app_io.c:fr_heap_num_elements Unexecuted instantiation: channel.c:fr_heap_num_elements Unexecuted instantiation: coord.c:fr_heap_num_elements Unexecuted instantiation: coord_pair.c:fr_heap_num_elements Unexecuted instantiation: master.c:fr_heap_num_elements Unexecuted instantiation: network.c:fr_heap_num_elements Unexecuted instantiation: schedule.c:fr_heap_num_elements Unexecuted instantiation: thread.c:fr_heap_num_elements Unexecuted instantiation: worker.c:fr_heap_num_elements |
185 | | |
186 | | int fr_heap_insert(fr_heap_t **hp, void *data) CC_HINT(nonnull); |
187 | | int fr_heap_extract(fr_heap_t **hp, void *data) CC_HINT(nonnull); |
188 | | int fr_heap_pop(void **out, fr_heap_t **hp) CC_HINT(nonnull); |
189 | | |
190 | | void *fr_heap_iter_init(fr_heap_t *hp, fr_heap_iter_t *iter) CC_HINT(nonnull); |
191 | | void *fr_heap_iter_next(fr_heap_t *hp, fr_heap_iter_t *iter) CC_HINT(nonnull); |
192 | | |
193 | | /** Iterate over the contents of a heap |
194 | | * |
195 | | * @note The initializer section of a for loop can't declare variables with distinct |
196 | | * base types, so we require a containing block, and can't follow the standard |
197 | | * do {...} while(0) dodge. The code to be run for each item in the heap should |
198 | | * thus start with one open brace and end with two close braces, and shouldn't |
199 | | * be followed with a semicolon. |
200 | | * This may fake out code formatting programs and code-aware editors. |
201 | | * |
202 | | * @param[in] _heap to iterate over. |
203 | | * @param[in] _type of item the heap contains. |
204 | | * @param[in] _data Name of variable holding a pointer to the heap element. |
205 | | * Will be declared in the scope of the loop. |
206 | | */ |
207 | 0 | #define fr_heap_foreach(_heap, _type, _data) \ |
208 | 0 | { \ |
209 | 0 | fr_heap_iter_t _iter; \ |
210 | 0 | for (_type *_data = fr_heap_iter_init(_heap, &_iter); _data; _data = fr_heap_iter_next(_heap, &_iter)) |
211 | | |
212 | | #ifndef TALLOC_GET_TYPE_ABORT_NOOP |
213 | | void fr_heap_verify(char const *file, int line, fr_heap_t *hp); |
214 | 0 | # define FR_HEAP_VERIFY(_heap) fr_heap_verify(__FILE__, __LINE__, _heap) |
215 | | #elif !defined(NDEBUG) |
216 | | # define FR_HEAP_VERIFY(_heap) fr_assert(_heap) |
217 | | #else |
218 | | # define FR_HEAP_VERIFY(_heap) |
219 | | #endif |
220 | | |
221 | | #undef _CONST |
222 | | #ifdef __cplusplus |
223 | | } |
224 | | #endif |