I have the following construction:
typedef struct bucket { char *key; ENTRY *data; struct bucket *next; } bucket; typedef struct { size_t size; bucket **table; } hash_table;
But I have no idea how to allocate memory for that. I tried:
hash_table* ht = malloc(sizeof(hash_table)*101);
in order to create a hashtable for 101 entries but it din’t work! Can anyone help me? I would really appreciate it!
Not quite. Assuming this is C, you probably want to make a function:
You might need some other fields in that struct.
If you wanted to be tricky, and never realloc the bucket, you can do this:
EDIT: I fixed my bucket* table’s to bucket**
EDIT2: I’ve gotten rid of the memsets and added error checking for malloc.