Improve my Hashing Function C++ I have the following hashing function : int hash
ID: 660969 • Letter: I
Question
Improve my Hashing Function C++
I have the following hashing function :
int hash(string str)
{
int sum = 0;
for(int i = 0; i < str.length(); i++)
sum += (str[i] - '0');
sum += str.length();
return (sum * 31) % SIZE;
}
The function recieved an string input then calculates the total ascii value + length of string then * 31 % tablesize
This function should return the same hash value if entered book or koob .
Currently, I recieve plenty of collisions in a table size less than 400
I wan to know if you can improve it to have less collisions .
Please help
Thank you