abc/src/opt/dar/darBalance.c
/**Function*************************************************************

  Synopsis    [Finds the left bound on the next candidate to be paired.]

  Description [The nodes in the array are in the decreasing order of levels. 
  The last node in the array has the smallest level. By default it would be paired 
  with the next node on the left. However, it may be possible to pair it with some
  other node on the left, in such a way that the new node is shared. This procedure
  finds the index of the left-most node, which can be paired with the last node.]
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Function
Synopsis    [Finds the left bound on the next candidate to be paired.]

Description [The nodes in the array are in the decreasing order of levels.
The last node in the array has the smallest level. By default it would be paired
with the next node on the left. However, it may be possible to pair it with some
other node on the left, in such a way that the new node is shared. This procedure
finds the index of the left-most node, which can be paired with the last node.]




Function Synopsis [ Finds the left bound on the next candidate to be paired . ] Description [ The nodes in the array are in the decreasing order of levels . The last node in the array has the smallest level . By default it would be paired with the next node on the left . However it may be possible to pair it with some other node on the left in such a way that the new node is shared . This procedure finds the index of the left - most node which can be paired with the last node . ]
int Dar_BalanceFindLeft( Vec_Ptr_t * vSuper )
{
    Aig_Obj_t * pObjRight, * pObjLeft;
    int Current;
    if ( Vec_PtrSize(vSuper) < 3 )
        return 0;
    Current = Vec_PtrSize(vSuper) - 2;
    pObjRight = (Aig_Obj_t *)Vec_PtrEntry( vSuper, Current );
    for ( Current--; Current >= 0; Current-- )
    {
        pObjLeft = (Aig_Obj_t *)Vec_PtrEntry( vSuper, Current );
        if ( Aig_ObjLevel(Aig_Regular(pObjLeft)) != Aig_ObjLevel(Aig_Regular(pObjRight)) )
            break;
    }
    Current++;    
    pObjLeft = (Aig_Obj_t *)Vec_PtrEntry( vSuper, Current );
    assert( Aig_ObjLevel(Aig_Regular(pObjLeft)) == Aig_ObjLevel(Aig_Regular(pObjRight)) );
    return Current;
}
int Dar_BalanceFindLeft ( Vec_Ptr_t * vSuper ) { Aig_Obj_t * pObjRight , * pObjLeft ; int Current ; if ( Vec_PtrSize ( vSuper ) < 3 ) return 0 ; Current = Vec_PtrSize ( vSuper ) - 2 ; pObjRight = ( Aig_Obj_t * ) Vec_PtrEntry ( vSuper , Current ) ; for ( Current -- ; Current >= 0 ; Current -- ) { pObjLeft = ( Aig_Obj_t * ) Vec_PtrEntry ( vSuper , Current ) ; if ( Aig_ObjLevel ( Aig_Regular ( pObjLeft ) ) != Aig_ObjLevel ( Aig_Regular ( pObjRight ) ) ) break ; } Current ++ ; pObjLeft = ( Aig_Obj_t * ) Vec_PtrEntry ( vSuper , Current ) ; assert ( Aig_ObjLevel ( Aig_Regular ( pObjLeft ) ) == Aig_ObjLevel ( Aig_Regular ( pObjRight ) ) ) ; return Current ; }
Function
Synopsis    [Finds the left bound on the next candidate to be paired.]
Function Synopsis [ Finds the left bound on the next candidate to be paired . ]
// if two or less nodes, pair with the first // set the pointer to the one before the last // go through the nodes to the left of this one // get the next node on the left // if the level of this node is different, quit the loop // get the node, for which the equality holds