mirror of
https://gitlab.nic.cz/labs/bird.git
synced 2024-11-10 05:08:42 +00:00
Extend remove_node() with deleting root node
This commit is contained in:
parent
26ac6dca5c
commit
7657d05592
@ -95,9 +95,11 @@ static void
|
|||||||
remove_node(struct trie_node *node)
|
remove_node(struct trie_node *node)
|
||||||
{
|
{
|
||||||
assert(node != NULL);
|
assert(node != NULL);
|
||||||
assert(node->parent != NULL);
|
|
||||||
assert(node->child[0] == NULL && node->child[1] == NULL);
|
assert(node->child[0] == NULL && node->child[1] == NULL);
|
||||||
|
|
||||||
|
if (node->parent == NULL)
|
||||||
|
goto free_node;
|
||||||
|
|
||||||
if (node->parent->child[0] == node)
|
if (node->parent->child[0] == node)
|
||||||
node->parent->child[0] = NULL;
|
node->parent->child[0] = NULL;
|
||||||
else if (node->parent->child[1] == node)
|
else if (node->parent->child[1] == node)
|
||||||
@ -105,7 +107,8 @@ remove_node(struct trie_node *node)
|
|||||||
else
|
else
|
||||||
bug("Invalid child pointer");
|
bug("Invalid child pointer");
|
||||||
|
|
||||||
sl_free(node);
|
free_node:
|
||||||
|
sl_free(node);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
Loading…
Reference in New Issue
Block a user