Kagome
Polkadot Runtime Engine in C++17
kagome::storage::trie::PolkadotTrie Class Referenceabstract

#include <polkadot_trie.hpp>

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

Public Types

using NodePtr = std::shared_ptr< TrieNode >
 
using ConstNodePtr = std::shared_ptr< const TrieNode >
 
using BranchPtr = std::shared_ptr< BranchNode >
 
using ConstBranchPtr = std::shared_ptr< const BranchNode >
 
using NodeRetrieveFunctor = std::function< outcome::result< NodePtr >(std::shared_ptr< OpaqueTrieNode > const &)>
 
using OnDetachCallback = std::function< outcome::result< void >(const common::BufferView &key, std::optional< common::Buffer > &&value)>
 
- Public Types inherited from kagome::storage::face::Iterable< common::Buffer, ReadableMap< common::Buffer, common::Buffer >::ConstValueView, common::BufferView >
using Cursor = MapCursor< common::Buffer, ReadableMap< common::Buffer, common::Buffer >::ConstValueView, common::BufferView >
 
- Public Types inherited from kagome::storage::face::ReadableMap< common::BufferView, common::Buffer >
using Key = common::BufferView
 
using Value = common::Buffer
 
using ValueView = std::reference_wrapper< common::Buffer >
 
using ConstValueView = std::reference_wrapper< const common::Buffer >
 
- Public Types inherited from kagome::storage::face::ReadableBase< common::BufferView >
using Key = common::BufferView
 

Public Member Functions

virtual outcome::result< std::tuple< bool, uint32_t > > clearPrefix (const common::BufferView &prefix, std::optional< uint64_t > limit, const OnDetachCallback &callback)=0
 
virtual NodePtr getRoot ()=0
 
virtual ConstNodePtr getRoot () const =0
 
virtual outcome::result< ConstNodePtrretrieveChild (const BranchNode &parent, uint8_t idx) const =0
 
virtual outcome::result< NodePtrretrieveChild (const BranchNode &parent, uint8_t idx)=0
 
virtual outcome::result< NodePtrgetNode (ConstNodePtr parent, const NibblesView &key_nibbles)=0
 
virtual outcome::result< ConstNodePtrgetNode (ConstNodePtr parent, const NibblesView &key_nibbles) const =0
 
virtual outcome::result< void > forNodeInPath (ConstNodePtr parent, const NibblesView &path, const std::function< outcome::result< void >(BranchNode const &, uint8_t idx)> &callback) const =0
 
virtual std::unique_ptr< PolkadotTrieCursortrieCursor ()=0
 
std::unique_ptr< Cursorcursor () final
 Returns new key-value iterator. More...
 
- Public Member Functions inherited from kagome::storage::face::Iterable< common::Buffer, ReadableMap< common::Buffer, common::Buffer >::ConstValueView, common::BufferView >
virtual ~Iterable ()=default
 
- Public Member Functions inherited from kagome::storage::face::ReadableMap< common::BufferView, common::Buffer >
virtual ~ReadableMap ()=default
 
virtual outcome::result< ConstValueViewget (const Key &key) const =0
 Get value by key. More...
 
virtual outcome::result< std::optional< ConstValueView > > tryGet (const Key &key) const =0
 Get value by key. More...
 
- Public Member Functions inherited from kagome::storage::face::ReadableBase< common::BufferView >
virtual ~ReadableBase ()=default
 
virtual outcome::result< bool > contains (const Key &key) const =0
 Checks if given key-value binding exists in the storage. More...
 
virtual bool empty () const =0
 Returns true if the storage is empty. More...
 
- Public Member Functions inherited from kagome::storage::face::Writeable< common::BufferView, common::Buffer >
virtual ~Writeable ()=default
 
virtual outcome::result< void > put (const common::BufferView &key, const common::Buffer &value)=0
 Store value by key. More...
 
virtual outcome::result< void > put (const common::BufferView &key, common::Buffer &&value)=0
 
virtual outcome::result< void > remove (const common::BufferView &key)=0
 Remove value by key. More...
 

Static Public Member Functions

static outcome::result< NodePtrdefaultNodeRetrieveFunctor (const std::shared_ptr< OpaqueTrieNode > &node)
 

Detailed Description

For specification see Polkadot Runtime Environment Protocol Specification '2.1.2 The General Tree Structure' and further

Definition at line 20 of file polkadot_trie.hpp.

Member Typedef Documentation

Definition at line 27 of file polkadot_trie.hpp.

Definition at line 28 of file polkadot_trie.hpp.

Definition at line 26 of file polkadot_trie.hpp.

Definition at line 25 of file polkadot_trie.hpp.

using kagome::storage::trie::PolkadotTrie::NodeRetrieveFunctor = std::function<outcome::result<NodePtr>( std::shared_ptr<OpaqueTrieNode> const &)>

Definition at line 30 of file polkadot_trie.hpp.

using kagome::storage::trie::PolkadotTrie::OnDetachCallback = std::function<outcome::result<void>( const common::BufferView &key, std::optional<common::Buffer> &&value)>

This callback is called when a node is detached from a trie. It is called for each leaf from the detached node subtree

Definition at line 37 of file polkadot_trie.hpp.

Member Function Documentation

virtual outcome::result<std::tuple<bool, uint32_t> > kagome::storage::trie::PolkadotTrie::clearPrefix ( const common::BufferView prefix,
std::optional< uint64_t >  limit,
const OnDetachCallback callback 
)
pure virtual

Remove all trie entries which key begins with the supplied prefix

Parameters
prefixkey prefix for nodes to be removed
limitnumber of elements to remove, std::nullopt if no limit
callbackfunction that will be called for each node removal
Returns
tuple first element true if removed all nodes to be removed, second tuple element is a number of removed elements

Implemented in kagome::storage::trie::PolkadotTrieImpl.

std::unique_ptr<Cursor> kagome::storage::trie::PolkadotTrie::cursor ( )
inlinefinalvirtual
static outcome::result<NodePtr> kagome::storage::trie::PolkadotTrie::defaultNodeRetrieveFunctor ( const std::shared_ptr< OpaqueTrieNode > &  node)
inlinestatic

Definition at line 94 of file polkadot_trie.hpp.

virtual outcome::result<void> kagome::storage::trie::PolkadotTrie::forNodeInPath ( ConstNodePtr  parent,
const NibblesView path,
const std::function< outcome::result< void >(BranchNode const &, uint8_t idx)> &  callback 
) const
pure virtual

Invokes callback on each node starting from

  • parent and ending on the node corresponding to the
  • path
    Returns
    error, if any call errored, success otherwise

Implemented in kagome::storage::trie::PolkadotTrieImpl.

virtual outcome::result<NodePtr> kagome::storage::trie::PolkadotTrie::getNode ( ConstNodePtr  parent,
const NibblesView key_nibbles 
)
pure virtual
Returns
a node which is a descendant of
  • parent found by following
  • key_nibbles (includes parent's key nibbles)

Implemented in kagome::storage::trie::PolkadotTrieImpl.

virtual outcome::result<ConstNodePtr> kagome::storage::trie::PolkadotTrie::getNode ( ConstNodePtr  parent,
const NibblesView key_nibbles 
) const
pure virtual
virtual NodePtr kagome::storage::trie::PolkadotTrie::getRoot ( )
pure virtual
Returns
the root node of the trie

Implemented in kagome::storage::trie::PolkadotTrieImpl.

virtual ConstNodePtr kagome::storage::trie::PolkadotTrie::getRoot ( ) const
pure virtual
virtual outcome::result<ConstNodePtr> kagome::storage::trie::PolkadotTrie::retrieveChild ( const BranchNode parent,
uint8_t  idx 
) const
pure virtual
Returns
a child node pointer of a provided
  • parent node at the index

Implemented in kagome::storage::trie::PolkadotTrieImpl.

virtual outcome::result<NodePtr> kagome::storage::trie::PolkadotTrie::retrieveChild ( const BranchNode parent,
uint8_t  idx 
)
pure virtual
virtual std::unique_ptr<PolkadotTrieCursor> kagome::storage::trie::PolkadotTrie::trieCursor ( )
pure virtual

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