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
Hashtable()
- Construct a hash table that is initially empty.
Hashtable(int)
- Construct a hash table that is capable of holding at least
initialCapacity values.
clear()
- Remove all key-value pairs from hashtable.
contains(Object)
- Returns true if a specific value appears within the table.
containsKey(Object)
- Returns true iff a specific key appears within the table.
elements()
- Returns an iterator that traverses over the values of the
hashtable.
get(Object)
- Get the value associated with a key.
isEmpty()
- Determine if table is empty.
keys()
- Get an iterator over the keys of the hashtable.
put(Object, Object)
- Place a key-value pair within the table.
remove(Object)
- Remove a key-value pair from the table.
size()
- Return the number of key-value pairs within the table.
toString()
- Generate a string representation of the hash table.
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.
Hashtable
public Hashtable()
- Construct a hash table that is initially empty.
- Postcondition:
- constructs a new Hashtable
clear
public void clear()
- Remove all key-value pairs from hashtable.
- Postcondition:
- removes all elements from Hashtable
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.
isEmpty
public boolean isEmpty()
- Determine if table is empty.
- Postcondition:
- returns true iff hash table has 0 elements
- Returns:
- True if table is empty.
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.
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.
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.
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.
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.
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.
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.
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