From: Sebastian Harl Date: Tue, 8 Jul 2014 20:08:55 +0000 (+0200) Subject: avltree: Removed some irrelevant special cases. X-Git-Tag: sysdb-0.3.0~72 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=d735d37ba7cb09d1ee269fa7d8962f5a89fcd4f8;p=sysdb.git avltree: Removed some irrelevant special cases. --- diff --git a/src/utils/avltree.c b/src/utils/avltree.c index 95c004d..7c81059 100644 --- a/src/utils/avltree.c +++ b/src/utils/avltree.c @@ -31,8 +31,9 @@ #include "utils/avltree.h" -#include +#include +#include #include /* @@ -202,8 +203,16 @@ sdb_avltree_insert(sdb_avltree_t *tree, sdb_object_t *obj) if (! n) return -1; + if (! tree->root) { + tree->root = n; + tree->size = 1; + return 0; + } + parent = tree->root; - while (parent) { + while (42) { + assert(parent); + diff = tree->cmp(obj, parent->obj); if (! diff) { node_destroy(n); @@ -226,15 +235,6 @@ sdb_avltree_insert(sdb_avltree_t *tree, sdb_object_t *obj) } } - if (! parent) { - /* new root */ - if (diff < 0) - n->right = tree->root; - else - n->left = tree->root; - tree->root = n; - } - n->parent = parent; ++tree->size;