num_buckets = 16;
}
- ht = malloc(sizeof(*ht) + ((num_buckets - 1) * sizeof(ht->buckets[0])));
+ ht = _mesa_malloc(sizeof(*ht) + ((num_buckets - 1)
+ * sizeof(ht->buckets[0])));
if (ht != NULL) {
ht->hash = hash;
ht->compare = compare;
}
+void
+hash_table_dtor(struct hash_table *ht)
+{
+ hash_table_clear(ht);
+ _mesa_free(ht);
+}
+
+
void
hash_table_clear(struct hash_table *ht)
{
for (i = 0; i < ht->num_buckets; i++) {
foreach_s(node, temp, & ht->buckets[i]) {
remove_from_list(node);
- free(node);
+ _mesa_free(node);
}
assert(is_empty_list(& ht->buckets[i]));
const unsigned bucket = hash_value % ht->num_buckets;
struct hash_node *node;
- node = calloc(1, sizeof(*node));
+ node = _mesa_calloc(1, sizeof(*node));
node->data = data;
node->key = key;
hash_func_t hash, hash_compare_func_t compare);
+/**
+ * Release all memory associated with a hash table
+ *
+ * \warning
+ * This function cannot release memory occupied either by keys or data.
+ */
+extern void hash_table_dtor(struct hash_table *ht);
+
+
/**
* Flush all entries from a hash table
*