engine
 
载入中...
搜索中...
未找到
类 | Public 成员函数 | 友元 | 所有成员列表
TSet< InElementType, KeyFuncs, Allocator > 模板类 参考

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

#include <Set.h>

类

class  TConstIterator
 Used to iterate over the elements of a const TSet. 更多...
 
class  TConstKeyIterator
 Used to iterate over the elements of a const TSet. 更多...
 
class  TIterator
 Used to iterate over the elements of a TSet. 更多...
 
class  TKeyIterator
 Used to iterate over the elements of a TSet. 更多...
 

Public 成员函数

FORCEINLINE FSetElementId Add (const InElementType &InElement, bool *bIsAlreadyInSetPtr=nullptr)
 Adds an element to the set. 更多...
 
FORCEINLINE FSetElementId AddByHash (uint32 KeyHash, const InElementType &InElement, bool *bIsAlreadyInSetPtr=nullptr)
 Adds an element to the set. 更多...
 
template<typename OtherAllocator >
void Append (const TSet< ElementType, KeyFuncs, OtherAllocator > &OtherSet)
 Add all items from another set to our set (union without creating a new set) 更多...
 
TArray< ElementType > Array () const
 
FORCEINLINE TRangedForIterator begin ()
 DO NOT USE DIRECTLY STL-like iterators to enable range-based for loop support.
 
FORCEINLINE void CheckAddress (const ElementType *Addr) const
 Checks that the specified address is not part of an element within the container. 更多...
 
FORCEINLINE void Compact ()
 Compacts the allocated elements into a contiguous range.
 
FORCEINLINE void CompactStable ()
 Compacts the allocated elements into a contiguous range. 更多...
 
FORCEINLINE bool Contains (KeyInitType Key) const
 Checks if the element contains an element with the given key. 更多...
 
template<typename ComparableKey >
FORCEINLINE bool ContainsByHash (uint32 KeyHash, const ComparableKey &Key) const
 Checks if the element contains an element with the given key. 更多...
 
FORCEINLINE void CountBytes (FArchive &Ar) const
 Tracks the container's memory use through an archive.
 
FORCEINLINE TConstIterator CreateConstIterator () const
 Creates a const iterator for the contents of this set
 
FORCEINLINE TIterator CreateIterator ()
 Creates an iterator for the contents of this set
 
TSet Difference (const TSet &OtherSet) const
 
void Dump (FOutputDevice &Ar)
 Describes the set's contents through an output device. 更多...
 
template<typename ArgsType >
FSetElementId Emplace (ArgsType &&Args, bool *bIsAlreadyInSetPtr=nullptr)
 Adds an element to the set. 更多...
 
template<typename ArgsType >
FSetElementId EmplaceByHash (uint32 KeyHash, ArgsType &&Args, bool *bIsAlreadyInSetPtr=nullptr)
 Adds an element to the set. 更多...
 
void Empty (int32 ExpectedNumElements=0)
 Removes all elements from the set, potentially leaving space allocated for an expected number of elements about to be added. 更多...
 
FORCEINLINE ElementType * Find (KeyInitType Key)
 Finds an element with the given key in the set. 更多...
 
FORCEINLINE const ElementType * Find (KeyInitType Key) const
 Finds an element with the given key in the set. 更多...
 
template<typename ComparableKey >
ElementType * FindByHash (uint32 KeyHash, const ComparableKey &Key)
 Finds an element with a pre-calculated hash and a key that can be compared to KeyType. 更多...
 
FSetElementId FindId (KeyInitType Key) const
 Finds an element with the given key in the set. 更多...
 
template<typename ComparableKey >
FSetElementId FindIdByHash (uint32 KeyHash, const ComparableKey &Key) const
 Finds an element with a pre-calculated hash and a key that can be compared to KeyType 更多...
 
FORCEINLINE uint32 GetAllocatedSize (void) const
 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. 更多...
 
bool Includes (const TSet< ElementType, KeyFuncs, Allocator > &OtherSet) const
 Determine whether the specified set is entirely included within this set 更多...
 
TSet Intersect (const TSet &OtherSet) const
 
FORCEINLINE bool IsValidId (FSetElementId Id) const
 Checks whether an element id is valid. 更多...
 
FORCEINLINE int32 Num () const
 
TSet & operator= (const TSet &Copy)
 Assignment operator.
 
