java.lang.Object | +----Table
Table
is an open-address hash table with a fixed capacity.
The purpose is to show students how an open-address hash table is
implemented. Programs should generally use java.util.Hashtable
rather than this hash table.
nextIndex
was fixed April 1999 by
Craig Miller.
public Table(int capacity)
capacity
- the capacity for this new open-address hash table
public boolean containsKey(Object key)
key
- the non-null key to look for
key
cannot be null.
true
false otherwise. Note that key.equals( )
is used to compare the key
to the keys that are in the
table.
key
is null.
public Object get(Object key)
key
- the non-null key to look for
key
cannot be null.
key
key.equals( ) is used to compare the key
to the keys that are in the table.
key
is null.
public Object put(Object key, Object element)
key
- the non-null key to use for the new element
element
- the new element that’s being added to this table
key
,
then this table’s size must be less than its capacity
(i.e., size() < capacity()
). Also, neither key
nor element is null.
key
,
then that object is replaced by element, and the return
value is a reference to the replaced object. Otherwise, the new
element is added with the specified key
and the return value is null.
key
or element
is null.
public Object remove(Object key)
key
- the non-null key to look for
key
cannot be null.
key.equals( )
is used to compare the key
to the keys that are in the table.