java.util.concurrent.ConcurrentHashMap
with primitive long keys, better scaling properties and
generally lower costs. The use of long
keys allows for faster
compares and lower memory costs. The Map provides identical correctness
properties as ConcurrentHashMap. All operations are non-blocking and
multi-thread safe, including all update operations. NonBlockingHashMapLong
scales substatially better than java.util.concurrent.ConcurrentHashMap
for high update rates, even with a large
concurrency factor. Scaling is linear up to 768 CPUs on a 768-CPU Azul
box, even with 100% updates or 100% reads or any fraction in-between.
Linear scaling up to all cpus has been observed on a 32-way Sun US2 box,
32-way Sun Niagra box, 8-way Intel box and a 4-way Power box.
The main benefit of this class over using plain io.
with Long
keys is
that it avoids the auto-boxing and unboxing costs. Since auto-boxing is
automatic, it is easy to accidentally cause auto-boxing and negate
the space and speed benefits.
This class obeys the same functional specification as java.
, and includes versions of methods corresponding to
each method of Hashtable. However, even though all operations are
thread-safe, operations do not entail locking and there is
not any support for locking the entire table in a way that
prevents all access. This class is fully interoperable with
Hashtable in programs that rely on its thread safety but not on
its synchronization details.
Operations (including put) generally do not block, so may
overlap with other update operations (including other puts and
removes). Retrievals reflect the results of the most recently
completed update operations holding upon their onset. For
aggregate operations such as putAll, concurrent retrievals may
reflect insertion or removal of only some entries. Similarly, Iterators
and Enumerations return elements reflecting the state of the hash table at
some point at or since the creation of the iterator/enumeration. They do
not throw ConcurrentModificationException
. However,
iterators are designed to be used by only one thread at a time.
Very full tables, or tables with high reprobe rates may trigger an internal resize operation to move into a larger table. Resizing is not terribly expensive, but it is not free either; during resize operations table throughput may drop somewhat. All threads that visit the table during a resize will 'help' the resizing but will still be allowed to complete their operation before the resize is finished (i.e., a simple 'get' operation on a million-entry table undergoing resizing will not need to block until the entire million entries are copied).
This class and its views and iterators implement all of the
optional methods of the Map
and Iterator
interfaces.
Like Hashtable
but unlike HashMap
, this class
does not allow null to be used as a value.
Modifier and Type | Class and Description |
---|---|
private static class | |
public class | NonBlockingHashMapLong.
A class which implements the |
private class | |
private static class | |
private class | |
private class |
Modifier and Type | Field and Description |
---|---|
private transient NonBlockingHashMapLong. | |
private static final long | |
private transient long | |
private static final int | |
private static final int | |
private static final int | |
private final boolean | |
private static final int | |
private transient Object | |
private static final long | |
private static final Object | |
private static final int | |
private static final int | |
private static final long | |
private static final Object | |
private static final int | |
private static final long | |
private static final NonBlockingHashMapLong. | |
private static final Object |
Access | Constructor and Description |
---|---|
public | NonBlockingHashMapLong()
Create a new NonBlockingHashMapLong with default minimum size (currently set to 8 K/V pairs or roughly 84 bytes on a standard 32-bit JVM). |
public | NonBlockingHashMapLong(final int initial_sz)
Create a new NonBlockingHashMapLong with initial room for the given number of elements, thus avoiding internal resizing operations to reach an appropriate size. |
public | NonBlockingHashMapLong(final boolean opt_for_space)
Create a new NonBlockingHashMapLong, setting the space-for-speed tradeoff. |
public | NonBlockingHashMapLong(final int initial_sz, final boolean opt_for_space)
Create a new NonBlockingHashMapLong, setting both the initial size and the space-for-speed tradeoff. |
Modifier and Type | Method and Description |
---|---|
private final boolean | |
public void | clear()
Overrides java. Implements java. |
public boolean | |
public boolean | |
public boolean | containsKey(Object
key whose presence in this map is to be tested key)Overrides java. Implements java. containsKey(long) .
|
public boolean | Returns: true if this Map maps one or more keys to the specified valuevalue whose presence in this map is to be tested val)Overrides java. Implements java. Note This method requires a full internal traversal of the
hash table and is much slower than |
public Enumeration | Returns: an enumeration of the values in this tableReturns an enumeration of the values in this table. |
public Set | entrySet()
Implements abstract java. Implements java. Set view of the mappings contained in this map.
|
public final TypeV | get(long key)
Returns the value to which the specified key is mapped, or |
public TypeV | get(Object
the key whose associated value is to be returned key)Overrides java. Implements java. get(long) .
|
private void | |
private void | |
public Enumeration | Returns: an enumeration of the auto-boxed keys in this tableReturns an enumeration of the auto-boxed keys in this table Warning this version will auto-box all returned keys. |
public Set | keySet()
Overrides java. Implements java. Set view of the keys contained in this map; with care
the keys may be iterated over without auto-boxing.
|
public long[] | |
public final void | |
private void | |
private static void | |
private static void | |
public TypeV | Returns: the previous value associated with key, or null if there was no mapping for keykey with which the specified value is to be associated key, TypeV value to be associated with the specified key val)Overrides java. Implements java. |
public TypeV | put(Long
key with which the specified value is to be associated key, TypeV value to be associated with the specified key val)Overrides java. Implements java. put .
|
public TypeV | Returns: the previous value associated with the specified key, or null if there was no mapping for the keykey with which the specified value is to be associated key, TypeV value to be associated with the specified key val)Overrides default java. Implements java. put if-and-only-if the key is not mapped.
|
public TypeV | putIfAbsent(Long
key with which the specified value is to be associated key, TypeV value to be associated with the specified key val)Overrides default java. Implements java. putIfAbsent .
|
private TypeV | |
private static long | |
private static long | |
private void | |
public TypeV | Returns: the previous value associated with key, or null if there was no mapping for keyRemoves the key (and its corresponding value) from this map. |
public boolean | remove(long key, Object val)
Atomically do a |
public TypeV | remove(Object
key whose mapping is to be removed from the map key)Overrides java. Implements java. remove(long) .
|
public boolean | remove(Object
key with which the specified value is associated key, Object value expected to be associated with the specified key Val)Overrides default java. Implements java. remove(long, Object) .
|
public TypeV | replace(long
key with which the specified value is associated key, TypeV value to be associated with the specified key val)Overrides default java. Implements java. put(key,val) if-and-only-if the key is
mapped to some value already.
|
public boolean | replace(long
key with which the specified value is associated key, TypeV value expected to be associated with the specified key oldValue, TypeV value to be associated with the specified key newValue)Overrides default java. Implements java. put(key,newValue) if-and-only-if the key is
mapped a value which is equals to oldValue .
|
public TypeV | replace(Long
key with which the specified value is associated key, TypeV value to be associated with the specified key Val)Overrides default java. Implements java. replace .
|
public boolean | replace(Long
key with which the specified value is associated key, TypeV value expected to be associated with the specified key oldValue, TypeV value to be associated with the specified key newValue)Overrides default java. Implements java. replace .
|
private static int | |
public int | Returns: the number of key-value mappings in this mapOverrides java. Implements java. |
public Collection | values()
Overrides java. Implements java. Collection view of the values contained in this map.
|
private void |