Navigation
API > API/Runtime > API/Runtime/Core
A set with an optional KeyFuncs parameters for customizing how the elements are compared and searched. E.g. You can specify a mapping from elements to keys if you want to find elements by specifying a subset of the element type. It uses a TSparseArray of the elements, and also links the elements into a hash with a number of buckets proportional to the number of elements. Addition, removal, and finding are O(1).
The ByHash() functions are somewhat dangerous but particularly useful in two scenarios: Heterogeneous lookup to avoid creating expensive keys like FString when looking up by const TCHAR*. You must ensure the hash is calculated in the same way as ElementType is hashed. If possible put both ComparableKey and ElementType hash functions next to each other in the same header to avoid bugs when the ElementType hash function is changed. Reducing contention around hash tables protected by a lock. It is often important to incur the cache misses of reading key data and doing the hashing before acquiring the lock.
| Name | TSet |
| Type | class |
| Header File | /Engine/Source/Runtime/Core/Public/Containers/Set.h |
| Include Path | #include "Containers/Set.h" |
Syntax
template<typename InElementType, typename KeyFuncs, typename Allocator>
class TSet
Derived Classes
Constructors
| Name | Remarks | Include Path | Unreal Specifiers |
|---|---|---|---|
| Constructor for moving elements from a TSet with a different SetAllocator | Containers/Set.h | ||
TSet () |
Initialization constructor. | Containers/Set.h | |
| Copy constructor. | Containers/Set.h | ||
TSet
(
TArrayView< const ElementType > InArrayView |
Containers/Set.h | ||
| Containers/Set.h | |||
TSet
(
FIntrusiveUnsetOptionalState Tag |
Containers/Set.h | ||
TSet
(
std::initializer_list< ElementType > InitList |
Initializer list constructor. | Containers/Set.h | |
| Move constructor. | Containers/Set.h | ||
| Constructor for copying elements from a TSet with a different SetAllocator | Containers/Set.h |
Destructors
| Name | Remarks | Include Path | Unreal Specifiers |
|---|---|---|---|
~TSet() |
Destructor. | Containers/Set.h |
Classes
| Name | Remarks |
|---|---|
| FElementCompareClass | Extracts the element value from the set's element structure and passes it to the user provided comparison class. |
| TBaseIterator | The base type of whole set iterators. |
| TBaseKeyIterator | The base type of whole set iterators. |
| TConstIterator | Used to iterate over the elements of a const TSet. |
| TConstKeyIterator | Used to iterate over the elements of a const TSet. |
| TIterator | Used to iterate over the elements of a TSet. |
| TKeyIterator | Used to iterate over the elements of a TSet. |
Typedefs
| Name | Type | Remarks | Include Path |
|---|---|---|---|
| AllocatorType | Allocator | Containers/Set.h | |
| ElementArrayType | TSparseArray< SetElementType, typename Allocator::SparseArrayAllocator > | Containers/Set.h | |
| ElementInitType | KeyFuncs::ElementInitType | Containers/Set.h | |
| ElementType | InElementType | Containers/Set.h | |
| HashType | typename Allocator::HashAllocator::template ForElementType< FSetElementId > | Containers/Set.h | |
| IntrusiveUnsetOptionalStateType | TSet | Containers/Set.h | |
| KeyFuncsType | KeyFuncs | Containers/Set.h | |
| KeyInitType | KeyFuncs::KeyInitType | Containers/Set.h | |
| SetElementType | TSetElement< InElementType > | Containers/Set.h | |
| SizeType | typename Allocator::SparseArrayAllocator::ElementAllocator::SizeType | Containers/Set.h | |
| TRangedForConstIterator | TBaseIterator< true, true > | Containers/Set.h | |
| TRangedForIterator | TBaseIterator< false, true > | Containers/Set.h | |
| USizeType | std::make_unsigned_t< SizeType > | Containers/Set.h |
Constants
| Name | Type | Remarks | Include Path |
|---|---|---|---|
| bHasIntrusiveUnsetOptionalState | bool | Start - intrusive TOptional |
Containers/Set.h |
Variables
Protected
| Name | Type | Remarks | Include Path | Unreal Specifiers |
|---|---|---|---|---|
| Elements | ElementArrayType | Containers/Set.h | ||
| Hash | HashType | Containers/Set.h | ||
| HashSize | int32 | Containers/Set.h |
Functions
Public
| Name | Remarks | Include Path | Unreal Specifiers |
|---|---|---|---|
FSetElementId Add
(
InElementType&& InElement, |
Containers/Set.h | ||
FSetElementId Add
(
const InElementType& InElement, |
Adds an element to the set. | Containers/Set.h | |
FSetElementId AddByHash
(
uint32 KeyHash, |
Containers/Set.h | ||
FSetElementId AddByHash
(
uint32 KeyHash, |
Adds an element to the set. | Containers/Set.h | |
| Containers/Set.h | |||
| Add all items from another set to our set (union without creating a new set) | Containers/Set.h | ||
| Containers/Set.h | |||
void Append
(
TArrayView< const ElementType > InElements |
Containers/Set.h | ||
void Append
(
TSet< typename TContainerElementTypeCompatibility< ElementType >::CopyFromOtherType, OtherKeyFuncs, ... |
Add all items from another set to our set (union without creating a new set) Compatible element type version. | Containers/Set.h | |
void Append
(
std::initializer_list< ElementType > InitList |
Containers/Set.h | ||
void Append
(
const TSet< typename TContainerElementTypeCompatibility< ElementType >::CopyFromOtherType, OtherKeyF... |
Add all items from another set to our set (union without creating a new set) Compatible element type version. | Containers/Set.h | |
TArray< ElementType > Array() |
Containers/Set.h | ||
TRangedForIterator begin () |
DO NOT USE DIRECTLY STL-like iterators to enable range-based for loop support. | Containers/Set.h | |
TRangedForConstIterator begin () |
Containers/Set.h | ||
void CheckAddress
(
const ElementType* Addr |
Checks that the specified address is not part of an element within the container. | Containers/Set.h | |
void Compact() |
Compacts the allocated elements into a contiguous range. | Containers/Set.h | |
void CompactStable () |
Compacts the allocated elements into a contiguous range. | Containers/Set.h | |
bool Contains
(
KeyInitType Key |
Checks if the element contains an element with the given key. | Containers/Set.h | |
bool ContainsByHash
(
uint32 KeyHash, |
Checks if the element contains an element with the given key. | Containers/Set.h | |
void CopyUnfrozen
(
const FMemoryUnfreezeContent& Context, |
Containers/Set.h | ||
void CountBytes
(
FArchive& Ar |
Tracks the container's memory use through an archive. | Containers/Set.h | |
TConstIterator CreateConstIterator() |
Creates a const iterator for the contents of this set | Containers/Set.h | |
TIterator CreateIterator() |
Creates an iterator for the contents of this set | Containers/Set.h | |
| Containers/Set.h | |||
void Dump
(
FOutputDevice& Ar |
Describes the set's contents through an output device. | Containers/Set.h | |
void DumpHashElements
(
FOutputDevice& Ar |
Containers/Set.h | ||
FSetElementId Emplace
(
ArgsType&& Args, |
Adds an element to the set. | Containers/Set.h | |
FSetElementId EmplaceByHash
(
uint32 KeyHash, |
Adds an element to the set. | Containers/Set.h | |
void Empty
(
int32 ExpectedNumElements |
Removes all elements from the set, potentially leaving space allocated for an expected number of elements about to be added. | Containers/Set.h | |
TRangedForIterator end () |
Containers/Set.h | ||
TRangedForConstIterator end () |
Containers/Set.h | ||
ElementType * Find
(
KeyInitType Key |
Finds an element with the given key in the set. | Containers/Set.h | |
const ElementType * Find
(
KeyInitType Key |
Finds an element with the given key in the set. | Containers/Set.h | |
const ElementType * FindArbitraryElement () |
Containers/Set.h | ||
ElementType * FindArbitraryElement () |
Finds any element in the set and returns a pointer to it. | Containers/Set.h | |
const ElementType * FindByHash
(
uint32 KeyHash, |
Containers/Set.h | ||
ElementType * FindByHash
(
uint32 KeyHash, |
Finds an element with a pre-calculated hash and a key that can be compared to KeyType. | Containers/Set.h | |
FSetElementId FindId
(
KeyInitType Key |
Finds an element with the given key in the set. | Containers/Set.h | |
FSetElementId FindIdByHash
(
uint32 KeyHash, |
Finds an element with a pre-calculated hash and a key that can be compared to KeyType | Containers/Set.h | |
ElementType & FindOrAdd
(
InElementType&& InElement, |
Containers/Set.h | ||
ElementType & FindOrAdd
(
const InElementType& InElement, |
Adds an element to the set if not already present and returns a reference to the added or existing element. | Containers/Set.h | |
ElementType & FindOrAddByHash
(
uint32 KeyHash, |
Adds an element to the set if not already present and returns a reference to the added or existing element. | Containers/Set.h | |
ElementType & Get
(
FSetElementId Id |
Accesses the identified element's value. Element must be valid (see @IsValidId). | Containers/Set.h | |
const ElementType & Get
(
FSetElementId Id |
Accesses the identified element's value. Element must be valid (see @IsValidId). | Containers/Set.h | |
SIZE_T GetAllocatedSize() |
Helper function to return the amount of memory allocated by this container Only returns the size of allocations made directly by the container, not the elements themselves. | Containers/Set.h | |
int32 GetMaxIndex() |
Containers/Set.h | ||
bool Includes
(
const TSet< ElementType, KeyFuncs, Allocator >& OtherSet |
Determine whether the specified set is entirely included within this set | Containers/Set.h | |
| Containers/Set.h | |||
bool IsEmpty () |
Returns true if the sets is empty and contains no elements. | Containers/Set.h | |
bool IsValidId
(
FSetElementId Id |
Checks whether an element id is valid. | Containers/Set.h | |
int32 Num() |
Containers/Set.h | ||
void Relax() |
Relaxes the set's hash to a size strictly bounded by the number of elements in the set. | Containers/Set.h | |
void Remove
(
FSetElementId ElementId |
Removes an element from the set. | Containers/Set.h | |
int32 Remove
(
KeyInitType Key |
Removes all elements from the set matching the specified key. | Containers/Set.h | |
int32 RemoveByHash
(
uint32 KeyHash, |
Removes all elements from the set matching the specified key. | Containers/Set.h | |
void Reserve
(
int32 Number |
Preallocates enough memory to contain Number elements | Containers/Set.h | |
void Reset() |
Efficiently empties out the set but preserves all allocations and capacities | Containers/Set.h | |
void Shrink() |
Shrinks the set's element storage to avoid slack. | Containers/Set.h | |
void Sort
(
const PREDICATE_CLASS& Predicate |
Sorts the set's elements using the provided comparison class. | Containers/Set.h | |
void SortFreeList () |
Sort the free element list so that subsequent additions will occur in the lowest available TSparseArray index resulting in tighter packing without moving any existing items. | Containers/Set.h | |
void StableSort
(
const PREDICATE_CLASS& Predicate |
Stable sorts the set's elements using the provided comparison class. | Containers/Set.h | |
| Containers/Set.h | |||
bool VerifyHashElementsKey
(
KeyInitType Key |
Containers/Set.h | ||
void WriteMemoryImage
(
FMemoryImageWriter& Writer |
Containers/Set.h |
Static
| Name | Remarks | Include Path | Unreal Specifiers |
|---|---|---|---|
static void AppendHash
(
const FPlatformTypeLayoutParameters& LayoutParams, |
Containers/Set.h | ||
static void Move
(
SetType& ToSet, |
Containers/Set.h |
Operators
| Name | Remarks | Include Path | Unreal Specifiers |
|---|---|---|---|
const ElementType & operator[]
(
FSetElementId Id |
Accesses the identified element's value. Element must be valid (see @IsValidId). | Containers/Set.h | |
ElementType & operator[]
(
FSetElementId Id |
Accesses the identified element's value. Element must be valid (see @IsValidId). | Containers/Set.h | |
| End - intrusive TOptional |
Containers/Set.h | ||
| Move assignment operator. | Containers/Set.h | ||
| Assignment operator for copying elements from a TSet with a different SetAllocator | Containers/Set.h | ||
TSet & operator=
(
TSet< typename TContainerElementTypeCompatibility< ElementType >::CopyFromOtherType, OtherKeyFuncs, ... |
Move assignment operator. Compatible element type version. | Containers/Set.h | |
TSet & operator=
(
const TSet< typename TContainerElementTypeCompatibility< ElementType >::CopyFromOtherType, OtherKeyF... |
Assignment operator. | Containers/Set.h | |
| Initializer list assignment operator | Containers/Set.h | ||
| Assignment operator for moving elements from a TSet with a different SetAllocator | Containers/Set.h | ||
bool operator==
(
FIntrusiveUnsetOptionalState Tag |
Containers/Set.h |