-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathset.c
210 lines (184 loc) · 6.05 KB
/
set.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
/***** ltl2ba : set.c *****/
/* Written by Denis Oddoux, LIAFA, France */
/* Copyright (c) 2001 Denis Oddoux */
/* Modified by Paul Gastin, LSV, France */
/* Copyright (c) 2007 Paul Gastin */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 2 of the License, or */
/* (at your option) any later version. */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program; if not, write to the Free Software */
/* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA*/
/* */
/* Based on the translation algorithm by Gastin and Oddoux, */
/* presented at the 13th International Conference on Computer Aided */
/* Verification, CAV 2001, Paris, France. */
/* Proceedings - LNCS 2102, pp. 53-65 */
/* */
/* Send bug-reports and/or questions to Paul Gastin */
/* http://www.lsv.ens-cachan.fr/~gastin */
#include "config.h"
#include "ltl2ba.h"
extern FILE *tl_out;
extern int node_size, sym_size, scc_size;
extern char **sym_table;
int mod = 8 * sizeof(int);
/* type = 2 for scc set, 1 for symbol sets, 0 for nodes sets */
#define set_size(t) (t==1?sym_size:(t==2?scc_size:node_size))
int *new_set(int type) /* creates a new set */
{
return (int *)tl_emalloc(set_size(type) * sizeof(int));
}
int *clear_set(int *l, int type) /* clears the set */
{
int i;
for(i = 0; i < set_size(type); i++) {
l[i] = 0;
}
return l;
}
int *make_set(int n, int type) /* creates the set {n}, or the empty set if n = -1 */
{
int *l = clear_set(new_set(type), type);
if(n == -1) return l;
l[n/mod] = 1 << (n%mod);
return l;
}
void copy_set(int *from, int *to, int type) /* copies a set */
{
int i;
for(i = 0; i < set_size(type); i++)
to[i] = from[i];
}
int *dup_set(int *l, int type) /* duplicates a set */
{
int i, *m = new_set(type);
for(i = 0; i < set_size(type); i++)
m[i] = l[i];
return m;
}
void merge_sets(int *l1, int *l2, int type) /* puts the union of the two sets in l1 */
{
int i;
for(i = 0; i < set_size(type); i++)
l1[i] = l1[i] | l2[i];
}
void do_merge_sets(int *l, int *l1, int *l2, int type) /* makes the union of two sets */
{
int i;
for(i = 0; i < set_size(type); i++)
l[i] = l1[i] | l2[i];
}
int *intersect_sets(int *l1, int *l2, int type) /* makes the intersection of two sets */
{
int i, *l = new_set(type);
for(i = 0; i < set_size(type); i++)
l[i] = l1[i] & l2[i];
return l;
}
int empty_intersect_sets(int *l1, int *l2, int type) /* tests intersection of two sets */
{
int i, test = 0;
for(i = 0; i < set_size(type); i++)
test |= l1[i] & l2[i];
return !test;
}
void add_set(int *l, int n) /* adds an element to a set */
{
l[n/mod] |= 1 << (n%mod);
}
void rem_set(int *l, int n) /* removes an element from a set */
{
l[n/mod] &= (-1 - (1 << (n%mod)));
}
void spin_print_set(int *pos, int *neg) /* prints the content of a set for spin */
{
int i, j, start = 1;
for(i = 0; i < sym_size; i++)
for(j = 0; j < mod; j++) {
if(pos[i] & (1 << j)) {
if(!start)
fprintf(tl_out, " && ");
fprintf(tl_out, "%s", sym_table[mod * i + j]);
start = 0;
}
if(neg[i] & (1 << j)) {
if(!start)
fprintf(tl_out, " && ");
fprintf(tl_out, "!%s", sym_table[mod * i + j]);
start = 0;
}
}
if(start)
fprintf(tl_out, "1");
}
void print_set(int *l, int type) /* prints the content of a set */
{
int i, j, start = 1;;
if(type != 1) fprintf(tl_out, "{");
for(i = 0; i < set_size(type); i++)
for(j = 0; j < mod; j++)
if(l[i] & (1 << j)) {
switch(type) {
case 0: case 2:
if(!start) fprintf(tl_out, ",");
fprintf(tl_out, "%i", mod * i + j);
break;
case 1:
if(!start) fprintf(tl_out, " & ");
fprintf(tl_out, "%s", sym_table[mod * i + j]);
break;
}
start = 0;
}
if(type != 1) fprintf(tl_out, "}");
}
int empty_set(int *l, int type) /* tests if a set is the empty set */
{
int i, test = 0;
for(i = 0; i < set_size(type); i++)
test |= l[i];
return !test;
}
int same_sets(int *l1, int *l2, int type) /* tests if two sets are identical */
{
int i, test = 1;
for(i = 0; i < set_size(type); i++)
test &= (l1[i] == l2[i]);
return test;
}
int included_set(int *l1, int *l2, int type)
{ /* tests if the first set is included in the second one */
int i, test = 0;
for(i = 0; i < set_size(type); i++)
test |= (l1[i] & ~l2[i]);
return !test;
}
int in_set(int *l, int n) /* tests if an element is in a set */
{
return(l[n/mod] & (1 << (n%mod)));
}
int *list_set(int *l, int type) /* transforms a set into a list */
{
int i, j, size = 1, *list;
for(i = 0; i < set_size(type); i++)
for(j = 0; j < mod; j++)
if(l[i] & (1 << j))
size++;
list = (int *)tl_emalloc(size * sizeof(int));
list[0] = size;
size = 1;
for(i = 0; i < set_size(type); i++)
for(j = 0; j < mod; j++)
if(l[i] & (1 << j))
list[size++] = mod * i + j;
return list;
}