13#ifndef FC__BITVECTOR_H
14#define FC__BITVECTOR_H
28#define TEST_BIT(val, bit_no) \
29 (((val) & (1u << (bit_no))) == (1u << (bit_no)))
56void dbv_to_bv(
unsigned char *dest,
const struct dbv *src);
57void bv_to_dbv(
struct dbv *dest,
const unsigned char *src);
63#define MAX_DBV_LENGTH (4 * 1024 * 1024)
66#define _BV_BYTES(bits) ((((bits) - 1) / 8) + 1)
67#define _BV_BYTE_INDEX(bits) ((bits) / 8)
68#define _BV_BITMASK(bit) (1u << ((bit) & 0x7))
71#define _BV_ASSERT(bv, bit) \
72 fc_assert((signed int)(bit) >= 0 \
73 && (signed int)(bit) < (signed int) sizeof((bv).vec) * 8)
75#define _BV_ASSERT(bv, bit) (void)0
78#define BV_ISSET(bv, bit) \
79 (_BV_ASSERT(bv, bit), \
80 ((bv).vec[_BV_BYTE_INDEX(bit)] & _BV_BITMASK(bit)) != 0)
81#define BV_SET(bv, bit) \
83 _BV_ASSERT(bv, bit); \
84 (bv).vec[_BV_BYTE_INDEX(bit)] |= _BV_BITMASK(bit); \
86#define BV_CLR(bv, bit) \
88 _BV_ASSERT(bv, bit); \
89 (bv).vec[_BV_BYTE_INDEX(bit)] &= ~_BV_BITMASK(bit); \
91#define BV_SET_VAL(bv, bit, val) \
93 if (val) { BV_SET(bv, bit); } else { BV_CLR(bv, bit); } \
95#define BV_CLR_ALL(bv) \
97 memset((bv).vec, 0, sizeof((bv).vec)); \
99#define BV_SET_ALL(bv) \
101 memset((bv).vec, 0xff, sizeof((bv).vec)); \
106#define BV_CHECK_MASK(vec1, vec2) \
107 bv_check_mask((vec1).vec, (vec2).vec, sizeof((vec1).vec), \
109#define BV_ISSET_ANY(vec) BV_CHECK_MASK(vec, vec)
113#define BV_ARE_EQUAL(vec1, vec2) \
114 bv_are_equal((vec1).vec, (vec2).vec, sizeof((vec1).vec), \
120#define BV_SET_ALL_FROM(vec_to, vec_from) \
121 bv_set_all_from((vec_to).vec, (vec_from).vec, \
122 sizeof((vec_to).vec), sizeof((vec_from).vec))
127#define BV_CLR_ALL_FROM(vec_to, vec_from) \
128 bv_clr_all_from((vec_to).vec, (vec_from).vec, \
129 sizeof((vec_to).vec), sizeof((vec_from).vec))
132#define BV_DEFINE(name, bits) \
133 typedef struct { unsigned char vec[_BV_BYTES(bits)]; } name
bool bv_check_mask(const unsigned char *vec1, const unsigned char *vec2, size_t size1, size_t size2)
void bv_to_dbv(struct dbv *dest, const unsigned char *src)
bool dbv_isset_any(const struct dbv *pdbv)
void dbv_resize(struct dbv *pdbv, int bits)
bool bv_match_dbv(const struct dbv *match, const unsigned char *src)
void dbv_init(struct dbv *pdbv, int bits)
void bv_clr_all_from(unsigned char *vec_to, const unsigned char *vec_from, size_t size_to, size_t size_from)
int dbv_bits(struct dbv *pdbv)
void dbv_set_all(struct dbv *pdbv)
void dbv_set(struct dbv *pdbv, int bit)
bool bv_are_equal(const unsigned char *vec1, const unsigned char *vec2, size_t size1, size_t size2)
bool dbv_isset(const struct dbv *pdbv, int bit)
void dbv_copy(struct dbv *dest, const struct dbv *src)
void dbv_debug(struct dbv *pdbv)
void bv_set_all_from(unsigned char *vec_to, const unsigned char *vec_from, size_t size_to, size_t size_from)
void dbv_free(struct dbv *pdbv)
void dbv_clr_all(struct dbv *pdbv)
void dbv_clr(struct dbv *pdbv, int bit)
bool dbv_are_equal(const struct dbv *pdbv1, const struct dbv *pdbv2)
void dbv_to_bv(unsigned char *dest, const struct dbv *src)