abc/src/base/abc/abcDfs.c
/**Function*************************************************************

  Synopsis    [Returns the levelized array of TFO nodes.]

  Description [Collects the levelized array of internal nodes, leaving out CIs/COs.
  However it marks both CIs and COs with the current TravId.
  Collects only the nodes whose support does not exceed the set of given CI nodes.]
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Function
Synopsis    [Returns the levelized array of TFO nodes.]

Description [Collects the levelized array of internal nodes, leaving out CIs/COs.
However it marks both CIs and COs with the current TravId.
Collects only the nodes whose support does not exceed the set of given CI nodes.]




Function Synopsis [ Returns the levelized array of TFO nodes . ] Description [ Collects the levelized array of internal nodes leaving out CIs / COs . However it marks both CIs and COs with the current TravId . Collects only the nodes whose support does not exceed the set of given CI nodes . ]
Vec_Ptr_t * Abc_NtkDfsReverseNodesContained( Abc_Ntk_t * pNtk, Abc_Obj_t ** ppNodes, int nNodes )
{
    Vec_Ptr_t * vNodes;
    Abc_Obj_t * pObj, * pFanout, * pFanin;
    int i, k, m, nLevels;
    nLevels = Abc_NtkLevel( pNtk );
    Abc_NtkIncrementTravId( pNtk );
    vNodes = Vec_PtrStart( nLevels + 2 );
    for ( i = 0; i < nNodes; i++ )
    {
        pObj = ppNodes[i];
        assert( Abc_ObjIsCi(pObj) );
        Abc_NodeSetTravIdCurrent( pObj );
        assert( pObj->Level == 0 );
        pObj->pCopy = (Abc_Obj_t *)Vec_PtrEntry( vNodes, pObj->Level );
        Vec_PtrWriteEntry( vNodes, pObj->Level, pObj );
    }
    for ( i = 0; i <= nLevels; i++ )
    {
        for ( pObj = (Abc_Obj_t *)Vec_PtrEntry(vNodes, i); pObj; pObj = pObj->pCopy )
        {
            Abc_ObjForEachFanout( pObj, pFanout, k )
            {
                if ( Abc_NodeIsTravIdCurrent(pFanout) )
                    continue;
                Abc_ObjForEachFanin( pFanout, pFanin, m )
                {
                    if ( !Abc_NodeIsTravIdCurrent(pFanin) )
                        break;
                }
                if ( m < Abc_ObjFaninNum(pFanout) )
                    continue;
                Abc_NodeSetTravIdCurrent( pFanout );
                if ( Abc_ObjIsCo(pFanout) )
                    pFanout->Level = nLevels + 1;
                pFanout->pCopy = (Abc_Obj_t *)Vec_PtrEntry( vNodes, pFanout->Level );
                Vec_PtrWriteEntry( vNodes, pFanout->Level, pFanout );
                if ( Abc_ObjIsCo(pFanout) )
                    pFanout->Level = 0;
            }
        }
    }
    return vNodes;
}
Vec_Ptr_t * Abc_NtkDfsReverseNodesContained ( Abc_Ntk_t * pNtk , Abc_Obj_t * * ppNodes , int nNodes ) { Vec_Ptr_t * vNodes ; Abc_Obj_t * pObj , * pFanout , * pFanin ; int i , k , m , nLevels ; nLevels = Abc_NtkLevel ( pNtk ) ; Abc_NtkIncrementTravId ( pNtk ) ; vNodes = Vec_PtrStart ( nLevels + 2 ) ; for ( i = 0 ; i < nNodes ; i ++ ) { pObj = ppNodes [ i ] ; assert ( Abc_ObjIsCi ( pObj ) ) ; Abc_NodeSetTravIdCurrent ( pObj ) ; assert ( pObj -> Level == 0 ) ; pObj -> pCopy = ( Abc_Obj_t * ) Vec_PtrEntry ( vNodes , pObj -> Level ) ; Vec_PtrWriteEntry ( vNodes , pObj -> Level , pObj ) ; } for ( i = 0 ; i <= nLevels ; i ++ ) { for ( pObj = ( Abc_Obj_t * ) Vec_PtrEntry ( vNodes , i ) ; pObj ; pObj = pObj -> pCopy ) { Abc_ObjForEachFanout ( pObj , pFanout , k ) { if ( Abc_NodeIsTravIdCurrent ( pFanout ) ) continue ; Abc_ObjForEachFanin ( pFanout , pFanin , m ) { if ( ! Abc_NodeIsTravIdCurrent ( pFanin ) ) break ; } if ( m < Abc_ObjFaninNum ( pFanout ) ) continue ; Abc_NodeSetTravIdCurrent ( pFanout ) ; if ( Abc_ObjIsCo ( pFanout ) ) pFanout -> Level = nLevels + 1 ; pFanout -> pCopy = ( Abc_Obj_t * ) Vec_PtrEntry ( vNodes , pFanout -> Level ) ; Vec_PtrWriteEntry ( vNodes , pFanout -> Level , pFanout ) ; if ( Abc_ObjIsCo ( pFanout ) ) pFanout -> Level = 0 ; } } } return vNodes ; }
Function
Synopsis    [Returns the levelized array of TFO nodes.]
Function Synopsis [ Returns the levelized array of TFO nodes . ]
// set the levels // set the traversal ID // start the array of nodes // add to the array // iterate through the levels // iterate through the nodes on each level // iterate through the fanouts of each node // skip visited nodes // visit the fanins of this fanout // all fanins are already collected // mark the node as visited // handle the COs // add to the array // handle the COs