summaryrefslogtreecommitdiffstats
path: root/src/misc/vec/vecWec.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/misc/vec/vecWec.h')
-rw-r--r--src/misc/vec/vecWec.h137
1 files changed, 136 insertions, 1 deletions
diff --git a/src/misc/vec/vecWec.h b/src/misc/vec/vecWec.h
index fdbded9c..cd463e01 100644
--- a/src/misc/vec/vecWec.h
+++ b/src/misc/vec/vecWec.h
@@ -275,6 +275,13 @@ static inline void Vec_WecClear( Vec_Wec_t * p )
Vec_IntClear( vVec );
p->nSize = 0;
}
+static inline void Vec_WecClearLevels( Vec_Wec_t * p )
+{
+ Vec_Int_t * vVec;
+ int i;
+ Vec_WecForEachLevel( p, vVec, i )
+ Vec_IntClear( vVec );
+}
/**Function*************************************************************
@@ -296,6 +303,15 @@ static inline void Vec_WecPush( Vec_Wec_t * p, int Level, int Entry )
}
Vec_IntPush( Vec_WecEntry(p, Level), Entry );
}
+static inline void Vec_WecPushTwo( Vec_Wec_t * p, int Level, int Entry1, int Entry2 )
+{
+ if ( p->nSize < Level + 1 )
+ {
+ Vec_WecGrow( p, Abc_MaxInt(2*p->nSize, Level + 1) );
+ p->nSize = Level + 1;
+ }
+ Vec_IntPushTwo( Vec_WecEntry(p, Level), Entry1, Entry2 );
+}
static inline Vec_Int_t * Vec_WecPushLevel( Vec_Wec_t * p )
{
if ( p->nSize == p->nCap )
@@ -422,7 +438,7 @@ static inline Vec_Wec_t * Vec_WecDup( Vec_Wec_t * p )
Vec_Wec_t * vNew;
Vec_Int_t * vVec;
int i, k, Entry;
- vNew = Vec_WecAlloc( Vec_WecSize(p) );
+ vNew = Vec_WecStart( Vec_WecSize(p) );
Vec_WecForEachLevel( p, vVec, i )
Vec_IntForEachEntry( vVec, Entry, k )
Vec_WecPush( vNew, i, Entry );
@@ -552,6 +568,29 @@ static inline void Vec_WecSortByLastInt( Vec_Wec_t * p, int fReverse )
SeeAlso []
***********************************************************************/
+static inline void Vec_WecKeepLevels( Vec_Wec_t * p, int Limit )
+{
+ Vec_Int_t * vLevel; int i, k = 0;
+ Vec_WecForEachLevel( p, vLevel, i )
+ if ( Vec_IntSize(vLevel) > Limit )
+ {
+ ABC_SWAP( Vec_Int_t, Vec_WecArray(p)[i], Vec_WecArray(p)[k] );
+ k++;
+ }
+ Vec_WecShrink( p, k );
+}
+
+/**Function*************************************************************
+
+ Synopsis []
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
static inline void Vec_WecPrint( Vec_Wec_t * p, int fSkipSingles )
{
Vec_Int_t * vVec;
@@ -637,6 +676,25 @@ static inline int Vec_WecCountNonTrivial( Vec_Wec_t * p, int * pnUsed )
SeeAlso []
***********************************************************************/
+static inline int Vec_WecMaxLevelSize( Vec_Wec_t * p )
+{
+ Vec_Int_t * vTemp; int i, Res = 0;
+ Vec_WecForEachLevel( p, vTemp, i )
+ Res = Abc_MaxInt( Res, Vec_IntSize(vTemp) );
+ return Res;
+}
+
+/**Function*************************************************************
+
+ Synopsis []
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
static inline Vec_Int_t * Vec_WecCollectFirsts( Vec_Wec_t * p )
{
Vec_Int_t * vFirsts, * vLevel;
@@ -733,6 +791,83 @@ static inline void Vec_WecRemoveEmpty( Vec_Wec_t * vCubes )
}
+/**Function*************************************************************
+
+ Synopsis [File interface.]
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+static inline void Vec_WecDumpBin( char * pFileName, Vec_Wec_t * p, int fVerbose )
+{
+ Vec_Int_t * vLevel;
+ int i, nSize, RetValue;
+ FILE * pFile = fopen( pFileName, "wb" );
+ if ( pFile == NULL )
+ {
+ printf( "Cannot open file \"%s\" for writing.\n", pFileName );
+ return;
+ }
+ nSize = Vec_WecSize(p);
+ RetValue = fwrite( &nSize, 1, sizeof(int), pFile );
+ Vec_WecForEachLevel( p, vLevel, i )
+ {
+ nSize = Vec_IntSize(vLevel);
+ RetValue += fwrite( &nSize, 1, sizeof(int), pFile );
+ RetValue += fwrite( Vec_IntArray(vLevel), 1, sizeof(int)*nSize, pFile );
+ }
+ fclose( pFile );
+ if ( RetValue != (int)sizeof(int)*(Vec_WecSizeSize(p)+Vec_WecSize(p)+1) )
+ printf( "Error writing data into file.\n" );
+ if ( fVerbose )
+ printf( "Written %d integer arrays into file \"%s\".\n", Vec_WecSize(p), pFileName );
+}
+static inline Vec_Wec_t * Vec_WecReadBin( char * pFileName, int fVerbose )
+{
+ Vec_Wec_t * p = NULL; Vec_Int_t * vLevel; int i, nSize, RetValue;
+ FILE * pFile = fopen( pFileName, "rb" );
+ if ( pFile == NULL )
+ {
+ printf( "Cannot open file \"%s\" for reading.\n", pFileName );
+ return NULL;
+ }
+ fseek( pFile, 0, SEEK_END );
+ nSize = ftell( pFile );
+ if ( nSize == 0 )
+ {
+ printf( "The input file is empty.\n" );
+ fclose( pFile );
+ return NULL;
+ }
+ if ( nSize % sizeof(int) > 0 )
+ {
+ printf( "Cannot read file with integers because it is not aligned at 4 bytes (remainder = %d).\n", (int)(nSize % sizeof(int)) );
+ fclose( pFile );
+ return NULL;
+ }
+ rewind( pFile );
+ RetValue = fread( &nSize, 1, sizeof(int), pFile );
+ assert( RetValue == 4 );
+ p = Vec_WecStart( nSize );
+ Vec_WecForEachLevel( p, vLevel, i )
+ {
+ RetValue = fread( &nSize, 1, sizeof(int), pFile );
+ assert( RetValue == 4 );
+ Vec_IntFill( vLevel, nSize, 0 );
+ RetValue = fread( Vec_IntArray(vLevel), 1, sizeof(int)*nSize, pFile );
+ assert( RetValue == 4*nSize );
+ }
+ fclose( pFile );
+ if ( fVerbose )
+ printf( "Read %d integer arrays from file \"%s\".\n", Vec_WecSize(p), pFileName );
+ return p;
+}
+
+
ABC_NAMESPACE_HEADER_END
#endif