user1656238
user1656238

Reputation: 123

Chained hash-table declaration

In Master Algorithm with C, the author has declared the structure of a chained hash table like below:

typedef struct CHTbl_ {

int                buckets;

int                (*h)(const void *key);
int                (*match)(const void *key1, const void *key2);
void               (*destroy)(void *data);

int                size;
List               *table;

} CHTbl;

But I thought the last one should be List *table[buckets]; as the author has used something like &htbl->table[bucket]. Am I right? Why the author's definition could correctly pass the test?why is it right? Thank you!

Upvotes: 1

Views: 212

Answers (1)

jxh
jxh

Reputation: 70402

The table is a List pointer, and is being used to represent an array of Lists. It is probably being initialized like this:

htbl->table = malloc(sizeof(List) * htbl->buckets);

Upvotes: 1

Related Questions