diff options
Diffstat (limited to 'include/bitset.h')
-rw-r--r-- | include/bitset.h | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/include/bitset.h b/include/bitset.h new file mode 100644 index 0000000..397435f --- /dev/null +++ b/include/bitset.h @@ -0,0 +1,17 @@ +#ifndef MLIB_BITSET_H +#define MLIB_BITSET_H + +#include <limits.h> + +#define __MLIB_BITSLOT(x) ((x) / CHAR_BIT) +#define __MLIB_BITMASK(x) (1 << ((x) % CHAR_BIT)) +#define __MLIB_BITIMPL(bs, x, op) ((bs)[__MLIB_BITSLOT(x)] op __MLIB_BITMASK(x)) + +#define bitset(name, n) unsigned char name[(n + CHAR_BIT - 1) / CHAR_BIT] + +#define BITCLR(bs, x) __MLIB_BITIMPL(bs, x, &=~) +#define BITSET(bs, x) __MLIB_BITIMPL(bs, x, |=) +#define BITTOGL(bs, x) __MLIB_BITIMPL(bs, x, ^=) +#define BITTEST(bs, x) (bool)__MLIB_BITIMPL(bs, x, &) + +#endif /* !MLIB_BITSET_H */ |