On 10/25/2012 03:36 AM, Eric Blake wrote:
Sometimes it's handy to know how many bits are set. * src/util/bitmap.h (virBitmapCountBits): New prototype. (virBitmapNextSetBit): Use correct type. * src/util/bitmap.c (virBitmapNextSetBit): Likewise. (virBitmapCountBits): New function. * src/libvirt_private.syms (bitmap.h): Export it. * tests/virbitmaptest.c (test2): Test it.
You might want to add a sign-off.
+/* Return the number of bits currently set in the map. */ +size_t +virBitmapCountBits(virBitmapPtr bitmap) +{ + size_t i; + size_t ret = 0; + int tail = bitmap->max_bit % VIR_BITMAP_BITS_PER_UNIT; + + /* Ensure tail bits are clear. */ + if (tail) + bitmap->map[bitmap->map_len - 1] &= + -1UL >> (VIR_BITMAP_BITS_PER_UNIT - tail);
Probably not necessary, as the bitmap is initialized to zero. Works for me. -- Mit freundlichen Grüßen/Kind Regards Viktor Mihajlovski IBM Deutschland Research & Development GmbH Vorsitzender des Aufsichtsrats: Martin Jetter Geschäftsführung: Dirk Wittkopp Sitz der Gesellschaft: Böblingen Registergericht: Amtsgericht Stuttgart, HRB 243294 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list