K - the key classV - the value classpublic class MVMap<K,V>
extends java.util.AbstractMap<K,V>
implements java.util.concurrent.ConcurrentMap<K,V>
All read and write operations can happen concurrently with all other operations, without risk of corruption.
| Modifier and Type | Class and Description |
|---|---|
static class |
MVMap.BasicBuilder<M extends MVMap<K,V>,K,V>
A builder for this class.
|
static class |
MVMap.Builder<K,V>
A builder for this class.
|
static class |
MVMap.Decision
The decision on what to do on an update.
|
static class |
MVMap.DecisionMaker<V>
Class DecisionMaker provides callback interface (and should become a such in Java 8)
for MVMap.operate method.
|
static interface |
MVMap.MapBuilder<M extends MVMap<K,V>,K,V>
A builder for maps.
|
| Modifier | Constructor and Description |
|---|---|
protected |
MVMap(java.util.Map<java.lang.String,java.lang.Object> config,
DataType<K> keyType,
DataType<V> valueType) |
protected |
MVMap(MVMap<K,V> source) |
| Modifier and Type | Method and Description |
|---|---|
void |
append(K key,
V value)
Appends entry to this map.
|
protected java.lang.String |
asString(java.lang.String name)
Get the map metadata as a string.
|
protected void |
beforeWrite()
This method is called before writing to the map.
|
K |
ceilingKey(K key)
Get the smallest key that is larger or equal to this key.
|
void |
clear()
Remove all entries.
|
protected MVMap<K,V> |
cloneIt()
Clone the current map.
|
boolean |
containsKey(java.lang.Object key) |
protected Page<K,V> |
createEmptyLeaf()
Create empty leaf node page.
|
protected Page<K,V> |
createEmptyNode()
Create empty internal node page.
|
Cursor<K,V> |
cursor(K from)
Get a cursor to iterate over a number of keys and values in the latest version of this map.
|
Cursor<K,V> |
cursor(K from,
K to,
boolean reverse)
Get a cursor to iterate over a number of keys and values in the latest version of this map.
|
Cursor<K,V> |
cursor(RootReference<K,V> rootReference,
K from,
K to,
boolean reverse)
Get a cursor to iterate over a number of keys and values.
|
java.util.Set<java.util.Map.Entry<K,V>> |
entrySet() |
boolean |
equals(java.lang.Object o) |
K |
firstKey()
Get the first key, or null if the map is empty.
|
K |
floorKey(K key)
Get the largest key that is smaller or equal to this key.
|
RootReference<K,V> |
flushAndGetRoot()
Get the root reference, flushing any current append buffer.
|
V |
get(java.lang.Object key)
Get the value for the given key, or null if not found.
|
V |
get(Page<K,V> p,
K key)
Get the value for the given key from a snapshot, or null if not found.
|
protected int |
getChildPageCount(Page<K,V> p)
Get the child page count for this page.
|
int |
getId()
Get the map id.
|
K |
getKey(long index)
Get the key at the given index.
|
long |
getKeyIndex(K key)
Get the index of the given key in the map.
|
DataType<K> |
getKeyType()
Get the key type.
|
java.lang.String |
getName()
Get the map name.
|
RootReference<K,V> |
getRoot() |
Page<K,V> |
getRootPage()
The current root page (may not be null).
|
MVStore |
getStore() |
java.lang.String |
getType()
Get the map type.
|
DataType<V> |
getValueType()
Get the value type.
|
long |
getVersion()
Get version of the map, which is the version of the store,
at the moment when map was modified last time.
|
int |
hashCode() |
K |
higherKey(K key)
Get the smallest key that is larger than the given key (next key in ascending order),
or null if no such key exists.
|
K |
higherKey(RootReference<K,V> rootRef,
K key)
Get the smallest key that is larger than the given key, for the given
root page, or null if no such key exists.
|
boolean |
isClosed() |
boolean |
isEmpty() |
protected boolean |
isPersistent() |
boolean |
isReadOnly() |
boolean |
isVolatile()
Whether this is volatile map, meaning that changes
are not persisted.
|
java.util.Iterator<K> |
keyIterator(K from)
Iterate over a number of keys.
|
java.util.Iterator<K> |
keyIteratorReverse(K from)
Iterate over a number of keys in reverse order
|
java.util.List<K> |
keyList()
Get the key list.
|
java.util.Set<K> |
keySet() |
K |
lastKey()
Get the last key, or null if the map is empty.
|
K |
lowerKey(K key)
Get the largest key that is smaller than the given key, or null if no
such key exists.
|
K |
lowerKey(RootReference<K,V> rootRef,
K key)
Get the largest key that is smaller than the given key, for the given
root page, or null if no such key exists.
|
MVMap<K,V> |
openVersion(long version)
Open an old version for the given map.
|
V |
operate(K key,
V value,
MVMap.DecisionMaker<? super V> decisionMaker)
Add, replace or remove a key-value pair.
|
V |
put(K key,
V value)
Add or replace a key-value pair.
|
V |
putIfAbsent(K key,
V value)
Add a key-value pair if it does not yet exist.
|
V |
remove(java.lang.Object key)
Remove a key-value pair, if the key exists.
|
boolean |
remove(java.lang.Object key,
java.lang.Object value)
Remove a key-value pair if the value matches the stored one.
|
V |
replace(K key,
V value)
Replace a value for an existing key.
|
boolean |
replace(K key,
V oldValue,
V newValue)
Replace a value for an existing key, if the value matches.
|
void |
setVolatile(boolean isVolatile)
Set the volatile flag of the map.
|
int |
size()
Get the number of entries, as a integer.
|
long |
sizeAsLong()
Get the number of entries, as a long.
|
java.lang.String |
toString() |
void |
trimLast()
Removes last entry from this map.
|
protected RootReference<K,V> |
tryLock(RootReference<K,V> rootReference,
int attempt)
Try to lock the root.
|
protected RootReference<K,V> |
unlockRoot(Page<K,V> newRootPage)
Unlock the root page.
|
protected static <K,V> boolean |
updateRoot(RootReference<K,V> expectedRootReference,
Page<K,V> newRootPage,
int attemptUpdateCounter)
Use the new root page from now on.
|
finalize, getClass, notify, notifyAll, wait, wait, waitpublic final MVStore store
protected MVMap(java.util.Map<java.lang.String,java.lang.Object> config,
DataType<K> keyType,
DataType<V> valueType)
public final K firstKey()
public final K lastKey()
public final K getKey(long index)
This is a O(log(size)) operation.
index - the indexpublic final java.util.List<K> keyList()
The get and indexOf methods are O(log(size)) operations. The result of indexOf is cast to an int.
public final long getKeyIndex(K key)
This is a O(log(size)) operation.
If the key was found, the returned value is the index in the key array. If not found, the returned value is negative, where -1 means the provided key is smaller than any keys. See also Arrays.binarySearch.
key - the keypublic final K higherKey(K key)
key - the keypublic final K higherKey(RootReference<K,V> rootRef, K key)
rootRef - the root reference of the mapkey - to start frompublic final K ceilingKey(K key)
key - the keypublic final K floorKey(K key)
key - the keypublic final K lowerKey(K key)
key - the keypublic final K lowerKey(RootReference<K,V> rootRef, K key)
rootRef - the root pagekey - the keypublic final V get(java.lang.Object key)
public V get(Page<K,V> p, K key)
p - the root of a snapshotkey - the keyjava.lang.ClassCastException - if type of the specified key is not compatible with this mappublic final boolean containsKey(java.lang.Object key)
public void clear()
public final boolean isClosed()
public V remove(java.lang.Object key)
remove in interface java.util.Map<K,V>remove in class java.util.AbstractMap<K,V>key - the key (may not be null)java.lang.ClassCastException - if type of the specified key is not compatible with this mappublic final V putIfAbsent(K key, V value)
public boolean remove(java.lang.Object key,
java.lang.Object value)
public final boolean replace(K key, V oldValue, V newValue)
public final java.util.Iterator<K> keyIterator(K from)
from - the first key to returnpublic final java.util.Iterator<K> keyIteratorReverse(K from)
from - the first key to returnpublic final Cursor<K,V> cursor(K from)
from - the first key to returnpublic final Cursor<K,V> cursor(K from, K to, boolean reverse)
from - the first key to returnto - the last key to returnreverse - if true, iterate in reverse (descending) orderpublic Cursor<K,V> cursor(RootReference<K,V> rootReference, K from, K to, boolean reverse)
rootReference - of this map's version to iterate overfrom - the first key to returnto - the last key to returnreverse - if true, iterate in reverse (descending) orderpublic java.util.Set<K> keySet()
public final java.lang.String getName()
public final MVStore getStore()
protected final boolean isPersistent()
public final int getId()
public final Page<K,V> getRootPage()
public RootReference<K,V> getRoot()
public RootReference<K,V> flushAndGetRoot()
protected static <K,V> boolean updateRoot(RootReference<K,V> expectedRootReference, Page<K,V> newRootPage, int attemptUpdateCounter)
K - the key classV - the value classexpectedRootReference - expected current root referencenewRootPage - the new root pageattemptUpdateCounter - how many attempt (including current)
were made to update rootpublic final boolean isReadOnly()
public final void setVolatile(boolean isVolatile)
isVolatile - the volatile flagpublic final boolean isVolatile()
protected final void beforeWrite()
java.lang.UnsupportedOperationException - if the map is read-only,
or if another thread is concurrently writingpublic final int hashCode()
public final boolean equals(java.lang.Object o)
public final int size()
Integer.MAX_VALUE is
returned if there are more than this entries.size in interface java.util.Map<K,V>size in class java.util.AbstractMap<K,V>sizeAsLong()public final long sizeAsLong()
public boolean isEmpty()
public final MVMap<K,V> openVersion(long version)
version - the versionpublic final long getVersion()
protected int getChildPageCount(Page<K,V> p)
p - the pagepublic java.lang.String getType()
protected java.lang.String asString(java.lang.String name)
name - the map name (or null)protected Page<K,V> createEmptyLeaf()
protected Page<K,V> createEmptyNode()
public void append(K key, V value)
key - should be higher in map's order than any existing keyvalue - to be appendedpublic void trimLast()
public final java.lang.String toString()
public V operate(K key, V value, MVMap.DecisionMaker<? super V> decisionMaker)
key - the key (may not be null)value - new value, it may be null when removal is intendeddecisionMaker - command object to make choices during transaction.protected RootReference<K,V> tryLock(RootReference<K,V> rootReference, int attempt)
rootReference - the old root referenceattempt - the number of attempts so far