In this assignment, you implement a rudimentary hash table. A hash table stores a set of arbitrary objects. If an object is already present, it is not stored twice. You can also find out whether an element is already present.
The storage is an array of objects, with null
for empty slots. If an object x
has hash code h = x.hashCode()
, then store it at elements[h % elements.length]
if you can, or at the next non-null slot. Wrap around the table if necessary. That is, go from slot elements.length - 1
to slot 0.
If the table is completely full, then don't insert any new elements.
To find an existing element, start looking for it at slot x.hashCode() % elements.length
. Keep looking until you found it, found a null
, or you visited all elements of the table.