// CS 223A // 11-29-06 // Demonstrating a hash function for String keys. package cs223bw; public class StringHash { public static int hashVal(String s, int tableSize) // pre: s is not null, tableSize is positive // post: returns hash value, f(s), for given table size // 0 <= f(s) < tableSize { int n = s.hashCode()%tableSize; // be careful to return a positive number... if(n<0) n = n+tableSize; return n; } public static void main(String[] args) { int N = 7; String[] a = new String[N]; a[0] = "ape"; a[1] = "bunny"; a[2] = "cereal"; a[3] = "Dumbo"; a[4] = "elephant"; a[5] = "frantic"; a[6] = "giraffe"; for(int i=0; i