CPSC170A
Fundamentals of Computer Science II

Lab 31

Polymorphism

Hashable

Modify the HashMap class so that it uses polymorphism to allow redefinition of the the keys’ hash function. To do this, do the following:

  1. Add an abstract class Hashable with a single pure virtual function int hash(). Classes that are derived from Hashable will implement hash to convert key values to an int in the range 0-9.

  2. Modify the HashMap to have keys that are pointers to Hashable objects.

  3. Modify the HashMap’s insert and at functions to use the hash function when computing indices.

  4. Test the changes by creating a class that is derived from Hashable and implements the hash function. Use this class to test inserting items into the map.