veriblock-pop-cpp
C++11 Libraries for leveraging VeriBlock Proof-Of-Proof blockchain technology.
altintegration::PayloadsIndex< IndexT > Struct Template Reference

Payloads index that stores mapping "payload id -> set of containing blocks" from all NON-FINALIZED blocks. More...

Detailed Description

template<typename IndexT>
struct altintegration::PayloadsIndex< IndexT >
Note
KV in this index should be removed BEFORE block is finalized.

Definition at line 63 of file payloads_index.hpp.

#include <payloads_index.hpp>

+ Inheritance diagram for altintegration::PayloadsIndex< IndexT >:
+ Collaboration diagram for altintegration::PayloadsIndex< IndexT >:

Public Types

using index_t = IndexT
 
using hash_t = typename index_t::hash_t
 
using payload_id = std::vector< uint8_t >
 

Public Member Functions

void addBlock (const index_t &block)
 
void removeBlock (const index_t &block)
 
void add (const payload_id &id, const hash_t &block)
 
void remove (const payload_id &id, const hash_t &block)
 
const std::set< hash_t > & find (const payload_id &id) const
 
const std::unordered_map< payload_id, std::set< hash_t > > & getAll () const
 

Member Typedef Documentation

◆ hash_t

template<typename IndexT >
using altintegration::PayloadsIndex< IndexT >::hash_t = typename index_t::hash_t

Definition at line 65 of file payloads_index.hpp.

◆ index_t

template<typename IndexT >
using altintegration::PayloadsIndex< IndexT >::index_t = IndexT

Definition at line 64 of file payloads_index.hpp.

◆ payload_id

template<typename IndexT >
using altintegration::PayloadsIndex< IndexT >::payload_id = std::vector<uint8_t>

Definition at line 66 of file payloads_index.hpp.

Member Function Documentation

◆ add()

template<typename IndexT >
void altintegration::PayloadsIndex< IndexT >::add ( const payload_id &  id,
const hash_t &  block 
)
inline

Definition at line 81 of file payloads_index.hpp.

81 {
82 map_[id].insert(block);
83 }

◆ addBlock()

template<typename IndexT >
void altintegration::PayloadsIndex< IndexT >::addBlock ( const index_t &  block)
inline

Definition at line 68 of file payloads_index.hpp.

68 {
69 // in PayloadsIndex we can add only NON-FINALIZED blocks!
70 VBK_ASSERT_MSG(!block.finalized, block.toPrettyString());
71 detail::PLIAddBlock(*this, block);
72 }

◆ find()

template<typename IndexT >
const std::set< hash_t > & altintegration::PayloadsIndex< IndexT >::find ( const payload_id &  id) const
inline

Definition at line 102 of file payloads_index.hpp.

102 {
103 static std::set<hash_t> empty;
104 auto it = map_.find(id);
105 if (it == map_.end()) {
106 return empty;
107 }
108
109 return it->second;
110 }

◆ getAll()

template<typename IndexT >
const std::unordered_map< payload_id, std::set< hash_t > > & altintegration::PayloadsIndex< IndexT >::getAll ( ) const
inline

Definition at line 112 of file payloads_index.hpp.

112 {
113 return map_;
114 }

◆ remove()

template<typename IndexT >
void altintegration::PayloadsIndex< IndexT >::remove ( const payload_id &  id,
const hash_t &  block 
)
inline

Definition at line 85 of file payloads_index.hpp.

85 {
86 auto it = map_.find(id);
87 if (it == map_.end()) {
88 // not found
89 return;
90 }
91
92 auto& set = it->second;
93 size_t erased = set.erase(block);
94
95 if (set.empty()) {
96 // "value" set is empty, we can cleanup key
97 erased = map_.erase(id);
98 VBK_ASSERT(erased == 1);
99 }
100 }

◆ removeBlock()

template<typename IndexT >
void altintegration::PayloadsIndex< IndexT >::removeBlock ( const index_t &  block)
inline

Definition at line 74 of file payloads_index.hpp.

74 {
75 // when blocks are removed from PayloadsIndex they are mostly non finalized.
76 // but there's an edge case: when we deallocate entire Tree (in destructor)
77 // we can remove finalized blocks.
78 detail::PLIRemoveBlock(*this, block);
79 }

The documentation for this struct was generated from the following file: