11/*******************************************************************************
22*** Author: Tyler Barrus
334- *** Version: 0.1.8
4+ *** Version: 0.2.0
55*** License: MIT 2017
66*******************************************************************************/
77
@@ -24,7 +24,7 @@ static void __read_from_file(CountMinSketch* cms, FILE *fp, short on_disk, const
2424static void __merge_cms (CountMinSketch * base , int num_sketches , va_list * args );
2525static int __validate_merge (CountMinSketch * base , int num_sketches , va_list * args );
2626static uint64_t * __default_hash (unsigned int num_hashes , const char * key );
27- static uint64_t __fnv_1a (const char * key );
27+ static uint64_t __fnv_1a (const char * key , int seed );
2828static int __compare (const void * a , const void * b );
2929static int32_t __safe_add (int32_t a , uint32_t b );
3030static int32_t __safe_sub (int32_t a , uint32_t b );
@@ -389,20 +389,18 @@ static int __validate_merge(CountMinSketch* base, int num_sketches, va_list* arg
389389
390390/* NOTE: The caller will free the results */
391391static uint64_t * __default_hash (unsigned int num_hashes , const char * str ) {
392- uint64_t * results = (uint64_t * )calloc (num_hashes , sizeof (uint64_t ));
393- char key [17 ] = {0 }; // largest value is 7FFF,FFFF,FFFF,FFFF
394- results [0 ] = __fnv_1a (str );
395- for (unsigned int i = 1 ; i < num_hashes ; ++ i ) {
396- sprintf (key , "%" PRIx64 "" , results [i - 1 ]);
397- results [i ] = __fnv_1a (key );
392+ uint64_t * results = (uint64_t * )calloc (num_hashes , sizeof (uint64_t ));
393+ int i ;
394+ for (i = 0 ; i < num_hashes ; ++ i ) {
395+ results [i ] = __fnv_1a (str , i );
398396 }
399397 return results ;
400398}
401399
402- static uint64_t __fnv_1a (const char * key ) {
400+ static uint64_t __fnv_1a (const char * key , int seed ) {
403401 // FNV-1a hash (http://www.isthe.com/chongo/tech/comp/fnv/)
404402 int i , len = strlen (key );
405- uint64_t h = 14695981039346656037ULL ; // FNV_OFFSET 64 bit
403+ uint64_t h = 14695981039346656037ULL + ( 31 * seed ) ; // FNV_OFFSET 64 bit with magic number seed
406404 for (i = 0 ; i < len ; ++ i ){
407405 h = h ^ (unsigned char ) key [i ];
408406 h = h * 1099511628211ULL ; // FNV_PRIME 64 bit
0 commit comments