/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: 5c615f0e4fee73795140048ce5b2eac2f3fd941f $") |
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/talloc.h> |
33 | | |
34 | | #include <stdint.h> |
35 | | #include <sys/types.h> |
36 | | |
37 | | /* |
38 | | * Allow public and private versions of the same structures |
39 | | */ |
40 | | #ifdef _CONST |
41 | | # error _CONST can only be defined in the local header |
42 | | #endif |
43 | | #ifndef _HEAP_PRIVATE |
44 | | # define _CONST const |
45 | | #else |
46 | | # define _CONST |
47 | | #endif |
48 | | |
49 | | /** Comparator to order heap elements |
50 | | * |
51 | | * Return negative numbers to put 'a' at the top of the heap. |
52 | | * Return positive numbers to put 'b' at the top of the heap. |
53 | | */ |
54 | | typedef int8_t (*fr_heap_cmp_t)(void const *a, void const *b); |
55 | | |
56 | | /** The main heap structure |
57 | | * |
58 | | * A heap entry is made of a pointer to the object, which |
59 | | * contains the key. The heap itself is an array of pointers. |
60 | | * |
61 | | * Heaps normally support only ordered insert, and extraction |
62 | | * of the minimum element. The heap entry can contain an "int" |
63 | | * field that holds the entries position in the heap. The offset |
64 | | * of the field is held inside of the heap structure. |
65 | | */ |
66 | | typedef struct { |
67 | | unsigned int _CONST size; //!< Number of nodes allocated. |
68 | | unsigned int _CONST min; //!< Minimum number of elements we allow |
69 | | ///< the heap to reduce down to. |
70 | | size_t _CONST offset; //!< Offset of heap index in element structure. |
71 | | |
72 | | unsigned int _CONST num_elements; //!< Number of nodes used. |
73 | | |
74 | | char const * _CONST type; //!< Talloc type of elements. |
75 | | fr_heap_cmp_t _CONST cmp; //!< Comparator function. |
76 | | |
77 | | void * _CONST p[]; //!< Array of nodes. |
78 | | } fr_heap_t; |
79 | | |
80 | | typedef unsigned int fr_heap_index_t; |
81 | | typedef unsigned int fr_heap_iter_t; |
82 | | |
83 | 0 | #define FR_HEAP_INDEX_INVALID (0) |
84 | | |
85 | | /** How many talloc headers need to be pre-allocated for a heap |
86 | | */ |
87 | | #define FR_HEAP_TALLOC_HEADERS 2 |
88 | | |
89 | | size_t fr_heap_pre_alloc_size(unsigned int count); |
90 | | |
91 | | /** Creates a heap that can be used with non-talloced elements |
92 | | * |
93 | | * @param[in] _ctx Talloc ctx to allocate heap in. |
94 | | * @param[in] _cmp Comparator used to compare elements. |
95 | | * @param[in] _type Of elements. |
96 | | * @param[in] _field to store heap indexes in. |
97 | | * @param[in] _init the initial number of elements to allocate. |
98 | | * Pass 0 to use the default. |
99 | | */ |
100 | | #define fr_heap_alloc(_ctx, _cmp, _type, _field, _init) \ |
101 | 0 | _fr_heap_alloc(_ctx, _cmp, NULL, (size_t)offsetof(_type, _field), _init) |
102 | | |
103 | | /** Creates a heap that verifies elements are of a specific talloc type |
104 | | * |
105 | | * @param[in] _ctx Talloc ctx to allocate heap in. |
106 | | * @param[in] _cmp Comparator used to compare elements. |
107 | | * @param[in] _talloc_type of elements. |
108 | | * @param[in] _field to store heap indexes in. |
109 | | * @param[in] _init the initial number of elements to allocate. |
110 | | * Pass 0 to use the default. |
111 | | * @return |
112 | | * - A new heap. |
113 | | * - NULL on error. |
114 | | */ |
115 | | #define fr_heap_talloc_alloc(_ctx, _cmp, _talloc_type, _field, _init) \ |
116 | 0 | _fr_heap_alloc(_ctx, _cmp, #_talloc_type, (size_t)offsetof(_talloc_type, _field), _init) |
117 | | fr_heap_t *_fr_heap_alloc(TALLOC_CTX *ctx, fr_heap_cmp_t cmp, char const *talloc_type, |
118 | | size_t offset, unsigned int init) CC_HINT(nonnull(2)); |
119 | | |
120 | | /** Check if an entry is inserted into a heap |
121 | | * |
122 | | * @param[in] heap_idx from object to check. |
123 | | */ |
124 | | static inline bool fr_heap_entry_inserted(fr_heap_index_t heap_idx) |
125 | 0 | { |
126 | 0 | return (heap_idx != FR_HEAP_INDEX_INVALID); |
127 | 0 | } Unexecuted instantiation: dl.c:fr_heap_entry_inserted Unexecuted instantiation: heap.c:fr_heap_entry_inserted Unexecuted instantiation: json.c:fr_heap_entry_inserted Unexecuted instantiation: jpath.c:fr_heap_entry_inserted Unexecuted instantiation: base.c:fr_heap_entry_inserted Unexecuted instantiation: cache.c:fr_heap_entry_inserted Unexecuted instantiation: cert.c:fr_heap_entry_inserted Unexecuted instantiation: conf.c:fr_heap_entry_inserted Unexecuted instantiation: ctx.c:fr_heap_entry_inserted Unexecuted instantiation: engine.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: 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: connection.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 Unexecuted instantiation: xlat_inst.c:fr_heap_entry_inserted Unexecuted instantiation: xlat_pair.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: 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 |
128 | | |
129 | | /** Return the item from the top of the heap but don't pop it |
130 | | * |
131 | | * @param[in] h to return element from. |
132 | | * @return |
133 | | * - Element at the top of the heap. |
134 | | * - NULL if no elements remain in the heap. |
135 | | */ |
136 | | static inline void *fr_heap_peek(fr_heap_t *h) |
137 | 0 | { |
138 | 0 | if (h->num_elements == 0) return NULL; |
139 | | |
140 | 0 | return h->p[1]; |
141 | 0 | } Unexecuted instantiation: dl.c:fr_heap_peek Unexecuted instantiation: heap.c:fr_heap_peek Unexecuted instantiation: json.c:fr_heap_peek Unexecuted instantiation: jpath.c:fr_heap_peek Unexecuted instantiation: base.c:fr_heap_peek Unexecuted instantiation: cache.c:fr_heap_peek Unexecuted instantiation: cert.c:fr_heap_peek Unexecuted instantiation: conf.c:fr_heap_peek Unexecuted instantiation: ctx.c:fr_heap_peek Unexecuted instantiation: engine.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: 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: connection.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_purify.c:fr_heap_peek Unexecuted instantiation: xlat_redundant.c:fr_heap_peek Unexecuted instantiation: xlat_tokenize.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 |
142 | | |
143 | | /** Peek at a specific index in the heap |
144 | | * |
145 | | * @param[in] h to return element from. |
146 | | * @param[in] idx to lookup |
147 | | * @return |
148 | | * - Element at the top of the heap. |
149 | | * - NULL if index outside of the range of the heap. |
150 | | */ |
151 | | static inline void *fr_heap_peek_at(fr_heap_t *h, fr_heap_index_t idx) |
152 | 0 | { |
153 | 0 | if (unlikely(idx > h->num_elements)) return NULL; |
154 | | |
155 | 0 | return h->p[idx]; |
156 | 0 | } Unexecuted instantiation: dl.c:fr_heap_peek_at Unexecuted instantiation: heap.c:fr_heap_peek_at Unexecuted instantiation: json.c:fr_heap_peek_at Unexecuted instantiation: jpath.c:fr_heap_peek_at Unexecuted instantiation: base.c:fr_heap_peek_at Unexecuted instantiation: cache.c:fr_heap_peek_at Unexecuted instantiation: cert.c:fr_heap_peek_at Unexecuted instantiation: conf.c:fr_heap_peek_at Unexecuted instantiation: ctx.c:fr_heap_peek_at Unexecuted instantiation: engine.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: 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: connection.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_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: 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 |
157 | | |
158 | | /** Peek at the last element in the heap (not necessarily the bottom) |
159 | | * |
160 | | * @param[in] h to return element from. |
161 | | * @return |
162 | | * - Last element in the heap. |
163 | | * - NULL if no elements remain in the heap. |
164 | | */ |
165 | | static inline void *fr_heap_peek_tail(fr_heap_t *h) |
166 | 0 | { |
167 | 0 | if (h->num_elements == 0) return NULL; |
168 | 0 |
|
169 | 0 | /* |
170 | 0 | * If this is NULL, we have a problem. |
171 | 0 | */ |
172 | 0 | return h->p[h->num_elements]; |
173 | 0 | } Unexecuted instantiation: dl.c:fr_heap_peek_tail Unexecuted instantiation: heap.c:fr_heap_peek_tail Unexecuted instantiation: json.c:fr_heap_peek_tail Unexecuted instantiation: jpath.c:fr_heap_peek_tail Unexecuted instantiation: base.c:fr_heap_peek_tail Unexecuted instantiation: cache.c:fr_heap_peek_tail Unexecuted instantiation: cert.c:fr_heap_peek_tail Unexecuted instantiation: conf.c:fr_heap_peek_tail Unexecuted instantiation: ctx.c:fr_heap_peek_tail Unexecuted instantiation: engine.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: 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: connection.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_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: 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 |
174 | | |
175 | | /** Return the number of elements in the heap |
176 | | * |
177 | | * @param[in] h to return the number of elements from. |
178 | | */ |
179 | | static inline unsigned int fr_heap_num_elements(fr_heap_t *h) |
180 | 0 | { |
181 | 0 | return h->num_elements; |
182 | 0 | } Unexecuted instantiation: dl.c:fr_heap_num_elements Unexecuted instantiation: heap.c:fr_heap_num_elements Unexecuted instantiation: json.c:fr_heap_num_elements Unexecuted instantiation: jpath.c:fr_heap_num_elements Unexecuted instantiation: base.c:fr_heap_num_elements Unexecuted instantiation: cache.c:fr_heap_num_elements Unexecuted instantiation: cert.c:fr_heap_num_elements Unexecuted instantiation: conf.c:fr_heap_num_elements Unexecuted instantiation: ctx.c:fr_heap_num_elements Unexecuted instantiation: engine.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: 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: connection.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 Unexecuted instantiation: xlat_inst.c:fr_heap_num_elements Unexecuted instantiation: xlat_pair.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: 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 |
183 | | |
184 | | int fr_heap_insert(fr_heap_t **hp, void *data) CC_HINT(nonnull); |
185 | | int fr_heap_extract(fr_heap_t **hp, void *data) CC_HINT(nonnull); |
186 | | void *fr_heap_pop(fr_heap_t **hp) CC_HINT(nonnull); |
187 | | |
188 | | void *fr_heap_iter_init(fr_heap_t *hp, fr_heap_iter_t *iter) CC_HINT(nonnull); |
189 | | void *fr_heap_iter_next(fr_heap_t *hp, fr_heap_iter_t *iter) CC_HINT(nonnull); |
190 | | |
191 | | /** Iterate over the contents of a heap |
192 | | * |
193 | | * @note The initializer section of a for loop can't declare variables with distinct |
194 | | * base types, so we require a containing block, and can't follow the standard |
195 | | * do {...} while(0) dodge. The code to be run for each item in the heap should |
196 | | * thus start with one open brace and end with two close braces, and shouldn't |
197 | | * be followed with a semicolon. |
198 | | * This may fake out code formatting programs and code-aware editors. |
199 | | * |
200 | | * @param[in] _heap to iterate over. |
201 | | * @param[in] _type of item the heap contains. |
202 | | * @param[in] _data Name of variable holding a pointer to the heap element. |
203 | | * Will be declared in the scope of the loop. |
204 | | */ |
205 | 0 | #define fr_heap_foreach(_heap, _type, _data) \ |
206 | 0 | { \ |
207 | 0 | fr_heap_iter_t _iter; \ |
208 | 0 | for (_type *_data = fr_heap_iter_init(_heap, &_iter); _data; _data = fr_heap_iter_next(_heap, &_iter)) |
209 | | |
210 | | #ifndef TALLOC_GET_TYPE_ABORT_NOOP |
211 | | void fr_heap_verify(char const *file, int line, fr_heap_t *hp); |
212 | 0 | # define FR_HEAP_VERIFY(_heap) fr_heap_verify(__FILE__, __LINE__, _heap) |
213 | | #elif !defined(NDEBUG) |
214 | | # define FR_HEAP_VERIFY(_heap) fr_assert(_heap) |
215 | | #else |
216 | | # define FR_HEAP_VERIFY(_heap) |
217 | | #endif |
218 | | |
219 | | #undef _CONST |
220 | | #ifdef __cplusplus |
221 | | } |
222 | | #endif |