diff options
author | Alan Mishchenko <alanmi@berkeley.edu> | 2017-04-10 14:17:03 -0700 |
---|---|---|
committer | Alan Mishchenko <alanmi@berkeley.edu> | 2017-04-10 14:17:03 -0700 |
commit | 175b42b48f52852b10af26a59c7e5e7b8e0ee13c (patch) | |
tree | 24a94b89a231f347963cf6b3ad16c311abb4fece /src/misc/util/utilNam.c | |
parent | fe3d334151dd3b81dca4beaa8635d89d3f8b2d71 (diff) | |
download | abc-175b42b48f52852b10af26a59c7e5e7b8e0ee13c.tar.gz abc-175b42b48f52852b10af26a59c7e5e7b8e0ee13c.tar.bz2 abc-175b42b48f52852b10af26a59c7e5e7b8e0ee13c.zip |
Experiments with hashing.
Diffstat (limited to 'src/misc/util/utilNam.c')
-rw-r--r-- | src/misc/util/utilNam.c | 24 |
1 files changed, 22 insertions, 2 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************************************************************* |