提交 fb549cd5 编写于 作者: P Peter Krempa

util: bitmap: Fix function formatting and spacing

上级 eacc9312
...@@ -136,7 +136,8 @@ virBitmapNewEmpty(void) ...@@ -136,7 +136,8 @@ virBitmapNewEmpty(void)
* *
* Free @bitmap previously allocated by virBitmapNew. * Free @bitmap previously allocated by virBitmapNew.
*/ */
void virBitmapFree(virBitmapPtr bitmap) void
virBitmapFree(virBitmapPtr bitmap)
{ {
if (bitmap) { if (bitmap) {
VIR_FREE(bitmap->map); VIR_FREE(bitmap->map);
...@@ -145,7 +146,9 @@ void virBitmapFree(virBitmapPtr bitmap) ...@@ -145,7 +146,9 @@ void virBitmapFree(virBitmapPtr bitmap)
} }
int virBitmapCopy(virBitmapPtr dst, virBitmapPtr src) int
virBitmapCopy(virBitmapPtr dst,
virBitmapPtr src)
{ {
if (dst->nbits != src->nbits) { if (dst->nbits != src->nbits) {
errno = EINVAL; errno = EINVAL;
...@@ -167,7 +170,9 @@ int virBitmapCopy(virBitmapPtr dst, virBitmapPtr src) ...@@ -167,7 +170,9 @@ int virBitmapCopy(virBitmapPtr dst, virBitmapPtr src)
* *
* Returns 0 on if bit is successfully set, -1 on error. * Returns 0 on if bit is successfully set, -1 on error.
*/ */
int virBitmapSetBit(virBitmapPtr bitmap, size_t b) int
virBitmapSetBit(virBitmapPtr bitmap,
size_t b)
{ {
if (bitmap->nbits <= b) if (bitmap->nbits <= b)
return -1; return -1;
...@@ -176,6 +181,7 @@ int virBitmapSetBit(virBitmapPtr bitmap, size_t b) ...@@ -176,6 +181,7 @@ int virBitmapSetBit(virBitmapPtr bitmap, size_t b)
return 0; return 0;
} }
/** /**
* virBitmapExpand: * virBitmapExpand:
* @map: Pointer to bitmap * @map: Pointer to bitmap
...@@ -186,7 +192,9 @@ int virBitmapSetBit(virBitmapPtr bitmap, size_t b) ...@@ -186,7 +192,9 @@ int virBitmapSetBit(virBitmapPtr bitmap, size_t b)
* *
* Returns 0 on success, -1 on error. * Returns 0 on success, -1 on error.
*/ */
static int virBitmapExpand(virBitmapPtr map, size_t b) static int
virBitmapExpand(virBitmapPtr map,
size_t b)
{ {
size_t new_len = VIR_DIV_UP(b + 1, VIR_BITMAP_BITS_PER_UNIT); size_t new_len = VIR_DIV_UP(b + 1, VIR_BITMAP_BITS_PER_UNIT);
...@@ -214,7 +222,9 @@ static int virBitmapExpand(virBitmapPtr map, size_t b) ...@@ -214,7 +222,9 @@ static int virBitmapExpand(virBitmapPtr map, size_t b)
* *
* Returns 0 on if bit is successfully set, -1 on error. * Returns 0 on if bit is successfully set, -1 on error.
*/ */
int virBitmapSetBitExpand(virBitmapPtr bitmap, size_t b) int
virBitmapSetBitExpand(virBitmapPtr bitmap,
size_t b)
{ {
if (bitmap->nbits <= b && virBitmapExpand(bitmap, b) < 0) if (bitmap->nbits <= b && virBitmapExpand(bitmap, b) < 0)
return -1; return -1;
...@@ -233,7 +243,9 @@ int virBitmapSetBitExpand(virBitmapPtr bitmap, size_t b) ...@@ -233,7 +243,9 @@ int virBitmapSetBitExpand(virBitmapPtr bitmap, size_t b)
* *
* Returns 0 on if bit is successfully clear, -1 on error. * Returns 0 on if bit is successfully clear, -1 on error.
*/ */
int virBitmapClearBit(virBitmapPtr bitmap, size_t b) int
virBitmapClearBit(virBitmapPtr bitmap,
size_t b)
{ {
if (bitmap->nbits <= b) if (bitmap->nbits <= b)
return -1; return -1;
...@@ -253,7 +265,9 @@ int virBitmapClearBit(virBitmapPtr bitmap, size_t b) ...@@ -253,7 +265,9 @@ int virBitmapClearBit(virBitmapPtr bitmap, size_t b)
* *
* Returns 0 on if bit is successfully cleared, -1 on error. * Returns 0 on if bit is successfully cleared, -1 on error.
*/ */
int virBitmapClearBitExpand(virBitmapPtr bitmap, size_t b) int
virBitmapClearBitExpand(virBitmapPtr bitmap,
size_t b)
{ {
if (bitmap->nbits <= b) { if (bitmap->nbits <= b) {
if (virBitmapExpand(bitmap, b) < 0) if (virBitmapExpand(bitmap, b) < 0)
...@@ -267,11 +281,13 @@ int virBitmapClearBitExpand(virBitmapPtr bitmap, size_t b) ...@@ -267,11 +281,13 @@ int virBitmapClearBitExpand(virBitmapPtr bitmap, size_t b)
/* Helper function. caller must ensure b < bitmap->nbits */ /* Helper function. caller must ensure b < bitmap->nbits */
static bool virBitmapIsSet(virBitmapPtr bitmap, size_t b) static bool
virBitmapIsSet(virBitmapPtr bitmap, size_t b)
{ {
return !!(bitmap->map[VIR_BITMAP_UNIT_OFFSET(b)] & VIR_BITMAP_BIT(b)); return !!(bitmap->map[VIR_BITMAP_UNIT_OFFSET(b)] & VIR_BITMAP_BIT(b));
} }
/** /**
* virBitmapIsBitSet: * virBitmapIsBitSet:
* @bitmap: Pointer to bitmap * @bitmap: Pointer to bitmap
...@@ -282,7 +298,9 @@ static bool virBitmapIsSet(virBitmapPtr bitmap, size_t b) ...@@ -282,7 +298,9 @@ static bool virBitmapIsSet(virBitmapPtr bitmap, size_t b)
* If @b is in the range of @bitmap, returns the value of the bit. * If @b is in the range of @bitmap, returns the value of the bit.
* Otherwise false is returned. * Otherwise false is returned.
*/ */
bool virBitmapIsBitSet(virBitmapPtr bitmap, size_t b) bool
virBitmapIsBitSet(virBitmapPtr bitmap,
size_t b)
{ {
if (bitmap->nbits <= b) if (bitmap->nbits <= b)
return false; return false;
...@@ -290,6 +308,7 @@ bool virBitmapIsBitSet(virBitmapPtr bitmap, size_t b) ...@@ -290,6 +308,7 @@ bool virBitmapIsBitSet(virBitmapPtr bitmap, size_t b)
return virBitmapIsSet(bitmap, b); return virBitmapIsSet(bitmap, b);
} }
/** /**
* virBitmapGetBit: * virBitmapGetBit:
* @bitmap: Pointer to bitmap * @bitmap: Pointer to bitmap
...@@ -301,7 +320,10 @@ bool virBitmapIsBitSet(virBitmapPtr bitmap, size_t b) ...@@ -301,7 +320,10 @@ bool virBitmapIsBitSet(virBitmapPtr bitmap, size_t b)
* On success, @result will contain the setting of @b and 0 is * On success, @result will contain the setting of @b and 0 is
* returned. On failure, -1 is returned and @result is unchanged. * returned. On failure, -1 is returned and @result is unchanged.
*/ */
int virBitmapGetBit(virBitmapPtr bitmap, size_t b, bool *result) int
virBitmapGetBit(virBitmapPtr bitmap,
size_t b,
bool *result)
{ {
if (bitmap->nbits <= b) if (bitmap->nbits <= b)
return -1; return -1;
...@@ -310,6 +332,7 @@ int virBitmapGetBit(virBitmapPtr bitmap, size_t b, bool *result) ...@@ -310,6 +332,7 @@ int virBitmapGetBit(virBitmapPtr bitmap, size_t b, bool *result)
return 0; return 0;
} }
/** /**
* virBitmapToString: * virBitmapToString:
* @bitmap: Pointer to bitmap * @bitmap: Pointer to bitmap
...@@ -367,6 +390,7 @@ virBitmapToString(virBitmapPtr bitmap, ...@@ -367,6 +390,7 @@ virBitmapToString(virBitmapPtr bitmap,
return ret; return ret;
} }
/** /**
* virBitmapFormat: * virBitmapFormat:
* @bitmap: the bitmap * @bitmap: the bitmap
...@@ -381,7 +405,8 @@ virBitmapToString(virBitmapPtr bitmap, ...@@ -381,7 +405,8 @@ virBitmapToString(virBitmapPtr bitmap,
* Returns the string on success or NULL otherwise. Caller should call * Returns the string on success or NULL otherwise. Caller should call
* VIR_FREE to free the string. * VIR_FREE to free the string.
*/ */
char *virBitmapFormat(virBitmapPtr bitmap) char *
virBitmapFormat(virBitmapPtr bitmap)
{ {
virBuffer buf = VIR_BUFFER_INITIALIZER; virBuffer buf = VIR_BUFFER_INITIALIZER;
bool first = true; bool first = true;
...@@ -426,6 +451,7 @@ char *virBitmapFormat(virBitmapPtr bitmap) ...@@ -426,6 +451,7 @@ char *virBitmapFormat(virBitmapPtr bitmap)
return virBufferContentAndReset(&buf); return virBufferContentAndReset(&buf);
} }
/** /**
* virBitmapParseSeparator: * virBitmapParseSeparator:
* @str: points to a string representing a human-readable bitmap * @str: points to a string representing a human-readable bitmap
...@@ -546,6 +572,7 @@ virBitmapParseSeparator(const char *str, ...@@ -546,6 +572,7 @@ virBitmapParseSeparator(const char *str,
return -1; return -1;
} }
/** /**
* virBitmapParse: * virBitmapParse:
* @str: points to a string representing a human-readable bitmap * @str: points to a string representing a human-readable bitmap
...@@ -569,6 +596,7 @@ virBitmapParse(const char *str, ...@@ -569,6 +596,7 @@ virBitmapParse(const char *str,
return virBitmapParseSeparator(str, '\0', bitmap, bitmapSize); return virBitmapParseSeparator(str, '\0', bitmap, bitmapSize);
} }
/** /**
* virBitmapParseUnlimited: * virBitmapParseUnlimited:
* @str: points to a string representing a human-readable bitmap * @str: points to a string representing a human-readable bitmap
...@@ -679,6 +707,7 @@ virBitmapParseUnlimited(const char *str) ...@@ -679,6 +707,7 @@ virBitmapParseUnlimited(const char *str)
return NULL; return NULL;
} }
/** /**
* virBitmapNewCopy: * virBitmapNewCopy:
* @src: the source bitmap. * @src: the source bitmap.
...@@ -688,7 +717,8 @@ virBitmapParseUnlimited(const char *str) ...@@ -688,7 +717,8 @@ virBitmapParseUnlimited(const char *str)
* returns the copied bitmap on success, or NULL otherwise. Caller * returns the copied bitmap on success, or NULL otherwise. Caller
* should call virBitmapFree to free the returned bitmap. * should call virBitmapFree to free the returned bitmap.
*/ */
virBitmapPtr virBitmapNewCopy(virBitmapPtr src) virBitmapPtr
virBitmapNewCopy(virBitmapPtr src)
{ {
virBitmapPtr dst; virBitmapPtr dst;
...@@ -703,6 +733,7 @@ virBitmapPtr virBitmapNewCopy(virBitmapPtr src) ...@@ -703,6 +733,7 @@ virBitmapPtr virBitmapNewCopy(virBitmapPtr src)
return dst; return dst;
} }
/** /**
* virBitmapNewData: * virBitmapNewData:
* @data: the data * @data: the data
...@@ -714,7 +745,9 @@ virBitmapPtr virBitmapNewCopy(virBitmapPtr src) ...@@ -714,7 +745,9 @@ virBitmapPtr virBitmapNewCopy(virBitmapPtr src)
* Returns a pointer to the allocated bitmap or NULL if * Returns a pointer to the allocated bitmap or NULL if
* memory cannot be allocated. * memory cannot be allocated.
*/ */
virBitmapPtr virBitmapNewData(const void *data, int len) virBitmapPtr
virBitmapNewData(const void *data,
int len)
{ {
virBitmapPtr bitmap; virBitmapPtr bitmap;
size_t i, j; size_t i, j;
...@@ -738,6 +771,7 @@ virBitmapPtr virBitmapNewData(const void *data, int len) ...@@ -738,6 +771,7 @@ virBitmapPtr virBitmapNewData(const void *data, int len)
return bitmap; return bitmap;
} }
/** /**
* virBitmapToData: * virBitmapToData:
* @data: the data * @data: the data
...@@ -749,7 +783,10 @@ virBitmapPtr virBitmapNewData(const void *data, int len) ...@@ -749,7 +783,10 @@ virBitmapPtr virBitmapNewData(const void *data, int len)
* *
* Returns 0 on success, -1 otherwise. * Returns 0 on success, -1 otherwise.
*/ */
int virBitmapToData(virBitmapPtr bitmap, unsigned char **data, int *dataLen) int
virBitmapToData(virBitmapPtr bitmap,
unsigned char **data,
int *dataLen)
{ {
ssize_t len; ssize_t len;
...@@ -768,6 +805,7 @@ int virBitmapToData(virBitmapPtr bitmap, unsigned char **data, int *dataLen) ...@@ -768,6 +805,7 @@ int virBitmapToData(virBitmapPtr bitmap, unsigned char **data, int *dataLen)
return 0; return 0;
} }
/** /**
* virBitmapToDataBuf: * virBitmapToDataBuf:
* @bytes: pointer to memory to fill * @bytes: pointer to memory to fill
...@@ -777,9 +815,10 @@ int virBitmapToData(virBitmapPtr bitmap, unsigned char **data, int *dataLen) ...@@ -777,9 +815,10 @@ int virBitmapToData(virBitmapPtr bitmap, unsigned char **data, int *dataLen)
* Data consists of sequential bytes, with lower bytes containing * Data consists of sequential bytes, with lower bytes containing
* lower bits. * lower bits.
*/ */
void virBitmapToDataBuf(virBitmapPtr bitmap, void
unsigned char *bytes, virBitmapToDataBuf(virBitmapPtr bitmap,
size_t len) unsigned char *bytes,
size_t len)
{ {
unsigned long *l; unsigned long *l;
size_t i, j; size_t i, j;
...@@ -797,6 +836,7 @@ void virBitmapToDataBuf(virBitmapPtr bitmap, ...@@ -797,6 +836,7 @@ void virBitmapToDataBuf(virBitmapPtr bitmap,
} }
} }
/** /**
* virBitmapEqual: * virBitmapEqual:
* @b1: bitmap 1 * @b1: bitmap 1
...@@ -807,7 +847,9 @@ void virBitmapToDataBuf(virBitmapPtr bitmap, ...@@ -807,7 +847,9 @@ void virBitmapToDataBuf(virBitmapPtr bitmap,
* Returns true if two bitmaps have exactly the same set of bits set, * Returns true if two bitmaps have exactly the same set of bits set,
* otherwise false. * otherwise false.
*/ */
bool virBitmapEqual(virBitmapPtr b1, virBitmapPtr b2) bool
virBitmapEqual(virBitmapPtr b1,
virBitmapPtr b2)
{ {
virBitmapPtr tmp; virBitmapPtr tmp;
size_t i; size_t i;
...@@ -839,11 +881,14 @@ bool virBitmapEqual(virBitmapPtr b1, virBitmapPtr b2) ...@@ -839,11 +881,14 @@ bool virBitmapEqual(virBitmapPtr b1, virBitmapPtr b2)
return true; return true;
} }
size_t virBitmapSize(virBitmapPtr bitmap)
size_t
virBitmapSize(virBitmapPtr bitmap)
{ {
return bitmap->nbits; return bitmap->nbits;
} }
/** /**
* virBitmapSetAll: * virBitmapSetAll:
* @bitmap: the bitmap * @bitmap: the bitmap
...@@ -863,25 +908,29 @@ void virBitmapSetAll(virBitmapPtr bitmap) ...@@ -863,25 +908,29 @@ void virBitmapSetAll(virBitmapPtr bitmap)
-1UL >> (VIR_BITMAP_BITS_PER_UNIT - tail); -1UL >> (VIR_BITMAP_BITS_PER_UNIT - tail);
} }
/** /**
* virBitmapClearAll: * virBitmapClearAll:
* @bitmap: the bitmap * @bitmap: the bitmap
* *
* clear all bits in @bitmap. * clear all bits in @bitmap.
*/ */
void virBitmapClearAll(virBitmapPtr bitmap) void
virBitmapClearAll(virBitmapPtr bitmap)
{ {
memset(bitmap->map, 0, memset(bitmap->map, 0,
bitmap->map_len * (VIR_BITMAP_BITS_PER_UNIT / CHAR_BIT)); bitmap->map_len * (VIR_BITMAP_BITS_PER_UNIT / CHAR_BIT));
} }
/** /**
* virBitmapIsAllSet: * virBitmapIsAllSet:
* @bitmap: the bitmap to check * @bitmap: the bitmap to check
* *
* check if all bits in @bitmap are set. * check if all bits in @bitmap are set.
*/ */
bool virBitmapIsAllSet(virBitmapPtr bitmap) bool
virBitmapIsAllSet(virBitmapPtr bitmap)
{ {
size_t i; size_t i;
int unusedBits; int unusedBits;
...@@ -906,13 +955,15 @@ bool virBitmapIsAllSet(virBitmapPtr bitmap) ...@@ -906,13 +955,15 @@ bool virBitmapIsAllSet(virBitmapPtr bitmap)
return true; return true;
} }
/** /**
* virBitmapIsAllClear: * virBitmapIsAllClear:
* @bitmap: the bitmap to check * @bitmap: the bitmap to check
* *
* check if all bits in @bitmap are clear * check if all bits in @bitmap are clear
*/ */
bool virBitmapIsAllClear(virBitmapPtr bitmap) bool
virBitmapIsAllClear(virBitmapPtr bitmap)
{ {
size_t i; size_t i;
...@@ -923,6 +974,7 @@ bool virBitmapIsAllClear(virBitmapPtr bitmap) ...@@ -923,6 +974,7 @@ bool virBitmapIsAllClear(virBitmapPtr bitmap)
return true; return true;
} }
/** /**
* virBitmapNextSetBit: * virBitmapNextSetBit:
* @bitmap: the bitmap * @bitmap: the bitmap
...@@ -935,7 +987,8 @@ bool virBitmapIsAllClear(virBitmapPtr bitmap) ...@@ -935,7 +987,8 @@ bool virBitmapIsAllClear(virBitmapPtr bitmap)
* Returns the position of the found bit, or -1 if no bit found. * Returns the position of the found bit, or -1 if no bit found.
*/ */
ssize_t ssize_t
virBitmapNextSetBit(virBitmapPtr bitmap, ssize_t pos) virBitmapNextSetBit(virBitmapPtr bitmap,
ssize_t pos)
{ {
size_t nl; size_t nl;
size_t nb; size_t nb;
...@@ -963,6 +1016,7 @@ virBitmapNextSetBit(virBitmapPtr bitmap, ssize_t pos) ...@@ -963,6 +1016,7 @@ virBitmapNextSetBit(virBitmapPtr bitmap, ssize_t pos)
return ffsl(bits) - 1 + nl * VIR_BITMAP_BITS_PER_UNIT; return ffsl(bits) - 1 + nl * VIR_BITMAP_BITS_PER_UNIT;
} }
/** /**
* virBitmapLastSetBit: * virBitmapLastSetBit:
* @bitmap: the bitmap * @bitmap: the bitmap
...@@ -1012,6 +1066,7 @@ virBitmapLastSetBit(virBitmapPtr bitmap) ...@@ -1012,6 +1066,7 @@ virBitmapLastSetBit(virBitmapPtr bitmap)
return -1; return -1;
} }
/** /**
* virBitmapNextClearBit: * virBitmapNextClearBit:
* @bitmap: the bitmap * @bitmap: the bitmap
...@@ -1024,7 +1079,8 @@ virBitmapLastSetBit(virBitmapPtr bitmap) ...@@ -1024,7 +1079,8 @@ virBitmapLastSetBit(virBitmapPtr bitmap)
* Returns the position of the found bit, or -1 if no bit found. * Returns the position of the found bit, or -1 if no bit found.
*/ */
ssize_t ssize_t
virBitmapNextClearBit(virBitmapPtr bitmap, ssize_t pos) virBitmapNextClearBit(virBitmapPtr bitmap,
ssize_t pos)
{ {
size_t nl; size_t nl;
size_t nb; size_t nb;
...@@ -1059,6 +1115,7 @@ virBitmapNextClearBit(virBitmapPtr bitmap, ssize_t pos) ...@@ -1059,6 +1115,7 @@ virBitmapNextClearBit(virBitmapPtr bitmap, ssize_t pos)
return ffsl(bits) - 1 + nl * VIR_BITMAP_BITS_PER_UNIT; return ffsl(bits) - 1 + nl * VIR_BITMAP_BITS_PER_UNIT;
} }
/* Return the number of bits currently set in the map. */ /* Return the number of bits currently set in the map. */
size_t size_t
virBitmapCountBits(virBitmapPtr bitmap) virBitmapCountBits(virBitmapPtr bitmap)
...@@ -1134,6 +1191,7 @@ virBitmapDataFormat(const void *data, ...@@ -1134,6 +1191,7 @@ virBitmapDataFormat(const void *data,
return ret; return ret;
} }
bool bool
virBitmapOverlaps(virBitmapPtr b1, virBitmapOverlaps(virBitmapPtr b1,
virBitmapPtr b2) virBitmapPtr b2)
...@@ -1154,6 +1212,7 @@ virBitmapOverlaps(virBitmapPtr b1, ...@@ -1154,6 +1212,7 @@ virBitmapOverlaps(virBitmapPtr b1,
return false; return false;
} }
/** /**
* virBitmapIntersect: * virBitmapIntersect:
* @a: bitmap, modified to contain result * @a: bitmap, modified to contain result
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册