util/set: add helper _mesa_set_equal

Reviewed-by: Aitor Camacho <aitor@lunarg.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/41329>
This commit is contained in:
Marek Olšák 2026-04-27 21:07:21 -04:00 committed by Marge Bot
parent 52d57d98a2
commit df54208fab
2 changed files with 25 additions and 0 deletions

View file

@ -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;
}

View file

@ -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