From 3c8b380b98b8fd5dcbaa3a254ab71ac20a485099 Mon Sep 17 00:00:00 2001 From: Mendes Oulamara Date: Fri, 6 Dec 2013 18:08:37 +0100 Subject: Addition of sets_equal to bitsets --- set_bitsets.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'set_bitsets.c') diff --git a/set_bitsets.c b/set_bitsets.c index 4ac8462..5578620 100644 --- a/set_bitsets.c +++ b/set_bitsets.c @@ -51,9 +51,9 @@ set empty_set(int n){ res.size = malloc(sizeof(int)); *(res.size) = 0; int NC = nbCells(n); - res.tab = malloc(SCOD*NC/8); + res.tab = malloc((SCOD*NC)/8); for(i = 0; i < NC; i++) - res.tab[i] = 0; + res.tab[i] = (unsigned long long) (0); return res; } @@ -117,6 +117,18 @@ bool is_set_empty(const set s){ return (*(s.size) == 0); } +bool sets_equal(const set a, const set b){ + if(a.N != b.N) + return false; + int i, NC = nbCells(a.N); + for(i = 0; i < NC; i++){ + if(a.tab[i] != b.tab[i]) + return false; + } + assert(*(a.size) == *(b.size)); + return true; +} + inline bool set_mem(int x, const set s){ unsigned long long ux = x; if (!(x < s.N && x >= 0)) { @@ -163,6 +175,7 @@ int elt_of_set_heur(const set s, int h){ } void set_add_ip(int x, set s){ + assert(x < s.N); unsigned long long ux = x; if(! set_mem(ux, s)){ s.tab[ux/SCOD] = s.tab[ux/SCOD] | (unsigned long long)(1)<<(ux%SCOD); @@ -192,7 +205,7 @@ 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]=0xFFFFFFFFFFFFFFFF; 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; -- cgit v1.2.3