diff options
| author | Clement Sibille <clements+git@lisible.xyz> | 2024-05-20 00:47:45 +0900 |
|---|---|---|
| committer | Clement Sibille <clements+git@lisible.xyz> | 2024-05-20 01:28:21 +0900 |
| commit | bd22b018c841cddf4eb8e1dae48eb14eef850523 (patch) | |
| tree | 19a450ffddfe885b2e2f504c84cc003ccf513b19 | |
| parent | 817c1fd14c9b9b3fc93922f7ea06d9edfd53c63b (diff) | |
Add bitset module
| -rw-r--r-- | src/lisiblestd/bitset.h | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/src/lisiblestd/bitset.h b/src/lisiblestd/bitset.h new file mode 100644 index 0000000..3e8cb70 --- /dev/null +++ b/src/lisiblestd/bitset.h @@ -0,0 +1,13 @@ +#ifndef LSTD_BITSET_H +#define LSTD_BITSET_H + +#include <limits.h> + +#define BITMASK(b) (1 << ((b) % CHAR_BIT)) +#define BITSLOT(b) ((b) / CHAR_BIT) +#define BITSET(a, b) ((a)[BITSLOT(b)] |= BITMASK(b)) +#define BITCLEAR(a, b) ((a)[BITSLOT(b)] &= ~BITMASK(b)) +#define BITTEST(a, b) ((a)[BITSLOT(b)] & BITMASK(b)) +#define BITNSLOTS(nb) ((nb + CHAR_BIT - 1) / CHAR_BIT) + +#endif // LSTD_BITSET_H |
