From: Robey Pointer Date: Fri, 23 Jan 2009 12:23:28 +0000 (+0100) Subject: Export generate_hash_value as memcache_generate_hash_value and fix key length check... X-Git-Tag: 0.26~2 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=0010c4a70fc2ffa4a191cf5270442a1fa009bb97;p=m6w6%2Flibmemcached Export generate_hash_value as memcache_generate_hash_value and fix key length check to use the constant. --- diff --git a/docs/Makefile.am b/docs/Makefile.am index 2c21bae0..03278abf 100644 --- a/docs/Makefile.am +++ b/docs/Makefile.am @@ -25,7 +25,8 @@ EXTRA_DIST = libmemcached.pod\ memcached_version.pod\ memflush.pod\ memcached_flush_buffers.pod\ - memcached_analyze.pod + memcached_analyze.pod\ + memcached_generate_hash_value.pod man_MANS = libmemcached.3\ libmemcached_examples.3\ @@ -84,7 +85,8 @@ man_MANS = libmemcached.3\ memcached_verbosity.3\ memcached_lib_version.3\ memcached_version.3\ - memcached_flush_buffers.3 + memcached_flush_buffers.3\ + memcached_generate_hash_value.3 libmemcached.3: libmemcached.pod @POD2MAN@ -c "libmemcached" -r "" -s 3 libmemcached.pod > libmemcached.3 @@ -272,6 +274,9 @@ memcached_flush_buffers.3: memcached_flush_buffers.pod memcached_analyze.3: memcached_analyze.pod @POD2MAN@ -c "libmemcached" -r "" -s 3 memcached_analyze.pod > memcached_analyze.3 +memcached_generate_hash_value.3: memcached_generate_hash_value.pod + @POD2MAN@ -c "libmemcached" -r "" -s 3 memcached_generate_hash_value.pod > memcached_generate_hash_value.3 + memcp.1: memcp.pod @POD2MAN@ -c "libmemcached" -r "" -s 1 memcp.pod > memcp.1 diff --git a/docs/memcached_generate_hash_value.pod b/docs/memcached_generate_hash_value.pod new file mode 100644 index 00000000..4136526b --- /dev/null +++ b/docs/memcached_generate_hash_value.pod @@ -0,0 +1,48 @@ +=head1 NAME + +memcached_generate_hash_value + +=head1 LIBRARY + +C Client Library for memcached (libmemcached, -lmemcached) + +=head1 SYNOPSIS + + #include + + uint32_t + memcached_generate_hash_value (const char *key, + size_t key_length, + memcached_hash hash_algorithm); + +=head1 DESCRIPTION + +memcached_generate_hash_value() allows you to hash a key using one of +the hash fuctions defined in the library. This method is provided for +the convenience of higher-level language bindings and is not necessary +for normal memcache operations. + +The allowed hash algorithm constants are listed in the manpage for +memcached_behavior_set(). + +=head1 RETURN + +A 32-bit integer which is the result of hashing the given key. +For 64-bit hash algorithms, only the least-significant 32 bits are +returned. + +=head1 HOME + +To find out more information please check: +L + +=head1 AUTHOR + +Brian Aker, Ebrian@tangent.orgE + +=head1 SEE ALSO + +memcached(1) libmemcached(3) memcached_behavior_set(3) + +=cut + diff --git a/libmemcached/common.h b/libmemcached/common.h index 40787d38..54b33a20 100644 --- a/libmemcached/common.h +++ b/libmemcached/common.h @@ -111,8 +111,6 @@ memcached_return memcachd_key_test(char **keys, size_t *key_length, memcached_return run_distribution(memcached_st *ptr); -uint32_t generate_hash_value(const char *key, size_t key_length, memcached_hash hash_algorithm); - uint32_t generate_hash(memcached_st *ptr, const char *key, size_t key_length); memcached_return memcached_server_remove(memcached_server_st *st_ptr); @@ -133,7 +131,7 @@ static inline memcached_return memcached_validate_key_length(size_t key_length, } else { - unlikely (key_length > 250) + unlikely (key_length >= MEMCACHED_MAX_KEY) return MEMCACHED_BAD_KEY_PROVIDED; } diff --git a/libmemcached/memcached.h b/libmemcached/memcached.h index 8db371a9..cc074d44 100644 --- a/libmemcached/memcached.h +++ b/libmemcached/memcached.h @@ -147,6 +147,7 @@ void memcached_quit(memcached_st *ptr); char *memcached_strerror(memcached_st *ptr, memcached_return rc); memcached_return memcached_behavior_set(memcached_st *ptr, memcached_behavior flag, uint64_t data); uint64_t memcached_behavior_get(memcached_st *ptr, memcached_behavior flag); +uint32_t memcached_generate_hash_value(const char *key, size_t key_length, memcached_hash hash_algorithm); memcached_return memcached_flush_buffers(memcached_st *mem); /* Server Public functions */ diff --git a/libmemcached/memcached_hash.c b/libmemcached/memcached_hash.c index 1f51ac25..c7bcb4be 100644 --- a/libmemcached/memcached_hash.c +++ b/libmemcached/memcached_hash.c @@ -11,7 +11,7 @@ static uint32_t FNV_32_PRIME= 16777619; static uint32_t internal_generate_hash(const char *key, size_t key_length); static uint32_t internal_generate_md5(const char *key, size_t key_length); -uint32_t generate_hash_value(const char *key, size_t key_length, memcached_hash hash_algorithm) +uint32_t memcached_generate_hash_value(const char *key, size_t key_length, memcached_hash hash_algorithm) { uint32_t hash= 1; /* Just here to remove compile warning */ uint32_t x= 0; @@ -103,7 +103,7 @@ uint32_t generate_hash(memcached_st *ptr, const char *key, size_t key_length) if (ptr->number_of_hosts == 1) return 0; - hash= generate_hash_value(key, key_length, ptr->hash); + hash= memcached_generate_hash_value(key, key_length, ptr->hash); WATCHPOINT_ASSERT(hash); return hash; } diff --git a/libmemcached/memcached_hosts.c b/libmemcached/memcached_hosts.c index abb1ce03..c0d0f036 100644 --- a/libmemcached/memcached_hosts.c +++ b/libmemcached/memcached_hosts.c @@ -197,7 +197,7 @@ memcached_return update_continuum(memcached_st *ptr) } else { - value= generate_hash_value(sort_host, sort_host_length, ptr->hash_continuum); + value= memcached_generate_hash_value(sort_host, sort_host_length, ptr->hash_continuum); ptr->continuum[continuum_index].index= host_index; ptr->continuum[continuum_index++].value= value; }