C:实现一个哈希表 [英] C: Implement a hash table
问题描述
我想在C创建一个高效的查找表。
I'm trying to create an efficient look-up table in C.
我有一个整数作为一个键和一个可变长度的char *作为值。
I have an integer as a key and a variable length char* as the value.
我看着uthash,但是这需要一个固定长度的char *值。如果我有这样的一个巨大的数字,然后我用了太多的内存。
I've looked at uthash, but this requires a fixed length char* value. If I make this a big number, then I'm using too much memory.
struct my_struct {
int key;
char value[10];
UT_hash_handle hh;
};
有没有人有任何指针?任何了解大大AP preciated。
Has anyone got any pointers? Any insight greatly appreciated.
在事先非常感谢,
感谢大家的答案。我已经与uthash和定义自己的自定义结构,以适应我的数据。
Thanks everyone for the answers. I've gone with uthash and defined my own custom struct to accommodate my data.
推荐答案
声明值
字段无效*值
。
这样你就可以有任何类型的数据的价值,但对于分配和释放它的责任将被委托给客户端code。
This way you can have any type of data as the value, but the responsibility for allocating and freeing it will be delegated to the client code.
这篇关于C:实现一个哈希表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!