summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Anholt <eric@anholt.net>2018-03-16 15:42:30 -0700
committerEric Anholt <eric@anholt.net>2018-03-16 15:42:30 -0700
commit7000d4285a4ac101a2b9dcb480416da22f1d8e5c (patch)
tree46df6c543b566518c06dd253fa047383b405db5a
parenta88e17d31d51054ff3232eacbce2e8361a46dc8b (diff)
Add missing set_foreach().
This was in the Mesa implementation but not upstream.
-rw-r--r--set.h10
1 files changed, 10 insertions, 0 deletions
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);