UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
VVMMapInline.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
10#include "VerseVM/VVMMap.h"
14
15namespace Verse
16{
17
18inline void VMapBase::Add(FAllocationContext Context, VValue Key, VValue Value)
19{
20 check(Capacity > 0);
21 FCellUniqueLock Lock(Mutex);
22
23 uint32 KeyHash = GetTypeHash(Key);
24 AddWithoutLocking(Context, KeyHash, Key, Value);
25}
26
27inline void VMapBase::AddTransactionally(FAllocationContext Context, VValue Key, VValue Value)
28{
29 check(Capacity > 0);
30 FCellUniqueLock Lock(Mutex);
31
32 uint32 KeyHash = GetTypeHash(Key);
33 bool bTransactional = true;
34 AddWithoutLocking(Context, KeyHash, Key, Value, bTransactional);
35}
36
37inline VMapBase::VMapBase(FAllocationContext Context, uint32 InitialCapacity, VEmergentType* Type)
39 , NumElements(0)
40 , Capacity(0)
41{
43 Reserve(Context, InitialCapacity);
44}
45
46template <typename GetEntryByIndex>
47inline VMapBase::VMapBase(FAllocationContext Context, uint32 MaxNumEntries, const GetEntryByIndex& GetEntry, VEmergentType* Type)
49 , NumElements(0)
50 , Capacity(0)
51{
52 AutoRTFM::UnreachableIfClosed("#jira SOL-8415");
53
55 Reserve(Context, MaxNumEntries * 2);
56
57 // Constructing a map in Verse has these semantics:
58 // - If the same key appears more than once, it's as if only the last key was provided.
59 // - The order of the map is based on the textual order a map is written in.
60 // - E.g, map{K1=>V1, K2=>V2} has the order (K1, V1) then (K2, V2).
61 // And map{K1=>V1, K2=>V2, K1=>V3} has the order (K2, V2) then (K1, V3).
62 for (uint32 Index = 0; Index < MaxNumEntries; ++Index)
63 {
64 TPair<VValue, VValue> Pair = GetEntry(Index);
65 uint32 KeyHash = GetTypeHash(Pair.Key);
66 TPair<uint32, bool> Res = AddWithoutLocking(Context, KeyHash, Pair.Key, Pair.Value); // We don't need to lock because we can't be visited by the GC until after the next handshake.
67 uint32 Slot = Res.Get<0>();
68 bool SlotOverwritten = Res.Get<1>();
70 {
72 uint32 SeqIdx = 0;
73 while (SeqIdx < NumElements)
74 {
75 if (SequenceTable[SeqIdx] == Slot)
76 {
77 // if we've overwritten a value, we need to change the sequence table so the new slot is at the end.
78 FMemory::Memmove(SequenceTable + SeqIdx, SequenceTable + SeqIdx + 1, sizeof(SequenceTable[0]) * (NumElements - SeqIdx - 1));
79 SequenceTable[NumElements - 1] = Slot;
80 break;
81 }
82 ++SeqIdx;
83 }
84 }
85 }
86}
87
88template <typename MapType, typename GetEntryByIndex>
89inline MapType& VMapBase::New(FAllocationContext Context, uint32 MaxNumEntries, const GetEntryByIndex& GetEntry)
90{
91 return *new (FAllocationContext(Context).AllocateFastCell(sizeof(MapType))) MapType(Context, MaxNumEntries, GetEntry, &MapType::GlobalTrivialEmergentType.Get(Context));
92}
93
94template <typename MapType>
95void VMapBase::SerializeLayoutImpl(FAllocationContext Context, MapType*& This, FStructuredArchiveVisitor& Visitor)
96{
97 if (Visitor.IsLoading())
98 {
99 This = &VMapBase::New<MapType>(Context);
100 }
101}
102
103} // namespace Verse
104
105#endif
#define check(expr)
Definition AssertionMacros.h:314
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
FRWLock Lock
Definition UnversionedPropertySerialization.cpp:921
uint32_t uint32
Definition binka_ue_file_header.h:6
Type
Definition PawnAction_Move.h:11
@ Visitor
Definition XmppMultiUserChat.h:94
uint32 GetTypeHash(const FKey &Key)
Definition BlackboardKey.h:35
FORCEINLINE T * Get(const FObjectPtr &ObjectPtr)
Definition ObjectPtr.h:426
Definition Archive.h:36
uint32 GetTypeHash(TPtrVariant< Ts... > Ptr)
Definition VVMPtrVariant.h:83
U16 Index
Definition radfft.cpp:71
static UE_FORCEINLINE_HINT void * Memmove(void *Dest, const void *Src, SIZE_T Count)
Definition UnrealMemory.h:109
Definition Tuple.h:652