util: add _mesa_set_create_u32_keys where keys are not pointers
the only limitation is that key=0 is not allowed
Reviewed-by: Timothy Arceri <tarceri@itsqueeze.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6955>
diff --git a/src/util/set.c b/src/util/set.c
index a9012b4..006d5d2 100644
--- a/src/util/set.c
+++ b/src/util/set.c
@@ -148,6 +148,26 @@
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 set *
+_mesa_set_create_u32_keys(void *mem_ctx)
+{
+ return _mesa_set_create(NULL, key_u32_hash, key_u32_equals);
+}
+
struct set *
_mesa_set_clone(struct set *set, void *dst_mem_ctx)
{
diff --git a/src/util/set.h b/src/util/set.h
index 2e0a2d6..1836864 100644
--- a/src/util/set.h
+++ b/src/util/set.h
@@ -61,6 +61,9 @@
bool (*key_equals_function)(const void *a,
const void *b));
struct set *
+_mesa_set_create_u32_keys(void *mem_ctx);
+
+struct set *
_mesa_set_clone(struct set *set, void *dst_mem_ctx);
void