bitmap(3) - NetBSD Manual Pages

BITMAP(3)               NetBSD Library Functions Manual              BITMAP(3)


NAME
__BITMAP_CLR, __BITMAP_ISSET, __BITMAP_SET, __BITMAP_SIZE, __BITMAP_TYPE, __BITMAP_ZERO -- bitmap manipulation macros
LIBRARY
Standard C Library (libc, -lc)
SYNOPSIS
#include <sys/bitops.h> __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);
DESCRIPTION
The supplied macros are similar to the select(2) FD_SET() family, to the setbit(9), macros and the bitstring(3) library. They are different from FD_SET() because they are designed to handle multiple sized bitmaps at the same time, and they can be of any integral type. They are different from setbit(9) because they can operate on different integral types, not just on bytes. They are different from bitstring(3) because they are just macros, they don't allocate memory or use code, and they can be used in both kernel and userland. The following macros are provided for manipulating creating and manipu- lating 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(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.
EXAMPLES
#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; }
SEE ALSO
select(2), bitops(3), bitstring(3), setbit(9)
HISTORY
The __BITMAP_*() macros appeared in NetBSD 7.0. NetBSD 10.1 March 8, 2018 NetBSD 10.1

Powered by man-cgi (2024-08-26). Maintained for NetBSD by Kimmo Suominen. Based on man-cgi by Panagiotis Christias.