// computes the hash function of a given string. Assumes // that the string consists of lower case letters, upper case letters, and // digits. Views the string as a base-32 number and returns equivalent // decimal value modulo 32. Uses bit shifting for multiplying // by 32 and Horner's rule for reducing number of multiplications private int hash(String word) { int hashValue = 0; for(int i = 0; i < word.length(); i++) // Solution for Quiz 7a: // Also note that we are now bit-shifting by 2 to the 6th or 64. { if((word.charAt(i) >= '0') && (word.charAt(i) <= '9')) hashValue = ((hashValue << 6) + (word.charAt(i) - '0') + 1) % M; // Note: this will map the values from 1 - 10 else if((word.charAt(i) >= 'A') && (word.charAt(i) <= 'Z')) hashValue = ((hashValue << 6) + (word.charAt(i) - 'A') + 11) % M; // Note: this will map the values from 11 - 36 else if((word.charAt(i) >= 'a') && (word.charAt(i) <= 'z')) hashValue = ((hashValue << 6) + (word.charAt(i) - 'a') + 37) % M; // Note: this will map the values from 37 - 62 } return hashValue; }