[Bug 1995] RBTree Successor and Predecessor

bugzilla-daemon at rtems.org bugzilla-daemon at rtems.org
Fri Mar 30 15:03:48 UTC 2012


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

--- Comment #8 from Gedare <gedare at rtems.org> 2012-03-30 10:03:48 CDT ---
(In reply to comment #7)
> (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;
> }

That was my misunderstanding of what was desired for the API. I see now that we
could just use one function. I will rework this soon.

-- 
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