Class BPlusTreeFile<KeyType,KeyBufferType>
java.lang.Object
com.semedy.reasoner.edb.persistentstore.bplustree.BPlusTreeFile<KeyType,KeyBufferType>
- Type Parameters:
KeyType-KeyBufferType-
This file handles the writing of nodes to files and the reading of nodes back.
- Author:
- angele
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionBPlusTreeFile(String filename, int m, int keyLengthInBytes, int nodeLengthInBytes, KeysFactory<KeyType, KeyBufferType> keysFactory, LeafFactory<KeyType, KeyBufferType> leafFactory, BPlusTree<KeyType, KeyBufferType> bplustree, int additionalHeadSpace, boolean compress) General constructor. -
Method Summary
Modifier and TypeMethodDescriptionbooleancheckSanity(String message) checks sanityvoidclose()Close filevoidcreate()create filevoidflush()flush filebyte[]return file headergetNode(byte[] bytes, int offset) get node out of bytes and offsetlongget size of filebooleanopen()open fileintwrite flagslong[]readGrounds(long[] grounds) read groundsreadNode(int offset, boolean shadow) public method for reading a node at a given file offset.longread number of elementsintread offset of rootvoidreleaseNode(BPlusNode<KeyType, KeyBufferType> node, boolean shadow) free up disk space for bplus nodevoidbegin transactionvoidcommitvoidrollback transactionvoidwriteAdditionalHeadSpace(int additional) write additional headspace (used for grounds)voidwriteFlags(int flags) read flagsvoidwriteGrounds(long[] grounds) write groundsintwriteInternalNode(BPlusInternalNode<KeyType, KeyBufferType> toWrite, int offset) write an internal node at offsetintwriteLeaf(BPlusLeaf<KeyType, KeyBufferType> toWrite, int offset) write a leaf at offsetlongWrites a new internal node to the end of the file.intwriteNewLeaf(BPlusLeaf<KeyType, KeyBufferType> toWrite) Writes a new leaf to the end of the file.voidwriteNodeSize(int size) write node sizevoidwriteNumberOfElements(long numElements) write number of elementsvoidwriteRootOffset(int offset) write offset of root
-
Field Details
-
DEFAULT_FILE_NAME
- See Also:
-
-
Constructor Details
-
BPlusTreeFile
public BPlusTreeFile(String filename, int m, int keyLengthInBytes, int nodeLengthInBytes, KeysFactory<KeyType, KeyBufferType> keysFactory, LeafFactory<KeyType, throws IOException, EDBExceptionKeyBufferType> leafFactory, BPlusTree<KeyType, KeyBufferType> bplustree, int additionalHeadSpace, boolean compress) General constructor.- Parameters:
filename-m-keyLengthInBytes-nodeLengthInBytes-keysFactory-leafFactory-bplustree-additionalHeadSpace-- Throws:
IOExceptionEDBException
-
-
Method Details
-
getSizeOnDisc
public long getSizeOnDisc()get size of file- Returns:
-
open
open file- Returns:
- Throws:
EDBExceptionIOException
-
create
create file- Throws:
IOExceptionEDBException
-
getHeader
public byte[] getHeader()return file header- Returns:
-
checkSanity
checks sanity- Returns:
-
close
Close file- Throws:
IOException
-
flush
flush file- Throws:
IOException
-
transactionCommit
commit- Throws:
IOException
-
transactionRollback
rollback transaction- Throws:
IOException
-
transactionBegin
begin transaction- Throws:
IOException
-
readNode
public method for reading a node at a given file offset.
First determines the type of node, then calls the appropriate helper method.- Parameters:
offset-shadow- , read from shadow tree- Returns:
- Throws:
IOException
-
getNode
get node out of bytes and offset- Parameters:
bytes-offset-- Returns:
- Throws:
IOException
-
writeNewInternalNode
public long writeNewInternalNode(BPlusInternalNode<KeyType, KeyBufferType> toWrite) throws IOException, EDBExceptionWrites a new internal node to the end of the file.- Parameters:
toWrite-- Returns:
- location (file offset) of the leaf
- Throws:
IOExceptionEDBException
-
writeNewLeaf
Writes a new leaf to the end of the file.- Parameters:
toWrite-- Returns:
- location (file offset) of the leaf
- Throws:
IOExceptionEDBException
-
writeInternalNode
public int writeInternalNode(BPlusInternalNode<KeyType, KeyBufferType> toWrite, int offset) throws IOException, EDBExceptionwrite an internal node at offset- Parameters:
toWrite-offset-- Returns:
- Throws:
IOExceptionEDBException
-
writeLeaf
public int writeLeaf(BPlusLeaf<KeyType, KeyBufferType> toWrite, int offset) throws IOException, EDBExceptionwrite a leaf at offset- Parameters:
toWrite-offset-- Returns:
- Throws:
IOExceptionEDBException
-
releaseNode
free up disk space for bplus node- Parameters:
node-- Throws:
IOException
-
writeNumberOfElements
public void writeNumberOfElements(long numElements) write number of elements- Parameters:
numElements-
-
readNumberOfElements
public long readNumberOfElements()read number of elements- Returns:
-
readFlags
write flags- Returns:
- Throws:
IOException
-
writeFlags
read flags- Parameters:
flags-- Throws:
IOException
-
writeNodeSize
public void writeNodeSize(int size) write node size- Parameters:
size-
-
writeRootOffset
public void writeRootOffset(int offset) write offset of root- Parameters:
offset-
-
readRootOffset
public int readRootOffset()read offset of root- Returns:
-
writeAdditionalHeadSpace
write additional headspace (used for grounds)- Parameters:
additional-- Throws:
IOException
-
writeGrounds
write grounds- Parameters:
grounds-- Throws:
IOException
-
readGrounds
read grounds- Parameters:
grounds-- Returns:
- Throws:
IOException
-