Kagome
Polkadot Runtime Engine in C++17
kagome::storage::trie::PolkadotTrieCursorImpl Class Reference

#include <polkadot_trie_cursor_impl.hpp>

Inheritance diagram for kagome::storage::trie::PolkadotTrieCursorImpl:
Collaboration diagram for kagome::storage::trie::PolkadotTrieCursorImpl:

Classes

struct  InvalidState
 
struct  ReachedEndState
 
class  SearchState
 
struct  TriePathEntry
 
struct  UninitializedState
 

Public Types

enum  Error { Error::INVALID_NODE_TYPE = 1, Error::INVALID_CURSOR_ACCESS, Error::KEY_NOT_FOUND }
 
using NodeType = TrieNode::Type
 

Public Member Functions

 PolkadotTrieCursorImpl (std::shared_ptr< const PolkadotTrie > trie)
 
 ~PolkadotTrieCursorImpl () override=default
 
outcome::result< bool > seekFirst () override
 Same as std::begin(...);. More...
 
outcome::result< bool > seek (const common::BufferView &key) override
 Find given key and seek iterator to this key. More...
 
outcome::result< bool > seekLast () override
 Same as std::rbegin(...);, e.g. points to the last valid element. More...
 
outcome::result< void > seekLowerBound (const common::BufferView &key) override
 
outcome::result< void > seekUpperBound (const common::BufferView &key) override
 
bool isValid () const override
 Is the cursor in a valid state? More...
 
outcome::result< void > next () override
 Make step forward. More...
 
std::optional< common::Bufferkey () const override
 Getter for the key of the element currently pointed at. More...
 
std::optional< common::BufferConstRefvalue () const override
 Getter for value of the element currently pointed at. More...
 
- Public Member Functions inherited from kagome::storage::trie::PolkadotTrieCursor
virtual ~PolkadotTrieCursor () override=default
 
- Public Member Functions inherited from kagome::storage::face::MapCursor< common::Buffer, common::BufferConstRef, common::BufferView >
virtual ~MapCursor ()=default
 

Static Public Member Functions

static outcome::result< std::unique_ptr< PolkadotTrieCursorImpl > > createAt (const common::BufferView &key, const std::shared_ptr< const PolkadotTrie > &trie)
 

Private Types

using CursorState = std::variant< UninitializedState, SearchState, InvalidState, ReachedEndState >
 

Private Member Functions

outcome::result< void > seekLowerBoundInternal (const TrieNode &current, gsl::span< const uint8_t > left_nibbles)
 
outcome::result< bool > nextNodeWithValueInOuterTree ()
 
outcome::result< void > nextNodeWithValueInSubTree (const TrieNode &subtree_root)
 
outcome::result< const TrieNode * > visitChildWithMinIdx (const TrieNode &node, uint8_t min_idx=0)
 
auto makeSearchStateAt (const common::BufferView &key) -> outcome::result< SearchState >
 
common::Buffer collectKey () const
 
template<typename Res >
outcome::result< Res > safeAccess (outcome::result< Res > &&result)
 

Private Attributes

PolkadotCodec codec_
 
log::Logger log_
 
std::shared_ptr< const PolkadotTrietrie_
 
CursorState state_
 

Detailed Description

Definition at line 18 of file polkadot_trie_cursor_impl.hpp.


Class Documentation

struct kagome::storage::trie::PolkadotTrieCursorImpl::InvalidState

Definition at line 140 of file polkadot_trie_cursor_impl.hpp.

Collaboration diagram for kagome::storage::trie::PolkadotTrieCursorImpl::InvalidState:
Class Members
error_code code
struct kagome::storage::trie::PolkadotTrieCursorImpl::ReachedEndState

Definition at line 147 of file polkadot_trie_cursor_impl.hpp.

Collaboration diagram for kagome::storage::trie::PolkadotTrieCursorImpl::ReachedEndState:
struct kagome::storage::trie::PolkadotTrieCursorImpl::UninitializedState

Definition at line 145 of file polkadot_trie_cursor_impl.hpp.

Collaboration diagram for kagome::storage::trie::PolkadotTrieCursorImpl::UninitializedState:

Member Typedef Documentation

Member Enumeration Documentation

Enumerator
INVALID_NODE_TYPE 
INVALID_CURSOR_ACCESS 
KEY_NOT_FOUND 

Definition at line 22 of file polkadot_trie_cursor_impl.hpp.

Constructor & Destructor Documentation

kagome::storage::trie::PolkadotTrieCursorImpl::PolkadotTrieCursorImpl ( std::shared_ptr< const PolkadotTrie trie)
explicit

Definition at line 44 of file polkadot_trie_cursor_impl.cpp.

kagome::storage::trie::PolkadotTrieCursorImpl::~PolkadotTrieCursorImpl ( )
overridedefault

Member Function Documentation

common::Buffer kagome::storage::trie::PolkadotTrieCursorImpl::collectKey ( ) const
private

Definition at line 352 of file polkadot_trie_cursor_impl.cpp.

outcome::result< std::unique_ptr< PolkadotTrieCursorImpl > > kagome::storage::trie::PolkadotTrieCursorImpl::createAt ( const common::BufferView key,
const std::shared_ptr< const PolkadotTrie > &  trie 
)
static

Definition at line 53 of file polkadot_trie_cursor_impl.cpp.

bool kagome::storage::trie::PolkadotTrieCursorImpl::isValid ( ) const
overridevirtual

