|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object structure.AbstractMap structure.ChainedHashtable
public class ChainedHashtable
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.
Hashtable
Field Summary | |
---|---|
protected int |
capacity
The length of the table. |
protected int |
count
The number of key-value pairs stored within the table. |
protected List[] |
data
The array of chains used to store values. |
Constructor Summary | |
---|---|
ChainedHashtable()
Constructs a reasonably large hashtable. |
|
ChainedHashtable(int size)
Constructs a hashtable with capacity for at size elements before chaining is absolutely required. |
Method Summary | |
---|---|
void |
clear()
Removes the values from the hashtable. |
boolean |
containsKey(java.lang.Object key)
Returns true iff a specific key appears within the table. |
boolean |
containsValue(java.lang.Object value)
Returns true if a specific value appears within the table. |
Set |
entrySet()
|
java.lang.Object |
get(java.lang.Object key)
Get the value associated with a key. |
boolean |
isEmpty()
Returns true if no elements are stored within the table. |
java.util.Iterator |
iterator()
Returns an iterator that traverses over the values of the hashtable. |
java.util.Iterator |
keys()
Get an iterator over the keys of the hashtable. |
Set |
keySet()
|
protected List |
locate(java.lang.Object key)
|
java.lang.Object |
put(java.lang.Object key,
java.lang.Object value)
Place a key-value pair within the table. |
java.lang.Object |
remove(java.lang.Object key)
Remove a key-value pair from the table. |
int |
size()
Computes the number of elements stored within the hashtable. |
java.lang.String |
toString()
Generate a string representation of the chained hash table. |
Structure |
values()
|
Methods inherited from class structure.AbstractMap |
---|
hashCode, putAll |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, notify, notifyAll, wait, wait, wait |
Methods inherited from interface structure.Map |
---|
equals, hashCode, putAll |
Field Detail |
---|
protected List[] data
protected int count
protected int capacity
Constructor Detail |
---|
public ChainedHashtable(int size)
size
- The number of entries initially allocated.public ChainedHashtable()
Method Detail |
---|
public void clear()
clear
in interface Map
public int size()
size
in interface Map
public boolean isEmpty()
isEmpty
in interface Map
protected List locate(java.lang.Object key)
public boolean containsValue(java.lang.Object value)
containsValue
in interface Map
value
- The value sought.
public boolean containsKey(java.lang.Object key)
containsKey
in interface Map
key
- The key sought.
public java.util.Iterator iterator()
public Set keySet()
keySet
in interface Map
public Set entrySet()
entrySet
in interface Map
public Structure values()
values
in interface Map
public java.lang.Object get(java.lang.Object key)
get
in interface Map
key
- The key used to find the desired value.
public java.util.Iterator keys()
public java.lang.Object put(java.lang.Object key, java.lang.Object value)
put
in interface Map
key
- The key to be added to table.value
- The value associated with key.
public java.lang.Object remove(java.lang.Object key)
remove
in interface Map
key
- The key of the key-value pair to be removed.
public java.lang.String toString()
toString
in class java.lang.Object
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |