summaryrefslogtreecommitdiffstats
path: root/src/misc
diff options
context:
space:
mode:
Diffstat (limited to 'src/misc')
-rw-r--r--src/misc/extra/extra.h1
-rw-r--r--src/misc/extra/extraUtilFile.c19
-rw-r--r--src/misc/util/utilNam.c74
-rw-r--r--src/misc/util/utilNam.h2
-rw-r--r--src/misc/vec/vecInt.h42
5 files changed, 126 insertions, 12 deletions
diff --git a/src/misc/extra/extra.h b/src/misc/extra/extra.h
index 5d9c405f..3dee5f4e 100644
--- a/src/misc/extra/extra.h
+++ b/src/misc/extra/extra.h
@@ -106,6 +106,7 @@ extern char * Extra_FileNameGenericAppend( char * pBase, char * pSuffix );
extern void Extra_FileNameCorrectPath( char * FileName );
extern char * Extra_FileNameWithoutPath( char * FileName );
extern char * Extra_FilePathWithoutName( char * FileName );
+extern char * Extra_FileDesignName( char * pFileName );
extern int Extra_FileCheck( char * pFileName );
extern int Extra_FileSize( char * pFileName );
extern char * Extra_FileRead( FILE * pFile );
diff --git a/src/misc/extra/extraUtilFile.c b/src/misc/extra/extraUtilFile.c
index ee9168f6..6b4453a5 100644
--- a/src/misc/extra/extraUtilFile.c
+++ b/src/misc/extra/extraUtilFile.c
@@ -247,6 +247,25 @@ char * Extra_FilePathWithoutName( char * FileName )
ABC_FREE( FileName );
return NULL;
}
+char * Extra_FileDesignName( char * pFileName )
+{
+ char * pBeg, * pEnd, * pStore, * pCur;
+ // find the first dot
+ for ( pEnd = pFileName; *pEnd; pEnd++ )
+ if ( *pEnd == '.' )
+ break;
+ // find the first char
+ for ( pBeg = pEnd - 1; pBeg >= pFileName; pBeg-- )
+ if ( !((*pBeg >= 'a' && *pBeg <= 'z') || (*pBeg >= 'A' && *pBeg <= 'Z') || (*pBeg >= '0' && *pBeg <= '9') || *pBeg == '_') )
+ break;
+ pBeg++;
+ // fill up storage
+ pStore = ABC_ALLOC( char, pEnd - pBeg + 1 );
+ for ( pCur = pStore; pBeg < pEnd; pBeg++, pCur++ )
+ *pCur = *pBeg;
+ *pCur = 0;
+ return pStore;
+}
/**Function*************************************************************
diff --git a/src/misc/util/utilNam.c b/src/misc/util/utilNam.c
index 5fb38c51..76c86aff 100644
--- a/src/misc/util/utilNam.c
+++ b/src/misc/util/utilNam.c
@@ -237,7 +237,7 @@ int Abc_NamMemAlloc( Abc_Nam_t * p )
SeeAlso []
***********************************************************************/
-int Abc_NamStrHash( const char * pStr, int nTableSize )
+int Abc_NamStrHash( const char * pStr, const char * pLim, int nTableSize )
{
static int s_FPrimes[128] = {
1009, 1049, 1093, 1151, 1201, 1249, 1297, 1361, 1427, 1459,
@@ -255,11 +255,22 @@ int Abc_NamStrHash( const char * pStr, int nTableSize )
8011, 8039, 8059, 8081, 8093, 8111, 8123, 8147
};
unsigned i, uHash;
- for ( uHash = 0, i = 0; pStr[i]; i++ )
- if ( i & 1 )
- uHash *= pStr[i] * s_FPrimes[i & 0x7F];
- else
- uHash ^= pStr[i] * s_FPrimes[i & 0x7F];
+ if ( pLim )
+ {
+ for ( uHash = 0, i = 0; pStr < pLim; i++ )
+ if ( i & 1 )
+ uHash *= pStr[i] * s_FPrimes[i & 0x7F];
+ else
+ uHash ^= pStr[i] * s_FPrimes[i & 0x7F];
+ }
+ else
+ {
+ for ( uHash = 0, i = 0; pStr[i]; i++ )
+ if ( i & 1 )
+ uHash *= pStr[i] * s_FPrimes[i & 0x7F];
+ else
+ uHash ^= pStr[i] * s_FPrimes[i & 0x7F];
+ }
return uHash % nTableSize;
}
@@ -274,10 +285,10 @@ int Abc_NamStrHash( const char * pStr, int nTableSize )
SeeAlso []
***********************************************************************/
-static inline int * Abc_NamStrHashFind( Abc_Nam_t * p, const char * pStr )
+static inline int * Abc_NamStrHashFind( Abc_Nam_t * p, const char * pStr, const char * pLim )
{
char * pThis;
- int * pPlace = (int *)(p->pBins + Abc_NamStrHash( pStr, p->nBins ));
+ int * pPlace = (int *)(p->pBins + Abc_NamStrHash( pStr, pLim, p->nBins ));
assert( *pStr );
for ( pThis = (*pPlace)? Abc_NamIntToStr(p, *pPlace) : NULL;
pThis; pPlace = Abc_NamIntToNextP(p, *pPlace),
@@ -318,7 +329,7 @@ void Abc_NamStrHashResize( Abc_Nam_t * p )
Vec_IntForEachEntryStart( vInt2HandleOld, iHandleOld, i, 1 )
{
pThis = Abc_NamHandleToStr( p, iHandleOld );
- piPlace = Abc_NamStrHashFind( p, pThis );
+ piPlace = Abc_NamStrHashFind( p, pThis, NULL );
assert( *piPlace == 0 );
*piPlace = Vec_IntSize( p->vInt2Handle );
assert( Vec_IntSize( p->vInt2Handle ) == i );
@@ -343,7 +354,11 @@ void Abc_NamStrHashResize( Abc_Nam_t * p )
***********************************************************************/
int Abc_NamStrFind( Abc_Nam_t * p, char * pStr )
{
- return *Abc_NamStrHashFind( p, pStr );
+ return *Abc_NamStrHashFind( p, pStr, NULL );
+}
+int Abc_NamStrFindLim( Abc_Nam_t * p, char * pStr, char * pLim )
+{
+ return *Abc_NamStrHashFind( p, pStr, pLim );
}
/**Function*************************************************************
@@ -368,7 +383,7 @@ int Abc_NamStrFindOrAdd( Abc_Nam_t * p, char * pStr, int * pfFound )
break;
assert( i < (int)strlen(pStr) );
}
- piPlace = Abc_NamStrHashFind( p, pStr );
+ piPlace = Abc_NamStrHashFind( p, pStr, NULL );
if ( *piPlace )
{
if ( pfFound )
@@ -396,6 +411,41 @@ int Abc_NamStrFindOrAdd( Abc_Nam_t * p, char * pStr, int * pfFound )
Abc_NamStrHashResize( p );
return Vec_IntSize(p->vInt2Handle) - 1;
}
+int Abc_NamStrFindOrAddLim( Abc_Nam_t * p, char * pStr, char * pLim, int * pfFound )
+{
+ int iHandleNew;
+ int *piPlace;
+ char * pStore;
+ piPlace = Abc_NamStrHashFind( p, pStr, pLim );
+ if ( *piPlace )
+ {
+ if ( pfFound )
+ *pfFound = 1;
+ return *piPlace;
+ }
+ if ( pfFound )
+ *pfFound = 0;
+ iHandleNew = p->iHandle + (pLim - pStr) + 1;
+ while ( p->nStore < iHandleNew )
+ {
+ p->nStore *= 3;
+ p->nStore /= 2;
+ p->pStore = ABC_REALLOC( char, p->pStore, p->nStore );
+ }
+ assert( p->nStore >= iHandleNew );
+ // create new handle
+ *piPlace = Vec_IntSize( p->vInt2Handle );
+ pStore = Abc_NamHandleToStr( p, p->iHandle );
+ strncpy( pStore, pStr, pLim - pStr );
+ pStore[pLim - pStr] = 0;
+ Vec_IntPush( p->vInt2Handle, p->iHandle );
+ Vec_IntPush( p->vInt2Next, 0 );
+ p->iHandle = iHandleNew;
+ // extend the hash table
+ if ( Vec_IntSize(p->vInt2Handle) > 2 * p->nBins )
+ Abc_NamStrHashResize( p );
+ return Vec_IntSize(p->vInt2Handle) - 1;
+}
/**Function*************************************************************
@@ -435,7 +485,7 @@ Vec_Int_t * Abc_NamComputeIdMap( Abc_Nam_t * p1, Abc_Nam_t * p2 )
Vec_IntForEachEntryStart( p1->vInt2Handle, iHandle1, i, 1 )
{
pThis = Abc_NamHandleToStr( p1, iHandle1 );
- piPlace = Abc_NamStrHashFind( p2, pThis );
+ piPlace = Abc_NamStrHashFind( p2, pThis, NULL );
Vec_IntWriteEntry( vMap, i, *piPlace );
// Abc_Print( 1, "%d->%d ", i, *piPlace );
}
diff --git a/src/misc/util/utilNam.h b/src/misc/util/utilNam.h
index 9f3048f3..86802802 100644
--- a/src/misc/util/utilNam.h
+++ b/src/misc/util/utilNam.h
@@ -59,7 +59,9 @@ extern int Abc_NamObjNumMax( Abc_Nam_t * p );
extern int Abc_NamMemUsed( Abc_Nam_t * p );
extern int Abc_NamMemAlloc( Abc_Nam_t * p );
extern int Abc_NamStrFind( Abc_Nam_t * p, char * pStr );
+extern int Abc_NamStrFindLim( Abc_Nam_t * p, char * pStr, char * pLim );
extern int Abc_NamStrFindOrAdd( Abc_Nam_t * p, char * pStr, int * pfFound );
+extern int Abc_NamStrFindOrAddLim( Abc_Nam_t * p, char * pStr, char * pLim, int * pfFound );
extern char * Abc_NamStr( Abc_Nam_t * p, int id );
extern Vec_Int_t * Abc_NamComputeIdMap( Abc_Nam_t * p1, Abc_Nam_t * p2 );
extern int Abc_NamReportCommon( Vec_Int_t * vNameIds1, Abc_Nam_t * p1, Abc_Nam_t * p2 );
diff --git a/src/misc/vec/vecInt.h b/src/misc/vec/vecInt.h
index 26c67073..3e195bd3 100644
--- a/src/misc/vec/vecInt.h
+++ b/src/misc/vec/vecInt.h
@@ -65,6 +65,8 @@ struct Vec_Int_t_
for ( i = 0; (i < Vec_IntSize(vVec1)) && (((Entry1) = Vec_IntEntry(vVec1, i)), 1) && (((Entry2) = Vec_IntEntry(vVec2, i)), 1); i++ )
#define Vec_IntForEachEntryDouble( vVec, Entry1, Entry2, i ) \
for ( i = 0; (i+1 < Vec_IntSize(vVec)) && (((Entry1) = Vec_IntEntry(vVec, i)), 1) && (((Entry2) = Vec_IntEntry(vVec, i+1)), 1); i += 2 )
+#define Vec_IntForEachEntryTriple( vVec, Entry1, Entry2, Entry3, i ) \
+ for ( i = 0; (i+2 < Vec_IntSize(vVec)) && (((Entry1) = Vec_IntEntry(vVec, i)), 1) && (((Entry2) = Vec_IntEntry(vVec, i+1)), 1) && (((Entry3) = Vec_IntEntry(vVec, i+2)), 1); i += 3 )
#define Vec_IntForEachEntryThisNext( vVec, This, Next, i ) \
for ( i = 0, (This) = (Next) = (Vec_IntSize(vVec) ? Vec_IntEntry(vVec, 0) : -1); (i+1 < Vec_IntSize(vVec)) && (((Next) = Vec_IntEntry(vVec, i+1)), 1); i += 2, (This) = (Next) )
@@ -696,6 +698,11 @@ static inline void Vec_IntPush( Vec_Int_t * p, int Entry )
}
p->pArray[p->nSize++] = Entry;
}
+static inline void Vec_IntPushTwo( Vec_Int_t * p, int Entry1, int Entry2 )
+{
+ Vec_IntPush( p, Entry1 );
+ Vec_IntPush( p, Entry2 );
+}
static inline void Vec_IntPushArray( Vec_Int_t * p, int * pEntries, int nEntries )
{
int i;
@@ -1045,6 +1052,34 @@ static inline void Vec_IntReverseOrder( Vec_Int_t * p )
/**Function*************************************************************
+ Synopsis [Removes odd entries.]
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+static inline void Vec_IntRemoveOdd( Vec_Int_t * p )
+{
+ int i;
+ assert( (p->nSize & 1) == 0 );
+ p->nSize >>= 1;
+ for ( i = 0; i < p->nSize; i++ )
+ p->pArray[i] = p->pArray[2*i];
+}
+static inline void Vec_IntRemoveEven( Vec_Int_t * p )
+{
+ int i;
+ assert( (p->nSize & 1) == 0 );
+ p->nSize >>= 1;
+ for ( i = 0; i < p->nSize; i++ )
+ p->pArray[i] = p->pArray[2*i+1];
+}
+
+/**Function*************************************************************
+
Synopsis []
Description []
@@ -1144,6 +1179,13 @@ static inline int Vec_IntCountPositive( Vec_Int_t * p )
Counter += (p->pArray[i] > 0);
return Counter;
}
+static inline int Vec_IntCountZero( Vec_Int_t * p )
+{
+ int i, Counter = 0;
+ for ( i = 0; i < p->nSize; i++ )
+ Counter += (p->pArray[i] == 0);
+ return Counter;
+}
/**Function*************************************************************