Kagome
Polkadot Runtime Engine in C++17
topper_trie_batch_impl.hpp
Go to the documentation of this file.
1 
6 #ifndef KAGOME_CORE_STORAGE_TRIE_IMPL_TOPPER_TRIE_BATCH_IMPL
7 #define KAGOME_CORE_STORAGE_TRIE_IMPL_TOPPER_TRIE_BATCH_IMPL
8 
10 
11 #include <deque>
12 
13 #include "outcome/outcome.hpp"
14 
15 namespace kagome::storage::trie {
16  class PolkadotTrieCursor;
17 }
18 
19 namespace kagome::storage::trie {
20 
21  class TopperTrieBatchImpl final : public TopperTrieBatch {
22  public:
23  enum class Error { PARENT_EXPIRED = 1 };
24 
25  explicit TopperTrieBatchImpl(const std::shared_ptr<TrieBatch> &parent);
26 
27  outcome::result<common::BufferConstRef> get(
28  const BufferView &key) const override;
29  outcome::result<std::optional<common::BufferConstRef>> tryGet(
30  const BufferView &key) const override;
31 
35  std::unique_ptr<PolkadotTrieCursor> trieCursor() override;
36  outcome::result<bool> contains(const BufferView &key) const override;
37  bool empty() const override;
38 
39  outcome::result<void> put(const BufferView &key,
40  const Buffer &value) override;
41  outcome::result<void> put(const BufferView &key, Buffer &&value) override;
42  outcome::result<void> remove(const BufferView &key) override;
43  outcome::result<std::tuple<bool, uint32_t>> clearPrefix(
44  const BufferView &prefix, std::optional<uint64_t> limit) override;
45 
46  outcome::result<void> writeBack() override;
47 
48  private:
49  bool wasClearedByPrefix(const BufferView &key) const;
50 
51  std::map<Buffer, std::optional<Buffer>, std::less<>> cache_;
52  std::deque<Buffer> cleared_prefixes_;
53  std::weak_ptr<TrieBatch> parent_;
54  };
55 
56 } // namespace kagome::storage::trie
57 
59 
60 #endif // KAGOME_CORE_STORAGE_TRIE_IMPL_TOPPER_TRIE_BATCH_IMPL
Class represents arbitrary (including empty) byte buffer.
Definition: buffer.hpp:29
outcome::result< std::optional< common::BufferConstRef > > tryGet(const BufferView &key) const override
Get value by key.
std::map< Buffer, std::optional< Buffer >, std::less<> > cache_
outcome::result< void > put(const BufferView &key, const Buffer &value) override
Store value by key.
bool empty() const override
Returns true if the storage is empty.
OUTCOME_HPP_DECLARE_ERROR(kagome::api, JRpcServerImpl::Error)
TopperTrieBatchImpl(const std::shared_ptr< TrieBatch > &parent)
bool wasClearedByPrefix(const BufferView &key) const
outcome::result< std::tuple< bool, uint32_t > > clearPrefix(const BufferView &prefix, std::optional< uint64_t > limit) override
outcome::result< void > writeBack() override
std::unique_ptr< PolkadotTrieCursor > trieCursor() override
outcome::result< bool > contains(const BufferView &key) const override
Checks if given key-value binding exists in the storage.