UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
TSparseArray< InElementType, Allocator > Class Template Reference

#include <SparseArray.h>

+ Inheritance diagram for TSparseArray< InElementType, Allocator >:

Classes

class  TConstIterator
 
class  TConstSubsetIterator
 
class  TIterator
 
class  TRangedForConstIterator
 
class  TRangedForIterator
 

Public Types

using IntrusiveUnsetOptionalStateType = TSparseArray
 

Public Member Functions

 ~TSparseArray ()
 
 TSparseArray (FIntrusiveUnsetOptionalState Tag)
 
bool operator== (FIntrusiveUnsetOptionalState Tag) const
 
int32 Add (const ElementType &Element)
 
int32 Add (ElementType &&Element)
 
template<typename... ArgsType>
int32 Emplace (ArgsType &&... Args)
 
template<typename... ArgsType>
int32 EmplaceAtLowestFreeIndex (int32 &LowestFreeIndexSearchStart, ArgsType &&... Args)
 
template<typename... ArgsType>
int32 EmplaceAt (int32 Index, ArgsType &&... Args)
 
void Insert (int32 Index, typename TTypeTraits< ElementType >::ConstInitType Element)
 
void RemoveAt (int32 Index, int32 Count=1)
 
void Empty (int32 ExpectedNumElements=0)
 
void Reset ()
 
bool CompactStable ()
 
template<typename PREDICATE_CLASS >
void Sort (const PREDICATE_CLASS &Predicate)
 
void Sort ()
 
template<typename PREDICATE_CLASS >
void StableSort (const PREDICATE_CLASS &Predicate)
 
void StableSort ()
 
template<typename Predicate >
int32 IndexOfByPredicate (Predicate Pred) const
 
int32 FindArbitraryElementIndex () const
 
SIZE_T GetAllocatedSize (void) const
 
void CountBytes (FArchive &Ar) const
 
bool IsCompact () const
 
bool operator== (const TSparseArray &B) const
 
bool operator!= (const TSparseArray &B) const
 
constexpr TSparseArray ()=default
 
consteval TSparseArray (EConstEval)
 
 TSparseArray (TSparseArray &&InCopy)
 
 TSparseArray (const TSparseArray &InCopy)
 
 TSparseArray (std::initializer_list< ElementType > InList)
 
TSparseArrayoperator= (TSparseArray &&InCopy)
 
TSparseArrayoperator= (const TSparseArray &InCopy)
 
TSparseArrayoperator= (std::initializer_list< ElementType > InList)
 
ElementType & operator[] (int32 Index)
 
const ElementType & operator[] (int32 Index) const
 
int32 PointerToIndex (const ElementType *Ptr) const
 
UE_FORCEINLINE_HINT void CheckAddress (const ElementType *Addr) const
 
TIterator CreateIterator ()
 
TConstIterator CreateConstIterator () const
 
UE_FORCEINLINE_HINT TRangedForIterator begin ()
 
UE_FORCEINLINE_HINT TRangedForConstIterator begin () const
 
UE_FORCEINLINE_HINT TRangedForIterator end ()
 
UE_FORCEINLINE_HINT TRangedForConstIterator end () const
 
TSparseArrayoperator+= (const TSparseArray &OtherArray)
 
TSparseArrayoperator+= (const TArray< ElementType > &OtherArray)
 
void WriteMemoryImage (FMemoryImageWriter &Writer) const
 
void CopyUnfrozen (const FMemoryUnfreezeContent &Context, void *Dst) const
 

Static Public Member Functions

static void AppendHash (const FPlatformTypeLayoutParameters &LayoutParams, FSHA1 &Hasher)
 

Static Public Attributes

static constexpr bool bHasIntrusiveUnsetOptionalState = true
 

Friends

template<typename , typename >
class TScriptSparseArray
 

Additional Inherited Members

- Protected Types inherited from TSparseArrayBase< sizeof(InElementType), alignof(InElementType), Allocator >
typedef TSparseArrayElementOrFreeListLink< TAlignedBytes< SizeOfElementType, AlignOfElementType > > FElementOrFreeListLink
 
typedef TArray< FElementOrFreeListLink, typename Allocator::ElementAllocator > DataType
 
typedef TBitArray< typename Allocator::BitArrayAllocator > AllocationBitArrayType
 
- Protected Member Functions inherited from TSparseArrayBase< sizeof(InElementType), alignof(InElementType), Allocator >
 TSparseArrayBase (FIntrusiveUnsetOptionalState Tag)
 
constexpr TSparseArrayBase ()
 
