All Packages  Class Hierarchy  This Package  Previous  Next  Index  

Class structure.ChainedHashtable

java.lang.Object
    |
    +----structure.ChainedHashtable

public class ChainedHashtable
extends Object
implements Dictionary
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, java.util.Hashtable

Constructor Index

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

Method Index

 o clear()
Removes the values from the hashtable.
 o contains(Object)
Returns true if a specific value appears within the table.
 o containsKey(Object)
Returns true iff a specific key appears within the table.
 o elements()
Returns an iterator that traverses over the values of the hashtable.
 o get(Object)
Get the value associated with a key.
 o isEmpty()
Returns true if no elements are stored within the table.
 o keys()
Get an iterator over the keys of the hashtable.
 o put(Object, Object)
Place a key-value pair within the table.
 o remove(Object)
Remove a key-value pair from the table.
 o size()
Computes the number of elements stored within the hashtable.
 o toString()
Generate a string representation of the chained hash table.

Constructors

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

Precondition:
size > 0
Postcondition:
constructs a new ChainedHashtable

Parameters:
size - The number of entries initially allocated.
 o ChainedHashtable
public ChainedHashtable()
Constructs a reasonably large hashtable.

Postcondition:
constructs a new ChainedHashtable

Methods

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

Postcondition:
removes all the elements from the ChainedHashtable.

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

Postcondition:
returns number of elements in hash table

Returns:
The number of elements within the hash table.
 o isEmpty
public boolean isEmpty()
Returns true if no elements are stored within the table.

Postcondition:
returns true iff hash table has 0 elements

Returns:
True iff size() == 0.
 o contains
public boolean contains(Object value)
Returns true if a specific value appears within the table.

Precondition:
value is non-null Object
Postcondition:
returns true iff hash table contains value

Parameters:
value - The value sought.
Returns:
True iff the value appears within the table.
 o containsKey
public boolean containsKey(Object key)
Returns true iff a specific key appears within the table.

Precondition:
value is non-null key
Postcondition:
returns true if key appears in hash table

Parameters:
key - The key sought.
Returns:
True iff the key sought appears within table.
 o elements
public Iterator elements()
Returns an iterator that traverses over the values of the hashtable.

Postcondition:
returns iterator to traverse hash table

Returns:
A value iterator, over the values of the table.
 o get
public Object get(Object key)
Get the value associated with a key.

Precondition:
key is non-null Object
Postcondition:
returns value associated with key, or null

Parameters:
key - The key used to find the desired value.
Returns:
The value associated with the desired key.
 o keys
public Iterator keys()
Get an iterator over the keys of the hashtable.

Postcondition:
returns iterator to traverse the keys of hash table.

Returns:
An iterator over the key values appearing within table.
 o put
public Object put(Object key,
                  Object value)
Place a key-value pair within the table.

Precondition:
key is non-null object
Postcondition:
key-value pair is added to hash table

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.
 o remove
public Object remove(Object key)
Remove a key-value pair from the table.

Precondition:
key is non-null object
Postcondition:
removes key-value pair associated with key

Parameters:
key - The key of the key-value pair to be removed.
Returns:
The value associated with the removed key.
 o toString
public String toString()
Generate a string representation of the chained hash table.

Postcondition:
returns a string representation of hash table.

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

All Packages  Class Hierarchy  This Package  Previous  Next  Index