summaryrefslogtreecommitdiffstats
path: root/src/mesa
diff options
context:
space:
mode:
authorIan Romanick <[email protected]>2010-07-06 14:49:14 -0700
committerIan Romanick <[email protected]>2010-07-06 15:00:46 -0700
commitd1a1ee583e7e8338243b3e9768d2fc5312a1145d (patch)
treed1bada4bebfbdf7bb7dbdc6435927a7e4c0cb5ac /src/mesa
parente45a982313e02dbc186b51cf0935e0bec18dc61a (diff)
Add hash table helper functions for using pointers as hash keys
Diffstat (limited to 'src/mesa')
-rw-r--r--src/mesa/shader/hash_table.c14
-rw-r--r--src/mesa/shader/hash_table.h24
2 files changed, 38 insertions, 0 deletions
diff --git a/src/mesa/shader/hash_table.c b/src/mesa/shader/hash_table.c
index fa6ba2bfdfc..933e300abdd 100644
--- a/src/mesa/shader/hash_table.c
+++ b/src/mesa/shader/hash_table.c
@@ -157,3 +157,17 @@ hash_table_string_hash(const void *key)
return hash;
}
+
+
+unsigned
+hash_table_pointer_hash(const void *key)
+{
+ return (unsigned)((uintptr_t) key / sizeof(void *));
+}
+
+
+int
+hash_table_pointer_compare(const void *key1, const void *key2)
+{
+ return key1 == key2 ? 0 : 1;
+}
diff --git a/src/mesa/shader/hash_table.h b/src/mesa/shader/hash_table.h
index 881e756f087..05526914643 100644
--- a/src/mesa/shader/hash_table.h
+++ b/src/mesa/shader/hash_table.h
@@ -118,6 +118,30 @@ extern unsigned hash_table_string_hash(const void *key);
*/
#define hash_table_string_compare ((hash_compare_func_t) strcmp)
+
+/**
+ * Compute hash value of a pointer
+ *
+ * \param key Pointer to be used as a hash key
+ *
+ * \note
+ * The memory pointed to by \c key is \b never accessed. The value of \c key
+ * itself is used as the hash key
+ *
+ * \sa hash_table_pointer_compare
+ */
+unsigned
+hash_table_pointer_hash(const void *key);
+
+
+/**
+ * Compare two pointers used as keys
+ *
+ * \sa hash_table_pointer_hash
+ */
+int
+hash_table_pointer_compare(const void *key1, const void *key2);
+
#ifdef __cplusplus
};
#endif