Organize ketama a bit more (ie lets keep it in its own little basket).
[awesomized/libmemcached] / libmemcached / hash.c
index a9c1f8ed6026a6ba458bdcc1434e454c01762af2..99a007091797f16a01da33360301fcb4202d14eb 100644 (file)
@@ -30,13 +30,13 @@ static uint32_t dispatch_host(const memcached_st *ptr, uint32_t hash)
   case MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA:
   case MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA_SPY:
     {
-      uint32_t num= ptr->continuum_points_counter;
+      uint32_t num= ptr->ketama.continuum_points_counter;
       WATCHPOINT_ASSERT(ptr->continuum);
 
       hash= hash;
       memcached_continuum_item_st *begin, *end, *left, *right, *middle;
-      begin= left= ptr->continuum;
-      end= right= ptr->continuum + num;
+      begin= left= ptr->ketama.continuum;
+      end= right= ptr->ketama.continuum + num;
 
       while (left < right)
       {
@@ -70,7 +70,7 @@ static inline uint32_t _generate_hash_wrapper(const memcached_st *ptr, const cha
   WATCHPOINT_ASSERT(memcached_server_count(ptr));
 
   if (memcached_server_count(ptr) == 1)
-    return EXIT_SUCCESS;
+    return 0;
 
   if (ptr->flags.hash_with_prefix_key)
   {
@@ -78,7 +78,7 @@ static inline uint32_t _generate_hash_wrapper(const memcached_st *ptr, const cha
     char temp[temp_length];
 
     if (temp_length > MEMCACHED_MAX_KEY -1)
-      return EXIT_SUCCESS;
+      return 0;
 
     strncpy(temp, memcached_array_string(ptr->prefix_key), memcached_array_size(ptr->prefix_key));
     strncpy(temp + memcached_array_size(ptr->prefix_key), key, key_length);
@@ -93,12 +93,12 @@ static inline uint32_t _generate_hash_wrapper(const memcached_st *ptr, const cha
 
 static inline void _regen_for_auto_eject(memcached_st *ptr)
 {
-  if (_is_auto_eject_host(ptr) && ptr->next_distribution_rebuild)
+  if (_is_auto_eject_host(ptr) && ptr->ketama.next_distribution_rebuild)
   {
     struct timeval now;
 
     if (gettimeofday(&now, NULL) == 0 &&
-        now.tv_sec > ptr->next_distribution_rebuild)
+        now.tv_sec > ptr->ketama.next_distribution_rebuild)
     {
       run_distribution(ptr);
     }
@@ -136,3 +136,23 @@ memcached_return_t memcached_set_hashkit(memcached_st *self, hashkit_st *hashk)
 
   return MEMCACHED_SUCCESS;
 }
+
+const char * libmemcached_string_hash(memcached_hash_t type)
+{
+  switch (type)
+  {
+  case MEMCACHED_HASH_DEFAULT: return "MEMCACHED_HASH_DEFAULT";
+  case MEMCACHED_HASH_MD5: return "MEMCACHED_HASH_MD5";
+  case MEMCACHED_HASH_CRC: return "MEMCACHED_HASH_CRC";
+  case MEMCACHED_HASH_FNV1_64: return "MEMCACHED_HASH_FNV1_64";
+  case MEMCACHED_HASH_FNV1A_64: return "MEMCACHED_HASH_FNV1A_64";
+  case MEMCACHED_HASH_FNV1_32: return "MEMCACHED_HASH_FNV1_32";
+  case MEMCACHED_HASH_FNV1A_32: return "MEMCACHED_HASH_FNV1A_32";
+  case MEMCACHED_HASH_HSIEH: return "MEMCACHED_HASH_HSIEH";
+  case MEMCACHED_HASH_MURMUR: return "MEMCACHED_HASH_MURMUR";
+  case MEMCACHED_HASH_JENKINS: return "MEMCACHED_HASH_JENKINS";
+  case MEMCACHED_HASH_CUSTOM: return "MEMCACHED_HASH_CUSTOM";
+  default:
+  case MEMCACHED_HASH_MAX: return "INVALID memcached_hash_t";
+  }
+}