uthashC語言哈希表
uthash 是一個C語言的哈希表,支持各種結(jié)構(gòu)類型的存儲、添加、刪除,這些操作都在固定的時間完成,跟哈希表本身的大小無關(guān)。鍵也可以是任何類型的數(shù)據(jù)。
示例代碼:
#include "uthash.h"
struct my_struct {
int id; /* we'll use this field as the key */
char name[10];
UT_hash_handle hh; /* makes this structure hashable */
};
struct my_struct *users = NULL;
void add_user(struct my_struct *s) {
HASH_ADD_INT( users, id, s );
}評論
圖片
表情
