X-Git-Url: https://git.ozlabs.org/?a=blobdiff_plain;f=ccan%2Fhtable%2Fhtable_type.h;h=61535c2c665c43fa611f5b995205e9fccd94f648;hb=15966998bbeaea92e4e1b1c9f067a4142f51f680;hp=6764c3f24ae103c8bccbcc8949c283ff56dcca1e;hpb=71b4e3ad90db6bacc51552438c3f6eb2a20d2631;p=ccan diff --git a/ccan/htable/htable_type.h b/ccan/htable/htable_type.h index 6764c3f2..61535c2c 100644 --- a/ccan/htable/htable_type.h +++ b/ccan/htable/htable_type.h @@ -31,9 +31,15 @@ * bool _del(struct *ht, const *e); * bool _delkey(struct *ht, const *k); * - * Find function return the matching element, or NULL: + * Find and return the (first) matching element, or NULL: * type *_get(const struct @name *ht, const *k); * + * Find and return all matching elements, or NULL: + * type *_getfirst(const struct @name *ht, const *k, + * struct _iter *i); + * type *_getnext(const struct @name *ht, const *k, + * struct _iter *i); + * * Iteration over hashtable is also supported: * type *_first(const struct *ht, struct _iter *i); * type *_next(const struct *ht, struct _iter *i); @@ -49,6 +55,7 @@ struct name##_iter { struct htable_iter i; }; \ static inline size_t name##_hash(const void *elem, void *priv) \ { \ + (void)priv; \ return hashfn(keyof((const type *)elem)); \ } \ static inline UNNEEDED void name##_init(struct name *ht) \ @@ -84,6 +91,35 @@ (bool (*)(const void *, void *))(eqfn), \ k); \ } \ + static inline UNNEEDED type *name##_getmatch_(const struct name *ht, \ + const HTABLE_KTYPE(keyof) k, \ + size_t h, \ + type *v, \ + struct name##_iter *iter) \ + { \ + while (v) { \ + if (eqfn(v, k)) \ + break; \ + v = htable_nextval(&ht->raw, &iter->i, h); \ + } \ + return v; \ + } \ + static inline UNNEEDED type *name##_getfirst(const struct name *ht, \ + const HTABLE_KTYPE(keyof) k, \ + struct name##_iter *iter) \ + { \ + size_t h = hashfn(k); \ + type *v = htable_firstval(&ht->raw, &iter->i, h); \ + return name##_getmatch_(ht, k, h, v, iter); \ + } \ + static inline UNNEEDED type *name##_getnext(const struct name *ht, \ + const HTABLE_KTYPE(keyof) k, \ + struct name##_iter *iter) \ + { \ + size_t h = hashfn(k); \ + type *v = htable_nextval(&ht->raw, &iter->i, h); \ + return name##_getmatch_(ht, k, h, v, iter); \ + } \ static inline UNNEEDED bool name##_delkey(struct name *ht, \ const HTABLE_KTYPE(keyof) k) \ { \