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

  Synopsis    [Inserts a new key in a level queue.]

  Description [Inserts a new key in a level queue. A new entry is
  created in the queue only if the node is not already
  enqueued. Returns a pointer to the queue item if successful; NULL
  otherwise.]

  SideEffects [None]

  SeeAlso     [cuddLevelQueueInit cuddLevelQueueDequeue]

******************************************************************************/
Function
Synopsis    [Inserts a new key in a level queue.]

Description [Inserts a new key in a level queue. A new entry is
created in the queue only if the node is not already
enqueued. Returns a pointer to the queue item if successful; NULL
otherwise.]




Function Synopsis [ Inserts a new key in a level queue . ] Description [ Inserts a new key in a level queue . A new entry is created in the queue only if the node is not already enqueued . Returns a pointer to the queue item if successful ; NULL otherwise . ]
void *
cuddLevelQueueEnqueue(
  DdLevelQueue * queue ,
  void * key ,
  int  level )
{
    int plevel;
    DdQueueItem *item;
#ifdef DD_DEBUG
    assert(level < queue->levels);
#endif
    item = hashLookup(queue,key);
    if (item != NULL) return(item);
    if (queue->freelist == NULL) {
        item = (DdQueueItem *) ABC_ALLOC(char, queue->itemsize);
        if (item == NULL)
            return(NULL);
    } else {
        item = queue->freelist;
        queue->freelist = item->next;
    }
    memset(item, 0, queue->itemsize);
    item->key = key;
    queue->size++;
    if (queue->last[level]) {
        item->next = queue->last[level]->next;
        queue->last[level]->next = item;
    } else {
        plevel = level;
        while (plevel != 0 && queue->last[plevel] == NULL)
            plevel--;
        if (queue->last[plevel] == NULL) {
            item->next = (DdQueueItem *) queue->first;
            queue->first = item;
        } else {
            item->next = queue->last[plevel]->next;
            queue->last[plevel]->next = item;
        }
    }
    queue->last[level] = item;
    if (hashInsert(queue,item) == 0) {
        return(NULL);
    }
    return(item);
}
void * cuddLevelQueueEnqueue ( DdLevelQueue * queue , void * key , int level ) { int plevel ; DdQueueItem * item ; #ifdef DD_DEBUG assert ( level < queue -> levels ) ; #endif item = hashLookup ( queue , key ) ; if ( item != NULL ) return ( item ) ; if ( queue -> freelist == NULL ) { item = ( DdQueueItem * ) ABC_ALLOC ( char , queue -> itemsize ) ; if ( item == NULL ) return ( NULL ) ; } else { item = queue -> freelist ; queue -> freelist = item -> next ; } memset ( item , 0 , queue -> itemsize ) ; item -> key = key ; queue -> size ++ ; if ( queue -> last [ level ] ) { item -> next = queue -> last [ level ] -> next ; queue -> last [ level ] -> next = item ; } else { plevel = level ; while ( plevel != 0 && queue -> last [ plevel ] == NULL ) plevel -- ; if ( queue -> last [ plevel ] == NULL ) { item -> next = ( DdQueueItem * ) queue -> first ; queue -> first = item ; } else { item -> next = queue -> last [ plevel ] -> next ; queue -> last [ plevel ] -> next = item ; } } queue -> last [ level ] = item ; if ( hashInsert ( queue , item ) == 0 ) { return ( NULL ) ; } return ( item ) ; }
Function
Synopsis    [Inserts a new key in a level queue.]
Function Synopsis [ Inserts a new key in a level queue . ]
/* level queue */ /* key to be enqueued */ /* level at which to insert */ /* Check whether entry for this node exists. */ /* Get a free item from either the free list or the memory manager. */ /* Initialize. */ /* Update stats. */ /* There are already items for this level in the queue. */ /* There are no items at the current level.  Look for the first
        ** non-empty level preceeding this one. */ /* No element precedes this one in the queue. */ /* Insert entry for the key in the hash table. */