summaryrefslogtreecommitdiff
path: root/src/bitvec.h
blob: ab6797cefb61475c16b8756210b7ff146fb0cfac (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#ifndef __BITVEC_H__
#define __BITVEC_H__

#include "d_size.h"

#define BVEC_TYPE uchar_t
#define BVEC_SIZE sizeof(BVEC_TYPE)

typedef struct _bitvec bitvec_t;

struct _bitvec {
   BVEC_TYPE *vec;
   int len;       /* number of bits [1 based] */
};


/*
 * Function prototypes
 */
bitvec_t *a_Bitvec_new(int bits);
void a_Bitvec_free(bitvec_t *bvec);
int a_Bitvec_get_bit(bitvec_t *bvec, int pos);
void a_Bitvec_set_bit(bitvec_t *bvec, int pos);

/*
#define a_Bitvec_get_bit(bvec,pos) \
   ((bvec)->vec[(pos)/BVEC_SIZE] & 1 << (pos) % BVEC_SIZE)

#define a_Bitvec_set_bit(bvec,pos) \
   ((bvec)->vec[(pos)/BVEC_SIZE] |= 1 << (pos) % BVEC_SIZE)
*/
#define a_Bitvec_clear_bit(bvec,pos) \
   ((bvec)->vec[(pos)/BVEC_SIZE] &= ~(1 << (pos) % BVEC_SIZE))


#endif /* __BITVEC_H__ */