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 TypeClassDescription(package private) class
Base iterator impl.final class
An iterator over entries.final class
An entry set implementation.final class
An iterator over keys.final class
A key set implementation.final class
A collection of values.final class
An 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 int
private int
private final boolean
private int
private 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 TypeMethodDescriptionint
capacity()
Get the total capacity for the map to which the load factor will be a fraction of.private void
capacity
(int newCapacity) void
clear()
void
compact()
Compact the backing arrays by rehashing with a capacity just larger than current size and giving consideration to the load factor.private void
compactChain
(int deleteKeyIndex) computeIfAbsent
(K key, Function<? super K, ? extends V> mappingFunction) computeIfPresent
(K key, BiFunction<? super K, ? super V, ? extends V> remappingFunction) boolean
containsKey
(Object key) boolean
containsValue
(Object value) Does the map contain the value.entrySet()
boolean
void
forEach
(BiConsumer<? super K, ? super V> consumer) private V
int
hashCode()
private void
boolean
isEmpty()
keySet()
float
Get the load factor applied for resize operations.protected Object
mapNullValue
(Object value) Handle incoming null value and optionally replace with another non-null counterpart.private static int
next
(int index, int mask) Put a key value pair into the map.void
private void
rehash
(int newCapacity) int
Get the actual threshold which when reached the map will resize.int
size()
toString()
protected V
unmapNullValue
(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, wait
Methods inherited from interface java.util.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_CAPACITY
andHashing.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_CAPACITY
loadFactor
- 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_CAPACITY
loadFactor
- 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
-
getMapped
-
put
Put a key value pair into the map.- Specified by:
put
in 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
-
increaseCapacity
private void increaseCapacity() -
rehash
private void rehash(int newCapacity) -
containsValue
Does the map contain the value.- Specified by:
containsValue
in 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:
containsKey
in interfaceMap<K,
V>
-
putAll
-
keySet
-
values
-
entrySet
-
remove
-
compactChain
private void compactChain(int deleteKeyIndex) -
toString
-
equals
-
hashCode
public int hashCode() -
computeIfAbsent
- Specified by:
computeIfAbsent
in interfaceMap<K,
V>
-
computeIfPresent
- Specified by:
computeIfPresent
in 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:
-
next
private static int next(int index, int mask) -
capacity
private void capacity(int newCapacity)
-