I've tried everything. Even java's forumla:
java.lang.String.hashCode():
s[0]*(31^(n-1)) + s[1]*(31^(n-2)) + ... + s[n-1]
I've interpretted this as a sum: Although I am not quite sure what to do with the s[n-1];
int hashmap::hashstr( const char*const str )
{
int result = 0;
int i = 0;
int j = 0;
int k = 0;
unsigned n = 0;
for ( ; str[n] != NULL; ++n ); // how many characters?
while ( j != n ) // no more characters
{
result += str[i] * ( 31 ^ ( n - k ) );
j++;
i++;
k++;
}
return result % maxSize;
}
where maxSize is the 10th element in my fixed array size of 11.
What am i doing wrong? SOME of my hash indicies are coming out wrong. Others, correctly. Why is this? So far everyones been like, "Who cares how it works!! Use a template!" Well, I want to understand this..