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 thePage
interface. 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 int
EMPTY_PAGE
Indicates an empty page.private boolean
existed
Whether or not the file originally existedprivate OnDiskArray
file
The file storing the pages.private java.nio.file.Path
filename
The file name to useprivate static int
FILLED_PAGE
Indicates a filled page.protected PageHeader
header
The header of this page file.private static Logging
LOG
Class 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 P
byteBufferToPage(java.nio.ByteBuffer buffer)
Reconstruct a serialized object from the specified byte array.void
clear()
Clears this PageFile.void
close()
Closes this file.void
deletePage(int pageID)
Deletes the node with the specified id from this file.protected Logging
getLogger()
Get the class logger.boolean
initialize(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.P
readPage(int pageID)
Reads the page with the given id from this file.void
writePage(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:
deletePage
in interfacePageFile<P extends Page>
- Overrides:
deletePage
in 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:
writePage
in 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:AbstractStoringPageFile
Initialize the page file with the given header - return "true" if the file already existed.- Specified by:
initialize
in interfacePageFile<P extends Page>
- Overrides:
initialize
in classAbstractStoringPageFile<P extends Page>
- Parameters:
header
- Header- Returns:
- true when the file already existed.
-
getLogger
protected Logging getLogger()
Description copied from class:AbstractPageFile
Get the class logger.- Specified by:
getLogger
in classAbstractPageFile<P extends Page>
- Returns:
- Logger
-
-