src/misc/espresso/contain.c File Reference

#include "espresso.h"
Include dependency graph for contain.c:

Go to the source code of this file.

Functions

pset_family sf_contain (INOUT pset_family A)
pset_family sf_rev_contain (INOUT pset_family A)
pset_family sf_ind_contain (INOUT pset_family A, INOUT int *row_indices)
pset_family sf_dupl (INOUT pset_family A)
pset_family sf_union (INOUT pset_family A, INOUT pset_family B)
pset_family dist_merge (INOUT pset_family A, IN pset mask)
pset_family d1merge (INOUT pset_family A, IN int var)
int d1_rm_equal (pset *A1, int(*compare)())
int rm_equal (INOUT pset *A1, IN int(*compare)())
int rm_contain (INOUT pset *A1)
int rm_rev_contain (INOUT pset *A1)
int rm2_equal (INOUT register pset *A1, INOUT register pset *B1, OUT pset *E1, IN int(*compare)())
int rm2_contain (INOUT pset *A1, IN pset *B1)
psetsf_sort (IN pset_family A, IN int(*compare)())
psetsf_list (IN register pset_family A)
pset_family sf_unlist (IN pset *A1, IN int totcnt, IN int size)
pset_family sf_ind_unlist (IN pset *A1, IN int totcnt, IN int size, INOUT int *row_indices, IN register pset pfirst)
pset_family sf_merge (INOUT pset *A1, INOUT pset *B1, INOUT pset *E1, IN int totcnt, IN int size)

Function Documentation

int d1_rm_equal ( pset A1,
int (*)()  compare 
)

Definition at line 168 of file contain.c.

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                 /* if sets are equal (under the mask) merge them */
00179                 (void) set_or(A1[i], A1[i], A1[j]);
00180             } else {
00181                 /* sets are unequal, so save the set i */
00182                 A1[dest++] = A1[i];
00183                 i = j;
00184             }
00185         A1[dest++] = A1[i];
00186     }
00187     A1[dest] = (pcube) NULL;
00188     return dest;
00189 }

pset_family d1merge ( INOUT pset_family  A,
IN int  var 
)

Definition at line 158 of file contain.c.

00161 {
00162     return dist_merge(A, cube.var_mask[var]);
00163 }

pset_family dist_merge ( INOUT pset_family  A,
IN pset  mask 
)

Definition at line 138 of file contain.c.

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 }

int rm2_contain ( INOUT pset A1,
IN pset B1 
)

Definition at line 297 of file contain.c.

00300 {
00301     register pset *pa, *pb, a, b, *pdest = A1;
00302 
00303     /* for each set in the first array ... */
00304     for(pa = A1; (a = *pa++) != NULL; ) {
00305         /* for each set in the second array which is larger ... */
00306         for(pb = B1; (b = *pb++) != NULL && SIZE(b) > SIZE(a); ) {
00307             INLINEsetp_implies(a, b, /* when_false => */ continue);
00308             /* set was contained in some set of B, so don't save pointer */
00309             goto lnext1;
00310         }
00311         /* set wasn't contained in any set of B, so save the pointer */
00312         *pdest++ = a;
00313     lnext1: ;
00314     }
00315 
00316     *pdest = NULL;                      /* sentinel */
00317     return pdest - A1;                  /* # elements in A1 */
00318 }

int rm2_equal ( INOUT register pset A1,
INOUT register pset B1,
OUT pset E1,
IN int (*)()  compare 
)

Definition at line 267 of file contain.c.

00271 {
00272     register pset *pda = A1, *pdb = B1, *pde = E1;
00273 
00274     /* Walk through the arrays advancing pointer to larger cube */
00275     for(; *A1 != NULL && *B1 != NULL; )
00276         switch((*compare)(A1, B1)) {
00277             case -1:    /* "a" comes before "b" */
00278                 *pda++ = *A1++; break;
00279             case 0:     /* equal cubes */
00280                 *pde++ = *A1++; B1++; break;
00281             case 1:     /* "a" is to follow "b" */
00282                 *pdb++ = *B1++; break;
00283         }
00284 
00285     /* Finish moving down the pointers of A and B */
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 }

int rm_contain ( INOUT pset A1  ) 

Definition at line 211 of file contain.c.

00213 {
00214     register pset *pa, *pb, *pcheck, a, b;
00215     pset *pdest = A1;
00216     int last_size = -1;
00217 
00218     /* Loop for all cubes of A1 */
00219     for(pa = A1; (a = *pa++) != NULL; ) {
00220         /* Update the check pointer if the size has changed */
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, /* when_false => */ continue);
00226             goto lnext1;
00227         }
00228         /* set a was not contained by some larger set, so save it */
00229         *pdest++ = a;
00230     lnext1: ;
00231     }
00232 
00233     *pdest = NULL;
00234     return pdest - A1;
00235 }

int rm_equal ( INOUT pset A1,
IN int (*)()  compare 
)

Definition at line 193 of file contain.c.

