X-Git-Url: https://git.octo.it/?p=rrdtool.git;a=blobdiff_plain;f=src%2Fhash_32.c;h=7885c3ed2d1863dedc1eb7ba88e25759d269735a;hp=3fda164c2d3cfd951168d56c5c5524adda20eb7d;hb=f0a82ae15cafb6ad47ea0c9f74754820e92e2078;hpb=7c016dfa001ae254bf4e18126f814ee8f0abd821 diff --git a/src/hash_32.c b/src/hash_32.c index 3fda164..7885c3e 100644 --- a/src/hash_32.c +++ b/src/hash_32.c @@ -65,7 +65,7 @@ /* * 32 bit magic FNV-0 and FNV-1 prime */ -#define FNV_32_PRIME ((Fnv32_t)0x01000193) +#define FNV_32_PRIME ((Fnv32_t)0x01000193) /* @@ -85,22 +85,24 @@ * NOTE: To use the recommended 32 bit FNV-1 hash, use FNV1_32_INIT as the hval * argument on the first call to either fnv_32_buf() or fnv_32_str(). */ -Fnv32_t -fnv_32_buf(void *buf, size_t len, Fnv32_t hval) +Fnv32_t fnv_32_buf( + const void *buf, + size_t len, + Fnv32_t hval) { - unsigned char *bp = (unsigned char *)buf; /* start of buffer */ - unsigned char *be = bp + len; /* beyond end of buffer */ + const unsigned char *bp = (const unsigned char *) buf; /* start of buffer */ + const unsigned char *be = bp + len; /* beyond end of buffer */ /* * FNV-1 hash each octet in the buffer */ while (bp < be) { - /* multiply by the 32 bit FNV magic prime mod 2^64 */ - hval *= FNV_32_PRIME; + /* multiply by the 32 bit FNV magic prime mod 2^64 */ + hval *= FNV_32_PRIME; - /* xor the bottom with the current octet */ - hval ^= (Fnv32_t)*bp++; + /* xor the bottom with the current octet */ + hval ^= (Fnv32_t) *bp++; } /* return our new hash value */ @@ -124,21 +126,22 @@ fnv_32_buf(void *buf, size_t len, Fnv32_t hval) * NOTE: To use the recommended 32 bit FNV-1 hash, use FNV1_32_INIT as the hval * argument on the first call to either fnv_32_buf() or fnv_32_str(). */ -Fnv32_t -fnv_32_str(char *str, Fnv32_t hval) +Fnv32_t fnv_32_str( + const char *str, + Fnv32_t hval) { - unsigned char *s = (unsigned char *)str; /* unsigned string */ + const unsigned char *s = (const unsigned char *) str; /* unsigned string */ /* * FNV-1 hash each octet in the buffer */ while (*s) { - /* multiply by the 32 bit FNV magic prime mod 2^64 */ - hval *= FNV_32_PRIME; + /* multiply by the 32 bit FNV magic prime mod 2^64 */ + hval *= FNV_32_PRIME; - /* xor the bottom with the current octet */ - hval ^= (Fnv32_t)*s++; + /* xor the bottom with the current octet */ + hval ^= (Fnv32_t) *s++; } /* return our new hash value */ @@ -146,7 +149,8 @@ fnv_32_str(char *str, Fnv32_t hval) } /* a wrapper function for fnv_32_str */ -unsigned long FnvHash(char *str) +unsigned long FnvHash( + const char *str) { - return fnv_32_str(str,FNV1_32_INIT); + return fnv_32_str(str, FNV1_32_INIT); }