aboutsummaryrefslogtreecommitdiff
path: root/mesalib/src/mesa/program/hash_table.c
diff options
context:
space:
mode:
authormarha <marha@users.sourceforge.net>2011-10-05 17:44:57 +0200
committermarha <marha@users.sourceforge.net>2011-10-05 17:44:57 +0200
commit8af87a5b60e37ae84fdd759e2c1602be38be4905 (patch)
tree2e621c7fbdc4dfe9eb8d733af4cc232bc03643d4 /mesalib/src/mesa/program/hash_table.c
parent8238de0fe0c28bd54b3e6cdd1fc94513cf21d3cc (diff)
parentf7025b4baa1ba35ee796785641f04eac5bedb0a6 (diff)
downloadvcxsrv-8af87a5b60e37ae84fdd759e2c1602be38be4905.tar.gz
vcxsrv-8af87a5b60e37ae84fdd759e2c1602be38be4905.tar.bz2
vcxsrv-8af87a5b60e37ae84fdd759e2c1602be38be4905.zip
Merge remote-tracking branch 'origin/released'
Conflicts: mesalib/src/mapi/glapi/glapi.h mesalib/src/mesa/main/syncobj.h xorg-server/dix/events.c xorg-server/dix/getevents.c xorg-server/include/misc.h
Diffstat (limited to 'mesalib/src/mesa/program/hash_table.c')
-rw-r--r--mesalib/src/mesa/program/hash_table.c39
1 files changed, 32 insertions, 7 deletions
diff --git a/mesalib/src/mesa/program/hash_table.c b/mesalib/src/mesa/program/hash_table.c
index 877a9e2ff..dc8563a33 100644
--- a/mesalib/src/mesa/program/hash_table.c
+++ b/mesalib/src/mesa/program/hash_table.c
@@ -108,8 +108,8 @@ hash_table_clear(struct hash_table *ht)
}
-void *
-hash_table_find(struct hash_table *ht, const void *key)
+static struct hash_node *
+get_node(struct hash_table *ht, const void *key)
{
const unsigned hash_value = (*ht->hash)(key);
const unsigned bucket = hash_value % ht->num_buckets;
@@ -119,13 +119,20 @@ hash_table_find(struct hash_table *ht, const void *key)
struct hash_node *hn = (struct hash_node *) node;
if ((*ht->compare)(hn->key, key) == 0) {
- return hn->data;
+ return hn;
}
}
return NULL;
}
+void *
+hash_table_find(struct hash_table *ht, const void *key)
+{
+ struct hash_node *hn = get_node(ht, key);
+
+ return (hn == NULL) ? NULL : hn->data;
+}
void
hash_table_insert(struct hash_table *ht, void *data, const void *key)
@@ -143,21 +150,39 @@ hash_table_insert(struct hash_table *ht, void *data, const void *key)
}
void
-hash_table_remove(struct hash_table *ht, const void *key)
+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]) {
- struct hash_node *hn = (struct hash_node *) node;
+ hn = (struct hash_node *) node;
if ((*ht->compare)(hn->key, key) == 0) {
- remove_from_list(node);
- free(node);
+ 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);
+ if (node != NULL) {
+ remove_from_list(node);
+ free(node);
+ return;
+ }
}
void