CatapultServer  v0.5.0.1 (Elephant)
IdentifierGroupCacheUtils.h
Go to the documentation of this file.
1 
21 #pragma once
24 #include "catapult/types.h"
25 
26 namespace catapult { namespace cache {
27 
29  template<typename TGroupedSet, typename TGroupingKey, typename TIdentifier>
30  void AddIdentifierWithGroup(TGroupedSet& groupedSet, const TGroupingKey& key, const TIdentifier& identifier) {
31  if (!groupedSet.contains(key))
32  groupedSet.insert(typename TGroupedSet::ElementType(key));
33 
34  auto groupIter = groupedSet.find(key);
35  auto* pGroup = groupIter.get();
36  pGroup->add(identifier);
37  }
38 
40  template<typename TSet, typename TGroupedSet, typename TGroupingKey, typename TAction>
41  void ForEachIdentifierWithGroup(TSet& set, const TGroupedSet& groupedSet, const TGroupingKey& key, TAction action) {
42  auto groupIter = groupedSet.find(key);
43  const auto* pGroup = groupIter.get();
44  if (!pGroup)
45  return;
46 
47  for (const auto& identifier : pGroup->identifiers()) {
48  auto valueIter = set.find(identifier);
49  auto* pValue = valueIter.get();
50  if (pValue)
51  action(*pValue);
52  }
53  }
54 
56  template<typename TGroupedSet, typename TGroupingKey, typename TIdentifier>
57  void RemoveIdentifierWithGroup(TGroupedSet& groupedSet, const TGroupingKey& key, const TIdentifier& identifier) {
58  auto groupIter = groupedSet.find(key);
59  auto* pGroup = groupIter.get();
60  if (!pGroup)
61  return;
62 
63  pGroup->remove(identifier);
64  if (pGroup->empty())
65  groupedSet.remove(key);
66  }
67 
69  template<typename TSet, typename TGroupedSet, typename TGroupingKey>
70  void RemoveAllIdentifiersWithGroup(TSet& set, TGroupedSet& groupedSet, const TGroupingKey& key) {
71  auto groupIter = groupedSet.find(key);
72  const auto* pGroup = groupIter.get();
73  if (!pGroup)
74  return;
75 
76  for (const auto& identifier : pGroup->identifiers())
77  set.remove(identifier);
78 
79  groupedSet.remove(key);
80  }
81 
83  template<typename TSet, typename TGroupedSet, typename TIdentifiers = typename TGroupedSet::ElementType::Identifiers>
84  TIdentifiers FindDeactivatingIdentifiersAtHeight(const TSet& set, const TGroupedSet& groupedSet, Height height) {
85  auto groupIter = groupedSet.find(height);
86  const auto* pGroup = groupIter.get();
87  if (!pGroup)
88  return {};
89 
90  TIdentifiers identifiers;
91  for (const auto& identifier : pGroup->identifiers()) {
92  auto valueIter = set.find(identifier);
93  auto* pValue = valueIter.get();
94  if (pValue && !pValue->isActive(height) && pValue->isActive(height - Height(1)))
95  identifiers.emplace(identifier);
96  }
97 
98  return identifiers;
99  }
100 }}
catapult::cache::FindDeactivatingIdentifiersAtHeight
TIdentifiers FindDeactivatingIdentifiersAtHeight(const TSet &set, const TGroupedSet &groupedSet, Height height)
Finds identifiers of all values in set (with grouped view groupedSet) that are deactivating at height...
Definition: IdentifierGroupCacheUtils.h:84
IdentifierGroup.h
catapult::cache::RemoveAllIdentifiersWithGroup
void RemoveAllIdentifiersWithGroup(TSet &set, TGroupedSet &groupedSet, const TGroupingKey &key)
Removes all values in set with grouping key according to groupedSet.
Definition: IdentifierGroupCacheUtils.h:70
catapult::cache::RemoveIdentifierWithGroup
void RemoveIdentifierWithGroup(TGroupedSet &groupedSet, const TGroupingKey &key, const TIdentifier &identifier)
Removes an identifier with grouping key from groupedSet.
Definition: IdentifierGroupCacheUtils.h:57
catapult::Height
utils::BaseValue< uint64_t, Height_tag > Height
Definition: src/catapult/types.h:85
catapult::cache::ForEachIdentifierWithGroup
void ForEachIdentifierWithGroup(TSet &set, const TGroupedSet &groupedSet, const TGroupingKey &key, TAction action)
Calls action for each value in set with grouping key according to groupedSet.
Definition: IdentifierGroupCacheUtils.h:41
catapult::utils::BaseValue< uint64_t, Height_tag >
catapult::cache::AddIdentifierWithGroup
void AddIdentifierWithGroup(TGroupedSet &groupedSet, const TGroupingKey &key, const TIdentifier &identifier)
Adds an identifier with with grouping key to groupedSet.
Definition: IdentifierGroupCacheUtils.h:30
catapult::action
std::function< void()> action
An action function.
Definition: functions.h:27
types.h
catapult
Definition: AddressExtractionExtension.cpp:28
BaseSetDelta.h