Class FixedRecordList

java.lang.Object
com.mckoi.database.FixedRecordList

public class FixedRecordList extends Object
A structure that provides a fast way to read and write fixed sized nodes in a Store object. Each node in the list is of fixed size.

This structure can locate a node in the list very quickly. However, the structure can not be mutated. For example, deleting node '4' will make the node available for recycling but will not shift any nodes after 4 in the list up by one.

Once a node is allocated from the list its position will not change.

This structure does not provide versioning features.

The structure is composed of two element types - the header and the list block elements. The header is resembled by the following diagram;

LIST BLOCK HEADER +-------------------------------+ | 4 MAGIC | | 4 list block count | | 8 (reserved for delete chain) | | 8 pointer to list block 0 | | 8 pointer to list block 1 | . ... etc ... . | 8 pointer to list block 63 | +-------------------------------+

The first list block element is 32 entries in size, the second list block is 64 entries in size, etc. Each entry of the list block element is of fixed size.

This class is NOT thread safe.

Author:
Tobias Downer
  • Constructor Summary

    Constructors
    Constructor
    Description
    FixedRecordList(Store store, int element_size)
    Constructs the structure.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Adds to the given ArrayList all the areas in the store that are used by this structure (as Long).
    long
    Returns the total number of nodes that are currently addressable by this list structure.
    long
    Creates the structure in the store, and returns a pointer to the structure.
    void
    Decreases the size of the list structure.
    long
    Returns the 8 byte long that is reserved for storing the delete chain (if there is one).
    void
    Increases the size of the list structure so it may accomodate more record entries.
    void
    init(long list_pointer)
    Initializes the structure from the store.
    int
    Returns the number of block elements in this list structure.
    long
    listBlockFirstPosition(int block_number)
    Returns the index of the first node in the given block number.
    long
    listBlockNodeCount(int block_number)
    Returns the number of nodes that can be stored in the given block, where block 0 is the first block (32 addressable nodes).
    positionOnNode(long record_number)
    Returns an Area object from the list block area with the position over the record entry requested.
    void
    Sets the 8 byte long that is reserved for storing the delete chain (if there is one).

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • FixedRecordList

      public FixedRecordList(Store store, int element_size)
      Constructs the structure.
  • Method Details

    • create

      public long create() throws IOException
      Creates the structure in the store, and returns a pointer to the structure.
      Throws:
      IOException
    • init

      public void init(long list_pointer) throws IOException
      Initializes the structure from the store.
      Throws:
      IOException
    • addAllAreasUsed

      public void addAllAreasUsed(ArrayList list) throws IOException
      Adds to the given ArrayList all the areas in the store that are used by this structure (as Long).
      Throws:
      IOException
    • getReservedLong

      public long getReservedLong() throws IOException
      Returns the 8 byte long that is reserved for storing the delete chain (if there is one).
      Throws:
      IOException
    • setReservedLong

      public void setReservedLong(long v) throws IOException
      Sets the 8 byte long that is reserved for storing the delete chain (if there is one).
      Throws:
      IOException
    • positionOnNode

      public MutableArea positionOnNode(long record_number) throws IOException
      Returns an Area object from the list block area with the position over the record entry requested. Note that the Area object can only be safely used if there is a guarentee that no other access to this object while the area object is accessed.
      Throws:
      IOException
    • listBlockCount

      public int listBlockCount()
      Returns the number of block elements in this list structure. This will return a number between 0 and 63 (inclusive).
    • addressableNodeCount

      public long addressableNodeCount()
      Returns the total number of nodes that are currently addressable by this list structure. For example, if the list contains 0 blocks then there are no addressable nodes. If it contains 1 block, there are 32 addressable nodes. If it contains 2 blocks, there are 64 + 32 = 96 nodes. 3 blocks = 128 + 64 + 32 = 224 nodes.
    • listBlockNodeCount

      public long listBlockNodeCount(int block_number)
      Returns the number of nodes that can be stored in the given block, where block 0 is the first block (32 addressable nodes).
    • listBlockFirstPosition

      public long listBlockFirstPosition(int block_number)
      Returns the index of the first node in the given block number. For example, this first node of block 0 is 0, the first node of block 1 is 32, the first node of block 2 is 96, etc.
    • increaseSize

      public void increaseSize() throws IOException
      Increases the size of the list structure so it may accomodate more record entries. This simply adds a new block for more nodes.
      Throws:
      IOException
    • decreaseSize

      public void decreaseSize() throws IOException
      Decreases the size of the list structure. This should be used with care because it deletes all nodes in the last block.
      Throws:
      IOException