edu.colorado.collections
Class ChainedTable

java.lang.Object
  extended by edu.colorado.collections.ChainedTable

public class ChainedTable
extends java.lang.Object

A ChainedTable is a chained hash table. The implementation isn't given here since it is an assignment in a typical data structures class. In general, programs should use java.util.HashTable rather than this ChainedTable.

Outline of Java Source Code for this class:
http://www.cs.colorado.edu/~main/edu/colorado/collections/ChainedTable.java


Constructor Summary
ChainedTable(int tableSize)
          Initialize an empty ChainedTable with a specified table size.
 
Method Summary
 boolean containsKey(java.lang.Object key)
          Determines whether a specified key is in this ChainedTable.
 java.lang.Object get(java.lang.Object key)
          Retrieves an object for a specified key.
 java.lang.Object put(java.lang.Object key, java.lang.Object element)
          Add a new element to this ChainedTable, using the specified key.
 java.lang.Object remove(java.lang.Object key)
          Removes an object for a specified key.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ChainedTable

public ChainedTable(int tableSize)
Initialize an empty ChainedTable with a specified table size.

Parameters:
tableSize - the table size for this new chained hash table
Precondition:
tableSize > 0
Postcondition:
This ChainedTable is empty and has the specified table size.
Throws:
java.lang.OutOfMemoryError - Indicates insufficient memory for the specified table size.
java.lang.IllegalArgumentException - Indicates that tableSize is not positive.
Method Detail

containsKey

public boolean containsKey(java.lang.Object key)
Determines whether a specified key is in this ChainedTable.

Parameters:
key - the non-null key to look for
Precondition:
key cannot be null.
Returns:
truefalse otherwise. Note that key.equals( ) is used to compare the key to the keys that are in the ChainedTable.
Throws:
java.lang.NullPointerException - Indicates that key is null.

get

public java.lang.Object get(java.lang.Object key)
Retrieves an object for a specified key.

Parameters:
key - the non-null key to look for
Precondition:
key cannot be null.
Returns:
a reference to the object with the specified keykey.equals( ) is used to compare the key to the keys that are in the ChainedTable.
Throws:
java.lang.NullPointerException - Indicates that key is null.

put

public java.lang.Object put(java.lang.Object key,
                            java.lang.Object element)
Add a new element to this ChainedTable, using the specified key.

Parameters:
key - the non-null key to use for the new element
element - the new element that's being added to this ChainedTable
Precondition:
Neither key nor element is null.
Postcondition:
If this ChainedTable already has an object with the specified 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.
Throws:
java.lang.NullPointerException - Indicates that key or element is null.

remove

public java.lang.Object remove(java.lang.Object key)
Removes an object for a specified key.

Parameters:
key - the non-null key to look for
Precondition:
key cannot be null.
Postcondition:
If an object was found with the specified key, then that object has been removed from this ChainedTable and a copy of the removed object is returned; otherwise, this ChainedTable is unchanged and the null reference is returned. Note that key.equals( ) is used to compare the key to the keys that are in the ChainedTable.
Throws:
java.lang.NullPointerException - Indicates that key is null.