consteval TSparseArrayBase (EConstEval)
 
 TSparseArrayBase (const TSparseArrayBase &InCopy)
 
FSparseArrayAllocationInfo AllocateIndex (int32 Index)
 
FSparseArrayAllocationInfo AddUninitialized ()
 
FSparseArrayAllocationInfo AddUninitializedAtLowestFreeIndex (int32 &LowestFreeIndexSearchStart)
 
void RemoveAtUninitialized (int32 Index, int32 Count=1)
 
void Reserve (int32 ExpectedNumElements)
 
void Shrink ()
 
void SortFreeList ()
 
FSparseArrayAllocationInfo InsertUninitialized (int32 Index)
 
bool Compact ()
 
int32 GetMaxIndex () const
 
bool IsEmpty () const
 
int32 Num () const
 
int32 Max () const
 
bool IsValidIndex (int32 Index) const
 
bool IsAllocated (int32 Index) const
 
- Protected Attributes inherited from TSparseArrayBase< sizeof(InElementType), alignof(InElementType), Allocator >
DataType Data
 
AllocationBitArrayType AllocationFlags
 
int32 FirstFreeIndex
 
int32 NumFreeIndices
 

Detailed Description

template<typename InElementType, typename Allocator>
class TSparseArray< InElementType, Allocator >

A dynamically sized array where element indices aren't necessarily contiguous. Memory is allocated for all elements in the array's index range, so it doesn't save memory; but it does allow O(1) element removal that doesn't invalidate the indices of subsequent elements. It uses TArray to store the elements, and a TBitArray to store whether each element index is allocated (for fast iteration over allocated elements).

Member Typedef Documentation

◆ IntrusiveUnsetOptionalStateType

using TSparseArray< InElementType, Allocator >::IntrusiveUnsetOptionalStateType = TSparseArray

Constructor & Destructor Documentation

◆ ~TSparseArray()

◆ TSparseArray() [1/6]

◆ TSparseArray() [2/6]

Default constructor.

◆ TSparseArray() [3/6]

◆ TSparseArray() [4/6]

◆ TSparseArray() [5/6]

◆ TSparseArray() [6/6]

TSparseArray< InElementType, Allocator >::TSparseArray ( std::initializer_list< ElementType >  InList)
inline

Initializer list constructor.

Member Function Documentation

◆ Add() [1/2]

int32 TSparseArray< InElementType, Allocator >::Add ( const ElementType &  Element)
inline

Adds an element to the array.

◆ Add() [2/2]

int32 TSparseArray< InElementType, Allocator >::Add ( ElementType &&  Element)
inline

Adds an element to the array.

◆ AppendHash()

static void TSparseArray< InElementType, Allocator >::AppendHash ( const FPlatformTypeLayoutParameters LayoutParams,
FSHA1 Hasher 
)
inlinestatic

◆ begin() [1/2]

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

◆ begin() [2/2]

◆ CheckAddress()

UE_FORCEINLINE_HINT void TSparseArray< InElementType, 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.

Parameters
AddrThe address to check.

◆ CompactStable()

bool TSparseArray< InElementType, Allocator >::CompactStable ( )
inline

Compacts the allocated elements into a contiguous index range. Does not change the iteration order of the elements. Returns true if any elements were relocated, false otherwise.

◆ CopyUnfrozen()

void TSparseArray< InElementType, Allocator >::CopyUnfrozen ( const FMemoryUnfreezeContent Context,
void Dst 
) const
inline

◆ CountBytes()

void TSparseArray< InElementType, Allocator >::CountBytes ( FArchive Ar) const
inline

Tracks the container's memory use through an archive.

◆ CreateConstIterator()

TConstIterator TSparseArray< InElementType, Allocator >::CreateConstIterator ( ) const
inline

Creates a const iterator for the contents of this array

◆ CreateIterator()

Creates an iterator for the contents of this array

◆ Emplace()

template<typename... ArgsType>
int32 TSparseArray< InElementType, Allocator >::Emplace ( ArgsType &&...  Args)
inline

Constructs a new item at the last freed index of the array.

Parameters
ArgsThe arguments to forward to the constructor of the new item.
Returns
Index to the new item

◆ EmplaceAt()

template<typename... ArgsType>
int32 TSparseArray< InElementType, Allocator >::EmplaceAt ( int32  Index,
ArgsType &&...  Args 
)
inline

Constructs a new item at a given index of the array.

Parameters
IndexIndex at which the new allocation will be done
ArgsThe arguments to forward to the constructor of the new item.
Returns
Index to the new item

