Commit 3818aeac authored by Bradley C. Kuszmaul's avatar Bradley C. Kuszmaul

Use FNV hash function

git-svn-id: file:///svn/tokudb@117 c7de825b-a66e-492c-adef-691d508d4ae1
parent 872a3881
......@@ -7,6 +7,7 @@
#include <errno.h>
#include <sys/stat.h>
#include <string.h>
#include "hashfun.h"
//#define TRACE_CACHETABLE
#ifdef TRACE_CACHETABLE
......@@ -164,27 +165,14 @@ int cachefile_count_pinned (CACHEFILE cf, int print_them) {
return n_pinned;
}
static unsigned int hash_key (const char *key, int keylen) {
/* From Sedgewick. There are probably better hash functions. */
unsigned int b = 378551;
unsigned int a = 63689;
unsigned int hash = 0;
int i;
for (i = 0; i < keylen; i++ ) {
hash = hash * a + key[i];
a *= b;
}
return hash;
}
unsigned int ct_hash_longlong (unsigned long long l) {
unsigned int r = hash_key((char*)&l, 8);
unsigned int r = hash_key((unsigned char*)&l, 8);
printf("%lld --> %d --> %d\n", l, r, r%64);
return r;
}
static unsigned int hashit (CACHETABLE t, CACHEKEY key) {
return hash_key((char*)&key, sizeof(key))%t->table_size;
return hash_key((unsigned char*)&key, sizeof(key))%t->table_size;
}
......
......@@ -9,6 +9,7 @@
#include "key.h"
#include "yerror.h"
#include "hashfun.h"
int toku_hashtable_create (HASHTABLE *h) {
HASHTABLE MALLOC(tab);
......@@ -23,33 +24,6 @@ int toku_hashtable_create (HASHTABLE *h) {
return 0;
}
// FNV Hash: From an idea sent by Glenn Fowler and Phong Vo to the IEEE POSIX 1003.2 committee. Landon Curt Noll improved it.
// See: http://isthe.com/chongo/tech/comp/fnv/
static unsigned int hash_key (const char *key, ITEMLEN keylen) {
ITEMLEN i;
unsigned int hash=0;
for (i=0; i<keylen; i++, key++) {
hash *= 16777619;
hash ^= *(unsigned char*)key;
}
return hash;
}
#if 0
static unsigned int hash_key (const char *key, ITEMLEN keylen) {
/* From Sedgewick. There are probably better hash functions. */
unsigned int b = 378551;
unsigned int a = 63689;
unsigned int hash = 0;
ITEMLEN i;
for (i = 0; i < keylen; i++ ) {
hash = hash * a + key[i];
a *= b;
}
return hash;
}
#endif
static void hash_find_internal (HASHTABLE tab, const char *key, ITEMLEN keylen, HASHELT *hashelt, HASHELT **prev_ptr) {
unsigned int h = hash_key (key, keylen) % tab->arraysize;
HASHELT he;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment