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

#include <topper_trie_batch_impl.hpp>

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

Public Types

enum  Error { Error::PARENT_EXPIRED = 1 }
 
- Public Types inherited from kagome::storage::trie::TrieBatch
using Cursor = face::Iterable< Buffer, common::BufferConstRef, BufferView >::Cursor
 
- Public Types inherited from kagome::storage::face::ReadableMap< BufferView, Buffer >
using Key = BufferView
 
using Value = Buffer
 
using ValueView = std::reference_wrapper< Buffer >
 
using ConstValueView = std::reference_wrapper< const Buffer >
 
- Public Types inherited from kagome::storage::face::ReadableBase< BufferView >
using Key = BufferView
 
- Public Types inherited from kagome::storage::face::Iterable< Buffer, common::BufferConstRef, BufferView >
using Cursor = MapCursor< Buffer, common::BufferConstRef, BufferView >
 

Public Member Functions

 TopperTrieBatchImpl (const std::shared_ptr< TrieBatch > &parent)
 
outcome::result< common::BufferConstRefget (const BufferView &key) const override
 Get value by key. More...
 
outcome::result< std::optional< common::BufferConstRef > > tryGet (const BufferView &key) const override
 Get value by key. More...
 
std::unique_ptr< PolkadotTrieCursortrieCursor () override
 
outcome::result< bool > contains (const 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< void > put (const BufferView &key, const Buffer &value) override
 Store value by key. More...
 
outcome::result< void > put (const BufferView &key, Buffer &&value) override
 
outcome::result< void > remove (const BufferView &key) override
 Remove value by key. More...
 
outcome::result< std::tuple< bool, uint32_t > > clearPrefix (const BufferView &prefix, std::optional< uint64_t > limit) override
 
outcome::result< void > writeBack () override
 
- Public Member Functions inherited from kagome::storage::trie::TrieBatch
 ~TrieBatch () override=default
 
std::unique_ptr< Cursorcursor () final
 Returns new key-value iterator. More...
 
- Public Member Functions inherited from kagome::storage::face::ReadableMap< BufferView, Buffer >
virtual ~ReadableMap ()=default
 
- Public Member Functions inherited from kagome::storage::face::ReadableBase< BufferView >
virtual ~ReadableBase ()=default
 
- Public Member Functions inherited from kagome::storage::face::Writeable< BufferView, Buffer >
virtual ~Writeable ()=default
 
- Public Member Functions inherited from kagome::storage::face::Iterable< Buffer, common::BufferConstRef, BufferView >
virtual ~Iterable ()=default
 

Private Member Functions

bool wasClearedByPrefix (const BufferView &key) const
 

Private Attributes

std::map< Buffer, std::optional< Buffer >, std::less<> > cache_
 
std::deque< Buffercleared_prefixes_
 
std::weak_ptr< TrieBatchparent_
 

Detailed Description

Definition at line 21 of file topper_trie_batch_impl.hpp.

Member Enumeration Documentation

Enumerator
PARENT_EXPIRED 

Definition at line 23 of file topper_trie_batch_impl.hpp.

Constructor & Destructor Documentation

kagome::storage::trie::TopperTrieBatchImpl::TopperTrieBatchImpl ( const std::shared_ptr< TrieBatch > &  parent)
explicit

Definition at line 27 of file topper_trie_batch_impl.cpp.

Member Function Documentation

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

Remove all trie entries which key begins with the supplied prefix

Implements kagome::storage::trie::TrieBatch.

Definition at line 110 of file topper_trie_batch_impl.cpp.

outcome::result< bool > kagome::storage::trie::TopperTrieBatchImpl::contains ( const 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< BufferView >.

Definition at line 64 of file topper_trie_batch_impl.cpp.

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

Returns true if the storage is empty.

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

Definition at line 78 of file topper_trie_batch_impl.cpp.

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

Get value by key.

Parameters
keyK
Returns
V

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

Definition at line 31 of file topper_trie_batch_impl.cpp.

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

Store value by key.

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

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

Definition at line 93 of file topper_trie_batch_impl.cpp.

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

Remove value by key.

Parameters
keyK
Returns
error code if error happened

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

Definition at line 104 of file topper_trie_batch_impl.cpp.

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

Won't consider changes not written back to the parent batch

Implements kagome::storage::trie::TrieBatch.

Definition at line 57 of file topper_trie_batch_impl.cpp.

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

Get value by key.

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

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

Definition at line 41 of file topper_trie_batch_impl.cpp.

bool kagome::storage::trie::TopperTrieBatchImpl::wasClearedByPrefix ( const BufferView key) const
private

Definition at line 141 of file topper_trie_batch_impl.cpp.

outcome::result< void > kagome::storage::trie::TopperTrieBatchImpl::writeBack ( )
overridevirtual

Writes changes to the parent batch

Implements kagome::storage::trie::TopperTrieBatch.

Definition at line 124 of file topper_trie_batch_impl.cpp.

Member Data Documentation

std::map<Buffer, std::optional<Buffer>, std::less<> > kagome::storage::trie::TopperTrieBatchImpl::cache_
private

Definition at line 51 of file topper_trie_batch_impl.hpp.

std::deque<Buffer> kagome::storage::trie::TopperTrieBatchImpl::cleared_prefixes_
private

Definition at line 52 of file topper_trie_batch_impl.hpp.

std::weak_ptr<TrieBatch> kagome::storage::trie::TopperTrieBatchImpl::parent_
private

Definition at line 53 of file topper_trie_batch_impl.hpp.


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