#include "firm_config.h"
#include "bitfiddle.h"
+#ifdef _WIN32
+#include <malloc.h>
+#else
+#include <alloca.h>
+#endif
+
typedef unsigned int bitset_pos_t;
#include "bitset_std.h"
bitset_t *ptr = area;
memset(area, 0, _bitset_overall_size(sizeof(bitset_t), size));
ptr->units = _bitset_units(size);
- ptr->size = size;
+ ptr->size = size;
ptr->data = _bitset_data_ptr(area, sizeof(bitset_t), size);
return ptr;
}
*/
static INLINE bitset_t *_bitset_mask_highest(bitset_t *bs)
{
- bs->data[bs->units - 1] &= (bs->size & BS_UNIT_MASK) - 1;
- return bs;
+ bitset_pos_t rest = bs->size & BS_UNIT_MASK;
+ if (rest)
+ bs->data[bs->units - 1] &= (1 << rest) - 1;
+ return bs;
}
/**
* @param bs The bitset.
* @return The highest bit which can be set or cleared plus 1.
*/
-#define bistet_size(bs) ((bs)->size)
+#define bitset_size(bs) ((bs)->size)
/**
* Allocate a bitset on an obstack.
* @return A pointer to an empty initialized bitset.
*/
#define bitset_malloc(size) \
- _bitset_prepare(malloc(_bitset_overall_size(sizeof(bitset_t), size)), size)
+ _bitset_prepare(xmalloc(_bitset_overall_size(sizeof(bitset_t), size)), size)
/**
* Free a bitset allocated with bitset_malloc().
_bitset_inside_flip(unit, bit & BS_UNIT_MASK);
}
+/**
+ * Flip the whole bitset.
+ * @param bs The bitset.
+ */
+static INLINE void bitset_flip_all(bitset_t *bs)
+{
+ bitset_pos_t i;
+ for(i = 0; i < bs->units; i++)
+ _bitset_inside_flip_unit(&bs->data[i]);
+ _bitset_mask_highest(bs);
+}
+
/**
* Copy a bitset to another.
* @param tgt The target bitset.
{
bitset_pos_t unit_number = pos / BS_UNIT_SIZE_BITS;
- if(unit_number >= bs->units)
+ if(pos >= bs->size)
return -1;
{
*/
static INLINE bitset_t *bitset_set_all(bitset_t *bs)
{
- memset(bs->data, -1, BS_UNIT_SIZE * bs->units);
- return bs;
+ memset(bs->data, -1, bs->units * BS_UNIT_SIZE);
+ return _bitset_mask_highest(bs);
}
/**