Eamorr Eamorr - 4 months ago 29
C Question

Implement a hash table

I'm trying to create an efficient look-up table in C.

I have an integer as a key and a variable length

as the value.

I've looked at
, but this requires a fixed length
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;

Has anyone got any pointers? Any insight greatly appreciated.

Thanks everyone for the answers. I've gone with
and defined my own custom struct to accommodate my data.


Declare the value field as void *value.

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.