This internal API just checks if two bitmaps intersect or not. Signed-off-by: Michal Privoznik <mprivozn@xxxxxxxxxx> --- Notes: This has been ACKed already, but the name of the function was not quite right. But there's no functional change since then. src/libvirt_private.syms | 1 + src/util/virbitmap.c | 20 ++++++++++++++++++++ src/util/virbitmap.h | 3 +++ tests/virbitmaptest.c | 26 ++++++++++++++++++++++++++ 4 files changed, 50 insertions(+) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index c928564..8b50417 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1005,6 +1005,7 @@ virBitmapNewCopy; virBitmapNewData; virBitmapNextClearBit; virBitmapNextSetBit; +virBitmapOverlaps; virBitmapParse; virBitmapSetAll; virBitmapSetBit; diff --git a/src/util/virbitmap.c b/src/util/virbitmap.c index 1029635..27282df 100644 --- a/src/util/virbitmap.c +++ b/src/util/virbitmap.c @@ -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; +} diff --git a/src/util/virbitmap.h b/src/util/virbitmap.h index 142a218..4493cc9 100644 --- a/src/util/virbitmap.h +++ b/src/util/virbitmap.h @@ -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 diff --git a/tests/virbitmaptest.c b/tests/virbitmaptest.c index 048946f..ea832ad 100644 --- a/tests/virbitmaptest.c +++ b/tests/virbitmaptest.c @@ -510,6 +510,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) { int ret = 0; @@ -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; } -- 1.8.5.5 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list