UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
VVMMap.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#if WITH_VERSE_VM || defined(__INTELLISENSE__)
6
7#include "Containers/Map.h"
8#include "CoreTypes.h"
10#include "VerseVM/VVMCell.h"
11#include "VerseVM/VVMContext.h"
13#include "VerseVM/VVMHeap.h"
15#include "VerseVM/VVMValue.h"
17
18namespace Verse
19{
20struct FOp;
21struct VTask;
22
23/*
24 * The following types can be used as keys:
25 * logic
26 * int
27 * float
28 * char
29 * string
30 * enum
31 * A class, if it’s comparable
32 * An option, if the element type is comparable
33 * An array, if the element type is comparable
34 * A map if both the key and the value types are comparable
35 * A tuple if all elements in the tuple are comparable
36 */
37struct VMapBase : VHeapValue
38{
40 using KeyType = TWriteBarrier<VValue>;
42 using PairType = TPair<KeyType, ValType>;
43 using SequenceType = uint32;
44
46 {
48 : Map(Map)
49 , Index(Index) {}
51 {
52 const PairType& Pair = Map->GetPairTable()[Map->GetSequenceTable()[Index]];
53 return {Pair.Key.Get().Follow(), Pair.Value.Get().Follow()};
54 }
55 bool operator==(const RangedForIterator& Rhs) const { return Index == Rhs.Index; }
56 bool operator!=(const RangedForIterator& Rhs) const { return Index != Rhs.Index; }
57 RangedForIterator& operator++()
58 {
59 ++Index;
60 return *this;
61 }
62
63 const VMapBase* Map;
65 };
66
67protected:
68 VMapBase(FAllocationContext Context, uint32 InitialCapacity, VEmergentType* Type);
69 template <typename GetEntryByIndex>
70 VMapBase(FAllocationContext Context, uint32 MaxNumEntries, const GetEntryByIndex& GetEntry, VEmergentType* Type);
71
72 // This should only be called if you already have the required mutexes or know you don't need them.
73 // Returns the slot in the data table where the value was inserted and a boolean indicating if an existing entry was replaced.
74 COREUOBJECT_API TPair<uint32, bool> AddWithoutLocking(FAllocationContext Context, uint32 KeyHash, VValue Key, VValue Value, bool bTransactional = false);
75
76public:
77 uint32 Num() const
78 {
79 return NumElements;
80 }
81
82 COREUOBJECT_API VValue FindByHashWithSlot(FAllocationContext Context, uint32 Hash, VValue Key, uint32* OutSlot);
83 VValue FindWithSlot(FAllocationContext Context, VValue Key, SequenceType* OutSlot)
84 {
85 uint32 Hash = GetTypeHash(Key);
87 }
88 VValue FindByHash(FAllocationContext Context, uint32 Hash, VValue Key)
89 {
90 SequenceType Slot;
91 return FindByHashWithSlot(Context, Hash, Key, &Slot);
92 }
93 VValue Find(FAllocationContext Context, VValue Key)
94 {
95 uint32 Hash = GetTypeHash(Key);
96 return FindByHash(Context, Hash, Key);
97 }
98
99 // GetKey/GetValue doesn't verify that Index is within limits and
100 // only works as long as nothing is removed from the map.
101 VValue GetKey(uint32 Index)
102 {
103 check(Index < Capacity);
104 PairType* PairTable = GetPairTable();
106 return PairTable[SequenceTable[Index]].Key.Follow();
107 }
108
109 VValue GetValue(uint32 Index)
110 {
111 check(Index < Capacity);
112 PairType* PairTable = GetPairTable();
114 return PairTable[SequenceTable[Index]].Value.Follow();
115 }
116
117 void Add(FAllocationContext Context, VValue Key, VValue Value);
118
119 void AddTransactionally(FAllocationContext Context, VValue Key, VValue Value);
120
121 COREUOBJECT_API void Reserve(FAllocationContext Context, uint32 InCapacity);
122
124 {
125 return sizeof(PairType) * InCapacity;
126 }
128 {
129 return sizeof(SequenceType) * InCapacity;
130 }
131 size_t GetPairTableSize() const
132 {
133 return GetPairTableSizeForCapacity(Capacity);
134 }
135 size_t GetSequenceTableSize() const
136 {
137 return GetSequenceTableSizeForCapacity(Capacity);
138 }
139 size_t GetAllocatedSize() const
140 {
142 }
143 const PairType* GetPairTable() const
144 {
145 return Data.Get().GetPtr();
146 }
147 const SequenceType* GetSequenceTable() const
148 {
149 return SequenceData.Get().GetPtr();
150 }
151 PairType* GetPairTable()
152 {
153 return Data.Get().GetPtr();
154 }
156 {
157 return SequenceData.Get().GetPtr();
158 }
159
160 // These `new` calls are templated so as to avoid boilerplate News/Ctors in VMapBase's subclasses.
161 template <typename MapType>
162 static MapType& New(FAllocationContext Context, uint32 InitialCapacity = 0)
163 {
164 std::byte* Cell = Context.AllocateFastCell(sizeof(MapType));
165 VEmergentType& EmergentType = MapType::GlobalTrivialEmergentType.Get(Context);
166 return *new (Cell) MapType{Context, InitialCapacity, &EmergentType};
167 }
168
169 template <typename MapType, typename GetEntryByIndex>
170 static MapType& New(FAllocationContext Context, uint32 MaxNumEntries, const GetEntryByIndex& GetEntry);
171
172 template <typename FunctionType>
173 void ForEachImpl(FunctionType);
174
175 template <typename FunctionType>
176 void ForEach(FunctionType);
177
178 template <typename MapType, typename FunctionType>
179 MapType& TraverseImpl(FAllocationContext, FunctionType);
180
181 template <typename MapType, typename FunctionType>
182 MapType& Traverse(FAllocationContext, FunctionType);
183
184 COREUOBJECT_API VValue MeltImpl(FAllocationContext Context);
185
186 COREUOBJECT_API ECompares EqualImpl(FAllocationContext Context, VCell* Other, const TFunction<void(::Verse::VValue, ::Verse::VValue)>& HandlePlaceholder);
187
189
190 void VisitMembersImpl(FAllocationContext Context, FDebuggerVisitor& Visitor);
191
192 COREUOBJECT_API void AppendToStringImpl(FAllocationContext Context, FUtf8StringBuilderBase& Builder, EValueStringFormat Format, TSet<const void*>& VisitedObjects, uint32 RecursionDepth);
194
195 template <typename MapType>
196 static void SerializeLayoutImpl(FAllocationContext Context, MapType*& This, FStructuredArchiveVisitor& Visitor);
197
198 void SerializeImpl(FAllocationContext Context, FStructuredArchiveVisitor& Visitor);
199
201 {
202 RangedForIterator it(this, 0);
203 return it;
204 }
205
206 RangedForIterator end() const
207 {
208 RangedForIterator it(this, NumElements);
209 return it;
210 }
211
213 TWriteBarrier<TAux<SequenceType>> SequenceData; // initial insert sequence only. Overwritten values will stay in their original sequence
214 uint32 NumElements;
215 uint32 Capacity;
216};
217
218struct VMap : VMapBase
219{
222
223 using VMapBase::VMapBase;
224
225 static void SerializeLayout(FAllocationContext Context, VMap*& This, FStructuredArchiveVisitor& Visitor) { SerializeLayoutImpl<VMap>(Context, This, Visitor); }
226};
227
228struct VMutableMap : VMapBase
229{
232
233 using VMapBase::VMapBase;
234
235 FOpResult FreezeImpl(FAllocationContext Context, VTask*, FOp* AwaitPC);
236
237 static void SerializeLayout(FAllocationContext Context, VMutableMap*& This, FStructuredArchiveVisitor& Visitor) { SerializeLayoutImpl<VMutableMap>(Context, This, Visitor); }
238};
239
241{
244
245 static VPersistentMap& New(FAllocationContext Context, FString Path, VValue ValueType);
246
247 static void SerializeLayout(FAllocationContext Context, VPersistentMap*& This, FStructuredArchiveVisitor& Visitor);
248
249 void SerializeImpl(FAllocationContext Context, FStructuredArchiveVisitor& Visitor);
250
251 VType& GetValueType() const { return ValueType.Get().StaticCast<VType>(); }
252
253 void NotifyKeyUpdate(FAllocationContext Context, VValue Key, VValue Value);
254
255 FString Path;
256 TWriteBarrier<VValue> ValueType;
258
259private:
260 static VPersistentMap& New(FAllocationContext Context);
261
262 VPersistentMap(FAllocationContext Context)
264 {
265 }
266
268};
269
270} // namespace Verse
271#endif // WITH_VERSE_VM
EForEachResult ForEach(T &Array, const PREDICATE_CLASS &Predicate)
Definition AISense_Sight.cpp:60
#define check(expr)
Definition AssertionMacros.h:314
UE_FORCEINLINE_HINT FLinearColor operator*(float Scalar, const FLinearColor &Color)
Definition Color.h:473
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
UE_FORCEINLINE_HINT bool operator!=(const FIndexedPointer &Other) const
Definition LockFreeList.h:76
T * New(FMemStackBase &Mem, int32 Count=1, int32 Align=DEFAULT_ALIGNMENT)
Definition MemStack.h:259
@ Num
Definition MetalRHIPrivate.h:234
uint32_t uint32
Definition binka_ue_file_header.h:6
Definition JsonObject.h:23
Definition AndroidPlatformMisc.h:14
Definition UnrealString.h.inl:34
Definition SharedPointer.h:692
Definition StringBuilder.h:79
GeometryCollection::Facades::FMuscleActivationData Data
Definition MuscleActivationConstraints.h:15
uint32 GetTypeHash(const FKey &Key)
Definition BlackboardKey.h:35
T::FDataType GetValue(const UBlackboardComponent &Blackboard, const FName &Name, FBlackboard::FKey &InOutCachedKey, const typename T::FDataType &DefaultValue)
Definition ValueOrBBKey.h:51
const FColor Path(255, 255, 255)
Definition MeshAttributeArray.h:2195
SIZE_T GetAllocatedSize(const T &Value)
Definition ManagedArray.h:93
FORCEINLINE T * Get(const FObjectPtr &ObjectPtr)
Definition ObjectPtr.h:426
bool SerializeImpl(const UScriptStruct *InSourceEventType, const void *InSourceEventData, FLiveLinkSerializedFrameData &OutSerializedData)
Definition LiveLinkCompression.cpp:126
UStruct * GetValueType(const FStructSerializerState &State)
Definition StructSerializer.cpp:254
bool operator==(const FCachedAssetKey &A, const FCachedAssetKey &B)
Definition AssetDataMap.h:501
FORCEINLINE FStridedReferenceIterator begin(FStridedReferenceView View)
Definition FastReferenceCollector.h:490
FORCEINLINE FStridedReferenceIterator end(FStridedReferenceView View)
Definition FastReferenceCollector.h:491
FORCEINLINE UE_STRING_CLASS RhsType && Rhs
Definition String.cpp.inl:718
Definition Archive.h:36
U16 Index
Definition radfft.cpp:71
Definition Tuple.h:652