diff options
author | Eric Anholt <eric@anholt.net> | 2018-03-16 15:42:30 -0700 |
---|---|---|
committer | Eric Anholt <eric@anholt.net> | 2018-03-16 15:42:30 -0700 |
commit | 7000d4285a4ac101a2b9dcb480416da22f1d8e5c (patch) | |
tree | 46df6c543b566518c06dd253fa047383b405db5a | |
parent | a88e17d31d51054ff3232eacbce2e8361a46dc8b (diff) |
Add missing set_foreach().
This was in the Mesa implementation but not upstream.
-rw-r--r-- | set.h | 10 |
1 files changed, 10 insertions, 0 deletions
@@ -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); |