@cryptotaxi247 / netdata-1 / commits / 67af57710

replace simple_hash with one at a time hash

Costa Tsaousis (ktsaou) committed Apr 3, 2015 at 00:52 UTC 67af57710d1fef400f48313bdff325f56e41778e
2 files changed +22 -1
src/common.c
+22
@@ -30,6 +30,7 @@ uint32_t simple_hash(const char *name)
30 }
31 */
32
33 +/*
34 // http://isthe.com/chongo/tech/comp/fnv/#FNV-1a
35 uint32_t simple_hash(const char *name) {
36 unsigned char *s = (unsigned char *)name;
@@ -48,7 +49,28 @@ uint32_t simple_hash(const char *name) {
49 // fprintf(stderr, "HASH: %u = %s\n", hval, name);
50 return hval;
51 }
52 +*/
53 +
54 +// http://eternallyconfuzzled.com/tuts/algorithms/jsw_tut_hashing.aspx
55 +// one at a time hash
56 +uint32_t simple_hash(const char *name) {
57 + unsigned char *s = (unsigned char *)name;
58 + uint32_t h = 0;
59
60 + while(*s) {
61 + h += *s++;
62 + h += (h << 10);
63 + h ^= (h >> 6);
64 + }
65 +
66 + h += (h << 3);
67 + h ^= (h >> 11);
68 + h += (h << 15);
69 +
70 + // fprintf(stderr, "HASH: %u = %s\n", h, name);
71 +
72 + return h;
73 +}
74
75 void strreverse(char* begin, char* end)
76 {
src/rrd.c
-1
@@ -127,7 +127,6 @@ static int rrddim_compare(void* a, void* b) {
127
128 static RRDDIM *rrddim_index_find(RRDSET *st, const char *id, uint32_t hash) {
129 RRDDIM *result = NULL, tmp;
130 - tmp.hash = (hash)?hash:simple_hash(id);
130 strncpy(tmp.id, id, RRD_ID_LENGTH_MAX);
131 tmp.id[RRD_ID_LENGTH_MAX] = '\0';
132 tmp.hash = (hash)?hash:simple_hash(tmp.id);