Updating tree for new function work in libhashkit.
[m6w6/libmemcached] / libmemcached / behavior.c
index d2f031a1586c5729c8e2b523eb415effc1082950..ba4db7377d8899d87d053748ad71082969c43952 100644 (file)
@@ -21,23 +21,6 @@ static bool set_flag(uint64_t data)
   return data ? true : false;
 }
 
-static memcached_return_t set_hash(memcached_hash_t *store, memcached_hash_t type)
-{
-#ifndef HAVE_HSIEH_HASH
-  if (type == MEMCACHED_HASH_HSIEH)
-    return MEMCACHED_FAILURE;
-#endif
-  if (type < MEMCACHED_HASH_MAX)
-  {
-    *store= type;
-  }
-  else
-  {
-    return MEMCACHED_FAILURE;
-  }
-
-  return MEMCACHED_SUCCESS;
-}
 /*
   This function is used to modify the behavior of running client.
 
@@ -283,9 +266,9 @@ uint64_t memcached_behavior_get(memcached_st *ptr,
   case MEMCACHED_BEHAVIOR_KETAMA:
     return (ptr->distribution == MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA) ? (uint64_t) 1 : 0;
   case MEMCACHED_BEHAVIOR_HASH:
-    return ptr->hash;
+    return hashkit_get_function(&ptr->hashkit);
   case MEMCACHED_BEHAVIOR_KETAMA_HASH:
-    return ptr->distribution_hash;
+    return hashkit_get_function(&ptr->distribution_hashkit);
   case MEMCACHED_BEHAVIOR_SERVER_FAILURE_LIMIT:
     return ptr->server_failure_limit;
   case MEMCACHED_BEHAVIOR_SORT_HOSTS:
@@ -398,20 +381,26 @@ memcached_server_distribution_t memcached_behavior_get_distribution(memcached_st
 
 memcached_return_t memcached_behavior_set_key_hash(memcached_st *ptr, memcached_hash_t type)
 {
-  return set_hash(&ptr->hash, type);
+  hashkit_return_t rc;
+  rc= hashkit_set_function(&ptr->hashkit, (hashkit_hash_algorithm_t)type);
+
+  return rc == HASHKIT_SUCCESS ? MEMCACHED_SUCCESS : MEMCACHED_FAILURE;
 }
 
 memcached_hash_t memcached_behavior_get_key_hash(memcached_st *ptr)
 {
-  return ptr->hash;
+  return (memcached_hash_t)hashkit_get_function(&ptr->hashkit);
 }
 
 memcached_return_t memcached_behavior_set_distribution_hash(memcached_st *ptr, memcached_hash_t type)
 {
-  return set_hash(&ptr->distribution_hash, type);
+  hashkit_return_t rc;
+  rc= hashkit_set_function(&ptr->distribution_hashkit, (hashkit_hash_algorithm_t)type);
+
+  return rc == HASHKIT_SUCCESS ? MEMCACHED_SUCCESS : MEMCACHED_FAILURE;
 }
 
 memcached_hash_t memcached_behavior_get_distribution_hash(memcached_st *ptr)
 {
-  return ptr->distribution_hash;
+  return (memcached_hash_t)hashkit_get_function(&ptr->distribution_hashkit);
 }