blob: 6be07d605e9e11ec2a058c1d4bdfdc45ae271f9c (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
#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 bitset(name, n) unsigned char name[(n + CHAR_BIT - 1) / CHAR_BIT]
#define CLRBIT(bs, x) ((bs)[__MLIB_BITSLOT(x)] &= ~__MLIB_BITMASK(x))
#define SETBIT(bs, x) ((bs)[__MLIB_BITSLOT(x)] |= __MLIB_BITMASK(x))
#define TOGLBIT(bs, x) ((bs)[__MLIB_BITSLOT(x)] ^= __MLIB_BITMASK(x))
#define TESTBIT(bs, x) ((bool)((bs)[__MLIB_BITSLOT(x)] & __MLIB_BITMASK(x)))
#endif /* !MLIB_BITSET_H */
|