X-Git-Url: https://git.ozlabs.org/?p=ccan;a=blobdiff_plain;f=ccan%2Fhashtable%2Fhashtable.h;h=cd878952bd4eb08e5b673b7783d468b85182cd6d;hp=269e942ff9fd8a3437a67be25b38684dc5ce8a65;hb=458831cf788f21f8588bad7d7490f729361fc136;hpb=581af9029888f99c663ea4554e23961a1933aca2 diff --git a/ccan/hashtable/hashtable.h b/ccan/hashtable/hashtable.h index 269e942f..cd878952 100644 --- a/ccan/hashtable/hashtable.h +++ b/ccan/hashtable/hashtable.h @@ -2,6 +2,7 @@ #define CCAN_HASHTABLE_H #include "config.h" #include +#include struct hashtable; @@ -63,12 +64,28 @@ bool hashtable_del(struct hashtable *ht, unsigned long hash, const void *p); /** * hashtable_traverse - call a function on every pointer in hash tree * @ht: the hashtable + * @type: the type of the element in the hashtable. * @cb: the callback: returns true to abort traversal. * @cbarg: the argument to the callback * * Note that your traversal callback may delete any entry (it won't crash), * but it may make the traverse unreliable. */ -void hashtable_traverse(struct hashtable *ht, bool (*cb)(void *p, void *cbarg), - void *cbarg); +#define hashtable_traverse(ht, type, cb, cbarg) \ + _hashtable_traverse(ht, cast_if_type(bool (*)(void *, void *), \ + cast_if_any(bool (*)(void *, \ + void *), \ + (cb), &*(cb), \ + bool (*)(const type *, \ + const typeof(*cbarg) *), \ + bool (*)(type *, \ + const typeof(*cbarg) *), \ + bool (*)(const type *, \ + typeof(*cbarg) *)), \ + &*(cb), \ + bool (*)(type *, typeof(*cbarg) *)), \ + (cbarg)) + +void _hashtable_traverse(struct hashtable *ht, + bool (*cb)(void *p, void *cbarg), void *cbarg); #endif /* CCAN_HASHTABLE_H */