Tkrzw
Public Member Functions | List of all members
tkrzw::DBM::Iterator Class Referenceabstract

Interface of iterator for each record. More...

#include <tkrzw_dbm.h>

Public Member Functions

virtual ~Iterator ()=default
 Destructor. More...
 
virtual Status First ()=0
 Initializes the iterator to indicate the first record. More...
 
virtual Status Last ()=0
 Initializes the iterator to indicate the last record. More...
 
virtual Status Jump (std::string_view key)=0
 Initializes the iterator to indicate a specific record. More...
 
virtual Status JumpLower (std::string_view key, bool inclusive=false)=0
 Initializes the iterator to indicate the last record whose key is lower than a given key. More...
 
virtual Status JumpUpper (std::string_view key, bool inclusive=false)=0
 Initializes the iterator to indicate the first record whose key is upper than a given key. More...
 
virtual Status Next ()=0
 Moves the iterator to the next record. More...
 
virtual Status Previous ()=0
 Moves the iterator to the previous record. More...
 
virtual Status Process (RecordProcessor *proc, bool writable)=0
 Processes the current record with a processor. More...
 
virtual Status Process (RecordLambdaType rec_lambda, bool writable)
 Processes the current record with a lambda function. More...
 
virtual Status Get (std::string *key=nullptr, std::string *value=nullptr)
 Gets the key and the value of the current record of the iterator. 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 Set (std::string_view value, std::string *old_key=nullptr, std::string *old_value=nullptr)
 Sets the value of the current record. More...
 
virtual Status Remove (std::string *old_key=nullptr, std::string *old_value=nullptr)
 Removes the current record. 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...
 

Detailed Description

Interface of iterator for each record.

Constructor & Destructor Documentation

◆ ~Iterator()

virtual tkrzw::DBM::Iterator::~Iterator ( )
virtualdefault

Member Function Documentation

◆ First()

virtual Status tkrzw::DBM::Iterator::First ( )
pure virtual

Initializes the iterator to indicate the first record.

Returns
The result status.

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

Implemented in tkrzw::TreeDBM::Iterator, tkrzw::TinyDBM::Iterator, tkrzw::StdTreeDBM::Iterator, tkrzw::StdHashDBM::Iterator, tkrzw::SkipDBM::Iterator, tkrzw::ShardDBM::Iterator, tkrzw::PolyDBM::Iterator, tkrzw::HashDBM::Iterator, tkrzw::CacheDBM::Iterator, and tkrzw::BabyDBM::Iterator.

◆ Last()

virtual Status tkrzw::DBM::Iterator::Last ( )
pure virtual

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.

Implemented in tkrzw::TreeDBM::Iterator, tkrzw::TinyDBM::Iterator, tkrzw::StdTreeDBM::Iterator, tkrzw::StdHashDBM::Iterator, tkrzw::SkipDBM::Iterator, tkrzw::ShardDBM::Iterator, tkrzw::PolyDBM::Iterator, tkrzw::HashDBM::Iterator, tkrzw::CacheDBM::Iterator, and tkrzw::BabyDBM::Iterator.

◆ Jump()

virtual Status tkrzw::DBM::Iterator::Jump ( std::string_view  key)
pure virtual

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.

Implemented in tkrzw::TreeDBM::Iterator, tkrzw::TinyDBM::Iterator, tkrzw::StdTreeDBM::Iterator, tkrzw::StdHashDBM::Iterator, tkrzw::SkipDBM::Iterator, tkrzw::ShardDBM::Iterator, tkrzw::PolyDBM::Iterator, tkrzw::HashDBM::Iterator, tkrzw::CacheDBM::Iterator, and tkrzw::BabyDBM::Iterator.

◆ JumpLower()

virtual Status tkrzw::DBM::Iterator::JumpLower ( std::string_view  key,
bool  inclusive = false 
)
pure virtual

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 condition 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.

Implemented in tkrzw::TreeDBM::Iterator, tkrzw::TinyDBM::Iterator, tkrzw::StdTreeDBM::Iterator, tkrzw::StdHashDBM::Iterator, tkrzw::SkipDBM::Iterator, tkrzw::ShardDBM::Iterator, tkrzw::PolyDBM::Iterator, tkrzw::HashDBM::Iterator, tkrzw::CacheDBM::Iterator, and tkrzw::BabyDBM::Iterator.

◆ JumpUpper()

