summaryrefslogtreecommitdiffstats
path: root/src/util/hash_table.c
diff options
context:
space:
mode:
authorNicolai Hähnle <nicolai.haehnle@amd.com>2016-01-06 14:50:46 -0500
committerNicolai Hähnle <nicolai.haehnle@amd.com>2016-02-03 14:03:25 +0100
commit8b11d8cfbfaaf72755e6c200140e253cb3e3fa8a (patch)
tree94f35edeae0838227c433092b97a474b05222a75 /src/util/hash_table.c
parent6ad2e55a1405ac3757439dae55ed86425bb65806 (diff)
downloadexternal_mesa3d-8b11d8cfbfaaf72755e6c200140e253cb3e3fa8a.zip
external_mesa3d-8b11d8cfbfaaf72755e6c200140e253cb3e3fa8a.tar.gz
external_mesa3d-8b11d8cfbfaaf72755e6c200140e253cb3e3fa8a.tar.bz2
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)
Diffstat (limited to 'src/util/hash_table.c')
-rw-r--r--src/util/hash_table.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/util/hash_table.c b/src/util/hash_table.c
index 3ec65af..4cfe3d9 100644
--- a/src/util/hash_table.c
+++ b/src/util/hash_table.c
@@ -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