public class ArrayHashMap<K,V> extends Object implements Iterable<V>
The hashtable is constructed with a given capacity, or 16 as a default. In case there's not enough room for new pairs, the hashtable grows. Capacity is adjusted to a power of 2, and there are 2 * capacity entries for the hash. The pre allocated arrays (for keys, values) are at length of capacity + 1, where index 0 is used as 'Ground' or 'NULL'.
The arrays are allocated ahead of hash operations, and form an 'empty space' list, to which the <key,value> pair is allocated.
Constructor and Description |
---|
ArrayHashMap()
Constructs a map with default capacity.
|
ArrayHashMap(int capacity)
Constructs a map with given capacity.
|
Modifier and Type | Method and Description |
---|---|
protected int |
calcBaseHashIndex(K key)
Calculating the baseHash index using the internal internal
hashFactor . |
void |
clear()
Empties the map.
|
boolean |
containsKey(K key)
Returns true iff the key exists in the map.
|
boolean |
containsValue(Object o)
Returns true iff the object exists in the map.
|
boolean |
equals(Object o) |
protected int |
find(K key)
Returns the index of the given key, or zero if the key wasn't found.
|
V |
get(K key)
Returns the object mapped with the given key, or null if the key wasn't found.
|
protected void |
grow()
Allocates a new map of double the capacity, and fast-insert the old
key-value pairs.
|
int |
hashCode() |
boolean |
isEmpty()
Returns true iff the map is empty.
|
Iterator<V> |
iterator()
Returns an iterator on the mapped objects.
|
Iterator<K> |
keyIterator()
Returns an iterator on the map keys.
|
V |
put(K key,
V e)
Inserts the <key,value> pair into the map.
|
V |
remove(K key)
Removes a <key,value> pair from the map and returns the mapped value,
or null if the none existed.
|
int |
size()
Returns number of pairs currently in the map.
|
Object[] |
toArray()
Translates the mapped pairs' values into an array of Objects
|
V[] |
toArray(V[] a)
Translates the mapped pairs' values into an array of V
|
String |
toString() |
public ArrayHashMap()
public ArrayHashMap(int capacity)
capacity
- minimum capacity for the map.protected int calcBaseHashIndex(K key)
hashFactor
.public void clear()
public boolean containsKey(K key)
public boolean containsValue(Object o)
protected int find(K key)
public V get(K key)
protected void grow()
public boolean isEmpty()
public V put(K key, V e)
public V remove(K key)
key
- used to find the value to removepublic int size()
public Object[] toArray()
public V[] toArray(V[] a)
a
- the array into which the elements of the list are to be stored, if
it is big enough; otherwise, use as much space as it can.Copyright © 2000-2013 Apache Software Foundation. All Rights Reserved.