00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include "espresso.h"
00026
00027
00028
00029
00030
00031
00032
00033
00034 pset_family sf_contain(A)
00035 INOUT pset_family A;
00036 {
00037 int cnt;
00038 pset *A1;
00039 pset_family R;
00040
00041 A1 = sf_sort(A, descend);
00042 cnt = rm_equal(A1, descend);
00043 cnt = rm_contain(A1);
00044 R = sf_unlist(A1, cnt, A->sf_size);
00045 sf_free(A);
00046 return R;
00047 }
00048
00049
00050
00051
00052
00053
00054
00055 pset_family sf_rev_contain(A)
00056 INOUT pset_family A;
00057 {
00058 int cnt;
00059 pset *A1;
00060 pset_family R;
00061
00062 A1 = sf_sort(A, ascend);
00063 cnt = rm_equal(A1, ascend);
00064 cnt = rm_rev_contain(A1);
00065 R = sf_unlist(A1, cnt, A->sf_size);
00066 sf_free(A);
00067 return R;
00068 }
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078 pset_family sf_ind_contain(A, row_indices)
00079 INOUT pset_family A;
00080 INOUT int *row_indices;
00081 {
00082 int cnt;
00083 pset *A1;
00084 pset_family R;
00085
00086 A1 = sf_sort(A, descend);
00087 cnt = rm_equal(A1, descend);
00088 cnt = rm_contain(A1);
00089 R = sf_ind_unlist(A1, cnt, A->sf_size, row_indices, A->data);
00090 sf_free(A);
00091 return R;
00092 }
00093
00094
00095
00096 pset_family sf_dupl(A)
00097 INOUT pset_family A;
00098 {
00099 register int cnt;
00100 register pset *A1;
00101 pset_family R;
00102
00103 A1 = sf_sort(A, descend);
00104 cnt = rm_equal(A1, descend);
00105 R = sf_unlist(A1, cnt, A->sf_size);
00106 sf_free(A);
00107 return R;
00108 }
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118 pset_family sf_union(A, B)
00119 INOUT pset_family A, B;
00120 {
00121 int cnt;
00122 pset_family R;
00123 pset *A1 = sf_list(A), *B1 = sf_list(B), *E1;
00124
00125 E1 = ALLOC(pset, MAX(A->count, B->count) + 1);
00126 cnt = rm2_equal(A1, B1, E1, descend);
00127 cnt += rm2_contain(A1, B1) + rm2_contain(B1, A1);
00128 R = sf_merge(A1, B1, E1, cnt, A->sf_size);
00129 sf_free(A); sf_free(B);
00130 return R;
00131 }
00132
00133
00134
00135
00136
00137
00138 pset_family dist_merge(A, mask)
00139 INOUT pset_family A;
00140 IN pset mask;
00141 {
00142 pset *A1;
00143 int cnt;
00144 pset_family R;
00145
00146 (void) set_copy(cube.temp[0], mask);
00147 A1 = sf_sort(A, d1_order);
00148 cnt = d1_rm_equal(A1, d1_order);
00149 R = sf_unlist(A1, cnt, A->sf_size);
00150 sf_free(A);
00151 return R;
00152 }
00153
00154
00155
00156
00157
00158 pset_family d1merge(A, var)
00159 INOUT pset_family A;
00160 IN int var;
00161 {
00162 return dist_merge(A, cube.var_mask[var]);
00163 }
00164
00165
00166
00167
00168 int d1_rm_equal(A1, compare)
00169 register pset *A1;
00170 int (*compare)();
00171 {
00172 register int i, j, dest;
00173
00174 dest = 0;
00175 if (A1[0] != (pcube) NULL) {
00176 for(i = 0, j = 1; A1[j] != (pcube) NULL; j++)
00177 if ( (*compare)(&A1[i], &A1[j]) == 0) {
00178
00179 (void) set_or(A1[i], A1[i], A1[j]);
00180 } else {
00181
00182 A1[dest++] = A1[i];
00183 i = j;
00184 }
00185 A1[dest++] = A1[i];
00186 }
00187 A1[dest] = (pcube) NULL;
00188 return dest;
00189 }
00190
00191
00192
00193 int rm_equal(A1, compare)
00194 INOUT pset *A1;
00195 IN int (*compare)();
00196 {
00197 register pset *p, *pdest = A1;
00198
00199 if (*A1 != NULL) {
00200 for(p = A1+1; *p != NULL; p++)
00201 if ((*compare)(p, p-1) != 0)
00202 *pdest++ = *(p-1);
00203 *pdest++ = *(p-1);
00204 *pdest = NULL;
00205 }
00206 return pdest - A1;
00207 }
00208
00209
00210
00211 int rm_contain(A1)
00212 INOUT pset *A1;
00213 {
00214 register pset *pa, *pb, *pcheck, a, b;
00215 pset *pdest = A1;
00216 int last_size = -1;
00217
00218
00219 for(pa = A1; (a = *pa++) != NULL; ) {
00220
00221 if (SIZE(a) != last_size)
00222 last_size = SIZE(a), pcheck = pdest;
00223 for(pb = A1; pb != pcheck; ) {
00224 b = *pb++;
00225 INLINEsetp_implies(a, b, continue);
00226 goto lnext1;
00227 }
00228
00229 *pdest++ = a;
00230 lnext1: ;
00231 }
00232
00233 *pdest = NULL;
00234 return pdest - A1;
00235 }
00236
00237
00238
00239 int rm_rev_contain(A1)
00240 INOUT pset *A1;
00241 {
00242 register pset *pa, *pb, *pcheck, a, b;
00243 pset *pdest = A1;
00244 int last_size = -1;
00245
00246
00247 for(pa = A1; (a = *pa++) != NULL; ) {
00248
00249 if (SIZE(a) != last_size)
00250 last_size = SIZE(a), pcheck = pdest;
00251 for(pb = A1; pb != pcheck; ) {
00252 b = *pb++;
00253 INLINEsetp_implies(b, a, continue);
00254 goto lnext1;
00255 }
00256
00257 *pdest++ = a;
00258 lnext1: ;
00259 }
00260
00261 *pdest = NULL;
00262 return pdest - A1;
00263 }
00264
00265
00266
00267 int rm2_equal(A1, B1, E1, compare)
00268 INOUT register pset *A1, *B1;
00269 OUT pset *E1;
00270 IN int (*compare)();
00271 {
00272 register pset *pda = A1, *pdb = B1, *pde = E1;
00273
00274
00275 for(; *A1 != NULL && *B1 != NULL; )
00276 switch((*compare)(A1, B1)) {
00277 case -1:
00278 *pda++ = *A1++; break;
00279 case 0:
00280 *pde++ = *A1++; B1++; break;
00281 case 1:
00282 *pdb++ = *B1++; break;
00283 }
00284
00285
00286 while (*A1 != NULL)
00287 *pda++ = *A1++;
00288 while (*B1 != NULL)
00289 *pdb++ = *B1++;
00290 *pda = *pdb = *pde = NULL;
00291
00292 return pde - E1;
00293 }
00294
00295
00296
00297 int rm2_contain(A1, B1)
00298 INOUT pset *A1;
00299 IN pset *B1;
00300 {
00301 register pset *pa, *pb, a, b, *pdest = A1;
00302
00303
00304 for(pa = A1; (a = *pa++) != NULL; ) {
00305
00306 for(pb = B1; (b = *pb++) != NULL && SIZE(b) > SIZE(a); ) {
00307 INLINEsetp_implies(a, b, continue);
00308
00309 goto lnext1;
00310 }
00311
00312 *pdest++ = a;
00313 lnext1: ;
00314 }
00315
00316 *pdest = NULL;
00317 return pdest - A1;
00318 }
00319
00320
00321
00322
00323 pset *sf_sort(A, compare)
00324 IN pset_family A;
00325 IN int (*compare)();
00326 {
00327 register pset p, last, *pdest, *A1;
00328
00329
00330 pdest = A1 = ALLOC(pset, A->count + 1);
00331 foreach_set(A, last, p) {
00332 PUTSIZE(p, set_ord(p));
00333 *pdest++ = p;
00334 }
00335 *pdest = NULL;
00336
00337
00338 qsort((char *) A1, A->count, sizeof(pset), compare);
00339 return A1;
00340 }
00341
00342
00343
00344 pset *sf_list(A)
00345 IN register pset_family A;
00346 {
00347 register pset p, last, *pdest, *A1;
00348
00349
00350 pdest = A1 = ALLOC(pset, A->count + 1);
00351 foreach_set(A, last, p)
00352 *pdest++ = p;
00353 *pdest = NULL;
00354 return A1;
00355 }
00356
00357
00358
00359 pset_family sf_unlist(A1, totcnt, size)
00360 IN pset *A1;
00361 IN int totcnt, size;
00362 {
00363 register pset pr, p, *pa;
00364 pset_family R = sf_new(totcnt, size);
00365
00366 R->count = totcnt;
00367 for(pr = R->data, pa = A1; (p = *pa++) != NULL; pr += R->wsize)
00368 INLINEset_copy(pr, p);
00369 FREE(A1);
00370 return R;
00371 }
00372
00373
00374
00375 pset_family sf_ind_unlist(A1, totcnt, size, row_indices, pfirst)
00376 IN pset *A1;
00377 IN int totcnt, size;
00378 INOUT int *row_indices;
00379 IN register pset pfirst;
00380 {
00381 register pset pr, p, *pa;
00382 register int i, *new_row_indices;
00383 pset_family R = sf_new(totcnt, size);
00384
00385 R->count = totcnt;
00386 new_row_indices = ALLOC(int, totcnt);
00387 for(pr = R->data, pa = A1, i=0; (p = *pa++) != NULL; pr += R->wsize, i++) {
00388 INLINEset_copy(pr, p);
00389 new_row_indices[i] = row_indices[(p - pfirst)/R->wsize];
00390 }
00391 for(i = 0; i < totcnt; i++)
00392 row_indices[i] = new_row_indices[i];
00393 FREE(new_row_indices);
00394 FREE(A1);
00395 return R;
00396 }
00397
00398
00399
00400 pset_family sf_merge(A1, B1, E1, totcnt, size)
00401 INOUT pset *A1, *B1, *E1;
00402 IN int totcnt, size;
00403 {
00404 register pset pr, ps, *pmin, *pmid, *pmax;
00405 pset_family R;
00406 pset *temp[3], *swap;
00407 int i, j, n;
00408
00409
00410 R = sf_new(totcnt, size);
00411 R->count = totcnt;
00412 pr = R->data;
00413
00414
00415 n = 3; temp[0] = A1; temp[1] = B1; temp[2] = E1;
00416 for(i = 0; i < n-1; i++)
00417 for(j = i+1; j < n; j++)
00418 if (desc1(*temp[i], *temp[j]) > 0) {
00419 swap = temp[j];
00420 temp[j] = temp[i];
00421 temp[i] = swap;
00422 }
00423 pmin = temp[0]; pmid = temp[1]; pmax = temp[2];
00424
00425
00426 while (*pmin != (pset) NULL) {
00427 ps = *pmin++;
00428 INLINEset_copy(pr, ps);
00429 pr += R->wsize;
00430 if (desc1(*pmin, *pmax) > 0) {
00431 swap = pmax; pmax = pmin; pmin = pmid; pmid = swap;
00432 } else if (desc1(*pmin, *pmid) > 0) {
00433 swap = pmin; pmin = pmid; pmid = swap;
00434 }
00435 }
00436
00437 FREE(A1);
00438 FREE(B1);
00439 FREE(E1);
00440 return R;
00441 }