#define VIR_FROM_THIS VIR_FROM_NONE
struct _virBitmap {
- size_t max_bit;
+ size_t nbits;
size_t map_len;
size_t map_alloc;
unsigned long *map;
return NULL;
}
- bitmap->max_bit = size;
+ bitmap->nbits = size;
bitmap->map_len = sz;
bitmap->map_alloc = sz;
return bitmap;
int virBitmapCopy(virBitmapPtr dst, virBitmapPtr src)
{
- if (dst->max_bit != src->max_bit) {
+ if (dst->nbits != src->nbits) {
errno = EINVAL;
return -1;
}
*/
int virBitmapSetBit(virBitmapPtr bitmap, size_t b)
{
- if (bitmap->max_bit <= b)
+ if (bitmap->nbits <= b)
return -1;
bitmap->map[VIR_BITMAP_UNIT_OFFSET(b)] |= VIR_BITMAP_BIT(b);
return -1;
}
- map->max_bit = b + 1;
+ map->nbits = b + 1;
map->map_len = new_len;
return 0;
*/
int virBitmapSetBitExpand(virBitmapPtr bitmap, size_t b)
{
- if (bitmap->max_bit <= b && virBitmapExpand(bitmap, b) < 0)
+ if (bitmap->nbits <= b && virBitmapExpand(bitmap, b) < 0)
return -1;
bitmap->map[VIR_BITMAP_UNIT_OFFSET(b)] |= VIR_BITMAP_BIT(b);
*/
int virBitmapClearBit(virBitmapPtr bitmap, size_t b)
{
- if (bitmap->max_bit <= b)
+ if (bitmap->nbits <= b)
return -1;
bitmap->map[VIR_BITMAP_UNIT_OFFSET(b)] &= ~VIR_BITMAP_BIT(b);
*/
int virBitmapClearBitExpand(virBitmapPtr bitmap, size_t b)
{
- if (bitmap->max_bit <= b) {
+ if (bitmap->nbits <= b) {
if (virBitmapExpand(bitmap, b) < 0)
return -1;
} else {
}
-/* Helper function. caller must ensure b < bitmap->max_bit */
+/* Helper function. caller must ensure b < bitmap->nbits */
static bool virBitmapIsSet(virBitmapPtr bitmap, size_t b)
{
return !!(bitmap->map[VIR_BITMAP_UNIT_OFFSET(b)] & VIR_BITMAP_BIT(b));
*/
bool virBitmapIsBitSet(virBitmapPtr bitmap, size_t b)
{
- if (bitmap->max_bit <= b)
+ if (bitmap->nbits <= b)
return false;
return virBitmapIsSet(bitmap, b);
*/
int virBitmapGetBit(virBitmapPtr bitmap, size_t b, bool *result)
{
- if (bitmap->max_bit <= b)
+ if (bitmap->nbits <= b)
return -1;
*result = virBitmapIsSet(bitmap, b);
if (!trim)
return ret;
- if (bitmap->max_bit != bitmap->map_len * VIR_BITMAP_BITS_PER_UNIT) {
+ if (bitmap->nbits != bitmap->map_len * VIR_BITMAP_BITS_PER_UNIT) {
char *tmp = ret;
if (prefix)
tmp += 2;
len = strlen(tmp);
- sz = VIR_DIV_UP(bitmap->max_bit, 4);
+ sz = VIR_DIV_UP(bitmap->nbits, 4);
diff = len - sz;
if (diff)
{
virBitmapPtr dst;
- if ((dst = virBitmapNew(src->max_bit)) == NULL)
+ if ((dst = virBitmapNew(src->nbits)) == NULL)
return NULL;
if (virBitmapCopy(dst, src) != 0) {
if (!b1 || !b2)
return false;
- if (b1->max_bit > b2->max_bit) {
+ if (b1->nbits > b2->nbits) {
tmp = b1;
b1 = b2;
b2 = tmp;
size_t virBitmapSize(virBitmapPtr bitmap)
{
- return bitmap->max_bit;
+ return bitmap->nbits;
}
/**
*/
void virBitmapSetAll(virBitmapPtr bitmap)
{
- int tail = bitmap->max_bit % VIR_BITMAP_BITS_PER_UNIT;
+ int tail = bitmap->nbits % VIR_BITMAP_BITS_PER_UNIT;
memset(bitmap->map, 0xff,
bitmap->map_len * (VIR_BITMAP_BITS_PER_UNIT / CHAR_BIT));
int unusedBits;
size_t sz;
- unusedBits = bitmap->map_len * VIR_BITMAP_BITS_PER_UNIT - bitmap->max_bit;
+ unusedBits = bitmap->map_len * VIR_BITMAP_BITS_PER_UNIT - bitmap->nbits;
sz = bitmap->map_len;
if (unusedBits > 0)
pos++;
- if (pos >= bitmap->max_bit)
+ if (pos >= bitmap->nbits)
return -1;
nl = pos / VIR_BITMAP_BITS_PER_UNIT;
if (bitmap->map_len == 0)
return -1;
- unusedBits = bitmap->map_len * VIR_BITMAP_BITS_PER_UNIT - bitmap->max_bit;
+ unusedBits = bitmap->map_len * VIR_BITMAP_BITS_PER_UNIT - bitmap->nbits;
sz = bitmap->map_len - 1;
if (unusedBits > 0) {
pos++;
- if (pos >= bitmap->max_bit)
+ if (pos >= bitmap->nbits)
return -1;
nl = pos / VIR_BITMAP_BITS_PER_UNIT;
if (nl == bitmap->map_len - 1) {
/* Ensure tail bits are ignored. */
- int tail = bitmap->max_bit % VIR_BITMAP_BITS_PER_UNIT;
+ int tail = bitmap->nbits % VIR_BITMAP_BITS_PER_UNIT;
if (tail)
bits &= -1UL >> (VIR_BITMAP_BITS_PER_UNIT - tail);
{
size_t i;
- if (b1->max_bit > b2->max_bit) {
+ if (b1->nbits > b2->nbits) {
virBitmapPtr tmp = b1;
b1 = b2;
b2 = tmp;
if (!map)
return 0;
- if (map->max_bit >= b)
- map->max_bit = b;
+ if (map->nbits >= b)
+ map->nbits = b;
- nl = map->max_bit / VIR_BITMAP_BITS_PER_UNIT;
- nb = map->max_bit % VIR_BITMAP_BITS_PER_UNIT;
+ nl = map->nbits / VIR_BITMAP_BITS_PER_UNIT;
+ nb = map->nbits % VIR_BITMAP_BITS_PER_UNIT;
map->map[nl] &= ((1UL << nb) - 1);
nl++;