As shown in Figure , we define an AbstractHashTable class from which several concrete realizations are derived.
Figure: Object class hierarchy.
Program introduces the AbstracHashTable class. The AbstractHashTable class extends the AbstractSearchableContainer class introduced in Program and it implements the HashTable interface defined in Program .
Program: AbstractHashTable methods.
Program introduces four methods--getLength, f, g, and h. The getLength method is an abstract method. This function returns the length of a hash table.
The methods f, g, and h correspond to the composition discussed in Section . The f method takes as an object and calls the hashCode method on that object to compute an integer. The g method uses the division method of hashing defined in Section to map an integer into the interval [0,M-1], where M is the length of the hash table. Finally, the h method computes the composition of f and g.
In the following we will consider various ways of implementing hash tables. In all cases, the underlying implementation makes use of an array. The position of an object in the array is determined by hashing the object. The main problem to be resolved is how to deal with collisions--two different objects cannot occupy the same array position at the same time. In the following section, we consider an approach which solves the problem of collisions by keeping objects that collide in a linked list.