Key and value record structure in the file hash database.
More...
#include <tkrzw_dbm_hash_impl.h>
|
| HashRecord (File *file, int32_t crc_width, int32_t offset_width, int32_t align_pow) |
| Constructor. More...
|
|
| ~HashRecord () |
| Destructor. More...
|
|
OperationType | GetOperationType () const |
| Gets the operation type of the record. More...
|
|
std::string_view | GetKey () const |
| Gets the key data. More...
|
|
std::string_view | GetValue () const |
| Gets the value data. More...
|
|
int64_t | GetChildOffset () const |
| Gets the offset of the child record. More...
|
|
int32_t | GetWholeSize () const |
| Gets the whole size of the record. More...
|
|
Status | ReadMetadataKey (int64_t offset, int32_t min_read_size) |
| Reads the metadata and the key. More...
|
|
Status | ReadBody () |
| Reads the body data and fill all the properties. More...
|
|
void | SetBodyWithNullValue () |
| Sets the body data with the value filled with null codes. More...
|
|
Status | CheckCRC () |
| Check the CRC. More...
|
|
void | SetData (OperationType type, int32_t ideal_whole_size, const char *key_ptr, int32_t key_size, const char *value_ptr, int32_t value_size, int64_t child_offset) |
| Sets the actual data of the record. More...
|
|
Status | Write (int64_t offset, int64_t *new_offset) const |
| Writes the record in the file. More...
|
|
Status | WriteChildOffset (int64_t offset, int64_t child_offset) |
| Writes the child offset of the record in the file. More...
|
|
Status | FindNextOffset (int64_t offset, int32_t min_read_size, int64_t *next_offset) |
| Finds the next record offset by heuristics. More...
|
|
|
static Status | ReplayOperations (File *file, DBM::RecordProcessor *proc, int64_t record_base, int32_t crc_width, Compressor *compressor, int32_t offset_width, int32_t align_pow, int32_t min_read_size, bool skip_broken_records, int64_t end_offset) |
| Replays operations applied on a hash database file. More...
|
|
static Status | ExtractOffsets (File *in_file, File *out_file, int64_t record_base, int32_t crc_width, int32_t offset_width, int32_t align_pow, bool skip_broken_records, int64_t end_offset) |
| Extracts a sequence of offsets from a file. More...
|
|
Key and value record structure in the file hash database.
◆ OperationType
Enumeration for operation types.
Enumerator |
---|
OP_VOID | Operation to do nothing.
|
OP_SET | Operation to set the value of an existing record.
|
OP_REMOVE | Operation to remove an existing record.
|
OP_ADD | Operation to add a new record.
|
◆ HashRecord()
tkrzw::HashRecord::HashRecord |
( |
File * |
file, |
|
|
int32_t |
crc_width, |
|
|
int32_t |
offset_width, |
|
|
int32_t |
align_pow |
|
) |
| |
Constructor.
- Parameters
-
file | The pointer to the file object. |
crc_width | The width of the CRC value. |
offset_width | The width of the offset data. |
align_pow | The alignment power. |
◆ ~HashRecord()
tkrzw::HashRecord::~HashRecord |
( |
| ) |
|
◆ GetOperationType()
Gets the operation type of the record.
- Returns
- The operation type of the record.
◆ GetKey()
std::string_view tkrzw::HashRecord::GetKey |
( |
| ) |
const |
Gets the key data.
- Returns
- The key data.
◆ GetValue()
std::string_view tkrzw::HashRecord::GetValue |
( |
| ) |
const |
Gets the value data.
- Returns
- The value data. The data might be nullptr if the body hasn't been read.
◆ GetChildOffset()
int64_t tkrzw::HashRecord::GetChildOffset |
( |
| ) |
const |
Gets the offset of the child record.
- Returns
- The offset of the child record.
◆ GetWholeSize()
int32_t tkrzw::HashRecord::GetWholeSize |
( |
| ) |
const |
Gets the whole size of the record.
- Returns
- The whole size of the record. It might be zero if the body hasn't been read.
◆ ReadMetadataKey()
Status tkrzw::HashRecord::ReadMetadataKey |
( |
int64_t |
offset, |
|
|
int32_t |
min_read_size |
|
) |
| |
Reads the metadata and the key.
- Parameters
-
offset | The offset of the record. |
min_read_size | The minimum reading size. |
- Returns
- The result status.
If successful, the key data is always read. However the value data and the whole size is not always read. To read them, call ReadBody.
◆ ReadBody()
Status tkrzw::HashRecord::ReadBody |
( |
| ) |
|
Reads the body data and fill all the properties.
- Returns
- The result status.
◆ SetBodyWithNullValue()
void tkrzw::HashRecord::SetBodyWithNullValue |
( |
| ) |
|
Sets the body data with the value filled with null codes.
◆ CheckCRC()
Status tkrzw::HashRecord::CheckCRC |
( |
| ) |
|
Check the CRC.
- Returns
- The result status.
◆ SetData()
void tkrzw::HashRecord::SetData |
( |
OperationType |
type, |
|
|
int32_t |
ideal_whole_size, |
|
|
const char * |
key_ptr, |
|
|
int32_t |
key_size, |
|
|
const char * |
value_ptr, |
|
|
int32_t |
value_size, |
|
|
int64_t |
child_offset |
|
) |
| |
Sets the actual data of the record.
- Parameters
-
type | An operation type. |
ideal_whole_size | The ideal size of the storage space. |
key_ptr | The pointer to a key buffer. |
key_size | The size of the key buffer. |
value_ptr | The pointer to a value buffer. |
value_size | The size of the value buffer. |
child_offset | The offset of the child record or zero for nothing. |
◆ Write()
Status tkrzw::HashRecord::Write |
( |
int64_t |
offset, |
|
|
int64_t * |
new_offset |
|
) |
| const |
Writes the record in the file.
- Parameters
-
offset | The offset of the record. If it is negative, the data is appended at the end of the file. |
new_offset | The pointer to an integer to store the offset of the appended data. If can be nullptr if the given offset is not negative. |
- Returns
- The result status.
◆ WriteChildOffset()
Status tkrzw::HashRecord::WriteChildOffset |
( |
int64_t |
offset, |
|
|
int64_t |
child_offset |
|
) |
| |
Writes the child offset of the record in the file.
- Parameters
-
offset | The offset of the record to update. |
child_offset | The offset of the child record. |
- Returns
- The result status.
◆ FindNextOffset()
Status tkrzw::HashRecord::FindNextOffset |
( |
int64_t |
offset, |
|
|
int32_t |
min_read_size, |
|
|
int64_t * |
next_offset |
|
) |
| |
Finds the next record offset by heuristics.
- Parameters
-
offset | The current offset. |
min_read_size | The minimum reading size. |
next_offset | The pointer to an integer to store the next offset. |
- Returns
- The result status.
◆ ReplayOperations()
static Status tkrzw::HashRecord::ReplayOperations |
( |
File * |
file, |
|
|
DBM::RecordProcessor * |
proc, |
|
|
int64_t |
record_base, |
|
|
int32_t |
crc_width, |
|
|
Compressor * |
compressor, |
|
|
int32_t |
offset_width, |
|
|
int32_t |
align_pow, |
|
|
int32_t |
min_read_size, |
|
|
bool |
skip_broken_records, |
|
|
int64_t |
end_offset |
|
) |
| |
|
static |
Replays operations applied on a hash database file.
- Parameters
-
file | A file object having opened the database file. |
proc | The pointer to the processor object. |
record_base | The record base offset. |
crc_width | The width of the CRC value. |
compressor | The compressor object. |
offset_width | The offset width. |
align_pow | The alignment power. |
min_read_size | The minimum reading size. |
skip_broken_records | If true, the operation continues even if there are broken records which can be skipped. |
end_offset | The exclusive end offset of records to read. Negative means unlimited. |
- Returns
- The result status.
For each setting operation, ProcessFull of the processer is called. For each removing operation, ProcessEmpty of the processor is called. If they return a value other than NOOP, the iteration is cancelled.
◆ ExtractOffsets()
static Status tkrzw::HashRecord::ExtractOffsets |
( |
File * |
in_file, |
|
|
File * |
out_file, |
|
|
int64_t |
record_base, |
|
|
int32_t |
crc_width, |
|
|
int32_t |
offset_width, |
|
|
int32_t |
align_pow, |
|
|
bool |
skip_broken_records, |
|
|
int64_t |
end_offset |
|
) |
| |
|
static |
Extracts a sequence of offsets from a file.
- Parameters
-
in_file | A file object having opened the input database file. |
out_file | A file object having opened as a writer to store the output. |
record_base | The record base offset. |
crc_width | The width of the CRC value. |
offset_width | The offset width. |
align_pow | The alignment power. |
skip_broken_records | If true, the operation continues even if there are broken records which can be skipped. |
end_offset | The exclusive end offset of records to read. Negative means unlimited. |
- Returns
- The result status.
◆ MAX_KEY_SIZE
constexpr int64_t tkrzw::HashRecord::MAX_KEY_SIZE = 8 * (1LL << 20) - 1 |
|
staticconstexpr |
◆ MAX_VALUE_SIZE
constexpr int64_t tkrzw::HashRecord::MAX_VALUE_SIZE = 2 * (1LL << 30) - 1 |
|
staticconstexpr |
◆ META_MIN_READ_SIZE
constexpr int64_t tkrzw::HashRecord::META_MIN_READ_SIZE = 48 |
|
staticconstexpr |
The minimum size to read the meta data.