source: rtems/cpukit/sapi/inline/rtems/rbtree.inl @ bd9baa81

4.115
Last change on this file since bd9baa81 was bd9baa81, checked in by Joel Sherrill <joel.sherrill@…>, on 04/04/11 at 18:44:16

2010-07-28 Gedare Bloom <giddyup44@…>

PR 1641/cpukit

  • sapi/Makefile.am, sapi/preinstall.am, score/Makefile.am, score/preinstall.am: Add Red Black Tree data structure to score.
  • sapi/include/rtems/rbtree.h, sapi/inline/rtems/rbtree.inl, score/include/rtems/score/rbtree.h, score/inline/rtems/score/rbtree.inl, score/src/rbtree.c, score/src/rbtreeextract.c, score/src/rbtreefind.c, score/src/rbtreefindheader.c, score/src/rbtreeget.c, score/src/rbtreeinsert.c, score/src/rbtreepeek.c: New files.
  • Property mode set to 100644
File size: 9.6 KB
Line 
1/**
2 * @file rtems/rbtree.inl
3 *
4 *  This include file contains all the constants and structures associated
5 *  with the RBTree API in RTEMS. The rbtree is a Red Black Tree that
6 *  is part of the Super Core. This is the published interface to that
7 *  code.
8 *
9 */
10 
11/*
12 *  Copyright (c) 2010 Gedare Bloom.
13 *
14 *  The license and distribution terms for this file may be
15 *  found in the file LICENSE in this distribution or at
16 *  http://www.rtems.com/license/LICENSE.
17 *
18 *  $Id$
19 */
20
21#ifndef _RTEMS_RBTREE_H
22# error "Never use <rtems/rbtree.inl> directly; include <rtems/rbtree.h> instead."
23#endif
24
25#ifndef _RTEMS_RBTREE_INL
26#define _RTEMS_RBTREE_INL
27
28#include <rtems/score/rbtree.inl>
29
30/**
31 *  @brief Initialize a RBTree Header
32 *
33 *  This routine initializes @a the_rbtree structure to manage the
34 *  contiguous array of @a number_nodes nodes which starts at
35 *  @a starting_address.  Each node is of @a node_size bytes.
36 */
37RTEMS_INLINE_ROUTINE void rtems_rbtree_initialize(
38  rtems_rbtree_control *the_rbtree,
39  void                *starting_address,
40  size_t               number_nodes,
41  size_t               node_size
42)
43{
44  _RBTree_Initialize( the_rbtree, starting_address, number_nodes, node_size);
45}
46
47/**
48 *  @brief Initialize this RBTree as Empty
49 *
50 *  This routine initializes @a the_rbtree to contain zero nodes.
51 */
52RTEMS_INLINE_ROUTINE void rtems_rbtree_initialize_empty(
53  rtems_rbtree_control *the_rbtree
54)
55{
56  _RBTree_Initialize_empty( the_rbtree );
57}
58
59/**
60 *  @brief Set off rbtree
61 *
62 *  This function sets the next and previous fields of the @a node to NULL
63 *  indicating the @a node is not part of any rbtree.
64 */
65RTEMS_INLINE_ROUTINE void rtems_rbtree_set_off_rbtree(
66  rtems_rbtree_node *node
67)
68{
69  _RBTree_Set_off_rbtree( node );
70}
71
72/**
73 *  @brief Is the Node off RBTree
74 *
75 *  This function returns true if the @a node is not on a rbtree. A @a node is
76 *  off rbtree if the next and previous fields are set to NULL.
77 */
78RTEMS_INLINE_ROUTINE bool rtems_rbtree_is_node_off_rbtree(
79  const rtems_rbtree_node *node
80)
81{
82  return _RBTree_Is_node_off_rbtree( node );
83}
84
85/**
86 *  @brief Is the RBTree Node Pointer NULL
87 *
88 *  This function returns true if @a the_node is NULL and false otherwise.
89 */
90RTEMS_INLINE_ROUTINE bool rtems_rbtree_is_null_node(
91  const rtems_rbtree_node *the_node
92)
93{
94  return _RBTree_Is_null_node( the_node );
95}
96
97/**
98 *  @brief Return pointer to RBTree Root
99 *
100 *  This function returns a pointer to the root node of @a the_rbtree.
101 */
102RTEMS_INLINE_ROUTINE rtems_rbtree_node *rtems_rbtree_root(
103  rtems_rbtree_control *the_rbtree
104)
105{
106  return _RBTree_Root( the_rbtree );
107}
108
109/**
110 *  @brief Return pointer to RBTree Minimum
111 *
112 *  This function returns a pointer to the minimum node of @a the_rbtree.
113 */
114RTEMS_INLINE_ROUTINE rtems_rbtree_node *rtems_rbtree_min(
115  rtems_rbtree_control *the_rbtree
116)
117{
118  return _RBTree_First( the_rbtree, RBT_LEFT );
119}
120
121/**
122 *  @brief Return pointer to RBTree Maximum
123 *
124 *  This function returns a pointer to the maximum node of @a the_rbtree.
125 */
126RTEMS_INLINE_ROUTINE rtems_rbtree_node *rtems_rbtree_max(
127  rtems_rbtree_control *the_rbtree
128)
129{
130  return _RBTree_First( the_rbtree, RBT_RIGHT );
131}
132
133/**
134 *  @brief Return pointer to the left child node from this node
135 *
136 *  This function returns a pointer to the left child node of @a the_node.
137 */
138RTEMS_INLINE_ROUTINE rtems_rbtree_node *rtems_rbtree_left(
139  rtems_rbtree_node *the_node
140)
141{
142  return _RBTree_Left( the_node );
143}
144
145/**
146 *  @brief Return pointer to the right child node from this node
147 *
148 *  This function returns a pointer to the right child node of @a the_node.
149 */
150RTEMS_INLINE_ROUTINE rtems_rbtree_node *rtems_rbtree_right(
151  rtems_rbtree_node *the_node
152)
153{
154  return _RBTree_Right( the_node );
155}
156
157/**
158 *  @brief Return pointer to the parent child node from this node
159 *
160 *  This function returns a pointer to the parent node of @a the_node.
161 */
162RTEMS_INLINE_ROUTINE rtems_rbtree_node *rtems_rbtree_parent(
163  rtems_rbtree_node *the_node
164)
165{
166  return _RBTree_Parent( the_node );
167}
168
169/**
170 *  @brief Are Two Nodes Equal
171 *
172 *  This function returns true if @a left and @a right are equal,
173 *  and false otherwise.
174 */
175RTEMS_INLINE_ROUTINE bool rtems_rbtree_are_nodes_equal(
176  const rtems_rbtree_node *left,
177  const rtems_rbtree_node *right
178)
179{
180  return _RBTree_Are_nodes_equal( left, right );
181}
182
183/**
184 *  @brief Is the RBTree Empty
185 *
186 *  This function returns true if there a no nodes on @a the_rbtree and
187 *  false otherwise.
188 */
189RTEMS_INLINE_ROUTINE bool rtems_rbtree_is_empty(
190  rtems_rbtree_control *the_rbtree
191)
192{
193  return _RBTree_Is_empty( the_rbtree );
194}
195
196/**
197 *  @brief Is this the Minimum Node on the RBTree
198 *
199 *  This function returns true if @a the_node is the min node on @a the_rbtree
200 *  and false otherwise.
201 */
202RTEMS_INLINE_ROUTINE bool rtems_rbtree_is_min(
203  rtems_rbtree_control *the_rbtree,
204  const rtems_rbtree_node *the_node
205)
206{
207  return _RBTree_Is_first( the_rbtree, the_node, RBT_LEFT );
208}
209
210/**
211 *  @brief Is this the Maximum Node on the RBTree
212 *
213 *  This function returns true if @a the_node is the max node on @a the_rbtree
214 *  and false otherwise.
215 */
216RTEMS_INLINE_ROUTINE bool rtems_rbtree_is_max(
217  rtems_rbtree_control *the_rbtree,
218  const rtems_rbtree_node *the_node
219)
220{
221  return _RBTree_Is_first( the_rbtree, the_node, RBT_RIGHT );
222}
223
224
225/**
226 *  @brief Does this RBTree have only One Node
227 *
228 *  This function returns true if there is only one node on @a the_rbtree and
229 *  false otherwise.
230 */
231RTEMS_INLINE_ROUTINE bool rtems_rbtree_has_only_one_node(
232  const rtems_rbtree_control *the_rbtree
233)
234{
235  return _RBTree_Has_only_one_node( the_rbtree );
236}
237
238/**
239 *  @brief Is this Node the RBTree Root
240 *
241 *  This function returns true if @a the_node is the root of @a the_rbtree and
242 *  false otherwise.
243 */
244RTEMS_INLINE_ROUTINE bool rtems_rbtree_is_root(
245  rtems_rbtree_control    *the_rbtree,
246  const rtems_rbtree_node *the_node
247)
248{
249  return _RBTree_Is_root( the_rbtree, the_node );
250}
251
252/** @brief Find the node with given value in the tree
253 *
254 *  This function returns a pointer to the node having value equal to @a value
255 *  if it exists within @a the_rbtree, and NULL if not.
256 */
257RTEMS_INLINE_ROUTINE rtems_rbtree_node* rtems_rbtree_find(
258  rtems_rbtree_control *the_rbtree,
259  unsigned int value
260)
261{
262  return _RBTree_Find( the_rbtree, value );
263}
264
265/** @brief Find the node's in-order predecessor
266 *
267 * This function returns a pointer to the in-order predecessor
268 * of @a the_node if it exists, and NULL if not.
269 */
270RTEMS_INLINE_ROUTINE rtems_rbtree_node* rtems_rbtree_predecessor(
271  rtems_rbtree_node *the_node
272)
273{
274  return _RBTree_Predecessor( the_node );
275}
276
277/** @brief Find the node's in-order successor
278 *
279 *  This function returns a pointer to the in-order successor 
280 *  of @a the_node if it exists, and NULL if not.
281 */
282RTEMS_INLINE_ROUTINE rtems_rbtree_node* rtems_rbtree_successor(
283  rtems_rbtree_node *the_node
284)
285{
286  return _RBTree_Successor( the_node );
287}
288
289/**
290 *  @brief Extract the specified node from a rbtree
291 *
292 *  This routine extracts @a the_node from @a the_rbtree on which it resides.
293 *  It disables interrupts to ensure the atomicity of the extract operation.
294 */
295RTEMS_INLINE_ROUTINE void rtems_rbtree_extract(
296  rtems_rbtree_control *the_rbtree,
297  rtems_rbtree_node *the_node
298)
299{
300  _RBTree_Extract( the_rbtree, the_node );
301}
302
303/**
304 *  @brief Obtain the min node on a rbtree
305 *
306 *  This function removes the min node from @a the_rbtree and returns
307 *  a pointer to that node.  If @a the_rbtree is empty, then NULL is returned.
308 *  It disables interrupts to ensure the atomicity of the get operation.
309 */
310RTEMS_INLINE_ROUTINE rtems_rbtree_node *rtems_rbtree_get_min(
311  rtems_rbtree_control *the_rbtree
312)
313{
314  return _RBTree_Get( the_rbtree, RBT_LEFT );
315}
316
317/**
318 *  @brief Obtain the max node on a rbtree
319 *
320 *  This function removes the max node from @a the_rbtree and returns
321 *  a pointer to that node.  If @a the_rbtree is empty, then NULL is returned.
322 *  It disables interrupts to ensure the atomicity of the get operation.
323 */
324RTEMS_INLINE_ROUTINE rtems_rbtree_node *rtems_rbtree_get_max(
325  rtems_rbtree_control *the_rbtree
326)
327{
328  return _RBTree_Get( the_rbtree, RBT_RIGHT );
329}
330
331/**
332 *  @brief Peek at the min node on a rbtree
333 *
334 *  This function returns a pointer to the min node from @a the_rbtree
335 *  without changing the tree.  If @a the_rbtree is empty,
336 *  then NULL is returned.
337 *  It disables interrupts to ensure the atomicity of the peek operation.
338 */
339RTEMS_INLINE_ROUTINE rtems_rbtree_node *rtems_rbtree_peek_min(
340  rtems_rbtree_control *the_rbtree
341)
342{
343  return _RBTree_Peek( the_rbtree, RBT_LEFT );
344}
345
346/**
347 *  @brief Peek at the max node on a rbtree
348 *
349 *  This function returns a pointer to the max node from @a the_rbtree
350 *  without changing the tree.  If @a the_rbtree is empty,
351 *  then NULL is returned.
352 *  It disables interrupts to ensure the atomicity of the peek operation.
353 */
354RTEMS_INLINE_ROUTINE rtems_rbtree_node *rtems_rbtree_peek_max(
355  rtems_rbtree_control *the_rbtree
356)
357{
358  return _RBTree_Peek( the_rbtree, RBT_RIGHT );
359}
360
361
362/**
363 *  @brief Find the control header of the tree containing a given node.
364 *
365 *  This routine finds the rtems_rbtree_control structure of the tree
366 *  containing @a the_node.
367 *  It disables interrupts to ensure the atomicity of the find operation.
368 */
369RTEMS_INLINE_ROUTINE rtems_rbtree_control *rtems_rbtree_find_header(
370  rtems_rbtree_node *the_node
371)
372{
373  return(_RBTree_Find_header( the_node ));
374}
375
376/**
377 *  @brief Insert a node on a rbtree
378 *
379 *  This routine inserts @a the_node on @a the_rbtree.
380 *  It disables interrupts to ensure the atomicity of the insert operation.
381 */
382RTEMS_INLINE_ROUTINE void rtems_rbtree_insert(
383  rtems_rbtree_control *the_rbtree,
384  rtems_rbtree_node *the_node
385)
386{
387  _RBTree_Insert( the_rbtree, the_node );
388}
389
390#endif
391/* end of include file */
Note: See TracBrowser for help on using the repository browser.