de.lmu.ifi.dbs.elki.index.tree
Class TreeIndexHeader

java.lang.Object
  extended by de.lmu.ifi.dbs.elki.persistent.DefaultPageHeader
      extended by de.lmu.ifi.dbs.elki.index.tree.TreeIndexHeader
All Implemented Interfaces:
PageHeader
Direct Known Subclasses:
MkTreeHeader

public class TreeIndexHeader
extends DefaultPageHeader

Encapsulates the header information of a tree-like index structure. This information is needed for persistent storage.


Field Summary
(package private)  int dirCapacity
          The capacity of a directory node (= 1 + maximum number of entries in a directory node).
(package private)  int dirMinimum
          The minimum number of entries in a directory node.
private  int emptyPagesSize
          The number of bytes additionally needed for the listing of empty pages of the headed page file.
private  int largestPageID
          The largest ID used so far
(package private)  int leafCapacity
          The capacity of a leaf node (= 1 + maximum number of entries in a leaf node).
(package private)  int leafMinimum
          The minimum number of entries in a leaf node.
private static int SIZE
          The size of this header in Bytes, which is 20 Bytes ( 4 Bytes for dirCapacity, leafCapacity, dirMinimum, leafMinimum, and emptyPagesSize).
 
Constructor Summary
TreeIndexHeader()
          Empty constructor for serialization.
TreeIndexHeader(int pageSize, int dirCapacity, int leafCapacity, int dirMinimum, int leafMinimum)
          Creates a new header with the specified parameters.
 
Method Summary
 int getDirCapacity()
          Returns the capacity of a directory node (= 1 + maximum number of entries in a directory node).
 int getDirMinimum()
          Returns the minimum number of entries in a directory node.
 int getEmptyPagesSize()
           
 int getLargestPageID()
           
 int getLeafCapacity()
          Returns the capacity of a leaf node (= 1 + maximum number of entries in a leaf node).
 int getLeafMinimum()
          Returns the minimum number of entries in a leaf node.
 Stack<Integer> readEmptyPages(RandomAccessFile file)
          Read the empty pages from the end of file.
 void readHeader(RandomAccessFile file)
          Initializes this header from the specified file.
 void setEmptyPagesSize(int emptyPagesSize)
          Set the size required by the listing of empty pages.
 void setLargestPageID(int largestPageID)
           
 int size()
          Returns DefaultPageHeader.size() plus the value of SIZE).
 void writeEmptyPages(Stack<Integer> emptyPages, RandomAccessFile file)
          Write the indices of empty pages the the end of file.
 void writeHeader(RandomAccessFile file)
          Writes this header to the specified file.
 
Methods inherited from class de.lmu.ifi.dbs.elki.persistent.DefaultPageHeader
asByteArray, getPageSize, getReservedPages, readHeader
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SIZE

private static int SIZE
The size of this header in Bytes, which is 20 Bytes ( 4 Bytes for dirCapacity, leafCapacity, dirMinimum, leafMinimum, and emptyPagesSize).


dirCapacity

int dirCapacity
The capacity of a directory node (= 1 + maximum number of entries in a directory node).


leafCapacity

int leafCapacity
The capacity of a leaf node (= 1 + maximum number of entries in a leaf node).


dirMinimum

int dirMinimum
The minimum number of entries in a directory node.


leafMinimum

int leafMinimum
The minimum number of entries in a leaf node.


emptyPagesSize

private int emptyPagesSize
The number of bytes additionally needed for the listing of empty pages of the headed page file.


largestPageID

private int largestPageID
The largest ID used so far

Constructor Detail

TreeIndexHeader

public TreeIndexHeader()
Empty constructor for serialization.


TreeIndexHeader

public TreeIndexHeader(int pageSize,
                       int dirCapacity,
                       int leafCapacity,
                       int dirMinimum,
                       int leafMinimum)
Creates a new header with the specified parameters.

Parameters:
pageSize - the size of a page in bytes
dirCapacity - the maximum number of entries in a directory node
leafCapacity - the maximum number of entries in a leaf node
dirMinimum - the minimum number of entries in a directory node
leafMinimum - the minimum number of entries in a leaf node
Method Detail

readHeader

public void readHeader(RandomAccessFile file)
                throws IOException
Initializes this header from the specified file. Calls DefaultPageHeader#readHeader(file) and reads the integer values of dirCapacity, leafCapacity, dirMinimum, leafMinimum and emptyPagesSize from the file.

Specified by:
readHeader in interface PageHeader
Overrides:
readHeader in class DefaultPageHeader
Parameters:
file - the file to which this header belongs
Throws:
IOException - if an I/O-error occurs during reading

writeHeader

public void writeHeader(RandomAccessFile file)
                 throws IOException
Writes this header to the specified file. Writes the integer values of dirCapacity, leafCapacity, dirMinimum, leafMinimum and emptyPagesSize to the file.

Specified by:
writeHeader in interface PageHeader
Overrides:
writeHeader in class DefaultPageHeader
Parameters:
file - the file to which this header belongs
Throws:
IOException - IOException if an I/O-error occurs during writing

getDirCapacity

public int getDirCapacity()
Returns the capacity of a directory node (= 1 + maximum number of entries in a directory node).

Returns:
the capacity of a directory node (= 1 + maximum number of entries in a directory node)

getLeafCapacity

public int getLeafCapacity()
Returns the capacity of a leaf node (= 1 + maximum number of entries in a leaf node).

Returns:
the capacity of a leaf node (= 1 + maximum number of entries in a leaf node)

getDirMinimum

public int getDirMinimum()
Returns the minimum number of entries in a directory node.

Returns:
the minimum number of entries in a directory node

getLeafMinimum

public int getLeafMinimum()
Returns the minimum number of entries in a leaf node.

Returns:
the minimum number of entries in a leaf node

getEmptyPagesSize

public int getEmptyPagesSize()
Returns:
the number of bytes needed for the listing of empty pages

setEmptyPagesSize

public void setEmptyPagesSize(int emptyPagesSize)
Set the size required by the listing of empty pages.

Parameters:
emptyPagesSize - the number of bytes needed for this listing of empty pages

getLargestPageID

public int getLargestPageID()

setLargestPageID

public void setLargestPageID(int largestPageID)

size

public int size()
Returns DefaultPageHeader.size() plus the value of SIZE). Note, this is only the base size and probably not the overall size of this header, as there may be empty pages to be maintained.

Specified by:
size in interface PageHeader
Overrides:
size in class DefaultPageHeader
Returns:
the size of this header in Bytes

writeEmptyPages

public void writeEmptyPages(Stack<Integer> emptyPages,
                            RandomAccessFile file)
                     throws IOException
Write the indices of empty pages the the end of file. Calling this method should be followed by a writeHeader(RandomAccessFile).

Parameters:
emptyPages - the stack of empty page ids which remain to be filled
file - File to work with
Throws:
IOException - thrown on IO errors

readEmptyPages

public Stack<Integer> readEmptyPages(RandomAccessFile file)
                              throws IOException,
                                     ClassNotFoundException
Read the empty pages from the end of file.

Parameters:
file - File to work with
Returns:
a stack of empty pages in file
Throws:
IOException - thrown on IO errors
ClassNotFoundException - if the stack of empty pages could not be correctly read from file

Release 0.4.0 (2011-09-20_1324)