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

  Synopsis    [Checks the unique table for the existence of a constant node.]

  Description [Checks the unique table for the existence of a constant node.
  If it does not exist, it creates a new one.  Does not
  modify the reference count of whatever is returned.  A newly created
  internal node comes back with a reference count 0.  Returns a
  pointer to the new node.]

  SideEffects [None]

******************************************************************************/
Function
Synopsis    [Checks the unique table for the existence of a constant node.]

Description [Checks the unique table for the existence of a constant node.
If it does not exist, it creates a new one.  Does not
modify the reference count of whatever is returned.  A newly created
internal node comes back with a reference count 0.  Returns a
pointer to the new node.]


Function Synopsis [ Checks the unique table for the existence of a constant node . ] Description [ Checks the unique table for the existence of a constant node . If it does not exist it creates a new one . Does not modify the reference count of whatever is returned . A newly created internal node comes back with a reference count 0 . Returns a pointer to the new node . ]
DdNode *
cuddUniqueConst(
  DdManager * unique,
  CUDD_VALUE_TYPE  value)
{
    int pos;
    DdNodePtr *nodelist;
    DdNode *looking;
    hack split;
#ifdef DD_UNIQUE_PROFILE
    unique->uniqueLookUps++;
#endif
    if (unique->constants.keys > unique->constants.maxKeys) {
        if (unique->gcEnabled && ((unique->dead > unique->minDead) ||
        (10 * unique->constants.dead > 9 * unique->constants.keys))) {  
            (void) cuddGarbageCollect(unique,1);
        } else {
            cuddRehash(unique,CUDD_CONST_INDEX);
        }
    }
    cuddAdjust(value); 
    if (ddAbs(value) < unique->epsilon) {
        value = 0.0;
    }
    split.value = value;
    pos = ddHash(split.bits[0], split.bits[1], unique->constants.shift);
    nodelist = unique->constants.nodelist;
    looking = nodelist[pos];
    while (looking != NULL) {
        if (looking->type.value == value ||
        ddEqualVal(looking->type.value,value,unique->epsilon)) {
            if (looking->ref == 0) {
                cuddReclaim(unique,looking);
            }
            return(looking);
        }
        looking = looking->next;
#ifdef DD_UNIQUE_PROFILE
        unique->uniqueLinks++;
#endif
    }
    unique->keys++;
    unique->constants.keys++;
    looking = cuddAllocNode(unique);
    if (looking == NULL) return(NULL);
    looking->index = CUDD_CONST_INDEX;
    looking->type.value = value;
    looking->next = nodelist[pos];
    nodelist[pos] = looking;
    return(looking);
}
DdNode * cuddUniqueConst ( DdManager * unique , CUDD_VALUE_TYPE value ) { int pos ; DdNodePtr * nodelist ; DdNode * looking ; hack split ; #ifdef DD_UNIQUE_PROFILE unique -> uniqueLookUps ++ ; #endif if ( unique -> constants . keys > unique -> constants . maxKeys ) { if ( unique -> gcEnabled && ( ( unique -> dead > unique -> minDead ) || ( 10 * unique -> constants . dead > 9 * unique -> constants . keys ) ) ) { ( void ) cuddGarbageCollect ( unique , 1 ) ; } else { cuddRehash ( unique , CUDD_CONST_INDEX ) ; } } cuddAdjust ( value ) ; if ( ddAbs ( value ) < unique -> epsilon ) { value = 0.0 ; } split . value = value ; pos = ddHash ( split . bits [ 0 ] , split . bits [ 1 ] , unique -> constants . shift ) ; nodelist = unique -> constants . nodelist ; looking = nodelist [ pos ] ; while ( looking != NULL ) { if ( looking -> type . value == value || ddEqualVal ( looking -> type . value , value , unique -> epsilon ) ) { if ( looking -> ref == 0 ) { cuddReclaim ( unique , looking ) ; } return ( looking ) ; } looking = looking -> next ; #ifdef DD_UNIQUE_PROFILE unique -> uniqueLinks ++ ; #endif } unique -> keys ++ ; unique -> constants . keys ++ ; looking = cuddAllocNode ( unique ) ; if ( looking == NULL ) return ( NULL ) ; looking -> index = CUDD_CONST_INDEX ; looking -> type . value = value ; looking -> next = nodelist [ pos ] ; nodelist [ pos ] = looking ; return ( looking ) ; }
Function
Synopsis    [Checks the unique table for the existence of a constant node.]
Function Synopsis [ Checks the unique table for the existence of a constant node . ]
/* too many dead */ /* for the case of crippled infinities */ /* Here we compare values both for equality and for difference less
     * than epsilon. The first comparison is required when values are
     * infinite, since Infinity - Infinity is NaN and NaN < X is 0 for
     * every X.
     */