Package org.agrona.collections
Class BiInt2ObjectMap<V>
java.lang.Object
org.agrona.collections.BiInt2ObjectMap<V>
- Type Parameters:
V- type of the object stored in the map.
- Direct Known Subclasses:
BiInt2NullableObjectMap
Map that takes two part int key and associates with an object.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceHandler for a map entry.static interfaceCreates a new value based upon keys.static interfaceCreates a new value based upon keys. -
Constructor Summary
ConstructorsConstructorDescriptionConstruct an empty map.BiInt2ObjectMap(int initialCapacity, float loadFactor) Construct a map that sets it initial capacity and load factor. -
Method Summary
Modifier and TypeMethodDescriptionintcapacity()Get the total capacity for the map to which the load factor with be a fraction of.voidclear()Clear out the map of all entries.voidcompact()Compact the backing arrays by rehashing with a capacity just larger than current size and giving consideration to the load factor.compute(int keyPartA, int keyPartB, BiInt2ObjectMap.EntryRemap<? super V, ? extends V> remappingFunction) Attempts to compute a mapping for the specified key and its current mapped value (or null if there is no current mapping).computeIfAbsent(int keyPartA, int keyPartB, BiInt2ObjectMap.EntryFunction<? extends V> mappingFunction) If the specified key is not already associated with a value (or is mapped tonull), attempts to compute its value using the given mapping function and enters it into this map unlessnull.computeIfPresent(int keyPartA, int keyPartB, BiInt2ObjectMap.EntryRemap<? super V, ? extends V> remappingFunction) If the value for the specified key is present and non-null, attempts to compute a new mapping given the key and its current mapped value.booleancontainsKey(int keyPartA, int keyPartB) Returns true if this map contains a mapping for the specified key.voidIterate over the contents of the map.voidforEach(BiInt2ObjectMap.EntryConsumer<V> consumer) Iterate over the contents of the map.get(int keyPartA, int keyPartB) Retrieve a value from the map.getOrDefault(int keyPartA, int keyPartB, V defaultValue) Retrieve a value from the map ordefaultValueif this map contains not mapping for the key.booleanisEmpty()Is map empty or not.floatGet the load factor beyond which the map will increase size.protected ObjectmapNullValue(Object value) Interceptor for masking null values.merge(int keyPartA, int keyPartB, V value, BiFunction<? super V, ? super V, ? extends V> remappingFunction) If the specified key is not already associated with a value or is associated with null, associates it with the given non-null value.Put a value into the map.putIfAbsent(int keyPartA, int keyPartB, V value) If the specified key is not already associated with a value (or is mapped to null) associates it with the given value and returns null, else returns the current value.remove(int keyPartA, int keyPartB) Remove a value from the map and return the value.booleanRemoves the entry for the specified key only if it is currently mapped to the specified value.Replaces the entry for the specified key only if currently mapped to the specified value.booleanReplaces the entry for the specified key only if currently mapped to the specified value.intGet the actual threshold which when reached the map will resize.intsize()Return the number of unique entries in the map.toString()protected VunmapNullValue(Object value) Interceptor for unmasking null values.
-
Constructor Details
-
BiInt2ObjectMap
public BiInt2ObjectMap()Construct an empty map. -
BiInt2ObjectMap
public BiInt2ObjectMap(int initialCapacity, float loadFactor) Construct a map that sets it initial capacity and load factor.- Parameters:
initialCapacity- for the underlying hash map.loadFactor- for the underlying hash map.
-
-
Method Details
-
capacity
public int capacity()Get the total capacity for the map to which the load factor with be a fraction of.- Returns:
- the total capacity for the map.
-
loadFactor
public float loadFactor()Get the load factor beyond which the map will increase size.- Returns:
- load factor for when the map should increase size.
-
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.
-
clear
public void clear()Clear out the map of all entries.- See Also:
-
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. -
put
Put a value into the map.- Parameters:
keyPartA- for the key.keyPartB- for the key.value- to put into the map.- Returns:
- the previous value if found otherwise null.
- See Also:
-
mapNullValue
Interceptor for masking null values.- Parameters:
value- value to mask.- Returns:
- masked value.
-
unmapNullValue
Interceptor for unmasking null values.- Parameters:
value- value to unmask.- Returns:
- unmasked value.
-
get
Retrieve a value from the map.- Parameters:
keyPartA- for the key.keyPartB- for the key.- Returns:
- value matching the key if found or null if not found.
- See Also:
-
getOrDefault
Retrieve a value from the map ordefaultValueif this map contains not mapping for the key.- Parameters:
keyPartA- for the key.keyPartB- for the key.defaultValue- the default mapping of the key.- Returns:
- value matching the key if found or
defaultValueif not found. - See Also:
-
containsKey
public boolean containsKey(int keyPartA, int keyPartB) Returns true if this map contains a mapping for the specified key.- Parameters:
keyPartA- for the key.keyPartB- for the key.- Returns:
trueif this map contains a mapping for the specified key- See Also:
-
remove
Remove a value from the map and return the value.- Parameters:
keyPartA- for the key.keyPartB- for the key.- Returns:
- the previous value if found otherwise null
- See Also:
-
computeIfAbsent
public V computeIfAbsent(int keyPartA, int keyPartB, BiInt2ObjectMap.EntryFunction<? extends V> mappingFunction) If the specified key is not already associated with a value (or is mapped tonull), attempts to compute its value using the given mapping function and enters it into this map unlessnull.- Parameters:
keyPartA- for the key.keyPartB- for the key.mappingFunction- creates values based upon keys if the key pair is missing.- Returns:
- the newly created or stored value.
- See Also:
-
computeIfPresent
public V computeIfPresent(int keyPartA, int keyPartB, BiInt2ObjectMap.EntryRemap<? super V, ? extends V> remappingFunction) If the value for the specified key is present and non-null, attempts to compute a new mapping given the key and its current mapped value.If the function returns null, the mapping is removed. If the function itself throws an (unchecked) exception, the exception is rethrown, and the current mapping is left unchanged.
- Parameters:
keyPartA- for the key.keyPartB- for the key.remappingFunction- the function to compute a value.- Returns:
- the new value associated with the specified key, or null if none.
- See Also:
-
compute
public V compute(int keyPartA, int keyPartB, BiInt2ObjectMap.EntryRemap<? super V, ? extends V> remappingFunction) Attempts to compute a mapping for the specified key and its current mapped value (or null if there is no current mapping).- Parameters:
keyPartA- for the key.keyPartB- for the key.remappingFunction- the function to compute a value.- Returns:
- the new value associated with the specified key, or null if none.
- See Also:
-
merge
public V merge(int keyPartA, int keyPartB, V value, BiFunction<? super V, ? super V, ? extends V> remappingFunction) If the specified key is not already associated with a value or is associated with null, associates it with the given non-null value. Otherwise, replaces the associated value with the results of the given remapping function, or removes if the result is null.- Parameters:
keyPartA- for the key.keyPartB- for the key.value- the non-null 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 null if no value is associated with the key.
- See Also:
-
forEach
Iterate over the contents of the map.- Parameters:
consumer- to apply to each value in the map.
-
forEach
Iterate over the contents of the map.- Parameters:
consumer- to apply to each value in the map.
-
replace
Replaces the entry for the specified key only if currently mapped to the specified value.- Parameters:
keyPartA- for the key.keyPartB- for the key.value- value to be associated with the specified key.- Returns:
- the previous value associated with the specified key, or null if there was no mapping for the key. A null return can also indicate that the map previously associated null with the key, if the implementation supports null values.
- See Also:
-
replace
Replaces the entry for the specified key only if currently mapped to the specified value.- Parameters:
keyPartA- for the key.keyPartB- for the key.oldValue- value expected to be associated with the specified key.newValue- to be associated with the specified key.- Returns:
- true if the value was replaced.
-
putIfAbsent
If the specified key is not already associated with a value (or is mapped to null) associates it with the given value and returns null, else returns the current value.- Parameters:
keyPartA- for the key.keyPartB- for the key.value- to put into the map.- Returns:
- the previous value if found otherwise null.
-
remove
Removes the entry for the specified key only if it is currently mapped to the specified value.- Parameters:
keyPartA- for the key.keyPartB- for the key.value- value expected to be associated with the specified key.- Returns:
- true if the value was removed.
- See Also:
-
size
public int size()Return the number of unique entries in the map.- Returns:
- number of unique entries in the map.
-
isEmpty
public boolean isEmpty()Is map empty or not.- Returns:
- boolean indicating empty map or not.
-
toString
-