C语言哈希表 uthash

来源:互联网 发布:语音输入翻译软件 编辑:程序博客网 时间:2024/06/06 01:53
uthash 是一个C语言的哈希表,支持各种结构类型的存储、添加、删除,这些操作都在固定的时间完成,跟哈希表本身的大小无关。键也可以是任何类型的数据。


示例代码:
https://github.com/troydhanson/uthash?
 
#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 );    
}
0 0
原创粉丝点击