Assignment #6: Hash Tables

Covers

Hash tables, Java programming

Basic problem

The Standard libray class TreeSet assumes that the objects are either comparable, or that there is a comparator function object that can be used to order the objects. As such, one can create a TreeSet of String objects in which "hello" and "HeLlO" are considered the same in the TreeSet. Unfortunately, there is no way to achieve this behavior in HashSet. This assignment asks you to start with the basic implementation of www.util.HashSet, as shown in the online code for the text and then add a mechanism that allows the user to construct a weiss.util.HashSet with an equals and hashCode that will be used instead of the normal defaults.

Specification of Alternate equals and hashCode

Move the weiss.util hash classes into a package call cop3530. Provide a public interface in package cop3530 as follows:

package cop3530;

public interface HashingFunction<T>
{
    int hashCode( T obj );
    boolean equals( T lhs, T rhs );
}
Add to the HashSet class a constructor that takes a HashingFunction object, add a data field, and modify the implementation of HashSet appropriately so that it consults the HashingFunction if one is provided, or uses the standard equals and hashCode if the HashSet is constructed without a HashingFunction.

What To Submit

Submit complete source code and provide a test program that shows that your code works for both String with the default equals and hashCode and also String with an equals and hashCode that is case-insensitve.