TSet

A set with an optional KeyFuncs parameters for customizing how the elements are compared and searched.

Windows
MacOS
Linux

Inheritance Hierarchy

References

Module

Core

Header

/Engine/Source/Runtime/Core/Public/Containers/Set.h

Include

#include "Containers/Set.h"

Syntax

template<typename InElementType, typename KeyFuncs, typename Allocator>
class TSet

Remarks

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.

Constructors

Name Description

Public function

TSet()

Initialization constructor.

Public function

TSet

(
    const TSet& Copy
)

Copy constructor.

Public function

TSet

(
    const TArray< ElementType >& InArr...
)

Public function

TSet

(
    TArray< ElementType >&& InArray
)

Public function

TSet

(
    std::initializer_list< ElementType ...
)

Initializer list constructor.

Public function

TSet

(
    TSet&& Other
)

Move constructor.

Public function

TSet

(
    TSet< ElementType, KeyFuncs, OtherA...
)

Constructor for moving elements from a TSet with a different SetAllocator

Public function

TSet

(
    const TSet< ElementType, KeyFuncs, ...
)

Constructor for copying elements from a TSet with a different SetAllocator

Destructors

Name Description

Public function

~TSet()

Destructor.

Functions

Name Description

Public function

FSetElementI...

 

Add

(
    InElementType&& InElement,
    bool* bIsAlreadyInSetPtr
)

Public function

FSetElementI...

 

Add

(
    const InElementType& InElement,
    bool* bIsAlreadyInSetPtr
)

Adds an element to the set.

Public function

FSetElementI...

 

AddByHash

(
    uint32 KeyHash,
    InElementType&& InElement,
    bool* bIsAlreadyInSetPtr
)

Public function

FSetElementI...

 

AddByHash

(
    uint32 KeyHash,
    const InElementType& InElement,
    bool* bIsAlreadyInSetPtr
)

Adds an element to the set.

Public function

void

 

Append

(
    const TSet< ElementType, KeyFuncs, ...
)

Add all items from another set to our set (union without creating a new set)

Public function

void

 

Append

(
    TArray< ElementType, ArrayAllocator...
)

Public function

void

 

Append

(
    const TArray< ElementType, ArrayAll...
)

Public function

void

 

Append

(
    TSet< ElementType, KeyFuncs, OtherA...
)

Public function

void

 

Append

(
    std::initializer_list< ElementType ...
)

Public function Static

void

 

AppendHash

(
    const FPlatformTypeLayoutParameters...,
    FSHA1& Hasher
)

Public function Const

TArray< Elem...

 

Array()

Public function

TRangedForIt...

 

begin()

DO NOT USE DIRECTLY STL-like iterators to enable range-based for loop support.

Public function Const

TRangedForCo...

 

begin()

Public function Const

void

 

CheckAddress

(
    const ElementType* Addr
)

Checks that the specified address is not part of an element within the container.

Public function

void

 

Compact()

Compacts the allocated elements into a contiguous range.

Public function

void

 

CompactStable()

Compacts the allocated elements into a contiguous range.

Public function Const

bool

 

Contains

(
    KeyInitType Key
)

Checks if the element contains an element with the given key.

Public function Const

bool

 

ContainsByHash

(
    uint32 KeyHash,
    const ComparableKey& Key
)

Checks if the element contains an element with the given key.

Public function Const

void

 

CopyUnfrozen

(
    const FMemoryUnfreezeContent& Cont...,
    void* Dst
)

Public function Const

void

 

CountBytes

(
    FArchive& Ar
)

Tracks the container's memory use through an archive.

Public function Const

TConstIterat...

 

CreateConstIterator()

Creates a const iterator for the contents of this set

Public function

TIterator

 

CreateIterator()

Creates an iterator for the contents of this set

Public function Const

TSet

 

Difference

(
    const TSet& OtherSet
)

Public function

void

 

Dump

(
    FOutputDevice& Ar
)

Describes the set's contents through an output device.

Public function

void

 

DumpHashElements

(
    FOutputDevice& Ar
)

Public function

FSetElementI...

 

Emplace

(
    ArgsType&& Args,
    bool* bIsAlreadyInSetPtr
)

Adds an element to the set.

Public function

FSetElementI...

 

EmplaceByHash

(
    uint32 KeyHash,
    ArgsType&& Args,
    bool* bIsAlreadyInSetPtr
)

