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
ChainedHashtable()
- Constructs a reasonably large hashtable.
ChainedHashtable(int)
- Constructs a hashtable with capacity for at size elements
before chaining is absolutely required.
clear()
- Removes the values from the 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()
- Returns true if no elements are stored within the table.
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()
- Computes the number of elements stored within the hashtable.
toString()
- Generate a string representation of the chained hash table.
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.
ChainedHashtable
public ChainedHashtable()
- Constructs a reasonably large hashtable.
- Postcondition:
- constructs a new ChainedHashtable
clear
public void clear()
- Removes the values from the hashtable.
- Postcondition:
- removes all the elements from the ChainedHashtable.
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.
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.
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:
- 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.
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 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