abc/src/bdd/cudd/cuddApa.c
/**Function********************************************************************

  Synopsis    [Counts the number of minterms of a DD.]

  Description [Counts the number of minterms of a DD. The function is
  assumed to depend on nvars variables. The minterm count is
  represented as an arbitrary precision unsigned integer, to allow for
  any number of variables CUDD supports.  Returns a pointer to the
  array representing the number of minterms of the function rooted at
  node if successful; NULL otherwise.]

  SideEffects [The number of digits of the result is returned in
  parameter <code>digits</code>.]

  SeeAlso     [Cudd_CountMinterm]

******************************************************************************/
Function
Synopsis    [Counts the number of minterms of a DD.]

Description [Counts the number of minterms of a DD. The function is
assumed to depend on nvars variables. The minterm count is
represented as an arbitrary precision unsigned integer, to allow for
any number of variables CUDD supports.  Returns a pointer to the
array representing the number of minterms of the function rooted at
node if successful; NULL otherwise.]

SideEffects [The number of digits of the result is returned in
parameter digits.]


Function Synopsis [ Counts the number of minterms of a DD . ] Description [ Counts the number of minterms of a DD . The function is assumed to depend on nvars variables . The minterm count is represented as an arbitrary precision unsigned integer to allow for any number of variables CUDD supports . Returns a pointer to the array representing the number of minterms of the function rooted at node if successful ; NULL otherwise . ] SideEffects [ The number of digits of the result is returned in parameter digits . ]
DdApaNumber
Cudd_ApaCountMinterm(
  DdManager * manager,
  DdNode * node,
  int  nvars,
  int * digits)
{
    DdApaNumber max, min;
    st__table    *table;
    DdApaNumber i,count;
    background = manager->background;
    zero = Cudd_Not(manager->one);
    *digits = Cudd_ApaNumberOfDigits(nvars+1);
    max = Cudd_NewApaNumber(*digits);
    if (max == NULL) {
        return(NULL);
    }
    Cudd_ApaPowerOfTwo(*digits,max,nvars);
    min = Cudd_NewApaNumber(*digits);
    if (min == NULL) {
        ABC_FREE(max);
        return(NULL);
    }
    Cudd_ApaSetToLiteral(*digits,min,0);
    table = st__init_table( st__ptrcmp, st__ptrhash);
    if (table == NULL) {
        ABC_FREE(max);
        ABC_FREE(min);
        return(NULL);
    }
    i = cuddApaCountMintermAux(Cudd_Regular(node),*digits,max,min,table);
    if (i == NULL) {
        ABC_FREE(max);
        ABC_FREE(min);
        st__foreach(table, cuddApaStCountfree, NULL);
        st__free_table(table);
        return(NULL);
    }
    count = Cudd_NewApaNumber(*digits);
    if (count == NULL) {
        ABC_FREE(max);
        ABC_FREE(min);
        st__foreach(table, cuddApaStCountfree, NULL);
        st__free_table(table);
        if (Cudd_Regular(node)->ref == 1) ABC_FREE(i);
        return(NULL);
    }
    if (Cudd_IsComplement(node)) {
        (void) Cudd_ApaSubtract(*digits,max,i,count);
    } else {
        Cudd_ApaCopy(*digits,i,count);
    }
    ABC_FREE(max);
    ABC_FREE(min);
    st__foreach(table, cuddApaStCountfree, NULL);
    st__free_table(table);
    if (Cudd_Regular(node)->ref == 1) ABC_FREE(i);
    return(count);
}
DdApaNumber Cudd_ApaCountMinterm ( DdManager * manager , DdNode * node , int nvars , int * digits ) { DdApaNumber max , min ; st__table * table ; DdApaNumber i , count ; background = manager -> background ; zero = Cudd_Not ( manager -> one ) ; * digits = Cudd_ApaNumberOfDigits ( nvars + 1 ) ; max = Cudd_NewApaNumber ( * digits ) ; if ( max == NULL ) { return ( NULL ) ; } Cudd_ApaPowerOfTwo ( * digits , max , nvars ) ; min = Cudd_NewApaNumber ( * digits ) ; if ( min == NULL ) { ABC_FREE ( max ) ; return ( NULL ) ; } Cudd_ApaSetToLiteral ( * digits , min , 0 ) ; table = st__init_table ( st__ptrcmp , st__ptrhash ) ; if ( table == NULL ) { ABC_FREE ( max ) ; ABC_FREE ( min ) ; return ( NULL ) ; } i = cuddApaCountMintermAux ( Cudd_Regular ( node ) , * digits , max , min , table ) ; if ( i == NULL ) { ABC_FREE ( max ) ; ABC_FREE ( min ) ; st__foreach ( table , cuddApaStCountfree , NULL ) ; st__free_table ( table ) ; return ( NULL ) ; } count = Cudd_NewApaNumber ( * digits ) ; if ( count == NULL ) { ABC_FREE ( max ) ; ABC_FREE ( min ) ; st__foreach ( table , cuddApaStCountfree , NULL ) ; st__free_table ( table ) ; if ( Cudd_Regular ( node ) -> ref == 1 ) ABC_FREE ( i ) ; return ( NULL ) ; } if ( Cudd_IsComplement ( node ) ) { ( void ) Cudd_ApaSubtract ( * digits , max , i , count ) ; } else { Cudd_ApaCopy ( * digits , i , count ) ; } ABC_FREE ( max ) ; ABC_FREE ( min ) ; st__foreach ( table , cuddApaStCountfree , NULL ) ; st__free_table ( table ) ; if ( Cudd_Regular ( node ) -> ref == 1 ) ABC_FREE ( i ) ; return ( count ) ; }
Function
Synopsis    [Counts the number of minterms of a DD.]
Function Synopsis [ Counts the number of minterms of a DD . ]