From eb8dbc2bbf00ee96c3f7ccd8c3704e7c5ea1fa52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Ol=C5=A1=C3=A1k?= Date: Mon, 27 Apr 2026 21:07:21 -0400 Subject: [PATCH] util/set: add helper _mesa_set_equal --- src/util/set.c | 22 ++++++++++++++++++++++ src/util/set.h | 3 +++ 2 files changed, 25 insertions(+) diff --git a/src/util/set.c b/src/util/set.c index d6c06235a3c..6c478ca34e2 100644 --- a/src/util/set.c +++ b/src/util/set.c @@ -700,3 +700,25 @@ _mesa_set_intersects(struct set *a, struct set *b) } return false; } + +bool +_mesa_set_equal(const struct set *a, const struct set *b) +{ + assert(a->key_hash_function == b->key_hash_function); + assert(a->key_equals_function == b->key_equals_function); + + if (a->entries != b->entries) + return false; + + set_foreach(a, entry) { + if (!_mesa_set_search_pre_hashed(b, entry->hash, entry->key)) + return false; + } + + set_foreach(b, entry) { + if (!_mesa_set_search_pre_hashed(a, entry->hash, entry->key)) + return false; + } + + return true; +} diff --git a/src/util/set.h b/src/util/set.h index 13cbb794d09..76c4e8ea2cb 100644 --- a/src/util/set.h +++ b/src/util/set.h @@ -142,6 +142,9 @@ _mesa_pointer_set_create(void *mem_ctx); bool _mesa_set_intersects(struct set *a, struct set *b); +bool +_mesa_set_equal(const struct set *a, const struct set *b); + /** * This foreach function is safe against deletion, but not against * insertion (which may rehash the set, making entry a dangling