Class TreeIndexHeader

  • All Implemented Interfaces:
    PageHeader
    Direct Known Subclasses:
    MkTreeHeader, RdKNNTreeHeader

    public class TreeIndexHeader
    extends DefaultPageHeader
    Encapsulates the header information of a tree-like index structure. This information is needed for persistent storage.
    Since:
    0.1
    Author:
    Elke Achtert
    • Field Summary

      Fields 
      Modifier and Type Field Description
      (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, emptyPagesSize), and largestPageID.
    • Constructor Summary

      Constructors 
      Constructor Description
      TreeIndexHeader()
      Empty constructor for serialization.
      TreeIndexHeader​(int pageSize, int dirCapacity, int leafCapacity, int dirMinimum, int leafMinimum)
      Creates a new header with the specified parameters.
    • Field Detail

      • 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

      • 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​(IntegerArray emptyPages,
                                    java.nio.channels.FileChannel file)
                             throws java.io.IOException
        Write the indices of empty pages the the end of file. Calling this method should be followed by a PageHeader.writeHeader(FileChannel).
        Parameters:
        emptyPages - the stack of empty page ids which remain to be filled
        file - File to work with
        Throws:
        java.io.IOException - thrown on IO errors
      • readEmptyPages

        public IntegerArray readEmptyPages​(java.nio.channels.FileChannel file)
                                    throws java.io.IOException,
                                           java.lang.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:
        java.io.IOException - thrown on IO errors
        java.lang.ClassNotFoundException - if the stack of empty pages could not be correctly read from file