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

On-memory secondary index implementation with BabyDBM. More...

#include <tkrzw_index.h>

Classes

class  Iterator
 Iterator for each record. More...
 

Public Member Functions

 MemIndex (KeyComparator key_comparator=PairLexicalKeyComparator)
 Constructor. More...
 
 MemIndex (const MemIndex &rhs)=delete
 Copy and assignment are disabled. More...
 
MemIndexoperator= (const MemIndex &rhs)=delete
 
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...
 
void Add (std::string_view key, std::string_view value)
 Adds a record. More...
 
void Remove (std::string_view key, std::string_view value)
 Removes a record. More...
 
size_t Count ()
 Gets the number of records. More...
 
void Clear ()
 Removes all records. More...
 
std::unique_ptr< IteratorMakeIterator ()
 Makes an iterator for each record. More...
 

Detailed Description

On-memory secondary index implementation with BabyDBM.

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

Constructor & Destructor Documentation

◆ MemIndex() [1/2]

tkrzw::MemIndex::MemIndex ( KeyComparator  key_comparator = PairLexicalKeyComparator)
explicit

Constructor.

Parameters
key_comparatorThe comparator of record keys.

Compatible key comparators are PairLexicalKeyComparator, PairLexicalCaseKeyComparator, PairDecimalKeyComparator, PairHexadecimalKeyComparator, and PairRealNumberKeyComparator.

◆ MemIndex() [2/2]

tkrzw::MemIndex::MemIndex ( const MemIndex rhs)
explicitdelete

Copy and assignment are disabled.

Member Function Documentation

◆ Check()

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

void tkrzw::MemIndex::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.

◆ Remove()

void tkrzw::MemIndex::Remove ( std::string_view  key,
std::string_view  value 
)

Removes a record.

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

◆ Count()

size_t tkrzw::MemIndex::Count ( )

Gets the number of records.

Returns
The number of records.

◆ Clear()

void tkrzw::MemIndex::Clear ( )

Removes all records.

◆ MakeIterator()

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

Makes an iterator for each record.

Returns
The iterator for each record.