util/set: add _mesa_set_intersects
[mesa.git] / src / util / set.c
index 5173c24474c972afa9365b9d81737891f321e501..a9012b4e6d4c6407cbf0d2a70a77d30b32feda58 100644 (file)
@@ -92,7 +92,7 @@ static const struct {
    ENTRY(2147483648ul, 2362232233ul, 2362232231ul )
 };
 
-static inline bool
+ASSERTED static inline bool
 key_pointer_is_reserved(const void *key)
 {
    return key == NULL || key == deleted_key;
@@ -570,3 +570,23 @@ _mesa_pointer_set_create(void *mem_ctx)
    return _mesa_set_create(mem_ctx, _mesa_hash_pointer,
                            _mesa_key_pointer_equal);
 }
+
+bool
+_mesa_set_intersects(struct set *a, struct set *b)
+{
+   assert(a->key_hash_function == b->key_hash_function);
+   assert(a->key_equals_function == b->key_equals_function);
+
+   /* iterate over the set with less entries */
+   if (b->entries < a->entries) {
+      struct set *tmp = a;
+      a = b;
+      b = tmp;
+   }
+
+   set_foreach(a, entry) {
+      if (_mesa_set_search_pre_hashed(b, entry->hash, entry->key))
+         return true;
+   }
+   return false;
+}