更新数据结构与哈希函数

master
brisk 2014-03-25 23:01:03 +08:00
parent 33fcc94004
commit 23715c44bf
2 changed files with 69 additions and 21 deletions

View File

@ -5,10 +5,50 @@ int hash_func1(const char *key);
int hash_func2(const char *key);
int conf_value_insert(CONF_ARG *arg)
{
}
CONF_VALUE *conf_value_get(CONF *conf,const char *key)
{}
CONF_ARG *conf_value_get(CONF *conf,const char *key)
CONF_VALUE **conf_value_get_all(CONF *conf)
{}
CONF_ARG *conf_value_get_all(CONF *conf)
{}
/*BKDR 哈希算法*/
int hash_func1(const char *key)
{
unsigned int seed=131;
unsigned int hash=0;
while(*key)
{
hash=hash*seed+*key;
++key;
}
return hash&0x7FFFFFFF;
}
/*AP 哈希算法*/
int hash_func2(const char *key)
{
unsigned int hash=0;
int i;
for(i=0;key[i];++i)
{
if((i & 1) == 0)
{
hash^=((hash << 7)^*key^(hash >> 3));
++key;
}
else
{
hash^=(~((hash << 11)^*key^(hash >> 5)));
++key;
}
}
return hash&0x7FFFFFFF;
}

View File

@ -6,39 +6,47 @@
#include <stdlib.h>
#include <string.h>
/*值链表数据结构*/
typedef struct node
{
char *key
char *value;
struct node *next;
}CONF_VALUE;
/* 键/值对数据结构
* hash使hash0 1
* len
* next
*/
typedef struct arg
{
int hash;
int len;
CONF_VALUE *value;
struct arg *next;
}CONF_ARG;
/* conf-c的数据结构
* fpFILE
* len/
* conf/hash
* hash_data/
*/
typedef struct
{
FILE *fp;
int len;
conf_hash *conf;
CONF_ARG *hash_data;
}CONF;
/*值链表数据结构*/
typedef struct node
{
char *value;
struct node *next;
}CONF_VALUE;
//键/值对数据结构
typedef struct
{
char *key;
CONF_VALUE *value;
}CONF_ARG;
//插入数据,key为键value为值
int conf_value_insert(CONF_ARG *arg);
//根据一个键查找数据
CONF_ARG conf_value_get(CONF *conf,const char *key);
CONF_VALUE *conf_value_get(CONF *conf,const char *key);
//得到所有键值对
CONF_ARG conf_value_get_all(CONF *conf);
CONF_VALUE **conf_value_get_all(CONF *conf);
#endif