Changeset 4752550f in rtems for cpukit/score/include


Ignore:
Timestamp:
07/23/14 11:19:09 (9 years ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
4.11, 5, master
Children:
993f5ac
Parents:
d472d21
git-author:
Sebastian Huber <sebastian.huber@…> (07/23/14 11:19:09)
git-committer:
Sebastian Huber <sebastian.huber@…> (08/07/14 13:59:25)
Message:

rbtree: Simplify _RBTree_Rotate()

Add and use _RBTree_Direction().

File:
1 edited

Legend:

Unmodified
Added
Removed
  • cpukit/score/include/rtems/score/rbtreeimpl.h

    rd472d21 r4752550f  
    7878
    7979/**
     80 * @brief Returns the direction of the node.
     81 *
     82 * @param[in] the_node The node of interest.
     83 * @param[in] parent The parent of the node.  The parent must exist, thus it is
     84 * invalid to use this function for the root node.
     85 */
     86RTEMS_INLINE_ROUTINE RBTree_Direction _RBTree_Direction(
     87  const RBTree_Node *the_node,
     88  const RBTree_Node *parent
     89)
     90{
     91  return (RBTree_Direction) ( the_node != parent->child[ 0 ] );
     92}
     93
     94/**
    8095 * @brief Is this node red.
    8196 *
     
    167182
    168183/**
    169  * @brief Rotate the_node in the direction passed as second argument.
    170  *
    171  * This routine rotates @a the_node to the direction @a dir, swapping
    172  * @a the_node with its child\[@a dir\].
     184 * @brief Rotates the node in the specified direction.
     185 *
     186 * The node is swapped with its child in the opposite direction if it exists.
     187 *
     188 * Sub-tree before rotation:
     189 * @dot
     190 * digraph state {
     191 *   parent -> the_node;
     192 *   the_node -> sibling [label="dir"];
     193 *   the_node -> child [label="opp_dir"];
     194 *   child -> grandchild [label="dir"];
     195 *   child -> grandchildsibling [label="opp_dir"];
     196 * }
     197 * @enddot
     198 *
     199 * Sub-tree after rotation:
     200 * @dot
     201 * digraph state {
     202 *   parent -> child;
     203 *   the_node -> sibling [label="dir"];
     204 *   the_node -> grandchild [label="opp_dir"];
     205 *   child -> the_node [label="dir"];
     206 *   child -> grandchildsibling [label="opp_dir"];
     207 * }
     208 * @enddot
     209 *
     210 * @param[in] the_node The node to rotate.
     211 * @param[in] dir The rotation direction.
    173212 */
    174213RTEMS_INLINE_ROUTINE void _RBTree_Rotate(
    175     RBTree_Node *the_node,
    176     RBTree_Direction dir
    177     )
    178 {
    179   RBTree_Node *c;
    180   if (the_node == NULL) return;
    181   if (the_node->child[_RBTree_Opposite_direction(dir)] == NULL) return;
    182 
    183   c = the_node->child[_RBTree_Opposite_direction(dir)];
    184   the_node->child[_RBTree_Opposite_direction(dir)] = c->child[dir];
    185 
    186   if (c->child[dir])
    187     c->child[dir]->parent = the_node;
    188 
    189   c->child[dir] = the_node;
    190 
    191   the_node->parent->child[the_node != the_node->parent->child[0]] = c;
    192 
    193   c->parent = the_node->parent;
    194   the_node->parent = c;
     214  RBTree_Node      *the_node,
     215  RBTree_Direction  dir
     216)
     217{
     218  RBTree_Direction  opp_dir = _RBTree_Opposite_direction( dir );
     219  RBTree_Node      *child = the_node->child[ opp_dir ];
     220  RBTree_Node      *grandchild;
     221  RBTree_Node      *parent;
     222
     223  if ( child == NULL)
     224    return;
     225
     226  grandchild = child->child[ dir ];
     227  the_node->child[ opp_dir ] = grandchild;
     228
     229  if ( grandchild != NULL )
     230    grandchild->parent = the_node;
     231
     232  child->child[ dir ] = the_node;
     233
     234  parent = _RBTree_Parent( the_node );
     235  parent->child[ _RBTree_Direction( the_node, parent ) ] = child;
     236
     237  child->parent = parent;
     238  the_node->parent = child;
    195239}
    196240
Note: See TracChangeset for help on using the changeset viewer.