diff options
author | Mendes Oulamara <oulamara@clipper.ens.fr> | 2013-12-04 17:26:39 +0100 |
---|---|---|
committer | Mendes Oulamara <oulamara@clipper.ens.fr> | 2013-12-04 17:26:39 +0100 |
commit | c0f025c2acc781573c14310a6cd543b397905695 (patch) | |
tree | 7950f45f801deb23a29685a37053339096a5c19c /set_bitsets.c | |
parent | 765da0b81086f2c025258507c0ee27e3b3900dfb (diff) | |
parent | 71094b2d48ac784e60d454609064d20e83c017be (diff) | |
download | AlgoProg-Projet-c0f025c2acc781573c14310a6cd543b397905695.tar.gz AlgoProg-Projet-c0f025c2acc781573c14310a6cd543b397905695.zip |
Merge branch 'master' of /users/13/info/oulamara/Work/../../auvolat/boulot/AlgoProg-Projet
Diffstat (limited to 'set_bitsets.c')
-rw-r--r-- | set_bitsets.c | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/set_bitsets.c b/set_bitsets.c index 2c85277..7eddcfd 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<N; i++) if(s.tab[i] != 0) - return i*SCOD+dyadic_val(s.tab[i]); + return i*SCOD + dyadic_val(s.tab[i]); printf("No element in an empty set!\n"); dump_set(s); @@ -174,7 +180,9 @@ set full_set(int n) { *(r.size) = n; int NC=nbCells(n), i; for(i=0; i< NC; i++) - r.tab[i]=-1; + r.tab[i]=-1; + r.tab[NC-1] = ( r.tab[NC-1]>>( (SCOD-(n%SCOD))%SCOD ) ); + assert((n%SCOD == 0) || (r.tab[NC-1]>>(n%SCOD)) == 0); return r; } |