summaryrefslogtreecommitdiffstats
path: root/src/misc
diff options
context:
space:
mode:
Diffstat (limited to 'src/misc')
-rw-r--r--src/misc/util/utilNam.c24
-rw-r--r--src/misc/util/utilNam.h2
-rw-r--r--src/misc/vec/vecHsh.h19
3 files changed, 41 insertions, 4 deletions
diff --git a/src/misc/util/utilNam.c b/src/misc/util/utilNam.c
index 6cb180c0..30a68c63 100644
--- a/src/misc/util/utilNam.c
+++ b/src/misc/util/utilNam.c
@@ -131,11 +131,15 @@ void Abc_NamStop( Abc_Nam_t * p )
SeeAlso []
***********************************************************************/
-void Abc_NamPrint( Abc_Nam_t * p )
+void Abc_NamPrint( Abc_Nam_t * p, char * pFileName )
{
+ FILE * pFile = pFileName ? fopen( pFileName, "wb" ) : stdout;
int h, i;
+ if ( pFile == NULL ) { printf( "Count node open file %s\n", pFileName ); return; }
Vec_IntForEachEntryStart( &p->vInt2Handle, h, i, 1 )
- Abc_Print( 1, "%d=\n%s\n", i, Abc_NamHandleToStr(p, h) );
+ fprintf( pFile, "%8d = %s\n", i, Abc_NamHandleToStr(p, h) );
+ if ( pFile != stdout )
+ fclose(pFile);
}
/**Function*************************************************************
@@ -275,6 +279,22 @@ int Abc_NamStrHash( const char * pStr, const char * pLim, int nTableSize )
}
return uHash % nTableSize;
}
+// https://en.wikipedia.org/wiki/Jenkins_hash_function
+int Abc_NamStrHash2( const char * pStr, const char * pLim, int nTableSize )
+{
+ int nSize = pLim ? pLim - pStr : -1;
+ int i = 0; unsigned hash = 0;
+ while ( i != nSize && pStr[i] )
+ {
+ hash += pStr[i++];
+ hash += hash << 10;
+ hash ^= hash >> 6;
+ }
+ hash += hash << 3;
+ hash ^= hash >> 11;
+ hash += hash << 15;
+ return (int)(hash % nTableSize);
+}
/**Function*************************************************************
diff --git a/src/misc/util/utilNam.h b/src/misc/util/utilNam.h
index 8083a566..8e054fc1 100644
--- a/src/misc/util/utilNam.h
+++ b/src/misc/util/utilNam.h
@@ -52,7 +52,7 @@ typedef struct Abc_Nam_t_ Abc_Nam_t;
/*=== utilNam.c ===============================================================*/
extern Abc_Nam_t * Abc_NamStart( int nObjs, int nAveSize );
extern void Abc_NamStop( Abc_Nam_t * p );
-extern void Abc_NamPrint( Abc_Nam_t * p );
+extern void Abc_NamPrint( Abc_Nam_t * p, char * pFileName );
extern Abc_Nam_t * Abc_NamRef( Abc_Nam_t * p );
extern void Abc_NamDeref( Abc_Nam_t * p );
extern int Abc_NamObjNumMax( Abc_Nam_t * p );
diff --git a/src/misc/vec/vecHsh.h b/src/misc/vec/vecHsh.h
index de9a038a..4f15f6f0 100644
--- a/src/misc/vec/vecHsh.h
+++ b/src/misc/vec/vecHsh.h
@@ -140,7 +140,24 @@ static inline int Hsh_IntManEntryNum( Hsh_IntMan_t * p )
SeeAlso []
***********************************************************************/
-static inline int Hsh_IntManHash( unsigned * pData, int nSize, int nTableSize )
+// https://en.wikipedia.org/wiki/Jenkins_hash_function
+static inline int Hsh_IntManHash( unsigned * pData, int nSize, int nTableSize )
+{
+ int i = 0; unsigned hash = 0;
+ unsigned char * pDataC = (unsigned char *)pData;
+ nSize <<= 2;
+ while ( i != nSize )
+ {
+ hash += pDataC[i++];
+ hash += hash << 10;
+ hash ^= hash >> 6;
+ }
+ hash += hash << 3;
+ hash ^= hash >> 11;
+ hash += hash << 15;
+ return (int)(hash % nTableSize);
+}
+static inline int Hsh_IntManHash2( unsigned * pData, int nSize, int nTableSize )
{
static int s_Primes[7] = { 4177, 5147, 5647, 6343, 7103, 7873, 8147 };
unsigned char * pDataC = (unsigned char *)pData;