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 TypeClassDescription(package private) classBase iterator impl.final 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. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate Object[]private Object2ObjectHashMap<K,V>.EntrySet private Object2ObjectHashMap<K,V>.KeySet private final float(package private) static final intprivate intprivate final booleanprivate intprivate Object2ObjectHashMap<K,V>.ValueCollection -
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.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) 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) private VinthashCode()private voidbooleanisEmpty()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.private static intnext(int index, int mask) Put a key value pair into the map.voidprivate voidrehash(int newCapacity) intGet 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 interface Map
getOrDefault, merge, putIfAbsent, remove, replace, replace, replaceAll
-
Field Details
-
MIN_CAPACITY
static final int MIN_CAPACITY- See Also:
-
loadFactor
private final float loadFactor -
resizeThreshold
private int resizeThreshold -
size
private int size -
shouldAvoidAllocation
private final boolean shouldAvoidAllocation -
entries
-
keySet
-
valueCollection
-
entrySet
-
-
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
-
isEmpty
-
get
-
getMapped
-
put
-
increaseCapacity
private void increaseCapacity() -
rehash
private void rehash(int newCapacity) -
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
-
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
-
compactChain
private void compactChain(int deleteKeyIndex) -
toString
-
equals
-
hashCode
-
computeIfAbsent
-
computeIfPresent
- Specified by:
computeIfPresentin interfaceMap<K,V>
-
compute
-
mapNullValue
-
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:
-
next
private static int next(int index, int mask) -
capacity
private void capacity(int newCapacity)
-