BITMAP(3) | Library Functions Manual | BITMAP(3) |
__BITMAP_CLR(int bit, type *bitmap);
__BITMAP_ISSET(int bit, type *bitmap);
__BITMAP_SET(int bit, type *bitmap);
__BITMAP_SIZE(type, int nbits);
__BITMAP_TYPE(name, type, int nbits);
__BITMAP_ZERO(type *bitmap);
The following macros are provided for manipulating creating and manipulating bitmaps:
__BITMAP_CLR(bit, bitmap) removes the given bit from the bitmap.
__BITMAP_ISSET(bit, bitmap) is non-zero if bit is a member of bitmap, zero otherwise.
__BITMAP_SET(bit, bitmap) Sets the given bit in the bitmap.
__BITMAP_SIZE(type, nbits) Returns the number of elements would be required of the given type to hold nbits.
__BITMAP_TYPE(name, type, nbits) Declares the properly sized bitmap structure of the given type that holds nbits and is named name.
__BITMAP_ZERO(bit, bitmap) initializes a descriptor set pointed to by bitmap to the null set.
The behavior of these macros is undefined for negative bit values or ones greater than the number of bits the bitmap can hold.
#include <sys/bitops.h> int main(int argc, char **argv) { __BITMAP_TYPE(, uint32_t, 5000) bitmap; /* Initialize the read set to null */ __BITMAP_ZERO(&bitmap); /* Set bit 1 */ __BITMAP_SET(1, &bitmap); for (size_t i = 0; i < 5000; i++) { if (__BITMAP_ISSET(i, &bitmap)) { /* Should just print 1 */ printf("Bit %zu is set\n", i); __BITMAP_CLR(i, &bitmap); } break; } return 0; }
December 6, 2012 | NetBSD 7.2 |