diff options
author | Bruno Haible <bruno@clisp.org> | 2006-10-04 17:28:15 +0000 |
---|---|---|
committer | Bruno Haible <bruno@clisp.org> | 2006-10-04 17:28:15 +0000 |
commit | 5c90f29795d4e8d9a66268d5dc61d02b82cf7db8 (patch) | |
tree | 52e242d232da3963405ca7643a8b31e0417139be /lib/gl_anytree_oset.h | |
parent | a7cc0db9f5f6c63936c6914d4bb6448789774e5f (diff) | |
download | gnulib-5c90f29795d4e8d9a66268d5dc61d02b82cf7db8.tar.gz |
Add a search_atleast operation.
Diffstat (limited to 'lib/gl_anytree_oset.h')
-rw-r--r-- | lib/gl_anytree_oset.h | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/lib/gl_anytree_oset.h b/lib/gl_anytree_oset.h index 6ac07e4625..53c877505a 100644 --- a/lib/gl_anytree_oset.h +++ b/lib/gl_anytree_oset.h @@ -73,6 +73,41 @@ gl_tree_search (gl_oset_t set, const void *elt) return false; } +static bool +gl_tree_search_atleast (gl_oset_t set, + gl_setelement_threshold_fn threshold_fn, + const void *threshold, + const void **eltp) +{ + gl_oset_node_t node; + + for (node = set->root; node != NULL; ) + { + if (! threshold_fn (node->value, threshold)) + node = node->right; + else + { + /* We have an element >= VALUE. But we need the leftmost such + element. */ + gl_oset_node_t found = node; + node = node->left; + for (; node != NULL; ) + { + if (! threshold_fn (node->value, threshold)) + node = node->right; + else + { + found = node; + node = node->left; + } + } + *eltp = found; + return true; + } + } + return false; +} + static gl_oset_node_t gl_tree_search_node (gl_oset_t set, const void *elt) { |