From 013715211f094bb98ab7ed830b6cd24328641eba Mon Sep 17 00:00:00 2001 From: Date: Wed, 5 Mar 2008 15:44:42 -0500 Subject: [PATCH] Patch for "murmur" hash algorithm. --- ChangeLog | 1 + include/memcached.h | 1 + lib/Makefile.am | 3 ++- lib/common.h | 13 +++++++------ lib/memcached_hash.c | 5 +++++ tests/function.c | 9 +++++++++ 6 files changed, 25 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index 1d199b27..a4579804 100644 --- a/ChangeLog +++ b/ChangeLog @@ -2,6 +2,7 @@ * MEMCACHED_BEHAVIOR_CONNECT_TIMEOUT added for connect timeout in non-block mode. * Fix plus tests for non-zero value objects and flags. + * MEMCACHED_HASH_MURMUR added for murmur algorithm provided. 0.16 Mon Feb 18 00:30:25 PST 2008 * Work on the UDP protocol diff --git a/include/memcached.h b/include/memcached.h index 419f1949..7fd94e7d 100644 --- a/include/memcached.h +++ b/include/memcached.h @@ -126,6 +126,7 @@ typedef enum { MEMCACHED_HASH_FNV1A_32, MEMCACHED_HASH_KETAMA, MEMCACHED_HASH_HSIEH, + MEMCACHED_HASH_MURMUR, } memcached_hash; typedef enum { diff --git a/lib/Makefile.am b/lib/Makefile.am index 5257b7ba..7e99091a 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -54,7 +54,8 @@ libmemcached_la_SOURCES = crc.c \ memcached_stats.c \ memcached_strerror.c \ memcached_verbosity.c \ - memcached_version.c + memcached_version.c \ + murmur_hash.c libmemcached_la_LIBADD = libmemcached_la_LDFLAGS = -version-info $(MEMCACHED_LIBRARY_VERSION) diff --git a/lib/common.h b/lib/common.h index b09d5433..c126b5d1 100644 --- a/lib/common.h +++ b/lib/common.h @@ -73,9 +73,10 @@ void md5_signature(unsigned char *key, unsigned int length, unsigned char *resul uint32_t hash_crc32(const char *data, size_t data_len); uint32_t hsieh_hash(char *key, size_t key_length); +uint32_t murmur_hash(char *key, size_t key_length); memcached_return memcached_connect(memcached_server_st *ptr); -memcached_return memcached_response(memcached_server_st *ptr, +memcached_return memcached_response(memcached_server_st *ptr, char *buffer, size_t buffer_length, memcached_result_st *result); unsigned int memcached_generate_hash(memcached_st *ptr, char *key, size_t key_length); @@ -91,19 +92,19 @@ void memcached_quit_server(memcached_server_st *ptr, uint8_t io_death); #define memcached_string_size(A) (A)->current_size #define memcached_string_value(A) (A)->string -memcached_string_st *memcached_string_create(memcached_st *ptr, - memcached_string_st *string, +memcached_string_st *memcached_string_create(memcached_st *ptr, + memcached_string_st *string, size_t initial_size); memcached_return memcached_string_check(memcached_string_st *string, size_t need); char *memcached_string_c_copy(memcached_string_st *string); -memcached_return memcached_string_append_character(memcached_string_st *string, +memcached_return memcached_string_append_character(memcached_string_st *string, char character); memcached_return memcached_string_append(memcached_string_st *string, char *value, size_t length); size_t memcached_string_backspace(memcached_string_st *string, size_t remove); memcached_return memcached_string_reset(memcached_string_st *string); void memcached_string_free(memcached_string_st *string); -memcached_return memcached_do(memcached_server_st *ptr, char *commmand, +memcached_return memcached_do(memcached_server_st *ptr, char *commmand, size_t command_length, uint8_t with_flush); memcached_return memcached_version(memcached_st *ptr); memcached_return value_fetch(memcached_server_st *ptr, @@ -111,7 +112,7 @@ memcached_return value_fetch(memcached_server_st *ptr, memcached_result_st *result); void server_list_free(memcached_st *ptr, memcached_server_st *servers); -memcached_return memcachd_key_test(char **keys, size_t *key_length, +memcached_return memcachd_key_test(char **keys, size_t *key_length, unsigned int number_of_keys); #endif /* __COMMON_H__ */ diff --git a/lib/memcached_hash.c b/lib/memcached_hash.c index 0b46a865..f365cc0e 100644 --- a/lib/memcached_hash.c +++ b/lib/memcached_hash.c @@ -90,6 +90,11 @@ unsigned int memcached_generate_hash(memcached_st *ptr, char *key, size_t key_le hash= hsieh_hash(key, key_length); break; } + case MEMCACHED_HASH_MURMUR: + { + hash= murmur_hash(key, key_length); + break; + } } WATCHPOINT_ASSERT(hash); diff --git a/tests/function.c b/tests/function.c index dd3af2ac..8d84c16f 100644 --- a/tests/function.c +++ b/tests/function.c @@ -2216,6 +2216,14 @@ memcached_return pre_nonblock(memcached_st *memc) return MEMCACHED_SUCCESS; } +memcached_return pre_murmur(memcached_st *memc) +{ + memcached_hash value= MEMCACHED_HASH_MURMUR; + memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_HASH, &value); + + return MEMCACHED_SUCCESS; +} + memcached_return pre_md5(memcached_st *memc) { memcached_hash value= MEMCACHED_HASH_MD5; @@ -2572,6 +2580,7 @@ collection_st collection[] ={ {"generate_hsieh", pre_hsieh, 0, generate_tests}, {"generate_hsieh_consistent", enable_consistent, 0, generate_tests}, {"generate_md5", pre_md5, 0, generate_tests}, + {"generate_murmur", pre_murmur, 0, generate_tests}, {"generate_nonblock", pre_nonblock, 0, generate_tests}, {0, 0, 0, 0} }; -- 2.30.2