00001
00021 #include "cutInt.h"
00022
00026
00030
00042 Cut_Cut_t * Cut_CutAlloc( Cut_Man_t * p )
00043 {
00044 Cut_Cut_t * pCut;
00045
00046 pCut = (Cut_Cut_t *)Extra_MmFixedEntryFetch( p->pMmCuts );
00047 memset( pCut, 0, sizeof(Cut_Cut_t) );
00048 pCut->nVarsMax = p->pParams->nVarsMax;
00049 pCut->fSimul = p->fSimul;
00050
00051 p->nCutsAlloc++;
00052 p->nCutsCur++;
00053 if ( p->nCutsPeak < p->nCutsAlloc - p->nCutsDealloc )
00054 p->nCutsPeak = p->nCutsAlloc - p->nCutsDealloc;
00055 return pCut;
00056 }
00057
00069 void Cut_CutRecycle( Cut_Man_t * p, Cut_Cut_t * pCut )
00070 {
00071 p->nCutsDealloc++;
00072 p->nCutsCur--;
00073 if ( pCut->nLeaves == 1 )
00074 p->nCutsTriv--;
00075 Extra_MmFixedEntryRecycle( p->pMmCuts, (char *)pCut );
00076 }
00077
00089 int Cut_CutCompare( Cut_Cut_t * pCut1, Cut_Cut_t * pCut2 )
00090 {
00091 int i;
00092 if ( pCut1->nLeaves < pCut2->nLeaves )
00093 return -1;
00094 if ( pCut1->nLeaves > pCut2->nLeaves )
00095 return 1;
00096 for ( i = 0; i < (int)pCut1->nLeaves; i++ )
00097 {
00098 if ( pCut1->pLeaves[i] < pCut2->pLeaves[i] )
00099 return -1;
00100 if ( pCut1->pLeaves[i] > pCut2->pLeaves[i] )
00101 return 1;
00102 }
00103 return 0;
00104 }
00105
00117 Cut_Cut_t * Cut_CutDupList( Cut_Man_t * p, Cut_Cut_t * pList )
00118 {
00119 Cut_Cut_t * pHead = NULL, ** ppTail = &pHead;
00120 Cut_Cut_t * pTemp, * pCopy;
00121 if ( pList == NULL )
00122 return NULL;
00123 Cut_ListForEachCut( pList, pTemp )
00124 {
00125 pCopy = (Cut_Cut_t *)Extra_MmFixedEntryFetch( p->pMmCuts );
00126 memcpy( pCopy, pTemp, p->EntrySize );
00127 *ppTail = pCopy;
00128 ppTail = &pCopy->pNext;
00129 }
00130 *ppTail = NULL;
00131 return pHead;
00132 }
00133
00145 void Cut_CutRecycleList( Cut_Man_t * p, Cut_Cut_t * pList )
00146 {
00147 Cut_Cut_t * pCut, * pCut2;
00148 Cut_ListForEachCutSafe( pList, pCut, pCut2 )
00149 Extra_MmFixedEntryRecycle( p->pMmCuts, (char *)pCut );
00150 }
00151
00163 int Cut_CutCountList( Cut_Cut_t * pList )
00164 {
00165 int Counter = 0;
00166 Cut_ListForEachCut( pList, pList )
00167 Counter++;
00168 return Counter;
00169 }
00170
00182 Cut_Cut_t * Cut_CutMergeLists( Cut_Cut_t * pList1, Cut_Cut_t * pList2 )
00183 {
00184 Cut_Cut_t * pList = NULL, ** ppTail = &pList;
00185 Cut_Cut_t * pCut;
00186 while ( pList1 && pList2 )
00187 {
00188 if ( Cut_CutCompare(pList1, pList2) < 0 )
00189 {
00190 pCut = pList1;
00191 pList1 = pList1->pNext;
00192 }
00193 else
00194 {
00195 pCut = pList2;
00196 pList2 = pList2->pNext;
00197 }
00198 *ppTail = pCut;
00199 ppTail = &pCut->pNext;
00200 }
00201 *ppTail = pList1? pList1: pList2;
00202 return pList;
00203 }
00204
00216 void Cut_CutNumberList( Cut_Cut_t * pList )
00217 {
00218 Cut_Cut_t * pCut;
00219 int i = 0;
00220 Cut_ListForEachCut( pList, pCut )
00221 pCut->Num0 = i++;
00222 }
00223
00235 Cut_Cut_t * Cut_CutCreateTriv( Cut_Man_t * p, int Node )
00236 {
00237 Cut_Cut_t * pCut;
00238 if ( p->pParams->fSeq )
00239 Node <<= CUT_SHIFT;
00240 pCut = Cut_CutAlloc( p );
00241 pCut->nLeaves = 1;
00242 pCut->pLeaves[0] = Node;
00243 pCut->uSign = Cut_NodeSign( Node );
00244 if ( p->pParams->fTruth )
00245 {
00246
00247
00248
00249
00250
00251
00252 unsigned * pTruth = Cut_CutReadTruth(pCut);
00253 int i;
00254 for ( i = 0; i < p->nTruthWords; i++ )
00255 pTruth[i] = 0xAAAAAAAA;
00256 }
00257 p->nCutsTriv++;
00258 return pCut;
00259 }
00260
00261
00273 void Cut_CutPrint( Cut_Cut_t * pCut, int fSeq )
00274 {
00275 int i;
00276 assert( pCut->nLeaves > 0 );
00277 printf( "%d : {", pCut->nLeaves );
00278 for ( i = 0; i < (int)pCut->nLeaves; i++ )
00279 {
00280 if ( fSeq )
00281 {
00282 printf( " %d", pCut->pLeaves[i] >> CUT_SHIFT );
00283 if ( pCut->pLeaves[i] & CUT_MASK )
00284 printf( "(%d)", pCut->pLeaves[i] & CUT_MASK );
00285 }
00286 else
00287 printf( " %d", pCut->pLeaves[i] );
00288 }
00289 printf( " }" );
00290
00291
00292 }
00293
00305 void Cut_CutPrintList( Cut_Cut_t * pList, int fSeq )
00306 {
00307 Cut_Cut_t * pCut;
00308 for ( pCut = pList; pCut; pCut = pCut->pNext )
00309 Cut_CutPrint( pCut, fSeq ), printf( "\n" );
00310 }
00311
00323 void Cut_CutPrintMerge( Cut_Cut_t * pCut, Cut_Cut_t * pCut0, Cut_Cut_t * pCut1 )
00324 {
00325 printf( "\n" );
00326 printf( "%d : %5d %5d %5d %5d %5d\n",
00327 pCut0->nLeaves,
00328 pCut0->nLeaves > 0 ? pCut0->pLeaves[0] : -1,
00329 pCut0->nLeaves > 1 ? pCut0->pLeaves[1] : -1,
00330 pCut0->nLeaves > 2 ? pCut0->pLeaves[2] : -1,
00331 pCut0->nLeaves > 3 ? pCut0->pLeaves[3] : -1,
00332 pCut0->nLeaves > 4 ? pCut0->pLeaves[4] : -1
00333 );
00334 printf( "%d : %5d %5d %5d %5d %5d\n",
00335 pCut1->nLeaves,
00336 pCut1->nLeaves > 0 ? pCut1->pLeaves[0] : -1,
00337 pCut1->nLeaves > 1 ? pCut1->pLeaves[1] : -1,
00338 pCut1->nLeaves > 2 ? pCut1->pLeaves[2] : -1,
00339 pCut1->nLeaves > 3 ? pCut1->pLeaves[3] : -1,
00340 pCut1->nLeaves > 4 ? pCut1->pLeaves[4] : -1
00341 );
00342 if ( pCut == NULL )
00343 printf( "Cannot merge\n" );
00344 else
00345 printf( "%d : %5d %5d %5d %5d %5d\n",
00346 pCut->nLeaves,
00347 pCut->nLeaves > 0 ? pCut->pLeaves[0] : -1,
00348 pCut->nLeaves > 1 ? pCut->pLeaves[1] : -1,
00349 pCut->nLeaves > 2 ? pCut->pLeaves[2] : -1,
00350 pCut->nLeaves > 3 ? pCut->pLeaves[3] : -1,
00351 pCut->nLeaves > 4 ? pCut->pLeaves[4] : -1
00352 );
00353 }
00354
00358
00359