summaryrefslogtreecommitdiff
path: root/set_bitsets.c
diff options
context:
space:
mode:
Diffstat (limited to 'set_bitsets.c')
-rw-r--r--set_bitsets.c20
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;
}