From bd22b018c841cddf4eb8e1dae48eb14eef850523 Mon Sep 17 00:00:00 2001 From: Clement Sibille Date: Mon, 20 May 2024 00:47:45 +0900 Subject: Add bitset module --- src/lisiblestd/bitset.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 src/lisiblestd/bitset.h 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 + +#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 -- cgit v1.2.3