util/hash_table: add _mesa_hash_table_clear (v4)

v4: coding style change (Matt Turner)

Reviewed-by: Ian Romanick <ian.d.romanick@intel.com> (v3)
This commit is contained in:
Nicolai Hähnle
2016-01-06 14:50:46 -05:00
parent 6ad2e55a14
commit 8b11d8cfbf
4 changed files with 120 additions and 0 deletions
+26
View File
@@ -163,6 +163,32 @@ _mesa_hash_table_destroy(struct hash_table *ht,
ralloc_free(ht);
}
/**
* Deletes all entries of the given hash table without deleting the table
* itself or changing its structure.
*
* If delete_function is passed, it gets called on each entry present.
*/
void
_mesa_hash_table_clear(struct hash_table *ht,
void (*delete_function)(struct hash_entry *entry))
{
struct hash_entry *entry;
for (entry = ht->table; entry != ht->table + ht->size; entry++) {
if (entry->key == NULL)
continue;
if (delete_function != NULL && entry->key != ht->deleted_key)
delete_function(entry);
entry->key = NULL;
}
ht->entries = 0;
ht->deleted_entries = 0;
}
/** Sets the value of the key pointer used for deleted entries in the table.
*
* The assumption is that usually keys are actual pointers, so we use a