From 7000d4285a4ac101a2b9dcb480416da22f1d8e5c Mon Sep 17 00:00:00 2001 From: Eric Anholt Date: Fri, 16 Mar 2018 15:42:30 -0700 Subject: Add missing set_foreach(). This was in the Mesa implementation but not upstream. --- set.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/set.h b/set.h index 53748bf..abb8aee 100644 --- a/set.h +++ b/set.h @@ -78,6 +78,16 @@ struct set_entry * set_random_entry(struct set *set, int (*predicate)(struct set_entry *entry)); +/** + * This foreach function is safe against deletion (which just replaces + * an entry's data with the deleted marker), but not against insertion + * (which may rehash the table, making entry a dangling pointer). + */ +#define set_foreach(ht, entry) \ + for (entry = set_next_entry(ht, NULL); \ + entry != NULL; \ + entry = set_next_entry(ht, entry)) + /* Alternate interfaces to reduce repeated calls to hash function. */ struct set_entry * set_search_pre_hashed(struct set *set, uint32_t hash, const void *key); -- cgit v1.2.3