[libvirt] [PATCH v4 1/3] bitmap: add virBitmapLastSetBit for finding the last bit position of bitmap

Chen, Fan chen.fan.fnst at cn.fujitsu.com
Tue Nov 4 01:27:12 UTC 2014


On Mon, 2014-11-03 at 14:18 +0100, Martin Kletzander wrote: 
> On Thu, Oct 30, 2014 at 01:44:17PM +0800, Chen Fan wrote:
> >Signed-off-by: Chen Fan <chen.fan.fnst at cn.fujitsu.com>
> >---
> > src/libvirt_private.syms |  1 +
> > src/util/virbitmap.c     | 45 +++++++++++++++++++++++++++++++++++++++++++++
> > src/util/virbitmap.h     |  3 +++
> > tests/virbitmaptest.c    | 13 ++++++++++++-
> > 4 files changed, 61 insertions(+), 1 deletion(-)
> >
> >diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
> >index d63a8f0..1e2bc0a 100644
> >--- a/src/libvirt_private.syms
> >+++ b/src/libvirt_private.syms
> >@@ -1011,6 +1011,7 @@ virBitmapFree;
> > virBitmapGetBit;
> > virBitmapIsAllClear;
> > virBitmapIsAllSet;
> >+virBitmapLastSetBit;
> > virBitmapNew;
> > virBitmapNewCopy;
> > virBitmapNewData;
> >diff --git a/src/util/virbitmap.c b/src/util/virbitmap.c
> >index b6bd074..3e7269e 100644
> >--- a/src/util/virbitmap.c
> >+++ b/src/util/virbitmap.c
> >@@ -651,6 +651,51 @@ virBitmapNextSetBit(virBitmapPtr bitmap, ssize_t pos)
> > }
> >
> > /**
> >+ * virBitmapLastSetBit:
> >+ * @bitmap: the bitmap
> >+ *
> >+ * Search for the last set bit in bitmap @bitmap.
> >+ *
> >+ * Returns the position of the found bit, or -1 if no bit found.
> 
> s/found/is set/
> 
> >+ */
> >+ssize_t
> >+virBitmapLastSetBit(virBitmapPtr bitmap)
> >+{
> >+    ssize_t i;
> >+    int unusedBits;
> >+    ssize_t sz;
> >+    unsigned long bits;
> >+
> >+    unusedBits = bitmap->map_len * VIR_BITMAP_BITS_PER_UNIT - bitmap->max_bit;
> >+
> >+    sz = bitmap->map_len - 1;
> >+    if (unusedBits > 0) {
> >+        bits = bitmap->map[sz] & (VIR_BITMAP_BIT(VIR_BITMAP_BITS_PER_UNIT - unusedBits) - 1);
> >+        if (bits != 0)
> >+            goto found;
> >+
> >+        sz--;
> >+    }
> >+
> >+    for (; sz >= 0; sz--) {
> >+        bits = bitmap->map[sz];
> >+        if (bits != 0)
> >+            goto found;
> >+    }
> >+
> >+    if (bits == 0)
> >+        return -1;
> >+
> >+found:
> 
> Missing space before label.  "make syntax-check" would tell you that
> instead of me ;)

Thanks for your remind. I will do that.

Chen





More information about the libvir-list mailing list