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

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...
 
FileIndexoperator= (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 a database file. More...
 
Status Close ()
 Closes the database 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...
 
Status Clear ()
 Removes all records. More...
 
Status Rebuild ()
 Rebuilds the entire database. More...
 
Status Synchronize (bool hard)
 Synchronizes the content of the database to the file system. More...
 
bool IsOpen () const
 Checks whether the database is open. More...
 
bool IsWritable () const
 Checks whether the database is writable. More...
 
TreeDBMGetInternalDBM () const
 Gets the pointer to the internal database object. More...
 
std::unique_ptr< IteratorMakeIterator ()
 Makes an iterator for each record. More...
 

Detailed Description

File secondary index implementation with TreeDBM.

All operations are thread-safe; Multiple threads can access the same database concurrently.

Constructor & Destructor Documentation

◆ FileIndex() [1/3]

tkrzw::FileIndex::FileIndex ( )

Default constructor.

MemoryMapParallelFile is used to handle the data.

◆ FileIndex() [2/3]

tkrzw::FileIndex::FileIndex ( std::unique_ptr< File file)
explicit

Constructor with a file object.

Parameters
fileThe file object to handle the data. The ownership is taken.

◆ FileIndex() [3/3]

tkrzw::FileIndex::FileIndex ( const FileIndex rhs)
explicitdelete

Copy and assignment are disabled.

Member Function Documentation

◆ Open()

Status tkrzw::FileIndex::Open ( const std::string &  path,
bool  writable,
int32_t  options = File::OPEN_DEFAULT,
const TreeDBM::TuningParameters tuning_params = TreeDBM::TuningParameters() 
)

Opens a database file.

Parameters
pathA path of the file.
writableIf true, the file is writable. If false, it is read-only.
optionsBit-sum options for opening the file.
tuning_paramsA structure for tuning parameters.
Returns
The result status.

If the key comparator of the tuning parameter is nullptr, PairLexicalKeyComparator is set implicitly. Other compatible key comparators are PairLexicalCaseKeyComparator, PairDecimalKeyComparator, PairHexadecimalKeyComparator, and PairRealNumberKeyComparator. The alignment power and the maximum page size are also set implicitly to be suitable for random access.

◆ Close()

Status tkrzw::FileIndex::Close ( )

Closes the database file.

Returns
The result status.

Precondition: The database is opened.

◆ Check()

bool tkrzw::FileIndex::Check ( std::string_view  key,
std::string_view  value 
)

Checks whether a record exists in the index.

Parameters
keyThe key of the record.
valueThe value of the record.

◆ GetValues()

std::vector< std::string > tkrzw::FileIndex::GetValues ( std::string_view  key,
size_t  max = 0 
)

Gets all values of records of a key.

Parameters
keyThe key to look for.
maxThe maximum number of values to get. 0 means unlimited.
Returns
All values of the key.

◆ Add()

Status tkrzw::FileIndex::Add ( std::string_view  key,
std::string_view  value 
)

Adds a record.

Parameters
keyThe key of the record. This can be an arbitrary expression to search the index.
valueThe value of the record. This should be a primary value of another database.
Returns
The result status.

◆ Remove()

Status tkrzw::FileIndex::Remove ( std::string_view  key,
std::string_view  value 
)

Removes a record.

Parameters
keyThe key of the record.
valueThe value of the record.
Returns
The result status.

◆ Count()

size_t tkrzw::FileIndex::Count ( )

Gets the number of records.

Returns
The number of records.

◆ Clear()

Status tkrzw::FileIndex::Clear ( )

Removes all records.

Returns
The result status.

◆ Rebuild()

Status tkrzw::FileIndex::Rebuild ( )

Rebuilds the entire database.

Returns
The result status.

◆ Synchronize()

Status tkrzw::FileIndex::Synchronize ( bool  hard)

Synchronizes the content of the database to the file system.

Parameters
hardTrue to do physical synchronization with the hardware or false to do only logical synchronization with the file system.
Returns
The result status.

◆ IsOpen()

bool tkrzw::FileIndex::IsOpen ( ) const

Checks whether the database is open.

Returns
True if the database is open, or false if not.

◆ IsWritable()

bool tkrzw::FileIndex::IsWritable ( ) const

Checks whether the database is writable.

Returns
True if the database is writable, or false if not.

◆ GetInternalDBM()

TreeDBM * tkrzw::FileIndex::GetInternalDBM ( ) const

Gets the pointer to the internal database object.

Returns
The pointer to the internal database object, or nullptr on failure.

◆ MakeIterator()

std::unique_ptr< FileIndex::Iterator > tkrzw::FileIndex::MakeIterator ( )

Makes an iterator for each record.

Returns
The iterator for each record.