00196 {
00197     register pset *p, *pdest = A1;
00198 
00199     if (*A1 != NULL) {                  /* If more than one set */
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 }

int rm_rev_contain ( INOUT pset A1  ) 

Definition at line 239 of file contain.c.

00241 {
00242     register pset *pa, *pb, *pcheck, a, b;
00243     pset *pdest = A1;
00244     int last_size = -1;
00245 
00246     /* Loop for all cubes of A1 */
00247     for(pa = A1; (a = *pa++) != NULL; ) {
00248         /* Update the check pointer if the size has changed */
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, /* when_false => */ continue);
00254             goto lnext1;
00255         }
00256         /* the set a did not contain some smaller set, so save it */
00257         *pdest++ = a;
00258     lnext1: ;
00259     }
00260 
00261     *pdest = NULL;
00262     return pdest - A1;
00263 }

pset_family sf_contain ( INOUT pset_family  A  ) 

Definition at line 34 of file contain.c.

00036 {
00037     int cnt;
00038     pset *A1;
00039     pset_family R;
00040 
00041     A1 = sf_sort(A, descend);           /* sort into descending order */
00042     cnt = rm_equal(A1, descend);        /* remove duplicates */
00043     cnt = rm_contain(A1);               /* remove contained sets */
00044     R = sf_unlist(A1, cnt, A->sf_size); /* recreate the set family */
00045     sf_free(A);
00046     return R;
00047 }

pset_family sf_dupl ( INOUT pset_family  A  ) 

Definition at line 96 of file contain.c.

00098 {
00099     register int cnt;
00100     register pset *A1;
00101     pset_family R;
00102 
00103     A1 = sf_sort(A, descend);           /* sort the set family */
00104     cnt = rm_equal(A1, descend);        /* remove duplicates */
00105     R = sf_unlist(A1, cnt, A->sf_size); /* recreate the set family */
00106     sf_free(A);
00107     return R;
00108 }

pset_family sf_ind_contain ( INOUT pset_family  A,
INOUT int *  row_indices 
)

Definition at line 78 of file contain.c.

00081 {
00082     int cnt;
00083     pset *A1;
00084     pset_family R;
00085 
00086     A1 = sf_sort(A, descend);           /* sort into descending order */
00087     cnt = rm_equal(A1, descend);        /* remove duplicates */
00088     cnt = rm_contain(A1);               /* remove contained sets */
00089     R = sf_ind_unlist(A1, cnt, A->sf_size, row_indices, A->data);
00090     sf_free(A);
00091     return R;
00092 }

pset_family sf_ind_unlist ( IN pset A1,
IN int  totcnt,
IN int  size,
INOUT int *  row_indices,
IN register pset  pfirst 
)

Definition at line 375 of file contain.c.

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 }

pset* sf_list ( IN register pset_family  A  ) 

Definition at line 344 of file contain.c.

00346 {
00347     register pset p, last, *pdest, *A1;
00348 
00349     /* Create a single array pointing to each cube of A */
00350     pdest = A1 = ALLOC(pset, A->count + 1);
00351     foreach_set(A, last, p)
00352         *pdest++ = p;                   /* save the pointer */
00353     *pdest = NULL;                      /* Sentinel */
00354     return A1;
00355 }

pset_family sf_merge ( INOUT pset A1,
INOUT pset B1,
INOUT pset E1,
IN int  totcnt,
IN int  size 
)

Definition at line 400 of file contain.c.

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     /* Allocate the result set_family */
00410     R = sf_new(totcnt, size);
00411     R->count = totcnt;
00412     pr = R->data;
00413 
00414     /* Quick bubble sort to order the top member of the three arrays */
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     /* Save the minimum element, then update pmin, pmid, pmax */
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 }

pset_family sf_rev_contain ( INOUT pset_family  A  ) 

Definition at line 55 of file contain.c.

00057 {
00058     int cnt;
00059     pset *A1;
00060     pset_family R;
00061 
00062     A1 = sf_sort(A, ascend);            /* sort into ascending order */
00063     cnt = rm_equal(A1, ascend);         /* remove duplicates */
00064     cnt = rm_rev_contain(A1);           /* remove containing sets */
00065     R = sf_unlist(A1, cnt, A->sf_size); /* recreate the set family */
00066     sf_free(A);
00067     return R;
00068 }

pset* sf_sort ( IN pset_family  A,
IN int (*)()  compare 
)

Definition at line 323 of file contain.c.

00326 {
00327     register pset p, last, *pdest, *A1;
00328 
00329     /* Create a single array pointing to each cube of A */
00330     pdest = A1 = ALLOC(pset, A->count + 1);
00331     foreach_set(A, last, p) {
00332         PUTSIZE(p, set_ord(p));         /* compute the set size */
00333         *pdest++ = p;                   /* save the pointer */
00334     }
00335     *pdest = NULL;                      /* Sentinel -- never seen by sort */
00336 
00337     /* Sort cubes by size */
00338     qsort((char *) A1, A->count, sizeof(pset), compare);
00339     return A1;
00340 }

pset_family sf_union ( INOUT pset_family  A,
INOUT pset_family  B 
)

Definition at line 118 of file contain.c.

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 }

pset_family sf_unlist ( IN pset A1,
IN int  totcnt,
IN int  size 
)

Definition at line 359 of file contain.c.

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 }


Generated on Tue Jan 5 12:19:09 2010 for abc70930 by  doxygen 1.6.1