X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fdaemon%2Futils_avltree.c;h=58b8b8479128b6a9b25377412e1e9e608070826a;hb=fc6f1e3d33d646391adb5cedc62e7b3904c15003;hp=04e540327fcbae05542cb5da6661b8ca88f904f0;hpb=f664b944f774e4d1e5d5c562eaf0bb207c6a7edf;p=collectd.git diff --git a/src/daemon/utils_avltree.c b/src/daemon/utils_avltree.c index 04e54032..58b8b847 100644 --- a/src/daemon/utils_avltree.c +++ b/src/daemon/utils_avltree.c @@ -146,6 +146,9 @@ static c_avl_node_t *rotate_right (c_avl_tree_t *t, c_avl_node_t *x) c_avl_node_t *y; c_avl_node_t *b; + assert (x != NULL); + assert (x->left != NULL); + p = x->parent; y = x->left; b = y->right; @@ -170,7 +173,7 @@ static c_avl_node_t *rotate_right (c_avl_tree_t *t, c_avl_node_t *x) y->height = calc_height (y); return (y); -} /* void rotate_left */ +} /* void rotate_right */ /* * (x) (y) @@ -187,6 +190,9 @@ static c_avl_node_t *rotate_left (c_avl_tree_t *t, c_avl_node_t *x) c_avl_node_t *y; c_avl_node_t *b; + assert (x != NULL); + assert (x->right != NULL); + p = x->parent; y = x->right; b = y->left; @@ -617,10 +623,18 @@ int c_avl_pick (c_avl_tree_t *t, void **key, void **value) n = t->root; while ((n->left != NULL) || (n->right != NULL)) { - int height_left = (n->left == NULL) ? 0 : n->left->height; - int height_right = (n->right == NULL) ? 0 : n->right->height; + if (n->left == NULL) + { + n = n->right; + continue; + } + else if (n->right == NULL) + { + n = n->left; + continue; + } - if (height_left > height_right) + if (n->left->height > n->right->height) n = n->left; else n = n->right; @@ -638,6 +652,7 @@ int c_avl_pick (c_avl_tree_t *t, void **key, void **value) *value = n->value; free_node (n); + --t->size; rebalance (t, p); return (0);