| Project #6 | CMSC 132 |
| Due: Saturday, 4/9 at 11:00PM | Object-Oriented Programming II |
| Type of project: Closed | Spring 2011 |
Hash Table
Introduction
For this project you will create a class called MyHashSet, which is a slightly simplified version of a HashSet. As you might guess, we will use a hash table to store the elements in the set. The "buckets" in the table will be implemented as linked lists.
If you take a look at the code distribution, you'll find a Node class nested inside the MyHashSet class. The Hash table will be an array of Node references. An empty bucket will be represented as a null entry in the array. Each Node encapsulates a data element and has a "next" reference, which will either refer to another Node in this same bucket, or will be null if this Node is the last one in the bucket.
The MyHashSet class will implement the Iterable interface, which of course means that you must implement the "iterator" method. Your Iterator will allow the user to iterate over all of the elements stored in the table. Implementing the Iterator is probably the most challenging part of this project!
Implementation Details
Most of the details are specified here in the Javadoc. But here are some additional remarks:bucket number = | (p * hashCode) % n |where p is a large prime of your choosing, and n is the capacity (length) of the table. Be sure to always use the same prime, p, throughout the life of the table!
Your Iterator should allow the user to iterate through all of the elements in the MyHashSet. The Iterator class should be implemented as an inner class of the MyHashSet class.
Your Iterator must implement all three of the methods in the interface: next, hasNext, and also remove. We suggest implementing all of the other features of the MyHashSet class before you tackle the Iterator. You can get most of the points for this project even if your iterator doesn't work, but we are hoping that you will succeed with it, too!
The order in which the iterator traverses the data is irrelevant, and doesn't need to be the same each time.
Your "next" method should throw an IllegalStateException if someone attempts to call it at a time when hasNext would return false.
Your "remove" method should throw an IllegalStateException in two cases:
By the way, it is okay if your Iterator does not throw ConcurrentModificationExceptions even when it should.
Additional Requirements
Grading
The public tests and release tests together will comprise 90% of your grade on the project. The remaining 10% will be "style grading", done by visual inspection. Be sure to use good variable names, proper indentation and use of braces, etc. Also be careful to avoid redundant code.