Tkrzw
Classes | Public Member Functions | List of all members
tkrzw::StdIndex< KEYTYPE, VALUETYPE, CMPTYPE > Class Template Referencefinal

On-memory secondary index implementation with std::map for generic types. More...

#include <tkrzw_index.h>

Classes

class  Iterator
 Iterator for each record. More...
 

Public Member Functions

 StdIndex ()
 Default constructor. More...
 
 ~StdIndex ()
 Destructor. More...
 
 StdIndex (const StdIndex &rhs)=delete
 Copy and assignment are disabled. More...
 
StdIndexoperator= (const StdIndex &rhs)=delete
 
bool Check (const KEYTYPE &key, const VALUETYPE &value)
 Checks whether a record exists in the index. More...
 
std::vector< VALUETYPE > GetValues (const KEYTYPE &key, size_t max=0)
 Gets all values of records of a key. More...
 
void Add (const KEYTYPE &key, const VALUETYPE &value)
 Adds a record. More...
 
void Remove (const KEYTYPE &key, const VALUETYPE &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

template<typename KEYTYPE, typename VALUETYPE, typename CMPTYPE = std::less<std::pair<KEYTYPE, VALUETYPE>>>
class tkrzw::StdIndex< KEYTYPE, VALUETYPE, CMPTYPE >

On-memory secondary index implementation with std::map for generic types.

Parameters
KEYTYPEthe key type.
VALUETYPEthe value type.
CMPTYPEthe comparator type.

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

Constructor & Destructor Documentation

◆ StdIndex() [1/2]

template<typename KEYTYPE , typename VALUETYPE , typename CMPTYPE = std::less<std::pair<KEYTYPE, VALUETYPE>>>
tkrzw::StdIndex< KEYTYPE, VALUETYPE, CMPTYPE >::StdIndex ( )

Default constructor.

◆ ~StdIndex()

template<typename KEYTYPE , typename VALUETYPE , typename CMPTYPE >
tkrzw::StdIndex< KEYTYPE, VALUETYPE, CMPTYPE >::~StdIndex

Destructor.

◆ StdIndex() [2/2]

template<typename KEYTYPE , typename VALUETYPE , typename CMPTYPE = std::less<std::pair<KEYTYPE, VALUETYPE>>>
tkrzw::StdIndex< KEYTYPE, VALUETYPE, CMPTYPE >::StdIndex ( const StdIndex< KEYTYPE, VALUETYPE, CMPTYPE > &  rhs)
explicitdelete

Copy and assignment are disabled.

Member Function Documentation

◆ Check()

template<typename KEYTYPE , typename VALUETYPE , typename CMPTYPE >
bool tkrzw::StdIndex< KEYTYPE, VALUETYPE, CMPTYPE >::Check ( const KEYTYPE &  key,
const VALUETYPE &  value 
)

Checks whether a record exists in the index.

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

◆ GetValues()

template<typename KEYTYPE , typename VALUETYPE , typename CMPTYPE >
std::vector< VALUETYPE > tkrzw::StdIndex< KEYTYPE, VALUETYPE, CMPTYPE >::GetValues ( const KEYTYPE &  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()

template<typename KEYTYPE , typename VALUETYPE , typename CMPTYPE >
void tkrzw::StdIndex< KEYTYPE, VALUETYPE, CMPTYPE >::Add ( const KEYTYPE &  key,
const VALUETYPE &  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()

template<typename KEYTYPE , typename VALUETYPE , typename CMPTYPE >
void tkrzw::StdIndex< KEYTYPE, VALUETYPE, CMPTYPE >::Remove ( const KEYTYPE &  key,
const VALUETYPE &  value 
)

Removes a record.

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

◆ Count()

template<typename KEYTYPE , typename VALUETYPE , typename CMPTYPE >
size_t tkrzw::StdIndex< KEYTYPE, VALUETYPE, CMPTYPE >::Count

Gets the number of records.

Returns
The number of records.

◆ Clear()

template<typename KEYTYPE , typename VALUETYPE , typename CMPTYPE >
void tkrzw::StdIndex< KEYTYPE, VALUETYPE, CMPTYPE >::Clear

Removes all records.

◆ MakeIterator()

template<typename KEYTYPE , typename VALUETYPE , typename CMPTYPE >
std::unique_ptr< typename StdIndex< KEYTYPE, VALUETYPE, CMPTYPE >::Iterator > tkrzw::StdIndex< KEYTYPE, VALUETYPE, CMPTYPE >::MakeIterator

Makes an iterator for each record.

Returns
The iterator for each record.