1#ifndef DE6BAACA_91D4_4C99_B0C5_F1AB318E58B0
2#define DE6BAACA_91D4_4C99_B0C5_F1AB318E58B0
5#include <unordered_map>
7#include <veriblock/pop/assert.hpp>
9#include "payloads_index_detail.hpp"
16template <
typename ContainerIndex>
18 using index_t = ContainerIndex;
19 using hash_t =
typename ContainerIndex::hash_t;
20 using payload_id = std::vector<uint8_t>;
22 const hash_t* find(
const payload_id& pid)
const {
23 auto it = map_.find(pid);
24 if (it == map_.end()) {
31 bool empty()
const {
return map_.empty(); }
33 size_t size()
const {
return map_.size(); }
35 void add(
const payload_id& pid,
const hash_t& hash) {
36 auto it = map_.find(pid);
37 VBK_ASSERT(it == map_.end());
38 map_.insert(std::make_pair(pid, hash));
41 void remove(
const payload_id& pid) {
42 auto it = map_.find(pid);
43 VBK_ASSERT(it != map_.end());
47 void addBlock(
const index_t& block) {
49 VBK_ASSERT_MSG(block.finalized, block.toPrettyString());
50 detail::PLIAddBlock(*
this, block);
53 const std::unordered_map<payload_id, hash_t>& getAll()
const {
return map_; }
56 std::unordered_map<payload_id, hash_t> map_;
62template <
typename IndexT>
64 using index_t = IndexT;
65 using hash_t =
typename index_t::hash_t;
66 using payload_id = std::vector<uint8_t>;
68 void addBlock(
const index_t& block) {
70 VBK_ASSERT_MSG(!block.finalized, block.toPrettyString());
71 detail::PLIAddBlock(*
this, block);
74 void removeBlock(
const index_t& block) {
78 detail::PLIRemoveBlock(*
this, block);
81 void add(
const payload_id&
id,
const hash_t& block) {
82 map_[id].insert(block);
85 void remove(
const payload_id&
id,
const hash_t& block) {
86 auto it = map_.find(
id);
87 if (it == map_.end()) {
92 auto& set = it->second;
93 size_t erased = set.erase(block);
97 erased = map_.erase(
id);
98 VBK_ASSERT(erased == 1);
102 const std::set<hash_t>& find(
const payload_id&
id)
const {
103 static std::set<hash_t> empty;
104 auto it = map_.find(
id);
105 if (it == map_.end()) {
112 const std::unordered_map<payload_id, std::set<hash_t>>& getAll()
const {
117 std::unordered_map<payload_id, std::set<hash_t>> map_;
Stores a mapping "payload id -> containing block" hash of payloads that are stored in finalized block...
Payloads index that stores mapping "payload id -> set of containing blocks" from all NON-FINALIZED bl...