[libvirt] [PATCHv3 1/4] bitmap: add virBitmapCountBits
Viktor Mihajlovski
mihajlov at linux.vnet.ibm.com
Thu Oct 25 14:35:04 UTC 2012
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
More information about the libvir-list
mailing list