diff options
author | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2014-07-23 13:03:54 +0200 |
---|---|---|
committer | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2014-08-07 15:59:29 +0200 |
commit | 993f5acd25cc3d140689c7a0f2c1912da7b2f0f3 (patch) | |
tree | b29e5c13f45c05e31e1260f13f800caed13cf2a3 /cpukit/score/include/rtems/score/rbtreeimpl.h | |
parent | rbtree: Simplify _RBTree_Rotate() (diff) | |
download | rtems-993f5acd25cc3d140689c7a0f2c1912da7b2f0f3.tar.bz2 |
rbtree: Simplify insert and extract
Simplify _RBTree_Insert() and _RBTree_Extract(). Remove more
superfluous NULL pointer checks. Change _RBTree_Is_root() to use only
the node. Add parent parameter to _RBTree_Sibling(). Delete
_RBTree_Grandparent() and _RBTree_Parent_sibling().
Diffstat (limited to '')
-rw-r--r-- | cpukit/score/include/rtems/score/rbtreeimpl.h | 53 |
1 files changed, 10 insertions, 43 deletions
diff --git a/cpukit/score/include/rtems/score/rbtreeimpl.h b/cpukit/score/include/rtems/score/rbtreeimpl.h index 5f5e78367a..ed4cbd558a 100644 --- a/cpukit/score/include/rtems/score/rbtreeimpl.h +++ b/cpukit/score/include/rtems/score/rbtreeimpl.h @@ -107,56 +107,23 @@ RTEMS_INLINE_ROUTINE bool _RBTree_Is_red( } /** - * @brief Return a pointer to node's grandparent. + * @brief Returns the sibling of the node. * - * This function returns a pointer to the grandparent of @a the_node if it - * exists, and NULL if not. - */ -RTEMS_INLINE_ROUTINE RBTree_Node *_RBTree_Grandparent( - const RBTree_Node *the_node -) -{ - if(!the_node) return NULL; - if(!(the_node->parent)) return NULL; - if(!(the_node->parent->parent)) return NULL; - if(!(the_node->parent->parent->parent)) return NULL; - return(the_node->parent->parent); -} - -/** - * @brief Return a pointer to node's sibling. + * @param[in] the_node The node of interest. + * @param[in] parent The parent of the node. The parent must exist, thus it is + * invalid to use this function for the root node. * - * This function returns a pointer to the sibling of @a the_node if it - * exists, and NULL if not. + * @retval NULL No sibling exists. + * @retval sibling The sibling of the node. */ RTEMS_INLINE_ROUTINE RBTree_Node *_RBTree_Sibling( - const RBTree_Node *the_node -) -{ - if(!the_node) return NULL; - if(!(the_node->parent)) return NULL; - if(!(the_node->parent->parent)) return NULL; - - if(the_node == the_node->parent->child[RBT_LEFT]) - return the_node->parent->child[RBT_RIGHT]; - else - return the_node->parent->child[RBT_LEFT]; -} - -/** - * @brief Return a pointer to node's parent's sibling. - * - * This function returns a pointer to the sibling of the parent of - * @a the_node if it exists, and NULL if not. - */ -RTEMS_INLINE_ROUTINE RBTree_Node *_RBTree_Parent_sibling( - const RBTree_Node *the_node + const RBTree_Node *the_node, + const RBTree_Node *parent ) { - if(!the_node) return NULL; - if(_RBTree_Grandparent(the_node) == NULL) return NULL; + RBTree_Node *left_child = parent->child[ RBT_LEFT ]; - return _RBTree_Sibling(the_node->parent); + return the_node == left_child ? parent->child[ RBT_RIGHT ] : left_child; } RTEMS_INLINE_ROUTINE bool _RBTree_Is_equal( |