| java.lang.Object org.openrdf.sail.nativerdf.btree.BTree
BTree | public class BTree (Code) | | Implementation of an on-disk B-Tree using the java.nio classes
that are available in JDK 1.4 and newer. Documentation about B-Trees can be
found on-line at the following URLs:
- http://cis.stvincent.edu/swd/btree/btree.html
,
- http://bluerwhite.org/btree/
, and
- http://semaphorecorp.com/btp/algo.html
.
The first reference was used to implement this class.
TODO: clean up code
author: Arjohn Kampman |
Constructor Summary | |
public | BTree(File dataFile, int blockSize, int valueSize) Creates a new BTree that uses an instance of
DefaultRecordComparator to compare values.
Parameters: dataFile - The file for the B-Tree. Parameters: blockSize - The size (in bytes) of a file block for a single node. | public | BTree(File dataFile, int blockSize, int valueSize, boolean forceSync) Creates a new BTree that uses an instance of
DefaultRecordComparator to compare values.
Parameters: dataFile - The file for the B-Tree. Parameters: blockSize - The size (in bytes) of a file block for a single node. | public | BTree(File dataFile, 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.
Parameters: dataFile - The file for the B-Tree. Parameters: blockSize - The size (in bytes) of a file block for a single node. | public | BTree(File dataFile, 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.
Parameters: dataFile - The file for the B-Tree. Parameters: blockSize - The size (in bytes) of a file block for a single node. |
Method Summary | |
public void | clear() Removes all values from the B-Tree. | public void | close() Closes any opened files and release any resources used by this B-Tree. | public byte[] | get(byte[] key) Gets the value that matches the specified key.
Parameters: key - A value that is equal to the value that should be retrieved, atleast as far as the RecordComparator of this BTree is concerned. | public File | getFile() Gets the file that this BTree operates on. | public long | getValueCountEstimate() Returns an estimate for the number of values stored in this BTree. | public byte[] | insert(byte[] value) Inserts the supplied value into the B-Tree. | public RecordIterator | iterateAll() Returns an iterator that iterates over all values in this B-Tree. | public RecordIterator | iterateRange(byte[] minValue, byte[] maxValue) Returns an iterator that iterates over all values between minValue and
maxValue, inclusive. | public 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. | public 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. | public static void | main(String[] args) | public void | print(PrintStream out) | public byte[] | remove(byte[] key) Removes the value that matches the specified key from the B-Tree.
Parameters: key - A key that matches the value that should be removed from theB-Tree. | public static void | runDebugTest(String[] args) | public static void | runPerformanceTest(String[] args) | public void | sync() Writes any changes that are cached in memory to disk. |
BTree | public BTree(File dataFile, int blockSize, int valueSize) throws IOException(Code) | | Creates a new BTree that uses an instance of
DefaultRecordComparator to compare values.
Parameters: dataFile - The file for the B-Tree. Parameters: blockSize - The size (in bytes) of a file block for a single node. Ideally, thesize specified is the size of a block in the used file system. Parameters: valueSize - The size (in bytes) of the fixed-length values that are or will bestored in the B-Tree. throws: IOException - In case the initialization of the B-Tree file failed. See Also: DefaultRecordComparator |
BTree | public BTree(File dataFile, int blockSize, int valueSize, boolean forceSync) throws IOException(Code) | | Creates a new BTree that uses an instance of
DefaultRecordComparator to compare values.
Parameters: dataFile - The file for the B-Tree. Parameters: blockSize - The size (in bytes) of a file block for a single node. Ideally, thesize specified is the size of a block in the used file system. Parameters: valueSize - The size (in bytes) of the fixed-length values that are or will bestored in the B-Tree. Parameters: forceSync - Flag indicating whether updates should be synced to disk forcefullyby calling FileChannel.force(boolean). This may have asevere impact on write performance. throws: IOException - In case the initialization of the B-Tree file failed. See Also: DefaultRecordComparator |
BTree | public BTree(File dataFile, int blockSize, int valueSize, RecordComparator comparator) throws IOException(Code) | | Creates a new BTree that uses the supplied RecordComparator to
compare the values that are or will be stored in the B-Tree.
Parameters: dataFile - The file for the B-Tree. Parameters: blockSize - The size (in bytes) of a file block for a single node. Ideally, thesize specified is the size of a block in the used file system. Parameters: valueSize - The size (in bytes) of the fixed-length values that are or will bestored in the B-Tree. Parameters: comparator - The RecordComparator to use for determining whether onevalue is smaller, larger or equal to another. throws: IOException - In case the initialization of the B-Tree file failed. |
BTree | public BTree(File dataFile, int blockSize, int valueSize, RecordComparator comparator, boolean forceSync) throws IOException(Code) | | Creates a new BTree that uses the supplied RecordComparator to
compare the values that are or will be stored in the B-Tree.
Parameters: dataFile - The file for the B-Tree. Parameters: blockSize - The size (in bytes) of a file block for a single node. Ideally, thesize specified is the size of a block in the used file system. Parameters: valueSize - The size (in bytes) of the fixed-length values that are or will bestored in the B-Tree. Parameters: comparator - The RecordComparator to use for determining whether onevalue is smaller, larger or equal to another. Parameters: forceSync - Flag indicating whether updates should be synced to disk forcefullyby calling FileChannel.force(boolean). This may have asevere impact on write performance. throws: IOException - In case the initialization of the B-Tree file failed. |
close | public void close() throws IOException(Code) | | Closes any opened files and release any resources used by this B-Tree. Any
pending changes will be synchronized to disk before closing. Once the
B-Tree has been closes, it can no longer be used.
|
get | public byte[] get(byte[] key) throws IOException(Code) | | Gets the value that matches the specified key.
Parameters: key - A value that is equal to the value that should be retrieved, atleast as far as the RecordComparator of this BTree is concerned. The value matching the key, or null if no such valuecould be found. |
getFile | public File getFile()(Code) | | Gets the file that this BTree operates on.
|
getValueCountEstimate | public long getValueCountEstimate() throws IOException(Code) | | Returns an estimate for the number of values stored in this BTree.
|
insert | public byte[] insert(byte[] value) throws IOException(Code) | | Inserts the supplied value into the B-Tree. In case an equal value is
already present in the B-Tree this value is overwritten with the new value
and the old value is returned by this method.
Parameters: value - The value to insert into the B-Tree. The old value that was replaced, if any. throws: IOException - If an I/O error occurred. |
iterateAll | public RecordIterator iterateAll()(Code) | | Returns an iterator that iterates over all values in this B-Tree.
|
iterateRange | public RecordIterator iterateRange(byte[] minValue, byte[] maxValue)(Code) | | Returns an iterator that iterates over all values between minValue and
maxValue, inclusive.
|
iterateRangedValues | public RecordIterator iterateRangedValues(byte[] searchKey, byte[] searchMask, byte[] minValue, byte[] maxValue)(Code) | | 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.
|
iterateValues | public RecordIterator iterateValues(byte[] searchKey, byte[] searchMask)(Code) | | 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.
|
remove | public byte[] remove(byte[] key) throws IOException(Code) | | Removes the value that matches the specified key from the B-Tree.
Parameters: key - A key that matches the value that should be removed from theB-Tree. The value that was removed from the B-Tree, or null ifno matching value was found. throws: IOException - If an I/O error occurred. |
|
|