|
CoherenceTM v3.3 Copyright© 2000-2007 by Oracle Corporation |
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.util.AbstractMap
com.tangosol.util.SafeHashMap
public class SafeHashMap
An implementation of java.util.Map that is synchronized, but minimally so. This class is for use in situation where high concurrency is required, but so is data integrity.
All additions and removals are synchronized on the map, so to temporarily prevent changes to the map contents, synchronize on the map object.
Nested Class Summary | |
---|---|
protected static class |
SafeHashMap.Entry
A map entry (key-value pair). |
protected class |
SafeHashMap.EntrySet
A set of entries backed by this map. |
protected class |
SafeHashMap.KeySet
A set of entries backed by this map. |
protected class |
SafeHashMap.ValuesCollection
A collection of values backed by this map. |
Field Summary | |
---|---|
protected static int |
BIGGEST_MODULO
Biggest possible modulo. |
static float |
DEFAULT_GROWTHRATE
Using the default growth rate, the bucket array will grow by a factor of four. |
static int |
DEFAULT_INITIALSIZE
Default initial size provides a prime modulo and is large enough that resize is not immediate. |
static float |
DEFAULT_LOADFACTOR
The default load factor is 100%, which means that the hash map will not resize until there is (on average) one entry in every bucket. |
protected SafeHashMap.Entry[] |
m_aeBucket
The array of hash buckets. |
protected int |
m_cCapacity
The capacity of the hash map (the point at which it must resize), 1 <= n. |
protected int |
m_cEntries
The number of entries stored in the hash map, 0 <= n. |
protected SafeHashMap.ValuesCollection |
m_colValues
The collection of values backed by this map. |
protected float |
m_flGrowthRate
The rate of growth as a fraction of the current number of buckets, 0 < n, such that the hash map grows to bucketcount * (1 + growthrate) |
protected float |
m_flLoadFactor
The determining factor for the hash map capacity given a certain number of buckets, such that capactiy = bucketcount * loadfactor. |
protected Object |
m_oIterActive
A holder for active Iterator(s): either WeakReference( |
protected SafeHashMap.EntrySet |
m_setEntries
The set of entries backed by this map. |
protected SafeHashMap.KeySet |
m_setKeys
The set of keys backed by this map. |
protected static int[] |
PRIME_MODULO
A list of possible modulos to use. |
protected Object |
RESIZING
When resizing completes, a notification is issued against this object. |
Constructor Summary | |
---|---|
SafeHashMap()
Construct a thread-safe hash map using the default settings. |
|
SafeHashMap(int cInitialBuckets,
float flLoadFactor,
float flGrowthRate)
Construct a thread-safe hash map using the specified settings. |
Method Summary | |
---|---|
void |
clear()
Removes all mappings from this map. |
Object |
clone()
Create a clone of the SafeHashMap. |
protected SafeHashMap.Entry |
cloneEntryList(SafeHashMap.Entry entryThat)
Clone an entire linked list of entries. |
boolean |
containsKey(Object key)
Returns true if this map contains a mapping for the specified key. |
Set |
entrySet()
Returns a set view of the mappings contained in this map. |
Object |
get(Object key)
Returns the value to which this map maps the specified key. |
protected int |
getBucketIndex(int nHash,
int cBuckets)
Calculate the bucket number for a particular hash code. |
SafeHashMap.Entry |
getEntry(Object key)
Locate an Entry in the hash map based on its key. |
protected SafeHashMap.Entry |
getEntryInternal(Object oKey)
Locate an Entry in the hash map based on its key. |
protected SafeHashMap.Entry[] |
getStableBucketArray()
Get the bucket array, or if a resize is occurring, wait for the resize to complete and return the new bucket array. |
protected void |
grow()
Resize the bucket array, rehashing all Entries. |
protected SafeHashMap.Entry |
instantiateEntry()
Factory pattern. |
protected SafeHashMap.EntrySet |
instantiateEntrySet()
Factory pattern. |
protected SafeHashMap.KeySet |
instantiateKeySet()
Factory pattern. |
protected SafeHashMap.ValuesCollection |
instantiateValuesCollection()
Factory pattern. |
protected boolean |
isActiveIterator()
Determine if there are any active Iterators, which may mean that they are in the middle of iterating over the Map. |
boolean |
isEmpty()
Returns true if this map contains no key-value mappings. |
protected void |
iteratorActivated(Iterator iter)
Register the activation of an Iterator. |
protected void |
iteratorDeactivated(Iterator iter)
Unregister the (formerly active) Iterator. |
Set |
keySet()
Returns a Set view of the keys contained in this map. |
Object |
put(Object key,
Object value)
Associates the specified value with the specified key in this map. |
Object |
remove(Object oKey)
Removes the mapping for this key from this map if present. |
protected void |
removeEntryInternal(SafeHashMap.Entry entry)
Removes the passed Entry from the map. |
int |
size()
Returns the number of key-value mappings in this map. |
Collection |
values()
Returns a collection view of the values contained in this map. |
Methods inherited from class java.util.AbstractMap |
---|
containsValue, equals, hashCode, putAll, toString |
Field Detail |
---|
protected static final int[] PRIME_MODULO
public static final int DEFAULT_INITIALSIZE
protected static final int BIGGEST_MODULO
public static final float DEFAULT_LOADFACTOR
public static final float DEFAULT_GROWTHRATE
protected Object RESIZING
protected volatile int m_cEntries
protected volatile SafeHashMap.Entry[] m_aeBucket
protected int m_cCapacity
protected float m_flLoadFactor
protected float m_flGrowthRate
protected transient SafeHashMap.EntrySet m_setEntries
protected transient SafeHashMap.KeySet m_setKeys
protected transient SafeHashMap.ValuesCollection m_colValues
protected transient Object m_oIterActive
Constructor Detail |
---|
public SafeHashMap()
public SafeHashMap(int cInitialBuckets, float flLoadFactor, float flGrowthRate)
cInitialBuckets
- the initial number of hash buckets, 0 < nflLoadFactor
- the acceptable load factor before resizing
occurs, 0 < n, such that a load factor of
1.0 causes resizing when the number of entries
exceeds the number of bucketsflGrowthRate
- the rate of bucket growth when a resize occurs,
0 < n, such that a growth rate of 1.0 will
double the number of buckets:
bucketcount = bucketcount * (1 + growthrate)Method Detail |
---|
public int size()
size
in interface Map
size
in class AbstractMap
public boolean isEmpty()
isEmpty
in interface Map
isEmpty
in class AbstractMap
public boolean containsKey(Object key)
containsKey
in interface Map
containsKey
in class AbstractMap
key
- key whose presence in this map is to be tested
public Object get(Object key)
get
in interface Map
get
in class AbstractMap
key
- key whose associated value is to be returned
public SafeHashMap.Entry getEntry(Object key)
key
- the key object to search for
public Object put(Object key, Object value)
put
in interface Map
put
in class AbstractMap
key
- key with which the specified value is to be associatedvalue
- value to be associated with the specified key
protected void grow()
public Object remove(Object oKey)
remove
in interface Map
remove
in class AbstractMap
oKey
- key whose mapping is to be removed from the map
public void clear()
clear
in interface Map
clear
in class AbstractMap
public Set entrySet()
entrySet
in interface Map
entrySet
in class AbstractMap
public Set keySet()
keySet
in interface Map
keySet
in class AbstractMap
public Collection values()
values
in interface Map
values
in class AbstractMap
public Object clone()
clone
in class AbstractMap
protected SafeHashMap.Entry cloneEntryList(SafeHashMap.Entry entryThat)
entryThat
- the entry that is the head of the list to clone
protected SafeHashMap.Entry getEntryInternal(Object oKey)
getEntry(java.lang.Object)
method, there must be no side-effects of
calling this method.
oKey
- the key object to search for
protected void removeEntryInternal(SafeHashMap.Entry entry)
entry
- the entry to remove from this mapprotected int getBucketIndex(int nHash, int cBuckets)
nHash
- the hash codecBuckets
- the number of buckets
protected SafeHashMap.Entry[] getStableBucketArray()
protected void iteratorActivated(Iterator iter)
iter
- the activated iteratorprotected void iteratorDeactivated(Iterator iter)
iter
- the deactivated iteratorprotected boolean isActiveIterator()
protected SafeHashMap.Entry instantiateEntry()
protected SafeHashMap.EntrySet instantiateEntrySet()
protected SafeHashMap.KeySet instantiateKeySet()
protected SafeHashMap.ValuesCollection instantiateValuesCollection()
|
CoherenceTM v3.3 Copyright© 2000-2007 by Oracle Corporation |
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |