Kagome
Polkadot Runtime Engine in C++17
polkadot_trie.hpp
Go to the documentation of this file.
1 
6 #ifndef KAGOME_STORAGE_TRIE_POLKADOT_TRIE_HPP
7 #define KAGOME_STORAGE_TRIE_POLKADOT_TRIE_HPP
8 
10 
13 
14 namespace kagome::storage::trie {
15 
21  : public face::
22  ReadOnlyMap<common::Buffer, common::Buffer, common::BufferView>,
23  public face::Writeable<common::BufferView, common::Buffer> {
24  public:
25  using NodePtr = std::shared_ptr<TrieNode>;
26  using ConstNodePtr = std::shared_ptr<const TrieNode>;
27  using BranchPtr = std::shared_ptr<BranchNode>;
28  using ConstBranchPtr = std::shared_ptr<const BranchNode>;
29  using NodeRetrieveFunctor = std::function<outcome::result<NodePtr>(
30  std::shared_ptr<OpaqueTrieNode> const &)>;
31 
36  using OnDetachCallback = std::function<outcome::result<void>(
37  const common::BufferView &key, std::optional<common::Buffer> &&value)>;
38 
48  virtual outcome::result<std::tuple<bool, uint32_t>> clearPrefix(
49  const common::BufferView &prefix,
50  std::optional<uint64_t> limit,
51  const OnDetachCallback &callback) = 0;
52 
56  virtual NodePtr getRoot() = 0;
57  virtual ConstNodePtr getRoot() const = 0;
58 
63  virtual outcome::result<ConstNodePtr> retrieveChild(
64  const BranchNode &parent, uint8_t idx) const = 0;
65  virtual outcome::result<NodePtr> retrieveChild(const BranchNode &parent,
66  uint8_t idx) = 0;
67 
72  virtual outcome::result<NodePtr> getNode(
73  ConstNodePtr parent, const NibblesView &key_nibbles) = 0;
74  virtual outcome::result<ConstNodePtr> getNode(
75  ConstNodePtr parent, const NibblesView &key_nibbles) const = 0;
76 
82  virtual outcome::result<void> forNodeInPath(
83  ConstNodePtr parent,
84  const NibblesView &path,
85  const std::function<outcome::result<void>(
86  BranchNode const &, uint8_t idx)> &callback) const = 0;
87 
88  virtual std::unique_ptr<PolkadotTrieCursor> trieCursor() = 0;
89 
90  std::unique_ptr<Cursor> cursor() final {
91  return trieCursor();
92  }
93 
94  inline static outcome::result<NodePtr> defaultNodeRetrieveFunctor(
95  const std::shared_ptr<OpaqueTrieNode> &node) {
96  BOOST_ASSERT_MSG(
97  node == nullptr
98  or std::dynamic_pointer_cast<TrieNode>(node) != nullptr,
99  "Unexpected Dummy node.");
100  return std::dynamic_pointer_cast<TrieNode>(node);
101  }
102  };
103 
104 } // namespace kagome::storage::trie
105 
106 #endif // KAGOME_STORAGE_TRIE_POLKADOT_TRIE_HPP
std::shared_ptr< TrieNode > NodePtr
An mixin for modifiable map.
Definition: writeable.hpp:19
virtual outcome::result< ConstNodePtr > retrieveChild(const BranchNode &parent, uint8_t idx) const =0
std::function< outcome::result< void >(const common::BufferView &key, std::optional< common::Buffer > &&value)> OnDetachCallback
std::shared_ptr< BranchNode > BranchPtr
virtual std::unique_ptr< PolkadotTrieCursor > trieCursor()=0
std::unique_ptr< Cursor > cursor() final
Returns new key-value iterator.
std::shared_ptr< const BranchNode > ConstBranchPtr
std::function< outcome::result< NodePtr >(std::shared_ptr< OpaqueTrieNode > const &)> NodeRetrieveFunctor
std::shared_ptr< const TrieNode > ConstNodePtr
virtual outcome::result< NodePtr > getNode(ConstNodePtr parent, const NibblesView &key_nibbles)=0
virtual outcome::result< std::tuple< bool, uint32_t > > clearPrefix(const common::BufferView &prefix, std::optional< uint64_t > limit, const OnDetachCallback &callback)=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
static outcome::result< NodePtr > defaultNodeRetrieveFunctor(const std::shared_ptr< OpaqueTrieNode > &node)