UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
SparseSetElement.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
7#include <initializer_list>
8#include <type_traits>
9
10template<typename InElementType, bool bTypeLayout>
12{
13public:
15
17
19 template <
20 typename... InitType
21 UE_REQUIRES((sizeof...(InitType) != 1) || (!std::is_same_v<TSparseSetElementBase, std::decay_t<InitType>> && ...))
22 >
24 : Value(Forward<InitType>(InValue)...)
25 {
26 }
27
32
35
38
41};
42
43template<typename InElementType>
45{
47public:
49
51
53 template <
54 typename... InitType
55 UE_REQUIRES((sizeof...(InitType) != 1) || (!std::is_same_v<TSparseSetElementBase, std::decay_t<InitType>> && ...))
56 >
58 : Value(Forward<InitType>(InValue)...)
59 {
60 }
61
66
69
72
75};
76
78template <typename InElementType>
79class TSparseSetElement : public TSparseSetElementBase<InElementType, THasTypeLayout<InElementType>::Value>
80{
82public:
85
87 template <
88 typename... InitType
89 UE_REQUIRES((sizeof...(InitType) != 1) || (!std::is_same_v<TSparseSetElement, std::decay_t<InitType>> && ...))
90 >
92 : Super(Forward<InitType>(InValue)...)
93 {
94 }
95
100
101 // Comparison operators
103 {
104 return this->Value == Other.Value;
105 }
107 {
108 return this->Value != Other.Value;
109 }
110};
111
112namespace UE::Core::Private
113{
114 [[noreturn]] CORE_API void OnInvalidSetNum(unsigned long long NewNum);
115
116 template<typename HashType>
117 void CopyHash(HashType& Hash, int32& HashSize, const HashType& Copy, int32 HashSizeCopy)
118 {
119 DestructItems((FSetElementId*)Hash.GetAllocation(), HashSize);
120 Hash.ResizeAllocation(0, HashSizeCopy, sizeof(FSetElementId));
121 ConstructItems<FSetElementId>(Hash.GetAllocation(), (FSetElementId*)Copy.GetAllocation(), HashSizeCopy);
122 HashSize = HashSizeCopy;
123 }
124
125 template<typename HashType>
127 {
128 return ((FSetElementId*)Hash.GetAllocation())[HashIndex & (HashSize - 1)];
129 }
130
131 template<typename HashType>
132 void Rehash(HashType& Hash, int32 HashSize)
133 {
134 // Free the old hash.
135 Hash.ResizeAllocation(0, 0, sizeof(FSetElementId));
136
137 if (HashSize)
138 {
139 // Allocate the new hash.
141 Hash.ResizeAllocation(0, HashSize, sizeof(FSetElementId));
142 for (int32 HashIndex = 0; HashIndex < HashSize; ++HashIndex)
143 {
144 GetTypedHash(Hash, HashIndex, HashSize) = FSetElementId();
145 }
146 }
147 }
148}
149
151template <typename ElementType>
153{
154 return Ar << Element.Value;
155}
156
158template <typename ElementType>
160{
161 Ar << Element.Value;
162}
#define checkSlow(expr)
Definition AssertionMacros.h:332
FPlatformTypes::int32 int32
A 32-bit signed integer.
Definition Platform.h:1125
#define UE_FORCEINLINE_HINT
Definition Platform.h:723
FORCEINLINE constexpr void DestructItems(ElementType *Element, SizeType Count)
Definition MemoryOps.h:81
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
return true
Definition ExternalRpcRegistry.cpp:601
#define DECLARE_INLINE_TYPE_LAYOUT(T, Interface)
Definition MemoryLayout.h:558
#define UE_REQUIRES(...)
Definition Requires.h:86
UE_FORCEINLINE_HINT FArchive & operator<<(FArchive &Ar, TSparseSetElement< ElementType > &Element)
Definition SparseSetElement.h:152
Definition Archive.h:1208
Definition SetUtilities.h:95
Definition StructuredArchiveSlots.h:52
TSparseSetElementBase & operator=(TSparseSetElementBase &&)=default
TSparseSetElementBase(const TSparseSetElementBase &)=default
TSparseSetElementBase(TSparseSetElementBase &&)=default
InElementType ElementType
Definition SparseSetElement.h:48
TSparseSetElementBase & operator=(const TSparseSetElementBase &)=default
LAYOUT_MUTABLE_FIELD(FSetElementId, HashNextId)
UE_FORCEINLINE_HINT TSparseSetElementBase(InitType &&... InValue)
Definition SparseSetElement.h:57
Definition SparseSetElement.h:12
InElementType ElementType
Definition SparseSetElement.h:14
UE_FORCEINLINE_HINT TSparseSetElementBase(InitType &&... InValue)
Definition SparseSetElement.h:23
FSetElementId HashNextId
Definition SparseSetElement.h:37
TSparseSetElementBase()=default
TSparseSetElementBase & operator=(const TSparseSetElementBase &)=default
ElementType Value
Definition SparseSetElement.h:34
int32 HashIndex
Definition SparseSetElement.h:40
TSparseSetElementBase(const TSparseSetElementBase &)=default
TSparseSetElementBase & operator=(TSparseSetElementBase &&)=default
TSparseSetElementBase(TSparseSetElementBase &&)=default
Definition SparseSetElement.h:80
TSparseSetElement(const TSparseSetElement &)=default
UE_FORCEINLINE_HINT bool operator==(const TSparseSetElement &Other) const
Definition SparseSetElement.h:102
TSparseSetElement & operator=(const TSparseSetElement &)=default
TSparseSetElement(TSparseSetElement &&)=default
UE_FORCEINLINE_HINT bool operator!=(const TSparseSetElement &Other) const
Definition SparseSetElement.h:106
UE_FORCEINLINE_HINT TSparseSetElement(InitType &&... InValue)
Definition SparseSetElement.h:91
TSparseSetElement()=default
TSparseSetElement & operator=(TSparseSetElement &&)=default
implementation
Definition PlayInEditorLoadingScope.h:8
void Rehash(HashType &Hash, int32 HashSize)
Definition SparseSetElement.h:132
UE_FORCEINLINE_HINT FSetElementId & GetTypedHash(HashType &Hash, int32 HashIndex, int32 HashSize)
Definition SparseSetElement.h:126
void CopyHash(HashType &Hash, int32 &HashSize, const HashType &Copy, int32 HashSizeCopy)
Definition SparseSetElement.h:117
CORE_API void OnInvalidSetNum(unsigned long long NewNum)
Definition ContainerHelpers.cpp:12
static constexpr UE_FORCEINLINE_HINT bool IsPowerOfTwo(T Value)
Definition UnrealMathUtility.h:519