public final class LongHashMap<V> extends AbstractLongMap<V> implements Cloneable, Serializable
LongMap interface. This
implementation provides all of the optional map operations, and permits
null values. This class makes no guarantees as to
the order of the map; in particular, it does not guarantee that the order
will remain constant over time.
Note that this implementation is not synchronized. If multiple
threads access this map concurrently, and at least one of the threads
modifies the map structurally, it must be synchronized externally.
(A structural modification is any operation that adds or deletes one or
more mappings; merely changing the value associated with a key that an
instance already contains is not a structural modification.) This is
typically accomplished by synchronizing on some object that naturally
encapsulates the map. If no such object exists, the map should be
"wrapped" using the Collections.synchronizedMap(java.util.Map<K, V>) method.
This is best done at creation time, to prevent accidental unsynchronized
access to the map.
The iterators returned by all of this class's "collection view methods" are
fail-fast: if the map is structurally modified at any time after the
iterator is created, in any way except through the iterator's own
remove or add methods, the iterator will throw a
ConcurrentModificationException. Thus, in the face of
concurrent modification, the iterator fails quickly and cleanly, rather
than risking arbitrary, non-deterministic behavior at an undetermined time
in the future.
AbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K,V>LongMap.Entry<V>| Modifier and Type | Field and Description |
|---|---|
static int |
MAX_CAPACITY
Maximal supported capacity of this hashtable.
|
| Constructor and Description |
|---|
LongHashMap()
Constructs a new, empty map.
|
LongHashMap(int capacity)
Constructs a new map with a specified capacity.
|
LongHashMap(Map<? extends Long,? extends V> m)
Constructs a new map containing all mappings from the specified map.
|
| Modifier and Type | Method and Description |
|---|---|
void |
clear() |
void |
clearAndCompact()
Removes all mappings and frees all memory.
|
void |
clearAndCompact(int capacity)
Removes all mappings and compacts memory usage of this hashtable,
but requested capacity is retained.
|
Object |
clone()
Returns a shallow copy of this
LongHashMap instance:
the values themselves are not cloned. |
void |
compact()
Compacts memory usage of this hashtable.
|
void |
compact(int capacity)
Compacts memory usage of this hashtable, but requested capacity
is retained.
|
boolean |
containsKey(long key)
Returns true if this map contains a mapping for the specified
key.
|
void |
ensureCapacity(int capacity)
Makes sure that no rehashes or memory reallocations will be
needed until
size() <= capacity. |
Set<Map.Entry<Long,V>> |
entrySet()
Returns a collection view of the mappings contained in this map.
|
V |
get(long key)
Returns the value to which this map maps the specified key.
|
V |
getOrDefault(long key,
V defaultValue)
Returns the value to which this map maps the specified key.
|
boolean |
isEmpty() |
LongSet |
longKeySet()
Returns a set view of the keys contained in this map.
|
V |
put(long key,
V value)
Associates the specified value with the specified key in this map.
|
void |
putAll(Map<? extends Long,? extends V> t) |
V |
remove(long key)
Removes the mapping for this key from this map if present.
|
boolean |
remove(long key,
Object value)
Removes the entry for the specified key only if it is currently
mapped to the specified value.
|
int |
size() |
Collection<V> |
values()
Returns a collection view of the values contained in this map.
|
compute, computeIfAbsent, computeIfPresent, containsKey, get, getOrDefault, keySet, merge, put, putIfAbsent, remove, remove, replace, replacecontainsValue, equals, hashCode, toStringfinalize, getClass, notify, notifyAll, wait, wait, waitcompute, computeIfAbsent, computeIfPresent, merge, putIfAbsent, replace, replacecontainsValue, equals, forEach, hashCode, replaceAllpublic static final int MAX_CAPACITY
public LongHashMap()
public LongHashMap(Map<? extends Long,? extends V> m)
public LongHashMap(int capacity)
public int size()
public boolean isEmpty()
public void clear()
public boolean containsKey(long key)
LongMapcontainsKey in interface LongMap<V>containsKey in class AbstractLongMap<V>Map.containsKey(Object)public V get(long key)
LongMapget in interface LongMap<V>get in class AbstractLongMap<V>Map.get(Object)public V put(long key, V value)
LongMapput in interface LongMap<V>put in class AbstractLongMap<V>Map.put(Object, Object)public V remove(long key)
LongMapremove in interface LongMap<V>remove in class AbstractLongMap<V>Map.remove(Object)public V getOrDefault(long key, V defaultValue)
LongMapdefaultValue if the map contains no mapping for this key.getOrDefault in interface LongMap<V>Map.getOrDefault(Object, Object)public boolean remove(long key,
Object value)
LongMapremove in interface LongMap<V>Map.remove(Object, Object)public LongSet longKeySet()
LongHashSet.longKeySet in interface LongMap<V>longKeySet in class AbstractLongMap<V>Map.keySet()public Collection<V> values()
public Set<Map.Entry<Long,V>> entrySet()
LongMap.Entry. The
collection is backed by the map, so changes to the map are reflected in
the collection, and vice-versa. The collection supports element
removal, which removes the corresponding mapping from the map, via the
Iterator.remove, Collection.remove,
removeAll, retainAll, and clear operations.
It does not support the add or addAll operations.entrySet in interface Map<Long,V>entrySet in class AbstractLongMap<V>LongMap.Entrypublic void ensureCapacity(int capacity)
size() <= capacity.IllegalArgumentException - when capacity > MAX_CAPACITY.public void compact()
public void compact(int capacity)
compact() and ensureCapacity(int) calls,
but is faster, because it does not produce excessive garbage.
When capacity is less or equal than 1, this method is equivalent
to compact().IllegalArgumentException - when capacity > MAX_CAPACITY.public void clearAndCompact()
public void clearAndCompact(int capacity)
clear() and compact(int) calls,
but is faster. When capacity is less or equal than 1, this method is
equivalent to clearAndCompact().IllegalArgumentException - when capacity > MAX_CAPACITY.public Object clone()
LongHashMap instance:
the values themselves are not cloned.clone in class AbstractMap<Long,V>Copyright © 2002–2025 Devexperts LLC. All rights reserved.