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