Kagome
Polkadot Runtime Engine in C++17
trie_storage_backend_impl.cpp
Go to the documentation of this file.
1 
7 
8 #include <utility>
9 
11 
12 namespace kagome::storage::trie {
13 
15  std::shared_ptr<BufferStorage> storage, common::Buffer node_prefix)
16  : storage_{std::move(storage)}, node_prefix_{std::move(node_prefix)} {
17  BOOST_ASSERT(storage_ != nullptr);
18  }
19 
20  std::unique_ptr<TrieStorageBackendImpl::Cursor>
22  return storage_
23  ->cursor(); // TODO(Harrm): perhaps should iterate over trie nodes only
24  }
25 
26  std::unique_ptr<face::WriteBatch<BufferView, Buffer>>
28  return std::make_unique<TrieStorageBackendBatch>(storage_->batch(),
29  node_prefix_);
30  }
31 
32  outcome::result<Buffer> TrieStorageBackendImpl::load(
33  const BufferView &key) const {
34  return storage_->load(prefixKey(key));
35  }
36 
37  outcome::result<std::optional<Buffer>> TrieStorageBackendImpl::tryLoad(
38  const BufferView &key) const {
39  return storage_->tryLoad(prefixKey(key));
40  }
41 
42  outcome::result<bool> TrieStorageBackendImpl::contains(
43  const BufferView &key) const {
44  return storage_->contains(prefixKey(key));
45  }
46 
48  return storage_->empty();
49  }
50 
51  outcome::result<void> TrieStorageBackendImpl::put(const BufferView &key,
52  const Buffer &value) {
53  return storage_->put(prefixKey(key), value);
54  }
55 
56  outcome::result<void> TrieStorageBackendImpl::put(const BufferView &key,
57  Buffer &&value) {
58  return storage_->put(prefixKey(key), std::move(value));
59  }
60 
61  outcome::result<void> TrieStorageBackendImpl::remove(const BufferView &key) {
62  return storage_->remove(prefixKey(key));
63  }
64 
66  const common::BufferView &key) const {
67  return common::Buffer{node_prefix_}.put(key);
68  }
69 
71  return storage_->size();
72  }
73 
74 } // namespace kagome::storage::trie
Class represents arbitrary (including empty) byte buffer.
Definition: buffer.hpp:29
outcome::result< bool > contains(const BufferView &key) const override
outcome::result< Buffer > load(const BufferView &key) const override
std::unique_ptr< face::WriteBatch< BufferView, Buffer > > batch() override
Creates new Write Batch - an object, which can be used to efficiently write bulk data.
outcome::result< void > remove(const common::BufferView &key) override
SLBuffer & put(std::string_view view)
Put a string into byte buffer.
Definition: buffer.hpp:117
TrieStorageBackendImpl(std::shared_ptr< BufferStorage > storage, common::Buffer node_prefix)
common::Buffer prefixKey(const common::BufferView &key) const
outcome::result< void > put(const BufferView &key, const Buffer &value) override
std::unique_ptr< Cursor > cursor() override
Returns new key-value iterator.
outcome::result< std::optional< Buffer > > tryLoad(const BufferView &key) const override
bool empty() const override
Returns true if the storage is empty.