Class VarSizeBlock
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.
number of bytes | what |
---|---|
1 | preamble: 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 Summary
-
Method Summary
Modifier and TypeMethodDescriptionint
compare
(byte[] key) int
computeHeaderSize
(byte preamble) byte[]
get()
Gets the data payload for currently selected entrygetBlock()
long
Gets the currently selected memory block, this entry works with.int
Gets the total capacity in bytes of this blockgetEntry()
Get the entries in the blockint
Get the header size of the current blockGet the multi block.int
protected byte
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-blockboolean
invalid()
boolean
If it is a multi-block block.boolean
If it is a multi-entry block (several entries in one block)void
moveTo
(long blockIndex) Selects the current memory block.toString()
boolean
valid()
-
Constructor Details
-
VarSizeBlock
-
-
Method Details
-
invalid
public boolean invalid() -
valid
public boolean valid() -
toString
-
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
Get the entries in the blockThis 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
-
getMultiEntryHeaderSize
public int getMultiEntryHeaderSize() -
getHeaderSize
public int getHeaderSize()Get the header size of the current blockHeader 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
-
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 blockIt 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
-