|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object HashTable<T>
public class HashTable<T>
This class implements a hashtable that using chaining for collision handling. Any non-null item may be added to a hashtable. Chains are implemented using LinkedLists. When a hashtable is created, its initial size, maximum load factor, and (optionally) maximum chain length are specified. The hashtable can hold arbitrarily many items and resizes itself whenever it reaches its maximum load factor or whenever it reaches its maximum chain length (if a maximum chain length has been specified). Note that the hashtable allows duplicate entries.
Constructor Summary | |
---|---|
HashTable(int initSize,
double loadFactor)
Constructs an empty hashtable with the given initial size, maximum load factor, and no maximum chain length. |
|
HashTable(int initSize,
double loadFactor,
int maxChainLength)
Constructs an empty hashtable with the given initial size, maximum load factor, and maximum chain length. |
Method Summary | |
---|---|
T |
delete(T item)
Removes and returns the given item from the hashtable. |
void |
displayStats(java.io.PrintStream out)
Prints statistics about the hashtable to the PrintStream supplied. |
void |
dump(java.io.PrintStream out)
Prints all the items in the hashtable to the PrintStream supplied. |
void |
insert(T item)
Inserts the given item into the hashtable. |
T |
lookup(T item)
Determines if the given item is in the hashtable and returns it if present. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public HashTable(int initSize, double loadFactor)
initSize
- the initial size of the hashtable.loadFactor
- the load factor expressed as a real number.
java.lang.IllegalArgumentException
- if initSize is less than or
equal to 0 or if loadFactor is less than or equal to 0.0public HashTable(int initSize, double loadFactor, int maxChainLength)
initSize
- the initial size of the hashtable.loadFactor
- the load factor expressed as a real number.maxChainLength
- the maximum chain length.
java.lang.IllegalArgumentException
- if initSize is less than or
equal to 0 or if loadFactor is less than or equal to 0.0
or if maxChainLength is less than or equal to 0.Method Detail |
---|
public T lookup(T item)
item
- the item to search for in the hashtable.
public void insert(T item)
If the load factor of the hashtable after the insert would exceed (not equal) the maximum load factor (given in the constructor), then the hashtable is resized. If the maximum chain length of the hashtable after insert would exceed (not equal) the maximum chain length (given in the constructor), then the hashtable is resized. When resizing, to make sure the size of the table is reasonable, the new size is always 2 x old size + 1. For example, size 101 would become 203. (This guarantees that it will be an odd size.)
Note that duplicates are allowed.
item
- the item to add to the hashtable.
java.lang.NullPointerException
- if item is null.public T delete(T item)
item
- the item to delete in the hashtable.
public void dump(java.io.PrintStream out)
out
- the place to print all the output.public void displayStats(java.io.PrintStream out)
out
- the place to print all the output.
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |