RTEMS 6.1-rc5
Loading...
Searching...
No Matches
rbtree.h
Go to the documentation of this file.
1/* SPDX-License-Identifier: BSD-2-Clause */
2
11/*
12 * Copyright (c) 2010 Gedare Bloom.
13 *
14 * Redistribution and use in source and binary forms, with or without
15 * modification, are permitted provided that the following conditions
16 * are met:
17 * 1. Redistributions of source code must retain the above copyright
18 * notice, this list of conditions and the following disclaimer.
19 * 2. Redistributions in binary form must reproduce the above copyright
20 * notice, this list of conditions and the following disclaimer in the
21 * documentation and/or other materials provided with the distribution.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
27 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 * POSSIBILITY OF SUCH DAMAGE.
34 */
35
36#ifndef _RTEMS_RBTREE_H
37#define _RTEMS_RBTREE_H
38
39#include <rtems/score/rbtree.h>
40
41#ifdef __cplusplus
42extern "C" {
43#endif
44
66
72typedef RBTree_Control rtems_rbtree_control;
73
82
97 const RBTree_Node *first,
98 const RBTree_Node *second
99);
100
104#define RTEMS_RBTREE_INITIALIZER_EMPTY(name) \
105 RBTREE_INITIALIZER_EMPTY(name)
106
110#define RTEMS_RBTREE_DEFINE_EMPTY(name) \
111 RBTREE_DEFINE_EMPTY(name)
112
129 rtems_rbtree_control *the_rbtree,
130 rtems_rbtree_compare compare,
131 void *starting_address,
132 size_t number_nodes,
133 size_t node_size,
134 bool is_unique
135);
136
142static inline void rtems_rbtree_initialize_empty(
143 rtems_rbtree_control *the_rbtree
144)
145{
146 _RBTree_Initialize_empty( the_rbtree );
147}
148
155static inline void rtems_rbtree_set_off_tree(
157)
158{
159 _RBTree_Set_off_tree( node );
160}
161
168static inline bool rtems_rbtree_is_node_off_tree(
169 const rtems_rbtree_node *node
170)
171{
172 return _RBTree_Is_node_off_tree( node );
173}
174
180static inline rtems_rbtree_node *rtems_rbtree_root(
181 const rtems_rbtree_control *the_rbtree
182)
183{
184 return _RBTree_Root( the_rbtree );
185}
186
190static inline rtems_rbtree_node *rtems_rbtree_min(
191 const rtems_rbtree_control *the_rbtree
192)
193{
194 return _RBTree_Minimum( the_rbtree );
195}
196
200static inline rtems_rbtree_node *rtems_rbtree_max(
201 const rtems_rbtree_control *the_rbtree
202)
203{
204 return _RBTree_Maximum( the_rbtree );
205}
206
212static inline rtems_rbtree_node *rtems_rbtree_left(
213 const rtems_rbtree_node *the_node
214)
215{
216 return _RBTree_Left( the_node );
217}
218
224static inline rtems_rbtree_node *rtems_rbtree_right(
225 const rtems_rbtree_node *the_node
226)
227{
228 return _RBTree_Right( the_node );
229}
230
234static inline rtems_rbtree_node *rtems_rbtree_parent(
235 const rtems_rbtree_node *the_node
236)
237{
238 return _RBTree_Parent( the_node );
239}
240
247static inline bool rtems_rbtree_is_empty(
248 const rtems_rbtree_control *the_rbtree
249)
250{
251 return _RBTree_Is_empty( the_rbtree );
252}
253
260static inline bool rtems_rbtree_is_min(
261 const rtems_rbtree_control *the_rbtree,
262 const rtems_rbtree_node *the_node
263)
264{
265 return rtems_rbtree_min( the_rbtree ) == the_node;
266}
267
274static inline bool rtems_rbtree_is_max(
275 const rtems_rbtree_control *the_rbtree,
276 const rtems_rbtree_node *the_node
277)
278{
279 return rtems_rbtree_max( the_rbtree ) == the_node;
280}
281
285static inline bool rtems_rbtree_is_root(
286 const rtems_rbtree_node *the_node
287)
288{
289 return _RBTree_Is_root( the_node );
290}
291
292static inline bool rtems_rbtree_is_equal(
293 rtems_rbtree_compare_result compare_result
294)
295{
296 return compare_result == 0;
297}
298
299static inline bool rtems_rbtree_is_greater(
300 rtems_rbtree_compare_result compare_result
301)
302{
303 return compare_result > 0;
304}
305
306static inline bool rtems_rbtree_is_lesser(
307 rtems_rbtree_compare_result compare_result
308)
309{
310 return compare_result < 0;
311}
312
328 const rtems_rbtree_control *the_rbtree,
329 const rtems_rbtree_node *the_node,
330 rtems_rbtree_compare compare,
331 bool is_unique
332);
333
337static inline rtems_rbtree_node* rtems_rbtree_predecessor(
338 const rtems_rbtree_node *node
339)
340{
341 return _RBTree_Predecessor( node );
342}
343
347static inline rtems_rbtree_node* rtems_rbtree_successor(
348 const rtems_rbtree_node *node
349)
350{
351 return _RBTree_Successor( node );
352}
353
357static inline void rtems_rbtree_extract(
358 rtems_rbtree_control *the_rbtree,
359 rtems_rbtree_node *the_node
360)
361{
362 _RBTree_Extract( the_rbtree, the_node );
363}
364
377static inline rtems_rbtree_node *rtems_rbtree_get_min(
378 rtems_rbtree_control *the_rbtree
379)
380{
381 rtems_rbtree_node *the_node = rtems_rbtree_min( the_rbtree );
382
383 if ( the_node != NULL ) {
384 rtems_rbtree_extract( the_rbtree, the_node );
385 }
386
387 return the_node;
388}
389
402static inline rtems_rbtree_node *rtems_rbtree_get_max(
403 rtems_rbtree_control *the_rbtree
404)
405{
406 rtems_rbtree_node *the_node = rtems_rbtree_max( the_rbtree );
407
408 if ( the_node != NULL ) {
409 rtems_rbtree_extract( the_rbtree, the_node );
410 }
411
412 return the_node;
413}
414
422static inline rtems_rbtree_node *rtems_rbtree_peek_min(
423 const rtems_rbtree_control *the_rbtree
424)
425{
426 return rtems_rbtree_min( the_rbtree );
427}
428
436static inline rtems_rbtree_node *rtems_rbtree_peek_max(
437 const rtems_rbtree_control *the_rbtree
438)
439{
440 return rtems_rbtree_max( the_rbtree );
441}
442
460 RBTree_Control *the_rbtree,
461 RBTree_Node *the_node,
462 rtems_rbtree_compare compare,
463 bool is_unique
464);
465
468#ifdef __cplusplus
469}
470#endif
471
472#endif
473/* end of include file */
RBTree_Control rtems_rbtree_control
Definition: rbtree.h:72
rtems_rbtree_compare_result(* rtems_rbtree_compare)(const RBTree_Node *first, const RBTree_Node *second)
Compares two red-black tree nodes.
Definition: rbtree.h:96
void rtems_rbtree_initialize(rtems_rbtree_control *the_rbtree, rtems_rbtree_compare compare, void *starting_address, size_t number_nodes, size_t node_size, bool is_unique)
Initialize a RBTree header.
Definition: rbtree.c:44
rtems_rbtree_node * rtems_rbtree_find(const rtems_rbtree_control *the_rbtree, const rtems_rbtree_node *the_node, rtems_rbtree_compare compare, bool is_unique)
Tries to find a node for the specified key in the tree.
Definition: rbtreefind.c:43
rtems_rbtree_node * rtems_rbtree_insert(RBTree_Control *the_rbtree, RBTree_Node *the_node, rtems_rbtree_compare compare, bool is_unique)
Inserts the node into the red-black tree.
Definition: sapirbtreeinsert.c:53
RBTree_Node rtems_rbtree_node
Definition: rbtree.h:65
long rtems_rbtree_compare_result
Integer type for compare results.
Definition: rbtree.h:81
RBTree_Node * _RBTree_Predecessor(const RBTree_Node *node)
Returns the predecessor of a node.
Definition: rbtreeprev.c:46
void _RBTree_Extract(RBTree_Control *the_rbtree, RBTree_Node *the_node)
Extracts (removes) the node from the red-black tree.
Definition: rbtreeextract.c:63
RBTree_Node * _RBTree_Maximum(const RBTree_Control *the_rbtree)
Returns the maximum node of the red-black tree.
Definition: rbtreemax.c:43
RBTree_Node * _RBTree_Successor(const RBTree_Node *node)
Returns the successor of a node.
Definition: rbtreenext.c:47
RBTree_Node * _RBTree_Minimum(const RBTree_Control *the_rbtree)
Returns the minimum node of the red-black tree.
Definition: rbtreemin.c:43
This header file provides interfaces of the Red-Black Tree Handler which are used by the implementati...
Red-black tree node.
Definition: rbtree.h:73