|
Oracle® Coherence Java API Reference v3.5 E14977-01 |
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object
java.util.AbstractMap
com.tangosol.util.SafeSortedMap
public class SafeSortedMap
SafeSortedMap is an implementation of SortedMap
based on a skip-list that is structurally thread-safe. Read-only operations are performed without synchronization; mutations synchronize on the map. In the presence of concurrent updates, SafeSortedMap iterators will reflect some state of the map, but will not throw ConcurrentModificationException or other unexpected exceptions. <p/> The structure of the SafeSortedMap is maintained in a 2-dimensional lattice:
Top | I3 -------------------------------> S5 -------------> | | I2 -------------> S2 -------------> S5 -------------> | | | I1 -------> S1 -> S2 -------> S4 -> S5 -------> S7 -> | | | | | | I0 -> E0 -> E1 -> E2 -> E3 -> E4 -> E5 -> E6 -> E7 ->
<p/> Searching for a key involves traversing, starting from the top index node, as far to the right at each index level, then down. For example, the search path for the element E4 in the above example would be:
The search path for the element E7 in the above example would be:
<p/> Removing a key involves inserting a temporary marker-entry while the entry pointers are fixed up. The marker node allows uncontended read threads to traverse the safely. Additionally, removing a key causes any index nodes for that key to be removed as well. Removals are synchronized on the map and proceed bottom up, removing the entry first followed by any index nodes in increasing index-level order. <p/> In the above example, the steps to remove entry E3 would be:
The steps to remove E4 (indexed to level 1) would be:
Inserting a key happens in 'bottom-up' fashion, with the entry node being inserted first, (possibly) followed by index nodes of increasing level. Inserts are fully synchronized on the map. When inserting a new entry, an index level randomly computed such that, the probability that a given insertion will be indexed to level n is approximately given by: (1/k)n where k is the average span of each index level. In the above example, the steps to insert entry E3.5 at index-level 1 would be:
<p/>
Nested Class Summary | |
---|---|
protected class |
SafeSortedMap.DeletedNode DeletedNode is a SkipNode that is used as a marker during deletion. |
protected class |
SafeSortedMap.EntryNode EntryNode represents a key-value mapping in this map. |
protected class |
SafeSortedMap.IndexNode IndexNode represents the start node in the map's lattice representation at a given index-level. |
protected class |
SafeSortedMap.SkipNode SkipNode is an entry or index node in the lattice for a SafeSortedMap's representation. |
class |
SafeSortedMap.Split Split encapsulates the headMap and tailMap of the SafeSortedMap at a given split-key and could be used as an optimization facility when both head and tail portions of the SortedMap are needed. |
protected class |
SafeSortedMap.ViewMap ViewMap provides a SortedMap view over a subset of the SafeSortedMap. |
Nested classes/interfaces inherited from interface java.util.Map |
---|
java.util.Map.Entry |
Field Summary | |
---|---|
protected static int |
DEFAULT_MAX_LEVEL The default limit on the index-level. |
protected static int |
DEFAULT_SPAN The default span value. |
protected float[] |
m_aflProbability The array of pre-computed probabilities for each level. |
protected SafeSortedMap.SkipNode[] |
m_aNodeBuffer The scratch buffer used by mutation operations to store the search path to the insertion/deletion site. |
protected java.util.Comparator |
m_comparator The comparator used to sort this map. |
protected SafeSortedMap.ViewMap |
m_mapView The default ViewMap (over the entire map's range). |
protected int |
m_nLevelMax The maximum number of index levels to use for this map. |
protected SafeSortedMap.IndexNode |
m_nodeTop The top index node. |
protected int |
m_nSize The memoized size of the map. |
protected int |
m_nSpan The span of the map. |
protected java.util.Random |
m_random The random-number generator for the map. |
protected static int |
SEARCH_EQ Search mode for equal-to. |
protected static int |
SEARCH_GT Search mode for strictly greater-than. |
protected static int |
SEARCH_GTEQ Search mode for greater-than or equal. |
protected static int |
SEARCH_LT Search mode for strictly less-than. |
protected static int |
SEARCH_LTEQ Search mode for less-than or equal. |
Constructor Summary | |
---|---|
SafeSortedMap() Construct a new SafeSortedMap using the natural ordering of the Comparable keys in this map. |
|
SafeSortedMap(java.util.Comparator comparator) Construct a new SafeSortedMap with the specified Comparator. |
|
SafeSortedMap(java.util.Comparator comparator, int nSpan, int nLevelMax) Construct a new SafeSortedMap with the specified parameters. |
Method Summary | |
---|---|
protected int |
calculateRandomLevel() Randomly generate a level value 0 <= L <= MAX_LEVEL, in such a way that the probability p(l) of generating level l is equal to p(l-1)/span and p(0)=1/span. |
void |
clear() |
java.util.Comparator |
comparator() |
boolean |
containsKey(java.lang.Object oKey) |
protected java.lang.Object |
deleteNode(SafeSortedMap.EntryNode node) Delete the specified node, as well any associated index nodes. |
java.lang.String |
dump() Return a human-readable description of this map's internal state. |
java.util.Set |
entrySet() |
protected SafeSortedMap.EntryNode |
findKey(java.lang.Object oKey) Return the EntryNode for the specified key if it is contained in this map, or null otherwise. |
protected SafeSortedMap.SkipNode |
findNearest(java.lang.Object oKey, int nMode) Return the SkipNode closest to the specified key, or null. |
protected SafeSortedMap.SkipNode[] |
findNearestPath(java.lang.Object oKey, int nMode) Return the search/index path to the node closest to the specified key. |
protected SafeSortedMap.SkipNode[] |
findNearestPath(java.lang.Object oKey, int nMode, SafeSortedMap.SkipNode[] aNodePath) Return the search/index path to the node closest to the specified key. |
protected SafeSortedMap.SkipNode |
findOnSameLevel(SafeSortedMap.SkipNode nodeStart, java.lang.Object oKey, int nMode) Find the closest SkipNode (according to the specified search mode) to the specified key, starting from the specified SkipNode. |
java.lang.Object |
firstKey() |
java.lang.Object |
get(java.lang.Object oKey) |
java.util.Map.Entry |
getEntry(java.lang.Object key) Locate an Entry in the this map based on its key. |
protected int |
getLevel() Return the current maximum level of this map's index (the highest level that any key has built an index node for). |
protected int |
getMaxLevel() Return the maximum index-level that this map is allowed to reach. |
protected float[] |
getProbabilities() Return the precomputed array of probability values used by this map to determine what index levels to build. |
protected java.util.Random |
getRandom() Return the random number generator for this map. |
protected SafeSortedMap.SkipNode[] |
getSearchBuffer() Return the buffer used to hold the search path for insertion/deletion operations. |
protected int |
getSpan() Return the span of this map. |
protected SafeSortedMap.IndexNode |
getTopNode() Return the top index node in the map. |
protected SafeSortedMap.ViewMap |
getViewMap() Return a view of the entire map. |
java.util.SortedMap |
headMap(java.lang.Object toKey) |
protected boolean |
insertNode(java.lang.Object oKey, java.lang.Object oValue) Insert a new EntryNode and (possibly) SkipNode(s) for the specified key and value in this skip-list, up to a random index-level. |
java.lang.Object |
lastKey() |
java.lang.Object |
put(java.lang.Object oKey, java.lang.Object oValue) |
java.lang.Object |
remove(java.lang.Object oKey) |
protected SafeSortedMap.SkipNode |
search(java.lang.Object oKey, int nMode, SafeSortedMap.IndexNode nodeTop, SafeSortedMap.SkipNode[] aNodePath) Return the search/index path to the node closest to the specified key. |
protected void |
setSearchBuffer(SafeSortedMap.SkipNode[] aNodeBuffer) Set the buffer used to hold the search path for insertion/deletion operations. |
protected void |
setSize(int nSize) Set the size of this map (cached to make the size() operation less expensive, since we already synchronize on all updates). |
protected void |
setTopNode(SafeSortedMap.IndexNode nodeTop) Set the top index node in the map. |
int |
size() |
SafeSortedMap.Split |
split(java.lang.Object oKey) Return a SafeSortedMap.Split of this map at the specified key. |
java.util.SortedMap |
subMap(java.lang.Object fromKey, java.lang.Object toKey) |
java.util.SortedMap |
tailMap(java.lang.Object fromKey) |
Methods inherited from class java.util.AbstractMap |
---|
clone, containsValue, equals, hashCode, isEmpty, keySet, putAll, toString, values |
Methods inherited from interface java.util.Map |
---|
containsValue, equals, hashCode, isEmpty, keySet, putAll, values |
Field Detail |
---|
protected static final int DEFAULT_SPAN
protected static final int DEFAULT_MAX_LEVEL
protected static final int SEARCH_EQ
protected static final int SEARCH_LT
protected static final int SEARCH_GT
protected static final int SEARCH_LTEQ
protected static final int SEARCH_GTEQ
protected final java.util.Comparator m_comparator
protected final int m_nLevelMax
protected final float[] m_aflProbability
protected int m_nSpan
protected final SafeSortedMap.ViewMap m_mapView
protected volatile SafeSortedMap.IndexNode m_nodeTop
protected transient SafeSortedMap.SkipNode[] m_aNodeBuffer
protected int m_nSize
protected java.util.Random m_random
Constructor Detail |
---|
public SafeSortedMap()
public SafeSortedMap(java.util.Comparator comparator)
comparator
- the comparator used to sort this mappublic SafeSortedMap(java.util.Comparator comparator, int nSpan, int nLevelMax)
comparator
- the comparator used to sort this mapnSpan
- the average span to use for each index-levelnLevelMax
- the maximum index-level to use for this mapMethod Detail |
---|
public int size()
size
in interface java.util.Map
size
in class java.util.AbstractMap
public boolean containsKey(java.lang.Object oKey)
containsKey
in interface java.util.Map
containsKey
in class java.util.AbstractMap
public java.util.Set entrySet()
entrySet
in interface java.util.Map
entrySet
in class java.util.AbstractMap
public java.lang.Object put(java.lang.Object oKey, java.lang.Object oValue)
put
in interface java.util.Map
put
in class java.util.AbstractMap
public java.lang.Object get(java.lang.Object oKey)
get
in interface java.util.Map
get
in class java.util.AbstractMap
public java.util.Map.Entry getEntry(java.lang.Object key)
key
- the key object to search forpublic java.lang.Object remove(java.lang.Object oKey)
remove
in interface java.util.Map
remove
in class java.util.AbstractMap
public void clear()
clear
in interface java.util.Map
clear
in class java.util.AbstractMap
public java.util.Comparator comparator()
comparator
in interface java.util.SortedMap
public java.util.SortedMap subMap(java.lang.Object fromKey, java.lang.Object toKey)
subMap
in interface java.util.SortedMap
public java.util.SortedMap headMap(java.lang.Object toKey)
headMap
in interface java.util.SortedMap
public java.util.SortedMap tailMap(java.lang.Object fromKey)
tailMap
in interface java.util.SortedMap
public java.lang.Object firstKey()
firstKey
in interface java.util.SortedMap
public java.lang.Object lastKey()
lastKey
in interface java.util.SortedMap
protected SafeSortedMap.ViewMap getViewMap()
protected void setSize(int nSize)
nSize
- the new size of the mapprotected float[] getProbabilities()
calculateRandomLevel()
protected java.util.Random getRandom()
protected int getLevel()
protected int getMaxLevel()
protected int getSpan()
protected SafeSortedMap.IndexNode getTopNode()
protected void setTopNode(SafeSortedMap.IndexNode nodeTop)
nodeTop
- the new top index nodeprotected SafeSortedMap.SkipNode[] getSearchBuffer()
protected void setSearchBuffer(SafeSortedMap.SkipNode[] aNodeBuffer)
aNodeBuffer
- the new search path bufferprotected boolean insertNode(java.lang.Object oKey, java.lang.Object oValue)
oKey
- the key to insertoValue
- the value to insertprotected java.lang.Object deleteNode(SafeSortedMap.EntryNode node)
protected SafeSortedMap.SkipNode findOnSameLevel(SafeSortedMap.SkipNode nodeStart, java.lang.Object oKey, int nMode)
nodeStart
- the SkipNode to start searching fromoKey
- the key to search fornMode
- one of the SEARCH_* constantsprotected SafeSortedMap.EntryNode findKey(java.lang.Object oKey)
oKey
- the key to search forprotected SafeSortedMap.SkipNode findNearest(java.lang.Object oKey, int nMode)
oKey
- the key to search fornMode
- one of the SEARCH_* constantsprotected SafeSortedMap.SkipNode[] findNearestPath(java.lang.Object oKey, int nMode)
oKey
- the key to search fornMode
- one of the SEARCH_* constantsprotected SafeSortedMap.SkipNode[] findNearestPath(java.lang.Object oKey, int nMode, SafeSortedMap.SkipNode[] aNodePath)
oKey
- the key to search fornMode
- one of the SEARCH_* constantsaNodePath
- the array into which the search path will be stored if it is the correct size; otherwise a new array will be allocatedprotected SafeSortedMap.SkipNode search(java.lang.Object oKey, int nMode, SafeSortedMap.IndexNode nodeTop, SafeSortedMap.SkipNode[] aNodePath)
oKey
- the key to search fornMode
- one of the SEARCH_* constantsnodeTop
- the top index node to start searching fromaNodePath
- the search/index path recorded by the search to the node closest to the specified key, according to the specified search mode. May be null.protected int calculateRandomLevel()
public java.lang.String dump()
public SafeSortedMap.Split split(java.lang.Object oKey)
SafeSortedMap.Split
of this map at the specified key.oKey
- the key at which to split the map
|
Oracle® Coherence Java API Reference v3.5 E14977-01 |
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |