21 #define BITARRAY_SHIFT 5
23 #define BITARRAY_SHIFT 6
25 #error "int is neither 4 nor 8 bytes. I can't deal with that."
27 #define BITARRAY_MASK ((1u<<BITARRAY_SHIFT)-1)
36 size_t sz = (n_bits+BITARRAY_MASK) >> BITARRAY_SHIFT;
37 return tor_calloc(sz,
sizeof(
unsigned int));
44 unsigned int n_bits_old,
unsigned int n_bits_new)
46 size_t sz_old = (n_bits_old+BITARRAY_MASK) >> BITARRAY_SHIFT;
47 size_t sz_new = (n_bits_new+BITARRAY_MASK) >> BITARRAY_SHIFT;
51 ptr = tor_reallocarray(ba, sz_new,
sizeof(
unsigned int));
54 memset(ptr+sz_old*
sizeof(
unsigned int), 0,
55 (sz_new-sz_old)*
sizeof(
unsigned int));
64 #define bitarray_free(ba) FREE_AND_NULL(bitarray_t, bitarray_free_, (ba))
70 b[bit >> BITARRAY_SHIFT] |= (1u << (bit & BITARRAY_MASK));
76 b[bit >> BITARRAY_SHIFT] &= ~ (1u << (bit & BITARRAY_MASK));
80 static inline unsigned int
83 return b[bit >> BITARRAY_SHIFT] & (1u << (bit & BITARRAY_MASK));
static void bitarray_set(bitarray_t *b, int bit)
static unsigned int bitarray_is_set(bitarray_t *b, int bit)
static void bitarray_free_(bitarray_t *ba)
static void bitarray_clear(bitarray_t *b, int bit)
static bitarray_t * bitarray_expand(bitarray_t *ba, unsigned int n_bits_old, unsigned int n_bits_new)
static bitarray_t * bitarray_init_zero(unsigned int n_bits)
Headers for util_malloc.c.
Integer definitions used throughout Tor.