Code

avltree: Added helper to determine smallest node.
authorSebastian Harl <sh@tokkee.org>
Wed, 9 Jul 2014 09:34:10 +0000 (11:34 +0200)
committerSebastian Harl <sh@tokkee.org>
Wed, 9 Jul 2014 09:34:10 +0000 (11:34 +0200)
src/utils/avltree.c

index 8c13233b2eabb6dd7f3fbfd3e408eaccf99f5a0f..6189d1716131cbbc3b00cd4321b43a1de3cdaede 100644 (file)
@@ -134,6 +134,20 @@ node_next(node_t *n)
        return next;
 } /* node_next */
 
+static node_t *
+node_smallest(sdb_avltree_t *tree)
+{
+       node_t *n;
+
+       if (! tree)
+               return NULL;
+
+       n = tree->root;
+       while (n && n->left)
+               n = n->left;
+       return n;
+} /* node_smallest */
+
 static void
 tree_clear(sdb_avltree_t *tree)
 {
@@ -361,9 +375,7 @@ sdb_avltree_get_iter(sdb_avltree_t *tree)
        pthread_rwlock_rdlock(&tree->lock);
 
        iter->tree = tree;
-       iter->node = tree->root->left;
-       while (iter->node && iter->node->left)
-               iter->node = iter->node->left;
+       iter->node = node_smallest(tree);
 
        pthread_rwlock_unlock(&tree->lock);
        return iter;