// Written by: Darren Gates & Ray Klefstad // Date: January 2000 // School: U.C. Irvine // #1: Sum of ASCII values int result = 0; for (int i = 0; i < value.length(); i++) { result += value.charAt(i); } return result % buf.length; // #2: Product of ASCII values int result = 1; for (int i = 0; i < value.length(); i++) { result *= value.charAt(i); } return result % buf.length; // #3: Built-in Java hashCode() function return Math.abs(value.hashCode()) % buf.length; // #4: Bit-shifter hash function from 'Data Structures and Algorithms', p. 208, by Bruno R. Preiss int r = 0; static final int shift = 6; static final int mask = ~0 << (32-shift); for (int i = 0; i< value.length(); i++) r = (r & mask) ^ (r << shift) ^ value.charAt(i); return Math.abs(r) % buf.length;