Package edu.caltech.nanodb.storage
Class FilePointer
- java.lang.Object
-
- edu.caltech.nanodb.storage.FilePointer
-
- All Implemented Interfaces:
java.lang.Cloneable
,java.lang.Comparable<FilePointer>
public class FilePointer extends java.lang.Object implements java.lang.Comparable<FilePointer>, java.lang.Cloneable
This class represents a pointer to a location within a database file. Because database files are broken into pages, the pointer contains the (zero-based) page number of the data, and the (zero-based) offset of the data within the page.File pointers themselves can be stored into database files for various purposes. The information is stored as follows:
- The page number is stored as a signed 32-bit value.
- The offset is stored as an unsigned 16-bit value. (Note that database files are limited to a maximum page-size of 64 Kbytes.)
-
-
Field Summary
Fields Modifier and Type Field Description private int
offset
The offset of the data within the page.private int
pageNo
The page number in the table file.static FilePointer
ZERO_FILE_POINTER
-
Constructor Summary
Constructors Constructor Description FilePointer(int pageNo, int offset)
Construct a new file pointer.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.Object
clone()
int
compareTo(FilePointer filePointer)
boolean
equals(java.lang.Object obj)
Returns true ifobj
refers to aFilePointer
with the same internal values.int
getOffset()
Returns the offset within the page where the data starts.int
getPageNo()
Returns the page number that the data is in.int
hashCode()
Calculate a hash-code for the file pointer.java.lang.String
toString()
-
-
-
Field Detail
-
ZERO_FILE_POINTER
public static final FilePointer ZERO_FILE_POINTER
-
pageNo
private int pageNo
The page number in the table file. This value is nonnegative.
-
offset
private int offset
The offset of the data within the page. This value is nonnegative.
-
-
Method Detail
-
getPageNo
public int getPageNo()
Returns the page number that the data is in.
-
getOffset
public int getOffset()
Returns the offset within the page where the data starts.
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
equals
public boolean equals(java.lang.Object obj)
Returns true ifobj
refers to aFilePointer
with the same internal values.- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
Calculate a hash-code for the file pointer.- Overrides:
hashCode
in classjava.lang.Object
-
compareTo
public int compareTo(FilePointer filePointer)
- Specified by:
compareTo
in interfacejava.lang.Comparable<FilePointer>
-
clone
public java.lang.Object clone() throws java.lang.CloneNotSupportedException
- Overrides:
clone
in classjava.lang.Object
- Throws:
java.lang.CloneNotSupportedException
-
-