Package org.agrona.collections
Class Object2ObjectHashMap<K,V>
java.lang.Object
org.agrona.collections.Object2ObjectHashMap<K,V>
- Type Parameters:
K- the type of keys maintained by this map.V- the type of mapped values.
- All Implemented Interfaces:
Map<K,V>
- Direct Known Subclasses:
Object2NullableObjectHashMap
An open-addressing with linear probing hash map, same algorithm as
Int2IntHashMap.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionfinal classAn iterator over entries.final classAn entry set implementation.final classAn iterator over keys.final classA key set implementation.final classA collection of values.final classAn iterator over values. -
Constructor Summary
ConstructorsConstructorDescriptionDefault constructor, i.e.Object2ObjectHashMap(int initialCapacity, float loadFactor) Create a map with initial capacity and load factor.Object2ObjectHashMap(int initialCapacity, float loadFactor, boolean shouldAvoidAllocation) Create a new instance with specified parameters.Object2ObjectHashMap(Object2ObjectHashMap<K, V> 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.voidclear()voidcompact()Compact the backing arrays by rehashing with a capacity just larger than current size and giving consideration to the load factor.computeIfAbsent(K key, Function<? super K, ? extends V> mappingFunction) computeIfPresent(K key, BiFunction<? super K, ? super V, ? extends V> remappingFunction) booleancontainsKey(Object key) booleancontainsValue(Object value) Does the map contain the value.entrySet()booleanvoidforEach(BiConsumer<? super K, ? super V> consumer) inthashCode()booleanisEmpty()keySet()floatGet the load factor applied for resize operations.protected ObjectmapNullValue(Object value) Handle incoming null value and optionally replace with another non-null counterpart.Put a key value pair into the map.voidintGet the actual threshold which when reached the map will resize.intsize()toString()protected VunmapNullValue(Object value) Handle incoming non-null value and optionally replace it with the null value counterpart.values()Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Map
getOrDefault, merge, putIfAbsent, remove, replace, replace, replaceAll
-
Constructor Details
-
Object2ObjectHashMap
public Object2ObjectHashMap()Default constructor, i.e. create a map withMIN_CAPACITYandHashing.DEFAULT_LOAD_FACTOR. -
Object2ObjectHashMap
public Object2ObjectHashMap(int initialCapacity, float loadFactor) Create a map with initial capacity and load factor.- Parameters:
initialCapacity- for the map to overrideMIN_CAPACITYloadFactor- for the map to overrideHashing.DEFAULT_LOAD_FACTOR.
-
Object2ObjectHashMap
public Object2ObjectHashMap(int initialCapacity, float loadFactor, boolean shouldAvoidAllocation) Create a new instance with specified parameters.- Parameters:
initialCapacity- for the map to overrideMIN_CAPACITYloadFactor- for the map to overrideHashing.DEFAULT_LOAD_FACTOR.shouldAvoidAllocation- should allocation be avoided by caching iterators and map entries.
-
Object2ObjectHashMap
Copy construct a new map from an existing one.- Parameters:
mapToCopy- for construction.
-
-
Method Details
-
loadFactor
public float loadFactor()Get the load factor applied for resize operations.- Returns:
- the load factor applied for resize operations.
-
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.
-
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.
-
size
public int size() -
isEmpty
public boolean isEmpty() -
get
-
put
Put a key value pair into the map.- Specified by:
putin interfaceMap<K,V> - Parameters:
key- lookup keyvalue- new value, must not be null- Returns:
- current value associated with key, or null if none found
- Throws:
IllegalArgumentException- if value is null
-
containsValue
Does the map contain the value.- Specified by:
containsValuein interfaceMap<K,V> - Parameters:
value- to be tested against contained values.- Returns:
- true if contained otherwise false.
-
clear
public void 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. -
forEach
-
containsKey
- Specified by:
containsKeyin interfaceMap<K,V>
-
putAll
-
keySet
-
values
-
entrySet
-
remove
-
toString
-
equals
-
hashCode
public int hashCode() -
computeIfAbsent
- Specified by:
computeIfAbsentin interfaceMap<K,V>
-
computeIfPresent
- Specified by:
computeIfPresentin interfaceMap<K,V>
-
compute
-
mapNullValue
Handle incoming null value and optionally replace with another non-null counterpart.- Parameters:
value- value to be handled.- Returns:
- replacement value.
-
unmapNullValue
Handle incoming non-null value and optionally replace it with the null value counterpart. This is the opposite of themapNullValue(Object)method.- Parameters:
value- value to be handled.- Returns:
- replacement value.
- See Also:
-