org.mapdb
Class LongConcurrentHashMap<V>

java.lang.Object
  extended by org.mapdb.LongMap<V>
      extended by org.mapdb.LongConcurrentHashMap<V>
All Implemented Interfaces:
Serializable

public class LongConcurrentHashMap<V>
extends LongMap<V>
implements Serializable

Thread safe LongMap. Is refactored version of 'ConcurrentHashMap'

Author:
Jan Kotek, Doug Lea
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class org.mapdb.LongMap
LongMap.LongMapIterator<V>
 
Field Summary
protected  long hashSalt
          Salt added to keys before hashing, so it is harder to trigger hash collision attack.
 
Constructor Summary
LongConcurrentHashMap()
          Creates a new, empty map with a default initial capacity (16), load factor (0.75) and concurrencyLevel (16).
LongConcurrentHashMap(int initialCapacity)
          Creates a new, empty map with the specified initial capacity, and with default load factor (0.75) and concurrencyLevel (16).
LongConcurrentHashMap(int initialCapacity, float loadFactor, int concurrencyLevel)
          Creates a new, empty map with the specified initial capacity, load factor and concurrency level.
 
Method Summary
 void clear()
          Removes all of the mappings from this map.
 boolean containsKey(long key)
          Tests if the specified object is a key in this table.
 boolean containsValue(Object value)
          Returns true if this map maps one or more keys to the specified value.
 V get(long key)
          Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.
 boolean isEmpty()
          Returns true if this map contains no key-value mappings.
 LongMap.LongMapIterator<V> longMapIterator()
           
 V put(long key, V value)
          Maps the specified key to the specified value in this table.
 V putIfAbsent(long key, V value)
           
 V remove(long key)
          Removes the key (and its corresponding value) from this map.
 boolean remove(long key, Object value)
           
 V replace(long key, V value)
           
 boolean replace(long key, V oldValue, V newValue)
           
 int size()
          Returns the number of key-value mappings in this map.
 Iterator<V> valuesIterator()
           
 
Methods inherited from class org.mapdb.LongMap
toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

hashSalt

protected final long hashSalt
Salt added to keys before hashing, so it is harder to trigger hash collision attack.

Constructor Detail

LongConcurrentHashMap

public LongConcurrentHashMap(int initialCapacity,
                             float loadFactor,
                             int concurrencyLevel)
Creates a new, empty map with the specified initial capacity, load factor and concurrency level.

Parameters:
initialCapacity - the initial capacity. The implementation performs internal sizing to accommodate this many elements.
loadFactor - the load factor threshold, used to control resizing. Resizing may be performed when the average number of elements per bin exceeds this threshold.
concurrencyLevel - the estimated number of concurrently updating threads. The implementation performs internal sizing to try to accommodate this many threads.
Throws:
IllegalArgumentException - if the initial capacity is negative or the load factor or concurrencyLevel are nonpositive.

LongConcurrentHashMap

public LongConcurrentHashMap(int initialCapacity)
Creates a new, empty map with the specified initial capacity, and with default load factor (0.75) and concurrencyLevel (16).

Parameters:
initialCapacity - the initial capacity. The implementation performs internal sizing to accommodate this many elements.
Throws:
IllegalArgumentException - if the initial capacity of elements is negative.

LongConcurrentHashMap

public LongConcurrentHashMap()
Creates a new, empty map with a default initial capacity (16), load factor (0.75) and concurrencyLevel (16).

Method Detail

isEmpty

public boolean isEmpty()
Returns true if this map contains no key-value mappings.

Specified by:
isEmpty in class LongMap<V>
Returns:
true if this map contains no key-value mappings
See Also:
LongMap.size()

size

public int size()
Returns the number of key-value mappings in this map. If the map contains more than Integer.MAX_VALUE elements, returns Integer.MAX_VALUE.

Specified by:
size in class LongMap<V>
Returns:
the number of key-value mappings in this map

valuesIterator

public Iterator<V> valuesIterator()
Specified by:
valuesIterator in class LongMap<V>
Returns:
iterator over values in map

longMapIterator

public LongMap.LongMapIterator<V> longMapIterator()
Specified by:
longMapIterator in class LongMap<V>

get

public V get(long key)
Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.

More formally, if this map contains a mapping from a key k to a value keys such that key.equals(k), then this method returns keys; otherwise it returns null. (There can be at most one such mapping.)

Specified by:
get in class LongMap<V>
Parameters:
key - the key.
Returns:
the value of the mapping with the specified key, or null if no mapping for the specified key is found.
Throws:
NullPointerException - if the specified key is null

containsKey

public boolean containsKey(long key)
Tests if the specified object is a key in this table.

Parameters:
key - possible key
Returns:
true if and only if the specified object is a key in this table, as determined by the equals method; false otherwise.
Throws:
NullPointerException - if the specified key is null

containsValue

public boolean containsValue(Object value)
Returns true if this map maps one or more keys to the specified value. Note: This method requires a full internal traversal of the hash table, and so is much slower than method containsKey.

Parameters:
value - value whose presence in this map is to be tested
Returns:
true if this map maps one or more keys to the specified value
Throws:
NullPointerException - if the specified value is null

put

public V put(long key,
             V value)
Maps the specified key to the specified value in this table. Neither the key nor the value can be null.

The value can be retrieved by calling the get method with a key that is equal to the original key.

Specified by:
put in class LongMap<V>
Parameters:
key - key with which the specified value is to be associated
value - value to be associated with the specified key
Returns:
the previous value associated with key, or null if there was no mapping for key
Throws:
NullPointerException - if the specified key or value is null

putIfAbsent

public V putIfAbsent(long key,
                     V value)
Returns:
the previous value associated with the specified key, or null if there was no mapping for the key
Throws:
NullPointerException - if the specified key or value is null

remove

public V remove(long key)
Removes the key (and its corresponding value) from this map. This method does nothing if the key is not in the map.

Specified by:
remove in class LongMap<V>
Parameters:
key - the key that needs to be removed
Returns:
the previous value associated with key, or null if there was no mapping for key
Throws:
NullPointerException - if the specified key is null

remove

public boolean remove(long key,
                      Object value)
Throws:
NullPointerException - if the specified key is null

replace

public boolean replace(long key,
                       V oldValue,
                       V newValue)
Throws:
NullPointerException - if any of the arguments are null

replace

public V replace(long key,
                 V value)
Returns:
the previous value associated with the specified key, or null if there was no mapping for the key
Throws:
NullPointerException - if the specified key or value is null

clear

public void clear()
Removes all of the mappings from this map.

Specified by:
clear in class LongMap<V>
See Also:
LongMap.isEmpty(), LongMap.size()


Copyright © 2014. All Rights Reserved.