summaryrefslogtreecommitdiff
path: root/set_bitsets.c
diff options
context:
space:
mode:
authorMendes Oulamara <oulamara@clipper.ens.fr>2013-12-06 18:08:37 +0100
committerMendes Oulamara <oulamara@clipper.ens.fr>2013-12-06 18:08:37 +0100
commit3c8b380b98b8fd5dcbaa3a254ab71ac20a485099 (patch)
treed294b3ec1ea86de96e57dcf50125a0cb7552b0e7 /set_bitsets.c
parent50b5699f9b6d887c31e546168d9e588b36e3f876 (diff)
downloadAlgoProg-Projet-3c8b380b98b8fd5dcbaa3a254ab71ac20a485099.tar.gz
AlgoProg-Projet-3c8b380b98b8fd5dcbaa3a254ab71ac20a485099.zip
Addition of sets_equal to bitsets
Diffstat (limited to 'set_bitsets.c')
-rw-r--r--set_bitsets.c19
1 files changed, 16 insertions, 3 deletions
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;