Package elki.persistent
Class OnDiskUpperTriangleMatrix
- java.lang.Object
-
- elki.persistent.OnDiskUpperTriangleMatrix
-
- All Implemented Interfaces:
java.lang.AutoCloseable
public class OnDiskUpperTriangleMatrix extends java.lang.Object implements java.lang.AutoCloseableClass representing an upper triangle matrix backed by an on-disk array of O((n+1)*n/2) size- Since:
- 0.2
- Author:
- Erich Schubert
-
-
Field Summary
Fields Modifier and Type Field Description private OnDiskArrayarrayData storageprivate intmatrixsizeSize of the matrixprivate static longserialVersionUIDSerial number, also used for generating a magicprivate static intTRIANGLE_HEADER_SIZESize of this class' header
-
Constructor Summary
Constructors Constructor Description OnDiskUpperTriangleMatrix(java.nio.file.Path filename, int magicseed, int extraheadersize, int recordsize, boolean writable)Constructor to access an existing array.OnDiskUpperTriangleMatrix(java.nio.file.Path filename, int magicseed, int extraheadersize, int recordsize, int matrixsize)Constructor to access a new array.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private static intarraysize(int matrixsize)Compute the size of the needed backing array from the matrix dimensions.voidclose()Close the matrix file.private intcomputeOffset(int x, int y)Compute the offset within the file.intgetMatrixSize()Query the size of the matrix.java.nio.ByteBuffergetRecordBuffer(int x, int y)Get a record buffervoidresizeMatrix(int newsize)Resize the matrix to cover newsize x newsize.
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
Serial number, also used for generating a magic- See Also:
- Constant Field Values
-
TRIANGLE_HEADER_SIZE
private static final int TRIANGLE_HEADER_SIZE
Size of this class' header- See Also:
- Constant Field Values
-
matrixsize
private int matrixsize
Size of the matrix
-
array
private OnDiskArray array
Data storage
-
-
Constructor Detail
-
OnDiskUpperTriangleMatrix
public OnDiskUpperTriangleMatrix(java.nio.file.Path filename, int magicseed, int extraheadersize, int recordsize, boolean writable) throws java.io.IOExceptionConstructor to access an existing array.- Parameters:
filename- File namemagicseed- Magic numberextraheadersize- Size of extra header datarecordsize- Record sizewritable- flag to open writable- Throws:
java.io.IOException- on IO errors
-
OnDiskUpperTriangleMatrix
public OnDiskUpperTriangleMatrix(java.nio.file.Path filename, int magicseed, int extraheadersize, int recordsize, int matrixsize) throws java.io.IOExceptionConstructor to access a new array.- Parameters:
filename- File namemagicseed- Magic numberextraheadersize- Size of extra header datarecordsize- Record sizematrixsize- Size of matrix to store- Throws:
java.io.IOException- on IO errors
-
-
Method Detail
-
resizeMatrix
public void resizeMatrix(int newsize) throws java.io.IOExceptionResize the matrix to cover newsize x newsize.- Parameters:
newsize- New matrix size.- Throws:
java.io.IOException- on IO errors
-
arraysize
private static int arraysize(int matrixsize)
Compute the size of the needed backing array from the matrix dimensions.- Parameters:
matrixsize- size of the matrix- Returns:
- size of the array
-
computeOffset
private int computeOffset(int x, int y)Compute the offset within the file.- Parameters:
x- First coordinatey- Second coordinate- Returns:
- Linear offset
-
getRecordBuffer
public java.nio.ByteBuffer getRecordBuffer(int x, int y) throws java.io.IOExceptionGet a record buffer- Parameters:
x- First coordinatey- Second coordinate- Returns:
- Byte buffer for the record
- Throws:
java.io.IOException- on IO errors
-
close
public void close() throws java.io.IOExceptionClose the matrix file.- Specified by:
closein interfacejava.lang.AutoCloseable- Throws:
java.io.IOException- on IO errors
-
getMatrixSize
public int getMatrixSize()
Query the size of the matrix.- Returns:
- size of the matrix
-
-