试试这个:http ://utash.sourceforge.net/
首页上的示例几乎是不言自明的。
struct Stock {
float price, change;
char name[3];
UT_hash_handle hh;
};
struct Stock * stocksHash = NULL;
struct Stock * stockItem;
HASH_ADD_STR(stocksHash, name, stockItem );
HASH_FIND_STR(stocksHash, "IBM", stockItem );
//edit
void new_stock(struct Stock * stocksHash, char *name, float price, float change) {
struct Stock *s;
s = malloc(sizeof(struct Stock));
strncpy (s->name, name, 3);
s->price = price; s->change = change;
s->id = user_id;
HASH_ADD_STR( stocksHash, name, s );
}
void update_stock (struct Stock * stocksHash, char *name,
float price, float change) {
struct Stock *s;
HASH_FIND_STR (stocksHash, name, s);
if (s) {
s->price = price; s->change = change;
}
}