Improved c++0x test.
This commit is contained in:
@@ -7,9 +7,8 @@
|
||||
#include <limits.h>
|
||||
#include <string.h>
|
||||
|
||||
// #define DEBUG
|
||||
//#define DEBUG
|
||||
#include "debug.h"
|
||||
#include "MurmurHash2.h"
|
||||
|
||||
#define hashsize(n) ((cmph_uint32)1<<(n))
|
||||
#define hashmask(n) (hashsize(n)-1)
|
||||
@@ -88,8 +87,8 @@ acceptable. Do NOT use for cryptographic purposes.
|
||||
jenkins_state_t *jenkins_state_new(cmph_uint32 size) //size of hash table
|
||||
{
|
||||
jenkins_state_t *state = (jenkins_state_t *)malloc(sizeof(jenkins_state_t));
|
||||
DEBUGP("Initializing jenkins hash\n");
|
||||
state->seed = ((cmph_uint32)rand() % size);
|
||||
DEBUGP("Initializied jenkins hash with seed %d\n", state->seed);
|
||||
return state;
|
||||
}
|
||||
void jenkins_state_destroy(jenkins_state_t *state)
|
||||
@@ -100,67 +99,63 @@ void jenkins_state_destroy(jenkins_state_t *state)
|
||||
|
||||
static inline void __jenkins_hash_vector(cmph_uint32 seed, const char *k, cmph_uint32 keylen, cmph_uint32 * hashes)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < 3; ++i) {
|
||||
hashes[i] = MurmurHash2(k, keylen, seed + i);
|
||||
register cmph_uint32 len, length;
|
||||
|
||||
/* Set up the internal state */
|
||||
length = keylen;
|
||||
len = length;
|
||||
hashes[0] = hashes[1] = 0x9e3779b9; /* the golden ratio; an arbitrary value */
|
||||
hashes[2] = seed; /* the previous hash value - seed in our case */
|
||||
|
||||
/*---------------------------------------- handle most of the key */
|
||||
while (len >= 12)
|
||||
{
|
||||
hashes[0] += ((cmph_uint32)k[0] +((cmph_uint32)k[1]<<8) +((cmph_uint32)k[2]<<16) +((cmph_uint32)k[3]<<24));
|
||||
hashes[1] += ((cmph_uint32)k[4] +((cmph_uint32)k[5]<<8) +((cmph_uint32)k[6]<<16) +((cmph_uint32)k[7]<<24));
|
||||
hashes[2] += ((cmph_uint32)k[8] +((cmph_uint32)k[9]<<8) +((cmph_uint32)k[10]<<16)+((cmph_uint32)k[11]<<24));
|
||||
mix(hashes[0],hashes[1],hashes[2]);
|
||||
k += 12; len -= 12;
|
||||
}
|
||||
// register cmph_uint32 len, length;
|
||||
//
|
||||
// /* Set up the internal state */
|
||||
// length = keylen;
|
||||
// len = length;
|
||||
// hashes[0] = hashes[1] = 0x9e3779b9; /* the golden ratio; an arbitrary value */
|
||||
// hashes[2] = seed; /* the previous hash value - seed in our case */
|
||||
//
|
||||
// /*---------------------------------------- handle most of the key */
|
||||
// while (len >= 12)
|
||||
// {
|
||||
// hashes[0] += ((cmph_uint32)k[0] +((cmph_uint32)k[1]<<8) +((cmph_uint32)k[2]<<16) +((cmph_uint32)k[3]<<24));
|
||||
// hashes[1] += ((cmph_uint32)k[4] +((cmph_uint32)k[5]<<8) +((cmph_uint32)k[6]<<16) +((cmph_uint32)k[7]<<24));
|
||||
// hashes[2] += ((cmph_uint32)k[8] +((cmph_uint32)k[9]<<8) +((cmph_uint32)k[10]<<16)+((cmph_uint32)k[11]<<24));
|
||||
// mix(hashes[0],hashes[1],hashes[2]);
|
||||
// k += 12; len -= 12;
|
||||
// }
|
||||
//
|
||||
// /*------------------------------------- handle the last 11 bytes */
|
||||
// hashes[2] += length;
|
||||
// switch(len) /* all the case statements fall through */
|
||||
// {
|
||||
// case 11:
|
||||
// hashes[2] +=((cmph_uint32)k[10]<<24);
|
||||
// case 10:
|
||||
// hashes[2] +=((cmph_uint32)k[9]<<16);
|
||||
// case 9 :
|
||||
// hashes[2] +=((cmph_uint32)k[8]<<8);
|
||||
// /* the first byte of hashes[2] is reserved for the length */
|
||||
// case 8 :
|
||||
// hashes[1] +=((cmph_uint32)k[7]<<24);
|
||||
// case 7 :
|
||||
// hashes[1] +=((cmph_uint32)k[6]<<16);
|
||||
// case 6 :
|
||||
// hashes[1] +=((cmph_uint32)k[5]<<8);
|
||||
// case 5 :
|
||||
// hashes[1] +=(cmph_uint8) k[4];
|
||||
// case 4 :
|
||||
// hashes[0] +=((cmph_uint32)k[3]<<24);
|
||||
// case 3 :
|
||||
// hashes[0] +=((cmph_uint32)k[2]<<16);
|
||||
// case 2 :
|
||||
// hashes[0] +=((cmph_uint32)k[1]<<8);
|
||||
// case 1 :
|
||||
// hashes[0] +=(cmph_uint8)k[0];
|
||||
// /* case 0: nothing left to add */
|
||||
// }
|
||||
//
|
||||
// mix(hashes[0],hashes[1],hashes[2]);
|
||||
|
||||
/*------------------------------------- handle the last 11 bytes */
|
||||
hashes[2] += length;
|
||||
switch(len) /* all the case statements fall through */
|
||||
{
|
||||
case 11:
|
||||
hashes[2] +=((cmph_uint32)k[10]<<24);
|
||||
case 10:
|
||||
hashes[2] +=((cmph_uint32)k[9]<<16);
|
||||
case 9 :
|
||||
hashes[2] +=((cmph_uint32)k[8]<<8);
|
||||
/* the first byte of hashes[2] is reserved for the length */
|
||||
case 8 :
|
||||
hashes[1] +=((cmph_uint32)k[7]<<24);
|
||||
case 7 :
|
||||
hashes[1] +=((cmph_uint32)k[6]<<16);
|
||||
case 6 :
|
||||
hashes[1] +=((cmph_uint32)k[5]<<8);
|
||||
case 5 :
|
||||
hashes[1] +=(cmph_uint8) k[4];
|
||||
case 4 :
|
||||
hashes[0] +=((cmph_uint32)k[3]<<24);
|
||||
case 3 :
|
||||
hashes[0] +=((cmph_uint32)k[2]<<16);
|
||||
case 2 :
|
||||
hashes[0] +=((cmph_uint32)k[1]<<8);
|
||||
case 1 :
|
||||
hashes[0] +=(cmph_uint8)k[0];
|
||||
/* case 0: nothing left to add */
|
||||
}
|
||||
|
||||
mix(hashes[0],hashes[1],hashes[2]);
|
||||
}
|
||||
|
||||
cmph_uint32 jenkins_hash(jenkins_state_t *state, const char *k, cmph_uint32 keylen)
|
||||
{
|
||||
// cmph_uint32 hashes[3];
|
||||
// __jenkins_hash_vector(state->seed, k, keylen, hashes);
|
||||
// return hashes[2];
|
||||
cmph_uint32 a, b, c;
|
||||
cmph_uint32 hashes[3];
|
||||
__jenkins_hash_vector(state->seed, k, keylen, hashes);
|
||||
return hashes[2];
|
||||
/* cmph_uint32 a, b, c;
|
||||
cmph_uint32 len, length;
|
||||
|
||||
// Set up the internal state
|
||||
@@ -214,6 +209,7 @@ cmph_uint32 jenkins_hash(jenkins_state_t *state, const char *k, cmph_uint32 keyl
|
||||
/// report the result
|
||||
|
||||
return c;
|
||||
*/
|
||||
}
|
||||
|
||||
void jenkins_hash_vector_(jenkins_state_t *state, const char *k, cmph_uint32 keylen, cmph_uint32 * hashes)
|
||||
|
||||
Reference in New Issue
Block a user