util: bitmap: Modify virBitmapSubtract to virBitmapIntersect

Since virBitmapSubtract is unused modify it to perform bitmap
intersection.
This commit is contained in:
Peter Krempa 2017-07-12 13:30:47 +02:00
parent f4258298d3
commit a908e9e45e
4 changed files with 18 additions and 17 deletions

View File

@ -1298,6 +1298,7 @@ virBitmapEqual;
virBitmapFormat;
virBitmapFree;
virBitmapGetBit;
virBitmapIntersect;
virBitmapIsAllClear;
virBitmapIsAllSet;
virBitmapIsBitSet;
@ -1318,7 +1319,6 @@ virBitmapSetBit;
virBitmapSetBitExpand;
virBitmapSize;
virBitmapString;
virBitmapSubtract;
virBitmapToData;
virBitmapToDataBuf;

View File

@ -1091,15 +1091,15 @@ virBitmapOverlaps(virBitmapPtr b1,
}
/**
* virBitmapSubtract:
* @a: minuend/result
* @b: subtrahend
* virBitmapIntersect:
* @a: bitmap, modified to contain result
* @b: bitmap
*
* Performs bitwise subtraction: a = a - b
* Performs intersection of two bitmaps: a = intersect(a, b)
*/
void
virBitmapSubtract(virBitmapPtr a,
virBitmapPtr b)
virBitmapIntersect(virBitmapPtr a,
virBitmapPtr b)
{
size_t i;
size_t max = a->map_len;
@ -1108,5 +1108,5 @@ virBitmapSubtract(virBitmapPtr a,
max = b->map_len;
for (i = 0; i < max; i++)
a->map[i] &= ~b->map[i];
a->map[i] &= b->map[i];
}

View File

@ -143,7 +143,7 @@ bool virBitmapOverlaps(virBitmapPtr b1,
virBitmapPtr b2)
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
void virBitmapSubtract(virBitmapPtr a, virBitmapPtr b)
void virBitmapIntersect(virBitmapPtr a, virBitmapPtr b)
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
#endif

View File

@ -589,10 +589,11 @@ test11(const void *opaque)
virBitmapParse(data->res, &resmap, 256) < 0)
goto cleanup;
virBitmapSubtract(amap, bmap);
virBitmapIntersect(amap, bmap);
if (!virBitmapEqual(amap, resmap)) {
fprintf(stderr, "\n bitmap subtraction failed: '%s'-'%s'!='%s'\n",
fprintf(stderr,
"\n bitmap intersection failed: intersect('%s','%s') !='%s'\n",
data->a, data->b, data->res);
goto cleanup;
}
@ -700,13 +701,13 @@ mymain(void)
ret = -1;
virTestCounterReset("test11-");
TESTBINARYOP("0", "0", "0,^0", test11);
TESTBINARYOP("0-3", "0", "1-3", test11);
TESTBINARYOP("0-3", "0,3", "1-2", test11);
TESTBINARYOP("0", "0", "0", test11);
TESTBINARYOP("0-3", "0", "0", test11);
TESTBINARYOP("0-3", "0,3", "0,3", test11);
TESTBINARYOP("0,^0", "0", "0,^0", test11);
TESTBINARYOP("0-3", "0-3", "0,^0", test11);
TESTBINARYOP("0-3", "0,^0", "0-3", test11);
TESTBINARYOP("0,2", "1,3", "0,2", test11);
TESTBINARYOP("0-3", "0-3", "0-3", test11);
TESTBINARYOP("0-3", "0,^0", "0,^0", test11);
TESTBINARYOP("0,2", "1,3", "0,^0", test11);
if (virTestRun("test12", test12, NULL) < 0)
ret = -1;