diff options
Diffstat (limited to 'src/util')
-rw-r--r-- | src/util/hash_table.c | 44 | ||||
-rw-r--r-- | src/util/hash_table.h | 20 | ||||
-rw-r--r-- | src/util/tests/hash_table/destroy_callback.c | 2 | ||||
-rw-r--r-- | src/util/tests/hash_table/insert_and_lookup.c | 2 | ||||
-rw-r--r-- | src/util/tests/hash_table/remove_key.c | 2 | ||||
-rw-r--r-- | src/util/tests/hash_table/replacement.c | 2 |
6 files changed, 57 insertions, 15 deletions
diff --git a/src/util/hash_table.c b/src/util/hash_table.c index 48d59e48431..6bac4a4f68e 100644 --- a/src/util/hash_table.c +++ b/src/util/hash_table.c @@ -555,6 +555,24 @@ _mesa_hash_data(const void *data, size_t size) return XXH32(data, size, 0); } +uint32_t +_mesa_hash_int(const void *key) +{ + return XXH32(key, sizeof(int), 0); +} + +uint32_t +_mesa_hash_uint(const void *key) +{ + return XXH32(key, sizeof(unsigned), 0); +} + +uint32_t +_mesa_hash_u32(const void *key) +{ + return XXH32(key, 4, 0); +} + /** FNV-1a string hash implementation */ uint32_t _mesa_hash_string(const void *_key) @@ -570,6 +588,32 @@ _mesa_hash_string(const void *_key) return hash; } +uint32_t +_mesa_hash_pointer(const void *pointer) +{ + uintptr_t num = (uintptr_t) pointer; + return (uint32_t) ((num >> 2) ^ (num >> 6) ^ (num >> 10) ^ (num >> 14)); +} + +bool +_mesa_key_int_equal(const void *a, const void *b) +{ + return *((const int *)a) == *((const int *)b); +} + +bool +_mesa_key_uint_equal(const void *a, const void *b) +{ + + return *((const unsigned *)a) == *((const unsigned *)b); +} + +bool +_mesa_key_u32_equal(const void *a, const void *b) +{ + return *((const uint32_t *)a) == *((const uint32_t *)b); +} + /** * String compare function for use as the comparison callback in * _mesa_hash_table_create(). diff --git a/src/util/hash_table.h b/src/util/hash_table.h index e2cd889f6da..b1eb9d4e217 100644 --- a/src/util/hash_table.h +++ b/src/util/hash_table.h @@ -109,21 +109,19 @@ _mesa_hash_table_random_entry(struct hash_table *ht, bool (*predicate)(struct hash_entry *entry)); uint32_t _mesa_hash_data(const void *data, size_t size); + +uint32_t _mesa_hash_int(const void *key); +uint32_t _mesa_hash_uint(const void *key); +uint32_t _mesa_hash_u32(const void *key); uint32_t _mesa_hash_string(const void *key); +uint32_t _mesa_hash_pointer(const void *pointer); + +bool _mesa_key_int_equal(const void *a, const void *b); +bool _mesa_key_uint_equal(const void *a, const void *b); +bool _mesa_key_u32_equal(const void *a, const void *b); bool _mesa_key_string_equal(const void *a, const void *b); bool _mesa_key_pointer_equal(const void *a, const void *b); -static inline uint32_t _mesa_key_hash_string(const void *key) -{ - return _mesa_hash_string((const char *)key); -} - -static inline uint32_t _mesa_hash_pointer(const void *pointer) -{ - uintptr_t num = (uintptr_t) pointer; - return (uint32_t) ((num >> 2) ^ (num >> 6) ^ (num >> 10) ^ (num >> 14)); -} - struct hash_table * _mesa_pointer_hash_table_create(void *mem_ctx); diff --git a/src/util/tests/hash_table/destroy_callback.c b/src/util/tests/hash_table/destroy_callback.c index 3a050ff2ae2..e6c7ac5c16f 100644 --- a/src/util/tests/hash_table/destroy_callback.c +++ b/src/util/tests/hash_table/destroy_callback.c @@ -56,7 +56,7 @@ main(int argc, char **argv) (void) argc; (void) argv; - ht = _mesa_hash_table_create(NULL, _mesa_key_hash_string, + ht = _mesa_hash_table_create(NULL, _mesa_hash_string, _mesa_key_string_equal); _mesa_hash_table_insert(ht, str1, NULL); diff --git a/src/util/tests/hash_table/insert_and_lookup.c b/src/util/tests/hash_table/insert_and_lookup.c index 1fd7353689f..f1244649053 100644 --- a/src/util/tests/hash_table/insert_and_lookup.c +++ b/src/util/tests/hash_table/insert_and_lookup.c @@ -43,7 +43,7 @@ main(int argc, char **argv) (void) argc; (void) argv; - ht = _mesa_hash_table_create(NULL, _mesa_key_hash_string, + ht = _mesa_hash_table_create(NULL, _mesa_hash_string, _mesa_key_string_equal); _mesa_hash_table_insert(ht, str1, NULL); diff --git a/src/util/tests/hash_table/remove_key.c b/src/util/tests/hash_table/remove_key.c index 6df6d7d0366..1abc68dfc90 100644 --- a/src/util/tests/hash_table/remove_key.c +++ b/src/util/tests/hash_table/remove_key.c @@ -40,7 +40,7 @@ main(int argc, char **argv) (void) argc; (void) argv; - ht = _mesa_hash_table_create(NULL, _mesa_key_hash_string, _mesa_key_string_equal); + ht = _mesa_hash_table_create(NULL, _mesa_hash_string, _mesa_key_string_equal); _mesa_hash_table_insert(ht, str1, NULL); _mesa_hash_table_insert(ht, str2, NULL); diff --git a/src/util/tests/hash_table/replacement.c b/src/util/tests/hash_table/replacement.c index e74e63453c4..a3759a3c93c 100644 --- a/src/util/tests/hash_table/replacement.c +++ b/src/util/tests/hash_table/replacement.c @@ -45,7 +45,7 @@ main(int argc, char **argv) assert(str1 != str2); - ht = _mesa_hash_table_create(NULL, _mesa_key_hash_string, + ht = _mesa_hash_table_create(NULL, _mesa_hash_string, _mesa_key_string_equal); _mesa_hash_table_insert(ht, str1, str1); |