-
Notifications
You must be signed in to change notification settings - Fork 0
/
ASet.c~
92 lines (68 loc) · 1.23 KB
/
ASet.c~
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#include "ASet.h"
#include <stdio.h>
int Contains(ASet *a, ASet *b)
{
if (*a==*b) //IF THEY ARE EQUAL, FAVOR a, THE ONE ALREADY IN THE CHAIN
return -1;
if ( (*a^*b) == (*a-*b))
return 1;
if ( (*a^*b) == (*b-*a) )
return -1;
return 0;
}
void Add(ASet *a, int itemIndex)
{
*a|= 1<< itemIndex;
}
void Remove(ASet *a, int itemIndex)
{
*a&= -1 ^ (1<<itemIndex);
}
void Clear(ASet *a)
{
*a=0;
}
void Union(ASet *a, ASet *b)
{
*a= *a | *b;
}
int SetOnlyDifference(ASet a, ASet b)
{
int i;
int twoPow;
if (a==b)
return -1; //they are not different at all
twoPow=1;
for (i=0; (a & twoPow) == ( b & twoPow) ; i++)
{
twoPow*=2;
}
// A difference is found now, there should be equal from AFTER that point
i++;
if ((a >> i) != (b >> i))
return -1; //they are still different from this point on.
return i;
}
void PrintSet(ASet a)
{
int i;
for (i=0; i< sizeof(ASet)*8; i++)
{
if (a%2)
printf("_%d", i);
a/=2;
}
printf(" ");
}
void PrintSet_IncNeg(ASet a) //Print a set with negated literals
{
int i;
for (i=ASET_SIZE_HALF; i>= 0; i--)
{
if (SET_MEMBER(a,i))
printf("_%d", i);
if (SET_MEMBER(a,SET_INDEX_NEGATE(i)))
printf("_~%d", i);
}
printf(" ");
}