public abstract class AbstractHashMap<K,V> extends AbstractMap<K,V>
AbstractMap.MapEntry<K,V>
Constructor and Description |
---|
AbstractHashMap()
Creates a hash table with capacity 17 and prime factor 109345121.
|
AbstractHashMap(int cap)
Creates a hash table with given capacity and prime factor 109345121.
|
AbstractHashMap(int cap,
int p)
Creates a hash table with the given capacity and prime factor.
|
Modifier and Type | Method and Description |
---|---|
protected abstract V |
bucketGet(int h,
K k)
Returns value associated with key k in bucket with hash value h.
|
protected abstract V |
bucketPut(int h,
K k,
V v)
Associates key k with value v in bucket with hash value h, returning
the previously associated value, if any.
|
protected abstract V |
bucketRemove(int h,
K k)
Removes entry having key k from bucket with hash value h, returning
the previously associated value, if found.
|
protected abstract void |
createTable()
Creates an empty table having length equal to current capacity.
|
V |
get(K key)
Returns the value associated with the specified key, or null if no such entry exists.
|
V |
put(K key,
V value)
Associates the given value with the given key.
|
V |
remove(K key)
Removes the entry with the specified key, if present, and returns
its associated value.
|
int |
size()
Tests whether the map is empty.
|
isEmpty, keySet, values
public AbstractHashMap(int cap, int p)
public AbstractHashMap(int cap)
public AbstractHashMap()
public int size()
public V get(K key)
key
- the key whose associated value is to be returnedpublic V remove(K key)
key
- the key whose entry is to be removed from the mappublic V put(K key, V value)
key
- key with which the specified value is to be associatedvalue
- value to be associated with the specified keyprotected abstract void createTable()
protected abstract V bucketGet(int h, K k)
h
- the hash value of the relevant bucketk
- the key of interestprotected abstract V bucketPut(int h, K k, V v)
h
- the hash value of the relevant bucketk
- the key of interestv
- the value to be associatedprotected abstract V bucketRemove(int h, K k)
h
- the hash value of the relevant bucketk
- the key of interest