233. <Right-side rebalancing after RB deletion 233> =
struct rb_node *w = pa[k - 1]->rb_link[0];
if (w->rb_color == RB_RED)
{
<Ensure w is black in right-side RB deletion rebalancing 234>
}
if ((w->rb_link[0] == NULL
|| w->rb_link[0]->rb_color == RB_BLACK)
&& (w->rb_link[1] == NULL
|| w->rb_link[1]->rb_color == RB_BLACK))
{ <Case 1 in right-side RB deletion rebalancing 235> }
else
{
if (w->rb_link[0] == NULL
|| w->rb_link[0]->rb_color == RB_BLACK)
{
<Transform right-side RB deletion rebalancing case 3 into case 2 236>
}
<Case 2 in right-side RB deletion rebalancing 237>
break;
}
This code is included in 226.
234. <Ensure w is black in right-side RB deletion rebalancing 234> =
w->rb_color = RB_BLACK;
pa[k - 1]->rb_color = RB_RED;
pa[k - 1]->rb_link[0] = w->rb_link[1];
w->rb_link[1] = pa[k - 1];
pa[k - 2]->rb_link[da[k - 2]] = w;
pa[k] = pa[k - 1];
da[k] = 1;
pa[k - 1] = w;
k++;
w = pa[k - 1]->rb_link[0];
235. <Case 1 in right-side RB deletion rebalancing 235> =
w->rb_color = RB_RED;
236. <Transform right-side RB deletion rebalancing case 3 into case 2 236> =
struct rb_node *y = w->rb_link[1];
y->rb_color = RB_BLACK;
w->rb_color = RB_RED;
w->rb_link[1] = y->rb_link[0];
y->rb_link[0] = w;
w = pa[k - 1]->rb_link[0] = y;
237. <Case 2 in right-side RB deletion rebalancing 237> =
w->rb_color = pa[k - 1]->rb_color;
pa[k - 1]->rb_color = RB_BLACK;
w->rb_link[0]->rb_color = RB_BLACK;
pa[k - 1]->rb_link[0] = w->rb_link[1];
w->rb_link[1] = pa[k - 1];
pa[k - 2]->rb_link[da[k - 2]] = w;
6.5.3 Step 4: Finish Up
|
6.5 Deletion
|
6.6 Testing
|