I am trying to make a hashstring function that:
sum the ordinal values of the characters of the variable multiplied by their position in the string (1-indexing), then taking the modulo by TABLESIZE.
unsignedint hashString( const string& s)
{
int sum = 0;
for (int k = 0; k < s.length(); k++)
sum = sum + int(s[k]);
return sum % 100;
}
int main()
{
cout<<"Start"<<endl;
cout<<" BORAMIR = "<<hashString("Boramir")<<endl;
cout<<" LEGOLAS = "<<hashString("LEGOLAS")<<endl;
cout<<" GANDALF = "<<hashString("GANDALF")<<endl;
cout<<" BORAMIR * 2 = "<<hashString("BORAMIR * 2")<<endl;
I am assuming I am using the wrong table size? I am not sure how to determine the table size for this problem? Any suggestions would be greatly appreciate!