/* NAME {* fdd\_scanset *} SECTION {* fdd *} SHORT {* scans a variable set *} PROTO {* int fdd_scanset(BDD r, int **varset, int *varnum) *} DESCR {* Scans the BDD {\tt r} to find all occurences of FDD variables and then stores these in {\tt varset}. {\tt varset} will be set to point to an array of size {\tt varnum} which will contain the indices of the found FDD variables. It is the users responsibility to free {\tt varset} after use. *} RETURN {* Zero on success or a negative error code on error. *} ALSO {* fdd\_makeset *} */ int fdd_scanset(BDD r, int **varset, int *varnum) { int *fv, fn; int num,n,m,i; if (!bddrunning) return bdd_error(BDD_RUNNING); if ((n=bdd_scanset(r, &fv, &fn)) < 0) return n; for (n=0,num=0 ; n<fdvarnum ; n++) { int found=0; for (m=0 ; m<domain[n].binsize && !found ; m++) { for (i=0 ; i<fn && !found ; i++) if (domain[n].ivar[m] == fv[i]) { num++; found=1; } } } if ((*varset=(int*)malloc(sizeof(int)*num)) == NULL) return bdd_error(BDD_MEMORY); for (n=0,num=0 ; n<fdvarnum ; n++) { int found=0; for (m=0 ; m<domain[n].binsize && !found ; m++) { for (i=0 ; i<fn && !found ; i++) if (domain[n].ivar[m] == fv[i]) { (*varset)[num++] = n; found=1; } } } *varnum = num; return 0; }
/* ML type: varSet -> varnum vector */ EXTERNML value mlbdd_bdd_scanset(value varset) { value result; int *v, n, i; if(bdd_scanset(Bdd_val(varset), &v, &n)) { RAISE_DOMAIN; return Val_unit; /* unreachable, here to prevent warnings */ } else { if(n == 0) result = Atom(0); /* The empty vector */ else { result = n < Max_young_wosize ? alloc(n, 0) : alloc_shr(n, 0); for (i = 0; i < n; i++) { Field(result, i) = Val_long(v[i]); } free(v); } } return result; }