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
-
Method Summary
Modifier and TypeMethodDescriptionvoid
clear()
clone()
boolean
containsKey
(long key) boolean
containsKey
(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) int
hashCode()
boolean
isEmpty()
keySet()
remove
(long key) Remove a single, arbitrary entry from this instance and return it.int
size()
Methods inherited from class java.util.AbstractMap
containsValue, equals, putAll, toString, values
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
Methods 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
- ifcapacity
is negative
-
LongMap
Constructs an instance initialized from the given map.- Parameters:
map
- initial contents for this instance- Throws:
NullPointerException
- ifmap
is nullIllegalArgumentException
- ifmap
contains a null key
-
-
Method Details
-
size
public int size() -
isEmpty
public boolean isEmpty() -
containsKey
- Specified by:
containsKey
in interfaceMap<Long,
V> - Overrides:
containsKey
in 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:
clone
in 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
- ifvalueCloner
is null
-