Changeset 41d33b9 in rtems


Ignore:
Timestamp:
Mar 4, 2012, 4:42:08 PM (7 years ago)
Author:
Gedare Bloom <gedare@…>
Branches:
4.11, master
Children:
314d327
Parents:
a52be5ec
Message:

score: Add _RBTree_Opposite_direction.

Add a red-black tree helper method to ease obtaining the direction opposite
to the current direction. Useful for manipulating and traversing an rbtree.

Location:
cpukit/score
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • cpukit/score/inline/rtems/score/rbtree.inl

    ra52be5ec r41d33b9  
    3131 *  @{
    3232 */
     33
     34/**
     35 * @brief Get the direction opposite to @a the_dir
     36 */
     37RTEMS_INLINE_ROUTINE RBTree_Direction _RBTree_Opposite_direction(
     38  RBTree_Direction the_dir
     39)
     40{
     41  return (!the_dir);
     42}
    3343
    3444/** @brief Set off rbtree
     
    436446  RBTree_Node *c;
    437447  if (the_node == NULL) return;
    438   if (the_node->child[(1-dir)] == NULL) return;
    439 
    440   c = the_node->child[(1-dir)];
    441   the_node->child[(1-dir)] = c->child[dir];
     448  if (the_node->child[_RBTree_Opposite_direction(dir)] == NULL) return;
     449
     450  c = the_node->child[_RBTree_Opposite_direction(dir)];
     451  the_node->child[_RBTree_Opposite_direction(dir)] = c->child[dir];
    442452
    443453  if (c->child[dir])
  • cpukit/score/src/rbtreeextract.c

    ra52be5ec r41d33b9  
    5151      dir = the_node != parent->child[0];
    5252      _RBTree_Rotate(parent, dir);
    53       sibling = parent->child[!dir];
     53      sibling = parent->child[_RBTree_Opposite_direction(dir)];
    5454    }
    5555
     
    7373       */
    7474      dir = the_node != parent->child[0];
    75       if (!_RBTree_Is_red(sibling->child[!dir])) {
     75      if (!_RBTree_Is_red(sibling->child[_RBTree_Opposite_direction(dir)])) {
    7676        sibling->color = RBT_RED;
    7777        sibling->child[dir]->color = RBT_BLACK;
    78         _RBTree_Rotate(sibling, !dir);
    79         sibling = parent->child[!dir];
     78        _RBTree_Rotate(sibling, _RBTree_Opposite_direction(dir));
     79        sibling = parent->child[_RBTree_Opposite_direction(dir)];
    8080      }
    8181      sibling->color = parent->color;
    8282      parent->color = RBT_BLACK;
    83       sibling->child[!dir]->color = RBT_BLACK;
     83      sibling->child[_RBTree_Opposite_direction(dir)]->color = RBT_BLACK;
    8484      _RBTree_Rotate(parent, dir);
    8585      break; /* done */
Note: See TracChangeset for help on using the changeset viewer.