All Packages  Class Hierarchy  This Package  Previous  Next  Index  

Class structure.Hashtable

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

public class Hashtable
extends Object
implements Dictionary
Implements a dictionary as a table of hashed key-value pairs. Collisions are resolved through linear probing. Values used as keys in this structure must have a hashcode method that returns the same value when two keys are "equals". Initially, a table of suggested size is allocated. It will be expanded as the load factor (ratio of pairs to entries) grows.

See Also:
ChainedHashtable, java.util.Hashtable

Constructor Index

 o Hashtable()
Construct a hash table that is initially empty.
 o Hashtable(int)
Construct a hash table that is capable of holding at least initialCapacity values.

Method Index

 o clear()
Remove all key-value pairs from 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()
Determine if table is empty.
 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()
Return the number of key-value pairs within the table.
 o toString()
Generate a string representation of the hash table.

Constructors

 o Hashtable
public Hashtable(int initialCapacity)
Construct a hash table that is capable of holding at least initialCapacity values. If that value is approached, it will be expanded appropriately. It is probably best if the capacity is prime. Table is initially empty.

Precondition:
initialCapacity > 0
Postcondition:
constructs a new Hashtable holding initialCapacity elements

Parameters:
initialCapacity - The initial capacity of the hash table.
 o Hashtable
public Hashtable()
Construct a hash table that is initially empty.

Postcondition:
constructs a new Hashtable

Methods

 o clear
public void clear()
Remove all key-value pairs from hashtable.

Postcondition:
removes all elements from Hashtable

 o size
public int size()
Return the number of key-value pairs within the table.

Postcondition:
returns number of elements in hash table

Returns:
The number of key-value pairs currently in table.
 o isEmpty
public boolean isEmpty()
Determine if table is empty.

Postcondition:
returns true iff hash table has 0 elements

Returns:
True if table is empty.
 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:
key is a non-null Object
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 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