Class VarSizeMultiBlock

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

public class VarSizeMultiBlock extends Object
This class is used when the key data exceeds the size of block.

In this case a sequence of blocks is allocated to store the data.

This class acts like a window to the currently selected block within this sequence.

The data is accessed here in the sequential manner.

  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    Creates a multi block
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    compare(byte[] key)
    Compares the provided key data array to the data stored in the multi block sequence
    void
    Free all the blocks in the multi block sequence
    byte[]
    get()
    Reads the data from the multi block sequence and stores it to the data array
    Provides a block associated with current position
    int
    Provides the data stored in this block
    int
    Provides a total size of space within the current block
    long
    Provides the total size of the data stored in the multi block
    int
    Provides a header size in bytes.
    long
    Provides the index of the next block
    long
    Provides the total size stored in the multi block as stored in the header
    boolean
    Identifies if this is the first block in the sequence
    boolean
    Moves to the next block
    long
    put(byte[] data)
    Stores the key data to the multi block sequence.
    void
    Resets the currently selected block to the first block
     

    Methods inherited from class java.lang.Object

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

    • VarSizeMultiBlock

      protected VarSizeMultiBlock(VarSizeBlock root)
      Creates a multi block
      Parameters:
      root - the root block
  • Method Details

    • toString

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

      public long getNextBlockIndex()
      Provides the index of the next block

      This is only non-zero if there is the next block

      Returns:
      the index of the next block
    • free

      public void free()
      Free all the blocks in the multi block sequence
    • next

      public boolean next()
      Moves to the next block
      Returns:
      true if there is new block
    • getBlock

      public Block getBlock()
      Provides a block associated with current position
      Returns:
      the block
    • getHeaderSize

      public int getHeaderSize()
      Provides a header size in bytes.

      For multi block the first block in the sequence will have a greater header than the rest

      Returns:
      the size in bytes
    • isRoot

      public boolean isRoot()
      Identifies if this is the first block in the sequence
      Returns:
      true if it is the first one
    • getDataSize

      public long getDataSize()
      Provides the total size of the data stored in the multi block
      Returns:
      the size of data in bytes
    • put

      public long put(byte[] data)
      Stores the key data to the multi block sequence.

      Blocks are allocated as they requested.

      Parameters:
      data - the key data to store
      Returns:
      the index of the first block
    • getDataCapacity

      public int getDataCapacity()
      Provides a total size of space within the current block
      Returns:
      the capacity of bytes
    • getTotalDataSize

      public long getTotalDataSize()
      Provides the total size stored in the multi block as stored in the header
      Returns:
      the size in bytes
    • getBlockDataSize

      public int getBlockDataSize()
      Provides the data stored in this block
      Returns:
      the size in bytes
    • compare

      public int compare(byte[] key)
      Compares the provided key data array to the data stored in the multi block sequence
      Parameters:
      key - the data to be compared with stored
      Returns:
      negative: current less than key, positive: current more than key, 0 if they are equal
    • get

      public byte[] get()
      Reads the data from the multi block sequence and stores it to the data array
      Returns:
      the data of the key
    • root

      public void root()
      Resets the currently selected block to the first block