Remember this awesome lab? Your job is to implement a hash set in JavaScript that has the same API as a Java hash set. You must use “hard objects”. Do not use class
. Do not use prototype
. Do not pass Go. Do not collect $200.
Provide a function createHashSet(bucketsLength, hashCode, equals)
. The second and third parameters are functions.
The createHashSet
function returns an object with methods contains
, add
, remove
, iterator
, size
.
The iterator
method returns an object with methods hasNext
, next
, and remove
.
No public state! No other properties than the above-named methods. Internally, you can (and should) use JavaScript objects for the links. Keep an array of buckets just like in the implementation of the HashSet
Java class in the exercise.
I said that you should use undefined
, not null
, in JavaScript. But in this assignment, I don't care. Use null
if you find it easier for porting the code.
When the Java code throws an exception, throw an Error
object with any reason string of your choice.
Put all that in a file hashset.js
that exports createHashSet
.
standard
should have no errors with hashset.js
.
Provide a Jest test hashset.test.js
that ensures that your implementation doesn't suffer from the bug of the implementation in lab 6. (If the grader tests your test case with a buggy implementation, it should fail). You might want to try this with a straight port of the buggy HashSet.java.
If you like, include a file project.txt
that includes the names (first+last) of any fellow students in your section with whom you would like to work on your project.