org.apache.lucene.util.collections
Class FloatToObjectMap<T>

java.lang.Object
  extended by org.apache.lucene.util.collections.FloatToObjectMap<T>
All Implemented Interfaces:
Iterable<T>

public class FloatToObjectMap<T>
extends Object
implements Iterable<T>

An Array-based hashtable which maps primitive float to Objects of generic type T.
The hashtable is constracted 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, when 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.

WARNING: This API is experimental and might change in incompatible ways in the next release.

Constructor Summary
FloatToObjectMap()
          Constructs a map with default capacity.
FloatToObjectMap(int capacity)
          Constructs a map with given capacity.
 
Method Summary
protected  int calcBaseHashIndex(float key)
          Calculating the baseHash index using the internal hashFactor.
 void clear()
          Empties the map.
 boolean containsKey(float key)
          Checks if a given key exists in the map.
 boolean containsValue(Object o)
          Checks if the given object exists in the map.
This method iterates over the collection, trying to find an equal object.
 boolean equals(Object o)
           
protected  int find(float key)
          Find the actual index of a given key.
 T get(float key)
          Returns the object mapped with the given key.
protected  void grow()
          Grows the map.
 int hashCode()
           
 boolean isEmpty()
           
 Iterator<T> iterator()
          Returns a new iterator for the mapped objects.
 FloatIterator keyIterator()
          Returns an iterator on the map keys.
 T put(float key, T e)
          Inserts the <key,value> pair into the map.
 T remove(float key)
          Removes a <key,value> pair from the map and returns the mapped value, or null if the none existed.
 int size()
           
 Object[] toArray()
          Translates the mapped pairs' values into an array of Objects
 T[] toArray(T[] a)
          Translates the mapped pairs' values into an array of T
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

FloatToObjectMap

public FloatToObjectMap()
Constructs a map with default capacity.


FloatToObjectMap

public FloatToObjectMap(int capacity)
Constructs a map with given capacity. Capacity is adjusted to a native power of 2, with minimum of 16.

Parameters:
capacity - minimum capacity for the map.
Method Detail

calcBaseHashIndex

protected int calcBaseHashIndex(float key)
Calculating the baseHash index using the internal hashFactor.

Parameters:
key -

clear

public void clear()
Empties the map. Generates the "Empty" space list for later allocation.


containsKey

public boolean containsKey(float key)
Checks if a given key exists in the map.

Parameters:
key - that is checked against the map data.
Returns:
true if the key exists in the map. false otherwise.

containsValue

public boolean containsValue(Object o)
Checks if the given object exists in the map.
This method iterates over the collection, trying to find an equal object.

Parameters:
o - object that is checked against the map data.
Returns:
true if the object exists in the map (in .equals() meaning). false otherwise.

find

protected int find(float key)
Find the actual index of a given key.

Parameters:
key -
Returns:
index of the key. zero if the key wasn't found.

get

public T get(float key)
Returns the object mapped with the given key.

Parameters:
key - int who's mapped object we're interested in.
Returns:
an object mapped by the given key. null if the key wasn't found.

grow

protected void grow()
Grows the map. Allocates a new map of double the capacity, and fast-insert the old key-value pairs.


isEmpty

public boolean isEmpty()
Returns:
true if the map is empty. false otherwise.

iterator

public Iterator<T> iterator()
Returns a new iterator for the mapped objects.

Specified by:
iterator in interface Iterable<T>

keyIterator

public FloatIterator keyIterator()
Returns an iterator on the map keys.


put

public T put(float key,
             T e)
Inserts the <key,value> pair into the map. If the key already exists, this method updates the mapped value to the given one, returning the old mapped value.

Returns:
the old mapped value, or null if the key didn't exist.

remove

public T remove(float key)
Removes a <key,value> pair from the map and returns the mapped value, or null if the none existed.

Parameters:
key - used to find the value to remove
Returns:
the removed value or null if none existed.

size

public int size()
Returns:
number of pairs currently in the map

toArray

public Object[] toArray()
Translates the mapped pairs' values into an array of Objects

Returns:
an object array of all the values currently in the map.

toArray

public T[] toArray(T[] a)
Translates the mapped pairs' values into an array of T

Parameters:
a - the array into which the elements of the list are to be stored, if it is big enough; otherwise, use whatever space we have, setting the one after the true data as null.
Returns:
an array containing the elements of the list

toString

public String toString()
Overrides:
toString in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object

equals

public boolean equals(Object o)
Overrides:
equals in class Object