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 |
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) |
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.
|
K |
ceilingKey(Page p,
K key)
Get the smallest key that is larger or equal to this key, for the given root page.
|
void |
clear()
Remove all entries.
|
protected MVMap<K,V> |
cloneIt()
Clone the current map.
|
boolean |
containsKey(java.lang.Object key) |
protected Page |
createEmptyLeaf()
Create empty leaf node page.
|
protected Page |
createEmptyNode()
Create empty internal node page.
|
Cursor<K,V> |
cursor(K from)
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 |
firstKey(Page p)
Get the first key of this page.
|
K |
floorKey(K key)
Get the largest key that is smaller or equal to this key.
|
K |
floorKey(Page p,
K key)
Get the largest key that is smaller or equal to this key, for the given root page.
|
RootReference |
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 p,
java.lang.Object key)
Get the value for the given key from a snapshot, or null if not found.
|
protected int |
getChildPageCount(Page p)
Get the child page count for this page.
|
long |
getCreateVersion() |
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 |
getKeyType()
Get the key type.
|
java.lang.String |
getName()
Get the map name.
|
RootReference |
getRoot() |
Page |
getRootPage()
The current root page (may not be null).
|
MVStore |
getStore() |
java.lang.String |
getType()
Get the map type.
|
DataType |
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, or null if no
such key exists.
|
K |
higherKey(Page p,
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.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 |
lastKey(Page p)
Get the last key of this page.
|
K |
lowerKey(K key)
Get the largest key that is smaller than the given key, or null if no
such key exists.
|
K |
lowerKey(Page p,
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 |
tryLock(RootReference rootReference,
int attempt)
Try to lock the root.
|
protected RootReference |
unlockRoot(Page newRootPage)
Unlock the root page.
|
protected static boolean |
updateRoot(RootReference expectedRootReference,
Page newRootPage,
int attemptUpdateCounter)
Use the new root page from now on.
|
public final MVStore store
public final K firstKey()
public final K firstKey(Page p)
p - the pagepublic final K lastKey()
public final K lastKey(Page p)
p - the pagepublic 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(Page p, K key)
p - the root pagekey - the keypublic final K ceilingKey(K key)
key - the keypublic final K ceilingKey(Page p, K key)
p - the root pagekey - the keypublic final K floorKey(K key)
key - the keypublic final K floorKey(Page p, K key)
p - the root pagekey - the keypublic final K lowerKey(K key)
key - the keypublic final K lowerKey(Page p, K key)
p - the root pagekey - the keypublic final V get(java.lang.Object key)
public V get(Page p, java.lang.Object 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 DataType getKeyType()
public final DataType getValueType()
public final java.util.Iterator<K> keyIterator(K from)
from - the first key to returnpublic final Cursor<K,V> cursor(K from)
from - the first key to returnpublic 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 getRootPage()
public RootReference getRoot()
public RootReference flushAndGetRoot()
protected static boolean updateRoot(RootReference expectedRootReference, Page newRootPage, int attemptUpdateCounter)
expectedRootReference - 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 long getCreateVersion()
public final MVMap<K,V> openVersion(long version)
version - the versionpublic final long getVersion()
protected int getChildPageCount(Page 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 createEmptyLeaf()
protected Page 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 tryLock(RootReference rootReference, int attempt)
rootReference - the old root referenceattempt - the number of attempts so farprotected RootReference unlockRoot(Page newRootPage)
newRootPage - the new root