rbtree.c: fixed bug with tree not being empty when removing root node.
This commit is contained in:
parent
3671888b8b
commit
246ea7854e
1 changed files with 7 additions and 7 deletions
14
src/rbtree.c
14
src/rbtree.c
|
|
@ -262,11 +262,7 @@ int rbtree_delete(rbtree *tree, const void *key) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
tree->root = head.child[1];
|
||||
if (tree->root)
|
||||
tree->root->color = RB_BLACK;
|
||||
|
||||
|
||||
/* remove if found */
|
||||
if (f) {
|
||||
if (tree->delete_fn)
|
||||
|
|
@ -276,7 +272,11 @@ int rbtree_delete(rbtree *tree, const void *key) {
|
|||
f->key = q->key;
|
||||
swap(p, 1, q) = swap(q, 0, NULL);
|
||||
xfree(q);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
|
||||
tree->root = head.child[1];
|
||||
if (tree->root)
|
||||
tree->root->color = RB_BLACK;
|
||||
|
||||
return f != NULL;
|
||||
}
|
||||
|
|
|
|||
Reference in a new issue