template<typename OtherAllocator >
TSet & operator= (const TSet< ElementType, KeyFuncs, OtherAllocator > &Other)
 Assignment operator for copying elements from a TSet with a different SetAllocator
 
TSet & operator= (std::initializer_list< ElementType > InitList)
 Initializer list assignment operator
 
TSet & operator= (TSet &&Other)
 Move assignment operator.
 
template<typename OtherAllocator >
TSet & operator= (TSet< ElementType, KeyFuncs, OtherAllocator > &&Other)
 Assignment operator for moving elements from a TSet with a different SetAllocator
 
FORCEINLINE ElementType & operator[] (FSetElementId Id)
 Accesses the identified element's value.
 
FORCEINLINE const ElementType & operator[] (FSetElementId Id) const
 Accesses the identified element's value.
 
FORCEINLINE void Relax ()
 Relaxes the set's hash to a size strictly bounded by the number of elements in the set.
 
void Remove (FSetElementId ElementId)
 Removes an element from the set. 更多...
 
int32 Remove (KeyInitType Key)
 Removes all elements from the set matching the specified key. 更多...
 
template<typename ComparableKey >
int32 RemoveByHash (uint32 KeyHash, const ComparableKey &Key)
 Removes all elements from the set matching the specified key. 更多...
 
FORCEINLINE void Reserve (int32 Number)
 Preallocates enough memory to contain Number elements
 
void Reset ()
 Efficiently empties out the set but preserves all allocations and capacities
 
FORCEINLINE void Shrink ()
 Shrinks the set's element storage to avoid slack.
 
template<typename PREDICATE_CLASS >
void Sort (const PREDICATE_CLASS &Predicate)
 Sorts the set's elements using the provided comparison class.
 
template<typename PREDICATE_CLASS >
void StableSort (const PREDICATE_CLASS &Predicate)
 Stable sorts the set's elements using the provided comparison class.
 
FORCEINLINE TSet ()
 Initialization constructor.
 
FORCEINLINE TSet (const TSet &Copy)
 Copy constructor.
 
template<typename OtherAllocator >
 TSet (const TSet< ElementType, KeyFuncs, OtherAllocator > &Other)
 Constructor for copying elements from a TSet with a different SetAllocator
 
 TSet (std::initializer_list< ElementType > InitList)
 Initializer list constructor.
 
 TSet (TSet &&Other)
 Move constructor.
 
template<typename OtherAllocator >
 TSet (TSet< ElementType, KeyFuncs, OtherAllocator > &&Other)
 Constructor for moving elements from a TSet with a different SetAllocator
 
TSet Union (const TSet &OtherSet) const
 
FORCEINLINE ~TSet ()
 Destructor.
 

友元

FArchive & operator<< (FArchive &Ar, TSet &Set)
 Serializer.
 
void operator<< (FStructuredArchive::FSlot Slot, TSet &Set)
 Structured archive serializer.
 

详细描述

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

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.

成员函数说明

◆ Add()

template<typename InElementType , typename KeyFuncs , typename Allocator >
FORCEINLINE FSetElementId TSet< InElementType, KeyFuncs, Allocator >::Add ( const InElementType &  InElement,
bool *  bIsAlreadyInSetPtr = nullptr 
)
inline

Adds an element to the set.

参数
InElementElement to add to set
bIsAlreadyInSetPtr[out] Optional pointer to bool that will be set depending on whether element is already in set
返回
A pointer to the element stored in the set.

◆ AddByHash()

template<typename InElementType , typename KeyFuncs , typename Allocator >
FORCEINLINE FSetElementId TSet< InElementType, KeyFuncs, Allocator >::AddByHash ( uint32  KeyHash,
const InElementType &  InElement,
bool *  bIsAlreadyInSetPtr = nullptr 
)
inline

Adds an element to the set.

参见
Class documentation section on ByHash() functions
参数
InElementElement to add to set
bIsAlreadyInSetPtr[out] Optional pointer to bool that will be set depending on whether element is already in set
返回
A handle to the element stored in the set

◆ Append()

template<typename InElementType , typename KeyFuncs , typename Allocator >
template<typename OtherAllocator >
void TSet< InElementType, KeyFuncs, Allocator >::Append ( const TSet< ElementType, KeyFuncs, OtherAllocator > &  OtherSet)
inline

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

