X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=lib%2Fgl_oset.h;fp=lib%2Fgl_oset.h;h=2a67994a86f3a2a0a7e659c253fb1b92cb5675f2;hb=5c90f29795d4e8d9a66268d5dc61d02b82cf7db8;hp=6c5d5eb42041a0983aacfe4bdb7d72206e5b126f;hpb=a7cc0db9f5f6c63936c6914d4bb6448789774e5f;p=gnulib.git diff --git a/lib/gl_oset.h b/lib/gl_oset.h index 6c5d5eb42..2a67994a8 100644 --- a/lib/gl_oset.h +++ b/lib/gl_oset.h @@ -59,6 +59,7 @@ extern "C" { gl_oset_add O(n) O(log n) gl_oset_remove O(n) O(log n) gl_oset_search O(log n) O(log n) + gl_oset_search_atleast O(log n) O(log n) gl_oset_iterator O(1) O(log n) gl_oset_iterator_next O(1) O(log n) */ @@ -69,6 +70,10 @@ extern "C" { NULL denotes pointer comparison. */ typedef int (*gl_setelement_compar_fn) (const void *elt1, const void *elt2); +/* Type of function used to compare an element with a threshold. + Return true if the element is greater or equal than the threshold. */ +typedef bool (*gl_setelement_threshold_fn) (const void *elt, const void *threshold); + struct gl_oset_impl; /* Type representing an entire ordered set. */ typedef struct gl_oset_impl * gl_oset_t; @@ -90,6 +95,16 @@ extern size_t gl_oset_size (gl_oset_t set); Return true if found, or false if not present in the set. */ extern bool gl_oset_search (gl_oset_t set, const void *elt); +/* Search the least element in the ordered set that compares greater or equal + to the given THRESHOLD. The representation of the THRESHOLD is defined + by the THRESHOLD_FN. + Return true and store the found element in *ELTP if found, otherwise return + false. */ +extern bool gl_oset_search_atleast (gl_oset_t set, + gl_setelement_threshold_fn threshold_fn, + const void *threshold, + const void **eltp); + /* Add an element to an ordered set. Return true if it was not already in the set and added. */ extern bool gl_oset_add (gl_oset_t set, const void *elt); @@ -143,6 +158,9 @@ struct gl_oset_implementation gl_setelement_compar_fn compar_fn); size_t (*size) (gl_oset_t set); bool (*search) (gl_oset_t set, const void *elt); + bool (*search_atleast) (gl_oset_t set, + gl_setelement_threshold_fn threshold_fn, + const void *threshold, const void **eltp); bool (*add) (gl_oset_t set, const void *elt); bool (*remove) (gl_oset_t set, const void *elt); void (*oset_free) (gl_oset_t set); @@ -186,6 +204,16 @@ gl_oset_search (gl_oset_t set, const void *elt) return ((const struct gl_oset_impl_base *) set)->vtable->search (set, elt); } +# define gl_oset_search_atleast gl_oset_search_atleast_inline +static inline bool +gl_oset_search_atleast (gl_oset_t set, + gl_setelement_threshold_fn threshold_fn, + const void *threshold, const void **eltp) +{ + return ((const struct gl_oset_impl_base *) set)->vtable + ->search_atleast (set, threshold_fn, threshold, eltp); +} + # define gl_oset_add gl_oset_add_inline static inline bool gl_oset_add (gl_oset_t set, const void *elt)