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

Polymorphic index manager adapter with PolyDBM. More...

#include <tkrzw_index.h>

Classes

class  Iterator
 Iterator for each record. More...
 

Public Member Functions

 PolyIndex ()
 Default constructor. More...
 
 PolyIndex (const PolyIndex &rhs)=delete
 Copy and assignment are disabled. More...
 
PolyIndexoperator= (const PolyIndex &rhs)=delete
 
Status Open (const std::string &path, bool writable, int32_t options=File::OPEN_DEFAULT, const std::map< std::string, std::string > &params={})
 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...
 
PolyDBMGetInternalDBM () const
 Gets the pointer to the internal database object. More...
 
std::unique_ptr< IteratorMakeIterator ()
 Makes an iterator for each record. More...
 

Detailed Description

Polymorphic index manager adapter with PolyDBM.

All operations except for Open and Close are thread-safe; Multiple threads can access the same index concurrently. Every opened index must be closed explicitly to avoid data corruption.

This class is a wrapper of FileIndex and MemIndex. The Open method specifies the actuall class used internally.

Constructor & Destructor Documentation

◆ PolyIndex() [1/2]

tkrzw::PolyIndex::PolyIndex ( )

Default constructor.

◆ PolyIndex() [2/2]

tkrzw::PolyIndex::PolyIndex ( const PolyIndex rhs)
explicitdelete

Copy and assignment are disabled.

Member Function Documentation

◆ Open()

Status tkrzw::PolyIndex::Open ( const std::string &  path,
bool  writable,
int32_t  options = File::OPEN_DEFAULT,
const std::map< std::string, std::string > &  params = {} 
)

Opens an index file.

Parameters
pathA path of the file.
writableIf true, the file is writable. If false, it is read-only.
optionsBit-sum options of File::OpenOption enums for opening the file.
paramsOptional parameters.
Returns
The result status.

If the path is empty, BabyDBM is used internally, which is equivalent to using the MemIndex class. If the path ends with ".tkt", TreeDBM is used internally, which is equivalent to using the FileIndex class. If the key comparator of the tuning parameter is not set, PairLexicalKeyComparator is set implicitly. Other compatible key comparators are PairLexicalCaseKeyComparator, PairDecimalKeyComparator, PairHexadecimalKeyComparator, and PairRealNumberKeyComparator. Other options can be specified as with PolyDBM::OpenAdvanced.

◆ Close()

Status tkrzw::PolyIndex::Close ( )

Closes the index file.

Returns
The result status.

◆ Check()

bool tkrzw::PolyIndex::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::PolyIndex::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::PolyIndex::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::PolyIndex::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::PolyIndex::Count ( )

Gets the number of records.

Returns
The number of records, or -1 on failure.

◆ GetFilePath()

std::string tkrzw::PolyIndex::GetFilePath ( )

Gets the path of the index file.

Returns
The file path of the index, or an empty string on failure.

◆ Clear()

Status tkrzw::PolyIndex::Clear ( )

Removes all records.

Returns
The result status.

◆ Rebuild()

Status tkrzw::PolyIndex::Rebuild ( )

Rebuilds the entire index.

Returns
The result status.

◆ Synchronize()

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

Synchronizes the content of the index 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::PolyIndex::IsOpen ( ) const

Checks whether the index is open.

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

◆ IsWritable()

bool tkrzw::PolyIndex::IsWritable ( ) const

Checks whether the index is writable.

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

◆ GetInternalDBM()

PolyDBM * tkrzw::PolyIndex::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< PolyIndex::Iterator > tkrzw::PolyIndex::MakeIterator ( )

Makes an iterator for each record.

Returns
The iterator for each record.