Adds an element to the set.

Public function

void

 

Empty

(
    int32 ExpectedNumElements
)

Removes all elements from the set, potentially leaving space allocated for an expected number of elements about to be added.

Public function

TRangedForIt...

 

end()

Public function Const

TRangedForCo...

 

end()

Public function Const

const Elemen...

 

Find

(
    KeyInitType Key
)

Finds an element with the given key in the set.

Public function

ElementType ...

 

Find

(
    KeyInitType Key
)

Finds an element with the given key in the set.

Public function

ElementType ...

 

FindByHash

(
    uint32 KeyHash,
    const ComparableKey& Key
)

Finds an element with a pre-calculated hash and a key that can be compared to KeyType.

Public function Const

const Elemen...

 

FindByHash

(
    uint32 KeyHash,
    const ComparableKey& Key
)

Public function Const

FSetElementI...

 

FindId

(
    KeyInitType Key
)

Finds an element with the given key in the set.

Public function Const

FSetElementI...

 

FindIdByHash

(
    uint32 KeyHash,
    const ComparableKey& Key
)

Finds an element with a pre-calculated hash and a key that can be compared to KeyType

Public function Const

uint32

 

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.

Public function Const

int32

 

GetMaxIndex()

Public function Const

bool

 

Includes

(
    const TSet< ElementType, KeyFuncs, ...
)

Determine whether the specified set is entirely included within this set

Public function Const

TSet

 

Intersect

(
    const TSet& OtherSet
)

Public function Const

bool

 

IsValidId

(
    FSetElementId Id
)

Checks whether an element id is valid.

Public function Const

int32

 

Num()

Public function

void

 

Relax()

Relaxes the set's hash to a size strictly bounded by the number of elements in the set.

Public function

void

 

Remove

(
    FSetElementId ElementId
)

Removes an element from the set.

Public function

int32

 

Remove

(
    KeyInitType Key
)

Removes all elements from the set matching the specified key.

Public function

int32

 

RemoveByHash

(
    uint32 KeyHash,
    const ComparableKey& Key
)

Removes all elements from the set matching the specified key.

Public function

void

 

Reserve

(
    int32 Number
)

Preallocates enough memory to contain Number elements

Public function

void

 

Reset()

Efficiently empties out the set but preserves all allocations and capacities

Public function

void

 

Shrink()

Shrinks the set's element storage to avoid slack.

Public function

void

 

Sort

(
    const PREDICATE_CLASS& Predicate
)

Sorts the set's elements using the provided comparison class.

Public function

void

 

StableSort

(
    const PREDICATE_CLASS& Predicate
)

Stable sorts the set's elements using the provided comparison class.

Public function Const

TSet

 

Union

(
    const TSet& OtherSet
)

Public function

bool

 

VerifyHashElementsKey

(
    KeyInitType Key
)

Public function Const

void

 

WriteMemoryImage

(
    FMemoryImageWriter& Writer
)

Operators

Name Description

Public function Const

const Elemen...

 

operator[]

(
    FSetElementId Id
)

Accesses the identified element's value.

Public function

ElementType ...

 

operator[]

(
    FSetElementId Id
)

Accesses the identified element's value.

Public function

TSet &

 

operator=

(
    TSet&& Other
)

Move assignment operator.

Public function

TSet &

 

operator=

(
    const TSet< ElementType, KeyFuncs, ...
)

Assignment operator for copying elements from a TSet with a different SetAllocator

Public function

TSet &

 

operator=

(
    std::initializer_list< ElementType ...
)

Initializer list assignment operator

Public function

TSet &

 

operator=

(
    const TSet& Copy
)

Assignment operator.

Public function

TSet &

 

operator=

(
    TSet< ElementType, KeyFuncs, OtherA...
)

Assignment operator for moving elements from a TSet with a different SetAllocator

Classes

Name

Description

Public class

TConstIterator

Used to iterate over the elements of a const TSet.

Public class

TConstKeyIterator

Used to iterate over the elements of a const TSet.

Public class

TIterator

Used to iterate over the elements of a TSet.

Public class

TKeyIterator

Used to iterate over the elements of a TSet.

Typedefs

Constants

Name

Description

SupportsFreezeMemoryImage

Help shape the future of Unreal Engine documentation! Tell us how we're doing so we can serve you better.
Take our survey
Dismiss