00001
00021 #include "aig.h"
00022
00026
00030
00042 void Aig_ManOrderStart( Aig_Man_t * p )
00043 {
00044 Aig_Obj_t * pObj;
00045 int i;
00046 assert( Aig_ManBufNum(p) == 0 );
00047
00048 assert( p->pOrderData == NULL );
00049 p->nOrderAlloc = 2 * Aig_ManObjNumMax(p);
00050 if ( p->nOrderAlloc < (1<<12) )
00051 p->nOrderAlloc = (1<<12);
00052 p->pOrderData = ALLOC( unsigned, 2 * p->nOrderAlloc );
00053 memset( p->pOrderData, 0xFF, sizeof(unsigned) * 2 * p->nOrderAlloc );
00054
00055 p->pOrderData[0] = p->pOrderData[1] = 0;
00056 p->iPrev = p->iNext = 0;
00057
00058 Aig_ManForEachNode( p, pObj, i )
00059 Aig_ObjOrderInsert( p, pObj->Id );
00060 }
00061
00073 void Aig_ManOrderStop( Aig_Man_t * p )
00074 {
00075 assert( p->pOrderData );
00076 FREE( p->pOrderData );
00077 p->nOrderAlloc = 0;
00078 p->iPrev = p->iNext = 0;
00079 }
00080
00092 void Aig_ObjOrderInsert( Aig_Man_t * p, int ObjId )
00093 {
00094 int iPrev;
00095 assert( ObjId != 0 );
00096 assert( Aig_ObjIsNode( Aig_ManObj(p, ObjId) ) );
00097 if ( ObjId >= p->nOrderAlloc )
00098 {
00099 int nOrderAlloc = 2 * ObjId;
00100 p->pOrderData = REALLOC( unsigned, p->pOrderData, 2 * nOrderAlloc );
00101 memset( p->pOrderData + 2 * p->nOrderAlloc, 0xFF, sizeof(unsigned) * 2 * (nOrderAlloc - p->nOrderAlloc) );
00102 p->nOrderAlloc = nOrderAlloc;
00103 }
00104 assert( p->pOrderData[2*ObjId] == 0xFFFFFFFF );
00105 assert( p->pOrderData[2*ObjId+1] == 0xFFFFFFFF );
00106 iPrev = p->pOrderData[2*p->iNext];
00107 assert( p->pOrderData[2*iPrev+1] == (unsigned)p->iNext );
00108 p->pOrderData[2*ObjId] = iPrev;
00109 p->pOrderData[2*iPrev+1] = ObjId;
00110 p->pOrderData[2*p->iNext] = ObjId;
00111 p->pOrderData[2*ObjId+1] = p->iNext;
00112 p->nAndTotal++;
00113 }
00114
00127 void Aig_ObjOrderRemove( Aig_Man_t * p, int ObjId )
00128 {
00129 int iPrev, iNext;
00130 assert( ObjId != 0 );
00131 assert( Aig_ObjIsNode( Aig_ManObj(p, ObjId) ) );
00132 iPrev = p->pOrderData[2*ObjId];
00133 iNext = p->pOrderData[2*ObjId+1];
00134 p->pOrderData[2*ObjId] = 0xFFFFFFFF;
00135 p->pOrderData[2*ObjId+1] = 0xFFFFFFFF;
00136 p->pOrderData[2*iNext] = iPrev;
00137 p->pOrderData[2*iPrev+1] = iNext;
00138 if ( p->iPrev == ObjId )
00139 {
00140 p->nAndPrev--;
00141 p->iPrev = iPrev;
00142 }
00143 if ( p->iNext == ObjId )
00144 p->iNext = iNext;
00145 p->nAndTotal--;
00146 }
00147
00159 void Aig_ObjOrderAdvance( Aig_Man_t * p )
00160 {
00161 assert( p->pOrderData );
00162 assert( p->pOrderData[2*p->iPrev+1] == (unsigned)p->iNext );
00163 p->iPrev = p->iNext;
00164 p->nAndPrev++;
00165 }
00166
00170
00171