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

Key and value record structure in the file skip database. More...

#include <tkrzw_dbm_skip_impl.h>

Public Member Functions

 SkipRecord (File *file, int32_t offset_width, int32_t step_unit, int32_t max_level)
 Constructor. More...
 
 ~SkipRecord ()
 Destructor. More...
 
SkipRecordoperator= (SkipRecord &&rhs)
 Assigns the internal state from another moved record object. More...
 
Status ReadMetadataKey (int64_t offset, int64_t index)
 Reads the metadata and the key. More...
 
Status ReadBody ()
 Reads the body data and fill all the properties. More...
 
std::string_view GetKey () const
 Gets the key data. More...
 
std::string_view GetValue () const
 Gets the value data. More...
 
const std::vector< int64_t > & GetStepOffsets () const
 Gets the offsets of the records to skip to. More...
 
int32_t GetLevel () const
 Gets the level of the record. More...
 
int64_t GetIndex () const
 Gets the index of the record. More...
 
int64_t GetOffset () const
 Gets the offset of the record. More...
 
int32_t GetWholeSize () const
 Gets the whole size of the record. More...
 
void SetData (int64_t index, const char *key_ptr, int32_t key_size, const char *value_ptr, int32_t value_size)
 Sets the actual data of the record. More...
 
Status Write ()
 Writes the record in the file. More...
 
Status UpdatePastRecords (int64_t index, int64_t offset, std::vector< int64_t > *past_offsets) const
 Updates past records which refer to this record. More...
 
Status Search (int64_t record_base, SkipRecordCache *cache, std::string_view key, bool upper)
 Searches records for the one with the same key. More...
 
Status SearchByIndex (int64_t record_base, SkipRecordCache *cache, int64_t index)
 Searches records for the one with the same index. More...
 
FileGetFile () const
 Gets the file object. More...
 
char * Serialize () const
 Searializes the internal data. More...
 
void Deserialize (int64_t index, const char *serialized)
 Deserializes a string and prepare the internal data. More...
 

Detailed Description

Key and value record structure in the file skip database.

Constructor & Destructor Documentation

◆ SkipRecord()

tkrzw::SkipRecord::SkipRecord ( File file,
int32_t  offset_width,
int32_t  step_unit,
int32_t  max_level 
)

Constructor.

Parameters
fileThe pointer to the file object.
offset_widthThe width of the offset data.
step_unitThe unit of stepping.
max_levelThe maximum level of the skip list.

◆ ~SkipRecord()

tkrzw::SkipRecord::~SkipRecord ( )

Destructor.

Member Function Documentation

◆ operator=()

SkipRecord& tkrzw::SkipRecord::operator= ( SkipRecord &&  rhs)

Assigns the internal state from another moved record object.

Parameters
rhsThe other record object.

◆ ReadMetadataKey()

Status tkrzw::SkipRecord::ReadMetadataKey ( int64_t  offset,
int64_t  index 
)

Reads the metadata and the key.

Parameters
offsetThe offset of the record.
indexThe index of the record.
Returns
The result status.

If successful, the key data is always read. However the value data is not always read. To read it, call ReadBody.

◆ ReadBody()

Status tkrzw::SkipRecord::ReadBody ( )

Reads the body data and fill all the properties.

Returns
The result status.

◆ GetKey()

std::string_view tkrzw::SkipRecord::GetKey ( ) const

Gets the key data.

Returns
The key data.

◆ GetValue()

std::string_view tkrzw::SkipRecord::GetValue ( ) const

Gets the value data.

Returns
The value data. The data might be nullptr if the body hasn't been read.

◆ GetStepOffsets()

const std::vector<int64_t>& tkrzw::SkipRecord::GetStepOffsets ( ) const

Gets the offsets of the records to skip to.

Returns
The offsets of the records to skip to.

◆ GetLevel()

int32_t tkrzw::SkipRecord::GetLevel ( ) const

Gets the level of the record.

Returns
The level of the record.

◆ GetIndex()

int64_t tkrzw::SkipRecord::GetIndex ( ) const

Gets the index of the record.

Returns
The index of the record.

◆ GetOffset()

int64_t tkrzw::SkipRecord::GetOffset ( ) const

Gets the offset of the record.

Returns
The offset of the record.

◆ GetWholeSize()

int32_t tkrzw::SkipRecord::GetWholeSize ( ) const

Gets the whole size of the record.

Returns
The whole size of the record.

◆ SetData()

void tkrzw::SkipRecord::SetData ( int64_t  index,
const char *  key_ptr,
int32_t  key_size,
const char *  value_ptr,
int32_t  value_size 
)

Sets the actual data of the record.

Parameters
indexThe index of the record.
key_ptrThe pointer to a key buffer.
key_sizeThe size of the key buffer.
value_ptrThe pointer to a value buffer.
value_sizeThe size of the value buffer.

◆ Write()

Status tkrzw::SkipRecord::Write ( )

Writes the record in the file.

Returns
The result status.

◆ UpdatePastRecords()

Status tkrzw::SkipRecord::UpdatePastRecords ( int64_t  index,
int64_t  offset,
std::vector< int64_t > *  past_offsets 
) const

Updates past records which refer to this record.

Parameters
indexThe index of the record.
offsetThe offset of the record.
past_offsetsThe pointer to a vector of offsets of the past records, whose size must be the same as the maximum level.
Returns
The result status.

◆ Search()

Status tkrzw::SkipRecord::Search ( int64_t  record_base,
SkipRecordCache cache,
std::string_view  key,
bool  upper 
)

Searches records for the one with the same key.

Parameters
record_baseThe record base offset.
cacheThe cache for skip records.
keyThe key to match with.
upperIf true, the first upper record is retrieved if there's no record matching.
Returns
The result status.

◆ SearchByIndex()

Status tkrzw::SkipRecord::SearchByIndex ( int64_t  record_base,
SkipRecordCache cache,
int64_t  index 
)

Searches records for the one with the same index.

Parameters
record_baseThe record base offset.
cacheThe cache for skip records.
indexThe index of the target record.
Returns
The result status.

◆ GetFile()

File* tkrzw::SkipRecord::GetFile ( ) const

Gets the file object.

Returns
The pointer to the file object.

◆ Serialize()

char* tkrzw::SkipRecord::Serialize ( ) const

Searializes the internal data.

Returns
The result string. The caller has the ownership.

◆ Deserialize()

void tkrzw::SkipRecord::Deserialize ( int64_t  index,
const char *  serialized 
)

Deserializes a string and prepare the internal data.

Parameters
indexThe index of the serialized record.
serializedThe serialized string. Ownership is not taken.