Tkrzw
Classes | Public Member Functions | Friends | List of all members
tkrzw::ShardDBM::Iterator Class Referencefinal

Iterator for each record. More...

#include <tkrzw_dbm_shard.h>

Public Member Functions

virtual ~Iterator ()
 Destructor. More...
 
 Iterator (const Iterator &rhs)=delete
 Copy and assignment are disabled. More...
 
Iteratoroperator= (const Iterator &rhs)=delete
 
Status First () override
 Initializes the iterator to indicate the first record. More...
 
Status Last () override
 Initializes the iterator to indicate the last record. More...
 
Status Jump (std::string_view key) override
 Initializes the iterator to indicate a specific record. More...
 
Status JumpLower (std::string_view key, bool inclusive=false) override
 Initializes the iterator to indicate the last record whose key is lower than a given key. More...
 
Status JumpUpper (std::string_view key, bool inclusive=false) override
 Initializes the iterator to indicate the first record whose key is upper than a given key. More...
 
Status Next () override
 Moves the iterator to the next record. More...
 
Status Previous () override
 Moves the iterator to the previous record. More...
 
Status Process (RecordProcessor *proc, bool writable) override
 Processes the current record with a processor. More...
 
Status Get (std::string *key=nullptr, std::string *value=nullptr) override
 Gets the key and the value of the current record of the iterator. More...
 
Status Set (std::string_view value, std::string *old_key=nullptr, std::string *old_value=nullptr) override
 Sets the value of the current record. More...
 
Status Remove (std::string *old_key=nullptr, std::string *old_value=nullptr) override
 Removes the current record. More...
 
- Public Member Functions inherited from tkrzw::DBM::Iterator
virtual Status Process (RecordLambdaType rec_lambda, bool writable)
 Processes the current record with a lambda function. More...
 
virtual std::string GetKey (std::string_view default_value="")
 Gets the key of the current record, in a simple way. More...
 
virtual std::string GetValue (std::string_view default_value="")
 Gets the value of the current record, in a simple way. More...
 
virtual Status Step (std::string *key=nullptr, std::string *value=nullptr)
 Gets the current record and moves the iterator to the next record. More...
 

Friends

class ShardDBM
 

Detailed Description

Iterator for each record.

When the database is updated, some iterators may or may not be invalided. Operations with invalidated iterators fails gracefully with NOT_FOUND_ERROR. One iterator cannot be shared by multiple threads.

Constructor & Destructor Documentation

◆ ~Iterator()

virtual tkrzw::ShardDBM::Iterator::~Iterator ( )
virtual

Destructor.

Reimplemented from tkrzw::DBM::Iterator.

◆ Iterator()

tkrzw::ShardDBM::Iterator::Iterator ( const Iterator rhs)
explicitdelete

Copy and assignment are disabled.

Member Function Documentation

◆ First()

Status tkrzw::ShardDBM::Iterator::First ( )
overridevirtual

Initializes the iterator to indicate the first record.

Returns
The result status.

Even if there's no record, the operation doesn't fail.

Implements tkrzw::DBM::Iterator.

◆ Last()

Status tkrzw::ShardDBM::Iterator::Last ( )
overridevirtual

Initializes the iterator to indicate the last record.

Returns
The result status.

Even if there's no record, the operation doesn't fail. This method is suppoerted only by ordered databases.

Implements tkrzw::DBM::Iterator.

◆ Jump()

Status tkrzw::ShardDBM::Iterator::Jump ( std::string_view  key)
overridevirtual

Initializes the iterator to indicate a specific record.

Parameters
keyThe key of the record to look for.
Returns
The result status.

Ordered databases can support "lower bound" jump; If there's no record with the same key, the iterator refers to the first record whose key is greater than the given key. The operation fails with unordered databases if there's no record with the same key.

Implements tkrzw::DBM::Iterator.

◆ JumpLower()

Status tkrzw::ShardDBM::Iterator::JumpLower ( std::string_view  key,
bool  inclusive = false 
)
overridevirtual

Initializes the iterator to indicate the last record whose key is lower than a given key.

Parameters
keyThe key to compare with.
inclusiveIf true, the considtion is inclusive: equal to or lower than the key.
Returns
The result status.

Even if there's no matching record, the operation doesn't fail. This method is suppoerted only by ordered databases.

Implements tkrzw::DBM::Iterator.

◆ JumpUpper()

Status tkrzw::ShardDBM::Iterator::JumpUpper ( std::string_view  key,
bool  inclusive = false 
)
overridevirtual

Initializes the iterator to indicate the first record whose key is upper than a given key.

Parameters
keyThe key to compare with.
inclusiveIf true, the considtion is inclusive: equal to or upper than the key.
Returns
The result status.

Even if there's no matching record, the operation doesn't fail. This method is suppoerted only by ordered databases.

Implements tkrzw::DBM::Iterator.

◆ Next()

Status tkrzw::ShardDBM::Iterator::Next ( )
overridevirtual

Moves the iterator to the next record.

Returns
The result status.

If the current record is missing, the operation fails. Even if there's no next record, the operation doesn't fail.

Implements tkrzw::DBM::Iterator.

◆ Previous()

Status tkrzw::ShardDBM::Iterator::Previous ( )
overridevirtual

Moves the iterator to the previous record.

Returns
The result status.

If the current record is missing, the operation fails. Even if there's no previous record, the operation doesn't fail. This method is suppoerted only by ordered databases.

Implements tkrzw::DBM::Iterator.

◆ Process()

Status tkrzw::ShardDBM::Iterator::Process ( RecordProcessor proc,
bool  writable 
)
overridevirtual

Processes the current record with a processor.

Parameters
procThe pointer to the processor object.
writableTrue if the processor can edit the record.
Returns
The result status.

If the current record exists, the ProcessFull of the processor is called. Otherwise, this method fails and no method of the processor is called. If the current record is removed, the iterator is moved to the next record.

Implements tkrzw::DBM::Iterator.

◆ Get()

Status tkrzw::ShardDBM::Iterator::Get ( std::string *  key = nullptr,
std::string *  value = nullptr 
)
overridevirtual

Gets the key and the value of the current record of the iterator.

Parameters
keyThe pointer to a string object to contain the record key. If it is nullptr, the key data is ignored.
valueThe pointer to a string object to contain the record value. If it is nullptr, the value data is ignored.
Returns
The result status.

Reimplemented from tkrzw::DBM::Iterator.

◆ Set()

Status tkrzw::ShardDBM::Iterator::Set ( std::string_view  value,
std::string *  old_key = nullptr,
std::string *  old_value = nullptr 
)
overridevirtual

Sets the value of the current record.

Parameters
valueThe value of the record.
old_keyThe pointer to a string object to contain the old key. If it is nullptr, it is ignored.
old_valueThe pointer to a string object to contain the old value. If it is nullptr, it is ignored.
Returns
The result status.

Reimplemented from tkrzw::DBM::Iterator.

◆ Remove()

Status tkrzw::ShardDBM::Iterator::Remove ( std::string *  old_key = nullptr,
std::string *  old_value = nullptr 
)
overridevirtual

Removes the current record.

Parameters
old_keyThe pointer to a string object to contain the old key. If it is nullptr, it is ignored.
old_valueThe pointer to a string object to contain the old value. If it is nullptr, it is ignored.
Returns
The result status.

If possible, the iterator moves to the next record.

Reimplemented from tkrzw::DBM::Iterator.