[rtems commit] rbtree: Simplify _RBTree_Extract()
Sebastian Huber
sebh at rtems.org
Thu Aug 7 13:51:57 UTC 2014
Module: rtems
Branch: master
Commit: 0ef6e3bfb9f763b4de46a8693d1e7cd59beb754e
Changeset: http://git.rtems.org/rtems/commit/?id=0ef6e3bfb9f763b4de46a8693d1e7cd59beb754e
Author: Sebastian Huber <sebastian.huber at embedded-brains.de>
Date: Thu Jul 24 17:50:58 2014 +0200
rbtree: Simplify _RBTree_Extract()
---
cpukit/score/src/rbtreeextract.c | 18 ++++++++++--------
1 files changed, 10 insertions(+), 8 deletions(-)
diff --git a/cpukit/score/src/rbtreeextract.c b/cpukit/score/src/rbtreeextract.c
index f3a7328..1aaba27 100644
--- a/cpukit/score/src/rbtreeextract.c
+++ b/cpukit/score/src/rbtreeextract.c
@@ -23,7 +23,6 @@
static void _RBTree_Extract_validate( RBTree_Node *the_node )
{
RBTree_Node *parent;
- RBTree_Direction dir;
parent = the_node->parent;
@@ -40,11 +39,13 @@ static void _RBTree_Extract_validate( RBTree_Node *the_node )
* update sibling pointer.
*/
if ( _RBTree_Is_red( sibling ) ) {
+ RBTree_Direction dir = _RBTree_Direction( the_node, parent );
+ RBTree_Direction opp_dir = _RBTree_Opposite_direction( dir );
+
parent->color = RBT_RED;
sibling->color = RBT_BLACK;
- dir = the_node != parent->child[ 0 ];
_RBTree_Rotate( parent, dir );
- sibling = parent->child[ _RBTree_Opposite_direction( dir ) ];
+ sibling = parent->child[ opp_dir ];
}
/* sibling is black, see if both of its children are also black. */
@@ -66,20 +67,21 @@ static void _RBTree_Extract_validate( RBTree_Node *the_node )
* and if so rotate in the proper direction and update sibling pointer.
* Then switch the sibling and parent colors, and rotate through parent.
*/
- dir = the_node != parent->child[ 0 ];
+ RBTree_Direction dir = _RBTree_Direction( the_node, parent );
+ RBTree_Direction opp_dir = _RBTree_Opposite_direction( dir );
if (
- !_RBTree_Is_red( sibling->child[ _RBTree_Opposite_direction( dir ) ] )
+ !_RBTree_Is_red( sibling->child[ opp_dir ] )
) {
sibling->color = RBT_RED;
sibling->child[ dir ]->color = RBT_BLACK;
- _RBTree_Rotate( sibling, _RBTree_Opposite_direction( dir ) );
- sibling = parent->child[ _RBTree_Opposite_direction( dir ) ];
+ _RBTree_Rotate( sibling, opp_dir );
+ sibling = parent->child[ opp_dir ];
}
sibling->color = parent->color;
parent->color = RBT_BLACK;
- sibling->child[ _RBTree_Opposite_direction( dir ) ]->color = RBT_BLACK;
+ sibling->child[ opp_dir ]->color = RBT_BLACK;
_RBTree_Rotate( parent, dir );
break; /* done */
}
More information about the vc
mailing list