[Bug 1995] RBTree Successor and Predecessor

bugzilla-daemon at rtems.org bugzilla-daemon at rtems.org
Fri Mar 30 09:38:05 UTC 2012


https://www.rtems.org/bugzilla/show_bug.cgi?id=1995

--- Comment #7 from Sebastian Huber <sebastian.huber at embedded-brains.de> 2012-03-30 04:38:05 CDT ---
(In reply to comment #6)
> Please review.

Why do we need two nearly identical functions?  I think this is sufficient:

RTEMS_INLINE_ROUTINE RBTree_Node *_RBTree_Next(
  const RBTree_Control *rbtree,
  const RBTree_Node *node,
  RBTree_Direction dir
)
{
  RBTree_Direction opp_dir = _RBTree_Opposite_direction( dir );
  RBTree_Node *current = node->child [dir];
  RBTree_Node *next = NULL;

  if (current != NULL) {
    next = current;
    while ((current = current->child [opp_dir]) != NULL) {
      next = current;
    }
  } else {
    const RBTree_Node *null = (const RBTree_Node *) rbtree;
    RBTree_Node *parent = node->parent;

    if (parent != null && node == parent->child [opp_dir]) {
      next = parent;
    } else {
      while (parent != null && node == parent->child [dir]) {
        node = parent;
        parent = node->parent;
      }

      if (parent != null) {
        next = parent;
      }
    }
  }

  return next;
}

-- 
Configure bugmail: https://www.rtems.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are watching all bug changes.



More information about the bugs mailing list