K
- The type for the keysV
- The type for the stored valuespublic class BTree<K,V> extends Object implements Closeable
Modifier and Type | Field and Description |
---|---|
static String |
DATA_SUFFIX
The default data file suffix
|
static String |
DEFAULT_JOURNAL
The default journal name
|
static int |
DEFAULT_PAGE_SIZE
Default page size (number of entries per node)
|
static long |
DEFAULT_READ_TIMEOUT
Define a default delay for a read transaction.
|
static int |
DEFAULT_WRITE_BUFFER_SIZE
Default size of the buffer used to write data on disk.
|
static String |
JOURNAL_SUFFIX
The default journal file suffix
|
protected static org.slf4j.Logger |
LOG
The LoggerFactory used by this class
|
protected Page<K,V> |
rootPage
The current rootPage
|
Constructor and Description |
---|
BTree()
Creates a new BTree, with no initialization.
|
BTree(BTreeConfiguration<K,V> configuration)
Creates a new in-memory BTree using the BTreeConfiguration to initialize the
BTree
|
BTree(String name,
ElementSerializer<K> keySerializer,
ElementSerializer<V> valueSerializer)
Creates a new in-memory BTree with a default page size and key/value serializers.
|
BTree(String name,
ElementSerializer<K> keySerializer,
ElementSerializer<V> valueSerializer,
boolean allowDuplicates) |
BTree(String name,
ElementSerializer<K> keySerializer,
ElementSerializer<V> valueSerializer,
boolean allowDuplicates,
int cacheSize) |
BTree(String name,
ElementSerializer<K> keySerializer,
ElementSerializer<V> valueSerializer,
int pageSize)
Creates a new in-memory BTree with a default page size and key/value serializers.
|
BTree(String name,
String path,
ElementSerializer<K> keySerializer,
ElementSerializer<V> valueSerializer)
Creates a new BTree with a default page size and a comparator, with an associated file.
|
BTree(String name,
String dataDir,
ElementSerializer<K> keySerializer,
ElementSerializer<V> valueSerializer,
int pageSize)
Creates a new instance of BTree with the given name and store it under the given dataDir if provided.
|
BTree(String name,
String dataDir,
ElementSerializer<K> keySerializer,
ElementSerializer<V> valueSerializer,
int pageSize,
boolean allowDuplicates) |
BTree(String name,
String dataDir,
ElementSerializer<K> keySerializer,
ElementSerializer<V> valueSerializer,
int pageSize,
boolean allowDuplicates,
int cacheSize) |
Modifier and Type | Method and Description |
---|---|
TupleCursor<K,V> |
browse()
Creates a cursor starting at the beginning of the tree
|
TupleCursor<K,V> |
browse(long revision)
Creates a cursor starting at the beginning of the tree, for a given revision
|
TupleCursor<K,V> |
browseFrom(K key)
Creates a cursor starting on the given key
|
TupleCursor<K,V> |
browseFrom(long revision,
K key)
Creates a cursor starting on the given key at the given revision
|
void |
close()
Close the BTree, cleaning up all the data structure
|
boolean |
contains(K key,
V value)
Checks if the BTree contains the given key with the given value.
|
boolean |
contains(long revision,
K key,
V value)
Checks if the BTree contains the given key with the given value for a given revision
|
Tuple<K,V> |
delete(K key)
Delete the entry which key is given as a parameter.
|
Tuple<K,V> |
delete(K key,
V value)
Delete the value from an entry associated with the given key.
|
void |
flush()
Flush the latest revision to disk.
|
V |
get(K key)
Find a value in the tree, given its key.
|
V |
get(long revision,
K key)
Find a value in the tree, given its key, at a specific revision.
|
Comparator<K> |
getComparator() |
ElementSerializer<K> |
getKeySerializer() |
String |
getKeySerializerFQCN() |
String |
getName() |
long |
getNbElems() |
int |
getPageSize() |
long |
getReadTimeOut() |
long |
getRevision() |
ValueCursor<V> |
getValues(K key) |
ElementSerializer<V> |
getValueSerializer() |
String |
getValueSerializerFQCN() |
int |
getWriteBufferSize() |
boolean |
hasKey(K key)
Checks if the given key exists.
|
boolean |
hasKey(long revision,
K key)
Checks if the given key exists for a given revision.
|
void |
init()
Initialize the BTree.
|
V |
insert(K key,
V value)
Insert an entry in the BTree.
|
boolean |
isAllowDuplicates() |
void |
setKeySerializer(ElementSerializer<K> keySerializer) |
void |
setName(String name) |
void |
setPageSize(int pageSize)
Set the maximum number of elements we can store in a page.
|
void |
setReadTimeOut(long readTimeOut) |
void |
setValueSerializer(ElementSerializer<V> valueSerializer) |
void |
setWriteBufferSize(int writeBufferSize) |
String |
toString() |
protected static final org.slf4j.Logger LOG
public static final int DEFAULT_PAGE_SIZE
public static final int DEFAULT_WRITE_BUFFER_SIZE
public static final String DEFAULT_JOURNAL
public static final String DATA_SUFFIX
public static final String JOURNAL_SUFFIX
public static final long DEFAULT_READ_TIMEOUT
public BTree()
public BTree(BTreeConfiguration<K,V> configuration) throws IOException
comparator
- The comparator to useIOException
public BTree(String name, ElementSerializer<K> keySerializer, ElementSerializer<V> valueSerializer) throws IOException
comparator
- The comparator to useIOException
public BTree(String name, ElementSerializer<K> keySerializer, ElementSerializer<V> valueSerializer, boolean allowDuplicates) throws IOException
IOException
public BTree(String name, ElementSerializer<K> keySerializer, ElementSerializer<V> valueSerializer, boolean allowDuplicates, int cacheSize) throws IOException
IOException
public BTree(String name, ElementSerializer<K> keySerializer, ElementSerializer<V> valueSerializer, int pageSize) throws IOException
comparator
- The comparator to useIOException
public BTree(String name, String path, ElementSerializer<K> keySerializer, ElementSerializer<V> valueSerializer) throws IOException
comparator
- The comparator to useserializer
- The serializer to useIOException
public BTree(String name, String dataDir, ElementSerializer<K> keySerializer, ElementSerializer<V> valueSerializer, int pageSize) throws IOException
name
- the name of the BTreedataDir
- the name of the data directory with absolute pathkeySerializer
- key serializervalueSerializer
- value serializerpageSize
- size of the pageIOException
public BTree(String name, String dataDir, ElementSerializer<K> keySerializer, ElementSerializer<V> valueSerializer, int pageSize, boolean allowDuplicates) throws IOException
IOException
public BTree(String name, String dataDir, ElementSerializer<K> keySerializer, ElementSerializer<V> valueSerializer, int pageSize, boolean allowDuplicates, int cacheSize) throws IOException
IOException
public void init() throws IOException
IOException
- If we get some exception while initializing the BTreepublic void close() throws IOException
close
in interface Closeable
close
in interface AutoCloseable
IOException
public void setPageSize(int pageSize)
pageSize
- The requested page sizepublic int getPageSize()
public V insert(K key, V value) throws IOException
We will replace the value if the provided key already exists in the btree.
key
- Inserted keyvalue
- Inserted valueIOException
- TODOpublic Tuple<K,V> delete(K key) throws IOException
key
- The key for the entry we try to removeIOException
public Tuple<K,V> delete(K key, V value) throws IOException
key
- The key for the entry we try to removevalue
- The value to delete (can be null)IOException
public V get(K key) throws IOException, KeyNotFoundException
key
- The key we are looking atKeyNotFoundException
- If the key is not found in the BTreeIOException
- TODOpublic ValueCursor<V> getValues(K key) throws IOException, KeyNotFoundException
IOException
KeyNotFoundException
Page.getValues(Object)
public V get(long revision, K key) throws IOException, KeyNotFoundException
revision
- The revision for which we want to find a keykey
- The key we are looking atKeyNotFoundException
- If the key is not found in the BTreeIOException
- If there was an issue while fetching data from the diskpublic boolean hasKey(K key) throws IOException
key
- The key we are looking atIOException
- If we have an error while trying to access the pagepublic boolean hasKey(long revision, K key) throws IOException, KeyNotFoundException
revision
- The revision for which we want to find a keykey
- The key we are looking atIOException
- If we have an error while trying to access the pageKeyNotFoundException
- If the key is not found in the BTreepublic boolean contains(K key, V value) throws IOException
key
- The key we are looking forvalue
- The value associated with the given keyIOException
public boolean contains(long revision, K key, V value) throws IOException, KeyNotFoundException
revision
- The revision we would like to browsekey
- The key we are looking forvalue
- The value associated with the given keyKeyNotFoundException
- If the key is not found in the BTreeIOException
public TupleCursor<K,V> browse() throws IOException
IOException
public TupleCursor<K,V> browse(long revision) throws IOException, KeyNotFoundException
revision
- The revision we would like to browseIOException
- If we had an issue while fetching data from the diskKeyNotFoundException
- If the key is not found in the BTreepublic TupleCursor<K,V> browseFrom(K key) throws IOException
key
- The key which is the starting point. If the key is not found,
then the cursor will always return null.IOException
public TupleCursor<K,V> browseFrom(long revision, K key) throws IOException, KeyNotFoundException
The
- revision we are looking forkey
- The key which is the starting point. If the key is not found,
then the cursor will always return null.IOException
- If wxe had an issue reading the BTree from diskKeyNotFoundException
- If we can't find a rootPage for this revisionpublic Comparator<K> getComparator()
public void setKeySerializer(ElementSerializer<K> keySerializer)
keySerializer
- the Key serializer to setpublic void setValueSerializer(ElementSerializer<V> valueSerializer)
valueSerializer
- the Value serializer to setpublic void flush() throws IOException
IOException
public long getReadTimeOut()
public void setReadTimeOut(long readTimeOut)
readTimeOut
- the readTimeOut to setpublic String getName()
public void setName(String name)
name
- the name to setpublic int getWriteBufferSize()
public void setWriteBufferSize(int writeBufferSize)
writeBufferSize
- the writeBufferSize to setpublic ElementSerializer<K> getKeySerializer()
public String getKeySerializerFQCN()
public ElementSerializer<V> getValueSerializer()
public String getValueSerializerFQCN()
public long getRevision()
public long getNbElems()
public boolean isAllowDuplicates()
public String toString()
toString
in class Object
Object.toString()
Copyright © 2012-2013 Apache Mavibot Project Parent. All Rights Reserved.