Remove ucore_ prefix from headers and source files

This commit is contained in:
Nils O. Selåsdal
2013-03-06 22:22:04 +01:00
parent ee8d9ae19d
commit 8badeaf857
85 changed files with 168 additions and 168 deletions
+126
View File
@@ -0,0 +1,126 @@
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <limits.h>
#include "ucore/bitvec.h"
#ifdef __GNUC__
#define likely(expr) __builtin_expect((expr), 1)
#define unlikely(expr) __builtin_expect((expr), 0)
#else
#define likely(expr) (expr)
#define unlikely(expr) (expr)
#endif
static inline int bit_index(int b)
{
return b / (sizeof(unsigned long) * CHAR_BIT);
}
static inline int bit_offset(int b)
{
return b % (sizeof(unsigned long) * CHAR_BIT);
}
struct bitvec *bitvec_new(size_t nbits)
{
struct bitvec *v = malloc(sizeof *v);
if (v == NULL)
return NULL;
v->vec_len = BITVEC_VEC_LEN(nbits);
v->vec = malloc(v->vec_len * sizeof(unsigned long));
if (v->vec == NULL) {
free(v);
return NULL;
}
clear_all(v);
return v;
}
void bitvec_free(struct bitvec *v)
{
if (v) {
free(v->vec);
free(v);
}
}
void clear_bit(struct bitvec *v,int b)
{
v->vec[bit_index(b)] &= ~(1UL << (bit_offset(b)));
}
int get_bit(const struct bitvec *v,int b)
{
return !!(v->vec[bit_index(b)] & (1UL << bit_offset(b)));
}
void set_bit(struct bitvec *v,int b)
{
v->vec[bit_index(b)] |= 1UL << (bit_offset(b));
}
void set_bit_s(struct bitvec *v,int b)
{
size_t idx = (size_t)bit_index(b);
assert(b >= 0);
assert(v->vec_len > (size_t)idx);
if (likely(idx < v->vec_len))
v->vec[idx] |= 1UL << (bit_offset(b));
}
void clear_bit_s(struct bitvec *v,int b)
{
size_t idx = (size_t)bit_index(b);
assert(b >= 0);
assert(v->vec_len > (size_t)idx);
if (likely(idx < v->vec_len))
v->vec[idx] &= ~(1UL << (bit_offset(b)));
}
int get_bit_s(const struct bitvec *v,int b)
{
size_t idx = (size_t)bit_index(b);
assert(b >= 0);
assert(v->vec_len > (size_t)idx);
if (likely(idx < v->vec_len))
return !!(v->vec[idx] & (1UL << bit_offset(b)));
else
return 0;
}
void set_bits_from_array(struct bitvec *v,char *array,size_t array_len)
{
size_t i;
for (i = 0; i < array_len; i++) {
size_t idx = (size_t)bit_index(array_len);
if (unlikely(idx >= v->vec_len))
break;
if (array[i])
set_bit(v,i);
else
clear_bit(v,i);
}
}
void clear_all(struct bitvec *v)
{
memset(v->vec,0, v->vec_len * sizeof(unsigned long));
}
void set_all(struct bitvec *v)
{
memset(v->vec,0xff,v->vec_len * sizeof(unsigned long));
}