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:
java.util.Map<K,V>
- Direct Known Subclasses:
Object2NullableObjectHashMap
public class Object2ObjectHashMap<K,V> extends java.lang.Object implements java.util.Map<K,V>
An open-addressing with linear probing hash map, same algorithm asInt2IntHashMap
.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) class
Object2ObjectHashMap.AbstractIterator
Base iterator impl.class
Object2ObjectHashMap.EntryIterator
An iterator over entries.class
Object2ObjectHashMap.EntrySet
An entry set implementation.class
Object2ObjectHashMap.KeyIterator
An iterator over keys.class
Object2ObjectHashMap.KeySet
A key set implementation.class
Object2ObjectHashMap.ValueCollection
A collection of values.class
Object2ObjectHashMap.ValueIterator
An iterator over values.
-
Field Summary
Fields Modifier and Type Field Description private java.lang.Object[]
entries
private Object2ObjectHashMap.EntrySet
entrySet
private Object2ObjectHashMap.KeySet
keySet
private float
loadFactor
(package private) static int
MIN_CAPACITY
private int
resizeThreshold
private boolean
shouldAvoidAllocation
private int
size
private Object2ObjectHashMap.ValueCollection
valueCollection
-
Constructor Summary
Constructors Constructor Description Object2ObjectHashMap()
Default 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
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description int
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)
V
compute(K key, java.util.function.BiFunction<? super K,? super V,? extends V> remappingFunction)
V
computeIfAbsent(K key, java.util.function.Function<? super K,? extends V> mappingFunction)
V
computeIfPresent(K key, java.util.function.BiFunction<? super K,? super V,? extends V> remappingFunction)
boolean
containsKey(java.lang.Object key)
boolean
containsValue(java.lang.Object value)
Does the map contain the value.Object2ObjectHashMap.EntrySet
entrySet()
boolean
equals(java.lang.Object o)
void
forEach(java.util.function.BiConsumer<? super K,? super V> consumer)
V
get(java.lang.Object key)
private V
getMapped(java.lang.Object key)
int
hashCode()
private void
increaseCapacity()
boolean
isEmpty()
Object2ObjectHashMap.KeySet
keySet()
float
loadFactor()
Get the load factor applied for resize operations.protected java.lang.Object
mapNullValue(java.lang.Object value)
Handle incoming null value and optionally replace with another non-null counterpart.private static int
next(int index, int mask)
V
put(K key, V value)
Put a key value pair into the map.void
putAll(java.util.Map<? extends K,? extends V> map)
private void
rehash(int newCapacity)
V
remove(java.lang.Object key)
int
resizeThreshold()
Get the actual threshold which when reached the map will resize.int
size()
java.lang.String
toString()
protected V
unmapNullValue(java.lang.Object value)
Handle incoming non-null value and optionally replace it with the null value counterpart.Object2ObjectHashMap.ValueCollection
values()
-
-
-
Field Detail
-
MIN_CAPACITY
static final int MIN_CAPACITY
- See Also:
- Constant Field Values
-
loadFactor
private final float loadFactor
-
resizeThreshold
private int resizeThreshold
-
size
private int size
-
shouldAvoidAllocation
private final boolean shouldAvoidAllocation
-
entries
private java.lang.Object[] entries
-
keySet
private Object2ObjectHashMap.KeySet keySet
-
valueCollection
private Object2ObjectHashMap.ValueCollection valueCollection
-
entrySet
private Object2ObjectHashMap.EntrySet entrySet
-
-
Constructor Detail
-
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
public Object2ObjectHashMap(Object2ObjectHashMap<K,V> mapToCopy)
Copy construct a new map from an existing one.- Parameters:
mapToCopy
- for construction.
-
-
Method Detail
-
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.
-
getMapped
private V getMapped(java.lang.Object key)
-
increaseCapacity
private void increaseCapacity()
-
rehash
private void rehash(int newCapacity)
-
containsValue
public boolean containsValue(java.lang.Object value)
Does the map contain the value.
-
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.
-
containsKey
public boolean containsKey(java.lang.Object key)
-
keySet
public Object2ObjectHashMap.KeySet keySet()
-
values
public Object2ObjectHashMap.ValueCollection values()
-
entrySet
public Object2ObjectHashMap.EntrySet entrySet()
-
compactChain
private void compactChain(int deleteKeyIndex)
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
equals
public boolean equals(java.lang.Object o)
-
hashCode
public int hashCode()
-
computeIfAbsent
public V computeIfAbsent(K key, java.util.function.Function<? super K,? extends V> mappingFunction)
-
computeIfPresent
public V computeIfPresent(K key, java.util.function.BiFunction<? super K,? super V,? extends V> remappingFunction)
-
compute
public V compute(K key, java.util.function.BiFunction<? super K,? super V,? extends V> remappingFunction)
-
mapNullValue
protected java.lang.Object mapNullValue(java.lang.Object value)
Handle incoming null value and optionally replace with another non-null counterpart.- Parameters:
value
- value to be handled.- Returns:
- replacement value.
-
unmapNullValue
protected V unmapNullValue(java.lang.Object value)
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:
mapNullValue(Object)
-
next
private static int next(int index, int mask)
-
capacity
private void capacity(int newCapacity)
-
-