Class Int2IntHashMap
java.lang.Object
org.agrona.collections.Int2IntHashMap
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) classBase iterator implementation.final classIterator over entries which supports access to unboxed keys and values.final classSet of entries which supports optionally cached iterators to avoid allocation.final classIterator over keys which supports access to unboxed keys viaInt2IntHashMap.KeyIterator.nextValue().final classSet of keys which supports optional cached iterators to avoid allocation.final classCollection of values which supports optionally cached iterators to avoid allocation.final classIterator over values which supports access to unboxed values. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate int[]private Int2IntHashMap.EntrySetprivate Int2IntHashMap.KeySetprivate final float(package private) static final intprivate final intprivate intprivate final booleanprivate intprivate Int2IntHashMap.ValueCollection -
Constructor Summary
ConstructorsConstructorDescriptionInt2IntHashMap(int missingValue) Create a map instance that does not allocate iterators with a specifiedmissingValue.Int2IntHashMap(int initialCapacity, float loadFactor, int missingValue) Create a map instance that does not allocate iterators with specified parameters.Int2IntHashMap(int initialCapacity, float loadFactor, int missingValue, boolean shouldAvoidAllocation) Create a map instance with specified parameters.Int2IntHashMap(Int2IntHashMap mapToCopy) Copy construct a new map from an existing one. -
Method Summary
Modifier and TypeMethodDescriptionintcapacity()Get the total capacity for the map to which the load factor will be a fraction of.private voidcapacity(int newCapacity) voidclear()voidcompact()Compact the backing arrays by rehashing with a capacity just larger than current size and giving consideration to the load factor.private voidcompactChain(int deleteKeyIndex) intcompute(int key, IntBinaryOperator remappingFunction) Primitive specialised version ofMap.compute(Object, BiFunction).intcomputeIfAbsent(int key, IntUnaryOperator mappingFunction) Primitive specialised version ofMap.computeIfAbsent(Object, Function).intcomputeIfPresent(int key, IntBinaryOperator remappingFunction) Primitive specialised version ofMap.computeIfPresent(Object, BiFunction).booleancontainsKey(int key) Int primitive specialised containsKey.booleancontainsKey(Object key) booleancontainsValue(int value) Does the map contain the value.booleancontainsValue(Object value) entrySet()booleanvoidforEach(BiConsumer<? super Integer, ? super Integer> action) voidforEachInt(IntIntConsumer consumer) Primitive specialised forEach implementation.intget(int key) Get a value using provided key avoiding boxing.intgetOrDefault(int key, int defaultValue) Returns the value to which the specified key is mapped, ordefaultValueif this map contains no mapping for the key.inthashCode()private voidvoidintForEach(IntIntConsumer consumer) Deprecated.booleanisEmpty()keySet()floatGet the load factor applied for resize operations.intmaxValue()Get the maximum value stored in the map.intmerge(int key, int value, IntIntFunction remappingFunction) Primitive specialised version ofMap.merge(Object, Object, BiFunction).intminValue()Get the minimum value stored in the map.intThe value to be used as a null marker in the map.private static intnext(int index, int mask) intput(int key, int value) Put a key value pair in the map.voidvoidputAll(Int2IntHashMap map) Put all values from the given map into this map without allocation.intputIfAbsent(int key, int value) Primitive specialised version ofMap.putIfAbsent(Object, Object)method.putIfAbsent(Integer key, Integer value) private voidrehash(int newCapacity) intremove(int key) Remove value from the map using given key avoiding boxing.booleanremove(int key, int value) Primitive specialised version ofMap.remove(Object, Object).booleanintreplace(int key, int value) Primitive specialised version ofMap.replace(Object, Object).booleanreplace(int key, int oldValue, int newValue) Primitive specialised version ofMap.replace(Object, Object, Object).booleanvoidreplaceAll(BiFunction<? super Integer, ? super Integer, ? extends Integer> function) voidreplaceAllInt(IntIntFunction function) Primitive specialised version ofMap.replaceAll(BiFunction).intGet the actual threshold which when reached the map will resize.intsize()toString()private IntegervalOrNull(int value) values()Methods inherited from interface Map
compute, computeIfAbsent, computeIfPresent, getOrDefault, merge
-
Field Details
-
MIN_CAPACITY
static final int MIN_CAPACITY- See Also:
-
loadFactor
private final float loadFactor -
missingValue
private final int missingValue -
resizeThreshold
private int resizeThreshold -
size
private int size -
shouldAvoidAllocation
private final boolean shouldAvoidAllocation -
entries
private int[] entries -
keySet
-
values
-
entrySet
-
-
Constructor Details
-
Int2IntHashMap
public Int2IntHashMap(int missingValue) Create a map instance that does not allocate iterators with a specifiedmissingValue.- Parameters:
missingValue- for the map that represents null.
-
Int2IntHashMap
public Int2IntHashMap(int initialCapacity, float loadFactor, int missingValue) Create a map instance that does not allocate iterators with specified parameters.- Parameters:
initialCapacity- for the map to overrideMIN_CAPACITYloadFactor- for the map to overrideHashing.DEFAULT_LOAD_FACTOR.missingValue- for the map that represents null.
-
Int2IntHashMap
public Int2IntHashMap(int initialCapacity, float loadFactor, int missingValue, boolean shouldAvoidAllocation) Create a map instance with specified parameters.- Parameters:
initialCapacity- for the map to overrideMIN_CAPACITYloadFactor- for the map to overrideHashing.DEFAULT_LOAD_FACTOR.missingValue- for the map that represents null.shouldAvoidAllocation- should allocation be avoided by caching iterators and map entries.
-
Int2IntHashMap
Copy construct a new map from an existing one.- Parameters:
mapToCopy- for construction.
-
-
Method Details
-
missingValue
public int missingValue()The value to be used as a null marker in the map.- Returns:
- value to be used as a null marker in the map.
-
loadFactor
public float loadFactor()Get the load factor applied for resize operations.- Returns:
- the load factor applied for resize operations.
-
capacity
public int capacity()Get the total capacity for the map to which the load factor will be a fraction of.- Returns:
- the total capacity for the map.
-
resizeThreshold
public int resizeThreshold()Get the actual threshold which when reached the map will resize. This is a function of the current capacity and load factor.- Returns:
- the threshold when the map will resize.
-
size
-
isEmpty
-
getOrDefault
public int getOrDefault(int key, int defaultValue) Returns the value to which the specified key is mapped, ordefaultValueif this map contains no mapping for the key.- Parameters:
key- whose associated value is to be returned.defaultValue- to be returned if there is no value in the map for a givenkey.- Returns:
- the value to which the specified key is mapped, or
defaultValueif this map contains no mapping for the key.
-
get
public int get(int key) Get a value using provided key avoiding boxing.- Parameters:
key- lookup key.- Returns:
- value associated with the key or
missingValue()if key is not found in the map.
-
put
public int put(int key, int value) Put a key value pair in the map.- Parameters:
key- lookup keyvalue- new value, must not bemissingValue()- Returns:
- previous value associated with the key, or
missingValue()if none found - Throws:
IllegalArgumentException- if value ismissingValue()
-
putIfAbsent
public int putIfAbsent(int key, int value) Primitive specialised version ofMap.putIfAbsent(Object, Object)method.- Parameters:
key- key with which the specified value is to be associatedvalue- value to be associated with the specified key- Returns:
- the previous value associated with the specified key, or
missingValue()if there was no mapping for the key. - Throws:
IllegalArgumentException- if value ismissingValue()
-
increaseCapacity
private void increaseCapacity() -
rehash
private void rehash(int newCapacity) -
intForEach
Deprecated.UseforEachInt(IntIntConsumer)instead.UseforEachInt(IntIntConsumer)instead.- Parameters:
consumer- a callback called for each key/value pair in the map.- See Also:
-
forEachInt
Primitive specialised forEach implementation.NB: Renamed from forEach to avoid overloading on parameter types of lambda expression, which doesn't play well with type inference in lambda expressions.
- Parameters:
consumer- a callback called for each key/value pair in the map.
-
containsKey
public boolean containsKey(int key) Int primitive specialised containsKey.- Parameters:
key- the key to check.- Returns:
- true if the map contains key as a key, false otherwise.
-
containsValue
public boolean containsValue(int value) Does the map contain the value.- Parameters:
value- to be tested against contained values.- Returns:
- true if contained otherwise value.
-
clear
-
compact
public void compact()Compact the backing arrays by rehashing with a capacity just larger than current size and giving consideration to the load factor. -
computeIfAbsent
Primitive specialised version ofMap.computeIfAbsent(Object, Function).- Parameters:
key- to search on.mappingFunction- to provide a value if the get returns null.- Returns:
- the value if found otherwise the missing value.
-
computeIfPresent
Primitive specialised version ofMap.computeIfPresent(Object, BiFunction).- Parameters:
key- to search on.remappingFunction- to compute a value if a mapping is found.- Returns:
- the updated value if a mapping was found, otherwise the missing value.
-
compute
Primitive specialised version ofMap.compute(Object, BiFunction).- Parameters:
key- to search on.remappingFunction- to compute a value.- Returns:
- the updated value.
-
get
-
put
-
forEach
-
containsKey
- Specified by:
containsKeyin interfaceMap<Integer,Integer>
-
containsValue
- Specified by:
containsValuein interfaceMap<Integer,Integer>
-
putAll
-
putAll
Put all values from the given map into this map without allocation.- Parameters:
map- whose value are to be added.
-
putIfAbsent
-
replace
-
replace
-
replaceAll
- Specified by:
replaceAllin interfaceMap<Integer,Integer>
-
keySet
-
values
-
entrySet
-
remove
-
remove
-
remove
public int remove(int key) Remove value from the map using given key avoiding boxing.- Parameters:
key- whose mapping is to be removed from the map.- Returns:
- removed value or
missingValue()if key was not found in the map.
-
remove
public boolean remove(int key, int value) Primitive specialised version ofMap.remove(Object, Object).- Parameters:
key- with which the specified value is associated.value- expected to be associated with the specified key.- Returns:
trueif the value was removed.
-
merge
Primitive specialised version ofMap.merge(Object, Object, BiFunction).- Parameters:
key- with which the resulting value is to be associated.value- to be merged with the existing value associated with the key or, if no existing value or a null value is associated with the key, to be associated with the key.remappingFunction- the function to recompute a value if present.- Returns:
- the new value associated with the specified key, or
missingValue()if no value is associated with the key as the result of this operation.
-
compactChain
private void compactChain(int deleteKeyIndex) -
minValue
public int minValue()Get the minimum value stored in the map. If the map is empty then it will returnmissingValue().- Returns:
- the minimum value stored in the map.
-
maxValue
public int maxValue()Get the maximum value stored in the map. If the map is empty then it will returnmissingValue().- Returns:
- the maximum value stored in the map.
-
toString
-
replace
public int replace(int key, int value) Primitive specialised version ofMap.replace(Object, Object).- Parameters:
key- key with which the specified value is associated.value- value to be associated with the specified key.- Returns:
- the previous value associated with the specified key, or
missingValue()if there was no mapping for the key.
-
replace
public boolean replace(int key, int oldValue, int newValue) Primitive specialised version ofMap.replace(Object, Object, Object).- Parameters:
key- key with which the specified value is associated.oldValue- value expected to be associated with the specified key.newValue- value to be associated with the specified key.- Returns:
trueif the value was replaced.
-
replaceAllInt
Primitive specialised version ofMap.replaceAll(BiFunction).NB: Renamed from replaceAll to avoid overloading on parameter types of lambda expression, which doesn't play well with type inference in lambda expressions.
- Parameters:
function- to apply to each entry.
-
equals
-
hashCode
-
next
private static int next(int index, int mask) -
capacity
private void capacity(int newCapacity) -
valOrNull
-
forEachInt(IntIntConsumer)instead.