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

#include <SparseArray.h>

+ Inheritance diagram for TSparseArrayBase< SizeOfElementType, AlignOfElementType, Allocator >:

Protected Types

typedef TSparseArrayElementOrFreeListLink< TAlignedBytes< SizeOfElementType, AlignOfElementType > > FElementOrFreeListLink
 
typedef TArray< FElementOrFreeListLink, typename Allocator::ElementAllocator > DataType
 
typedef TBitArray< typename Allocator::BitArrayAllocator > AllocationBitArrayType
 

Protected Member Functions

 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

DataType Data
 
AllocationBitArrayType AllocationFlags
 
int32 FirstFreeIndex = -1
 
int32 NumFreeIndices = 0
 

Member Typedef Documentation

◆ AllocationBitArrayType

template<size_t SizeOfElementType, size_t AlignOfElementType, typename Allocator >
typedef TBitArray<typename Allocator::BitArrayAllocator> TSparseArrayBase< SizeOfElementType, AlignOfElementType, Allocator >::AllocationBitArrayType
protected

◆ DataType

template<size_t SizeOfElementType, size_t AlignOfElementType, typename Allocator >
typedef TArray<FElementOrFreeListLink, typename Allocator::ElementAllocator> TSparseArrayBase< SizeOfElementType, AlignOfElementType, Allocator >::DataType
protected

◆ FElementOrFreeListLink

The element type stored is only indirectly related to the element type requested, to avoid instantiating TArray redundantly for compatible types.

Constructor & Destructor Documentation

◆ TSparseArrayBase() [1/4]

template<size_t SizeOfElementType, size_t AlignOfElementType, typename Allocator >
TSparseArrayBase< SizeOfElementType, AlignOfElementType, Allocator >::TSparseArrayBase ( FIntrusiveUnsetOptionalState  Tag)
inlineexplicitprotected

◆ TSparseArrayBase() [2/4]

template<size_t SizeOfElementType, size_t AlignOfElementType, typename Allocator >
constexpr TSparseArrayBase< SizeOfElementType, AlignOfElementType, Allocator >::TSparseArrayBase ( )
inlineconstexprprotected

Default constructor.

◆ TSparseArrayBase() [3/4]

template<size_t SizeOfElementType, size_t AlignOfElementType, typename Allocator >
consteval TSparseArrayBase< SizeOfElementType, AlignOfElementType, Allocator >::TSparseArrayBase ( EConstEval  )
inlineexplicitprotected

Explicitly consteval constructor.

◆ TSparseArrayBase() [4/4]

Copy constructor.

Member Function Documentation

◆ AddUninitialized()

template<size_t SizeOfElementType, size_t AlignOfElementType, typename Allocator >
FSparseArrayAllocationInfo TSparseArrayBase< SizeOfElementType, AlignOfElementType, Allocator >::AddUninitialized ( )
inlineprotected

Allocates space for an element in the array. The element is not initialized, and you must use the corresponding placement new operator to construct the element in the allocated memory.

◆ AddUninitializedAtLowestFreeIndex()

template<size_t SizeOfElementType, size_t AlignOfElementType, typename Allocator >
FSparseArrayAllocationInfo TSparseArrayBase< SizeOfElementType, AlignOfElementType, Allocator >::AddUninitializedAtLowestFreeIndex ( int32 LowestFreeIndexSearchStart)
inlineprotected

◆ AllocateIndex()

template<size_t SizeOfElementType, size_t AlignOfElementType, typename Allocator >
FSparseArrayAllocationInfo TSparseArrayBase< SizeOfElementType, AlignOfElementType, Allocator >::AllocateIndex ( int32  Index)
inlineprotected

Marks an index as allocated, and returns information about the allocation.

◆ Compact()

template<size_t SizeOfElementType, size_t AlignOfElementType, typename Allocator >
bool TSparseArrayBase< SizeOfElementType, AlignOfElementType, Allocator >::Compact ( )
inlineprotected

Compacts the allocated elements into a contiguous index range. Returns true if any elements were relocated, false otherwise.

◆ GetMaxIndex()

template<size_t SizeOfElementType, size_t AlignOfElementType, typename Allocator >
int32 TSparseArrayBase< SizeOfElementType, AlignOfElementType, Allocator >::GetMaxIndex ( ) const
inlineprotected

◆ InsertUninitialized()

template<size_t SizeOfElementType, size_t AlignOfElementType, typename Allocator >
FSparseArrayAllocationInfo TSparseArrayBase< SizeOfElementType, AlignOfElementType, Allocator >::InsertUninitialized ( int32  Index)
inlineprotected

