]> arthur.barton.de Git - netdata.git/commitdiff
replace simple_hash with one at a time hash
authorCosta Tsaousis (ktsaou) <costa@tsaousis.gr>
Thu, 2 Apr 2015 21:52:24 +0000 (00:52 +0300)
committerCosta Tsaousis (ktsaou) <costa@tsaousis.gr>
Thu, 2 Apr 2015 21:52:24 +0000 (00:52 +0300)
src/common.c
src/rrd.c

index a76b78f227b935c715170d3231cf9fa885bc6729..46cb182e4b0676691de4c956cc1e726f7b7f8b6a 100755 (executable)
@@ -30,6 +30,7 @@ uint32_t simple_hash(const char *name)
 }
 */
 
+/*
 // http://isthe.com/chongo/tech/comp/fnv/#FNV-1a
 uint32_t simple_hash(const char *name) {
        unsigned char *s = (unsigned char *)name;
@@ -48,7 +49,28 @@ uint32_t simple_hash(const char *name) {
        // fprintf(stderr, "HASH: %u = %s\n", hval, name);
        return hval;
 }
+*/
+
+// http://eternallyconfuzzled.com/tuts/algorithms/jsw_tut_hashing.aspx
+// one at a time hash
+uint32_t simple_hash(const char *name) {
+       unsigned char *s = (unsigned char *)name;
+       uint32_t h = 0;
 
+       while(*s) {
+               h += *s++;
+               h += (h << 10);
+               h ^= (h >> 6);
+       }
+
+       h += (h << 3);
+       h ^= (h >> 11);
+       h += (h << 15);
+
+       // fprintf(stderr, "HASH: %u = %s\n", h, name);
+
+       return h;
+}
 
 void strreverse(char* begin, char* end)
 {
index 7de62ef8892d609bea1c6f4648a153f73be29fcf..b05669ebd5f2441ef89037f6606078baf0e2c1fe 100755 (executable)
--- a/src/rrd.c
+++ b/src/rrd.c
@@ -127,7 +127,6 @@ static int rrddim_compare(void* a, void* b) {
 
 static RRDDIM *rrddim_index_find(RRDSET *st, const char *id, uint32_t hash) {
        RRDDIM *result = NULL, tmp;
-       tmp.hash = (hash)?hash:simple_hash(id);
        strncpy(tmp.id, id, RRD_ID_LENGTH_MAX);
        tmp.id[RRD_ID_LENGTH_MAX] = '\0';
        tmp.hash = (hash)?hash:simple_hash(tmp.id);