From ddbe30f3a3e25ce260c1560af51664e0dc9a6289 Mon Sep 17 00:00:00 2001
From: Gedare Bloom <gedare@rtems.org>
Date: Wed, 2 May 2012 15:04:58 -0400
Subject: [PATCH] PR2060: RBTree: updating min and max on extract path
During node extraction from a red-black tree the min and max values are updated
incorrectly. We need to use the successor/predecessor functions to find the
next/previous node when we remove the min/max from the tree.
---
cpukit/score/src/rbtreeextract.c | 26 +++++++++-----------------
1 files changed, 9 insertions(+), 17 deletions(-)
diff --git a/cpukit/score/src/rbtreeextract.c b/cpukit/score/src/rbtreeextract.c
index 4071361..9a0a18b 100644
a
|
b
|
void _RBTree_Extract_unprotected( |
108 | 108 | |
109 | 109 | /* check if min needs to be updated */ |
110 | 110 | if (the_node == the_rbtree->first[RBT_LEFT]) { |
111 | | if (the_node->child[RBT_RIGHT]) |
112 | | the_rbtree->first[RBT_LEFT] = the_node->child[RBT_RIGHT]; |
113 | | else { |
114 | | the_rbtree->first[RBT_LEFT] = the_node->parent; |
115 | | if(_RBTree_Are_nodes_equal((RBTree_Node *)the_rbtree, |
116 | | the_rbtree->first[RBT_LEFT])) |
117 | | the_rbtree->first[RBT_LEFT] = NULL; |
118 | | } |
| 111 | RBTree_Node *next; |
| 112 | next = _RBTree_Successor_unprotected(the_rbtree, the_node); |
| 113 | the_rbtree->first[RBT_LEFT] = next; |
119 | 114 | } |
120 | | /* check if max needs to be updated: note, min can equal max (1 element) */ |
| 115 | |
| 116 | /* Check if max needs to be updated. min=max for 1 element trees so |
| 117 | * do not use else if here. */ |
121 | 118 | if (the_node == the_rbtree->first[RBT_RIGHT]) { |
122 | | if (the_node->child[RBT_LEFT]) |
123 | | the_rbtree->first[RBT_RIGHT] = the_node->child[RBT_LEFT]; |
124 | | else { |
125 | | the_rbtree->first[RBT_RIGHT] = the_node->parent; |
126 | | if(_RBTree_Are_nodes_equal((RBTree_Node *)the_rbtree, |
127 | | the_rbtree->first[RBT_RIGHT])) |
128 | | the_rbtree->first[RBT_RIGHT] = NULL; |
129 | | } |
| 119 | RBTree_Node *previous; |
| 120 | previous = _RBTree_Predecessor_unprotected(the_rbtree, the_node); |
| 121 | the_rbtree->first[RBT_RIGHT] = previous; |
130 | 122 | } |
131 | 123 | |
132 | 124 | /* if the_node has at most one non-null child then it is safe to proceed |