-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathASet.h~
44 lines (26 loc) · 1.65 KB
/
ASet.h~
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
typedef unsigned long long ASet;
#define ASET_SIZE_DIVISIONFACTOR 2 //We shouldn't need this, but there is inconsistency in the size of the words
#define ASET_SIZE_HALF (sizeof(ASet)* 8 /2 / ASET_SIZE_DIVISIONFACTOR)
#define ASET_SIZE (sizeof(ASet)* 8 / ASET_SIZE_DIVISIONFACTOR)
#define SET_CONTAINS(a,b) ( ((a)==(b))? (-1): ((a)^(b) == (a)-(b))? (1): ((a)^(b) == (b)-(a))? (-1):0)
int Contains(ASet *a, ASet *b); //1: a contains b, 0: none, -1 b contains a
#define SET_ADD(a,itemIndex) {(a)|= 1<<(itemIndex);}
#define SET_ADDE(a, itemIndex) ((a) | 1 <<(itemIndex)) //Doesn't modify a, just gives an EXPRESSION
void Add(ASet *a, int itemIndex);
#define SET_MEMBER(a, itemIndex) ( (a) & (1<< (itemIndex)) )
#define SET_REMOVE(a,itemIndex) { (a)&= -1 ^ (1<<(itemIndex));}
void Remove(ASet *a, int itemIndex);
#define SET_CLEAR(a) { (a)=0;}
void Clear(ASet *a);
#define SET_UNION(a,b) ((a)|(b))
void Union(ASet *a, ASet *b);
#define SET_INTERSECTION(a,b) ((a)&(b))
#define SET_ISFALSE(a) (((a)>> ASET_SIZE_HALF) & (a) ) //MAKE SURE SHIFT RIGHT IS NOT CIRCULAR
#define SET_UPPERHALF(a) ((a)>> ASET_SIZE_HALF)
#define SET_LOWERHALF(a) ((a) & ((1<< ASET_SIZE_HALF)-1))
#define SET_ALL_ATOMS(a) (SET_UPPERHALF(a) | SET_LOWERHALF(a) )
#define SET_NEGATE_ALL(a) ((a)<< ASET_SIZE_HALF) //MAKE SURE SHIFT LEFT IS CIRCULAR. THIS IS NOT EQUIVALENT TO A NOT OPERATION ON AN AND CLAUSE
#define SET_INDEX_NEGATE(a) (((a)+ ASET_SIZE_HALF)% ASET_SIZE)
int SetOnlyDifference(ASet a, ASet b); //If they are different in only one bit, its index is returned, -1 otherwise
void PrintSet_IncNeg(ASet); //Print a set with negated literals
#define LOGIC_NORMALIZE(a) ((a)?1:0)