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 TypeMethodDescriptionboolean
checkSanity
(String message) checks sanityvoid
close()
Close filevoid
create()
create filevoid
flush()
flush filebyte[]
return file headergetNode
(byte[] bytes, int offset) get node out of bytes and offsetlong
get size of fileboolean
open()
open fileint
write flagslong[]
readGrounds
(long[] grounds) read groundsreadNode
(int offset, boolean shadow) public method for reading a node at a given file offset.long
read number of elementsint
read offset of rootvoid
releaseNode
(BPlusNode<KeyType, KeyBufferType> node, boolean shadow) free up disk space for bplus nodevoid
begin transactionvoid
commitvoid
rollback transactionvoid
writeAdditionalHeadSpace
(int additional) write additional headspace (used for grounds)void
writeFlags
(int flags) read flagsvoid
writeGrounds
(long[] grounds) write groundsint
writeInternalNode
(BPlusInternalNode<KeyType, KeyBufferType> toWrite, int offset) write an internal node at offsetint
writeLeaf
(BPlusLeaf<KeyType, KeyBufferType> toWrite, int offset) write a leaf at offsetlong
Writes a new internal node to the end of the file.int
writeNewLeaf
(BPlusLeaf<KeyType, KeyBufferType> toWrite) Writes a new leaf to the end of the file.void
writeNodeSize
(int size) write node sizevoid
writeNumberOfElements
(long numElements) write number of elementsvoid
writeRootOffset
(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:
IOException
EDBException
-
-
Method Details
-
getSizeOnDisc
public long getSizeOnDisc()get size of file- Returns:
-
open
open file- Returns:
- Throws:
EDBException
IOException
-
create
create file- Throws:
IOException
EDBException
-
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:
IOException
EDBException
-
writeNewLeaf
Writes a new leaf to the end of the file.- Parameters:
toWrite
-- Returns:
- location (file offset) of the leaf
- Throws:
IOException
EDBException
-
writeInternalNode
public int writeInternalNode(BPlusInternalNode<KeyType, KeyBufferType> toWrite, int offset) throws IOException, EDBExceptionwrite an internal node at offset- Parameters:
toWrite
-offset
-- Returns:
- Throws:
IOException
EDBException
-
writeLeaf
public int writeLeaf(BPlusLeaf<KeyType, KeyBufferType> toWrite, int offset) throws IOException, EDBExceptionwrite a leaf at offset- Parameters:
toWrite
-offset
-- Returns:
- Throws:
IOException
EDBException
-
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
-