Hi Jukka, On 02/12/2015 02:35 AM, Jukka Rissanen wrote: > Hi Denis, > > On ti, 2015-02-10 at 16:42 +0200, Jukka Rissanen wrote: >> Add new function l_hashmap_find() which is similar to foreach. >> The find will start to call a user supplied function for every >> entry in hashmap. If user function returns true, then the find >> will return and not call remaining hash elements. >> --- > > Just wanted to ask are you ok with func? At the moment there is no > function to traverse the hash, other than the foreach variant and it is > very sub-optimal as it will traverse the whole hash even if such a thing > is not needed by the caller. Even better option would be to change the > return parameter of foreach callback to return bool so we could do with > only one traversing function. > I'm not totally against it, so I might be convinced this is useful. However, I really have to wonder why a hashmap is being used as a glorified linked list? Whats the target use case? >> void *user_data); >> +typedef bool (*l_hashmap_find_func_t) (const void *key, void *value, >> + void *user_data); >> typedef void (*l_hashmap_destroy_func_t) (void *value); >> typedef unsigned int (*l_hashmap_hash_func_t) (const void *p); >> typedef int (*l_hashmap_compare_func_t) (const void *a, const void *b); >> @@ -70,6 +72,9 @@ void *l_hashmap_lookup(struct l_hashmap *hashmap, const void *key); >> void l_hashmap_foreach(struct l_hashmap *hashmap, >> l_hashmap_foreach_func_t function, void *user_data); >> >> +void l_hashmap_find(struct l_hashmap *hashmap, >> + l_hashmap_find_func_t function, void *user_data); >> + If we're going to do this, then the signature should mimic l_hashmap_lookup. e.g. void *l_hashmap_find(struct l_hashmap *hashmap, l_hashmap_find_func_t function, void *user_data); Regards, -Denis