structure
Class ChainedHashtable

java.lang.Object
  extended by structure.AbstractMap
      extended by structure.ChainedHashtable
All Implemented Interfaces:
Map

public class ChainedHashtable
extends AbstractMap
implements Map

This class implements a hash table whose collisions are resolved through external chaining. Values used as keys in this structure must have a hashcode method that returns the same value when two keys are "equals". Initially, a hash table of suggested size is allocated.

See Also:
Hashtable

Constructor Summary
ChainedHashtable()
          Constructs a reasonably large hashtable.
ChainedHashtable(int size)
          Constructs a hashtable with capacity for at size elements before chaining is absolutely required.
 
Method Summary
 void clear()
          Removes the values from the hashtable.
 boolean containsKey(Object key)
          Returns true iff a specific key appears within the table.
 boolean containsValue(Object value)
          Returns true if a specific value appears within the table.
 Set entrySet()
           
 Object get(Object key)
          Get the value associated with a key.
 boolean isEmpty()
          Returns true if no elements are stored within the table.
 Iterator iterator()
          Returns an iterator that traverses over the values of the hashtable.
 Iterator keys()
          Get an iterator over the keys of the hashtable.
 Set keySet()
           
 Object put(Object key, Object value)
          Place a key-value pair within the table.
 Object remove(Object key)
          Remove a key-value pair from the table.
 int size()
          Computes the number of elements stored within the hashtable.
 String toString()
          Generate a string representation of the chained hash table.
 Structure values()
           
 
Methods inherited from class structure.AbstractMap
hashCode, putAll
 
Methods inherited from class java.lang.Object
equals, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface structure.Map
equals, hashCode, putAll
 

Constructor Detail

ChainedHashtable

public ChainedHashtable(int size)
Constructs a hashtable with capacity for at size elements before chaining is absolutely required.

Parameters:
size - The number of entries initially allocated.

ChainedHashtable

public ChainedHashtable()
Constructs a reasonably large hashtable.

Method Detail

clear

public void clear()
Removes the values from the hashtable.

Specified by:
clear in interface Map

size

public int size()
Computes the number of elements stored within the hashtable.

Specified by:
size in interface Map
Returns:
The number of elements within the hash table.

isEmpty

public boolean isEmpty()
Returns true if no elements are stored within the table.

Specified by:
isEmpty in interface Map
Returns:
True iff size() == 0.

containsValue

public boolean containsValue(Object value)
Returns true if a specific value appears within the table.

Specified by:
containsValue in interface Map
Parameters:
value - The value sought.
Returns:
True iff the value appears within the table.

containsKey

public boolean containsKey(Object key)
Returns true iff a specific key appears within the table.

Specified by:
containsKey in interface Map
Parameters:
key - The key sought.
Returns:
True iff the key sought appears within table.

iterator

public Iterator iterator()
Returns an iterator that traverses over the values of the hashtable.

Returns:
A value iterator, over the values of the table.

keySet

public Set keySet()
Specified by:
keySet in interface Map

entrySet

public Set entrySet()
Specified by:
entrySet in interface Map

values

public Structure values()
Specified by:
values in interface Map

get

public Object get(Object key)
Get the value associated with a key.

Specified by:
get in interface Map
Parameters:
key - The key used to find the desired value.
Returns:
The value associated with the desired key.

keys

public Iterator keys()
Get an iterator over the keys of the hashtable.

Returns:
An iterator over the key values appearing within table.

put

public Object put(Object key,
                  Object value)
Place a key-value pair within the table.

Specified by:
put in interface Map
Parameters:
key - The key to be added to table.
value - The value associated with key.
Returns:
The old value associated with key if previously present.

remove

public Object remove(Object key)
Remove a key-value pair from the table.

Specified by:
remove in interface Map
Parameters:
key - The key of the key-value pair to be removed.
Returns:
The value associated with the removed key.

toString

public String toString()
Generate a string representation of the chained hash table.

Overrides:
toString in class Object
Returns:
The string representing the table.