Top Description Fields Constructors Methods
org.h2.mvstore

public Class FreeSpaceBitSet

extends Object
Class Inheritance
Imports
java.util.BitSet, org.h2.util.MathUtils

A free space bit set.

Field Summary

Modifier and TypeField and Description
private final int
blockSize

The block size in bytes.

private static final boolean
private int
failureFlags

Left-shifting register, which holds outcomes of recent allocations.

private final int
firstFreeBlock

The first usable block.

private final BitSet
set

The bit set.

Constructor Summary

AccessConstructor and Description
public
FreeSpaceBitSet(int
the first free block
firstFreeBlock
,
int
the block size
blockSize
)

Create a new free space map.

Method Summary

Modifier and TypeMethod and Description
public long

Returns:

the start position in bytes
allocate
(int
the number of bytes to allocate
length
)

Allocate a number of blocks and mark them as used.

pack-priv long

Returns:

the start position in bytes
allocate
(int
the number of bytes to allocate
length
,
long
start block index of the reserved area (inclusive)
reservedLow
,
long
end block index of the reserved area (exclusive), special value -1 means beginning of the infinite free area
reservedHigh
)

Allocate a number of blocks and mark them as used.

private int
allocate(int blocks, int reservedLow, int reservedHigh, boolean allocate)

public void
clear()

Reset the list.

public void
free(long
the position in bytes
pos
,
int
the number of bytes
length
)

Mark the space as free.

pack-priv int

Returns:

block index
getAfterLastBlock
()

Get the index of the first block after last occupied one.

private int
getBlock(long pos)

private int
getBlockCount(int length)

pack-priv int

Returns:

the fill rate (0 - 100)
getFillRate
()

Get the fill rate of the space in percent.

pack-priv long

Returns:

the position.
getFirstFree
()

Get the position of the first free space.

pack-priv long

Returns:

the position.
getLastFree
()

Get the position of the last (infinite) free space.

pack-priv int

Returns:

priority, bigger number indicate that chunk need to be moved sooner
getMovePriority
(int
where chunk starts
block
)

Calculates relative "priority" for chunk to be moved.

private long
getPos(int block)

pack-priv boolean
public boolean

Returns:

true if a block is free
isFree
(long
the position in bytes
pos
,
int
the number of bytes
length
)

Check whether one of the blocks is free.

public boolean

Returns:

true if a block is in use
isUsed
(long
the position in bytes
pos
,
int
the number of bytes
length
)

Check whether one of the blocks is in use.

public void
markUsed(long
the position in bytes
pos
,
int
the number of bytes
length
)

Mark the space as in use.

pack-priv long

Returns:

the starting block index
predictAllocation
(int
the number of blocks to allocate
blocks
,
long
start block index of the reserved area (inclusive)
reservedLow
,
long
end block index of the reserved area (exclusive), special value -1 means beginning of the infinite free area
reservedHigh
)

Calculate starting position of the prospective allocation.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

blockSizeback to summary
private final int blockSize

The block size in bytes.

DETAILED_INFOback to summary
private static final boolean DETAILED_INFO
failureFlagsback to summary
private int failureFlags

Left-shifting register, which holds outcomes of recent allocations. Only allocations done in "reuseSpace" mode are recorded here. For example, rightmost bit set to 1 means that last allocation failed to find a hole big enough, and next bit set to 0 means that previous allocation request have found one.

firstFreeBlockback to summary
private final int firstFreeBlock

The first usable block.

setback to summary
private final BitSet set

The bit set.

Constructor Detail

FreeSpaceBitSetback to summary
public FreeSpaceBitSet(int firstFreeBlock, int blockSize)

Create a new free space map.

Parameters
firstFreeBlock:int

the first free block

blockSize:int

the block size

Method Detail

allocateback to summary
public long allocate(int length)

Allocate a number of blocks and mark them as used.

Parameters
length:int

the number of bytes to allocate

Returns:long

the start position in bytes

allocateback to summary
pack-priv long allocate(int length, long reservedLow, long reservedHigh)

Allocate a number of blocks and mark them as used.

Parameters
length:int

the number of bytes to allocate

reservedLow:long

start block index of the reserved area (inclusive)

reservedHigh:long

end block index of the reserved area (exclusive), special value -1 means beginning of the infinite free area

Returns:long

the start position in bytes

allocateback to summary
private int allocate(int blocks, int reservedLow, int reservedHigh, boolean allocate)
clearback to summary
public void clear()

Reset the list.

freeback to summary
public void free(long pos, int length)

Mark the space as free.

Parameters
pos:long

the position in bytes

length:int

the number of bytes

getAfterLastBlockback to summary
pack-priv int getAfterLastBlock()

Get the index of the first block after last occupied one. It marks the beginning of the last (infinite) free space.

Returns:int

block index

getBlockback to summary
private int getBlock(long pos)
getBlockCountback to summary
private int getBlockCount(int length)
getFillRateback to summary
pack-priv int getFillRate()

Get the fill rate of the space in percent. The value 0 means the space is completely free, and 100 means it is completely full.

Returns:int

the fill rate (0 - 100)

getFirstFreeback to summary
pack-priv long getFirstFree()

Get the position of the first free space.

Returns:long

the position.

getLastFreeback to summary
pack-priv long getLastFree()

Get the position of the last (infinite) free space.

Returns:long

the position.

getMovePriorityback to summary
pack-priv int getMovePriority(int block)

Calculates relative "priority" for chunk to be moved.

Parameters
block:int

where chunk starts

Returns:int

priority, bigger number indicate that chunk need to be moved sooner

getPosback to summary
private long getPos(int block)
isFragmentedback to summary
pack-priv boolean isFragmented()
isFreeback to summary
public boolean isFree(long pos, int length)

Check whether one of the blocks is free.

Parameters
pos:long

the position in bytes

length:int

the number of bytes

Returns:boolean

true if a block is free

isUsedback to summary
public boolean isUsed(long pos, int length)

Check whether one of the blocks is in use.

Parameters
pos:long

the position in bytes

length:int

the number of bytes

Returns:boolean

true if a block is in use

markUsedback to summary
public void markUsed(long pos, int length)

Mark the space as in use.

Parameters
pos:long

the position in bytes

length:int

the number of bytes

predictAllocationback to summary
pack-priv long predictAllocation(int blocks, long reservedLow, long reservedHigh)

Calculate starting position of the prospective allocation.

Parameters
blocks:int

the number of blocks to allocate

reservedLow:long

start block index of the reserved area (inclusive)

reservedHigh:long

end block index of the reserved area (exclusive), special value -1 means beginning of the infinite free area

Returns:long

the starting block index

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

Annotations
@Override