Package org.rostore.v2.keys
Class VarSizeEntry
java.lang.Object
org.rostore.v2.keys.VarSizeEntry
Manages several variable-sized entries in one block.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionint
compare
(byte[] data) Compares the currently selected entry with the data providedvoid
expand
(byte[] data) Expands the block by adding the data provided to the end of the block.byte[]
extract()
Extracts the currently selected entry as a byte arrayint
Gets the total capacity of the blockint
Gets the total size of payload stored in the block.int
Gets the currently selected entry's sizeint
Gets the free space within the current blockint
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 blockvoid
Initializes a new entry-based block at the provided block.void
insert
(byte[] data) Inserts the data provided to the currently selected offset.boolean
isFirst()
Checks if currently selected entry is the first oneboolean
isLast()
Checks if currently selected entry is the last onevoid
remove()
Removes the currently selected entry from the blockvoid
setEntrySize
(int entrySize) Sets the size of the currently selected entryvoid
setOffset
(int offset) Sets the current offset within a blockvoid
Splits the current block into two at the point of offset.void
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.toString()
-
Constructor Details
-
VarSizeEntry
Creates the instance of entry- Parameters:
root
- the anchor-block
-
-
Method Details
-
toString
-
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 entryWhen 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 blockIt 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
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
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
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 todata
- the data to move
-