Class VarSizeBlock

java.lang.Object
org.rostore.v2.keys.VarSizeBlock

public class VarSizeBlock extends Object
This class refer the sequence of entries of variable size, that are stored in the memory blocks.

This block can be set to get the data from the memory blocks in form of entries.

Each entry can stretch across several memory blocks (multi-block), and could also be several entries in one memory block, depending on the sizes of these entries.

In case of multi-block the memory blocks that store the entry are connected to the main one of the sequence.

The operations ot this class are steered heavily by the KeyBlockEntry, that initializes an object of this class based on the currently selected key-entry. Both classes work in conjunction and split the responsibility in a way that the KeyBlockEntry organizes a key fix-sized array, whereas this class manages the key payload itself.

A reference to the memory block where the var size block is stored is held by the KeyBlockEntry, as well as the size of the entry.

Header
number of byteswhat
1preamble: number of bytes for length encoding (multi) or 0
preamble = 1..4 (multi-block)
(bytesPerBlockIndex)next block index
(preamble)length of the data
preamble = 0 (multi-entries)
(bytesPerBlockOffset)length of data
  • Constructor Details

    • VarSizeBlock

      public VarSizeBlock(BlockProvider blockProvider)
  • Method Details

    • invalid

      public boolean invalid()
    • valid

      public boolean valid()
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • getMultiBlock

      public VarSizeMultiBlock getMultiBlock()
      Get the multi block.

      This one should be used only if the block is of multi-block type, check it by isMultiBlock()

      It is mutually exclusive to getEntry()

      Returns:
      the multi-block element
    • getEntry

      public VarSizeEntry getEntry()
      Get the entries in the block

      This one should be used in the multi-entry case, check it by isMultiEntry() ()}

      It is mutually exclusive to getMultiBlock()

      Returns:
      the var size entry
    • computeHeaderSize

      public int computeHeaderSize(byte preamble)
    • getBlockProvider

      public BlockProvider getBlockProvider()
    • getMultiEntryHeaderSize

      public int getMultiEntryHeaderSize()
    • getHeaderSize

      public int getHeaderSize()
      Get the header size of the current block

      Header is a non-payload administrative unit of memory.

      Returns:
      the size of the header in bytes
    • getPreamble

      protected byte getPreamble()
      Get a byte of preamble that defines a type of the block and encode a number of bytes needed to store the length of data in case of multi-block
      Returns:
      a value stored in the preamble
    • isMultiBlock

      public boolean isMultiBlock()
      If it is a multi-block block.

      It should contain several memory blocks to store the entry data.

      Returns:
      true if this block refers the multi-block
    • isMultiEntry

      public boolean isMultiEntry()
      If it is a multi-entry block (several entries in one block)
      Returns:
      true if this block refers the multi-entry
    • getBlock

      public Block getBlock()
    • getBlockIndex

      public long getBlockIndex()
      Gets the currently selected memory block, this entry works with.
      Returns:
      the memory block index
    • getDataCapacity

      public int getDataCapacity()
      Gets the total capacity in bytes of this block

      It also considers the header's size.

      Returns:
      the total payload size
    • compare

      public int compare(byte[] key)
    • get

      public byte[] get()
      Gets the data payload for currently selected entry
      Returns:
      the payload
    • moveTo

      public void moveTo(long blockIndex)
      Selects the current memory block.
      Parameters:
      blockIndex - the block index to select