From 71094b2d48ac784e60d454609064d20e83c017be Mon Sep 17 00:00:00 2001 From: Alex Auvolat--bernstein Date: Wed, 4 Dec 2013 17:26:06 +0100 Subject: Finished implementation for algorithm C, and corrected bitset bugs. --- set_bitsets.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'set_bitsets.c') diff --git a/set_bitsets.c b/set_bitsets.c index 53af83a..fda7085 100644 --- a/set_bitsets.c +++ b/set_bitsets.c @@ -83,6 +83,7 @@ void set_inter_ip(set a, const set b){ a.tab[i] = a.tab[i]&b.tab[i]; *(a.size) += nb_one(a.tab[i]); } + assert((a.N%SCOD == 0) || (a.tab[NC-1]>>(a.N%SCOD)) == 0); } @@ -92,10 +93,12 @@ void set_diff_ip(set a, const set b){ assert(a.N == b.N); } int NC = nbCells(a.N), i; + *(a.size)=0; for(i = 0; i < NC; i++) { a.tab[i] = a.tab[i] & (~b.tab[i]); *(a.size) += nb_one(a.tab[i]); } + assert((a.N%SCOD == 0) || (a.tab[NC-1]>>(a.N%SCOD)) == 0); } bool is_set_empty(const set s){ @@ -103,18 +106,21 @@ bool is_set_empty(const set s){ } inline bool set_mem(int x, const set s){ - unsigned long long ux = x; + unsigned long long ux = x; + if (!(x < s.N && x >= 0)) { + printf("Invalid argument for set_mem : %d\n", x); assert(x < s.N && x >= 0); + } return (s.tab[ux/SCOD]>>(ux%SCOD))&1; } int dyadic_val(unsigned long long x){ - if(x == 0){ + if(x == 0) { printf("Infinite valuation\n"); assert(false); } - int i; - for(i=0; ((x>>i)&1) == 0; i++); + int i = 0; + while (((x>>i)&1) == 0) i++; return i; } @@ -122,7 +128,7 @@ int elt_of_set(const set s){ int N=nbCells(s.N), i; for(i=0; i>( (SCOD-(n%SCOD))%SCOD ) ); + assert((n%SCOD == 0) || (r.tab[NC-1]>>(n%SCOD)) == 0); return r; } -- cgit v1.2.3