Is the cursor in a valid state?

Returns
true if the cursor points to an element of the map, false otherwise

Implements kagome::storage::face::MapCursor< common::Buffer, common::BufferConstRef, common::BufferView >.

Definition at line 301 of file polkadot_trie_cursor_impl.cpp.

std::optional< common::Buffer > kagome::storage::trie::PolkadotTrieCursorImpl::key ( ) const
overridevirtual

Getter for the key of the element currently pointed at.

Returns
key if isValid()

Implements kagome::storage::face::MapCursor< common::Buffer, common::BufferConstRef, common::BufferView >.

Definition at line 368 of file polkadot_trie_cursor_impl.cpp.

auto kagome::storage::trie::PolkadotTrieCursorImpl::makeSearchStateAt ( const common::BufferView key) -> outcome::result<SearchState>
private

Constructs a list of branch nodes on the path from the root to the node with the given

  • key

Definition at line 389 of file polkadot_trie_cursor_impl.cpp.

outcome::result< void > kagome::storage::trie::PolkadotTrieCursorImpl::next ( )
overridevirtual
outcome::result< bool > kagome::storage::trie::PolkadotTrieCursorImpl::nextNodeWithValueInOuterTree ( )
private

Definition at line 236 of file polkadot_trie_cursor_impl.cpp.

outcome::result< void > kagome::storage::trie::PolkadotTrieCursorImpl::nextNodeWithValueInSubTree ( const TrieNode subtree_root)
private

Definition at line 257 of file polkadot_trie_cursor_impl.cpp.

template<typename Res >
outcome::result<Res> kagome::storage::trie::PolkadotTrieCursorImpl::safeAccess ( outcome::result< Res > &&  result)
inlineprivate

Definition at line 162 of file polkadot_trie_cursor_impl.hpp.

outcome::result< bool > kagome::storage::trie::PolkadotTrieCursorImpl::seek ( const common::BufferView key)
overridevirtual

Find given key and seek iterator to this key.

Returns
error if any, true if
  • key found, false otherwise

Implements kagome::storage::face::MapCursor< common::Buffer, common::BufferConstRef, common::BufferView >.

Definition at line 68 of file polkadot_trie_cursor_impl.cpp.

outcome::result< bool > kagome::storage::trie::PolkadotTrieCursorImpl::seekFirst ( )
overridevirtual

Same as std::begin(...);.

Returns
error if any, true if trie is not empty, false otherwise

Implements kagome::storage::face::MapCursor< common::Buffer, common::BufferConstRef, common::BufferView >.

Definition at line 62 of file polkadot_trie_cursor_impl.cpp.

outcome::result< bool > kagome::storage::trie::PolkadotTrieCursorImpl::seekLast ( )
overridevirtual

Same as std::rbegin(...);, e.g. points to the last valid element.

Returns
error if any, true if trie is not empty, false otherwise

Implements kagome::storage::face::MapCursor< common::Buffer, common::BufferConstRef, common::BufferView >.

Definition at line 97 of file polkadot_trie_cursor_impl.cpp.

outcome::result< void > kagome::storage::trie::PolkadotTrieCursorImpl::seekLowerBound ( const common::BufferView key)
overridevirtual

Seek the first element with key not less than

  • key

Implements kagome::storage::trie::PolkadotTrieCursor.

Definition at line 223 of file polkadot_trie_cursor_impl.cpp.

outcome::result< void > kagome::storage::trie::PolkadotTrieCursorImpl::seekLowerBoundInternal ( const TrieNode current,
gsl::span< const uint8_t >  left_nibbles 
)
private

Definition at line 130 of file polkadot_trie_cursor_impl.cpp.

outcome::result< void > kagome::storage::trie::PolkadotTrieCursorImpl::seekUpperBound ( const common::BufferView key)
overridevirtual

Seek the first element with key greater than

  • key

Implements kagome::storage::trie::PolkadotTrieCursor.

Definition at line 274 of file polkadot_trie_cursor_impl.cpp.

std::optional< common::BufferConstRef > kagome::storage::trie::PolkadotTrieCursorImpl::value ( ) const
overridevirtual

Getter for value of the element currently pointed at.

Returns
value if isValid()

Implements kagome::storage::face::MapCursor< common::Buffer, common::BufferConstRef, common::BufferView >.

Definition at line 376 of file polkadot_trie_cursor_impl.cpp.

outcome::result< const TrieNode * > kagome::storage::trie::PolkadotTrieCursorImpl::visitChildWithMinIdx ( const TrieNode node,
uint8_t  min_idx = 0 
)
private

Definition at line 285 of file polkadot_trie_cursor_impl.cpp.

Member Data Documentation

PolkadotCodec kagome::storage::trie::PolkadotTrieCursorImpl::codec_
private

Definition at line 158 of file polkadot_trie_cursor_impl.hpp.

log::Logger kagome::storage::trie::PolkadotTrieCursorImpl::log_
private

Definition at line 159 of file polkadot_trie_cursor_impl.hpp.

CursorState kagome::storage::trie::PolkadotTrieCursorImpl::state_
private

Definition at line 176 of file polkadot_trie_cursor_impl.hpp.

std::shared_ptr<const PolkadotTrie> kagome::storage::trie::PolkadotTrieCursorImpl::trie_
private

Definition at line 172 of file polkadot_trie_cursor_impl.hpp.


The documentation for this class was generated from the following files: