Hey guys I been reading about pointers, structs and data structures in C over the last couple of days. Now I am trying to implement a Hash Table in C by following along this tutorial: https://www.tutorialspoint.com/data_structures_algorithms/hash_table_program_in_c.htm
However tutorialspoint is assuming there will only be 1 hash table and it is making it global. Furthermore, tutorialspoint does not take into account collisions.
I want to make a struct to not limit myself to a single hash table and I plan to incorporate chaining (to deal with collisions) with a linked list. I have the following:
typedef struct node {
int key;
int data;
struct node* next;
} node;
typedef struct linkedList{
node* head;
node* tail;
size_t size;
} linkedList;
typedef struct hashTable{
//perhaps an array of linked list? This member is what I need help with
//And other potential members I am overlooking
size_t size
} hashTable;
Some things that I need to explain:
The node struct serves as a pair of key/data and it has a pointer to the next pair that has the same hash code. All nodes with the same hash code will be in the same linked list.
The linkedList struct is represents a linked list that will eventually become a row in the hash table. All linked lists will be a row in the hash table.
The hashTable struct contains all the linkedLists.
How can I make an array of the linkedList struct in my hashTable struct? Is there other members I am overlooking in my 3 structs?
Any help is appreciated!
P.S. I plan to use the methods I wrote in my Linked List program. Here is a link to an early version of it: https://codereview.stackexchange.com/questions/176904/my-linked-list-implementation-in-c
size,data, and key into one struct is something you could consider, unless they are not related. (It appears they are from the code you have shown). And typically a key is used to capture something from an encrypted object. Something that is hashed cannot be recovered, so why do you need a key? - ryyker