Mesa (glsl2): hash_table: Add new hash_table_remove function.
Ian Romanick
idr at kemper.freedesktop.org
Wed Jul 21 00:07:46 UTC 2010
Module: Mesa
Branch: glsl2
Commit: d4f239de6e988a59d4ba3783ea325aa1552c3f5a
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=d4f239de6e988a59d4ba3783ea325aa1552c3f5a
Author: Carl Worth <cworth at cworth.org>
Date: Mon Jul 19 18:01:43 2010 -0700
hash_table: Add new hash_table_remove function.
To allow for the removal of a single element from a hash table.
---
src/mesa/shader/hash_table.c | 17 +++++++++++++++++
src/mesa/shader/hash_table.h | 4 ++++
2 files changed, 21 insertions(+), 0 deletions(-)
diff --git a/src/mesa/shader/hash_table.c b/src/mesa/shader/hash_table.c
index 933e300..f7ef366 100644
--- a/src/mesa/shader/hash_table.c
+++ b/src/mesa/shader/hash_table.c
@@ -142,6 +142,23 @@ hash_table_insert(struct hash_table *ht, void *data, const void *key)
insert_at_head(& ht->buckets[bucket], & node->link);
}
+void
+hash_table_remove(struct hash_table *ht, const void *key)
+{
+ const unsigned hash_value = (*ht->hash)(key);
+ const unsigned bucket = hash_value % ht->num_buckets;
+ struct node *node;
+
+ foreach(node, & ht->buckets[bucket]) {
+ struct hash_node *hn = (struct hash_node *) node;
+
+ if ((*ht->compare)(hn->key, key) == 0) {
+ remove_from_list(node);
+ free(node);
+ return;
+ }
+ }
+}
unsigned
hash_table_string_hash(const void *key)
diff --git a/src/mesa/shader/hash_table.h b/src/mesa/shader/hash_table.h
index 0552691..228ab94 100644
--- a/src/mesa/shader/hash_table.h
+++ b/src/mesa/shader/hash_table.h
@@ -94,6 +94,10 @@ extern void *hash_table_find(struct hash_table *ht, const void *key);
extern void hash_table_insert(struct hash_table *ht, void *data,
const void *key);
+/**
+ * Remove a specific element from a hash table.
+ */
+extern void hash_table_remove(struct hash_table *ht, const void *key);
/**
* Compute hash value of a string
More information about the mesa-commit
mailing list