UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
UniqueIndexSet.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "Containers/Array.h"
6#include "CoreMinimal.h"
7#include "HAL/Platform.h"
8#include "HAL/PlatformCrt.h"
9#include "HAL/UnrealMemory.h"
11
12namespace UE
13{
14namespace Geometry
15{
16
26{
27 // TODO: second bit set that tracks which blocks of ints have been set.
28 // This would allow for clears to be much quicker for subsets.
29 // (would want to profile to see that it helps, but the bit set is still 0.125mb per million indices,
30 // which isn't a trivial amount to set to zero...)
31
32 // TODO: alternately, use a TSet instead of Bits array if we know that the number
33 // of values we are going to add is very small? This would avoid clears.
34
35 // TODO: AtomicAdd()
36
37 // TODO: support growing bit set
38
39public:
41
47 {
48 this->MaxIndex = MaxIndexIn;
49 int32 NeedWords = (MaxIndex / 64) + 1;
50 if (NumWords < NeedWords)
51 {
52 if (Bits != nullptr)
53 {
54 delete[] Bits;
55 }
57 Bits = new int64[NumWords];
58 }
59 FMemory::Memset(&Bits[0], (uint8)0, NeedWords * 8);
60 Values.Reset();
62 }
63
65 inline const int32 Num() const { return Values.Num(); }
66
68 inline const TArray<int32>& Indices() const { return Values; }
69
73 inline bool Add(int32 Index)
74 {
75 int64& Word = Bits[(int64)(Index / 64)];
76 int64 Offset = (int64)(Index % 64);
77 int64 Mask = (int64)1 << Offset;
78 if ( (Word & Mask) == 0 )
79 {
80 Word |= Mask;
82 return true;
83 }
84 return false;
85 }
86
90 inline bool Contains(int32 Index) const
91 {
92 const int64& Word = Bits[(int64)(Index / 64)];
93 int64 Offset = (int64)(Index % 64);
94 int64 Mask = (int64)1 << Offset;
95 return (Word & Mask) != 0;
96 }
97
101 template<typename ArrayType>
102 void Collect(ArrayType& Storage) const
103 {
104 Storage.Reserve(Values.Num());
105 for (int32 Value : Values)
106 {
107 Storage.Add(Value);
108 }
109 }
110
115 {
116 return MoveTemp(Values);
117 }
118
128
129
130public:
131 // range-for support. Do not directly call these functions.
134
135
136protected:
139 int64* Bits = nullptr;
141};
142
143
144} // end namespace UE::Geometry
145} // end namespace UE
FPlatformTypes::int64 int64
A 64-bit signed integer.
Definition Platform.h:1127
FPlatformTypes::int32 int32
A 32-bit signed integer.
Definition Platform.h:1125
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
UE_INTRINSIC_CAST UE_REWRITE constexpr std::remove_reference_t< T > && MoveTemp(T &&Obj) noexcept
Definition UnrealTemplate.h:520
uint32 Offset
Definition VulkanMemory.cpp:4033
uint8_t uint8
Definition binka_ue_file_header.h:8
Definition Array.h:670
UE_REWRITE SizeType Num() const
Definition Array.h:1144
void Reset(SizeType NewSize=0)
Definition Array.h:2246
UE_NODEBUG UE_FORCEINLINE_HINT RangedForIteratorType end()
Definition Array.h:3391
UE_NODEBUG UE_FORCEINLINE_HINT SizeType Add(ElementType &&Item)
Definition Array.h:2696
UE_NODEBUG UE_FORCEINLINE_HINT RangedForIteratorType begin()
Definition Array.h:3389
UE_FORCEINLINE_HINT void Reserve(SizeType Number)
Definition Array.h:3016
Definition UniqueIndexSet.h:26
int32 NumWords
Definition UniqueIndexSet.h:140
TArray< int32 >::RangedForConstIteratorType begin() const
Definition UniqueIndexSet.h:132
const int32 Num() const
Definition UniqueIndexSet.h:65
void SwapValuesWith(TArray< int32 > &OtherArray)
Definition UniqueIndexSet.h:122
const TArray< int32 > & Indices() const
Definition UniqueIndexSet.h:68
void Collect(ArrayType &Storage) const
Definition UniqueIndexSet.h:102
TArray< int32 > && TakeValues()
Definition UniqueIndexSet.h:114
void Initialize(int32 MaxIndexIn, int32 MaxValuesHint=0)
Definition UniqueIndexSet.h:46
TArray< int32 > Values
Definition UniqueIndexSet.h:138
int64 * Bits
Definition UniqueIndexSet.h:139
int32 MaxIndex
Definition UniqueIndexSet.h:137
TArray< int32 >::RangedForConstIteratorType end() const
Definition UniqueIndexSet.h:133
bool Add(int32 Index)
Definition UniqueIndexSet.h:73
bool Contains(int32 Index) const
Definition UniqueIndexSet.h:90
GEOMETRYCORE_API ~FUniqueIndexSet()
Definition UniqueIndexSet.cpp:7
Definition AdvancedWidgetsModule.cpp:13
U16 Index
Definition radfft.cpp:71
static UE_FORCEINLINE_HINT void * Memset(void *Dest, uint8 Char, SIZE_T Count)
Definition UnrealMemory.h:119
Definition Array.h:206