Package org.dellroad.stuff.util
Class LongMap<V>
- All Implemented Interfaces:
Serializable,Cloneable,Map<Long,V>
A map with non-zero
long keys.
This implementation uses long[] arrays and open addressing to minimize memory overhead.
Equivalent Map methods taking long instead of Long are also provided.
Instances will throw IllegalStateException if their capacity is exceeded.
Instances do not accept zero keys and are not thread safe.
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class java.util.AbstractMap
AbstractMap.SimpleEntry<K extends Object,V extends Object>, AbstractMap.SimpleImmutableEntry<K extends Object, V extends Object> -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()clone()booleancontainsKey(long key) booleancontainsKey(Object obj) deepClone(UnaryOperator<V> valueCloner) Perform a "deep clone" operation, which is a normalclone()followed by a cloning of each value using the provided clone function.entrySet()get(long key) inthashCode()booleanisEmpty()keySet()remove(long key) Remove a single, arbitrary entry from this instance and return it.intsize()Methods inherited from class java.util.AbstractMap
containsValue, equals, putAll, toString, valuesMethods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, putIfAbsent, remove, replace, replace, replaceAll
-
Constructor Details
-
LongMap
public LongMap()Constructs an empty instance. -
LongMap
public LongMap(int capacity) Constructs an instance with the given initial capacity.- Parameters:
capacity- initial capacity- Throws:
IllegalArgumentException- ifcapacityis negative
-
LongMap
Constructs an instance initialized from the given map.- Parameters:
map- initial contents for this instance- Throws:
NullPointerException- ifmapis nullIllegalArgumentException- ifmapcontains a null key
-
-
Method Details
-
size
public int size() -
isEmpty
public boolean isEmpty() -
containsKey
- Specified by:
containsKeyin interfaceMap<Long,V> - Overrides:
containsKeyin classAbstractMap<Long,V>
-
containsKey
public boolean containsKey(long key) -
get
-
get
-
put
-
put
-
remove
-
remove
-
clear
public void clear() -
keySet
-
entrySet
-
removeOne
Remove a single, arbitrary entry from this instance and return it.- Returns:
- the removed entry, or null if this instance is empty
-
hashCode
public int hashCode() -
clone
- Overrides:
clonein classAbstractMap<Long,V>
-
deepClone
Perform a "deep clone" operation, which is a normalclone()followed by a cloning of each value using the provided clone function.- Parameters:
valueCloner- used to clone the individual values in this map- Returns:
- a deeply cloned copy of this instance
- Throws:
IllegalArgumentException- ifvalueCloneris null
-