K
- type of keys stored in the Map
public class Object2IntHashMap<K>
extends java.lang.Object
implements java.util.Map<K,java.lang.Integer>, java.io.Serializable
Map
implementation specialised for int values using open addressing and
linear probing for cache efficient access. The implementation is mirror copy of Int2ObjectHashMap
and it also relies on missing value concept from Int2IntHashMap
Modifier and Type | Class and Description |
---|---|
class |
Object2IntHashMap.EntryIterator |
class |
Object2IntHashMap.EntrySet |
class |
Object2IntHashMap.KeyIterator |
class |
Object2IntHashMap.KeySet |
class |
Object2IntHashMap.ValueCollection |
class |
Object2IntHashMap.ValueIterator |
Constructor and Description |
---|
Object2IntHashMap(int missingValue)
Construct a map with default capacity and load factor.
|
Object2IntHashMap(int initialCapacity,
float loadFactor,
int missingValue)
Construct a new map allowing a configuration for initial capacity and load factor.
|
Object2IntHashMap(int initialCapacity,
float loadFactor,
int missingValue,
boolean shouldAvoidAllocation)
Construct a new map allowing a configuration for initial capacity and load factor.
|
Object2IntHashMap(Object2IntHashMap<K> mapToCopy)
Copy construct a new map from an existing one.
|
Modifier and Type | Method and Description |
---|---|
int |
capacity()
Get the total capacity for the map to which the load factor will be a fraction of.
|
void |
clear() |
void |
compact()
Compact the
Map backing arrays by rehashing with a capacity just larger than current size
and giving consideration to the load factor. |
int |
computeIfAbsent(K key,
java.util.function.ToIntFunction<? super K> mappingFunction)
Get a value for a given key, or if it does not exist then default the value via a
IntFunction and put it in the map. |
boolean |
containsKey(java.lang.Object key)
Overloaded version of
Map.containsKey(Object) that takes a primitive int key. |
boolean |
containsValue(int value) |
boolean |
containsValue(java.lang.Object value) |
Object2IntHashMap.EntrySet |
entrySet() |
boolean |
equals(java.lang.Object o) |
java.lang.Integer |
get(java.lang.Object key) |
int |
getValue(K key)
Overloaded version of
Map.get(Object) that takes a primitive int key. |
int |
hashCode() |
boolean |
isEmpty() |
Object2IntHashMap.KeySet |
keySet() |
float |
loadFactor()
Get the load factor beyond which the map will increase size.
|
int |
missingValue()
The value to be used as a null marker in the map.
|
int |
put(K key,
int value)
Overloaded version of
Map.put(Object, Object) that takes a primitive int key. |
java.lang.Integer |
put(K key,
java.lang.Integer value) |
void |
putAll(java.util.Map<? extends K,? extends java.lang.Integer> map) |
java.lang.Integer |
remove(java.lang.Object key) |
int |
removeKey(K key)
Overloaded version of
Map.remove(Object) that takes a primitive int key. |
int |
replace(K key,
int value)
Primitive specialised version of
Map.replace(Object, Object) |
boolean |
replace(K key,
int oldValue,
int newValue)
Primitive specialised version of
Map.replace(Object, Object, Object) |
int |
resizeThreshold()
Get the actual threshold which when reached the map will resize.
|
int |
size() |
java.lang.String |
toString() |
Object2IntHashMap.ValueCollection |
values() |
public Object2IntHashMap(int missingValue)
missingValue
- value to be used as a null maker in the mappublic Object2IntHashMap(int initialCapacity, float loadFactor, int missingValue)
initialCapacity
- for the backing arrayloadFactor
- limit for resizing on putsmissingValue
- value to be used as a null marker in the mappublic Object2IntHashMap(int initialCapacity, float loadFactor, int missingValue, boolean shouldAvoidAllocation)
initialCapacity
- for the backing arrayloadFactor
- limit for resizing on putsmissingValue
- value to be used as a null marker in the mapshouldAvoidAllocation
- should allocation be avoided by caching iterators and map entries.public Object2IntHashMap(Object2IntHashMap<K> mapToCopy)
mapToCopy
- for construction.public int missingValue()
public float loadFactor()
public int capacity()
public int resizeThreshold()
public int size()
size
in interface java.util.Map<K,java.lang.Integer>
public boolean isEmpty()
isEmpty
in interface java.util.Map<K,java.lang.Integer>
public boolean containsKey(java.lang.Object key)
Map.containsKey(Object)
that takes a primitive int key.containsKey
in interface java.util.Map<K,java.lang.Integer>
key
- for indexing the Map
public boolean containsValue(java.lang.Object value)
containsValue
in interface java.util.Map<K,java.lang.Integer>
public boolean containsValue(int value)
public java.lang.Integer get(java.lang.Object key)
get
in interface java.util.Map<K,java.lang.Integer>
public int getValue(K key)
Map.get(Object)
that takes a primitive int key.
Due to type erasure have to rename the methodkey
- for indexing the Map
public int computeIfAbsent(K key, java.util.function.ToIntFunction<? super K> mappingFunction)
IntFunction
and put it in the map.
Primitive specialized version of Map.computeIfAbsent(K, java.util.function.Function<? super K, ? extends V>)
.
key
- to search on.mappingFunction
- to provide a value if the get returns missingValue.public java.lang.Integer put(K key, java.lang.Integer value)
put
in interface java.util.Map<K,java.lang.Integer>
public int put(K key, int value)
Map.put(Object, Object)
that takes a primitive int key.key
- for indexing the Map
value
- to be inserted in the Map
public java.lang.Integer remove(java.lang.Object key)
remove
in interface java.util.Map<K,java.lang.Integer>
public int removeKey(K key)
Map.remove(Object)
that takes a primitive int key.
Due to type erasure have to rename the methodkey
- for indexing the Map
public void clear()
clear
in interface java.util.Map<K,java.lang.Integer>
public void compact()
Map
backing arrays by rehashing with a capacity just larger than current size
and giving consideration to the load factor.public void putAll(java.util.Map<? extends K,? extends java.lang.Integer> map)
putAll
in interface java.util.Map<K,java.lang.Integer>
public Object2IntHashMap.KeySet keySet()
keySet
in interface java.util.Map<K,java.lang.Integer>
public Object2IntHashMap.ValueCollection values()
values
in interface java.util.Map<K,java.lang.Integer>
public Object2IntHashMap.EntrySet entrySet()
entrySet
in interface java.util.Map<K,java.lang.Integer>
public java.lang.String toString()
toString
in class java.lang.Object
public boolean equals(java.lang.Object o)
equals
in interface java.util.Map<K,java.lang.Integer>
equals
in class java.lang.Object
public int hashCode()
hashCode
in interface java.util.Map<K,java.lang.Integer>
hashCode
in class java.lang.Object
public int replace(K key, int value)
Map.replace(Object, Object)
key
- key with which the specified value is associatedvalue
- value to be associated with the specified keynull
if there was no mapping for the key.public boolean replace(K key, int oldValue, int newValue)
Map.replace(Object, Object, Object)
key
- key with which the specified value is associatedoldValue
- value expected to be associated with the specified keynewValue
- value to be associated with the specified keytrue
if the value was replacedCopyright © 2014-2019 Real Logic Ltd. All Rights Reserved.