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:
Mike Blumenkrantz
2021-01-12 14:49:48 -05:00
committed by Marge Bot
parent 539c7ca508
commit 759cc91450
3 changed files with 46 additions and 0 deletions
+21
View File
@@ -560,6 +560,27 @@ _mesa_set_remove_key(struct set *set, const void *key)
_mesa_set_remove(set, _mesa_set_search(set, key));
}
/**
* This function is an iterator over the set when no deleted entries are present.
*
* Pass in NULL for the first entry, as in the start of a for loop.
*/
struct set_entry *
_mesa_set_next_entry_unsafe(const struct set *ht, struct set_entry *entry)
{
assert(!ht->deleted_entries);
if (!ht->entries)
return NULL;
if (entry == NULL)
entry = ht->table;
else
entry = entry + 1;
if (entry != ht->table + ht->size)
return entry->key ? entry : _mesa_set_next_entry_unsafe(ht, entry);
return NULL;
}
/**
* This function is an iterator over the hash table.
*