Package elki.persistent
Class OnDiskArrayPageFile<P extends Page>
- java.lang.Object
-
- elki.persistent.AbstractPageFile<P>
-
- elki.persistent.AbstractStoringPageFile<P>
-
- elki.persistent.OnDiskArrayPageFile<P>
-
- Type Parameters:
P- Page type
- All Implemented Interfaces:
PageFile<P>
public class OnDiskArrayPageFile<P extends Page> extends AbstractStoringPageFile<P>
A OnDiskArrayPageFile stores objects persistently that implement thePageinterface. For convenience each page is represented by a single file. All pages are stored in a specified directory.- Since:
- 0.1
- Author:
- Elke Achtert
-
-
Field Summary
Fields Modifier and Type Field Description private static intEMPTY_PAGEIndicates an empty page.private booleanexistedWhether or not the file originally existedprivate OnDiskArrayfileThe file storing the pages.private java.nio.file.PathfilenameThe file name to useprivate static intFILLED_PAGEIndicates a filled page.protected PageHeaderheaderThe header of this page file.private static LoggingLOGClass logger.-
Fields inherited from class elki.persistent.AbstractStoringPageFile
emptyPages, nextPageID, pageSize
-
-
Constructor Summary
Constructors Constructor Description OnDiskArrayPageFile(int pageSize, java.nio.file.Path filename)Creates a new OnDiskArrayPageFile from an existing file.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private PbyteBufferToPage(java.nio.ByteBuffer buffer)Reconstruct a serialized object from the specified byte array.voidclear()Clears this PageFile.voidclose()Closes this file.voiddeletePage(int pageID)Deletes the node with the specified id from this file.protected LogginggetLogger()Get the class logger.booleaninitialize(PageHeader header)Initialize the page file with the given header - return "true" if the file already existed.private byte[]pageToByteArray(P page)Serializes an object into a byte array.PreadPage(int pageID)Reads the page with the given id from this file.voidwritePage(int pageID, P page)Write page to disk.-
Methods inherited from class elki.persistent.AbstractStoringPageFile
getNextPageID, getPageSize, logStatistics, setNextPageID, setPageID
-
Methods inherited from class elki.persistent.AbstractPageFile
countRead, countWrite, writePage
-
-
-
-
Field Detail
-
LOG
private static final Logging LOG
Class logger.
-
EMPTY_PAGE
private static final int EMPTY_PAGE
Indicates an empty page.- See Also:
- Constant Field Values
-
FILLED_PAGE
private static final int FILLED_PAGE
Indicates a filled page.- See Also:
- Constant Field Values
-
filename
private java.nio.file.Path filename
The file name to use
-
file
private OnDiskArray file
The file storing the pages.
-
header
protected PageHeader header
The header of this page file.
-
existed
private final boolean existed
Whether or not the file originally existed
-
-
Method Detail
-
readPage
public P readPage(int pageID)
Reads the page with the given id from this file.- Parameters:
pageID- the id of the page to be returned- Returns:
- the page with the given pageId
-
deletePage
public void deletePage(int pageID)
Deletes the node with the specified id from this file.- Specified by:
deletePagein interfacePageFile<P extends Page>- Overrides:
deletePagein classAbstractStoringPageFile<P extends Page>- Parameters:
pageID- the id of the node to be deleted
-
writePage
public void writePage(int pageID, P page)Write page to disk.- Specified by:
writePagein classAbstractPageFile<P extends Page>- Parameters:
pageID- page idpage- the page which has to be written to disk
-
close
public void close()
Closes this file.
-
clear
public void clear()
Clears this PageFile.
-
byteBufferToPage
private P byteBufferToPage(java.nio.ByteBuffer buffer)
Reconstruct a serialized object from the specified byte array.- Parameters:
buffer- the buffer from which the object should be reconstructed- Returns:
- a serialized object from the specified byte array
-
pageToByteArray
private byte[] pageToByteArray(P page)
Serializes an object into a byte array.- Parameters:
page- the object to be serialized- Returns:
- the byte array
-
initialize
public boolean initialize(PageHeader header)
Description copied from class:AbstractStoringPageFileInitialize the page file with the given header - return "true" if the file already existed.- Specified by:
initializein interfacePageFile<P extends Page>- Overrides:
initializein classAbstractStoringPageFile<P extends Page>- Parameters:
header- Header- Returns:
- true when the file already existed.
-
getLogger
protected Logging getLogger()
Description copied from class:AbstractPageFileGet the class logger.- Specified by:
getLoggerin classAbstractPageFile<P extends Page>- Returns:
- Logger
-
-