source: rtems/cpukit/sapi/include/rtems/rbtree.h @ 509e8d7f

5
Last change on this file since 509e8d7f was 509e8d7f, checked in by Sebastian Huber <sebastian.huber@…>, on 08/18/15 at 04:21:17

rbtree: Delete rtems_rbtree_find_control()

This function is hard to support in alternative implementations. It has
no internal use case.

  • Property mode set to 100644
File size: 9.2 KB
Line 
1/**
2 * @file
3 *
4 * @brief Constants and Structures Associated with the RBTree API in RTEMS
5 *
6 * This include file contains all the constants and structures associated
7 * with the RBTree API in RTEMS. The rbtree is a Red Black Tree that
8 * is part of the Super Core. This is the published interface to that
9 * code.
10 */
11
12/*
13 *  Copyright (c) 2010 Gedare Bloom.
14 *
15 *  The license and distribution terms for this file may be
16 *  found in the file LICENSE in this distribution or at
17 *  http://www.rtems.org/license/LICENSE.
18 */
19
20#ifndef _RTEMS_RBTREE_H
21#define _RTEMS_RBTREE_H
22
23#include <rtems/score/rbtree.h>
24
25#ifdef __cplusplus
26extern "C" {
27#endif
28
29/**
30 * @defgroup ClassicRBTrees Red-Black Trees
31 *
32 * @ingroup ClassicRTEMS
33 *
34 * @brief A Red-Black Tree container.
35 *
36 * The red-black tree container offers no internal protection against
37 * concurrent access.  The user must ensure that at most one thread at once can
38 * access a red-black tree instance.
39 *
40 * @{
41 */
42
43/**
44 * @typedef rtems_rbtree_node
45 *
46 * A node that can be manipulated in the rbtree.
47 */
48typedef RBTree_Node rtems_rbtree_node;
49
50/**
51 * @typedef rtems_rbtree_control
52 *
53 * The rbtree's control anchors the rbtree.
54 */
55typedef RBTree_Control rtems_rbtree_control;
56
57/**
58 * @copydoc RBTree_Compare_result
59 */
60typedef RBTree_Compare_result rtems_rbtree_compare_result;
61
62/**
63 * @copydoc RBTree_Compare
64 */
65typedef RBTree_Compare rtems_rbtree_compare;
66
67/**
68 * @brief RBTree initializer for an empty rbtree with designator @a name.
69 */
70#define RTEMS_RBTREE_INITIALIZER_EMPTY(name) \
71  RBTREE_INITIALIZER_EMPTY(name)
72
73/**
74 * @brief RBTree definition for an empty rbtree with designator @a name.
75 */
76#define RTEMS_RBTREE_DEFINE_EMPTY(name) \
77  RBTREE_DEFINE_EMPTY(name)
78
79/**
80 * @brief Initialize a RBTree header.
81 *
82 * This routine initializes @a the_rbtree structure to manage the
83 * contiguous array of @a number_nodes nodes which starts at
84 * @a starting_address.  Each node is of @a node_size bytes.
85 *
86 * @param[in] the_rbtree is the pointer to rbtree header
87 * @param[in] compare The node compare function.
88 * @param[in] starting_address is the starting address of first node
89 * @param[in] number_nodes is the number of nodes in rbtree
90 * @param[in] node_size is the size of node in bytes
91 * @param[in] is_unique If true, then reject nodes with a duplicate key, else
92 *   otherwise.
93 */
94void rtems_rbtree_initialize(
95  rtems_rbtree_control *the_rbtree,
96  rtems_rbtree_compare  compare,
97  void                 *starting_address,
98  size_t                number_nodes,
99  size_t                node_size,
100  bool                  is_unique
101);
102
103/**
104 * @brief Initialize this RBTree as Empty
105 *
106 * This routine initializes @a the_rbtree to contain zero nodes.
107 */
108RTEMS_INLINE_ROUTINE void rtems_rbtree_initialize_empty(
109  rtems_rbtree_control *the_rbtree
110)
111{
112  _RBTree_Initialize_empty( the_rbtree );
113}
114
115/**
116 * @brief Set off RBtree.
117 *
118 * This function sets the next and previous fields of the @a node to NULL
119 * indicating the @a node is not part of any rbtree.
120 */
121RTEMS_INLINE_ROUTINE void rtems_rbtree_set_off_tree(
122  rtems_rbtree_node *node
123)
124{
125  _RBTree_Set_off_tree( node );
126}
127
128/**
129 * @brief Is the Node off RBTree.
130 *
131 * This function returns true if the @a node is not on a rbtree. A @a node is
132 * off rbtree if the next and previous fields are set to NULL.
133 */
134RTEMS_INLINE_ROUTINE bool rtems_rbtree_is_node_off_tree(
135  const rtems_rbtree_node *node
136)
137{
138  return _RBTree_Is_node_off_tree( node );
139}
140
141/**
142 * @brief Return pointer to RBTree root.
143 *
144 * This function returns a pointer to the root node of @a the_rbtree.
145 */
146RTEMS_INLINE_ROUTINE rtems_rbtree_node *rtems_rbtree_root(
147  const rtems_rbtree_control *the_rbtree
148)
149{
150  return _RBTree_Root( the_rbtree );
151}
152
153/**
154 * @copydoc _RBTree_Minimum()
155 */
156RTEMS_INLINE_ROUTINE rtems_rbtree_node *rtems_rbtree_min(
157  const rtems_rbtree_control *the_rbtree
158)
159{
160  return _RBTree_Minimum( the_rbtree );
161}
162
163/**
164 * @copydoc _RBTree_Maximum()
165 */
166RTEMS_INLINE_ROUTINE rtems_rbtree_node *rtems_rbtree_max(
167  const rtems_rbtree_control *the_rbtree
168)
169{
170  return _RBTree_Maximum( the_rbtree );
171}
172
173/**
174 * @brief Return pointer to the left child node from this node.
175 *
176 * This function returns a pointer to the left child node of @a the_node.
177 */
178RTEMS_INLINE_ROUTINE rtems_rbtree_node *rtems_rbtree_left(
179  const rtems_rbtree_node *the_node
180)
181{
182  return _RBTree_Left( the_node );
183}
184
185/**
186 * @brief Return pointer to the right child node from this node.
187 *
188 * This function returns a pointer to the right child node of @a the_node.
189 */
190RTEMS_INLINE_ROUTINE rtems_rbtree_node *rtems_rbtree_right(
191  const rtems_rbtree_node *the_node
192)
193{
194  return _RBTree_Right( the_node );
195}
196
197/**
198 * @copydoc _RBTree_Parent()
199 */
200RTEMS_INLINE_ROUTINE rtems_rbtree_node *rtems_rbtree_parent(
201  const rtems_rbtree_node *the_node
202)
203{
204  return _RBTree_Parent( the_node );
205}
206
207/**
208 * @brief Is the RBTree empty.
209 *
210 * This function returns true if there a no nodes on @a the_rbtree and
211 * false otherwise.
212 */
213RTEMS_INLINE_ROUTINE bool rtems_rbtree_is_empty(
214  const rtems_rbtree_control *the_rbtree
215)
216{
217  return _RBTree_Is_empty( the_rbtree );
218}
219
220/**
221 * @brief Is this the minimum node on the RBTree.
222 *
223 * This function returns true if @a the_node is the min node on @a the_rbtree
224 * and false otherwise.
225 */
226RTEMS_INLINE_ROUTINE bool rtems_rbtree_is_min(
227  const rtems_rbtree_control *the_rbtree,
228  const rtems_rbtree_node *the_node
229)
230{
231  return rtems_rbtree_min( the_rbtree ) == the_node;
232}
233
234/**
235 * @brief Is this the maximum node on the RBTree.
236 *
237 * This function returns true if @a the_node is the max node on @a the_rbtree
238 * and false otherwise.
239 */
240RTEMS_INLINE_ROUTINE bool rtems_rbtree_is_max(
241  const rtems_rbtree_control *the_rbtree,
242  const rtems_rbtree_node *the_node
243)
244{
245  return rtems_rbtree_max( the_rbtree ) == the_node;
246}
247
248/**
249 * @copydoc _RBTree_Is_root()
250 */
251RTEMS_INLINE_ROUTINE bool rtems_rbtree_is_root(
252  const rtems_rbtree_node *the_node
253)
254{
255  return _RBTree_Is_root( the_node );
256}
257
258/**
259 * @copydoc _RBTree_Find()
260 */
261RTEMS_INLINE_ROUTINE rtems_rbtree_node* rtems_rbtree_find(
262  const rtems_rbtree_control *the_rbtree,
263  const rtems_rbtree_node    *the_node,
264  rtems_rbtree_compare        compare,
265  bool                        is_unique
266)
267{
268  return _RBTree_Find( the_rbtree, the_node, compare, is_unique );
269}
270
271/**
272 * @copydoc _RBTree_Predecessor()
273 */
274RTEMS_INLINE_ROUTINE rtems_rbtree_node* rtems_rbtree_predecessor(
275  const rtems_rbtree_node *node
276)
277{
278  return _RBTree_Predecessor( node );
279}
280
281/**
282 * @copydoc _RBTree_Successor()
283 */
284RTEMS_INLINE_ROUTINE rtems_rbtree_node* rtems_rbtree_successor(
285  const rtems_rbtree_node *node
286)
287{
288  return _RBTree_Successor( node );
289}
290
291/**
292 * @copydoc _RBTree_Extract()
293 */
294RTEMS_INLINE_ROUTINE void rtems_rbtree_extract(
295  rtems_rbtree_control *the_rbtree,
296  rtems_rbtree_node *the_node
297)
298{
299  _RBTree_Extract( the_rbtree, the_node );
300}
301
302/**
303 * @brief Gets a node with the minimum key value from the red-black tree.
304 *
305 * This function extracts a node with the minimum key value from
306 * tree and returns a pointer to that node if it exists.  In case multiple
307 * nodes with a minimum key value exist, then they are extracted in FIFO order.
308 *
309 * @param[in] the_rbtree The red-black tree control.
310 *
311 * @retval NULL The tree is empty.
312 * @retval node A node with the minimal key value on the tree.
313 */
314RTEMS_INLINE_ROUTINE rtems_rbtree_node *rtems_rbtree_get_min(
315  rtems_rbtree_control *the_rbtree
316)
317{
318  rtems_rbtree_node *the_node = rtems_rbtree_min( the_rbtree );
319
320  if ( the_node != NULL ) {
321    rtems_rbtree_extract( the_rbtree, the_node );
322  }
323
324  return the_node;
325}
326
327/**
328 * @brief Gets a node with the maximal key value from the red-black tree.
329 *
330 * This function extracts a node with the maximum key value from tree and
331 * returns a pointer to that node if it exists.  In case multiple nodes with a
332 * maximum key value exist, then they are extracted in LIFO order.
333 *
334 * @param[in] the_rbtree The red-black tree control.
335 *
336 * @retval NULL The tree is empty.
337 * @retval node A node with the maximal key value on the tree.
338 */
339RTEMS_INLINE_ROUTINE rtems_rbtree_node *rtems_rbtree_get_max(
340  rtems_rbtree_control *the_rbtree
341)
342{
343  rtems_rbtree_node *the_node = rtems_rbtree_max( the_rbtree );
344
345  if ( the_node != NULL ) {
346    rtems_rbtree_extract( the_rbtree, the_node );
347  }
348
349  return the_node;
350}
351
352/**
353 * @brief Peek at the min node on a rbtree.
354 *
355 * This function returns a pointer to the min node from @a the_rbtree
356 * without changing the tree.  If @a the_rbtree is empty,
357 * then NULL is returned.
358 */
359RTEMS_INLINE_ROUTINE rtems_rbtree_node *rtems_rbtree_peek_min(
360  const rtems_rbtree_control *the_rbtree
361)
362{
363  return rtems_rbtree_min( the_rbtree );
364}
365
366/**
367 * @brief Peek at the max node on a rbtree.
368 *
369 * This function returns a pointer to the max node from @a the_rbtree
370 * without changing the tree.  If @a the_rbtree is empty,
371 * then NULL is returned.
372 */
373RTEMS_INLINE_ROUTINE rtems_rbtree_node *rtems_rbtree_peek_max(
374  const rtems_rbtree_control *the_rbtree
375)
376{
377  return rtems_rbtree_max( the_rbtree );
378}
379
380/**
381 * @copydoc _RBTree_Insert()
382 */
383RTEMS_INLINE_ROUTINE rtems_rbtree_node *rtems_rbtree_insert(
384  rtems_rbtree_control *the_rbtree,
385  rtems_rbtree_node    *the_node,
386  rtems_rbtree_compare  compare,
387  bool                  is_unique
388)
389{
390  return _RBTree_Insert( the_rbtree, the_node, compare, is_unique );
391}
392
393/** @} */
394
395#ifdef __cplusplus
396}
397#endif
398
399#endif
400/* end of include file */
Note: See TracBrowser for help on using the repository browser.