/*
- * Copyrigth (C) 1995-2007 University of Karlsruhe. All right reserved.
+ * Copyright (C) 1995-2007 University of Karlsruhe. All right reserved.
*
* This file is part of libFirm.
*
/**
* @file
- * @date 15.10.2004
- * @author Sebastian Hack
- * @brief A bitset implementation.
+ * @brief A bitset implementation.
+ * @author Sebastian Hack
+ * @date 15.10.2004
+ * @version $Id$
*/
#ifndef FIRM_ADT_BITSET_H
#define FIRM_ADT_BITSET_H
* @param bs The bitset.
* @return The number of bits set in the bitset.
*/
-static INLINE bitset_pos_t bitset_popcnt(const bitset_t *bs)
+static INLINE unsigned bitset_popcnt(const bitset_t *bs)
{
- bitset_pos_t i, pop = 0;
+ bitset_pos_t i;
bitset_unit_t *unit;
+ unsigned pop = 0;
- for(i = 0, unit = bs->data; i < bs->units; ++i, ++unit)
+ for (i = 0, unit = bs->data; i < bs->units; ++i, ++unit)
pop += _bitset_inside_pop(unit);
return pop;
#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)
+{
+ bitset_pos_t n = a->units < b->units ? a->units : b->units;
+ bitset_pos_t 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)
+{
+ bitset_pos_t 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.
fprintf(file, " " BITSET_UNIT_FMT, bs->data[i]);
}
+/**
+ * Perform tgt = tgt \ src operation.
+ * @param tgt The target bitset.
+ * @param src The source bitset.
+ * @return the tgt set.
+ */
+static INLINE bitset_t *bitset_andnot(bitset_t *tgt, const bitset_t *src);
+
+/**
+ * Perform Union, tgt = tgt u src operation.
+ * @param tgt The target bitset.
+ * @param src The source bitset.
+ * @return the tgt set.
+ */
+static INLINE bitset_t *bitset_or(bitset_t *tgt, const bitset_t *src);
+
+/**
+ * Perform tgt = tgt ^ ~src operation.
+ * @param tgt The target bitset.
+ * @param src The source bitset.
+ * @return the tgt set.
+ */
+static INLINE bitset_t *bitset_xor(bitset_t *tgt, const bitset_t *src);
+
/*
* Here, the binary operations follow.
* And, Or, And Not, Xor are available.