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
+15 -15
View File
@@ -5,7 +5,7 @@
extern "C" {
#endif
struct bitvec {
struct UCBitVec {
//storage for the bits
unsigned long *vec;
//length of the above vec. (Not the number of bits !)
@@ -15,14 +15,14 @@ struct bitvec {
/**
* Evaluates the length required for a bitvec to store nbit bits.
*/
#define BITVEC_VEC_LEN(nbits) ((nbits/(sizeof(unsigned long)*CHAR_BIT)) + (nbits % (sizeof(unsigned long)*CHAR_BIT) == 0 ? 0 : 1))
#define UC_BV_LEN(nbits) ((nbits/(sizeof(unsigned long)*CHAR_BIT)) + (nbits % (sizeof(unsigned long)*CHAR_BIT) == 0 ? 0 : 1))
/**
* Use as :
* unsigned long v[10];
* struct bitvec v = BITVEC_STATIC_INIT(v);
* struct UCBitVec v = BITVEC_STATIC_INIT(v);
*/
#define BITVEC_STATIC_INIT(vec_data)\
#define UC_BV_STATIC_INIT(vec_data)\
{\
vec_data,\
sizeof vec_data/sizeof vec_data[0]}
@@ -33,29 +33,29 @@ sizeof vec_data/sizeof vec_data[0]}
* All bits are initially zero.
*
*/
struct bitvec *bitvec_new(size_t nbits);
struct UCBitVec *uc_bv_new(size_t nbits);
/** free a bitvec previously allocated by bitvec_new
*/
void bitvec_free(struct bitvec *v);
void uc_bv_free(struct UCBitVec *v);
//Note that accessing a bit beyond the nbits originally initialized
//for the given bitvec is undedefined
/** Sets bit no. b */
void set_bit(struct bitvec *v,int b);
void uc_bv_set_bit(struct UCBitVec *v,int b);
/** Clears bit no. b*/
void clear_bit(struct bitvec *v,int b);
void uc_bv_clr_bit(struct UCBitVec *v,int b);
/** Gets the current value (0 or 1) of bit no. b*/
int get_bit(const struct bitvec *v,int b);
int uc_bv_get_bit(const struct UCBitVec *v,int b);
/** Sets all bits to zero */
void clear_all(struct bitvec *v);
void uc_bv_clr_all(struct UCBitVec *v);
/** Sets all bits to one */
void set_all(struct bitvec *v);
void uc_bv_set_all(struct UCBitVec *v);
/** Initialize bits from a array of ints, each array element maps to one bit.
* The bits are initialized from the int array so zero maps to zero and non-zero maps to one.
@@ -63,16 +63,16 @@ void set_all(struct bitvec *v);
* int a[] = {0,1,1,1,0};
* set_bits_from_array(v,a,5);
* */
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);
// The _s ("secure") versions does boundary checking and assert() if they
// try to access a bit out of bounds.
void set_bit_s(struct bitvec *v,int b);
void uc_bv_set_bit_s(struct UCBitVec *v,int b);
void clear_bit_s(struct bitvec *v,int b);
void uc_bv_clear_bit_s(struct UCBitVec *v,int b);
int get_bit_s(const struct bitvec *v,int b);
int uc_bv_get_bit_s(const struct UCBitVec *v,int b);
#ifdef __cplusplus
}