In this project, you will implement a hashmap and a hashset. We will be using these two data structures extensively in the upcoming project.
This is a team assignment. This entire project is due on Wed, Jan 31 at 11:30pm.
When working on this assignment, we expect you meet these baseline expectations at all times:
Here are some baseline expectations we expect you to meet:
Follow the course collaboration policies
DO NOT use any classes from
java.util.*
. There are only two exceptions to this rule:
You may import and use java.util.Iterator
and
java.util.NoSuchElementException
.
You may import and use anything from java.util.*
within your testing code.
DO NOT modify instructor-provided code (unless told otherwise)
Download the project from this link and open it in your IDE. See the instructions from project 1 if you need a reminder on how to do this.
Copy your DoubleLinkedList.java
and
ArrayDictionary.java
files from project 1 to this
new one.
The copied code will not immediately compile. This
is ok: we modified IDictionary
so it requires
you to implement one additional method.
Copy any of the delete tests you wrote from TestDoubleLinkedList.java
to the new one.
Be sure not to overwrite the entire TestDoubleLinkedList
class: we gave you a slightly modified one containing a few extra tests.
Finally, make sure everything works.
Try running TestDoubleLinkedList
and make sure the tests run.
Try running SanityCheck.java
, and try running checkstyle.
Checkstyle should still report the same 5 errors with SanityCheck.java
as it did with project 1.
Task: implement ArrayDictionary.iterator()
.
Take a look at IDictionary
. You may notice that the
interface now requires all subclasses to implement one additional
method: iterator()
.
By implementing this method, we can now (efficiently) iterate over all key-value pairs in our dictionaries! For example, we can now do this:
IDictionary<String, Integer> foo = makeTheDictionary();
for (KVPair<String, Integer> pair : foo) {
String key = pair.getKey();
Integer value = pair.getValue();
// Do something with key and value
System.out.println(key + " : " + value);
}
The above program should print out every key-value pair contained within
foo
.
Notes:
Your iterator()
method may return the key value pairs
in any order you wish. The easiest approach would likely be to
return them in the order your pairs are listed in your internal
array.
You may assume the user will not modify the dictionary while you're iterating over it.
You may NOT create any temporary data
structures such as a temp IList
when implementing
your iterator. We want our iterators to be efficient, and having
to copy the contents of our dictionary to some other data
structure at any point is suboptimal.
You may, however, create new KVPair
objects. (They
do not count as "temporary" data structures).
We have provided you with unit tests for your iterators. You can add more tests if you want.
If you need examples on how to implement an iterator, see
DoubleLinkedList
and the stubs in
ChainingHashDictionary
. Also see the
ArrayList
iterator we implemented together
at the start of the quarter.
The IDictionary
interface requires that dictionaries
return KVPair
objects. However, your internal dictionary
uses private Pair
objects. You will need to convert
between the two within your iterator – see the method header comments
in KVPair
to understand how to instantiate new
KVPair
objects.
When creating the iterator, you will need to create a private static
inner class to ArrayDictionary
. Your class should look roughly
like this:
private static class ArrayDictionaryIterator<K, V> implements Iterator<KVPair<K, V>> {
// ...
}
Make sure to make the class private and static, and make sure you copy how the generics are being defined correctly.
Task: complete the ChainingHashDictionary
class.
Notes:
ArrayDictionary
s as your internal chains/buckets.iterator()
method doesn't need to yield the
pairs in any particular order.Correctly implementing your iterator will be tricky –
don't leave it to the last minute! Try and finish the other methods
in ChainingHashDictionary
as soon as possible so you
can move on to implementing iterator()
.
The comments in ChainingHashDictionary
will contain a
few hints on how to implement this method.
Task: complete the ChainingHashSet
class.
Notes:
IDictionary<KeyType, Boolean>
to store
your set values. We will completely ignore the values
in your dictionary: use a placeholder boolean whenever
necessary.Task: submit answers to the following questions.
Each group member should answer and submit these questions independently at this canvas page.
You must submit your answers in either .txt
or
.pdf
form.
The following deliverables are due on Wed, Jan 31 at 11:30pm.
A single person from your partnership should
submit a zip file conaining the entire contents of your src
folder
on Canvas.
Before submitting, be sure to double-check and make sure that...
ArrayDictionary
class is fully repaired and
passes all tests.
ChainedHashDictionary
class is fully
implemented and passes all tests.ChainedHashSet
class is fully
implemented and passes all tests.Both partners should turn in a .txt
or
.pdf
file containing their answers to part 4
on Canvas
if you haven't already. This is due at the same time as
the rest of your project.