|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||
java.lang.ObjectOpenHashTable<K,V>
public class OpenHashTable<K,V>
| Nested Class Summary | |
|---|---|
private static class |
OpenHashTable.Entry<K,V>
An inner class that represents a key-value pair that can be stored in a hash table. |
| Field Summary | |
|---|---|
private OpenHashTable.Entry<K,V> |
DELETED
an indicator that can be stored in a hash table in place of an item that has been removed |
private static int |
INITIAL_CAPACITY
constant which defines the initial size of the hash table |
private double |
LOAD_THRESHOLD
maximum allowable capacity before expanding the hash table |
private int |
numDeletes
how many keys (or entries) have been deleted from the table |
private int |
numKeys
how many keys (or entries) are currently stored in the hash table, excluding the number of keys that were deleted |
private java.util.List<OpenHashTable.Entry<K,V>> |
table
hash table - an arraylist of entries |
| Constructor Summary | |
|---|---|
OpenHashTable()
Hash table constructor which creates a hash table with an initial size given by INITIAL_CAPACITY. |
|
| Method Summary | |
|---|---|
private int |
find(K key)
Finds either the target key in the hash table or the first empty location in the hash table. |
V |
get(K key)
Returns the value associated with the specified key. |
int |
getNumberOfKeys()
Provides the number of keys in the map. |
boolean |
isEmpty()
Returns true if this map contains no key-value mappings. |
void |
printTable()
A debugging routine designed to display the contents of the hash table. |
V |
put(K key,
V value)
Associates the specified value with the specified key. |
private void |
rehash()
Expands the table size whenever the number of entries exceeds some threshold (defined in LOAD_THRESHOLD). |
V |
remove(K key)
Removes the mapping for this key if it is present. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
private java.util.List<OpenHashTable.Entry<K,V>> table
private static final int INITIAL_CAPACITY
private double LOAD_THRESHOLD
private int numKeys
private int numDeletes
private final OpenHashTable.Entry<K,V> DELETED
| Constructor Detail |
|---|
public OpenHashTable()
| Method Detail |
|---|
private int find(K key)
key - specified key to search for
public V get(K key)
get in interface SimpleHashMap<K,V>key - the key being looked for
public boolean isEmpty()
isEmpty in interface SimpleHashMap<K,V>public int getNumberOfKeys()
getNumberOfKeys in interface SimpleHashMap<K,V>
public V put(K key,
V value)
put in interface SimpleHashMap<K,V>key - the key for the value to insertvalue - the value associated with this key
private void rehash()
public V remove(K key)
remove in interface SimpleHashMap<K,V>key - the key being looked for
public void printTable()
0: 0 0
1:
2: 30 30
3: 10 10
4:
5: null null
6: 20 20
(<-- this blank line appears here)
|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||