/*
* Using a known ketama.servers file, and a fixed set of keys
* print and hash the output of this program using your modified
* libketama, compare the hash of the output to the known correct
* hash in the test harness.
*/
#include <ketama.h>
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char **argv)
{
if(argc==1){
printf("Usage: %s <ketama.servers file>\n", *argv);//相當於*argv[]
return 1;//返回異常
}
ketama_continuum c; //聲明一個全類型的變量
ketama_roll( &c, *++argv ); //將服務器分散到圈中的個個地點
printf( "%s\n", ketama_error() );
int i;
for ( i = 0; i < 10; i++ )
{
char k[10];
sprintf( k, "%d", i ); //格式化字符串後賦值
unsigned int kh = ketama_hashi( k ); //進行散列處理,獲得散列值
mcs* m = ketama_get_server( k, c ); //將散列值放入圈中,並返回mcs結構體指針
printf( "%u %u %s\n", kh, m->point, m->ip );
}
ketama_smoke(c);
return 0;