Getting appropriate hash index C++
<p>I've tried everything. Even java's forumla: </p>

<p>java.lang.String.hashCode():</p>

<pre><code>s[0]*(31^(n-1)) + s[1]*(31^(n-2)) + ... + s[n-1]
</code></pre>

<p>I've interpretted this as a sum:
Although I am not quite sure what to do with the s[n-1];</p>

<pre><code>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;
}
</code></pre>

<p>where maxSize is the 10th element in my fixed array size of 11.</p>

<p>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.. </p>