参数
OtherSet- The other set of items to add.

◆ Array()

template<typename InElementType , typename KeyFuncs , typename Allocator >
TArray< ElementType > TSet< InElementType, KeyFuncs, Allocator >::Array ( ) const
inline
返回
a TArray of the elements

◆ CheckAddress()

template<typename InElementType , typename KeyFuncs , typename Allocator >
FORCEINLINE void TSet< InElementType, KeyFuncs, Allocator >::CheckAddress ( const ElementType *  Addr) const
inline

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

Used for implementations to check that reference arguments aren't going to be invalidated by possible reallocation.

参数
AddrThe address to check.

◆ CompactStable()

template<typename InElementType , typename KeyFuncs , typename Allocator >
FORCEINLINE void TSet< InElementType, KeyFuncs, Allocator >::CompactStable ( )
inline

Compacts the allocated elements into a contiguous range.

Does not change the iteration order of the elements.

◆ Contains()

template<typename InElementType , typename KeyFuncs , typename Allocator >
FORCEINLINE bool TSet< InElementType, KeyFuncs, Allocator >::Contains ( KeyInitType  Key) const
inline

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

参数
Key- The key to check for.
返回
true if the set contains an element with the given key.

◆ ContainsByHash()

template<typename InElementType , typename KeyFuncs , typename Allocator >
template<typename ComparableKey >
FORCEINLINE bool TSet< InElementType, KeyFuncs, Allocator >::ContainsByHash ( uint32  KeyHash,
const ComparableKey &  Key 
) const
inline

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

参见
Class documentation section on ByHash() functions

◆ Difference()

template<typename InElementType , typename KeyFuncs , typename Allocator >
TSet TSet< InElementType, KeyFuncs, Allocator >::Difference ( const TSet< InElementType, KeyFuncs, Allocator > &  OtherSet) const
inline
返回
the complement of two sets. (A not in B where A is this and B is Other)

◆ Dump()

template<typename InElementType , typename KeyFuncs , typename Allocator >
void TSet< InElementType, KeyFuncs, Allocator >::Dump ( FOutputDevice &  Ar)
inline

Describes the set's contents through an output device.

参数
Ar- The output device to describe the set's contents through.

◆ Emplace()

template<typename InElementType , typename KeyFuncs , typename Allocator >
template<typename ArgsType >
FSetElementId TSet< InElementType, KeyFuncs, Allocator >::Emplace ( ArgsType &&  Args,
bool *  bIsAlreadyInSetPtr = nullptr 
)
inline

Adds an element to the set.

参数
ArgsThe argument(s) to be forwarded to the set element's constructor.
bIsAlreadyInSetPtr[out] Optional pointer to bool that will be set depending on whether element is already in set
返回
A handle to the element stored in the set.

◆ EmplaceByHash()

template<typename InElementType , typename KeyFuncs , typename Allocator >
template<typename ArgsType >
FSetElementId TSet< InElementType, KeyFuncs, Allocator >::EmplaceByHash ( uint32  KeyHash,
ArgsType &&  Args,
bool *  bIsAlreadyInSetPtr = nullptr 
)
inline

Adds an element to the set.

参见
Class documentation section on ByHash() functions
参数
ArgsThe argument(s) to be forwarded to the set element's constructor.
bIsAlreadyInSetPtr[out] Optional pointer to bool that will be set depending on whether element is already in set
返回
A handle to the element stored in the set.

◆ Empty()

template<typename InElementType , typename KeyFuncs , typename Allocator >
void TSet< InElementType, KeyFuncs, Allocator >::Empty ( int32  ExpectedNumElements = 0)
inline

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

参数
ExpectedNumElements- The number of elements about to be added to the set.

◆ Find() [1/2]

template<typename InElementType , typename KeyFuncs , typename Allocator >
FORCEINLINE ElementType * TSet< InElementType, KeyFuncs, Allocator >::Find ( KeyInitType  Key)
inline

Finds an element with the given key in the set.

参数
Key- The key to search for.
返回
A pointer to an element with the given key. If no element in the set has the given key, this will return NULL.

◆ Find() [2/2]

template<typename InElementType , typename KeyFuncs , typename Allocator >
FORCEINLINE const ElementType * TSet< InElementType, KeyFuncs, Allocator >::Find ( KeyInitType  Key) const
inline

