From a9d5b6c6db3a99ba92ef4b298702ecfbbd5145af Mon Sep 17 00:00:00 2001 From: Date: Tue, 23 Sep 2008 02:16:51 +0300 Subject: [PATCH] Merging in Brian Pontz work on Jenkins hash --- ChangeLog | 5 ++++- docs/memcached_behavior.pod | 3 ++- libmemcached/Makefile.am | 1 + libmemcached/common.h | 1 + libmemcached/memcached_constants.h | 3 ++- libmemcached/memcached_hash.c | 5 +++++ tests/function.c | 10 ++++++++++ 7 files changed, 25 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 16e53cb1..ecb91f72 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,7 @@ -0.24 Tue Sep 16 02:59:03 PDT 2008 +0.25 + * Jenkins HASH added. + +0.24 Tue Sep 16 02:59:03 PDT 2008 (never released) * Cleanup compile warnings. * Fix issues in partitioning by keys. * Fixed "fail case" to make sure when calling memcached_clone() no diff --git a/docs/memcached_behavior.pod b/docs/memcached_behavior.pod index 68714fb4..51e09e71 100755 --- a/docs/memcached_behavior.pod +++ b/docs/memcached_behavior.pod @@ -64,7 +64,8 @@ environments). =item MEMCACHED_BEHAVIOR_HASH Makes the default hashing algorithm for keys use MD5. The value can be set -to either MEMCACHED_HASH_DEFAULT, MEMCACHED_HASH_MD5, MEMCACHED_HASH_CRC, MEMCACHED_HASH_FNV1_64, MEMCACHED_HASH_FNV1A_64, MEMCACHED_HASH_FNV1_32, and MEMCACHED_HASH_FNV1A_32. The behavior for all hashes but MEMCACHED_HASH_DEFAULT is identitical to the Java driver written by Dustin Sallings. +to either MEMCACHED_HASH_DEFAULT, MEMCACHED_HASH_MD5, MEMCACHED_HASH_CRC, MEMCACHED_HASH_FNV1_64, MEMCACHED_HASH_FNV1A_64, MEMCACHED_HASH_FNV1_32, MEMCACHED_HASH_FNV1A_32, MEMCACHED_HASH_JENKINS, MEMCACHED_HASH_HSIEH, and MEMCACHED_HASH_MURMUR. +Each hash has it's advantages and it's weaknesses. If you dont know or dont care, just go with the default. =item MEMCACHED_BEHAVIOR_DISTRIBUTION diff --git a/libmemcached/Makefile.am b/libmemcached/Makefile.am index fbb7726a..595a3c89 100644 --- a/libmemcached/Makefile.am +++ b/libmemcached/Makefile.am @@ -69,6 +69,7 @@ libmemcached_la_SOURCES = crc.c \ memcached_verbosity.c \ memcached_version.c \ murmur_hash.c \ + jenkins_hash.c \ byteorder.c libmemcached_la_LIBADD = diff --git a/libmemcached/common.h b/libmemcached/common.h index ff60c232..24d4cce8 100644 --- a/libmemcached/common.h +++ b/libmemcached/common.h @@ -90,6 +90,7 @@ uint32_t hash_crc32(const char *data, size_t data_len); uint32_t hsieh_hash(const char *key, size_t key_length); uint32_t murmur_hash(const char *key, size_t key_length); +uint32_t jenkins_hash(const void *key, size_t length, uint32_t initval); memcached_return memcached_connect(memcached_server_st *ptr); memcached_return memcached_response(memcached_server_st *ptr, diff --git a/libmemcached/memcached_constants.h b/libmemcached/memcached_constants.h index ab640421..47774d37 100644 --- a/libmemcached/memcached_constants.h +++ b/libmemcached/memcached_constants.h @@ -115,7 +115,8 @@ typedef enum { MEMCACHED_HASH_FNV1_32, MEMCACHED_HASH_FNV1A_32, MEMCACHED_HASH_HSIEH, - MEMCACHED_HASH_MURMUR + MEMCACHED_HASH_MURMUR, + MEMCACHED_HASH_JENKINS } memcached_hash; typedef enum { diff --git a/libmemcached/memcached_hash.c b/libmemcached/memcached_hash.c index fb8bd63d..901f2c48 100644 --- a/libmemcached/memcached_hash.c +++ b/libmemcached/memcached_hash.c @@ -84,6 +84,11 @@ uint32_t generate_hash_value(const char *key, size_t key_length, memcached_hash hash= murmur_hash(key, key_length); break; } + case MEMCACHED_HASH_JENKINS: + { + hash=jenkins_hash(key, key_length, 13); + break; + } } return hash; } diff --git a/tests/function.c b/tests/function.c index 599a8868..4483232c 100644 --- a/tests/function.c +++ b/tests/function.c @@ -2526,6 +2526,14 @@ static memcached_return pre_murmur(memcached_st *memc) return MEMCACHED_SUCCESS; } +static memcached_return pre_jenkins(memcached_st *memc) +{ + memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_HASH, (uint64_t)MEMCACHED_HASH_JENKINS); + + return MEMCACHED_SUCCESS; +} + + static memcached_return pre_md5(memcached_st *memc) { memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_HASH, (uint64_t)MEMCACHED_HASH_MD5); @@ -2980,6 +2988,7 @@ collection_st collection[] ={ {"md5", pre_md5, 0, tests}, {"crc", pre_crc, 0, tests}, {"hsieh", pre_hsieh, 0, tests}, + {"jenkins", pre_jenkins, 0, tests}, {"fnv1_64", pre_hash_fnv1_64, 0, tests}, {"fnv1a_64", pre_hash_fnv1a_64, 0, tests}, {"fnv1_32", pre_hash_fnv1_32, 0, tests}, @@ -3003,6 +3012,7 @@ collection_st collection[] ={ {"generate_hsieh_consistent", enable_consistent, 0, generate_tests}, {"generate_md5", pre_md5, 0, generate_tests}, {"generate_murmur", pre_murmur, 0, generate_tests}, + {"generate_jenkins", pre_jenkins, 0, generate_tests}, {"generate_nonblock", pre_nonblock, 0, generate_tests}, {"consistent_not", 0, 0, consistent_tests}, {"consistent_ketama", pre_behavior_ketama, 0, consistent_tests}, -- 2.30.2