Class VarSizeEntry

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

public class VarSizeEntry extends Object
Manages several variable-sized entries in one block.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates the instance of entry
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    compare(byte[] data)
    Compares the currently selected entry with the data provided
    void
    expand(byte[] data)
    Expands the block by adding the data provided to the end of the block.
    byte[]
    Extracts the currently selected entry as a byte array
    int
    Gets the total capacity of the block
    int
    Gets the total size of payload stored in the block.
    int
    Gets the currently selected entry's size
    int
    Gets the free space within the current block
    int
    Gets the current offset within a block.
    int
    Returns the total size of all elements stored in the block, including entries and header.
    void
    incDataLength(long delta)
    Increments the current data length within the current block
    void
    init(Block block)
    Initializes a new entry-based block at the provided block.
    void
    insert(byte[] data)
    Inserts the data provided to the currently selected offset.
    boolean
    Checks if currently selected entry is the first one
    boolean
    Checks if currently selected entry is the last one
    void
    Removes the currently selected entry from the block
    void
    setEntrySize(int entrySize)
    Sets the size of the currently selected entry
    void
    setOffset(int offset)
    Sets the current offset within a block
    void
    split(Block block)
    Splits the current block into two at the point of offset.
    void
    split(Block block, byte[] data)
    Splits the current block into two at the point of offset, adds the provided data at the beginning of the new block and move the rest from the original block afterwards.
     

    Methods inherited from class java.lang.Object

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

    • VarSizeEntry

      public VarSizeEntry(VarSizeBlock root)
      Creates the instance of entry
      Parameters:
      root - the anchor-block
  • Method Details

    • toString

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

      public boolean isFirst()
      Checks if currently selected entry is the first one
      Returns:
      true if a current entry is the first one in the block
    • isLast

      public boolean isLast()
      Checks if currently selected entry is the last one
      Returns:
      true if a current entry is the last one in the block
    • getEntrySize

      public int getEntrySize()
      Gets the currently selected entry's size
      Returns:
      the size of the entry
    • setEntrySize

      public void setEntrySize(int entrySize)
      Sets the size of the currently selected entry

      When entry is selected the entry size and offset should be set.

      Parameters:
      entrySize - the entry size in bytes
    • getOffset

      public int getOffset()
      Gets the current offset within a block.

      It defines where starts the currently selected entry.

      Returns:
      the offset with the mem block in bytes from its beginning
    • setOffset

      public void setOffset(int offset)
      Sets the current offset within a block

      It defines where starts the currently selected entry.

      When entry is selected the entry size and offset should be set.

      Parameters:
      offset - the offset from the block begin in bytes
    • getTotalSize

      public int getTotalSize()
      Returns the total size of all elements stored in the block, including entries and header.
      Returns:
      return the total size in bytes
    • getDataLength

      public int getDataLength()
      Gets the total size of payload stored in the block. It does not contain the header size.
      Returns:
      the data length in bytes
    • getFreeSpace

      public int getFreeSpace()
      Gets the free space within the current block
      Returns:
      the free space within the block in bytes
    • incDataLength

      public void incDataLength(long delta)
      Increments the current data length within the current block
      Parameters:
      delta - the delta in bytes to increase the length
    • getDataCapacity

      public int getDataCapacity()
      Gets the total capacity of the block
      Returns:
      capacity of the block in bytes
    • compare

      public int compare(byte[] data)
      Compares the currently selected entry with the data provided
      Parameters:
      data - the data to compare with
      Returns:
      positive if the data is greater, negative - opposite
    • extract

      public byte[] extract()
      Extracts the currently selected entry as a byte array
      Returns:
      the currently selected entry as a byte array
    • insert

      public void insert(byte[] data)
      Inserts the data provided to the currently selected offset.

      The data that is currently located in the block is shifted to make the space for the provided data.

      Parameters:
      data - the data to insert
    • expand

      public void expand(byte[] data)
      Expands the block by adding the data provided to the end of the block.

      Compare to insert(byte[])

      Parameters:
      data - the data to insert
    • remove

      public void remove()
      Removes the currently selected entry from the block
    • init

      public void init(Block block)
      Initializes a new entry-based block at the provided block.

      It will set a proper preamble, offset is put to the first entry

      Parameters:
      block - the memory block
    • split

      public void split(Block block)
      Splits the current block into two at the point of offset.

      Everything what is after the offset is moved to the next block.

      This is an auxilary operation that facilitates insert/expand operations in case if the capacity of the block is reached.

      Parameters:
      block - the newly allocated memory block to move the data to
    • split

      public void split(Block block, byte[] data)
      Splits the current block into two at the point of offset, adds the provided data at the beginning of the new block and move the rest from the original block afterwards.

      As a split(Block), but put the data before the split part in the new block.

      Parameters:
      block - the newly allocated block to move the data to
      data - the data to move