title: Hash function for strings in C
body: <p>I am currently trying to implement a hash function for my program in C. I have found many possible solutions but I do not understand them. The following is the hash function:</p>
  
  <pre><code>int hash(const char *word) {
      int hash = 0;
      int n;
      for (int i = 0; word[i] != '\0'; i++) {
          // alphabet case
          if (isalpha(word[i]))
              n = word[i] - 'a' + 1;
          else  // comma case
              n = 27;
  
          hash = ((hash &lt;&lt; 3) + n) % SIZE;
      }
      return hash;
  }
  </code></pre>
  
  <p>Why are we subtracting <code>'a'+1</code> from <code>word[i]</code>? Also, why are we doing the following: <code>hash = ((hash &lt;&lt; 3) + n) % SIZE</code>?</p>