return -1;
}
+
+static int count_bits_in_word(unsigned int word)
+{
+ int i = 0;
+ while (word)
+ {
+ if (word & 1)
+ i++;
+ word >>= 1;
+ }
+ return i;
+}
+
+int bitmap_count_set_bits(unsigned int* bitmap, int size)
+{
+ int word;
+ int words = ((size-1) / BITS_PER_WORD) + 1;
+ int count = 0;
+
+ for (word=0; word<words; word++)
+ {
+ unsigned int w = bitmap[word];
+ count += count_bits_in_word(w);
+ }
+
+ return count;
+}
extern void bitmap_and(unsigned int* dest, int size, unsigned int* src);
extern void bitmap_or(unsigned int* dest, int size, unsigned int* src);
extern int bitmap_find_unset_bit(unsigned int* bitmap, int size);
+extern int bitmap_count_set_bits(unsigned int* bitmap, int size);
#define BITS_PER_WORD (sizeof(unsigned int)*8)
#define WORDS_FOR_BITMAP_SIZE(n) (((n-1) / BITS_PER_WORD) + 1)