◆ EmplaceAtLowestFreeIndex()

template<typename... ArgsType>
int32 TSparseArray< InElementType, Allocator >::EmplaceAtLowestFreeIndex ( int32 LowestFreeIndexSearchStart,
ArgsType &&...  Args 
)
inline

Constructs a new item at the lowest free index of the array. This requires a search which can be accelerated with LowestFreeIndexSearchStart.

Parameters
LowestFreeIndexSearchStartWhere to start the search for a free index.
ArgsThe arguments to forward to the constructor of the new item.
Returns
Index to the new item

◆ Empty()

void TSparseArray< InElementType, Allocator >::Empty ( int32  ExpectedNumElements = 0)
inline

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

Parameters
ExpectedNumElements- The expected number of elements about to be added.

◆ end() [1/2]

◆ end() [2/2]

◆ FindArbitraryElementIndex()

int32 TSparseArray< InElementType, Allocator >::FindArbitraryElementIndex ( ) const
inline

Finds the index of an arbitrary element. Callers should not depend on particular patterns in the behaviour of this function.

Returns
The index of any element in the container, or INDEX_NONE if it is empty.

◆ GetAllocatedSize()

SIZE_T TSparseArray< InElementType, 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.

Returns
number of bytes allocated by this container

◆ IndexOfByPredicate()

template<typename Predicate >
int32 TSparseArray< InElementType, Allocator >::IndexOfByPredicate ( Predicate  Pred) const
inline

Finds an item by predicate.

Parameters
PredThe predicate to match.
Returns
Index to the first matching element, or INDEX_NONE if none is found.

◆ Insert()

void TSparseArray< InElementType, Allocator >::Insert ( int32  Index,
typename TTypeTraits< ElementType >::ConstInitType  Element 
)
inline

Inserts an element to the array.

◆ IsCompact()

bool TSparseArray< InElementType, Allocator >::IsCompact ( ) const
inline

◆ operator!=()

Inequality comparison operator. Checks that both arrays have the same elements and element indices; that means that unallocated elements are signifigant!

◆ operator+=() [1/2]

TSparseArray & TSparseArray< InElementType, Allocator >::operator+= ( const TArray< ElementType > &  OtherArray)
inline

◆ operator+=() [2/2]

Concatenation operators

◆ operator=() [1/3]

Copy assignment operator.

◆ operator=() [2/3]

TSparseArray & TSparseArray< InElementType, Allocator >::operator= ( std::initializer_list< ElementType >  InList)
inline

Initializer list assignment operator.

◆ operator=() [3/3]

Move assignment operator.

◆ operator==() [1/2]

Equality comparison operator. Checks that both arrays have the same elements and element indices; that means that unallocated elements are signifigant!

◆ operator==() [2/2]

◆ operator[]() [1/2]

ElementType & TSparseArray< InElementType, Allocator >::operator[] ( int32  Index)
inline

◆ operator[]() [2/2]

const ElementType & TSparseArray< InElementType, Allocator >::operator[] ( int32  Index) const
inline

◆ PointerToIndex()

int32 TSparseArray< InElementType, Allocator >::PointerToIndex ( const ElementType *  Ptr) const
inline

◆ RemoveAt()

void TSparseArray< InElementType, Allocator >::RemoveAt ( int32  Index,
int32  Count = 1 
)
inline

Removes Count elements from the array, starting from Index.

◆ Reset()

Empties the array, but keep its allocated memory as slack.

◆ Sort() [1/2]

Sorts the elements assuming < operator is defined for ElementType.

◆ Sort() [2/2]

void TSparseArray< InElementType, Allocator >::Sort ( const PREDICATE_CLASS Predicate)
inline

Sorts the elements using the provided comparison class.

◆ StableSort() [1/2]

Stable sorts the elements assuming < operator is defined for ElementType.

◆ StableSort() [2/2]

void TSparseArray< InElementType, Allocator >::StableSort ( const PREDICATE_CLASS Predicate)
inline

Stable sorts the elements using the provided comparison class.

◆ WriteMemoryImage()

void TSparseArray< InElementType, Allocator >::WriteMemoryImage ( FMemoryImageWriter Writer) const
inline

Friends And Related Symbol Documentation

◆ TScriptSparseArray

Member Data Documentation

◆ bHasIntrusiveUnsetOptionalState

constexpr bool TSparseArray< InElementType, Allocator >::bHasIntrusiveUnsetOptionalState = true
staticconstexpr

The documentation for this class was generated from the following file: