The logic of hash will be as follows
A hash table is made up of two parts: An array (it will be like a table which contains the data to be searched) and a mapping function, this is known as a hash function.
The hash function provides a way for assigning numbers to the input data such that the data can then be stored at the array index corresponding to the assigned number.
The hash function can be like this
Code:
int hash(char *str, int table_size)
{
int sum;
/* Make sure a valid string passed in */
if (str==NULL) return -1;
/* Sum up all the characters in the string */
for( ; *str; str++) sum += *str;
/* Return the sum mod the table size */
return sum % table_size;
}