int hazmat::hashStr(char const * const str)
{
int count = 0;
for ( unsigned i = 0; i < strlen( str ); i++ )
{
count += str[i]; // get the ascii sum.
}
return count % maxSize;
}
int hazmat::hashStr(char const * const str) { int count = 0; for ( unsigned
Share
You are misunderstanding how hash tables work. You need to allocate a fixed-length array (in the simplest case) and then each entry must have a linked list so you can resolve duplicates. That is, two strings may result in the same hash value and you will need to walk the linked list and compare the keys.
And yes, like the other poster said, adding characters is a terrible approach. Think about it – “abc” and “cba” will result in the same hash value.