aboutsummaryrefslogtreecommitdiffstats
path: root/src/vppinfra
diff options
context:
space:
mode:
authorFlorin Coras <fcoras@cisco.com>2019-06-19 16:45:09 -0700
committerFlorin Coras <fcoras@cisco.com>2019-06-19 16:50:30 -0700
commitd314963d0f1d12c45c55c7fd210f93c5cac3a8fc (patch)
tree70e630d04046e8a4c5e1fe261bdae402ce4f6798 /src/vppinfra
parent6ac96762dc2631bb1c720057f2b9dd854c69b767 (diff)
vppinfra: fix rbtree node delete
Type:fix Make sure tnil color is black and that the right node colors are updated. Change-Id: Ibd9d7ea9438df4dab977202955957824723a865d Signed-off-by: Florin Coras <fcoras@cisco.com>
Diffstat (limited to 'src/vppinfra')
-rw-r--r--src/vppinfra/rbtree.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/src/vppinfra/rbtree.c b/src/vppinfra/rbtree.c
index df759cb2344..ff86b0f1b5b 100644
--- a/src/vppinfra/rbtree.c
+++ b/src/vppinfra/rbtree.c
@@ -344,7 +344,7 @@ rb_tree_del_node (rb_tree_t * rt, rb_node_t * z)
x->parent = yi;
else
{
- rb_tree_transplant (rt, y, rb_node_right (rt, y));
+ rb_tree_transplant (rt, y, x);
y->right = z->right;
yr = rb_node_right (rt, y);
yr->parent = yi;
@@ -379,7 +379,8 @@ rb_tree_del_node (rb_tree_t * rt, rb_node_t * z)
wr = rb_node_right (rt, w);
if (wl->color == RBTREE_BLACK && wr->color == RBTREE_BLACK)
{
- w->color = RBTREE_RED;
+ if (!rb_node_is_tnil (rt, w))
+ w->color = RBTREE_RED;
x = xp;
}
else
@@ -390,6 +391,7 @@ rb_tree_del_node (rb_tree_t * rt, rb_node_t * z)
w->color = RBTREE_RED;
rb_tree_rotate_right (rt, w);
w = rb_node_right (rt, xp);
+ wr = rb_node_right (rt, w);
}
w->color = xp->color;
xp->color = RBTREE_BLACK;
@@ -412,7 +414,8 @@ rb_tree_del_node (rb_tree_t * rt, rb_node_t * z)
wr = rb_node_right (rt, w);
if (wl->color == RBTREE_BLACK && wr->color == RBTREE_BLACK)
{
- w->color = RBTREE_RED;
+ if (!rb_node_is_tnil (rt, w))
+ w->color = RBTREE_RED;
x = xp;
}
else
@@ -423,6 +426,7 @@ rb_tree_del_node (rb_tree_t * rt, rb_node_t * z)
w->color = RBTREE_RED;
rb_tree_rotate_left (rt, w);
w = rb_node_left (rt, xp);
+ wl = rb_node_left (rt, w);
}
w->color = xp->color;
xp->color = RBTREE_BLACK;