abc/src/bdd/mtr/mtrBasic.c
/**Function********************************************************************

  Synopsis    [Makes a copy of tree.]

  Description [Makes a copy of tree. If parameter expansion is greater
  than 1, it will expand the tree by that factor. It is an error for
  expansion to be less than 1. Returns a pointer to the copy if
  successful; NULL otherwise.]

  SideEffects [None]

  SeeAlso     [Mtr_InitTree]

******************************************************************************/
Function
Synopsis    [Makes a copy of tree.]

Description [Makes a copy of tree. If parameter expansion is greater
than 1, it will expand the tree by that factor. It is an error for
expansion to be less than 1. Returns a pointer to the copy if
successful; NULL otherwise.]




Function Synopsis [ Makes a copy of tree . ] Description [ Makes a copy of tree . If parameter expansion is greater than 1 it will expand the tree by that factor . It is an error for expansion to be less than 1 . Returns a pointer to the copy if successful ; NULL otherwise . ]
MtrNode *
Mtr_CopyTree(
  MtrNode * node,
  int  expansion)
{
    MtrNode *copy;
    if (node == NULL) return(NULL);
    if (expansion < 1) return(NULL);
    copy = Mtr_AllocNode();
    if (copy == NULL) return(NULL);
    copy->parent = copy->elder = copy->child = copy->younger = NULL;
    if (node->child != NULL) {
        copy->child = Mtr_CopyTree(node->child, expansion);
        if (copy->child == NULL) {
            Mtr_DeallocNode(copy);
            return(NULL);
        }
    }
    if (node->younger != NULL) {
        copy->younger = Mtr_CopyTree(node->younger, expansion);
        if (copy->younger == NULL) {
            Mtr_FreeTree(copy);
            return(NULL);
        }
    }
    copy->flags = node->flags;
    copy->low = node->low * expansion;
    copy->size = node->size * expansion;
    copy->index = node->index * expansion;
    if (copy->younger) copy->younger->elder = copy;
    if (copy->child) {
        MtrNode *auxnode = copy->child;
        while (auxnode != NULL) {
            auxnode->parent = copy;
            auxnode = auxnode->younger;
        }
    }
    return(copy);
}
MtrNode * Mtr_CopyTree ( MtrNode * node , int expansion ) { MtrNode * copy ; if ( node == NULL ) return ( NULL ) ; if ( expansion < 1 ) return ( NULL ) ; copy = Mtr_AllocNode ( ) ; if ( copy == NULL ) return ( NULL ) ; copy -> parent = copy -> elder = copy -> child = copy -> younger = NULL ; if ( node -> child != NULL ) { copy -> child = Mtr_CopyTree ( node -> child , expansion ) ; if ( copy -> child == NULL ) { Mtr_DeallocNode ( copy ) ; return ( NULL ) ; } } if ( node -> younger != NULL ) { copy -> younger = Mtr_CopyTree ( node -> younger , expansion ) ; if ( copy -> younger == NULL ) { Mtr_FreeTree ( copy ) ; return ( NULL ) ; } } copy -> flags = node -> flags ; copy -> low = node -> low * expansion ; copy -> size = node -> size * expansion ; copy -> index = node -> index * expansion ; if ( copy -> younger ) copy -> younger -> elder = copy ; if ( copy -> child ) { MtrNode * auxnode = copy -> child ; while ( auxnode != NULL ) { auxnode -> parent = copy ; auxnode = auxnode -> younger ; } } return ( copy ) ; }
Function
Synopsis    [Makes a copy of tree.]
Function Synopsis [ Makes a copy of tree . ]