#Comp 124 - MyMap Lab Instructions
In this lab, you'll be completing a simple hashtable implementation. Before you start, make sure you understand the types of the instance variables in the map:
- A single key / value pair is stored in a MyEntry object.
MyEntry is a generic type with type parameters for the key and the value:
MyEntry<K, V>
. - A single hash bucket is a list of MyEntry objects:
List<MyEntry<K, V>>
- The type for the array of hash buckets is a simple extension of the previous data structure:
List<MyEntry<K, V>> []
You should complete this lab in three parts:
- Complete the put() method:
- Hint: the key may already exist!
- Hint: every Java Object has a hashCode() and equals() method.
- After you complete the put() method, the first unit test in TestMyMap should pass.
- Complete the get() method. The first two unit tests in TestMyMap should pass.
- Complete the expandIfNecessary() method.
- This method should decide whether or not to double the size of the array based on the loadFactor.
- If the size is doubled, all the entries have to be put into their new spots, or "rehashed."
- All three unit tests should now pass.