public class BTree extends Object implements Closeable
Constructor and Description |
---|
BTree(File dataDir,
String filenamePrefix,
int blockSize,
int valueSize)
Creates a new BTree that uses an instance of DefaultRecordComparator to compare values.
|
BTree(File dataDir,
String filenamePrefix,
int blockSize,
int valueSize,
boolean forceSync)
Creates a new BTree that uses an instance of DefaultRecordComparator to compare values.
|
BTree(File dataDir,
String filenamePrefix,
int blockSize,
int valueSize,
RecordComparator comparator)
Creates a new BTree that uses the supplied RecordComparator to compare the values that are or will be
stored in the B-Tree.
|
BTree(File dataDir,
String filenamePrefix,
int blockSize,
int valueSize,
RecordComparator comparator,
boolean forceSync)
Creates a new BTree that uses the supplied RecordComparator to compare the values that are or will be
stored in the B-Tree.
|
Modifier and Type | Method and Description |
---|---|
void |
clear()
Removes all values from the B-Tree.
|
void |
close()
Closes any opened files and release any resources used by this B-Tree.
|
boolean |
delete()
Closes the BTree and then deletes its data files.
|
byte[] |
get(byte[] key)
Gets the value that matches the specified key.
|
File |
getFile()
Gets the file that this BTree operates on.
|
long |
getValueCountEstimate()
Returns an estimate for the number of values stored in this BTree.
|
long |
getValueCountEstimate(byte[] minValue,
byte[] maxValue)
Gives an estimate of the number of values between minValue and maxValue.
|
byte[] |
insert(byte[] value)
Inserts the supplied value into the B-Tree.
|
RecordIterator |
iterateAll()
Returns an iterator that iterates over all values in this B-Tree.
|
RecordIterator |
iterateRange(byte[] minValue,
byte[] maxValue)
Returns an iterator that iterates over all values between minValue and maxValue, inclusive.
|
RecordIterator |
iterateRangedValues(byte[] searchKey,
byte[] searchMask,
byte[] minValue,
byte[] maxValue)
Returns an iterator that iterates over all values between minValue and maxValue (inclusive) and returns the
values that match the supplied searchKey after searchMask has been applied to the value.
|
RecordIterator |
iterateValues(byte[] searchKey,
byte[] searchMask)
Returns an iterator that iterates over all values and returns the values that match the supplied searchKey after
searchMask has been applied to the value.
|
void |
print(PrintStream out) |
byte[] |
remove(byte[] key)
Removes the value that matches the specified key from the B-Tree.
|
void |
sync()
Writes any changes that are cached in memory to disk.
|
public BTree(File dataDir, String filenamePrefix, int blockSize, int valueSize) throws IOException
dataDir
- The directory for the BTree data.filenamePrefix
- The prefix for all files used by this BTree.blockSize
- The size (in bytes) of a file block for a single node. Ideally, the size specified is the
size of a block in the used file system.valueSize
- The size (in bytes) of the fixed-length values that are or will be stored in the B-Tree.IOException
- In case the initialization of the B-Tree file failed.DefaultRecordComparator
public BTree(File dataDir, String filenamePrefix, int blockSize, int valueSize, boolean forceSync) throws IOException
dataDir
- The directory for the BTree data.filenamePrefix
- The prefix for all files used by this BTree.blockSize
- The size (in bytes) of a file block for a single node. Ideally, the size specified is the
size of a block in the used file system.valueSize
- The size (in bytes) of the fixed-length values that are or will be stored in the B-Tree.forceSync
- Flag indicating whether updates should be synced to disk forcefully by calling
FileChannel.force(boolean)
. This may have a severe impact on write performance.IOException
- In case the initialization of the B-Tree file failed.DefaultRecordComparator
public BTree(File dataDir, String filenamePrefix, int blockSize, int valueSize, RecordComparator comparator) throws IOException
dataDir
- The directory for the BTree data.filenamePrefix
- The prefix for all files used by this BTree.blockSize
- The size (in bytes) of a file block for a single node. Ideally, the size specified is the
size of a block in the used file system.valueSize
- The size (in bytes) of the fixed-length values that are or will be stored in the B-Tree.comparator
- The RecordComparator to use for determining whether one value is smaller, larger
or equal to another.IOException
- In case the initialization of the B-Tree file failed.public BTree(File dataDir, String filenamePrefix, int blockSize, int valueSize, RecordComparator comparator, boolean forceSync) throws IOException
dataDir
- The directory for the BTree data.filenamePrefix
- The prefix for all files used by this BTree.blockSize
- The size (in bytes) of a file block for a single node. Ideally, the size specified is the
size of a block in the used file system.valueSize
- The size (in bytes) of the fixed-length values that are or will be stored in the B-Tree.comparator
- The RecordComparator to use for determining whether one value is smaller, larger
or equal to another.forceSync
- Flag indicating whether updates should be synced to disk forcefully by calling
FileChannel.force(boolean)
. This may have a severe impact on write performance.IOException
- In case the initialization of the B-Tree file failed.public File getFile()
public boolean delete() throws IOException
IOException
public void close() throws IOException
close
in interface Closeable
close
in interface AutoCloseable
IOException
public void sync() throws IOException
IOException
public byte[] get(byte[] key) throws IOException
key
- A value that is equal to the value that should be retrieved, at least as far as the RecordComparator
of this BTree is concerned.IOException
public RecordIterator iterateAll()
public RecordIterator iterateRange(byte[] minValue, byte[] maxValue)
public RecordIterator iterateValues(byte[] searchKey, byte[] searchMask)
public RecordIterator iterateRangedValues(byte[] searchKey, byte[] searchMask, byte[] minValue, byte[] maxValue)
public long getValueCountEstimate() throws IOException
IOException
public long getValueCountEstimate(byte[] minValue, byte[] maxValue) throws IOException
minValue
- the lower bound of the range.maxValue
- the upper bound of the range,IOException
public byte[] insert(byte[] value) throws IOException
value
- The value to insert into the B-Tree.IOException
- If an I/O error occurred.public byte[] remove(byte[] key) throws IOException
key
- A key that matches the value that should be removed from the B-Tree.IOException
- If an I/O error occurred.public void clear() throws IOException
IOException
- If an I/O error occurred.public void print(PrintStream out) throws IOException
IOException
Copyright © 2015-2020 Eclipse Foundation. All Rights Reserved.