util/hash_table: _mesa_hash_table_create_u32_keys()
authorMike Blumenkrantz <michael.blumenkrantz@gmail.com>
Sat, 1 May 2021 19:08:31 +0000 (15:08 -0400)
committerMarge Bot <eric+marge@anholt.net>
Fri, 7 May 2021 13:14:08 +0000 (13:14 +0000)
Reviewed-by: Erik Faye-Lund <erik.faye-lund@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/10673>

src/util/hash_table.c
src/util/hash_table.h

index a0cebdb..1811ee7 100644 (file)
@@ -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)
 {
index b61721a..8079d10 100644 (file)
@@ -73,6 +73,9 @@ _mesa_hash_table_init(struct hash_table *ht,
                                                   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,
                               void (*delete_function)(struct hash_entry *entry));