Code

avltree: Removed some irrelevant special cases.
authorSebastian Harl <sh@tokkee.org>
Tue, 8 Jul 2014 20:08:55 +0000 (22:08 +0200)
committerSebastian Harl <sh@tokkee.org>
Tue, 8 Jul 2014 20:08:55 +0000 (22:08 +0200)
src/utils/avltree.c

index 95c004d32ffbe10ae39a31b9a146a80adccd2b41..7c810599135cf94658791fd1acb5c0a41f759852 100644 (file)
@@ -31,8 +31,9 @@
 
 #include "utils/avltree.h"
 
-#include <stdlib.h>
+#include <assert.h>
 
+#include <stdlib.h>
 #include <pthread.h>
 
 /*
@@ -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;