24#define UE_COMPACTHASHTABLE_CALLBYTYPE(NextIndexCount) \
25 switch (UE::Core::CompactHashTable::GetTypeSize(NextIndexCount)) { \
26 case 1: { UE_COMPACTHASHTABLE_EXECUTEBYTYPE(uint8); } break; \
27 case 2: { UE_COMPACTHASHTABLE_EXECUTEBYTYPE(uint16); } break; \
28 case 4: { UE_COMPACTHASHTABLE_EXECUTEBYTYPE(uint32); } break; \
29 default: checkNoEntry(); }
34 template<
typename IndexType>
37 const uint32 HashIndex = Key & (HashCount - 1);
39 for (IndexType* Lookup = &HashData[HashIndex]; *Lookup < NextIndexCount; Lookup = &NextIndexData[*Lookup])
44 *Lookup = NextIndexData[
Index];
56 return 1 + int(IndexCount > 0xff) + int(IndexCount > 0xffff) * 2;
61 return 0 + int(IndexCount > 0xff) + int(IndexCount > 0xffff);
66 return ((
size_t)IndexCount + HashCount) <<
GetTypeShift(IndexCount);
91 template<
typename IndexType>
94 const uint32 HashIndex = Key & (HashCount - 1);
95 const IndexType FirstIndex = HashData[HashIndex];
98 constexpr IndexType InvalidIndex = (IndexType)
INDEX_NONE;
103 template<
typename IndexType>
107 const IndexType FirstIndex = HashData[HashIndex];
110 constexpr IndexType InvalidIndex = (IndexType)
INDEX_NONE;
115 template<
typename IndexType>
119 const IndexType NextIndex = NextIndexData[
Index];
122 constexpr IndexType InvalidIndex = (IndexType)
INDEX_NONE;
127 template<
typename IndexType,
typename PredicateType>
130 for (IndexType ElementIndex = HashData[Key & (HashCount - 1)]; ElementIndex != (IndexType)
INDEX_NONE; ElementIndex = NextIndexData[ElementIndex])
132 if (Predicate(ElementIndex))
137 checkSlow(ElementIndex < NextIndexCount);
143 template<
typename IndexType>
148 const uint32 HashIndex = Key & (HashCount - 1);
149 NextIndexData[
Index] = HashData[HashIndex];
150 HashData[HashIndex] = (IndexType)
Index;
156 template<
typename IndexType>
161 UE::Core::CompactHashTable::Private::RemoveInternal<IndexType>(
Index, Key, HashData, HashCount, NextIndexData, NextIndexCount);
163 if (
Index != LastIndex)
166 UE::Core::CompactHashTable::Private::RemoveInternal<IndexType>(LastIndex,
OptLastKey, HashData, HashCount, NextIndexData, NextIndexCount);
169 NextIndexData[
Index] = HashData[HashIndex];
170 HashData[HashIndex] = (IndexType)
Index;
177 template<
typename IndexType>
182 UE::Core::CompactHashTable::Private::RemoveInternal<IndexType>(
Index, Key, HashData, HashCount, NextIndexData, NextIndexCount);
185 for (
uint32 HashIndex = 0; HashIndex < HashCount; ++HashIndex)
187 if (HashData[HashIndex] >
Index && HashData[HashIndex] != (IndexType)
INDEX_NONE)
189 --HashData[HashIndex];
224template<u
int32 ElementCount, u
int32 HashCount = UE::Core::CompactHashTable::GetHashCount(ElementCount)>
258 template<
typename PredicateType>
306 #define UE_COMPACTHASHTABLE_EXECUTEBYTYPE(Type) return UE::Core::CompactHashTable::GetFirst(Key, (const Type *)HashData, HashCount)
308 #undef UE_COMPACTHASHTABLE_EXECUTEBYTYPE
315 #define UE_COMPACTHASHTABLE_EXECUTEBYTYPE(Type) return UE::Core::CompactHashTable::GetFirstByIndex(HashIndex, (const Type *)HashData, HashCount)
317 #undef UE_COMPACTHASHTABLE_EXECUTEBYTYPE
325 #define UE_COMPACTHASHTABLE_EXECUTEBYTYPE(Type) return UE::Core::CompactHashTable::GetNext(Index, (const Type *)NextIndexData, CurrentCount)
327 #undef UE_COMPACTHASHTABLE_EXECUTEBYTYPE
331 template<
typename PredicateType>
335 #define UE_COMPACTHASHTABLE_EXECUTEBYTYPE(Type) return UE::Core::CompactHashTable::Find(Key, (const Type *)HashData, HashCount, (const Type *)NextIndexData, CurrentCount, Predicate)
337 #undef UE_COMPACTHASHTABLE_EXECUTEBYTYPE
368 #define UE_COMPACTHASHTABLE_EXECUTEBYTYPE(Type) UE::Core::CompactHashTable::Add(Index, Key, (Type*)(HashData), HashCount, (Type*)(NextIndexData), NextIndexCount)
370 #undef UE_COMPACTHASHTABLE_EXECUTEBYTYPE
375 #define UE_COMPACTHASHTABLE_EXECUTEBYTYPE(Type) return UE::Core::CompactHashTable::Remove(Index, Key, LastIndex, OptLastKey, (Type*)(HashData), HashCount, (Type*)(NextIndexData), NextIndexCount)
377 #undef UE_COMPACTHASHTABLE_EXECUTEBYTYPE
382 #define UE_COMPACTHASHTABLE_EXECUTEBYTYPE(Type) return UE::Core::CompactHashTable::RemoveStable(Index, Key, (Type*)(HashData), HashCount, (Type*)(NextIndexData), NextIndexCount)
384 #undef UE_COMPACTHASHTABLE_EXECUTEBYTYPE
#define checkSlow(expr)
Definition AssertionMacros.h:332
#define checkfSlow(expr, format,...)
Definition AssertionMacros.h:333
#define UE_COMPACTHASHTABLE_CALLBYTYPE(NextIndexCount)
Definition CompactHashTable.h:24
ENoInit
Definition CoreMiscDefines.h:158
@ INDEX_NONE
Definition CoreMiscDefines.h:150
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
Definition Core.Build.cs:8
Definition CompactHashTable.h:350
UE_FORCEINLINE_HINT void RemoveStable(uint32 Index, uint32 Key) const
Definition CompactHashTable.h:380
void Reset() const
Definition CompactHashTable.h:357
void Add(uint32 Index, uint32 Key) const
Definition CompactHashTable.h:365
UE_FORCEINLINE_HINT FCompactHashTableView(uint8 *Memory, uint32 InNextIndexCount, uint32 InHashCount, size_t MemorySize)
Definition CompactHashTable.h:352
UE_FORCEINLINE_HINT void Remove(uint32 Index, uint32 Key, uint32 LastIndex, uint32 OptLastKey) const
Definition CompactHashTable.h:373
Definition CompactHashTable.h:283
const uint8 * NextIndexData
Definition CompactHashTable.h:342
uint32 GetFirst(uint32 Key) const
Definition CompactHashTable.h:304
uint32 GetHashCount() const
Definition CompactHashTable.h:298
uint32 GetNext(uint32 Index, uint32 CurrentCount) const
Definition CompactHashTable.h:321
uint32 NextIndexCount
Definition CompactHashTable.h:344
uint32 HashCount
Definition CompactHashTable.h:345
const uint8 * HashData
Definition CompactHashTable.h:343
uint32 Find(uint32 Key, uint32 CurrentCount, const PredicateType &Predicate) const
Definition CompactHashTable.h:332
FConstCompactHashTableView()=default
uint32 GetFirstByIndex(uint32 HashIndex) const
Definition CompactHashTable.h:313
FConstCompactHashTableView(const uint8 *Memory, uint32 InNextIndexCount, uint32 InHashCount, size_t MemorySize)
Definition CompactHashTable.h:287
Definition CompactHashTable.h:226
typename TCompactHashTypeLookupBySize< UE::Core::CompactHashTable::GetTypeSize(ElementCount)>::Type IndexType
Definition CompactHashTable.h:228
IndexType NextIndexData[ElementCount]
Definition CompactHashTable.h:277
UE_FORCEINLINE_HINT void Reset()
Definition CompactHashTable.h:237
TStaticCompactHashTable()
Definition CompactHashTable.h:230
UE_FORCEINLINE_HINT uint32 GetFirst(uint32 Key) const
Definition CompactHashTable.h:242
void Add(uint32 CurrentCount, uint32 Key)
Definition CompactHashTable.h:265
UE_FORCEINLINE_HINT uint32 GetFirstByIndex(uint32 HashIndex) const
Definition CompactHashTable.h:247
TStaticCompactHashTable(ENoInit)
Definition CompactHashTable.h:235
uint32 GetNext(uint32 Index, uint32 CurrentCount) const
Definition CompactHashTable.h:252
IndexType HashData[HashCount]
Definition CompactHashTable.h:278
UE_FORCEINLINE_HINT void Remove(uint32 Index, uint32 Key, uint32 LastIndex, uint32 OptLastKey)
Definition CompactHashTable.h:271
uint32 Find(uint32 Key, uint32 CurrentCount, const PredicateType &Predicate) const
Definition CompactHashTable.h:259
Definition CompactHashTable.h:32
void RemoveInternal(const uint32 Index, const uint32 Key, IndexType *HashData, const uint32 HashCount, IndexType *NextIndexData, const uint32 NextIndexCount)
Definition CompactHashTable.h:35
Definition CompactHashTable.h:32
uint32 GetFirst(uint32 Key, const IndexType *HashData, const uint32 HashCount)
Definition CompactHashTable.h:92
void Add(uint32 Index, uint32 Key, IndexType *HashData, const uint32 HashCount, IndexType *NextIndexData, const uint32 NextIndexCount)
Definition CompactHashTable.h:144
void Remove(const uint32 Index, const uint32 Key, const uint32 LastIndex, uint32 OptLastKey, IndexType *HashData, const uint32 HashCount, IndexType *NextIndexData, const uint32 NextIndexCount)
Definition CompactHashTable.h:157
void RemoveStable(const uint32 Index, const uint32 Key, IndexType *HashData, const uint32 HashCount, IndexType *NextIndexData, const uint32 NextIndexCount)
Definition CompactHashTable.h:178
uint32 GetFirstByIndex(uint32 HashIndex, const IndexType *HashData, const uint32 HashCount)
Definition CompactHashTable.h:104
constexpr size_t GetHashCount(uint32 NumElements)
Definition CompactHashTable.h:75
UE_FORCEINLINE_HINT constexpr uint32 GetTypeShift(uint32 IndexCount)
Definition CompactHashTable.h:59
UE_FORCEINLINE_HINT constexpr size_t GetMemoryRequiredInBytes(uint32 IndexCount, uint32 HashCount)
Definition CompactHashTable.h:64
UE_FORCEINLINE_HINT constexpr size_t GetMemoryAlignment()
Definition CompactHashTable.h:69
UE_FORCEINLINE_HINT constexpr uint32 GetTypeSize(uint32 IndexCount)
Definition CompactHashTable.h:54
uint32 GetNext(uint32 Index, const IndexType *NextIndexData, const uint32 NextIndexCount)
Definition CompactHashTable.h:116
uint32 Find(uint32 Key, const IndexType *HashData, const uint32 HashCount, const IndexType *NextIndexData, const uint32 NextIndexCount, const PredicateType &Predicate)
Definition CompactHashTable.h:128
Definition AdvancedWidgetsModule.cpp:13
U16 Index
Definition radfft.cpp:71
static constexpr UE_FORCEINLINE_HINT bool IsPowerOfTwo(T Value)
Definition UnrealMathUtility.h:519
static UE_FORCEINLINE_HINT void * Memset(void *Dest, uint8 Char, SIZE_T Count)
Definition UnrealMemory.h:119
uint8 Type
Definition CompactHashTable.h:219
uint16 Type
Definition CompactHashTable.h:220
uint32 Type
Definition CompactHashTable.h:221
Definition CompactHashTable.h:218