Package com.mckoi.database

## Class FixedRecordList

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

    public class FixedRecordList
    extends java.lang.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
`FixedRecordList​(Store store, int element_size)` Constructs the structure.

### Method Summary

All Methods Instance Methods Concrete Methods
`void` `addAllAreasUsed​(java.util.ArrayList list)` Adds to the given ArrayList all the areas in the store that are used by this structure (as Long).
`long` `addressableNodeCount()` Returns the total number of nodes that are currently addressable by this list structure.
`long` `create()` Creates the structure in the store, and returns a pointer to the structure.
`void` `decreaseSize()` Decreases the size of the list structure.
`long` `getReservedLong()` Returns the 8 byte long that is reserved for storing the delete chain (if there is one).
`void` `increaseSize()` 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` `listBlockCount()` 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).
`MutableArea` `positionOnNode​(long record_number)` Returns an Area object from the list block area with the position over the record entry requested.
`void` `setReservedLong​(long v)` 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 Detail

#### FixedRecordList

    public FixedRecordList​(Store store,
                           int element_size)

Constructs the structure.

### Method Detail

#### create

    public long create()
                throws java.io.IOException

Creates the structure in the store, and returns a pointer to the structure.

Throws:
  `java.io.IOException`

#### init

    public void init​(long list_pointer)
              throws java.io.IOException

Initializes the structure from the store.

Throws:
  `java.io.IOException`

#### addAllAreasUsed

    public void addAllAreasUsed​(java.util.ArrayList list)
                         throws java.io.IOException

Adds to the given ArrayList all the areas in the store that are used by this structure (as Long).

Throws:
  `java.io.IOException`

#### getReservedLong

    public long getReservedLong()
                         throws java.io.IOException

Returns the 8 byte long that is reserved for storing the delete chain (if there is one).

Throws:
  `java.io.IOException`

#### setReservedLong

    public void setReservedLong​(long v)
                         throws java.io.IOException

Sets the 8 byte long that is reserved for storing the delete chain (if there is one).

Throws:
  `java.io.IOException`

#### positionOnNode

    public MutableArea positionOnNode​(long record_number)
                               throws java.io.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:
  `java.io.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 java.io.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:
  `java.io.IOException`

#### decreaseSize

    public void decreaseSize()
                      throws java.io.IOException

Decreases the size of the list structure. This should be used with care because it deletes all nodes in the last block.

Throws:
  `java.io.IOException`