CatapultServer  v0.5.0.1 (Elephant)
LockInfoCacheDelta.h
Go to the documentation of this file.
1 
21 #pragma once
26 
27 namespace catapult { namespace cache {
28 
30  template<typename TDescriptor, typename TCacheTypes>
31  struct LockInfoCacheDeltaMixins : public PatriciaTreeCacheMixins<typename TCacheTypes::PrimaryTypes::BaseSetDeltaType, TDescriptor> {
33  typename TCacheTypes::PrimaryTypes::BaseSetDeltaType,
34  typename TCacheTypes::HeightGroupingTypes::BaseSetDeltaType>;
36  typename TCacheTypes::PrimaryTypes::BaseSetDeltaType,
37  typename TCacheTypes::HeightGroupingTypes::BaseSetDeltaType>;
38  };
39 
41  template<typename TDescriptor, typename TCacheTypes>
43  : public utils::MoveOnly
44  , public LockInfoCacheDeltaMixins<TDescriptor, TCacheTypes>::Size
45  , public LockInfoCacheDeltaMixins<TDescriptor, TCacheTypes>::Contains
46  , public LockInfoCacheDeltaMixins<TDescriptor, TCacheTypes>::ConstAccessor
47  , public LockInfoCacheDeltaMixins<TDescriptor, TCacheTypes>::MutableAccessor
48  , public LockInfoCacheDeltaMixins<TDescriptor, TCacheTypes>::PatriciaTreeDelta
49  , public LockInfoCacheDeltaMixins<TDescriptor, TCacheTypes>::ActivePredicate
50  , public LockInfoCacheDeltaMixins<TDescriptor, TCacheTypes>::BasicInsertRemove
51  , public LockInfoCacheDeltaMixins<TDescriptor, TCacheTypes>::Touch
52  , public LockInfoCacheDeltaMixins<TDescriptor, TCacheTypes>::Pruning
53  , public LockInfoCacheDeltaMixins<TDescriptor, TCacheTypes>::DeltaElements {
54  public:
56 
57  public:
59  explicit BasicLockInfoCacheDelta(const typename TCacheTypes::BaseSetDeltaPointers& lockInfoSets)
60  : LockInfoCacheDeltaMixins<TDescriptor, TCacheTypes>::Size(*lockInfoSets.pPrimary)
61  , LockInfoCacheDeltaMixins<TDescriptor, TCacheTypes>::Contains(*lockInfoSets.pPrimary)
62  , LockInfoCacheDeltaMixins<TDescriptor, TCacheTypes>::ConstAccessor(*lockInfoSets.pPrimary)
63  , LockInfoCacheDeltaMixins<TDescriptor, TCacheTypes>::MutableAccessor(*lockInfoSets.pPrimary)
64  , LockInfoCacheDeltaMixins<TDescriptor, TCacheTypes>::PatriciaTreeDelta(*lockInfoSets.pPrimary, lockInfoSets.pPatriciaTree)
65  , LockInfoCacheDeltaMixins<TDescriptor, TCacheTypes>::ActivePredicate(*lockInfoSets.pPrimary)
66  , LockInfoCacheDeltaMixins<TDescriptor, TCacheTypes>::BasicInsertRemove(*lockInfoSets.pPrimary)
67  , LockInfoCacheDeltaMixins<TDescriptor, TCacheTypes>::Touch(*lockInfoSets.pPrimary, *lockInfoSets.pHeightGrouping)
68  , LockInfoCacheDeltaMixins<TDescriptor, TCacheTypes>::Pruning(*lockInfoSets.pPrimary, *lockInfoSets.pHeightGrouping)
69  , LockInfoCacheDeltaMixins<TDescriptor, TCacheTypes>::DeltaElements(*lockInfoSets.pPrimary)
70  , m_pDelta(lockInfoSets.pPrimary)
71  , m_pHeightGroupingDelta(lockInfoSets.pHeightGrouping)
72  {}
73 
74  public:
77 
78  public:
80  void insert(const typename TDescriptor::ValueType& value) {
82  AddIdentifierWithGroup(*m_pHeightGroupingDelta, value.Height, TDescriptor::GetKeyFromValue(value));
83  }
84 
86  void remove(const typename TDescriptor::KeyType& key) {
87  auto iter = m_pDelta->find(key);
88  const auto* pLockInfo = iter.get();
89  if (!!pLockInfo)
90  RemoveIdentifierWithGroup(*m_pHeightGroupingDelta, pLockInfo->Height, key);
91 
93  }
94 
98  if (state::LockStatus::Unused == lockInfo.Status)
99  consumer(lockInfo);
100  });
101  }
102 
103  private:
104  typename TCacheTypes::PrimaryTypes::BaseSetDeltaPointerType m_pDelta;
105  typename TCacheTypes::HeightGroupingTypes::BaseSetDeltaPointerType m_pHeightGroupingDelta;
106  };
107 
109  template<typename TDescriptor, typename TCacheTypes, typename TBasicView = BasicLockInfoCacheDelta<TDescriptor, TCacheTypes>>
110  class LockInfoCacheDelta : public ReadOnlyViewSupplier<TBasicView> {
111  public:
113  explicit LockInfoCacheDelta(const typename TCacheTypes::BaseSetDeltaPointers& lockInfoSets)
114  : ReadOnlyViewSupplier<TBasicView>(lockInfoSets)
115  {}
116  };
117 }}
catapult::cache::BasicInsertRemoveMixin::remove
void remove(const KeyType &key)
Removes the value identified by key from the cache.
Definition: CacheMixins.h:295
catapult::cache::BasicLockInfoCacheDelta::processUnusedExpiredLocks
void processUnusedExpiredLocks(Height height, const consumer< const typename TDescriptor::ValueType > &consumer) const
Processes all unused lock infos that expired at height by passing them to consumer.
Definition: LockInfoCacheDelta.h:96
catapult::state::LockStatus::Unused
Lock is unused.
catapult::cache::BasicInsertRemoveMixin::insert
void insert(const ValueType &value)
Inserts value into the cache.
Definition: CacheMixins.h:285
catapult::cache::BasicLockInfoCacheDelta::BasicLockInfoCacheDelta
BasicLockInfoCacheDelta(const typename TCacheTypes::BaseSetDeltaPointers &lockInfoSets)
Creates a delta around lockInfoSets.
Definition: LockInfoCacheDelta.h:59
catapult::cache::ReadOnlyViewSupplier
Decorates a view and supplies a read-only view.
Definition: ReadOnlyViewSupplier.h:28
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::cache::BasicLockInfoCacheDelta::remove
void remove(const typename TDescriptor::KeyType &key)
Removes the value identified by key from the cache.
Definition: LockInfoCacheDelta.h:86
ReadOnlyViewSupplier.h
catapult::cache::LockInfoCacheDelta::LockInfoCacheDelta
LockInfoCacheDelta(const typename TCacheTypes::BaseSetDeltaPointers &lockInfoSets)
Creates a delta around lockInfoSets.
Definition: LockInfoCacheDelta.h:113
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::as_const
constexpr const T & as_const(T &ref)
Coerces a reference (ref) to a const reference.
Definition: Casting.h:31
catapult::utils::BaseValue< uint64_t, Height_tag >
catapult::cache::PatriciaTreeCacheMixins
Grouping of all basic and patricia tree cache mixins for a single set.
Definition: CacheMixinAliases.h:52
catapult::cache::BasicLockInfoCacheDelta
Basic delta on top of the lock info cache.
Definition: LockInfoCacheDelta.h:42
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::cache::BasicLockInfoCacheDelta::m_pHeightGroupingDelta
TCacheTypes::HeightGroupingTypes::BaseSetDeltaPointerType m_pHeightGroupingDelta
Definition: LockInfoCacheDelta.h:105
catapult::cache::BasicLockInfoCacheDelta< SecretLockInfoCacheDescriptor, SecretLockInfoCacheTypes >::ReadOnlyView
typename SecretLockInfoCacheTypes ::CacheReadOnlyType ReadOnlyView
Definition: LockInfoCacheDelta.h:55
catapult::validators::CacheReadOnlyType
typename cache::AccountRestrictionCacheTypes::CacheReadOnlyType CacheReadOnlyType
Definition: AddressInteractionValidator.cpp:30
catapult::utils::MoveOnly
A class that can be moved but not copied.
Definition: NonCopyable.h:43
CacheMixinAliases.h
catapult::cache::HeightBasedTouchMixin
A mixin for height-based touching.
Definition: CacheMixins.h:310
catapult::cache::BasicLockInfoCacheDelta::m_pDelta
TCacheTypes::PrimaryTypes::BaseSetDeltaPointerType m_pDelta
Definition: LockInfoCacheDelta.h:104
IdentifierGroupCacheUtils.h
catapult
Definition: AddressExtractionExtension.cpp:28
catapult::cache::LockInfoCacheDeltaMixins
Mixins used by the lock info cache delta.
Definition: LockInfoCacheDelta.h:31
BaseSetDelta.h
catapult::cache::BasicLockInfoCacheDelta::insert
void insert(const typename TDescriptor::ValueType &value)
Inserts value into the cache.
Definition: LockInfoCacheDelta.h:80
catapult::consumer
std::function< void(TArgs...)> consumer
A consumer function.
Definition: functions.h:35
catapult::cache::HeightBasedPruningMixin
A mixin for height-based pruning.
Definition: CacheMixins.h:335
catapult::cache::LockInfoCacheDelta
Delta on top of the lock info cache.
Definition: LockInfoCacheDelta.h:110