Package org.rostore.v2.keys
Class VarSizeMultiBlock
java.lang.Object
org.rostore.v2.keys.VarSizeMultiBlock
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
ConstructorsModifierConstructorDescriptionprotectedCreates a multi block -
Method Summary
Modifier and TypeMethodDescriptionintcompare(byte[] key) Compares the provided key data array to the data stored in the multi block sequencevoidfree()Free all the blocks in the multi block sequencebyte[]get()Reads the data from the multi block sequence and stores it to the data arraygetBlock()Provides a block associated with current positionintProvides the data stored in this blockintProvides a total size of space within the current blocklongProvides the total size of the data stored in the multi blockintProvides a header size in bytes.longProvides the index of the next blocklongProvides the total size stored in the multi block as stored in the headerbooleanisRoot()Identifies if this is the first block in the sequencebooleannext()Moves to the next blocklongput(byte[] data) Stores the key data to the multi block sequence.voidroot()Resets the currently selected block to the first blocktoString()
-
Constructor Details
-
VarSizeMultiBlock
Creates a multi block- Parameters:
root- the root block
-
-
Method Details
-
toString
-
getNextBlockIndex
public long getNextBlockIndex()Provides the index of the next blockThis 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:
trueif there is new 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:
trueif 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,
0if 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
-