From d735d37ba7cb09d1ee269fa7d8962f5a89fcd4f8 Mon Sep 17 00:00:00 2001 From: Sebastian Harl Date: Tue, 8 Jul 2014 22:08:55 +0200 Subject: [PATCH] avltree: Removed some irrelevant special cases. --- src/utils/avltree.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) 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; -- 2.30.2