Added btset intersection test and a "fast" bitset empty test
authorSebastian Hack <hack@ipd.info.uni-karlsruhe.de>
Thu, 10 May 2007 15:58:28 +0000 (15:58 +0000)
committerSebastian Hack <hack@ipd.info.uni-karlsruhe.de>
Thu, 10 May 2007 15:58:28 +0000 (15:58 +0000)
[r13763]

ir/adt/bitset.h

index 835165b..a68b21d 100644 (file)
@@ -445,6 +445,38 @@ static INLINE void bitset_minus1(bitset_t *bs)
 #undef _SH
 }
 
+/**
+ * Check if two bitsets intersect.
+ * @param a The first bitset.
+ * @param b The second bitset.
+ * @return 1 if they have a bit in common, 0 if not.
+ */
+static INLINE int bitset_intersect(const bitset_t *a, const bitset_t *b)
+{
+       int n = a->units < b->units ? a->units : b->units;
+       int i;
+
+       for (i = 0; i < n; ++i)
+               if (a->data[i] & b->data[i])
+                       return 1;
+
+       return 0;
+}
+
+/**
+ * Check, if a bitset is empty.
+ * @param a The bitset.
+ * @return 1, if the bitset is empty, 0 if not.
+ */
+static INLINE int bitset_is_empty(const bitset_t *a)
+{
+       int i;
+       for (i = 0; i < a->units; ++i)
+               if (a->data[i] != 0)
+                       return 0;
+       return 1;
+}
+
 /**
  * Print a bitset to a stream.
  * The bitset is printed as a comma separated list of bits set.