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

  Synopsis    [Looks up a key in a hash table.]

  Description [Looks up a key consisting of more than three pointers
  in a hash table.  Returns the value associated to the key if there
  is an entry for the given key in the table; NULL otherwise. If the
  entry is present, its reference counter is decremented if not
  saturated. If the counter reaches 0, the value of the entry is
  dereferenced, and the entry is returned to the free list.]

  SideEffects [None]

  SeeAlso     [cuddHashTableLookup1 cuddHashTableLookup2 cuddHashTableLookup3
  cuddHashTableInsert]

******************************************************************************/
Function
Synopsis    [Looks up a key in a hash table.]

Description [Looks up a key consisting of more than three pointers
in a hash table.  Returns the value associated to the key if there
is an entry for the given key in the table; NULL otherwise. If the
entry is present, its reference counter is decremented if not
saturated. If the counter reaches 0, the value of the entry is
dereferenced, and the entry is returned to the free list.]




Function Synopsis [ Looks up a key in a hash table . ] Description [ Looks up a key consisting of more than three pointers in a hash table . Returns the value associated to the key if there is an entry for the given key in the table ; NULL otherwise . If the entry is present its reference counter is decremented if not saturated . If the counter reaches 0 the value of the entry is dereferenced and the entry is returned to the free list . ]
DdNode *
cuddHashTableLookup(
  DdHashTable * hash,
  DdNodePtr * key)
{
    unsigned int posn;
    DdHashItem *item, *prev;
    unsigned int i, keysize;
#ifdef DD_DEBUG
    assert(hash->keysize > 3);
#endif
    posn = ddLCHash(key,hash->keysize,hash->shift);
    item = hash->bucket[posn];
    prev = NULL;
    keysize = hash->keysize;
    while (item != NULL) {
        DdNodePtr *key2 = item->key;
        int equal = 1;
        for (i = 0; i < keysize; i++) {
            if (key[i] != key2[i]) {
                equal = 0;
                break;
            }
        }
        if (equal) {
            DdNode *value = item->value;
            cuddSatDec(item->count);
            if (item->count == 0) {
                cuddDeref(value);
                if (prev == NULL) {
                    hash->bucket[posn] = item->next;
                } else {
                    prev->next = item->next;
                }
                item->next = hash->nextFree;
                hash->nextFree = item;
                hash->size--;
            }
            return(value);
        }
        prev = item;
        item = item->next;
    }
    return(NULL);
}
DdNode * cuddHashTableLookup ( DdHashTable * hash , DdNodePtr * key ) { unsigned int posn ; DdHashItem * item , * prev ; unsigned int i , keysize ; #ifdef DD_DEBUG assert ( hash -> keysize > 3 ) ; #endif posn = ddLCHash ( key , hash -> keysize , hash -> shift ) ; item = hash -> bucket [ posn ] ; prev = NULL ; keysize = hash -> keysize ; while ( item != NULL ) { DdNodePtr * key2 = item -> key ; int equal = 1 ; for ( i = 0 ; i < keysize ; i ++ ) { if ( key [ i ] != key2 [ i ] ) { equal = 0 ; break ; } } if ( equal ) { DdNode * value = item -> value ; cuddSatDec ( item -> count ) ; if ( item -> count == 0 ) { cuddDeref ( value ) ; if ( prev == NULL ) { hash -> bucket [ posn ] = item -> next ; } else { prev -> next = item -> next ; } item -> next = hash -> nextFree ; hash -> nextFree = item ; hash -> size -- ; } return ( value ) ; } prev = item ; item = item -> next ; } return ( NULL ) ; }
Function
Synopsis    [Looks up a key in a hash table.]
Function Synopsis [ Looks up a key in a hash table . ]