edu.olemiss.cs211
Class HashTable<K,V>
java.lang.Object
edu.olemiss.cs211.HashTable<K,V>
- Type Parameters:
K
- The key type.V
- The value type.
- All Implemented Interfaces:
- java.lang.Iterable<V>
public class HashTable<K,V>
- extends java.lang.Object
- implements java.lang.Iterable<V>
A Hash Table class that represents associations between keys and values.
An association is just a tuple . So, we might add <"foo", 12> to this
hash table, associating the string "foo" with the number 12. The key "foo"
is used to determine where in the hashtable the tuple is stored. Key
types should have a robust implementation of hashCode().
- Author:
- rhodes
Constructor Summary |
HashTable(int tableSize)
Create a hash table of the specified size. |
Method Summary |
void |
add(K key,
V v)
Add an association to the hash table. |
V |
find(java.lang.Object k)
Return the value corresponding to the key k. |
java.util.Iterator<V> |
iterator()
Return an iterator associated with this HashTable. |
java.lang.String |
toString()
Return a string representing all the values (not keys)
in the hash table. |
Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
HashTable
public HashTable(int tableSize)
- Create a hash table of the specified size.
- Parameters:
tableSize
- size of the table
add
public void add(K key,
V v)
- Add an association to the hash table.
k is used to choose a position in the table.
find
public V find(java.lang.Object k)
- Return the value corresponding to the key k.
- Parameters:
k
- the key
- Returns:
- the value
toString
public java.lang.String toString()
- Return a string representing all the values (not keys)
in the hash table.
- Overrides:
toString
in class java.lang.Object
iterator
public java.util.Iterator<V> iterator()
- Return an iterator associated with this HashTable.
- Specified by:
iterator
in interface java.lang.Iterable<V>