X-Git-Url: https://git.ozlabs.org/?a=blobdiff_plain;f=ccan%2Fhtable%2Fhtable.h;fp=ccan%2Fhtable%2Fhtable.h;h=eac57e37a326612226f6cd7907c04bcbc589c360;hb=209a81909942a07cb334d6dcae7626a3ecde141d;hp=0ecae726c0bd560a5a1ba598e4d544d7480041a4;hpb=c910bdce167ff42aa6d9e4f1b8f905a76f0b9e75;p=ccan diff --git a/ccan/htable/htable.h b/ccan/htable/htable.h index 0ecae726..eac57e37 100644 --- a/ccan/htable/htable.h +++ b/ccan/htable/htable.h @@ -267,6 +267,19 @@ void *htable_prev_(const struct htable *htable, struct htable_iter *i); htable_delval_(htable_debug(htable, HTABLE_LOC), i) void htable_delval_(struct htable *ht, struct htable_iter *i); +/** + * htable_pick - set iterator to a random valid entry. + * @ht: the htable + * @seed: a random number to use. + * @i: the htable_iter which is output (or NULL). + * + * Usually used with htable_delval to delete a random entry. Returns + * NULL iff the table is empty, otherwise a random entry. + */ +#define htable_pick(htable, seed, i) \ + htable_pick_(htable_debug(htable, HTABLE_LOC), seed, i) +void *htable_pick_(const struct htable *ht, size_t seed, struct htable_iter *i); + /** * htable_set_allocator - set calloc/free functions. * @alloc: allocator to use, must zero memory!