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

  Synopsis    [Threads all the nodes of a search tree into a linear list.]

  Description [Threads all the nodes of a search tree into a linear
  list. For each node of the search tree, the "left" child, if non-null, has
  a lower address than its parent, and the "right" child, if non-null, has a
  higher address than its parent.
  The list is sorted in order of increasing addresses. The search
  tree is destroyed as a result of this operation. The last element of
  the linear list is made to point to the address passed in list. Each
  node if the search tree is a linearly-linked list of nodes from the
  same memory page (as defined in DD_PAGE_MASK). When a node is added to
  the linear list, all the elements of the linked list are added.]

  SideEffects [The search tree is destroyed as a result of this operation.]

  SeeAlso     [cuddOrderedInsert]

******************************************************************************/
Function
Synopsis    [Threads all the nodes of a search tree into a linear list.]

Description [Threads all the nodes of a search tree into a linear
list. For each node of the search tree, the "left" child, if non-null, has
a lower address than its parent, and the "right" child, if non-null, has a
higher address than its parent.
The list is sorted in order of increasing addresses. The search
tree is destroyed as a result of this operation. The last element of
the linear list is made to point to the address passed in list. Each
node if the search tree is a linearly-linked list of nodes from the
same memory page (as defined in DD_PAGE_MASK). When a node is added to
the linear list, all the elements of the linked list are added.]

SideEffects [The search tree is destroyed as a result of this operation.]


Function Synopsis [ Threads all the nodes of a search tree into a linear list . ] Description [ Threads all the nodes of a search tree into a linear list . For each node of the search tree the " left " child if non - null has a lower address than its parent and the " right " child if non - null has a higher address than its parent . The list is sorted in order of increasing addresses . The search tree is destroyed as a result of this operation . The last element of the linear list is made to point to the address passed in list . Each node if the search tree is a linearly - linked list of nodes from the same memory page ( as defined in DD_PAGE_MASK ) . When a node is added to the linear list all the elements of the linked list are added . ] SideEffects [ The search tree is destroyed as a result of this operation . ]
static DdNode *
cuddOrderedThread(
  DdNode * root,
  DdNode * list)
{
    DdNode *current, *next, *prev, *end;
    current = root;
    *((DdNodePtr *) current) = NULL;
    while (current != NULL) {
        if (DD_RIGHT(current) != NULL) {
            next = DD_RIGHT(current);
            DD_RIGHT(current) = NULL;
            *((DdNodePtr *)next) = current;
            current = next;
        } else {
            prev = *((DdNodePtr *) current); 
            for (end = current; DD_NEXT(end) != NULL; end = DD_NEXT(end));
            DD_NEXT(end) = list; 
            list = current;   
            if (DD_LEFT(current) != NULL) {
                next = DD_LEFT(current);
                *((DdNodePtr *) next) = prev;
                current = next;
            } else {
                current = prev;
            }
        }
    }
    return(list);
}
static DdNode * cuddOrderedThread ( DdNode * root , DdNode * list ) { DdNode * current , * next , * prev , * end ; current = root ; * ( ( DdNodePtr * ) current ) = NULL ; while ( current != NULL ) { if ( DD_RIGHT ( current ) != NULL ) { next = DD_RIGHT ( current ) ; DD_RIGHT ( current ) = NULL ; * ( ( DdNodePtr * ) next ) = current ; current = next ; } else { prev = * ( ( DdNodePtr * ) current ) ; for ( end = current ; DD_NEXT ( end ) != NULL ; end = DD_NEXT ( end ) ) ; DD_NEXT ( end ) = list ; list = current ; if ( DD_LEFT ( current ) != NULL ) { next = DD_LEFT ( current ) ; * ( ( DdNodePtr * ) next ) = prev ; current = next ; } else { current = prev ; } } } return ( list ) ; }
Function
Synopsis    [Threads all the nodes of a search tree into a linear list.]
Function Synopsis [ Threads all the nodes of a search tree into a linear list . ]
/* The first word in the node is used to implement a stack that holds
    ** the nodes from the root of the tree to the current node. Here we
    ** put the root of the tree at the bottom of the stack.
    */ /* If possible, we follow the "right" link. Eventually we'll
            ** find the node with the largest address in the current tree.
            ** In this phase we use the first word of a node to implemen
            ** a stack of the nodes on the path from the root to "current".
            ** Also, we disconnect the "right" pointers to indicate that
            ** we have already followed them.
            */ /* We can't proceed along the "right" links any further.
            ** Hence "current" is the largest element in the current tree.
            ** We make this node the new head of "list". (Repeating this
            ** operation until the tree is empty yields the desired linear
            ** threading of all nodes.)
            */ /* save prev node on stack in prev */ /* Traverse the linked list of current until the end. */ /* attach "list" at end and make */ /* "current" the new head of "list" */ /* Now, if current has a "left" child, we push it on the stack.
            ** Otherwise, we just continue with the parent of "current".
            */