From: Sebastian Harl Date: Wed, 9 Jul 2014 09:34:10 +0000 (+0200) Subject: avltree: Added helper to determine smallest node. X-Git-Tag: sysdb-0.3.0~68 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=9b2a1044801e9ba7d8d7d68bba3ac46742140235;p=sysdb.git avltree: Added helper to determine smallest node. --- diff --git a/src/utils/avltree.c b/src/utils/avltree.c index 8c13233..6189d17 100644 --- a/src/utils/avltree.c +++ b/src/utils/avltree.c @@ -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;