## org.apache.lucene.facet.collections
Class IntToFloatMap

    java.lang.Object
      org.apache.lucene.facet.collections.IntToFloatMap

    public class IntToFloatMap

extends Object

An Array-based hashtable which maps primitive int to a primitive float.
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.

Field Summary
`static float` `GROUND`

Constructor Summary
`IntToFloatMap()` Constructs a map with default capacity.
`IntToFloatMap(int capacity)` Constructs a map with given capacity.

Method Summary
`protected int` `calcBaseHashIndex(int key)` Calculating the baseHash index using the internal `hashFactor` .
`void` `clear()` Empties the map.
`boolean` `containsKey(int key)` Checks if a given key exists in the map.
`boolean` `containsValue(float value)` Checks if the given value exists in the map. This method iterates over the collection, trying to find an equal object.
`boolean` `equals(Object o)`
`protected int` `find(int key)` Find the actual index of a given key.
`float` `get(int key)` Returns the value mapped with the given key.
`protected void` `grow()` Grows the map.
`int` `hashCode()`
`boolean` `isEmpty()`
`FloatIterator` `iterator()` Returns a new iterator for the mapped float values.
`IntIterator` `keyIterator()` Returns an iterator on the map keys.
`float` `put(int key, float v)` Inserts the <key,value> pair into the map.
`float` `remove(int key)` Removes a <key,value> pair from the map and returns the mapped value, or `Float.NaN` if the none existed.
`int` `size()`
`float[]` `toArray()` Translates the mapped pairs' values into an array of Objects
`float[]` `toArray(float[] 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`

Field Detail

### GROUND

    public static final float GROUND

See Also:
  Constant Field Values

Constructor Detail

### IntToFloatMap

    public IntToFloatMap()

  Constructs a map with default capacity.

### IntToFloatMap

    public IntToFloatMap(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(int key)

  Calculating the baseHash index using the internal `hashFactor` .

### clear

    public void clear()

  Empties the map. Generates the "Empty" space list for later allocation.

### containsKey

    public boolean containsKey(int 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(float value)

  Checks if the given value exists in the map.
  This method iterates over the collection, trying to find an equal object.

  Parameters:
    `value` - float value that is checked against the map data.
  Returns:
    true if the value exists in the map, false otherwise.

### find

    protected int find(int key)

  Find the actual index of a given key.

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

### get

    public float get(int key)

  Returns the value mapped with the given key.

  Parameters:
    `key` - int who's mapped object we're interested in.
  Returns:
    a float value mapped by the given key. float.NaN if the key wasn't found.

### grow

    protected void grow()

  Grows the map. Allocates a new map of float 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 FloatIterator iterator()

  Returns a new iterator for the mapped float values.

### keyIterator

    public IntIterator keyIterator()

  Returns an iterator on the map keys.

### put

    public float put(int key,
                     float v)

  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 `Float.NaN` if the key didn't exist.

### remove

    public float remove(int key)

  Removes a <key,value> pair from the map and returns the mapped value, or `Float.NaN` if the none existed.

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

### size

    public int size()

  Returns:
    number of pairs currently in the map

### toArray

    public float[] toArray()

  Translates the mapped pairs' values into an array of Objects

  Returns:
    a float array of all the values currently in the map.

### toArray

    public float[] toArray(float[] 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 use whatever space we need, setting the one after the true data as `Float.NaN`.
  Returns:
    an array containing the elements of the list, using the given parameter if big enough, otherwise allocate an appropriate array and return it.

### 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`

Copyright © 2000-2013 Apache Software Foundation. All Rights Reserved.