/src/fluent-bit/lib/monkey/deps/rbtree/rbtree.h
Line | Count | Source (jump to first uncovered line) |
1 | | #ifndef __INCLUDED_RBTREE_H__ |
2 | | #define __INCLUDED_RBTREE_H__ |
3 | | |
4 | | /** \file rbtree.h |
5 | | * Declaration of associated structures and functions for a simple, intrusive |
6 | | * red-black tree implementation. |
7 | | */ |
8 | | |
9 | | #ifdef __cplusplus |
10 | | extern "C" { |
11 | | #endif /* __cplusplus */ |
12 | | |
13 | | #include <stdlib.h> |
14 | | #include <assert.h> |
15 | | |
16 | | /** \defgroup rb_tree_compiler_prims Compiler Abstractions |
17 | | * Primitives used to abstract compiler-specific syntax for common details used in |
18 | | * providing hints to the compiler for optimization or linker details. |
19 | | * @{ |
20 | | */ |
21 | | |
22 | | /** |
23 | | * Macro to check if a given assertion about an argument is true |
24 | | */ |
25 | | #define RB_ASSERT_ARG(x) \ |
26 | 0 | do { \ |
27 | 0 | if (RB_UNLIKELY(!(x))) { \ |
28 | 0 | assert(#x && 0); \ |
29 | 0 | return RB_BAD_ARG; \ |
30 | 0 | } \ |
31 | 0 | } while (0) |
32 | | |
33 | | /** |
34 | | * The tagged branch is unlikely to be taken |
35 | | */ |
36 | | #ifdef _WIN32 |
37 | | #define RB_UNLIKELY(x) x |
38 | | #else |
39 | 0 | #define RB_UNLIKELY(x) __builtin_expect(!!(x), 0) |
40 | | #endif |
41 | | /**@}*/ |
42 | | |
43 | | /** \defgroup rb_tree_state State Structures |
44 | | * Structures that are used to represent state of a red-black tree, including the |
45 | | * state of the tree itself, comparison functions used to determine how the tree |
46 | | * is to be traversed, and representations of red-black tree nodes themselves. |
47 | | * @{ |
48 | | */ |
49 | | |
50 | | /** |
51 | | * Structure that represents a node in a red-black tree. Embed this in your own |
52 | | * structure in order to add your structure to the given red-black tree. |
53 | | * Users of the rb_tree_node would embed it something like |
54 | | * \code{.c} |
55 | | struct my_sample_struct { |
56 | | char *name; |
57 | | int data; |
58 | | struct rb_tree_node rnode; |
59 | | }; |
60 | | * \endcode |
61 | | * |
62 | | * \note No user of `struct rb_tree_node` should ever modify or inspect any |
63 | | * members of the structure. |
64 | | */ |
65 | | struct rb_tree_node { |
66 | | /** |
67 | | * The left child (`NULL` if empty) |
68 | | */ |
69 | | struct rb_tree_node *left; |
70 | | |
71 | | /** |
72 | | * The right child (`NULL` if empty) |
73 | | */ |
74 | | struct rb_tree_node *right; |
75 | | |
76 | | /** |
77 | | * The parent of this node (`NULL` if at root) |
78 | | */ |
79 | | struct rb_tree_node *parent; |
80 | | |
81 | | /** |
82 | | * The key for this node |
83 | | */ |
84 | | const void *key; |
85 | | |
86 | | /** |
87 | | * The color of the node |
88 | | */ |
89 | | int color; |
90 | | }; |
91 | | |
92 | | /** |
93 | | * Pointer to a function to compare two keys, and returns as follows: |
94 | | * - (0, +inf] if lhs > rhs |
95 | | * - 0 if lhs == rhs |
96 | | * - [-inf, 0) if lhs < rhs |
97 | | */ |
98 | | typedef int (*rb_cmp_func_t)(const void *lhs, const void *rhs); |
99 | | |
100 | | /** |
101 | | * Pointer to a comparison function that allows passing along state. |
102 | | * Return values are interpreted as follows: |
103 | | * (0, +inf] if lhs > rhs |
104 | | * 0 if lhs == rhs |
105 | | * [-inf, 0) if lhs < rhs |
106 | | */ |
107 | | typedef int (*rb_cmp_func_ex_t)(void *state, const void *lhs, const void *rhs); |
108 | | |
109 | | /** |
110 | | * Structure representing an RB tree's associated state. Contains all |
111 | | * the information needed to manage the lifecycle of a RB tree. |
112 | | * \note Typically users should not directly manipulate the structure, |
113 | | * but rather use the provided accessor functions. |
114 | | */ |
115 | | struct rb_tree { |
116 | | /** |
117 | | * The root of the tree |
118 | | */ |
119 | | struct rb_tree_node *root; |
120 | | |
121 | | /** |
122 | | * Predicate used for traversing the tree |
123 | | */ |
124 | | rb_cmp_func_ex_t compare; |
125 | | |
126 | | /** |
127 | | * The right-most node of the rb-tree |
128 | | */ |
129 | | struct rb_tree_node *rightmost; |
130 | | |
131 | | /** |
132 | | * Private state that can be used by the rb-tree owner |
133 | | */ |
134 | | void *state; |
135 | | }; |
136 | | |
137 | | /**@} rb_tree_state */ |
138 | | |
139 | | /** \defgroup rb_result Function Results and Error Handling |
140 | | * @{ |
141 | | */ |
142 | | /** \typedef rb_result_t |
143 | | * Value of a returned result code from a red-black tree function. |
144 | | */ |
145 | | typedef int rb_result_t; |
146 | | |
147 | | /** \defgroup rb_result_code Result Codes |
148 | | * Error codes that can be returned from any function that returns an rb_result_t. |
149 | | * @{ |
150 | | */ |
151 | | |
152 | | /** |
153 | | * Function was successful |
154 | | */ |
155 | 0 | #define RB_OK 0x0 |
156 | | /** |
157 | | * Element was not found |
158 | | */ |
159 | 0 | #define RB_NOT_FOUND 0x1 |
160 | | /** |
161 | | * Bad argument provided to function (typically unexpected NULL) |
162 | | */ |
163 | 0 | #define RB_BAD_ARG 0x2 |
164 | | /** |
165 | | * Node is a duplicate of an existing node |
166 | | */ |
167 | 0 | #define RB_DUPLICATE 0x3 |
168 | | |
169 | | /**@} rb_result_code */ |
170 | | /**@} rb_result */ |
171 | | |
172 | | /** \brief Helper to get a pointer to a containing structure. |
173 | | * Given a pointer to an rb_tree_node, a target type and a member name, |
174 | | * return a pointer to the structure containing the `struct rb_tree_node`. |
175 | | * \code{.c} |
176 | | struct sample { |
177 | | const char *name; |
178 | | struct rb_tree_node node; |
179 | | }; |
180 | | |
181 | | void test(void) |
182 | | { |
183 | | struct sample samp = { .name = "Test 123" }; |
184 | | struct rb_tree_node *samp_node = &(samp.node); |
185 | | struct sample *samp2 = RB_CONTAINER_OF(samp_node, struct sample, node); |
186 | | |
187 | | assert(&samp == samp2); |
188 | | } |
189 | | * \endcode |
190 | | * \param x The pointer to the node |
191 | | * \param type The type of the containing structure |
192 | | * \param memb The name of the `struct rb_tree_node` in the containing structure |
193 | | * \return Pointer to the containing structure of the specified type |
194 | | */ |
195 | | #define RB_CONTAINER_OF(x, type, memb) \ |
196 | | ({ \ |
197 | | const __typeof__( ((type *)0)->memb ) *__member = (x); \ |
198 | | (type *)( (char *)__member - __offsetof__(type, memb) ); \ |
199 | | }) |
200 | | |
201 | | |
202 | | /** \defgroup rb_functions Functions for Manipulating Red-Black Trees |
203 | | * All functions associated with manipulating Red-Black trees using `struct rb_tree`, |
204 | | * inluding lifecycle functions and member manipulation and state checking functions. |
205 | | * @{ |
206 | | */ |
207 | | |
208 | | /** |
209 | | * \brief Construct a new, empty red-black tree, with extended state |
210 | | * Given a region of memory at least the size of a struct rb_tree to |
211 | | * store the red-black tree metadata, update it to contain an initialized, empty |
212 | | * red-black tree, with given private state. |
213 | | * \param tree Pointer to the new tree. |
214 | | * \param compare Function used to traverse the tree. |
215 | | * \param state The private state to be passed to the compare function |
216 | | * \return RB_OK on success, an error code otherwise |
217 | | */ |
218 | | rb_result_t rb_tree_new_ex(struct rb_tree *tree, rb_cmp_func_ex_t compare, void *state); |
219 | | |
220 | | /** |
221 | | * \brief Construct a new, empty red-black tree. |
222 | | * Given a region of memory at least the size of a struct rb_tree to |
223 | | * store the red-black tree metadata, update it to contain an initialized, empty |
224 | | * red-black tree. |
225 | | * \param tree Pointer to the new tree. |
226 | | * \param compare Function used to traverse the tree. |
227 | | * \return RB_OK on success, an error code otherwise |
228 | | */ |
229 | | rb_result_t rb_tree_new(struct rb_tree *tree, |
230 | | rb_cmp_func_t compare); |
231 | | |
232 | | /** |
233 | | * \brief Destroy a Red-Black tree. |
234 | | * Clean up the state structure, clearing out the state of the tree |
235 | | * so that it no longer can be used. |
236 | | * \note Assumes that external callers will deallocate all nodes through |
237 | | * some application-specific mechanism. |
238 | | * \param tree The reference to the pointer to the tree itself. |
239 | | * \return RB_OK on success, an error code otherwise |
240 | | */ |
241 | | rb_result_t rb_tree_destroy(struct rb_tree *tree); |
242 | | |
243 | | /** |
244 | | * \brief Check if an red-black tree is empty (has no nodes). |
245 | | * If no nodes are present, returns a non-zero value in `is_empty` -- returns |
246 | | * 0 if there are nodes present. |
247 | | * \param tree The tree to check |
248 | | * \param is_empty nonzero on true, 0 otherwise |
249 | | * \return RB_OK on success, an error code otherwise |
250 | | */ |
251 | | rb_result_t rb_tree_empty(struct rb_tree *tree, int *is_empty); |
252 | | |
253 | | /** |
254 | | * \brief Find a node in the Red-Black tree given the specified key. |
255 | | * Given a key, search the RB-tree iteratively until the specified key is found. |
256 | | * This traversal is in O(log n) time, per the properties of a binary search tree. |
257 | | * \param tree The RB-tree to search |
258 | | * \param key The key to search for |
259 | | * \param value a reference to a pointer to receive the pointer to the rb_tree_node if key is found |
260 | | * \return RB_OK on success, an error code otherwise |
261 | | */ |
262 | | rb_result_t rb_tree_find(struct rb_tree *tree, |
263 | | const void *key, |
264 | | struct rb_tree_node **value); |
265 | | |
266 | | /** |
267 | | * \brief Insert a node into the tree. |
268 | | * Given a node and key, insert the node into the red-black tree and rebalance |
269 | | * the tree if appropriate. Insertion is O(log n) time, with two tree traversals |
270 | | * possible -- one for insertion (guaranteed) and one for rebalancing. |
271 | | * \param tree the RB tree to insert the node into |
272 | | * \param key The key for the node (must live as long as the node itself is in the tree) |
273 | | * \param node the node to be inserted into the tree |
274 | | * \return RB_OK on sucess, an error code otherwise |
275 | | */ |
276 | | rb_result_t rb_tree_insert(struct rb_tree *tree, |
277 | | const void *key, |
278 | | struct rb_tree_node *node); |
279 | | |
280 | | /** |
281 | | * \brief Remove the specified node from the Red-Black tree. |
282 | | * Given a pointer to the node, splice the node out of the tree, then, if applicable |
283 | | * rebalance the tree so the Red-Black properties are maintained. |
284 | | * \param tree The tree we want to remove the node from |
285 | | * \param node The the node we want to remove |
286 | | * \return RB_OK on success, an error code otherwise |
287 | | */ |
288 | | rb_result_t rb_tree_remove(struct rb_tree *tree, |
289 | | struct rb_tree_node *node); |
290 | | |
291 | | /** |
292 | | * \brief Find a node. If not found, insert the candidate. |
293 | | * Find a node with the given key. If the node is found, return it by |
294 | | * reference, without modifying the tree. If the node is not found, |
295 | | * insert the provided candidate node. |
296 | | * \note This function always will return in *value the node inserted |
297 | | * or the existing node. If you want to check if the candidate |
298 | | * node was inserted, check if `*value == new_candidate` |
299 | | * |
300 | | * \param tree The tree in question |
301 | | * \param key The key to search for |
302 | | * \param new_candidate The candidate node to insert |
303 | | * \param value The value at the given location |
304 | | * \return RB_OK on success, an error code otherwise |
305 | | */ |
306 | | rb_result_t rb_tree_find_or_insert(struct rb_tree *tree, |
307 | | void *key, |
308 | | struct rb_tree_node *new_candidate, |
309 | | struct rb_tree_node **value); |
310 | | |
311 | | /** |
312 | | * \brief Find a node. If not found, insert the candidate. |
313 | | * Find a node with the given key. If the node is found, return it by |
314 | | * reference, without modifying the tree. If the node is not found, |
315 | | * insert the provided candidate node. |
316 | | * \note This function always will return in *value the node inserted |
317 | | * or the existing node. If you want to check if the candidate |
318 | | * node was inserted, check if `*value == new_candidate` |
319 | | * |
320 | | * \param tree The tree in question |
321 | | * \param key The key to search for |
322 | | * \param new_candidate The candidate node to insert |
323 | | * \param value The value at the given location |
324 | | * |
325 | | * \return RB_OK on success, an error code otherwise |
326 | | */ |
327 | | rb_result_t rb_tree_find_or_insert(struct rb_tree *tree, |
328 | | void *key, |
329 | | struct rb_tree_node *new_candidate, |
330 | | struct rb_tree_node **value); |
331 | | /** |
332 | | * \brief Get the rightmost (greatest relative to predicate) node. |
333 | | * Return the rightmost (i.e. greatest relative to predicate) node of the Red-Black tree. |
334 | | */ |
335 | | static inline |
336 | | rb_result_t rb_tree_get_rightmost(struct rb_tree *tree, |
337 | | struct rb_tree_node **rightmost) |
338 | 0 | { |
339 | 0 | if ( (NULL == tree) || (NULL == rightmost) ) { |
340 | 0 | return RB_BAD_ARG; |
341 | 0 | } |
342 | 0 |
|
343 | 0 | *rightmost = tree->rightmost; |
344 | 0 |
|
345 | 0 | return RB_OK; |
346 | 0 | } Unexecuted instantiation: flb_config.c:rb_tree_get_rightmost Unexecuted instantiation: flb_engine.c:rb_tree_get_rightmost Unexecuted instantiation: flb_storage.c:rb_tree_get_rightmost Unexecuted instantiation: flb_metrics_exporter.c:rb_tree_get_rightmost Unexecuted instantiation: flb_hs.c:rb_tree_get_rightmost Unexecuted instantiation: flb_hs_endpoints.c:rb_tree_get_rightmost Unexecuted instantiation: flb_hs_utils.c:rb_tree_get_rightmost Unexecuted instantiation: http.c:rb_tree_get_rightmost Unexecuted instantiation: http_conn.c:rb_tree_get_rightmost Unexecuted instantiation: http_prot.c:rb_tree_get_rightmost Unexecuted instantiation: http_config.c:rb_tree_get_rightmost Unexecuted instantiation: opentelemetry.c:rb_tree_get_rightmost Unexecuted instantiation: opentelemetry_prot.c:rb_tree_get_rightmost Unexecuted instantiation: opentelemetry_config.c:rb_tree_get_rightmost Unexecuted instantiation: in_elasticsearch.c:rb_tree_get_rightmost Unexecuted instantiation: in_elasticsearch_config.c:rb_tree_get_rightmost Unexecuted instantiation: in_elasticsearch_bulk_conn.c:rb_tree_get_rightmost Unexecuted instantiation: in_elasticsearch_bulk_prot.c:rb_tree_get_rightmost Unexecuted instantiation: splunk.c:rb_tree_get_rightmost Unexecuted instantiation: splunk_conn.c:rb_tree_get_rightmost Unexecuted instantiation: splunk_prot.c:rb_tree_get_rightmost Unexecuted instantiation: splunk_config.c:rb_tree_get_rightmost Unexecuted instantiation: prom_rw.c:rb_tree_get_rightmost Unexecuted instantiation: prom_rw_prot.c:rb_tree_get_rightmost Unexecuted instantiation: prom_rw_conn.c:rb_tree_get_rightmost Unexecuted instantiation: prom_rw_config.c:rb_tree_get_rightmost Unexecuted instantiation: azure_blob.c:rb_tree_get_rightmost Unexecuted instantiation: azure_logs_ingestion.c:rb_tree_get_rightmost Unexecuted instantiation: opensearch.c:rb_tree_get_rightmost Unexecuted instantiation: td_http.c:rb_tree_get_rightmost Unexecuted instantiation: opentelemetry_logs.c:rb_tree_get_rightmost Unexecuted instantiation: prom.c:rb_tree_get_rightmost Unexecuted instantiation: prom_http.c:rb_tree_get_rightmost Unexecuted instantiation: remote_write.c:rb_tree_get_rightmost Unexecuted instantiation: s3.c:rb_tree_get_rightmost Unexecuted instantiation: vivo.c:rb_tree_get_rightmost Unexecuted instantiation: vivo_http.c:rb_tree_get_rightmost Unexecuted instantiation: register.c:rb_tree_get_rightmost Unexecuted instantiation: health.c:rb_tree_get_rightmost Unexecuted instantiation: trace.c:rb_tree_get_rightmost Unexecuted instantiation: uptime.c:rb_tree_get_rightmost Unexecuted instantiation: metrics.c:rb_tree_get_rightmost Unexecuted instantiation: storage.c:rb_tree_get_rightmost Unexecuted instantiation: plugins.c:rb_tree_get_rightmost Unexecuted instantiation: reload.c:rb_tree_get_rightmost Unexecuted instantiation: flb_gzip.c:rb_tree_get_rightmost Unexecuted instantiation: flb_http_common.c:rb_tree_get_rightmost Unexecuted instantiation: flb_http_server.c:rb_tree_get_rightmost Unexecuted instantiation: flb_http_server_http1.c:rb_tree_get_rightmost Unexecuted instantiation: flb_http_server_http2.c:rb_tree_get_rightmost Unexecuted instantiation: flb_aws_compress.c:rb_tree_get_rightmost Unexecuted instantiation: mk_lib.c:rb_tree_get_rightmost Unexecuted instantiation: mk_fifo.c:rb_tree_get_rightmost Unexecuted instantiation: mk_vhost.c:rb_tree_get_rightmost Unexecuted instantiation: mk_header.c:rb_tree_get_rightmost Unexecuted instantiation: mk_config.c:rb_tree_get_rightmost Unexecuted instantiation: mk_utils.c:rb_tree_get_rightmost Unexecuted instantiation: mk_stream.c:rb_tree_get_rightmost Unexecuted instantiation: mk_scheduler.c:rb_tree_get_rightmost Unexecuted instantiation: mk_http.c:rb_tree_get_rightmost Unexecuted instantiation: mk_http_parser.c:rb_tree_get_rightmost Unexecuted instantiation: mk_http_thread.c:rb_tree_get_rightmost Unexecuted instantiation: mk_socket.c:rb_tree_get_rightmost Unexecuted instantiation: mk_net.c:rb_tree_get_rightmost Unexecuted instantiation: mk_cache.c:rb_tree_get_rightmost Unexecuted instantiation: mk_server.c:rb_tree_get_rightmost Unexecuted instantiation: mk_plugin.c:rb_tree_get_rightmost Unexecuted instantiation: monkey.c:rb_tree_get_rightmost Unexecuted instantiation: mk_mimetype.c:rb_tree_get_rightmost Unexecuted instantiation: mk_user.c:rb_tree_get_rightmost Unexecuted instantiation: mk_clock.c:rb_tree_get_rightmost Unexecuted instantiation: mk_kernel.c:rb_tree_get_rightmost Unexecuted instantiation: rbtree.c:rb_tree_get_rightmost Unexecuted instantiation: liana.c:rb_tree_get_rightmost Unexecuted instantiation: utils_fuzzer.c:rb_tree_get_rightmost |
347 | | |
348 | | |
349 | | /** |
350 | | * Find the minimum of the given tree/subtree rooted at the given node. |
351 | | */ |
352 | | static inline |
353 | | rb_result_t __rb_tree_find_minimum(struct rb_tree_node *root, |
354 | | struct rb_tree_node **min) |
355 | 0 | { |
356 | 0 | struct rb_tree_node *x = root; |
357 | 0 |
|
358 | 0 | while (x->left != NULL) { |
359 | 0 | x = x->left; |
360 | 0 | } |
361 | 0 |
|
362 | 0 | *min = x; |
363 | 0 |
|
364 | 0 | return RB_OK; |
365 | 0 | } Unexecuted instantiation: flb_config.c:__rb_tree_find_minimum Unexecuted instantiation: flb_engine.c:__rb_tree_find_minimum Unexecuted instantiation: flb_storage.c:__rb_tree_find_minimum Unexecuted instantiation: flb_metrics_exporter.c:__rb_tree_find_minimum Unexecuted instantiation: flb_hs.c:__rb_tree_find_minimum Unexecuted instantiation: flb_hs_endpoints.c:__rb_tree_find_minimum Unexecuted instantiation: flb_hs_utils.c:__rb_tree_find_minimum Unexecuted instantiation: http.c:__rb_tree_find_minimum Unexecuted instantiation: http_conn.c:__rb_tree_find_minimum Unexecuted instantiation: http_prot.c:__rb_tree_find_minimum Unexecuted instantiation: http_config.c:__rb_tree_find_minimum Unexecuted instantiation: opentelemetry.c:__rb_tree_find_minimum Unexecuted instantiation: opentelemetry_prot.c:__rb_tree_find_minimum Unexecuted instantiation: opentelemetry_config.c:__rb_tree_find_minimum Unexecuted instantiation: in_elasticsearch.c:__rb_tree_find_minimum Unexecuted instantiation: in_elasticsearch_config.c:__rb_tree_find_minimum Unexecuted instantiation: in_elasticsearch_bulk_conn.c:__rb_tree_find_minimum Unexecuted instantiation: in_elasticsearch_bulk_prot.c:__rb_tree_find_minimum Unexecuted instantiation: splunk.c:__rb_tree_find_minimum Unexecuted instantiation: splunk_conn.c:__rb_tree_find_minimum Unexecuted instantiation: splunk_prot.c:__rb_tree_find_minimum Unexecuted instantiation: splunk_config.c:__rb_tree_find_minimum Unexecuted instantiation: prom_rw.c:__rb_tree_find_minimum Unexecuted instantiation: prom_rw_prot.c:__rb_tree_find_minimum Unexecuted instantiation: prom_rw_conn.c:__rb_tree_find_minimum Unexecuted instantiation: prom_rw_config.c:__rb_tree_find_minimum Unexecuted instantiation: azure_blob.c:__rb_tree_find_minimum Unexecuted instantiation: azure_logs_ingestion.c:__rb_tree_find_minimum Unexecuted instantiation: opensearch.c:__rb_tree_find_minimum Unexecuted instantiation: td_http.c:__rb_tree_find_minimum Unexecuted instantiation: opentelemetry_logs.c:__rb_tree_find_minimum Unexecuted instantiation: prom.c:__rb_tree_find_minimum Unexecuted instantiation: prom_http.c:__rb_tree_find_minimum Unexecuted instantiation: remote_write.c:__rb_tree_find_minimum Unexecuted instantiation: s3.c:__rb_tree_find_minimum Unexecuted instantiation: vivo.c:__rb_tree_find_minimum Unexecuted instantiation: vivo_http.c:__rb_tree_find_minimum Unexecuted instantiation: register.c:__rb_tree_find_minimum Unexecuted instantiation: health.c:__rb_tree_find_minimum Unexecuted instantiation: trace.c:__rb_tree_find_minimum Unexecuted instantiation: uptime.c:__rb_tree_find_minimum Unexecuted instantiation: metrics.c:__rb_tree_find_minimum Unexecuted instantiation: storage.c:__rb_tree_find_minimum Unexecuted instantiation: plugins.c:__rb_tree_find_minimum Unexecuted instantiation: reload.c:__rb_tree_find_minimum Unexecuted instantiation: flb_gzip.c:__rb_tree_find_minimum Unexecuted instantiation: flb_http_common.c:__rb_tree_find_minimum Unexecuted instantiation: flb_http_server.c:__rb_tree_find_minimum Unexecuted instantiation: flb_http_server_http1.c:__rb_tree_find_minimum Unexecuted instantiation: flb_http_server_http2.c:__rb_tree_find_minimum Unexecuted instantiation: flb_aws_compress.c:__rb_tree_find_minimum Unexecuted instantiation: mk_lib.c:__rb_tree_find_minimum Unexecuted instantiation: mk_fifo.c:__rb_tree_find_minimum Unexecuted instantiation: mk_vhost.c:__rb_tree_find_minimum Unexecuted instantiation: mk_header.c:__rb_tree_find_minimum Unexecuted instantiation: mk_config.c:__rb_tree_find_minimum Unexecuted instantiation: mk_utils.c:__rb_tree_find_minimum Unexecuted instantiation: mk_stream.c:__rb_tree_find_minimum Unexecuted instantiation: mk_scheduler.c:__rb_tree_find_minimum Unexecuted instantiation: mk_http.c:__rb_tree_find_minimum Unexecuted instantiation: mk_http_parser.c:__rb_tree_find_minimum Unexecuted instantiation: mk_http_thread.c:__rb_tree_find_minimum Unexecuted instantiation: mk_socket.c:__rb_tree_find_minimum Unexecuted instantiation: mk_net.c:__rb_tree_find_minimum Unexecuted instantiation: mk_cache.c:__rb_tree_find_minimum Unexecuted instantiation: mk_server.c:__rb_tree_find_minimum Unexecuted instantiation: mk_plugin.c:__rb_tree_find_minimum Unexecuted instantiation: monkey.c:__rb_tree_find_minimum Unexecuted instantiation: mk_mimetype.c:__rb_tree_find_minimum Unexecuted instantiation: mk_user.c:__rb_tree_find_minimum Unexecuted instantiation: mk_clock.c:__rb_tree_find_minimum Unexecuted instantiation: mk_kernel.c:__rb_tree_find_minimum Unexecuted instantiation: rbtree.c:__rb_tree_find_minimum Unexecuted instantiation: liana.c:__rb_tree_find_minimum Unexecuted instantiation: utils_fuzzer.c:__rb_tree_find_minimum |
366 | | |
367 | | /** |
368 | | * Find the maximum of the given tree/subtree rooted at the given node. |
369 | | */ |
370 | | static inline |
371 | | rb_result_t __rb_tree_find_maximum(struct rb_tree_node *root, |
372 | | struct rb_tree_node **max) |
373 | 0 | { |
374 | 0 | struct rb_tree_node *x = root; |
375 | 0 |
|
376 | 0 | while (x->right != NULL) { |
377 | 0 | x = x->right; |
378 | 0 | } |
379 | 0 |
|
380 | 0 | *max = x; |
381 | 0 |
|
382 | 0 | return RB_OK; |
383 | 0 | } Unexecuted instantiation: flb_config.c:__rb_tree_find_maximum Unexecuted instantiation: flb_engine.c:__rb_tree_find_maximum Unexecuted instantiation: flb_storage.c:__rb_tree_find_maximum Unexecuted instantiation: flb_metrics_exporter.c:__rb_tree_find_maximum Unexecuted instantiation: flb_hs.c:__rb_tree_find_maximum Unexecuted instantiation: flb_hs_endpoints.c:__rb_tree_find_maximum Unexecuted instantiation: flb_hs_utils.c:__rb_tree_find_maximum Unexecuted instantiation: http.c:__rb_tree_find_maximum Unexecuted instantiation: http_conn.c:__rb_tree_find_maximum Unexecuted instantiation: http_prot.c:__rb_tree_find_maximum Unexecuted instantiation: http_config.c:__rb_tree_find_maximum Unexecuted instantiation: opentelemetry.c:__rb_tree_find_maximum Unexecuted instantiation: opentelemetry_prot.c:__rb_tree_find_maximum Unexecuted instantiation: opentelemetry_config.c:__rb_tree_find_maximum Unexecuted instantiation: in_elasticsearch.c:__rb_tree_find_maximum Unexecuted instantiation: in_elasticsearch_config.c:__rb_tree_find_maximum Unexecuted instantiation: in_elasticsearch_bulk_conn.c:__rb_tree_find_maximum Unexecuted instantiation: in_elasticsearch_bulk_prot.c:__rb_tree_find_maximum Unexecuted instantiation: splunk.c:__rb_tree_find_maximum Unexecuted instantiation: splunk_conn.c:__rb_tree_find_maximum Unexecuted instantiation: splunk_prot.c:__rb_tree_find_maximum Unexecuted instantiation: splunk_config.c:__rb_tree_find_maximum Unexecuted instantiation: prom_rw.c:__rb_tree_find_maximum Unexecuted instantiation: prom_rw_prot.c:__rb_tree_find_maximum Unexecuted instantiation: prom_rw_conn.c:__rb_tree_find_maximum Unexecuted instantiation: prom_rw_config.c:__rb_tree_find_maximum Unexecuted instantiation: azure_blob.c:__rb_tree_find_maximum Unexecuted instantiation: azure_logs_ingestion.c:__rb_tree_find_maximum Unexecuted instantiation: opensearch.c:__rb_tree_find_maximum Unexecuted instantiation: td_http.c:__rb_tree_find_maximum Unexecuted instantiation: opentelemetry_logs.c:__rb_tree_find_maximum Unexecuted instantiation: prom.c:__rb_tree_find_maximum Unexecuted instantiation: prom_http.c:__rb_tree_find_maximum Unexecuted instantiation: remote_write.c:__rb_tree_find_maximum Unexecuted instantiation: s3.c:__rb_tree_find_maximum Unexecuted instantiation: vivo.c:__rb_tree_find_maximum Unexecuted instantiation: vivo_http.c:__rb_tree_find_maximum Unexecuted instantiation: register.c:__rb_tree_find_maximum Unexecuted instantiation: health.c:__rb_tree_find_maximum Unexecuted instantiation: trace.c:__rb_tree_find_maximum Unexecuted instantiation: uptime.c:__rb_tree_find_maximum Unexecuted instantiation: metrics.c:__rb_tree_find_maximum Unexecuted instantiation: storage.c:__rb_tree_find_maximum Unexecuted instantiation: plugins.c:__rb_tree_find_maximum Unexecuted instantiation: reload.c:__rb_tree_find_maximum Unexecuted instantiation: flb_gzip.c:__rb_tree_find_maximum Unexecuted instantiation: flb_http_common.c:__rb_tree_find_maximum Unexecuted instantiation: flb_http_server.c:__rb_tree_find_maximum Unexecuted instantiation: flb_http_server_http1.c:__rb_tree_find_maximum Unexecuted instantiation: flb_http_server_http2.c:__rb_tree_find_maximum Unexecuted instantiation: flb_aws_compress.c:__rb_tree_find_maximum Unexecuted instantiation: mk_lib.c:__rb_tree_find_maximum Unexecuted instantiation: mk_fifo.c:__rb_tree_find_maximum Unexecuted instantiation: mk_vhost.c:__rb_tree_find_maximum Unexecuted instantiation: mk_header.c:__rb_tree_find_maximum Unexecuted instantiation: mk_config.c:__rb_tree_find_maximum Unexecuted instantiation: mk_utils.c:__rb_tree_find_maximum Unexecuted instantiation: mk_stream.c:__rb_tree_find_maximum Unexecuted instantiation: mk_scheduler.c:__rb_tree_find_maximum Unexecuted instantiation: mk_http.c:__rb_tree_find_maximum Unexecuted instantiation: mk_http_parser.c:__rb_tree_find_maximum Unexecuted instantiation: mk_http_thread.c:__rb_tree_find_maximum Unexecuted instantiation: mk_socket.c:__rb_tree_find_maximum Unexecuted instantiation: mk_net.c:__rb_tree_find_maximum Unexecuted instantiation: mk_cache.c:__rb_tree_find_maximum Unexecuted instantiation: mk_server.c:__rb_tree_find_maximum Unexecuted instantiation: mk_plugin.c:__rb_tree_find_maximum Unexecuted instantiation: monkey.c:__rb_tree_find_maximum Unexecuted instantiation: mk_mimetype.c:__rb_tree_find_maximum Unexecuted instantiation: mk_user.c:__rb_tree_find_maximum Unexecuted instantiation: mk_clock.c:__rb_tree_find_maximum Unexecuted instantiation: mk_kernel.c:__rb_tree_find_maximum Unexecuted instantiation: rbtree.c:__rb_tree_find_maximum Unexecuted instantiation: liana.c:__rb_tree_find_maximum Unexecuted instantiation: utils_fuzzer.c:__rb_tree_find_maximum |
384 | | |
385 | | /** |
386 | | * Find the successor (greater than, relative to predicate) node of the given node. |
387 | | */ |
388 | | static inline |
389 | | rb_result_t rb_tree_find_successor(struct rb_tree *tree, |
390 | | struct rb_tree_node *node, |
391 | | struct rb_tree_node **successor) |
392 | 0 | { |
393 | 0 | rb_result_t ret = RB_OK; |
394 | 0 |
|
395 | 0 | RB_ASSERT_ARG(tree != NULL); |
396 | 0 | RB_ASSERT_ARG(node != NULL); |
397 | 0 | RB_ASSERT_ARG(successor != NULL); |
398 | 0 |
|
399 | 0 | struct rb_tree_node *x = node; |
400 | 0 |
|
401 | 0 | if (x->right != NULL) { |
402 | 0 | __rb_tree_find_minimum(x->right, successor); |
403 | 0 | goto done; |
404 | 0 | } |
405 | 0 |
|
406 | 0 | struct rb_tree_node *y = x->parent; |
407 | 0 |
|
408 | 0 | while (y != NULL && (x == y->right)) { |
409 | 0 | x = y; |
410 | 0 | y = y->parent; |
411 | 0 | } |
412 | 0 |
|
413 | 0 | *successor = y; |
414 | 0 |
|
415 | 0 | done: |
416 | 0 | return ret; |
417 | 0 | } Unexecuted instantiation: flb_config.c:rb_tree_find_successor Unexecuted instantiation: flb_engine.c:rb_tree_find_successor Unexecuted instantiation: flb_storage.c:rb_tree_find_successor Unexecuted instantiation: flb_metrics_exporter.c:rb_tree_find_successor Unexecuted instantiation: flb_hs.c:rb_tree_find_successor Unexecuted instantiation: flb_hs_endpoints.c:rb_tree_find_successor Unexecuted instantiation: flb_hs_utils.c:rb_tree_find_successor Unexecuted instantiation: http.c:rb_tree_find_successor Unexecuted instantiation: http_conn.c:rb_tree_find_successor Unexecuted instantiation: http_prot.c:rb_tree_find_successor Unexecuted instantiation: http_config.c:rb_tree_find_successor Unexecuted instantiation: opentelemetry.c:rb_tree_find_successor Unexecuted instantiation: opentelemetry_prot.c:rb_tree_find_successor Unexecuted instantiation: opentelemetry_config.c:rb_tree_find_successor Unexecuted instantiation: in_elasticsearch.c:rb_tree_find_successor Unexecuted instantiation: in_elasticsearch_config.c:rb_tree_find_successor Unexecuted instantiation: in_elasticsearch_bulk_conn.c:rb_tree_find_successor Unexecuted instantiation: in_elasticsearch_bulk_prot.c:rb_tree_find_successor Unexecuted instantiation: splunk.c:rb_tree_find_successor Unexecuted instantiation: splunk_conn.c:rb_tree_find_successor Unexecuted instantiation: splunk_prot.c:rb_tree_find_successor Unexecuted instantiation: splunk_config.c:rb_tree_find_successor Unexecuted instantiation: prom_rw.c:rb_tree_find_successor Unexecuted instantiation: prom_rw_prot.c:rb_tree_find_successor Unexecuted instantiation: prom_rw_conn.c:rb_tree_find_successor Unexecuted instantiation: prom_rw_config.c:rb_tree_find_successor Unexecuted instantiation: azure_blob.c:rb_tree_find_successor Unexecuted instantiation: azure_logs_ingestion.c:rb_tree_find_successor Unexecuted instantiation: opensearch.c:rb_tree_find_successor Unexecuted instantiation: td_http.c:rb_tree_find_successor Unexecuted instantiation: opentelemetry_logs.c:rb_tree_find_successor Unexecuted instantiation: prom.c:rb_tree_find_successor Unexecuted instantiation: prom_http.c:rb_tree_find_successor Unexecuted instantiation: remote_write.c:rb_tree_find_successor Unexecuted instantiation: s3.c:rb_tree_find_successor Unexecuted instantiation: vivo.c:rb_tree_find_successor Unexecuted instantiation: vivo_http.c:rb_tree_find_successor Unexecuted instantiation: register.c:rb_tree_find_successor Unexecuted instantiation: health.c:rb_tree_find_successor Unexecuted instantiation: trace.c:rb_tree_find_successor Unexecuted instantiation: uptime.c:rb_tree_find_successor Unexecuted instantiation: metrics.c:rb_tree_find_successor Unexecuted instantiation: storage.c:rb_tree_find_successor Unexecuted instantiation: plugins.c:rb_tree_find_successor Unexecuted instantiation: reload.c:rb_tree_find_successor Unexecuted instantiation: flb_gzip.c:rb_tree_find_successor Unexecuted instantiation: flb_http_common.c:rb_tree_find_successor Unexecuted instantiation: flb_http_server.c:rb_tree_find_successor Unexecuted instantiation: flb_http_server_http1.c:rb_tree_find_successor Unexecuted instantiation: flb_http_server_http2.c:rb_tree_find_successor Unexecuted instantiation: flb_aws_compress.c:rb_tree_find_successor Unexecuted instantiation: mk_lib.c:rb_tree_find_successor Unexecuted instantiation: mk_fifo.c:rb_tree_find_successor Unexecuted instantiation: mk_vhost.c:rb_tree_find_successor Unexecuted instantiation: mk_header.c:rb_tree_find_successor Unexecuted instantiation: mk_config.c:rb_tree_find_successor Unexecuted instantiation: mk_utils.c:rb_tree_find_successor Unexecuted instantiation: mk_stream.c:rb_tree_find_successor Unexecuted instantiation: mk_scheduler.c:rb_tree_find_successor Unexecuted instantiation: mk_http.c:rb_tree_find_successor Unexecuted instantiation: mk_http_parser.c:rb_tree_find_successor Unexecuted instantiation: mk_http_thread.c:rb_tree_find_successor Unexecuted instantiation: mk_socket.c:rb_tree_find_successor Unexecuted instantiation: mk_net.c:rb_tree_find_successor Unexecuted instantiation: mk_cache.c:rb_tree_find_successor Unexecuted instantiation: mk_server.c:rb_tree_find_successor Unexecuted instantiation: mk_plugin.c:rb_tree_find_successor Unexecuted instantiation: monkey.c:rb_tree_find_successor Unexecuted instantiation: mk_mimetype.c:rb_tree_find_successor Unexecuted instantiation: mk_user.c:rb_tree_find_successor Unexecuted instantiation: mk_clock.c:rb_tree_find_successor Unexecuted instantiation: mk_kernel.c:rb_tree_find_successor Unexecuted instantiation: rbtree.c:rb_tree_find_successor Unexecuted instantiation: liana.c:rb_tree_find_successor Unexecuted instantiation: utils_fuzzer.c:rb_tree_find_successor |
418 | | |
419 | | /** |
420 | | * Find the predecessor (less than, relative to predicate) node of the given node. |
421 | | */ |
422 | | static inline |
423 | | rb_result_t rb_tree_find_predecessor(struct rb_tree *tree, |
424 | | struct rb_tree_node *node, |
425 | | struct rb_tree_node **pred) |
426 | 0 | { |
427 | 0 | rb_result_t ret = RB_OK; |
428 | 0 | struct rb_tree_node *x = node; |
429 | 0 |
|
430 | 0 | RB_ASSERT_ARG(tree != NULL); |
431 | 0 | RB_ASSERT_ARG(node != NULL); |
432 | 0 | RB_ASSERT_ARG(pred != NULL); |
433 | 0 |
|
434 | 0 | if (x->left != NULL) { |
435 | 0 | __rb_tree_find_maximum(x->left, pred); |
436 | 0 | goto done; |
437 | 0 | } |
438 | 0 |
|
439 | 0 | struct rb_tree_node *y = x->parent; |
440 | 0 |
|
441 | 0 | while (y != NULL && (x == y->left)) { |
442 | 0 | x = y; |
443 | 0 | y = y->parent; |
444 | 0 | } |
445 | 0 |
|
446 | 0 | *pred = y; |
447 | 0 |
|
448 | 0 | done: |
449 | 0 | return ret; |
450 | 0 | } Unexecuted instantiation: flb_config.c:rb_tree_find_predecessor Unexecuted instantiation: flb_engine.c:rb_tree_find_predecessor Unexecuted instantiation: flb_storage.c:rb_tree_find_predecessor Unexecuted instantiation: flb_metrics_exporter.c:rb_tree_find_predecessor Unexecuted instantiation: flb_hs.c:rb_tree_find_predecessor Unexecuted instantiation: flb_hs_endpoints.c:rb_tree_find_predecessor Unexecuted instantiation: flb_hs_utils.c:rb_tree_find_predecessor Unexecuted instantiation: http.c:rb_tree_find_predecessor Unexecuted instantiation: http_conn.c:rb_tree_find_predecessor Unexecuted instantiation: http_prot.c:rb_tree_find_predecessor Unexecuted instantiation: http_config.c:rb_tree_find_predecessor Unexecuted instantiation: opentelemetry.c:rb_tree_find_predecessor Unexecuted instantiation: opentelemetry_prot.c:rb_tree_find_predecessor Unexecuted instantiation: opentelemetry_config.c:rb_tree_find_predecessor Unexecuted instantiation: in_elasticsearch.c:rb_tree_find_predecessor Unexecuted instantiation: in_elasticsearch_config.c:rb_tree_find_predecessor Unexecuted instantiation: in_elasticsearch_bulk_conn.c:rb_tree_find_predecessor Unexecuted instantiation: in_elasticsearch_bulk_prot.c:rb_tree_find_predecessor Unexecuted instantiation: splunk.c:rb_tree_find_predecessor Unexecuted instantiation: splunk_conn.c:rb_tree_find_predecessor Unexecuted instantiation: splunk_prot.c:rb_tree_find_predecessor Unexecuted instantiation: splunk_config.c:rb_tree_find_predecessor Unexecuted instantiation: prom_rw.c:rb_tree_find_predecessor Unexecuted instantiation: prom_rw_prot.c:rb_tree_find_predecessor Unexecuted instantiation: prom_rw_conn.c:rb_tree_find_predecessor Unexecuted instantiation: prom_rw_config.c:rb_tree_find_predecessor Unexecuted instantiation: azure_blob.c:rb_tree_find_predecessor Unexecuted instantiation: azure_logs_ingestion.c:rb_tree_find_predecessor Unexecuted instantiation: opensearch.c:rb_tree_find_predecessor Unexecuted instantiation: td_http.c:rb_tree_find_predecessor Unexecuted instantiation: opentelemetry_logs.c:rb_tree_find_predecessor Unexecuted instantiation: prom.c:rb_tree_find_predecessor Unexecuted instantiation: prom_http.c:rb_tree_find_predecessor Unexecuted instantiation: remote_write.c:rb_tree_find_predecessor Unexecuted instantiation: s3.c:rb_tree_find_predecessor Unexecuted instantiation: vivo.c:rb_tree_find_predecessor Unexecuted instantiation: vivo_http.c:rb_tree_find_predecessor Unexecuted instantiation: register.c:rb_tree_find_predecessor Unexecuted instantiation: health.c:rb_tree_find_predecessor Unexecuted instantiation: trace.c:rb_tree_find_predecessor Unexecuted instantiation: uptime.c:rb_tree_find_predecessor Unexecuted instantiation: metrics.c:rb_tree_find_predecessor Unexecuted instantiation: storage.c:rb_tree_find_predecessor Unexecuted instantiation: plugins.c:rb_tree_find_predecessor Unexecuted instantiation: reload.c:rb_tree_find_predecessor Unexecuted instantiation: flb_gzip.c:rb_tree_find_predecessor Unexecuted instantiation: flb_http_common.c:rb_tree_find_predecessor Unexecuted instantiation: flb_http_server.c:rb_tree_find_predecessor Unexecuted instantiation: flb_http_server_http1.c:rb_tree_find_predecessor Unexecuted instantiation: flb_http_server_http2.c:rb_tree_find_predecessor Unexecuted instantiation: flb_aws_compress.c:rb_tree_find_predecessor Unexecuted instantiation: mk_lib.c:rb_tree_find_predecessor Unexecuted instantiation: mk_fifo.c:rb_tree_find_predecessor Unexecuted instantiation: mk_vhost.c:rb_tree_find_predecessor Unexecuted instantiation: mk_header.c:rb_tree_find_predecessor Unexecuted instantiation: mk_config.c:rb_tree_find_predecessor Unexecuted instantiation: mk_utils.c:rb_tree_find_predecessor Unexecuted instantiation: mk_stream.c:rb_tree_find_predecessor Unexecuted instantiation: mk_scheduler.c:rb_tree_find_predecessor Unexecuted instantiation: mk_http.c:rb_tree_find_predecessor Unexecuted instantiation: mk_http_parser.c:rb_tree_find_predecessor Unexecuted instantiation: mk_http_thread.c:rb_tree_find_predecessor Unexecuted instantiation: mk_socket.c:rb_tree_find_predecessor Unexecuted instantiation: mk_net.c:rb_tree_find_predecessor Unexecuted instantiation: mk_cache.c:rb_tree_find_predecessor Unexecuted instantiation: mk_server.c:rb_tree_find_predecessor Unexecuted instantiation: mk_plugin.c:rb_tree_find_predecessor Unexecuted instantiation: monkey.c:rb_tree_find_predecessor Unexecuted instantiation: mk_mimetype.c:rb_tree_find_predecessor Unexecuted instantiation: mk_user.c:rb_tree_find_predecessor Unexecuted instantiation: mk_clock.c:rb_tree_find_predecessor Unexecuted instantiation: mk_kernel.c:rb_tree_find_predecessor Unexecuted instantiation: rbtree.c:rb_tree_find_predecessor Unexecuted instantiation: liana.c:rb_tree_find_predecessor Unexecuted instantiation: utils_fuzzer.c:rb_tree_find_predecessor |
451 | | |
452 | | /**@} rb_functions */ |
453 | | |
454 | | #ifdef __cplusplus |
455 | | } // extern "C" |
456 | | #endif /* __cplusplus */ |
457 | | |
458 | | #endif /* __INCLUDED_RBTREE_H__ */ |
459 | | |