mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-22 05:35:25 +00:00
virbitmap: Introduce virBitmapOverlaps
This internal API just checks if two bitmaps intersect or not. Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
parent
725a211fc0
commit
49baed2b29
@ -1005,6 +1005,7 @@ virBitmapNewCopy;
|
||||
virBitmapNewData;
|
||||
virBitmapNextClearBit;
|
||||
virBitmapNextSetBit;
|
||||
virBitmapOverlaps;
|
||||
virBitmapParse;
|
||||
virBitmapSetAll;
|
||||
virBitmapSetBit;
|
||||
|
@ -732,3 +732,23 @@ virBitmapDataToString(void *data,
|
||||
virBitmapFree(map);
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool
|
||||
virBitmapOverlaps(virBitmapPtr b1,
|
||||
virBitmapPtr b2)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
if (b1->max_bit > b2->max_bit) {
|
||||
virBitmapPtr tmp = b1;
|
||||
b1 = b2;
|
||||
b2 = tmp;
|
||||
}
|
||||
|
||||
for (i = 0; i < b1->map_len; i++) {
|
||||
if (b1->map[i] & b2->map[i])
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
@ -114,5 +114,8 @@ size_t virBitmapCountBits(virBitmapPtr bitmap)
|
||||
char *virBitmapDataToString(void *data,
|
||||
int len)
|
||||
ATTRIBUTE_NONNULL(1);
|
||||
bool virBitmapOverlaps(virBitmapPtr b1,
|
||||
virBitmapPtr b2)
|
||||
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
|
||||
|
||||
#endif
|
||||
|
@ -509,6 +509,30 @@ test9(const void *opaque ATTRIBUTE_UNUSED)
|
||||
|
||||
}
|
||||
|
||||
static int
|
||||
test10(const void *opaque ATTRIBUTE_UNUSED)
|
||||
{
|
||||
int ret = -1;
|
||||
virBitmapPtr b1 = NULL, b2 = NULL, b3 = NULL;
|
||||
|
||||
if (virBitmapParse("0-3,5-8,11-15", 0, &b1, 20) < 0 ||
|
||||
virBitmapParse("4,9,10,16-19", 0, &b2, 20) < 0 ||
|
||||
virBitmapParse("15", 0, &b3, 20) < 0)
|
||||
goto cleanup;
|
||||
|
||||
if (virBitmapOverlaps(b1, b2) ||
|
||||
virBitmapOverlaps(b2, b3) ||
|
||||
!virBitmapOverlaps(b1, b3))
|
||||
goto cleanup;
|
||||
|
||||
ret = 0;
|
||||
cleanup:
|
||||
virBitmapFree(b1);
|
||||
virBitmapFree(b2);
|
||||
virBitmapFree(b3);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int
|
||||
mymain(void)
|
||||
{
|
||||
@ -532,6 +556,8 @@ mymain(void)
|
||||
ret = -1;
|
||||
if (virtTestRun("test9", test9, NULL) < 0)
|
||||
ret = -1;
|
||||
if (virtTestRun("test10", test10, NULL) < 0)
|
||||
ret = -1;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user