Tkrzw
|
File secondary index implementation with TreeDBM. More...
#include <tkrzw_index.h>
Classes | |
class | Iterator |
Iterator for each record. More... | |
Public Member Functions | |
FileIndex () | |
Default constructor. More... | |
FileIndex (std::unique_ptr< File > file) | |
Constructor with a file object. More... | |
FileIndex (const FileIndex &rhs)=delete | |
Copy and assignment are disabled. More... | |
FileIndex & | operator= (const FileIndex &rhs)=delete |
Status | Open (const std::string &path, bool writable, int32_t options=File::OPEN_DEFAULT, const TreeDBM::TuningParameters &tuning_params=TreeDBM::TuningParameters()) |
Opens an index file. More... | |
Status | Close () |
Closes the index file. More... | |
bool | Check (std::string_view key, std::string_view value) |
Checks whether a record exists in the index. More... | |
std::vector< std::string > | GetValues (std::string_view key, size_t max=0) |
Gets all values of records of a key. More... | |
Status | Add (std::string_view key, std::string_view value) |
Adds a record. More... | |
Status | Remove (std::string_view key, std::string_view value) |
Removes a record. More... | |
size_t | Count () |
Gets the number of records. More... | |
std::string | GetFilePath () |
Gets the path of the index file. More... | |
Status | Clear () |
Removes all records. More... | |
Status | Rebuild () |
Rebuilds the entire index. More... | |
Status | Synchronize (bool hard) |
Synchronizes the content of the index to the file system. More... | |
bool | IsOpen () const |
Checks whether the index is open. More... | |
bool | IsWritable () const |
Checks whether the index is writable. More... | |
TreeDBM * | GetInternalDBM () const |
Gets the pointer to the internal database object. More... | |
std::unique_ptr< Iterator > | MakeIterator () |
Makes an iterator for each record. More... | |
File secondary index implementation with TreeDBM.
All operations are thread-safe; Multiple threads can access the same index concurrently. Every opened index must be closed explicitly to avoid data corruption.
tkrzw::FileIndex::FileIndex | ( | ) |
Default constructor.
MemoryMapParallelFile is used to handle the data.
|
explicit |
Constructor with a file object.
file | The file object to handle the data. The ownership is taken. |
|
explicitdelete |
Copy and assignment are disabled.
Status tkrzw::FileIndex::Open | ( | const std::string & | path, |
bool | writable, | ||
int32_t | options = File::OPEN_DEFAULT , |
||
const TreeDBM::TuningParameters & | tuning_params = TreeDBM::TuningParameters() |
||
) |
Opens an index file.
path | A path of the file. |
writable | If true, the file is writable. If false, it is read-only. |
options | Bit-sum options for opening the file. |
tuning_params | A structure for tuning parameters. |
If the key comparator of the tuning parameter is nullptr, PairLexicalKeyComparator is set implicitly. Other compatible key comparators are PairLexicalCaseKeyComparator, PairDecimalKeyComparator, PairHexadecimalKeyComparator, PairRealNumberKeyComparator, PairSignedBigEndianKeyComparator, and PairFloatBigEndianKeyComparator. The alignment power and the maximum page size are also set implicitly to be suitable for random access.
Status tkrzw::FileIndex::Close | ( | ) |
Closes the index file.
bool tkrzw::FileIndex::Check | ( | std::string_view | key, |
std::string_view | value | ||
) |
Checks whether a record exists in the index.
key | The key of the record. |
value | The value of the record. |
std::vector< std::string > tkrzw::FileIndex::GetValues | ( | std::string_view | key, |
size_t | max = 0 |
||
) |
Gets all values of records of a key.
key | The key to look for. |
max | The maximum number of values to get. 0 means unlimited. |
Status tkrzw::FileIndex::Add | ( | std::string_view | key, |
std::string_view | value | ||
) |
Adds a record.
key | The key of the record. This can be an arbitrary expression to search the index. |
value | The value of the record. This should be a primary value of another database. |
Status tkrzw::FileIndex::Remove | ( | std::string_view | key, |
std::string_view | value | ||
) |
Removes a record.
key | The key of the record. |
value | The value of the record. |
size_t tkrzw::FileIndex::Count | ( | ) |
Gets the number of records.
std::string tkrzw::FileIndex::GetFilePath | ( | ) |
Gets the path of the index file.
Status tkrzw::FileIndex::Clear | ( | ) |
Removes all records.
Status tkrzw::FileIndex::Rebuild | ( | ) |
Rebuilds the entire index.
Status tkrzw::FileIndex::Synchronize | ( | bool | hard | ) |
Synchronizes the content of the index to the file system.
hard | True to do physical synchronization with the hardware or false to do only logical synchronization with the file system. |
bool tkrzw::FileIndex::IsOpen | ( | ) | const |
Checks whether the index is open.
bool tkrzw::FileIndex::IsWritable | ( | ) | const |
Checks whether the index is writable.
TreeDBM * tkrzw::FileIndex::GetInternalDBM | ( | ) | const |
Gets the pointer to the internal database object.
std::unique_ptr< FileIndex::Iterator > tkrzw::FileIndex::MakeIterator | ( | ) |
Makes an iterator for each record.