K - type of keys stored in the Mappublic class Object2LongHashMap<K> extends Object implements Map<K,Long>
Map implementation specialised for long values using open addressing and
linear probing for cache efficient access. The implementation is mirror copy of Long2ObjectHashMap
and it also relies on missing value concept from Long2LongHashMap| Modifier and Type | Class and Description |
|---|---|
class |
Object2LongHashMap.EntryIterator
Iterator over entries which can provide unboxed access and optionally avoid allocation.
|
class |
Object2LongHashMap.EntrySet
Set of entries which can optionally cache iterators to avoid allocation.
|
class |
Object2LongHashMap.KeyIterator
Iterator over keys.
|
class |
Object2LongHashMap.KeySet
Set of keys that can optionally cache iterators to avoid allocation.
|
class |
Object2LongHashMap.ValueCollection
Collection of values which can optionally cache iterators to avoid allocation.
|
class |
Object2LongHashMap.ValueIterator
Iterator over values providing unboxed access via
Object2LongHashMap.ValueIterator.nextLong(). |
| Constructor and Description |
|---|
Object2LongHashMap(int initialCapacity,
float loadFactor,
long missingValue)
Construct a new map allowing a configuration for initial capacity and load factor.
|
Object2LongHashMap(int initialCapacity,
float loadFactor,
long missingValue,
boolean shouldAvoidAllocation)
Construct a new map allowing a configuration for initial capacity and load factor.
|
Object2LongHashMap(long missingValue)
Construct a map with default capacity and load factor.
|
Object2LongHashMap(Object2LongHashMap<K> mapToCopy)
Copy construct a new map from an existing one.
|
| Modifier and Type | Method and Description |
|---|---|
int |
capacity()
Get the total capacity for the map to which the load factor will be a fraction of.
|
void |
clear() |
void |
compact()
Compact the
Map backing arrays by rehashing with a capacity just larger than current size
and giving consideration to the load factor. |
long |
compute(K key,
ObjectLongToLongFunction<? super K> remappingFunction)
Attempts to compute a mapping for the specified key and its current mapped
value (or missingValue if there is no current mapping).
|
long |
computeIfAbsent(K key,
ToLongFunction<? super K> mappingFunction)
Get a value for a given key, or if it does not exist then default the value via a
LongFunction and put it in the map. |
long |
computeIfPresent(K key,
ObjectLongToLongFunction<? super K> remappingFunction)
If the value for the specified key is present, attempts to compute a new
mapping given the key and its current mapped value.
|
boolean |
containsKey(Object key)
Overloaded version of
Map.containsKey(Object) that takes a primitive long key. |
boolean |
containsValue(long value)
Overloaded version to avoid boxing.
|
boolean |
containsValue(Object value) |
Object2LongHashMap.EntrySet |
entrySet() |
boolean |
equals(Object o) |
void |
forEach(BiConsumer<? super K,? super Long> action) |
void |
forEachLong(ObjLongConsumer<? super K> action)
Performs the given action for each entry in this map until all entries have been processed or the action throws
an exception.
|
Long |
get(Object key) |
long |
getOrDefault(Object key,
long defaultValue)
Returns the value to which the specified key is mapped, or
defaultValue if this map contains no mapping
for the key. |
long |
getValue(K key)
Overloaded version of
Map.get(Object) that takes a primitive long key. |
int |
hashCode() |
boolean |
isEmpty() |
Object2LongHashMap.KeySet |
keySet() |
float |
loadFactor()
Get the load factor beyond which the map will increase size.
|
long |
merge(K key,
long value,
LongLongFunction remappingFunction)
If the specified key is not already associated with a value associates it with the given value.
|
long |
missingValue()
The value to be used as a null marker in the map.
|
long |
put(K key,
long value)
Overloaded version of
Map.put(Object, Object) that takes a primitive long key. |
Long |
put(K key,
Long value) |
void |
putAll(Map<? extends K,? extends Long> map) |
void |
putAll(Object2LongHashMap<? extends K> map)
Puts all values from the given map to this map.
|
long |
putIfAbsent(K key,
long value)
If the specified key is not already associated with a value associates it with the given value and returns
missingValue(), else returns the current value. |
Long |
putIfAbsent(K key,
Long value) |
Long |
remove(Object key) |
boolean |
remove(Object key,
long value)
Primitive overload of the
Map.remove(Object, Object) that avoids boxing on the value. |
boolean |
remove(Object key,
Object value) |
long |
removeKey(K key)
Overloaded version of
Map.remove(Object) that takes a key and returns a primitive long value. |
long |
replace(K key,
long value)
Primitive specialised version of
Map.replace(Object, Object) |
boolean |
replace(K key,
long oldValue,
long newValue)
Primitive specialised version of
Map.replace(Object, Object, Object) |
void |
replaceAllLong(ObjectLongToLongFunction<? super K> function)
Primitive specialised version of
Map.replaceAll(BiFunction). |
int |
resizeThreshold()
Get the actual threshold which when reached the map will resize.
|
int |
size() |
String |
toString() |
Object2LongHashMap.ValueCollection |
values() |
clone, finalize, getClass, notify, notifyAll, wait, wait, waitcompute, computeIfAbsent, computeIfPresent, getOrDefault, merge, replace, replace, replaceAllpublic Object2LongHashMap(long missingValue)
missingValue - value to be used as a null maker in the mappublic Object2LongHashMap(int initialCapacity,
float loadFactor,
long missingValue)
initialCapacity - for the backing arrayloadFactor - limit for resizing on putsmissingValue - value to be used as a null marker in the mappublic Object2LongHashMap(int initialCapacity,
float loadFactor,
long missingValue,
boolean shouldAvoidAllocation)
initialCapacity - for the backing arrayloadFactor - limit for resizing on putsmissingValue - value to be used as a null marker in the mapshouldAvoidAllocation - should allocation be avoided by caching iterators and map entries.public Object2LongHashMap(Object2LongHashMap<K> mapToCopy)
mapToCopy - for construction.public long missingValue()
public float loadFactor()
public int capacity()
public int resizeThreshold()
public boolean containsKey(Object key)
Map.containsKey(Object) that takes a primitive long key.containsKey in interface Map<K,Long>key - for indexing the Mappublic boolean containsValue(Object value)
containsValue in interface Map<K,Long>public boolean containsValue(long value)
value - to check.public long getOrDefault(Object key, long defaultValue)
defaultValue if this map contains no mapping
for the key.key - whose associated value is to be returned.defaultValue - the default mapping of the keydefaultValue if this map contains no mapping
for the key.public long getValue(K key)
Map.get(Object) that takes a primitive long key.
Due to type erasure have to rename the methodkey - for indexing the Mappublic long computeIfAbsent(K key, ToLongFunction<? super K> mappingFunction)
LongFunction and put it in the map.
Primitive specialized version of Map.computeIfAbsent(K, java.util.function.Function<? super K, ? extends V>).
key - to search on.mappingFunction - to provide a value if the get returns missingValue.public long computeIfPresent(K key, ObjectLongToLongFunction<? super K> remappingFunction)
If the function returns missingValue, the mapping is removed
Primitive specialized version of Map.computeIfPresent(Object, BiFunction).
key - to search on.remappingFunction - to provide a value if the get returns missingValue.public long compute(K key, ObjectLongToLongFunction<? super K> remappingFunction)
If the function returns missingValue, the mapping is removed (or remains absent if initially absent).
Primitive specialized version of Map.compute(Object, BiFunction).
key - to search on.remappingFunction - to provide a value if the get returns missingValue.public long merge(K key, long value, LongLongFunction remappingFunction)
missingValue(). This method may be of use when combining multiple mapped values for a key. If the
function returns missingValue() the mapping is removed.
Primitive specialized version of Map.merge(Object, Object, BiFunction).
key - with which the resulting value is to be associated.value - to be merged with the existing value associated with the key or, if no existing value
is associated with the key, to be associated with the key.remappingFunction - the function to recompute a value if present.missingValue() if no value is associated
with the key.public long put(K key, long value)
Map.put(Object, Object) that takes a primitive long key.public Long putIfAbsent(K key, Long value)
putIfAbsent in interface Map<K,Long>public long putIfAbsent(K key, long value)
missingValue(), else returns the current value.key - with which the specified value is to be associated.value - to be associated with the specified key.missingValue() if there was no mapping
for the key.IllegalArgumentException - if value == missingValue()public boolean remove(Object key, long value)
Map.remove(Object, Object) that avoids boxing on the value.key - with which the specified value is associated.value - expected to be associated with the specified key.true if the value was removed.public long removeKey(K key)
Map.remove(Object) that takes a key and returns a primitive long value.
Due to type erasure have to rename the methodkey - for indexing the Mappublic void compact()
Map backing arrays by rehashing with a capacity just larger than current size
and giving consideration to the load factor.public void putAll(Object2LongHashMap<? extends K> map)
map - whose values to be added to this map.public Object2LongHashMap.KeySet keySet()
public Object2LongHashMap.ValueCollection values()
public Object2LongHashMap.EntrySet entrySet()
public boolean equals(Object o)
public int hashCode()
public long replace(K key, long value)
Map.replace(Object, Object)key - with which the specified value is associated.value - to be associated with the specified key.missingValue() if there was no mapping
for the key.public boolean replace(K key, long oldValue, long newValue)
Map.replace(Object, Object, Object)key - key with which the specified value is associated.oldValue - value expected to be associated with the specified key.newValue - value to be associated with the specified key.true if the value was replaced.public void replaceAllLong(ObjectLongToLongFunction<? super K> function)
Map.replaceAll(BiFunction).
NB: Renamed from replaceAll to avoid overloading on parameter types of lambda expression, which doesn't play well with type inference in lambda expressions.
function - the function to apply to each entry.public void forEach(BiConsumer<? super K,? super Long> action)
public void forEachLong(ObjLongConsumer<? super K> action)
action - to be performed for each entry.Copyright © 2014-2022 Real Logic Limited. All Rights Reserved.