Finds an element with the given key in the set.

参数
Key- The key to search for.
返回
A const pointer to an element with the given key. If no element in the set has the given key, this will return NULL.

◆ FindByHash()

template<typename InElementType , typename KeyFuncs , typename Allocator >
template<typename ComparableKey >
ElementType * TSet< InElementType, KeyFuncs, Allocator >::FindByHash ( uint32  KeyHash,
const ComparableKey &  Key 
)
inline

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

参见
Class documentation section on ByHash() functions
返回
A pointer to the contained element or nullptr.

◆ FindId()

template<typename InElementType , typename KeyFuncs , typename Allocator >
FSetElementId TSet< InElementType, KeyFuncs, Allocator >::FindId ( KeyInitType  Key) const
inline

Finds an element with the given key in the set.

参数
Key- The key to search for.
返回
The id of the set element matching the given key, or the NULL id if none matches.

◆ FindIdByHash()

template<typename InElementType , typename KeyFuncs , typename Allocator >
template<typename ComparableKey >
FSetElementId TSet< InElementType, KeyFuncs, Allocator >::FindIdByHash ( uint32  KeyHash,
const ComparableKey &  Key 
) const
inline

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

参见
Class documentation section on ByHash() functions
返回
The element id that matches the key and hash or an invalid element id

◆ GetAllocatedSize()

template<typename InElementType , typename KeyFuncs , typename Allocator >
FORCEINLINE uint32 TSet< InElementType, KeyFuncs, Allocator >::GetAllocatedSize ( void  ) const
inline

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.

返回
number of bytes allocated by this container

◆ Includes()

template<typename InElementType , typename KeyFuncs , typename Allocator >
bool TSet< InElementType, KeyFuncs, Allocator >::Includes ( const TSet< ElementType, KeyFuncs, Allocator > &  OtherSet) const
inline

Determine whether the specified set is entirely included within this set

参数
OtherSetSet to check
返回
True if the other set is entirely included in this set, false if it is not

◆ Intersect()

template<typename InElementType , typename KeyFuncs , typename Allocator >
TSet TSet< InElementType, KeyFuncs, Allocator >::Intersect ( const TSet< InElementType, KeyFuncs, Allocator > &  OtherSet) const
inline
返回
the intersection of two sets. (A AND B)

◆ IsValidId()

template<typename InElementType , typename KeyFuncs , typename Allocator >
FORCEINLINE bool TSet< InElementType, KeyFuncs, Allocator >::IsValidId ( FSetElementId  Id) const
inline

Checks whether an element id is valid.

参数
Id- The element id to check.
返回
true if the element identifier refers to a valid element in this set.

◆ Num()

template<typename InElementType , typename KeyFuncs , typename Allocator >
FORCEINLINE int32 TSet< InElementType, KeyFuncs, Allocator >::Num ( ) const
inline
返回
the number of elements.

◆ Remove() [1/2]

template<typename InElementType , typename KeyFuncs , typename Allocator >
void TSet< InElementType, KeyFuncs, Allocator >::Remove ( FSetElementId  ElementId)
inline

Removes an element from the set.

参数
Element- A pointer to the element in the set, as returned by Add or Find.

◆ Remove() [2/2]

template<typename InElementType , typename KeyFuncs , typename Allocator >
int32 TSet< InElementType, KeyFuncs, Allocator >::Remove ( KeyInitType  Key)
inline

Removes all elements from the set matching the specified key.

参数
Key- The key to match elements against.
返回
The number of elements removed.

◆ RemoveByHash()

template<typename InElementType , typename KeyFuncs , typename Allocator >
template<typename ComparableKey >
int32 TSet< InElementType, KeyFuncs, Allocator >::RemoveByHash ( uint32  KeyHash,
const ComparableKey &  Key 
)
inline

Removes all elements from the set matching the specified key.

参见
Class documentation section on ByHash() functions
参数
Key- The key to match elements against.
返回
The number of elements removed.

◆ Union()

template<typename InElementType , typename KeyFuncs , typename Allocator >
TSet TSet< InElementType, KeyFuncs, Allocator >::Union ( const TSet< InElementType, KeyFuncs, Allocator > &  OtherSet) const
inline
返回
the union of two sets. (A OR B)

该类的文档由以下文件生成: