|
net.datastructures - version 5.0 | |||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnet.datastructures.HashTableMap<K,V>
public class HashTableMap<K,V>
A hash table data structure that uses linear probing to handle collisions. The hash function uses the built-in hashCode method and the multiply-add-and-divide method. The load factor is alwyas kept less than or equal to 0.5. When the load factor reaches 0.5, the entries are rehashed into a new bucket array with twice the capacity.
Nested Class Summary | |
---|---|
static class |
HashTableMap.HashEntry<K,V>
Nested class for an entry in a hash table. |
Field Summary | |
---|---|
protected Entry<K,V> |
AVAILABLE
|
protected Entry<K,V>[] |
bucket
|
protected int |
capacity
|
protected int |
n
|
protected int |
prime
|
protected long |
scale
|
protected long |
shift
|
Constructor Summary | |
---|---|
HashTableMap()
Creates a hash table with prime factor 109345121 and capacity 1000. |
|
HashTableMap(int cap)
Creates a hash table with prime factor 109345121 and given capacity. |
|
HashTableMap(int p,
int cap)
Creates a hash table with the given prime factor and capacity. |
Method Summary | |
---|---|
protected void |
checkKey(K k)
Determines whether a key is valid. |
Iterable<Entry<K,V>> |
entrySet()
Returns an iterable object containing all of the entries. |
protected int |
findEntry(K key)
Helper search method - returns index of found key or -(a + 1), where a is the index of the first empty or available slot found. |
V |
get(K key)
Returns the value associated with a key. |
int |
hashValue(K key)
Hash function applying MAD method to default hash code. |
boolean |
isEmpty()
Returns whether or not the table is empty. |
Iterable<K> |
keySet()
Returns an iterable object containing all of the keys. |
V |
put(K key,
V value)
Put a key-value pair in the map, replacing previous one if it exists. |
protected void |
rehash()
Doubles the size of the hash table and rehashes all the entries. |
V |
remove(K key)
Removes the key-value pair with a specified key. |
int |
size()
Returns the number of entries in the hash table. |
Iterable<V> |
values()
Returns an iterable object containing all of the values. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected Entry<K,V> AVAILABLE
protected int n
protected int prime
protected int capacity
protected Entry<K,V>[] bucket
protected long scale
protected long shift
Constructor Detail |
---|
public HashTableMap()
public HashTableMap(int cap)
public HashTableMap(int p, int cap)
Method Detail |
---|
protected void checkKey(K k)
public int hashValue(K key)
public int size()
size
in interface Map<K,V>
public boolean isEmpty()
isEmpty
in interface Map<K,V>
public Iterable<K> keySet()
keySet
in interface Map<K,V>
protected int findEntry(K key) throws InvalidKeyException
InvalidKeyException
public V get(K key) throws InvalidKeyException
get
in interface Map<K,V>
InvalidKeyException
public V put(K key, V value) throws InvalidKeyException
put
in interface Map<K,V>
InvalidKeyException
protected void rehash()
public V remove(K key) throws InvalidKeyException
remove
in interface Map<K,V>
InvalidKeyException
public Iterable<Entry<K,V>> entrySet()
entrySet
in interface Map<K,V>
public Iterable<V> values()
values
in interface Map<K,V>
|
net.datastructures - version 5.0 | |||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |