RTEMS CPU Kit with SuperCore  4.11.2
rbtreeimpl.h
Go to the documentation of this file.
1 
14 /*
15  * Copyright (c) 2010-2012 Gedare Bloom.
16  *
17  * The license and distribution terms for this file may be
18  * found in the file LICENSE in this distribution or at
19  * http://www.rtems.org/license/LICENSE.
20  */
21 
22 #ifndef _RTEMS_SCORE_RBTREEIMPL_H
23 #define _RTEMS_SCORE_RBTREEIMPL_H
24 
25 #include <rtems/score/rbtree.h>
26 
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
30 
48 typedef bool (*RBTree_Visitor)(
49  const RBTree_Node *node,
50  RBTree_Direction dir,
51  void *visitor_arg
52 );
53 
62 void _RBTree_Iterate(
63  const RBTree_Control *rbtree,
64  RBTree_Direction dir,
65  RBTree_Visitor visitor,
66  void *visitor_arg
67 );
68 
73  RBTree_Direction the_dir
74 )
75 {
76  return (RBTree_Direction) !((int) the_dir);
77 }
78 
87  const RBTree_Node *the_node,
88  const RBTree_Node *parent
89 )
90 {
91  return (RBTree_Direction) ( the_node != parent->child[ 0 ] );
92 }
93 
103  const RBTree_Node *the_node
104  )
105 {
106  return (the_node && the_node->color == RBT_RED);
107 }
108 
120  const RBTree_Node *the_node,
121  const RBTree_Node *parent
122 )
123 {
124  RBTree_Node *left_child = parent->child[ RBT_LEFT ];
125 
126  return the_node == left_child ? parent->child[ RBT_RIGHT ] : left_child;
127 }
128 
129 RTEMS_INLINE_ROUTINE bool _RBTree_Is_equal(
130  RBTree_Compare_result compare_result
131 )
132 {
133  return compare_result == 0;
134 }
135 
136 RTEMS_INLINE_ROUTINE bool _RBTree_Is_greater(
137  RBTree_Compare_result compare_result
138 )
139 {
140  return compare_result > 0;
141 }
142 
143 RTEMS_INLINE_ROUTINE bool _RBTree_Is_lesser(
144  RBTree_Compare_result compare_result
145 )
146 {
147  return compare_result < 0;
148 }
149 
181  RBTree_Node *the_node,
182  RBTree_Direction dir
183 )
184 {
186  RBTree_Node *child = the_node->child[ opp_dir ];
187  RBTree_Node *grandchild;
188  RBTree_Node *parent;
189 
190  if ( child == NULL)
191  return;
192 
193  grandchild = child->child[ dir ];
194  the_node->child[ opp_dir ] = grandchild;
195 
196  if ( grandchild != NULL )
197  grandchild->parent = the_node;
198 
199  child->child[ dir ] = the_node;
200 
201  parent = _RBTree_Parent( the_node );
202  parent->child[ _RBTree_Direction( the_node, parent ) ] = child;
203 
204  child->parent = parent;
205  the_node->parent = child;
206 }
207 
210 #ifdef __cplusplus
211 }
212 #endif
213 
214 #endif
215 /* end of include file */
RTEMS_INLINE_ROUTINE bool _RBTree_Is_red(const RBTree_Node *the_node)
Is this node red.
Definition: rbtreeimpl.h:102
RBTree_Node * parent
This points to the node&#39;s parent.
Definition: rbtree.h:77
#define RTEMS_INLINE_ROUTINE
The following (in conjunction with compiler arguments) are used to choose between the use of static i...
Definition: basedefs.h:135
RTEMS_INLINE_ROUTINE void _RBTree_Rotate(RBTree_Node *the_node, RBTree_Direction dir)
Rotates the node in the specified direction.
Definition: rbtreeimpl.h:180
RTEMS_INLINE_ROUTINE RBTree_Direction _RBTree_Opposite_direction(RBTree_Direction the_dir)
Get the direction opposite to the_dir.
Definition: rbtreeimpl.h:72
long RBTree_Compare_result
Integer type for compare results.
Definition: rbtree.h:99
RBTree_Color color
The color of the node.
Definition: rbtree.h:81
Constants and Structures Associated with the Red-Black Tree Handler.
RTEMS_INLINE_ROUTINE RBTree_Node * _RBTree_Sibling(const RBTree_Node *the_node, const RBTree_Node *parent)
Returns the sibling of the node.
Definition: rbtreeimpl.h:119
RTEMS_INLINE_ROUTINE RBTree_Node * _RBTree_Parent(const RBTree_Node *the_node)
Returns a pointer to the parent of this node.
Definition: rbtree.h:347
RTEMS_INLINE_ROUTINE RBTree_Direction _RBTree_Direction(const RBTree_Node *the_node, const RBTree_Node *parent)
Returns the direction of the node.
Definition: rbtreeimpl.h:86
RBTree_Direction
This type indicates the direction.
Definition: rbtree.h:87
bool(* RBTree_Visitor)(const RBTree_Node *node, RBTree_Direction dir, void *visitor_arg)
Red-black tree visitor.
Definition: rbtreeimpl.h:48
void _RBTree_Iterate(const RBTree_Control *rbtree, RBTree_Direction dir, RBTree_Visitor visitor, void *visitor_arg)
Red-black tree iteration.
Definition: rbtreeiterate.c:29
This is used to manage a RBT.
Definition: rbtree.h:138
RBTree_Node * child[2]
child[0] points to the left child, child[1] points to the right child
Definition: rbtree.h:79
This is used to manage each element (node) which is placed on a RBT.
Definition: rbtree.h:75