<commit_before>#include "common.h"

/* Protoypes (static) */
static memcached_return server_add(memcached_st *ptr, char *hostname, 
                                   unsigned int port,
                                   memcached_connection type);

#define MEMCACHED_WHEEL_SIZE 1024
#define MEMCACHED_STRIDE 4
static void rebalance_wheel(memcached_st *ptr)
{
  unsigned int x;
  unsigned int y;
  unsigned int latch;

  /* Seed the Wheel */
  memset(ptr->wheel, 0, sizeof(unsigned int) * MEMCACHED_WHEEL_SIZE);

  for (latch= y= x= 0; x < MEMCACHED_WHEEL_SIZE; x++, latch++)
  {
    if (latch == MEMCACHED_STRIDE)
    {
      y++;
      if (y == ptr->number_of_hosts)
        y= 0;
      latch= 0;
    }

    ptr->wheel[x]= y;
  }
}

static int compare_servers(const void *p1, const void *p2)
{
  int return_value;
  memcached_server_st *a= (memcached_server_st *)p1;
  memcached_server_st *b= (memcached_server_st *)p2;

  return_value= strcmp(a->hostname, b->hostname);

  if (return_value == 0)
  {
    if (a->port > b->port)
      return_value++;
    else
      return_value--;
  }

  return return_value;
}

void sort_hosts(memcached_st *ptr)
{
  qsort(ptr->hosts, ptr->number_of_hosts, sizeof(memcached_server_st), compare_servers);
}

static void host_reset(memcached_st *ptr, memcached_server_st *host, 
                       char *hostname, unsigned int port,
                       memcached_connection type)<commit_msg>Fix for memcached_server_st after sort<commit_after>#include "common.h"

/* Protoypes (static) */
static memcached_return server_add(memcached_st *ptr, char *hostname, 
                                   unsigned int port,
                                   memcached_connection type);

#define MEMCACHED_WHEEL_SIZE 1024
#define MEMCACHED_STRIDE 4
static void rebalance_wheel(memcached_st *ptr)
{
  unsigned int x;
  unsigned int y;
  unsigned int latch;

  /* Seed the Wheel */
  memset(ptr->wheel, 0, sizeof(unsigned int) * MEMCACHED_WHEEL_SIZE);

  for (latch= y= x= 0; x < MEMCACHED_WHEEL_SIZE; x++, latch++)
  {
    if (latch == MEMCACHED_STRIDE)
    {
      y++;
      if (y == ptr->number_of_hosts)
        y= 0;
      latch= 0;
    }

    ptr->wheel[x]= y;
  }
}

static int compare_servers(const void *p1, const void *p2)
{
  int return_value;
  memcached_server_st *a= (memcached_server_st *)p1;
  memcached_server_st *b= (memcached_server_st *)p2;

  return_value= strcmp(a->hostname, b->hostname);

  if (return_value == 0)
  {
    if (a->port > b->port)
      return_value++;
    else
      return_value--;
  }

  return return_value;
}

void sort_hosts(memcached_st *ptr)
{
  qsort(ptr->hosts, ptr->number_of_hosts, sizeof(memcached_server_st), compare_servers);
  ptr->hosts[0].count= ptr->number_of_hosts;
}

static void host_reset(memcached_st *ptr, memcached_server_st *host, 
                       char *hostname, unsigned int port,
                       memcached_connection type)
{'fraction_non_alphanumeric': 0.11213360599863667, 'fraction_numerical': 0.009884117246080437, 'mean_word_length': 2.8216145833333335, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2465142', 'n_tokens_mistral': 1072, 'n_tokens_neox': 1020, 'n_words': 237}