public class HashTableMap<K,V> extends java.lang.Object implements Map<K,V>
Modifier and Type | Class and Description |
---|---|
static class |
HashTableMap.HashEntry<K,V>
Nested class for an entry in a hash table.
|
Constructor and Description |
---|
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.
|
Modifier and Type | Method and Description |
---|---|
java.lang.Iterable<Entry<K,V>> |
entries()
Returns an iterable object containing all of the entries.
|
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.
|
java.lang.Iterable<K> |
keys()
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.
|
V |
remove(K key)
Removes the key-value pair with a specified key.
|
int |
size()
Returns the number of entries in the hash table.
|
java.lang.Iterable<V> |
values()
Returns an iterable object containing all of the values.
|
public HashTableMap()
public HashTableMap(int cap)
public HashTableMap(int p, int cap)
public java.lang.Iterable<Entry<K,V>> entries()
public V get(K key) throws InvalidKeyException
get
in interface Map<K,V>
InvalidKeyException
public int hashValue(K key)
public boolean isEmpty()
public java.lang.Iterable<K> keys()
public V put(K key, V value) throws InvalidKeyException
put
in interface Map<K,V>
InvalidKeyException
public V remove(K key) throws InvalidKeyException
remove
in interface Map<K,V>
InvalidKeyException
public int size()