CatapultServer
v0.5.0.1 (Elephant)
|
Go to the documentation of this file.
28 #include <type_traits>
29 #include <unordered_map>
31 namespace catapult {
namespace deltaset {
66 template<
typename TSetTraits>
74 template<
typename TElementTraits,
typename TSetTraits>
80 using SetType =
typename TSetTraits::SetType;
83 using KeyType =
typename TSetTraits::KeyType;
88 std::is_same_v<ElementMutabilityTag, ImmutableTypeTag>,
116 return Find<FindConstIterator>(*
this, key);
122 auto iter = Find<FindIterator>(*
this, key);
130 template<
typename TResultIterator,
typename TBaseSetDelta>
131 static TResultIterator
Find(TBaseSetDelta& set,
const KeyType& key) {
132 if (
Contains(set.m_removedElements, key))
133 return TResultIterator();
136 if (originalIter.get())
139 auto addedIter = set.m_addedElements.find(key);
140 return set.m_addedElements.cend() != addedIter ? TResultIterator(std::move(addedIter)) : TResultIterator();
149 if (!originalIter.get())
152 auto copy = TElementTraits::Copy(originalIter.get());
185 template<
typename TSet>
187 return set.cend() != set.find(key);
198 template<
typename... TArgs>
206 const auto& key = TSetTraits::ToKey(element);
207 auto storage = TSetTraits::ToStorage(element);
226 pTargetElements->erase(key);
227 pTargetElements->insert(std::move(storage));
232 const auto& key = TSetTraits::ToKey(element);
347 template<
typename T,
typename =
void>
349 using Type = std::map<KeyType, uint32_t, typename T::key_compare>;
355 using Type = std::unordered_map<KeyType, uint32_t, typename T::hasher, typename T::key_equal>;
368 template<
typename TElementTraits2,
typename TSetTraits2>
FindConstIterator find(const KeyType &key, ImmutableTypeTag) const
Definition: BaseSetDelta.h:164
static TResultIterator Find(TBaseSetDelta &set, const KeyType &key)
Definition: BaseSetDelta.h:131
FindConstIterator find(const KeyType &key, MutableTypeTag) const
Definition: BaseSetDelta.h:157
uint32_t generationId() const
Gets the current generation id.
Definition: BaseSetDelta.h:320
MemorySetType m_copiedElements
Definition: BaseSetDelta.h:362
Insert failed because the element already exists (immutable elements only).
FindIterator find(const KeyType &key)
Definition: BaseSetDelta.h:121
InsertResult insert(const ElementType &element, MutableTypeTag)
Definition: BaseSetDelta.h:204
const SetType & m_originalElements
Definition: BaseSetDelta.h:359
std::conditional_t< std::is_same_v< ElementMutabilityTag, ImmutableTypeTag >, BaseSetDeltaFindConstIterator< FindTraits, TSetTraits >, BaseSetDeltaFindIterator< FindTraits, TSetTraits > > FindIterator
Definition: BaseSetDelta.h:91
BaseSetDeltaFindConstIterator< FindTraits, TSetTraits > FindConstIterator
Definition: BaseSetDelta.h:92
void clearKey(const KeyType &key)
Definition: BaseSetDelta.h:341
uint32_t m_generationId
Definition: BaseSetDelta.h:364
bool empty() const
Gets a value indicating whether or not the set is empty.
Definition: BaseSetDelta.h:103
Slim wrapper around changed elements.
Definition: DeltaElements.h:27
void markFoundElement(const KeyType &key, MutableTypeTag)
Definition: BaseSetDelta.h:169
Tag that indicates a type is immutable.
Definition: BaseSetDefaultTraits.h:162
An element pending insert was reverted.
std::map< KeyType, uint32_t, typename SetType ::key_compare > Type
Definition: BaseSetDelta.h:349
InsertResult insert(const ElementType &element, ImmutableTypeTag)
Definition: BaseSetDelta.h:231
void reset()
Resets all pending modifications.
Definition: BaseSetDelta.h:309
Traits for customizing the behavior of find depending on element type.
Definition: BaseSetDefaultTraits.h:180
Definition: BaseSetDelta.h:67
typename TElementTraits::MutabilityTag ElementMutabilityTag
Definition: BaseSetDelta.h:78
typename TSetTraits::KeyType KeyType
Definition: BaseSetDelta.h:83
RemoveResult remove(const KeyType &key, MutableTypeTag)
Definition: BaseSetDelta.h:263
std::unordered_map< KeyType, uint32_t, typename T::hasher, typename T::key_equal > Type
Definition: BaseSetDelta.h:355
TSetTraits SetTraits
Definition: BaseSetDelta.h:85
Definition: BaseSetDelta.h:348
InsertResult emplace(TArgs &&... args)
Creates an element around the passed arguments (args) and inserts the element into this set.
Definition: BaseSetDelta.h:199
InsertResult insert(const ElementType &element)
Definition: BaseSetDelta.h:193
uint32_t generationId(const KeyType &key) const
Gets the generation id associated with key.
Definition: BaseSetDelta.h:325
InsertResult
Possible results of an insert into a base set delta.
Definition: BaseSetDelta.h:34
void incrementGenerationId()
Increments the generation id.
Definition: BaseSetDelta.h:331
Definition: BaseSetFindIterator.h:30
detail::BaseSetConditionalIteratorWrapper< TFindTraits, TSetTraits, typename TSetTraits::SetType::const_iterator, typename TSetTraits::MemorySetType::const_iterator, typename TFindTraits::ConstResultType > BaseSetDeltaFindConstIterator
Iterator that returns a find (const) result from a base set delta.
Definition: BaseSetFindIterator.h:131
An existing element was removed.
typename is_type_expression< T, Enable >::type is_type_expression_t
true if the expression is valid and evaluates to a type, false otherwise.
Definition: Traits.h:98
RemoveResult
Possible results of a remove from a base set delta.
Definition: BaseSetDelta.h:49
FindIterator find(const KeyType &key, MutableTypeTag)
Definition: BaseSetDelta.h:143
size_t size() const
Gets the size of this set.
Definition: BaseSetDelta.h:108
DeltaElements< MemorySetType > deltas() const
Gets const references to the pending modifications.
Definition: BaseSetDelta.h:304
FindConstIterator find(const KeyType &key) const
Definition: BaseSetDelta.h:115
An element pending modification was reverted and removed (mutable elements only).
typename TSetTraits::SetType SetType
Definition: BaseSetDelta.h:80
An element pending removal was reverted.
An existing element was updated (mutable elements only).
No matching element was found.
void markKey(const KeyType &key)
Definition: BaseSetDelta.h:336
KeyGenerationIdMap< SetType >::Type m_keyGenerationIdMap
Definition: BaseSetDelta.h:365
MemorySetType m_addedElements
Definition: BaseSetDelta.h:360
RemoveResult remove(const KeyType &key, ImmutableTypeTag)
Definition: BaseSetDelta.h:275
friend BaseSetDeltaIterationView< TSetTraits2 > MakeIterableView(const BaseSetDelta< TElementTraits2, TSetTraits2 > &set)
Definition: AddressExtractionExtension.cpp:28
static constexpr bool Contains(const TSet &set, const KeyType &key)
Definition: BaseSetDelta.h:186
bool contains(const KeyType &key) const
Definition: BaseSetDelta.h:180
RemoveResult remove(const KeyType &key)
Removes the element identified by key from the delta.
Definition: BaseSetDelta.h:255
A new element was inserted.
typename TElementTraits::ElementType ElementType
Definition: BaseSetDelta.h:77
A class that can neither be copied nor moved.
Definition: NonCopyable.h:26
BaseSetDelta(const SetType &originalElements)
Creates a delta around originalElements.
Definition: BaseSetDelta.h:96
typename TSetTraits::MemorySetType MemorySetType
Definition: BaseSetDelta.h:81
void markFoundElement(const KeyType &, ImmutableTypeTag)
Definition: BaseSetDelta.h:173
Tag that indicates a type is mutable.
Definition: BaseSetDefaultTraits.h:148
MemorySetType m_removedElements
Definition: BaseSetDelta.h:361