summaryrefslogtreecommitdiffstats
path: root/src/mesa/program/hash_table.c
diff options
context:
space:
mode:
authorIan Romanick <[email protected]>2011-08-17 11:51:15 -0700
committerIan Romanick <[email protected]>2011-10-04 12:33:28 -0700
commitacd834fde2e604173985be5d44cb2cf2b0cd5673 (patch)
treea2a9237fcaca11ba8dddb7cb836b373eaa87f1a5 /src/mesa/program/hash_table.c
parentb7fa0d0727a3a9e1f64d3cfc7a0f157b35dec09e (diff)
mesa: Add hash_table_replace
hash_table_replace doesn't use get_node to avoid having to hash the key twice. Signed-off-by: Ian Romanick <[email protected]> Reviewed-by: Kenneth Graunke <[email protected]>
Diffstat (limited to 'src/mesa/program/hash_table.c')
-rw-r--r--src/mesa/program/hash_table.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/mesa/program/hash_table.c b/src/mesa/program/hash_table.c
index 2b09462c0f5..dc8563a330f 100644
--- a/src/mesa/program/hash_table.c
+++ b/src/mesa/program/hash_table.c
@@ -150,6 +150,31 @@ hash_table_insert(struct hash_table *ht, void *data, const void *key)
}
void
+hash_table_replace(struct hash_table *ht, void *data, const void *key)
+{
+ const unsigned hash_value = (*ht->hash)(key);
+ const unsigned bucket = hash_value % ht->num_buckets;
+ struct node *node;
+ struct hash_node *hn;
+
+ foreach(node, & ht->buckets[bucket]) {
+ hn = (struct hash_node *) node;
+
+ if ((*ht->compare)(hn->key, key) == 0) {
+ hn->data = data;
+ return;
+ }
+ }
+
+ hn = calloc(1, sizeof(*hn));
+
+ hn->data = data;
+ hn->key = key;
+
+ insert_at_head(& ht->buckets[bucket], & hn->link);
+}
+
+void
hash_table_remove(struct hash_table *ht, const void *key)
{
struct node *node = (struct node *) get_node(ht, key);