+ case MEMCACHED_DISTRIBUTION_RANDOM:
+ return random() % ptr->number_of_hosts;
+ default:
+ WATCHPOINT_ASSERT(0); /* We have added a distribution without extending the logic */
+ return hash % ptr->number_of_hosts;
+ }
+
+ WATCHPOINT_ASSERT(0); /* We should never reach here */
+ return 0;
+}
+
+/*
+ One day make this public, and have it return the actual memcached_server_st
+ to the calling application.
+*/
+uint32_t memcached_generate_hash(memcached_st *ptr, const char *key, size_t key_length)
+{
+ uint32_t hash= 1; /* Just here to remove compile warning */
+
+ WATCHPOINT_ASSERT(ptr->number_of_hosts);
+
+ if (ptr->number_of_hosts == 1)
+ return 0;
+
+ if (ptr->flags & MEM_HASH_WITH_PREFIX_KEY)
+ {
+ int temp_len= ptr->prefix_key_length + key_length;
+ char *temp= (char *)malloc(temp_len);
+ strncpy(temp, ptr->prefix_key, ptr->prefix_key_length);
+ strncpy(temp + ptr->prefix_key_length, key, key_length);
+ hash= generate_hash(ptr, temp, temp_len);
+ free(temp);