X-Git-Url: http://git.nguyen.vg/gitweb/?p=SXSI%2Flibbp.git;a=blobdiff_plain;f=bp-utils.c;fp=bp-utils.c;h=b1d68ce071e9b28edcb9e09b2f347f2680b5ade6;hp=0000000000000000000000000000000000000000;hb=45ff7a2260f890f6ef6a7b56f654ffa1a057a7e7;hpb=b3b328570c63aea4d9d15854eec9f7434cc9fe0d diff --git a/bp-utils.c b/bp-utils.c new file mode 100644 index 0000000..b1d68ce --- /dev/null +++ b/bp-utils.c @@ -0,0 +1,53 @@ +#include +#include "bp-utils.h" + +static size_t allocated = 0; + +void * bp_malloc(size_t n) +{ + void * res = malloc(n); + if (!res) { + fprintf(stderr, __FILE__ ": failure to allocate %lu bytes\n", n); + exit(1); + }; + allocated += n; + return res; +} + +void bp_free(void * p) +{ + if (p) free(p); +} +size_t bp_get_alloc_stats(void) +{ + return allocated; +} +void bp_reset_alloc_states(void) +{ + allocated = 0; +} + +int bp_setbit(unsigned int *B, int i,int x) +{ + int j,l; + + j = i / D; + l = i % D; + if (x==0) B[j] &= (~(1<<(D-1-l))); + else if (x==1) B[j] |= (1<<(D-1-l)); + else { + printf("error setbit x=%d\n",x); + exit(1); + } + return x; +} + +int bp_setbits(unsigned int *B, int i, int d, int x) +{ + int j; + + for (j=0; j>(d-j-1))&1); + } + return x; +}