forked from Imagelibrary/rtems
PR2061: RBTree: updating min and max on insert with duplicates
When inserting to a red-black tree with duplicates the min and max pointers are not updated properly. We need to check the key of the min/max node against the insert node since the insert point could be the child of a node with an identical key to the min/max node.
This commit is contained in:
@@ -106,7 +106,12 @@ RBTree_Node *_RBTree_Insert_unprotected(
|
||||
iter_node->child[dir] = the_node;
|
||||
the_node->parent = iter_node;
|
||||
/* update min/max */
|
||||
if (_RBTree_Is_first(the_rbtree, iter_node, dir)) {
|
||||
compare_result = the_rbtree->compare_function(
|
||||
the_node,
|
||||
_RBTree_First(the_rbtree, dir)
|
||||
);
|
||||
if ( (!dir && _RBTree_Is_lesser(compare_result)) ||
|
||||
(dir && _RBTree_Is_greater(compare_result)) ) {
|
||||
the_rbtree->first[dir] = the_node;
|
||||
}
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user