00001
00021 #include "nmInt.h"
00022
00026
00030
00042 Nm_Man_t * Nm_ManCreate( int nSize )
00043 {
00044 Nm_Man_t * p;
00045
00046 p = ALLOC( Nm_Man_t, 1 );
00047 memset( p, 0, sizeof(Nm_Man_t) );
00048
00049 p->nSizeFactor = 2;
00050 p->nGrowthFactor = 3;
00051
00052 p->nBins = Cudd_PrimeNm(nSize);
00053 p->pBinsI2N = ALLOC( Nm_Entry_t *, p->nBins );
00054 p->pBinsN2I = ALLOC( Nm_Entry_t *, p->nBins );
00055 memset( p->pBinsI2N, 0, sizeof(Nm_Entry_t *) * p->nBins );
00056 memset( p->pBinsN2I, 0, sizeof(Nm_Entry_t *) * p->nBins );
00057
00058 p->pMem = Extra_MmFlexStart();
00059 return p;
00060 }
00061
00073 void Nm_ManFree( Nm_Man_t * p )
00074 {
00075 Extra_MmFlexStop( p->pMem );
00076 FREE( p->pBinsI2N );
00077 FREE( p->pBinsN2I );
00078 FREE( p );
00079 }
00080
00092 int Nm_ManNumEntries( Nm_Man_t * p )
00093 {
00094 return p->nEntries;
00095 }
00096
00109 char * Nm_ManStoreIdName( Nm_Man_t * p, int ObjId, int Type, char * pName, char * pSuffix )
00110 {
00111 Nm_Entry_t * pEntry;
00112 int RetValue, nEntrySize;
00113
00114 if ( pEntry = Nm_ManTableLookupId(p, ObjId) )
00115 {
00116 printf( "Nm_ManStoreIdName(): Entry with the same ID already exists.\n" );
00117 return NULL;
00118 }
00119
00120 nEntrySize = sizeof(Nm_Entry_t) + strlen(pName) + (pSuffix?strlen(pSuffix):0) + 1;
00121 nEntrySize = (nEntrySize / 4 + ((nEntrySize % 4) > 0)) * 4;
00122 pEntry = (Nm_Entry_t *)Extra_MmFlexEntryFetch( p->pMem, nEntrySize );
00123 pEntry->pNextI2N = pEntry->pNextN2I = pEntry->pNameSake = NULL;
00124 pEntry->ObjId = ObjId;
00125 pEntry->Type = Type;
00126 sprintf( pEntry->Name, "%s%s", pName, pSuffix? pSuffix : "" );
00127
00128 RetValue = Nm_ManTableAdd( p, pEntry );
00129 assert( RetValue == 1 );
00130 return pEntry->Name;
00131 }
00132
00145 void Nm_ManDeleteIdName( Nm_Man_t * p, int ObjId )
00146 {
00147 Nm_Entry_t * pEntry;
00148 pEntry = Nm_ManTableLookupId(p, ObjId);
00149 if ( pEntry == NULL )
00150 {
00151 printf( "Nm_ManDeleteIdName(): This entry is not in the table.\n" );
00152 return;
00153 }
00154
00155 Nm_ManTableDelete( p, ObjId );
00156 }
00157
00158
00171 char * Nm_ManCreateUniqueName( Nm_Man_t * p, int ObjId )
00172 {
00173 static char NameStr[1000];
00174 Nm_Entry_t * pEntry;
00175 int i;
00176 if ( pEntry = Nm_ManTableLookupId(p, ObjId) )
00177 return pEntry->Name;
00178 sprintf( NameStr, "n%d", ObjId );
00179 for ( i = 1; Nm_ManTableLookupName(p, NameStr, -1); i++ )
00180 sprintf( NameStr, "n%d_%d", ObjId, i );
00181 return NameStr;
00182 }
00183
00195 char * Nm_ManFindNameById( Nm_Man_t * p, int ObjId )
00196 {
00197 Nm_Entry_t * pEntry;
00198 if ( pEntry = Nm_ManTableLookupId(p, ObjId) )
00199 return pEntry->Name;
00200 return NULL;
00201 }
00202
00215 int Nm_ManFindIdByName( Nm_Man_t * p, char * pName, int Type )
00216 {
00217 Nm_Entry_t * pEntry;
00218 if ( pEntry = Nm_ManTableLookupName(p, pName, Type) )
00219 return pEntry->ObjId;
00220 return -1;
00221 }
00222
00235 int Nm_ManFindIdByNameTwoTypes( Nm_Man_t * p, char * pName, int Type1, int Type2 )
00236 {
00237 int iNodeId;
00238 iNodeId = Nm_ManFindIdByName( p, pName, Type1 );
00239 if ( iNodeId == -1 )
00240 iNodeId = Nm_ManFindIdByName( p, pName, Type2 );
00241 if ( iNodeId == -1 )
00242 return -1;
00243 return iNodeId;
00244 }
00245
00257 Vec_Int_t * Nm_ManReturnNameIds( Nm_Man_t * p )
00258 {
00259 Vec_Int_t * vNameIds;
00260 int i;
00261 vNameIds = Vec_IntAlloc( p->nEntries );
00262 for ( i = 0; i < p->nBins; i++ )
00263 if ( p->pBinsI2N[i] )
00264 Vec_IntPush( vNameIds, p->pBinsI2N[i]->ObjId );
00265 return vNameIds;
00266 }
00267
00271
00272