简体   繁体   中英

What can be stored in the bucket of hash table in C

I'm new with hashing so I wondered if I have structure like below and I'm using hash function to may key to value, how can I store the third element number into the hash table?

I found a lot of implementations on github with key/value but I'm confused how to store another value it may not be hashed with key, a just need to store it.

struct my_struct
{

int key;

char value[512];

int number;

};

A typical hash-table implementation have a "table" (array) of the structures that are to be stored in the hash-table. Something like this

struct my_struct hash_table[SOME_SIZE];

Then you calculate the key and store it at position key % SOME_SIZE in the array. The extra data in the structures are filled in as usual.

To avoid collisions, each entry in the table is actually a linked list, so multiple keys that are stored in the same position in the table is a node in the list.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM