Kagome
Polkadot Runtime Engine in C++17
kagome::storage::trie::PolkadotTrieImpl Class Referencefinal

#include <polkadot_trie_impl.hpp>

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

Public Types

enum  Error { Error::INVALID_NODE_TYPE = 1 }
 
- Public Types inherited from kagome::storage::trie::PolkadotTrie
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

 PolkadotTrieImpl (PolkadotTrie::NodeRetrieveFunctor f=PolkadotTrie::defaultNodeRetrieveFunctor)
 
 PolkadotTrieImpl (NodePtr root, PolkadotTrie::NodeRetrieveFunctor f=PolkadotTrie::defaultNodeRetrieveFunctor)
 
 ~PolkadotTrieImpl ()
 
NodePtr getRoot () override
 
ConstNodePtr getRoot () const override
 
outcome::result< NodePtrgetNode (ConstNodePtr parent, const NibblesView &key_nibbles) override
 
outcome::result< ConstNodePtrgetNode (ConstNodePtr parent, const NibblesView &key_nibbles) const override
 
outcome::result< void > forNodeInPath (ConstNodePtr parent, const NibblesView &path, const std::function< outcome::result< void >(BranchNode const &, uint8_t idx)> &callback) const override
 
outcome::result< std::tuple< bool, uint32_t > > clearPrefix (const common::BufferView &prefix, std::optional< uint64_t > limit, const OnDetachCallback &callback) override
 
outcome::result< void > put (const common::BufferView &key, const common::Buffer &value) override
 Store value by key. More...
 
outcome::result< void > put (const common::BufferView &key, common::Buffer &&value) override
 
outcome::result< void > remove (const common::BufferView &key) override
 Remove value by key. More...
 
outcome::result< common::BufferConstRefget (const common::BufferView &key) const override
 Get value by key. More...
 
outcome::result< std::optional< common::BufferConstRef > > tryGet (const common::BufferView &key) const override
 Get value by key. More...
 
std::unique_ptr< PolkadotTrieCursortrieCursor () override
 
outcome::result< bool > contains (const common::BufferView &key) const override
 Checks if given key-value binding exists in the storage. More...
 
bool empty () const override
 Returns true if the storage is empty. More...
 
outcome::result< ConstNodePtrretrieveChild (const BranchNode &parent, uint8_t idx) const override
 
outcome::result< NodePtrretrieveChild (const BranchNode &parent, uint8_t idx) override
 
- Public Member Functions inherited from kagome::storage::trie::PolkadotTrie
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
 
- Public Member Functions inherited from kagome::storage::face::ReadableBase< common::BufferView >
virtual ~ReadableBase ()=default
 
- Public Member Functions inherited from kagome::storage::face::Writeable< common::BufferView, common::Buffer >
virtual ~Writeable ()=default
 

Private Member Functions

outcome::result< NodePtrinsert (const NodePtr &parent, const NibblesView &key_nibbles, NodePtr node)
 
outcome::result< NodePtrupdateBranch (BranchPtr parent, const NibblesView &key_nibbles, const NodePtr &node)
 

Private Attributes

std::unique_ptr< OpaqueNodeStoragenodes_
 
log::Logger logger_
 

Additional Inherited Members

- Static Public Member Functions inherited from kagome::storage::trie::PolkadotTrie
static outcome::result< NodePtrdefaultNodeRetrieveFunctor (const std::shared_ptr< OpaqueTrieNode > &node)
 

Detailed Description

Definition at line 19 of file polkadot_trie_impl.hpp.

Member Enumeration Documentation

Enumerator
INVALID_NODE_TYPE 

Definition at line 23 of file polkadot_trie_impl.hpp.

Constructor & Destructor Documentation

kagome::storage::trie::PolkadotTrieImpl::PolkadotTrieImpl ( PolkadotTrie::NodeRetrieveFunctor  f = PolkadotTrie::defaultNodeRetrieveFunctor)
explicit

Creates an empty Trie

Parameters
fa functor that will be used to obtain a child of a branch node by its index. Most useful if Trie grows too big to occupy main memory and is stored on an external storage

Definition at line 286 of file polkadot_trie_impl.cpp.

kagome::storage::trie::PolkadotTrieImpl::PolkadotTrieImpl ( NodePtr  root,
PolkadotTrie::NodeRetrieveFunctor  f = PolkadotTrie::defaultNodeRetrieveFunctor 
)
explicit

Definition at line 290 of file polkadot_trie_impl.cpp.

kagome::storage::trie::PolkadotTrieImpl::~PolkadotTrieImpl ( )

Definition at line 294 of file polkadot_trie_impl.cpp.

Member Function Documentation

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

Remove all entries, which key starts with the prefix

Implements kagome::storage::trie::PolkadotTrie.

Definition at line 326 of file polkadot_trie_impl.cpp.

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

Checks if given key-value binding exists in the storage.

Parameters
keyK
Returns
true if key has value, false if does not, or error at .

Implements kagome::storage::face::ReadableBase< common::BufferView >.

Definition at line 606 of file polkadot_trie_impl.cpp.

bool kagome::storage::trie::PolkadotTrieImpl::empty ( ) const
overridevirtual

Returns true if the storage is empty.

Implements kagome::storage::face::ReadableBase< common::BufferView >.

Definition at line 617 of file polkadot_trie_impl.cpp.

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

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

Implements kagome::storage::trie::PolkadotTrie.

Definition at line 542 of file polkadot_trie_impl.cpp.

outcome::result< common::BufferConstRef > kagome::storage::trie::PolkadotTrieImpl::get ( const common::BufferView key) const
overridevirtual

Get value by key.

Parameters
keyK
Returns
V

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

Definition at line 460 of file polkadot_trie_impl.cpp.

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

Implements kagome::storage::trie::PolkadotTrie.

Definition at line 482 of file polkadot_trie_impl.cpp.

outcome::result< PolkadotTrie::ConstNodePtr > kagome::storage::trie::PolkadotTrieImpl::getNode ( ConstNodePtr  parent,
const NibblesView key_nibbles 
) const
overridevirtual

Implements kagome::storage::trie::PolkadotTrie.

Definition at line 494 of file polkadot_trie_impl.cpp.

PolkadotTrie::NodePtr kagome::storage::trie::PolkadotTrieImpl::getRoot ( )
overridevirtual
Returns
the root node of the trie

Implements kagome::storage::trie::PolkadotTrie.

Definition at line 306 of file polkadot_trie_impl.cpp.

PolkadotTrie::ConstNodePtr kagome::storage::trie::PolkadotTrieImpl::getRoot ( ) const
overridevirtual

Implements kagome::storage::trie::PolkadotTrie.

Definition at line 302 of file polkadot_trie_impl.cpp.

outcome::result< PolkadotTrie::NodePtr > kagome::storage::trie::PolkadotTrieImpl::insert ( const NodePtr parent,
const NibblesView key_nibbles,
NodePtr  node 
)
private

Definition at line 340 of file polkadot_trie_impl.cpp.

outcome::result< void > kagome::storage::trie::PolkadotTrieImpl::put ( const common::BufferView key,
const common::Buffer value 
)
overridevirtual

Store value by key.

Parameters
keykey
valuevalue
Returns
result containing void if put successful, error otherwise

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

Definition at line 296 of file polkadot_trie_impl.cpp.

outcome::result< void > kagome::storage::trie::PolkadotTrieImpl::put ( const common::BufferView key,
common::Buffer &&  value 
)
overridevirtual
outcome::result< void > kagome::storage::trie::PolkadotTrieImpl::remove ( const common::BufferView key)
overridevirtual

Remove value by key.

Parameters
keyK
Returns
error code if error happened

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

Definition at line 621 of file polkadot_trie_impl.cpp.

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

Implements kagome::storage::trie::PolkadotTrie.

Definition at line 634 of file polkadot_trie_impl.cpp.

outcome::result< PolkadotTrie::NodePtr > kagome::storage::trie::PolkadotTrieImpl::retrieveChild ( const BranchNode parent,
uint8_t  idx 
)
overridevirtual

Implements kagome::storage::trie::PolkadotTrie.

Definition at line 640 of file polkadot_trie_impl.cpp.

std::unique_ptr< PolkadotTrieCursor > kagome::storage::trie::PolkadotTrieImpl::trieCursor ( )
overridevirtual

Implements kagome::storage::trie::PolkadotTrie.

Definition at line 602 of file polkadot_trie_impl.cpp.

outcome::result< std::optional< common::BufferConstRef > > kagome::storage::trie::PolkadotTrieImpl::tryGet ( const common::BufferView key) const
overridevirtual

Get value by key.

Parameters
keyK
Returns
V if contains(K) or std::nullopt

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

Definition at line 470 of file polkadot_trie_impl.cpp.

outcome::result< PolkadotTrie::NodePtr > kagome::storage::trie::PolkadotTrieImpl::updateBranch ( BranchPtr  parent,
const NibblesView key_nibbles,
const NodePtr node 
)
private

Definition at line 423 of file polkadot_trie_impl.cpp.

Member Data Documentation

log::Logger kagome::storage::trie::PolkadotTrieImpl::logger_
private

Definition at line 99 of file polkadot_trie_impl.hpp.

std::unique_ptr<OpaqueNodeStorage> kagome::storage::trie::PolkadotTrieImpl::nodes_
private

Definition at line 97 of file polkadot_trie_impl.hpp.


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