Tkrzw
Public Member Functions | List of all members
tkrzw::FreeBlockPool Class Referencefinal

Registry of free blocks. More...

#include <tkrzw_dbm_hash_impl.h>

Public Member Functions

 FreeBlockPool (int32_t capacity)
 Constructor. More...
 
void SetCapacity (int32_t capacity)
 Sets the capacity. More...
 
void Clear ()
 Removes all records. More...
 
void InsertFreeBlock (int64_t offset, int32_t size)
 Inserts a free block. More...
 
bool FetchFreeBlock (int32_t min_size, FreeBlock *res)
 Fetchs the minimum free block meeting the record size to fit it in. More...
 
int32_t Size ()
 Gets the current number of free blocks. More...
 
std::string Serialize (int32_t offset_width, int32_t align_pow, int32_t size)
 Serializes records into a string. More...
 
void Deserialize (std::string_view str, int32_t offset_width, int32_t align_pow)
 Deserializes a string to set records. More...
 

Detailed Description

Registry of free blocks.

Constructor & Destructor Documentation

◆ FreeBlockPool()

tkrzw::FreeBlockPool::FreeBlockPool ( int32_t  capacity)

Constructor.

Parameters
capacityThe capacity of the pool.

Member Function Documentation

◆ SetCapacity()

void tkrzw::FreeBlockPool::SetCapacity ( int32_t  capacity)

Sets the capacity.

Parameters
capacityThe capacity of the pool.

◆ Clear()

void tkrzw::FreeBlockPool::Clear ( )

Removes all records.

◆ InsertFreeBlock()

void tkrzw::FreeBlockPool::InsertFreeBlock ( int64_t  offset,
int32_t  size 
)

Inserts a free block.

Parameters
offsetThe offset in the file.
sizeThe size of the block

◆ FetchFreeBlock()

bool tkrzw::FreeBlockPool::FetchFreeBlock ( int32_t  min_size,
FreeBlock res 
)

Fetchs the minimum free block meeting the record size to fit it in.

Parameters
min_sizeThe minimum size of the block to fetch.
resThe pointer to a free block object to store the result.
Returns
True on success or false on failure.

◆ Size()

int32_t tkrzw::FreeBlockPool::Size ( )

Gets the current number of free blocks.

Returns
The current number of free blocks.

◆ Serialize()

std::string tkrzw::FreeBlockPool::Serialize ( int32_t  offset_width,
int32_t  align_pow,
int32_t  size 
)

Serializes records into a string.

Parameters
offset_widthThe offset width.
align_powThe alignment power.
sizeThe size of the result string.
Returns
The result string.

◆ Deserialize()

void tkrzw::FreeBlockPool::Deserialize ( std::string_view  str,
int32_t  offset_width,
int32_t  align_pow 
)

Deserializes a string to set records.

Parameters
strThe string to deserialize.
offset_widthThe offset width.
align_powThe alignment power.