// SPDX-License-Identifier: GPL-2.0-only /* * From lib/bitmap.c * Helper functions for bitmap.h.
*/ #include <linux/bitmap.h>
unsignedint __bitmap_weight(constunsignedlong *bitmap, int bits)
{ unsignedint k, w = 0, lim = bits/BITS_PER_LONG;
for (k = 0; k < lim; k++)
w += hweight_long(bitmap[k]);
if (bits % BITS_PER_LONG)
w += hweight_long(bitmap[k] & BITMAP_LAST_WORD_MASK(bits));
return w;
}
void __bitmap_or(unsignedlong *dst, constunsignedlong *bitmap1, constunsignedlong *bitmap2, int bits)
{ int k; int nr = BITS_TO_LONGS(bits);
for (k = 0; k < nr; k++)
dst[k] = bitmap1[k] | bitmap2[k];
}
size_t bitmap_scnprintf(unsignedlong *bitmap, unsignedint nbits, char *buf, size_t size)
{ /* current bit is 'cur', most recently seen range is [rbot, rtop] */ unsignedint cur, rbot, rtop; bool first = true;
size_t ret = 0;
rbot = cur = find_first_bit(bitmap, nbits); while (cur < nbits) {
rtop = cur;
cur = find_next_bit(bitmap, nbits, cur + 1); if (cur < nbits && cur <= rtop + 1) continue;
if (!first)
ret += scnprintf(buf + ret, size - ret, ",");
first = false;
ret += scnprintf(buf + ret, size - ret, "%d", rbot); if (rbot < rtop)
ret += scnprintf(buf + ret, size - ret, "-%d", rtop);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.