Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifndef BITSET_H
- #define BITSET_H
- /**
- * @file bitset.h
- * @brief Interface to the bitset data structure.
- */
- #include <stdlib.h>
- #include <limits.h>
- #define UINT_BITS sizeof(unsigned)*CHAR_BIT
- /**
- * Bitset data structure.
- */
- struct bitset {
- size_t length; /**< Length in bits. */
- unsigned chunk[]; /**< Storage for the set. */
- };
- extern struct bitset *new_bitset(size_t length);
- extern void delete_bitset(struct bitset *self);
- static inline void bitset_set(struct bitset *self, int index)
- {
- div_t d = div(index, UINT_BITS);
- self->chunk[d.quot] |= (1 << (unsigned) d.rem);
- }
- static inline int bitset_get(const struct bitset *self, int index)
- {
- div_t d = div(index, UINT_BITS);
- return (self->chunk[d.quot] >> (unsigned) d.rem) & 1;
- }
- static inline void bitset_clear(struct bitset *self, int index)
- {
- div_t d = div(index, UINT_BITS);
- self->chunk[d.quot] &= ~(1 << (unsigned) d.rem);
- }
- #endif // !BITSET_H
Add Comment
Please, Sign In to add comment