virtual Status tkrzw::DBM::Iterator::JumpUpper ( std::string_view  key,
bool  inclusive = false 
)
pure virtual

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 condition 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.

Implemented in tkrzw::TreeDBM::Iterator, tkrzw::TinyDBM::Iterator, tkrzw::StdTreeDBM::Iterator, tkrzw::StdHashDBM::Iterator, tkrzw::SkipDBM::Iterator, tkrzw::ShardDBM::Iterator, tkrzw::PolyDBM::Iterator, tkrzw::HashDBM::Iterator, tkrzw::CacheDBM::Iterator, and tkrzw::BabyDBM::Iterator.

◆ Next()

virtual Status tkrzw::DBM::Iterator::Next ( )
pure virtual

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.

Implemented in tkrzw::TreeDBM::Iterator, tkrzw::TinyDBM::Iterator, tkrzw::StdTreeDBM::Iterator, tkrzw::StdHashDBM::Iterator, tkrzw::SkipDBM::Iterator, tkrzw::ShardDBM::Iterator, tkrzw::PolyDBM::Iterator, tkrzw::HashDBM::Iterator, tkrzw::CacheDBM::Iterator, and tkrzw::BabyDBM::Iterator.

◆ Previous()

virtual Status tkrzw::DBM::Iterator::Previous ( )
pure virtual

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.

Implemented in tkrzw::TreeDBM::Iterator, tkrzw::TinyDBM::Iterator, tkrzw::StdTreeDBM::Iterator, tkrzw::StdHashDBM::Iterator, tkrzw::SkipDBM::Iterator, tkrzw::ShardDBM::Iterator, tkrzw::PolyDBM::Iterator, tkrzw::HashDBM::Iterator, tkrzw::CacheDBM::Iterator, and tkrzw::BabyDBM::Iterator.

◆ Process() [1/2]

virtual Status tkrzw::DBM::Iterator::Process ( RecordProcessor proc,
bool  writable 
)
pure virtual

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.

Implemented in tkrzw::TreeDBM::Iterator, tkrzw::TinyDBM::Iterator, tkrzw::StdTreeDBM::Iterator, tkrzw::StdHashDBM::Iterator, tkrzw::SkipDBM::Iterator, tkrzw::ShardDBM::Iterator, tkrzw::PolyDBM::Iterator, tkrzw::HashDBM::Iterator, tkrzw::CacheDBM::Iterator, and tkrzw::BabyDBM::Iterator.

◆ Process() [2/2]

virtual Status tkrzw::DBM::Iterator::Process ( RecordLambdaType  rec_lambda,
bool  writable 
)
virtual

Processes the current record with a lambda function.

Parameters
rec_lambdaThe lambda function to process a record. The first parameter is the key of the record. The second parameter is the value of the existing record. The return value is a string reference to RecordProcessor::NOOP, RecordProcessor::REMOVE, or the new record value.
writableTrue if the processor can edit the record.
Returns
The result status.

◆ Get()

virtual Status tkrzw::DBM::Iterator::Get ( std::string *  key = nullptr,
std::string *  value = nullptr 
)
virtual

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 in tkrzw::SkipDBM::Iterator, tkrzw::ShardDBM::Iterator, and tkrzw::PolyDBM::Iterator.

◆ GetKey()

virtual std::string tkrzw::DBM::Iterator::GetKey ( std::string_view  default_value = "")
virtual

Gets the key of the current record, in a simple way.

Parameters
default_valueThe value to be returned on failure.
Returns
The key of the current record on success, or the default value on failure.

◆ GetValue()

virtual std::string tkrzw::DBM::Iterator::GetValue ( std::string_view  default_value = "")
virtual

Gets the value of the current record, in a simple way.

Parameters
default_valueThe value to be returned on failure.
Returns
The value of the current record on success, or the default value on failure.

◆ Set()

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

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 in tkrzw::ShardDBM::Iterator, and tkrzw::PolyDBM::Iterator.

◆ Remove()

virtual Status tkrzw::DBM::Iterator::Remove ( std::string *  old_key = nullptr,
std::string *  old_value = nullptr 
)
virtual

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 in tkrzw::ShardDBM::Iterator, and tkrzw::PolyDBM::Iterator.

◆ Step()

virtual Status tkrzw::DBM::Iterator::Step ( std::string *  key = nullptr,
std::string *  value = nullptr 
)
virtual

Gets the current record and moves the iterator to the next record.

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.