|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.util.AbstractMap<K,V>
org.h2.mvstore.MVMap<K,V>
K
- the key classV
- the value classpublic class MVMap<K,V>
A stored map.
Nested Class Summary | |
---|---|
static class |
MVMap.Builder<K,V>
A builder for this class. |
static interface |
MVMap.MapBuilder<M extends MVMap<K,V>,K,V>
A builder for maps. |
Nested classes/interfaces inherited from class java.util.AbstractMap |
---|
java.util.AbstractMap.SimpleEntry<K,V>, java.util.AbstractMap.SimpleImmutableEntry<K,V> |
Nested classes/interfaces inherited from interface java.util.Map |
---|
java.util.Map.Entry<K,V> |
Field Summary | |
---|---|
protected long |
currentWriteVersion
This version is set during a write operation. |
protected Page |
root
The current root page (may not be null). |
protected MVStore |
store
The store. |
protected long |
writeVersion
The version used for writing. |
Constructor Summary | |
---|---|
protected |
MVMap(DataType keyType,
DataType valueType)
|
Method Summary | |
---|---|
protected void |
afterWrite()
This method is called after writing to the map (whether or not the write operation was successful). |
boolean |
areValuesEqual(java.lang.Object a,
java.lang.Object b)
Check whether the two values are equal. |
protected void |
beforeWrite()
This method is called before writing to the map. |
protected java.lang.Object |
binarySearch(Page p,
java.lang.Object key)
Get the value for the given key, or null if not found. |
protected Page |
binarySearchPage(Page p,
java.lang.Object key)
Get the value for the given key, or null if not found. |
K |
ceilingKey(K key)
Get the smallest key that is larger or equal to this key. |
protected void |
checkConcurrentWrite()
Check that no write operation is in progress. |
void |
clear()
Remove all entries. |
boolean |
containsKey(java.lang.Object key)
|
protected Page |
copyOnWrite(Page p,
long writeVersion)
Create a copy of a page, if the write version is higher than the current version. |
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 |
floorKey(K key)
Get the largest key that is smaller or equal to this key. |
V |
get(java.lang.Object key)
Get a value. |
protected int |
getChildPageCount(Page p)
Get the child page count for this page. |
long |
getCreateVersion()
|
protected K |
getFirstLast(boolean first)
Get the first (lowest) or last (largest) key. |
int |
getId()
|
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. |
protected K |
getMinMax(K key,
boolean min,
boolean excluding)
Get the smallest or largest key using the given bounds. |
java.lang.String |
getName()
Get the map name. |
protected Page |
getPage(K key)
Get the page for the given value. |
Page |
getRoot()
Get the root page. |
java.lang.String |
getType()
Get the map type. |
DataType |
getValueType()
Get the value type. |
long |
getVersion()
|
int |
hashCode()
|
K |
higherKey(K key)
Get the smallest key that is larger than the given key, or null if no such key exists. |
protected void |
init(MVStore store,
java.util.HashMap<java.lang.String,java.lang.String> config)
Open this map with the given store and configuration. |
boolean |
isClosed()
|
boolean |
isEmpty()
|
boolean |
isReadOnly()
|
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 |
lowerKey(K key)
Get the largest key that is smaller than the given key, or null if no such key exists. |
protected void |
newRoot(Page newRoot)
Use the new root page from now on. |
MVMap<K,V> |
openVersion(long version)
Open an old version for the given map. |
V |
put(K key,
V value)
Add or replace a key-value pair. |
protected java.lang.Object |
put(Page p,
long writeVersion,
java.lang.Object key,
java.lang.Object value)
Add or update 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. |
protected java.lang.Object |
remove(Page p,
long writeVersion,
java.lang.Object key)
Remove a key-value pair. |
protected void |
removePage(long pos)
Remove the given page (make the space available). |
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. |
int |
size()
Get the number of entries, as a integer. |
long |
sizeAsLong()
Get the number of entries, as a long. |
protected Page |
splitRootIfNeeded(Page p,
long writeVersion)
Split the root page if necessary. |
java.lang.String |
toString()
|
protected void |
waitUntilWritten(long version)
If there is a concurrent update to the given version, wait until it is finished. |
Methods inherited from class java.util.AbstractMap |
---|
clone, containsValue, putAll, values |
Methods inherited from class java.lang.Object |
---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
Methods inherited from interface java.util.Map |
---|
containsValue, putAll, values |
Field Detail |
---|
protected MVStore store
protected volatile Page root
protected volatile long writeVersion
protected volatile long currentWriteVersion
Constructor Detail |
---|
protected MVMap(DataType keyType, DataType valueType)
Method Detail |
---|
protected void init(MVStore store, java.util.HashMap<java.lang.String,java.lang.String> config)
store
- the storeconfig
- the configurationprotected Page copyOnWrite(Page p, long writeVersion)
p
- the pagewriteVersion
- the write version
public V put(K key, V value)
put
in interface java.util.Map<K,V>
put
in class java.util.AbstractMap<K,V>
key
- the key (may not be null)value
- the value (may not be null)
protected Page splitRootIfNeeded(Page p, long writeVersion)
p
- the pagewriteVersion
- the write version
protected java.lang.Object put(Page p, long writeVersion, java.lang.Object key, java.lang.Object value)
p
- the pagewriteVersion
- the write versionkey
- the key (may not be null)value
- the value (may not be null)
public K firstKey()
public K lastKey()
public K getKey(long index)
This is a O(log(size)) operation.
index
- the index
public 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 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 key
protected K getFirstLast(boolean first)
first
- whether to retrieve the first key
public K higherKey(K key)
key
- the key
public K ceilingKey(K key)
key
- the key
public K floorKey(K key)
key
- the key
public K lowerKey(K key)
key
- the key
protected K getMinMax(K key, boolean min, boolean excluding)
key
- the keymin
- whether to retrieve the smallest keyexcluding
- if the given upper/lower bound is exclusive
public V get(java.lang.Object key)
get
in interface java.util.Map<K,V>
get
in class java.util.AbstractMap<K,V>
key
- the key
protected java.lang.Object binarySearch(Page p, java.lang.Object key)
p
- the pagekey
- the key
public boolean containsKey(java.lang.Object key)
containsKey
in interface java.util.Map<K,V>
containsKey
in class java.util.AbstractMap<K,V>
protected Page getPage(K key)
key
- the key
protected Page binarySearchPage(Page p, java.lang.Object key)
p
- the parent pagekey
- the key
public void clear()
clear
in interface java.util.Map<K,V>
clear
in class java.util.AbstractMap<K,V>
public 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)
public V putIfAbsent(K key, V value)
putIfAbsent
in interface java.util.concurrent.ConcurrentMap<K,V>
key
- the key (may not be null)value
- the new value
public boolean remove(java.lang.Object key, java.lang.Object value)
remove
in interface java.util.concurrent.ConcurrentMap<K,V>
key
- the key (may not be null)value
- the expected value
public boolean areValuesEqual(java.lang.Object a, java.lang.Object b)
a
- the first valueb
- the second value
public boolean replace(K key, V oldValue, V newValue)
replace
in interface java.util.concurrent.ConcurrentMap<K,V>
key
- the key (may not be null)oldValue
- the expected valuenewValue
- the new value
public V replace(K key, V value)
replace
in interface java.util.concurrent.ConcurrentMap<K,V>
key
- the key (may not be null)value
- the new value
protected java.lang.Object remove(Page p, long writeVersion, java.lang.Object key)
p
- the page (may not be null)writeVersion
- the write versionkey
- the key
protected void newRoot(Page newRoot)
newRoot
- the new root pagepublic DataType getKeyType()
public DataType getValueType()
public java.util.Iterator<K> keyIterator(K from)
from
- the first key to return
public Cursor<K,V> cursor(K from)
from
- the first key to return
public java.util.Set<java.util.Map.Entry<K,V>> entrySet()
entrySet
in interface java.util.Map<K,V>
entrySet
in class java.util.AbstractMap<K,V>
public java.util.Set<K> keySet()
keySet
in interface java.util.Map<K,V>
keySet
in class java.util.AbstractMap<K,V>
public Page getRoot()
public java.lang.String getName()
public int getId()
public boolean isReadOnly()
protected void beforeWrite()
java.lang.UnsupportedOperationException
- if the map is read-only,
or if another thread is concurrently writingprotected void checkConcurrentWrite()
protected void afterWrite()
protected void waitUntilWritten(long version)
version
- the read versionpublic int hashCode()
hashCode
in interface java.util.Map<K,V>
hashCode
in class java.util.AbstractMap<K,V>
public boolean equals(java.lang.Object o)
equals
in interface java.util.Map<K,V>
equals
in class java.util.AbstractMap<K,V>
public int size()
size
in interface java.util.Map<K,V>
size
in class java.util.AbstractMap<K,V>
public long sizeAsLong()
public boolean isEmpty()
isEmpty
in interface java.util.Map<K,V>
isEmpty
in class java.util.AbstractMap<K,V>
public long getCreateVersion()
protected void removePage(long pos)
pos
- the position of the page to removepublic MVMap<K,V> openVersion(long version)
version
- the version
public long getVersion()
protected int getChildPageCount(Page p)
p
- the page
public java.lang.String getType()
public java.lang.String toString()
toString
in class java.util.AbstractMap<K,V>
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |