|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.apache.lucene.util.collections.ArrayHashMap<K,V>
public class ArrayHashMap<K,V>
An Array-based hashtable which maps, similar to Java's HashMap, only performance tests showed it performs better.
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 Summary | |
---|---|
ArrayHashMap()
Constructs a map with default capacity. |
|
ArrayHashMap(int capacity)
Constructs a map with given capacity. |
Method Summary | |
---|---|
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()
|
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public ArrayHashMap()
public ArrayHashMap(int capacity)
capacity
- minimum capacity for the map.Method Detail |
---|
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 Iterator<V> iterator()
iterator
in interface Iterable<V>
public Iterator<K> keyIterator()
public V put(K key, V e)
public V remove(K key)
key
- used to find the value to remove
public 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.
public String toString()
toString
in class Object
public int hashCode()
hashCode
in class Object
public boolean equals(Object o)
equals
in class Object
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |