Namespace the bitvec functions

This commit is contained in:
Nils O. Selåsdal
2013-03-07 18:15:20 +01:00
parent 8badeaf857
commit 5e376d47fc
3 changed files with 52 additions and 52 deletions
+16 -16
View File
@@ -22,25 +22,25 @@ static inline int bit_offset(int b)
return b % (sizeof(unsigned long) * CHAR_BIT);
}
struct bitvec *bitvec_new(size_t nbits)
struct UCBitVec *uc_bv_new(size_t nbits)
{
struct bitvec *v = malloc(sizeof *v);
struct UCBitVec *v = malloc(sizeof *v);
if (v == NULL)
return NULL;
v->vec_len = BITVEC_VEC_LEN(nbits);
v->vec_len = UC_BV_LEN(nbits);
v->vec = malloc(v->vec_len * sizeof(unsigned long));
if (v->vec == NULL) {
free(v);
return NULL;
}
clear_all(v);
uc_bv_clr_all(v);
return v;
}
void bitvec_free(struct bitvec *v)
void uc_bv_free(struct UCBitVec *v)
{
if (v) {
free(v->vec);
@@ -49,22 +49,22 @@ void bitvec_free(struct bitvec *v)
}
void clear_bit(struct bitvec *v,int b)
void uc_bv_clr_bit(struct UCBitVec *v,int b)
{
v->vec[bit_index(b)] &= ~(1UL << (bit_offset(b)));
}
int get_bit(const struct bitvec *v,int b)
int uc_bv_get_bit(const struct UCBitVec *v,int b)
{
return !!(v->vec[bit_index(b)] & (1UL << bit_offset(b)));
}
void set_bit(struct bitvec *v,int b)
void uc_bv_set_bit(struct UCBitVec *v,int b)
{
v->vec[bit_index(b)] |= 1UL << (bit_offset(b));
}
void set_bit_s(struct bitvec *v,int b)
void uc_bv_set_bit_s(struct UCBitVec *v,int b)
{
size_t idx = (size_t)bit_index(b);
assert(b >= 0);
@@ -74,7 +74,7 @@ void set_bit_s(struct bitvec *v,int b)
v->vec[idx] |= 1UL << (bit_offset(b));
}
void clear_bit_s(struct bitvec *v,int b)
void uc_bv_clear_bit_s(struct UCBitVec *v,int b)
{
size_t idx = (size_t)bit_index(b);
@@ -85,7 +85,7 @@ void clear_bit_s(struct bitvec *v,int b)
v->vec[idx] &= ~(1UL << (bit_offset(b)));
}
int get_bit_s(const struct bitvec *v,int b)
int uc_bv_get_bit_s(const struct UCBitVec *v,int b)
{
size_t idx = (size_t)bit_index(b);
@@ -98,7 +98,7 @@ int get_bit_s(const struct bitvec *v,int b)
return 0;
}
void set_bits_from_array(struct bitvec *v,char *array,size_t array_len)
void uc_bv_set_bits_from_array(struct UCBitVec *v,char *array,size_t array_len)
{
size_t i;
@@ -108,18 +108,18 @@ void set_bits_from_array(struct bitvec *v,char *array,size_t array_len)
break;
if (array[i])
set_bit(v,i);
uc_bv_set_bit(v,i);
else
clear_bit(v,i);
uc_bv_clr_bit(v,i);
}
}
void clear_all(struct bitvec *v)
void uc_bv_clr_all(struct UCBitVec *v)
{
memset(v->vec,0, v->vec_len * sizeof(unsigned long));
}
void set_all(struct bitvec *v)
void uc_bv_set_all(struct UCBitVec *v)
{
memset(v->vec,0xff,v->vec_len * sizeof(unsigned long));
}