Programming Exercise 4


In this exercise you will learn to use library data structures and also increase your "object" skills. The desired outcome is a hashtable that can store duplicates.

Recall the problem with Java's Hashtable: duplicates may not be stored. For example, consider:

  Hashtable h = new Hashtable ();
  h.put ("A", "AAA");   // Store the key "A" and value "AAA"
  h.put ("B", "BBB");   // Store the key "B" and value "BBB"
  h.put ("B", "BBBBB"); // This key-value pair replaces "B" and "BBB".
What we would like is a hashtable that stores duplicates. However, suppose we have a hashtable DupHashtable that stores duplicates, e.g.
  DupHashtable h = new DupHashtable ();
  h.put ("A", "AAA");   // Store the key "A" and value "AAA"
  h.put ("B", "BBB");   // Store the key "B" and value "BBB"
  h.put ("B", "BBBBB"); // Store the value "BBBBB" with existing key "B"
When we retrieve on a key, we could have a collection of values stored along with that one key. Thus, in retrieving, we need to be prepared to receive a collection of values. In other words, the equivalent in DupHashtable of the get() method in Hashtable should return a collection.

In this exercise, you are to implement the class DupHashtable and compare its performance with that of Hashtable:

Submission: