kemata处理
/*
* 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;
补充:软件开发 , C语言 ,