Package org.btrplace.util
Class IntObjectMap<V>
java.lang.Object
org.btrplace.util.IntObjectMap<V>
public class IntObjectMap<V> extends Object
A map to associate an Object to an element.
The map does not compact the key space so it is very efficient in terms of memory when there is no or a very few
holes. For the best performances, it is also wise to set the capacity as early as possible to bypass the incremental
expansion.
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
IntObjectMap.Entry<V>
Interface used to iterate over the entries. -
Field Summary
Fields Modifier and Type Field Description static int
DEFAULT_SIZE
Default size for the map. -
Constructor Summary
Constructors Constructor Description IntObjectMap()
Empty may withnull
to indicate no value.IntObjectMap(V noValue)
New map.IntObjectMap(V noValue, int size)
New map. -
Method Summary
Modifier and Type Method Description void
clear()
Clear the map.V
clear(int key)
Clear the given key.IntObjectMap<V>
copy()
Returns a copy of the map.boolean
equals(Object o)
void
expand(int newSize)
Expand the map to a new size.void
forEach(IntObjectMap.Entry<V> e)
Iterate over the map entries.V
get(int key)
Get the value for the key.boolean
has(int key)
Check if a key is in the map.int
hashCode()
V
noEntryValue()
Get the value indicating the key is not in the map.V
put(int key, V value)
Put an entry in the map.V
quickGet(int key)
Unsafe version ofget(int)
.int
size()
Get the number of entries in the map.
-
Field Details
-
DEFAULT_SIZE
public static final int DEFAULT_SIZEDefault size for the map.- See Also:
- Constant Field Values
-
-
Constructor Details
-
IntObjectMap
public IntObjectMap()Empty may withnull
to indicate no value. -
IntObjectMap
New map.- Parameters:
noValue
- the value to use to report a missing key.
-
IntObjectMap
New map.- Parameters:
noValue
- the value to use to report a missing key.size
- the backend size.
-
-
Method Details
-
expand
public void expand(int newSize)Expand the map to a new size.- Parameters:
newSize
- the new size for the backend.
-
get
Get the value for the key. If the key is not in,noEntryValue()
is returned.- Parameters:
key
- the key.- Returns:
- the value associated to the key.
noEntryValue()
otherwise.
-
quickGet
Unsafe version ofget(int)
.- Parameters:
key
- the key.- Returns:
- the value.
-
has
public boolean has(int key)Check if a key is in the map.- Parameters:
key
- the key.- Returns:
true
if the key is in the map. This means that the value differs fromnoEntryValue()
.
-
noEntryValue
Get the value indicating the key is not in the map.- Returns:
- the value.
-
put
Put an entry in the map. The map is expanded if needed.- Parameters:
key
- the entry key.value
- the value.
-
copy
Returns a copy of the map. The values associated to the keys are not copied.- Returns:
- a copy.
-
clear
Clear the given key. The value will be set tonoEntryValue()
.- Parameters:
key
- the key.
-
clear
public void clear()Clear the map. -
forEach
Iterate over the map entries. This should not be used for any performance critical computation as the performance will depend on the key density.- Parameters:
e
- the iterator to use.
-
equals
-
hashCode
public int hashCode() -
size
public int size()Get the number of entries in the map.- Returns:
- a positive number.
-