From c449a8a2c1b16b7eaa95fabd519efcf2f94c8a82 Mon Sep 17 00:00:00 2001 From: Mike Blumenkrantz Date: Sat, 1 May 2021 15:08:31 -0400 Subject: [PATCH] util/hash_table: _mesa_hash_table_create_u32_keys() Reviewed-by: Erik Faye-Lund Part-of: --- src/util/hash_table.c | 20 ++++++++++++++++++++ src/util/hash_table.h | 3 +++ 2 files changed, 23 insertions(+) diff --git a/src/util/hash_table.c b/src/util/hash_table.c index a0cebdb250b..1811ee7432f 100644 --- a/src/util/hash_table.c +++ b/src/util/hash_table.c @@ -191,6 +191,26 @@ _mesa_hash_table_create(void *mem_ctx, return ht; } +static uint32_t +key_u32_hash(const void *key) +{ + uint32_t u = (uint32_t)(uintptr_t)key; + return _mesa_hash_uint(&u); +} + +static bool +key_u32_equals(const void *a, const void *b) +{ + return (uint32_t)(uintptr_t)a == (uint32_t)(uintptr_t)b; +} + +/* key == 0 and key == deleted_key are not allowed */ +struct hash_table * +_mesa_hash_table_create_u32_keys(void *mem_ctx) +{ + return _mesa_hash_table_create(mem_ctx, key_u32_hash, key_u32_equals); +} + struct hash_table * _mesa_hash_table_clone(struct hash_table *src, void *dst_mem_ctx) { diff --git a/src/util/hash_table.h b/src/util/hash_table.h index b61721a5df8..8079d102d4b 100644 --- a/src/util/hash_table.h +++ b/src/util/hash_table.h @@ -72,6 +72,9 @@ _mesa_hash_table_init(struct hash_table *ht, bool (*key_equals_function)(const void *a, const void *b)); +struct hash_table * +_mesa_hash_table_create_u32_keys(void *mem_ctx); + struct hash_table * _mesa_hash_table_clone(struct hash_table *src, void *dst_mem_ctx); void _mesa_hash_table_destroy(struct hash_table *ht,