abc/src/misc/mvc/mvcUtils.c
/**Function*************************************************************

  Synopsis    [Counts the differences in each cube pair in the cover.]

  Description [Takes the cover (pCover) and the array where the
  diff counters go (pDiffs). The array pDiffs should have as many
  entries as there are different pairs of cubes in the cover: n(n-1)/2.
  Fills out the array pDiffs with the following info: For each cube
  pair, included in the array is the number of literals in both cubes
  after they are made cube ABC_FREE.]
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Function
Synopsis    [Counts the differences in each cube pair in the cover.]

Description [Takes the cover (pCover) and the array where the
diff counters go (pDiffs). The array pDiffs should have as many
entries as there are different pairs of cubes in the cover: n(n-1)/2.
Fills out the array pDiffs with the following info: For each cube
pair, included in the array is the number of literals in both cubes
after they are made cube ABC_FREE.]




Function Synopsis [ Counts the differences in each cube pair in the cover . ] Description [ Takes the cover ( pCover ) and the array where the diff counters go ( pDiffs ) . The array pDiffs should have as many entries as there are different pairs of cubes in the cover : n ( n - 1 ) / 2 . Fills out the array pDiffs with the following info : For each cube pair included in the array is the number of literals in both cubes after they are made cube ABC_FREE . ]
int Mvc_CoverCountCubePairDiffs( Mvc_Cover_t * pCover, unsigned char pDiffs[] )
{
    Mvc_Cube_t * pCube1;
    Mvc_Cube_t * pCube2;
    Mvc_Cube_t * pMask;
    unsigned char * pByte, * pByteStart, * pByteStop;
    int nBytes, nOnes;
    int nCubePairs;
    pMask = Mvc_CubeAlloc( pCover );
    nBytes = pCover->nBits / (8 * sizeof(unsigned char)) + (int)(pCover->nBits % (8 * sizeof(unsigned char)) > 0);
    nCubePairs = 0;
    Mvc_CoverForEachCube( pCover, pCube1 )
    {
        Mvc_CoverForEachCubeStart( Mvc_CubeReadNext(pCube1), pCube2 )
        {
            Mvc_CubeBitExor( pMask, pCube1, pCube2 );
            pByteStart = (unsigned char *)pMask->pData;
            pByteStop  = pByteStart + nBytes;
            nOnes = 0;
            for ( pByte = pByteStart; pByte < pByteStop; pByte++ )
                nOnes += bit_count[*pByte];
            pDiffs[nCubePairs++] = nOnes;
        }
    }
    Mvc_CubeFree( pCover, pMask );
    return 1;
}
int Mvc_CoverCountCubePairDiffs ( Mvc_Cover_t * pCover , unsigned char pDiffs [ ] ) { Mvc_Cube_t * pCube1 ; Mvc_Cube_t * pCube2 ; Mvc_Cube_t * pMask ; unsigned char * pByte , * pByteStart , * pByteStop ; int nBytes , nOnes ; int nCubePairs ; pMask = Mvc_CubeAlloc ( pCover ) ; nBytes = pCover -> nBits / ( 8 * sizeof ( unsigned char ) ) + ( int ) ( pCover -> nBits % ( 8 * sizeof ( unsigned char ) ) > 0 ) ; nCubePairs = 0 ; Mvc_CoverForEachCube ( pCover , pCube1 ) { Mvc_CoverForEachCubeStart ( Mvc_CubeReadNext ( pCube1 ) , pCube2 ) { Mvc_CubeBitExor ( pMask , pCube1 , pCube2 ) ; pByteStart = ( unsigned char * ) pMask -> pData ; pByteStop = pByteStart + nBytes ; nOnes = 0 ; for ( pByte = pByteStart ; pByte < pByteStop ; pByte ++ ) nOnes += bit_count [ * pByte ] ; pDiffs [ nCubePairs ++ ] = nOnes ; } } Mvc_CubeFree ( pCover , pMask ) ; return 1 ; }
Function
Synopsis    [Counts the differences in each cube pair in the cover.]
Function Synopsis [ Counts the differences in each cube pair in the cover . ]
// allocate a temporary mask // get the number of unsigned chars in the cube's bit strings // iterate through the cubes // find the bit-wise exor of cubes // set the starting and stopping positions // clean the counter of ones // iterate through the positions // set the nOnes // deallocate the mask