Class IntToIntMap
- java.lang.Object
-
- org.apache.lucene.util.collections.IntToIntMap
-
public class IntToIntMap extends Object
An Array-based hashtable which maps primitive int to primitive int.
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
Fields Modifier and Type Field Description static int
GROUD
-
Constructor Summary
Constructors Constructor Description IntToIntMap()
Constructs a map with default capacity.IntToIntMap(int capacity)
Constructs a map with given capacity.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected int
calcBaseHashIndex(int key)
Calculating the baseHash index using the internalhashFactor
.void
clear()
Empties the map.boolean
containsKey(int key)
Checks if a given key exists in the map.boolean
containsValue(int v)
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(int key)
Find the actual index of a given key.int
get(int key)
Returns the object mapped with the given key.protected void
grow()
Grows the map.int
hashCode()
boolean
isEmpty()
IntIterator
iterator()
Returns a new iterator for the mapped objects.IntIterator
keyIterator()
Returns an iterator on the map keys.int
put(int key, int e)
Inserts the <key,value> pair into the map.int
remove(int key)
Removes a <key,value> pair from the map and returns the mapped value, or 0 if the none existed.int
size()
int[]
toArray()
Translates the mapped pairs' values into an array of Objectsint[]
toArray(int[] a)
Translates the mapped pairs' values into an array of intsString
toString()
-
-
-
Field Detail
-
GROUD
public static final int GROUD
- See Also:
- Constant Field Values
-
-
Method Detail
-
calcBaseHashIndex
protected int calcBaseHashIndex(int key)
Calculating the baseHash index using the internalhashFactor
.- Parameters:
key
-
-
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(int v)
Checks if the given object exists in the map.
This method iterates over the collection, trying to find an equal object.- Parameters:
v
- value that is checked against the map data.- Returns:
- true if the value exists in the map (in .equals() meaning). false otherwise.
-
find
protected int find(int 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 int get(int 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 IntIterator iterator()
Returns a new iterator for the mapped objects.
-
keyIterator
public IntIterator keyIterator()
Returns an iterator on the map keys.
-
put
public int put(int key, int 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 0 if the key didn't exist.
-
remove
public int remove(int key)
Removes a <key,value> pair from the map and returns the mapped value, or 0 if the none existed.- Parameters:
key
- used to find the value to remove- Returns:
- the removed value or 0 if none existed.
-
size
public int size()
- Returns:
- number of pairs currently in the map
-
toArray
public int[] 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 int[] toArray(int[] a)
Translates the mapped pairs' values into an array of ints- Parameters:
a
- the array into which the elements of the map are to be stored, if it is big enough; otherwise, a new array of the same runtime type is allocated for this purpose.- Returns:
- an array containing the values stored in the map
-
-