util/set: add macro for destructively iterating set entries
a common usage for sets is for tracking exactly one instance of a pointer for a given period of time, after which the set's entries are purged and it is reused this macro enables the purge phase of such usage to reset the table to a pristine state, avoiding future rehashing due to ballooning of deleted entries Reviewed-by: Adam Jackson <ajax@redhat.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/8498>
This commit is contained in:
committed by
Marge Bot
parent
539c7ca508
commit
759cc91450
@@ -111,6 +111,8 @@ _mesa_set_remove_key(struct set *set, const void *key);
|
||||
|
||||
struct set_entry *
|
||||
_mesa_set_next_entry(const struct set *set, struct set_entry *entry);
|
||||
struct set_entry *
|
||||
_mesa_set_next_entry_unsafe(const struct set *set, struct set_entry *entry);
|
||||
|
||||
struct set_entry *
|
||||
_mesa_set_random_entry(struct set *set,
|
||||
@@ -132,6 +134,15 @@ _mesa_set_intersects(struct set *a, struct set *b);
|
||||
entry != NULL; \
|
||||
entry = _mesa_set_next_entry(set, entry))
|
||||
|
||||
/**
|
||||
* This foreach function destroys the table as it iterates.
|
||||
* It is not safe to use when inserting or removing entries.
|
||||
*/
|
||||
#define set_foreach_remove(set, entry) \
|
||||
for (struct set_entry *entry = _mesa_set_next_entry_unsafe(set, NULL); \
|
||||
(set)->entries; \
|
||||
entry->hash = 0, entry->key = (void*)NULL, (set)->entries--, entry = _mesa_set_next_entry_unsafe(set, entry))
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern C */
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user