Allocates space for an element in the array at a given index. The element is not initialized, and you must use the corresponding placement new operator to construct the element in the allocated memory.

◆ IsAllocated()

template<size_t SizeOfElementType, size_t AlignOfElementType, typename Allocator >
bool TSparseArrayBase< SizeOfElementType, AlignOfElementType, Allocator >::IsAllocated ( int32  Index) const
inlineprotected

◆ IsEmpty()

template<size_t SizeOfElementType, size_t AlignOfElementType, typename Allocator >
bool TSparseArrayBase< SizeOfElementType, AlignOfElementType, Allocator >::IsEmpty ( ) const
inlineprotected

◆ IsValidIndex()

template<size_t SizeOfElementType, size_t AlignOfElementType, typename Allocator >
bool TSparseArrayBase< SizeOfElementType, AlignOfElementType, Allocator >::IsValidIndex ( int32  Index) const
inlineprotected

◆ Max()

template<size_t SizeOfElementType, size_t AlignOfElementType, typename Allocator >
int32 TSparseArrayBase< SizeOfElementType, AlignOfElementType, Allocator >::Max ( ) const
inlineprotected
Returns
The number of elements the array can hold before reallocation.

◆ Num()

template<size_t SizeOfElementType, size_t AlignOfElementType, typename Allocator >
int32 TSparseArrayBase< SizeOfElementType, AlignOfElementType, Allocator >::Num ( ) const
inlineprotected

◆ RemoveAtUninitialized()

template<size_t SizeOfElementType, size_t AlignOfElementType, typename Allocator >
void TSparseArrayBase< SizeOfElementType, AlignOfElementType, Allocator >::RemoveAtUninitialized ( int32  Index,
int32  Count = 1 
)
inlineprotected

Removes Count elements from the array, starting from Index, without destructing them.

◆ Reserve()

template<size_t SizeOfElementType, size_t AlignOfElementType, typename Allocator >
void TSparseArrayBase< SizeOfElementType, AlignOfElementType, Allocator >::Reserve ( int32  ExpectedNumElements)
inlineprotected

Preallocates enough memory to contain the specified number of elements.

Parameters
ExpectedNumElementsthe total number of elements that the array will have

◆ Shrink()

template<size_t SizeOfElementType, size_t AlignOfElementType, typename Allocator >
void TSparseArrayBase< SizeOfElementType, AlignOfElementType, Allocator >::Shrink ( )
inlineprotected

Shrinks the array's storage to avoid slack.

◆ SortFreeList()

template<size_t SizeOfElementType, size_t AlignOfElementType, typename Allocator >
void TSparseArrayBase< SizeOfElementType, AlignOfElementType, Allocator >::SortFreeList ( )
inlineprotected

Sort the free element list so that subsequent allocations will occur in the lowest available position resulting in tighter packing without moving any existing items. This also means that assigned indices no longer depend on the order in which old items were removed, making it easier to use the container when determinism is required (without a container reset).

E.g., call SortFreeList() each frame to make the container assign the same indices when we perform the following operations: Frame1: Add(A) -> [0]; Add(B) -> [1]; Remove(A); Remove(B); (Free list is now {[1],[0],...}) Frame2: Add(A) -> [1]; Add(B) -> [0]; Remove(A); Remove(B); (Free list is now {[0],[1],...})

NOTE: This is operation is currently O(N) with N = GetMaxIndex(). This could be improved for large mostly-full arrays if necessary.

Member Data Documentation

◆ AllocationFlags

template<size_t SizeOfElementType, size_t AlignOfElementType, typename Allocator >
AllocationBitArrayType TSparseArrayBase< SizeOfElementType, AlignOfElementType, Allocator >::AllocationFlags
protected

◆ Data

template<size_t SizeOfElementType, size_t AlignOfElementType, typename Allocator >
DataType TSparseArrayBase< SizeOfElementType, AlignOfElementType, Allocator >::Data
protected

◆ FirstFreeIndex

template<size_t SizeOfElementType, size_t AlignOfElementType, typename Allocator >
int32 TSparseArrayBase< SizeOfElementType, AlignOfElementType, Allocator >::FirstFreeIndex = -1
protected

The index of an unallocated element in the array that currently contains the head of the linked list of free elements.

◆ NumFreeIndices

template<size_t SizeOfElementType, size_t AlignOfElementType, typename Allocator >
int32 TSparseArrayBase< SizeOfElementType, AlignOfElementType, Allocator >::NumFreeIndices = 0
protected

The number of elements in the free list.


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