* free to avoid exponential performance degradation as the hash table fills
*/
-uint32_t deleted_key_value;
-const void *deleted_key = &deleted_key_value;
+static const uint32_t deleted_key_value;
+static const void *deleted_key = &deleted_key_value;
static const struct {
uint32_t max_entries, size, rehash;
ralloc_free(ht);
}
+/**
+ * Clears all values from the given set.
+ *
+ * If delete_function is passed, it gets called on each entry present before
+ * the set is cleared.
+ */
+void
+_mesa_set_clear(struct set *set, void (*delete_function)(struct set_entry *entry))
+{
+ struct set_entry *entry;
+
+ if (!set)
+ return;
+
+ set_foreach (set, entry) {
+ if (delete_function)
+ delete_function(entry);
+ entry->key = deleted_key;
+ }
+
+ set->entries = set->deleted_entries = 0;
+}
+
/**
* Finds a set entry with the given key and hash of that key.
*
ht->entries = 0;
ht->deleted_entries = 0;
- for (entry = old_ht.table;
- entry != old_ht.table + old_ht.size;
- entry++) {
- if (entry_is_present(entry)) {
- set_add(ht, entry->hash, entry->key);
- }
+ set_foreach(&old_ht, entry) {
+ set_add(ht, entry->hash, entry->key);
}
ralloc_free(old_ht.table);