Navigation
API > API/Runtime > API/Runtime/Core
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).
| Name | TSparseArray |
| Type | class |
| Header File | /Engine/Source/Runtime/Core/Public/Containers/SparseArray.h |
| Include Path | #include "Containers/SparseArray.h" |
Syntax
template<typename InElementType, typename Allocator>
class TSparseArray : public TSparseArrayBase< sizeof, alignof, Allocator >
Inheritance Hierarchy
- TSparseArrayBase → TSparseArray
Constructors
| Name | Remarks | Include Path | Unreal Specifiers |
|---|---|---|---|
TSparseArray
(
TSparseArray&& InCopy |
Move constructor. | Containers/SparseArray.h | |
consteval TSparseArray
(
EConstEval |
Containers/SparseArray.h | ||
TSparseArray
(
std::initializer_list< ElementType > InList |
Initializer list constructor. | Containers/SparseArray.h | |
constexpr TSparseArray () |
Default constructor. | Containers/SparseArray.h | |
TSparseArray
(
const TSparseArray& InCopy |
Copy constructor. | Containers/SparseArray.h | |
| Containers/SparseArray.h |
Destructors
| Name | Remarks | Include Path | Unreal Specifiers |
|---|---|---|---|
~TSparseArray() |
Destructor. | Containers/SparseArray.h |
Classes
| Name | Remarks |
|---|---|
| FElementCompareClass | Extracts the element value from the array's element structure and passes it to the user provided comparison class. |
| TBaseIterator | The base class of sparse array iterators. |
| TConstIterator | Iterates over all allocated elements in a const sparse array. |
| TConstSubsetIterator | An iterator which only iterates over the elements of the array which correspond to set bits in a separate bit array. |
| TIterator | Iterates over all allocated elements in a sparse array. |
| TRangedForConstIterator | |
| TRangedForIterator |
Typedefs
| Name | Type | Remarks | Include Path |
|---|---|---|---|
| ElementType | InElementType | Containers/SparseArray.h | |
| FElementOrFreeListLink | typename SuperType::FElementOrFreeListLink | Containers/SparseArray.h | |
| IntrusiveUnsetOptionalStateType | TSparseArray | Containers/SparseArray.h | |
| SuperType | TSparseArrayBase< sizeof(InElementType), alignof(InElementType), Allocator > | Containers/SparseArray.h |
Constants
| Name | Type | Remarks | Include Path |
|---|---|---|---|
| bHasIntrusiveUnsetOptionalState | bool | Start - intrusive TOptional |
Containers/SparseArray.h |
Functions
Public
| Name | Remarks | Include Path | Unreal Specifiers |
|---|---|---|---|
int32 Add
(
const ElementType& Element |
Adds an element to the array. | Containers/SparseArray.h | |
int32 Add
(
ElementType&& Element |
Adds an element to the array. | Containers/SparseArray.h | |
| Containers/SparseArray.h | |||
| DO NOT USE DIRECTLY STL-like iterators to enable range-based for loop support. | Containers/SparseArray.h | ||
void CheckAddress
(
const ElementType* Addr |
Checks that the specified address is not part of an element within the container. | Containers/SparseArray.h | |
bool CompactStable () |
Compacts the allocated elements into a contiguous index range. | Containers/SparseArray.h | |
void CopyUnfrozen
(
const FMemoryUnfreezeContent& Context, |
Containers/SparseArray.h | ||
void CountBytes
(
FArchive& Ar |
Tracks the container's memory use through an archive. | Containers/SparseArray.h | |
TConstIterator CreateConstIterator() |
Creates a const iterator for the contents of this array | Containers/SparseArray.h | |
TIterator CreateIterator() |
Creates an iterator for the contents of this array | Containers/SparseArray.h | |
int32 Emplace
(
ArgsType&&... Args |
Constructs a new item at the last freed index of the array. | Containers/SparseArray.h | |
int32 EmplaceAt
(
int32 Index, |
Constructs a new item at a given index of the array. | Containers/SparseArray.h | |
int32 EmplaceAtLowestFreeIndex
(
int32& LowestFreeIndexSearchStart, |
Constructs a new item at the lowest free index of the array. | Containers/SparseArray.h | |
void Empty
(
int32 ExpectedNumElements |
Removes all elements from the array, potentially leaving space allocated for an expected number of elements about to be added. | Containers/SparseArray.h | |
| Containers/SparseArray.h | |||
| Containers/SparseArray.h | |||
int32 FindArbitraryElementIndex () |
Finds the index of an arbitrary element. | Containers/SparseArray.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/SparseArray.h | |
int32 IndexOfByPredicate
(
Predicate Pred |
Finds an item by predicate. | Containers/SparseArray.h | |
void Insert
(
int32 Index, |
Inserts an element to the array. | Containers/SparseArray.h | |
bool IsCompact() |
Containers/SparseArray.h | ||
int32 PointerToIndex
(
const ElementType* Ptr |
Containers/SparseArray.h | ||
void RemoveAt
(
int32 Index, |
Removes Count elements from the array, starting from Index. | Containers/SparseArray.h | |
void Reset() |
Empties the array, but keep its allocated memory as slack. | Containers/SparseArray.h | |
void Sort () |
Sorts the elements assuming < operator is defined for ElementType. | Containers/SparseArray.h | |
void Sort
(
const PREDICATE_CLASS& Predicate |
Sorts the elements using the provided comparison class. | Containers/SparseArray.h | |
void StableSort () |
Stable sorts the elements assuming < operator is defined for ElementType. | Containers/SparseArray.h | |
void StableSort
(
const PREDICATE_CLASS& Predicate |
Stable sorts the elements using the provided comparison class. | Containers/SparseArray.h | |
void WriteMemoryImage
(
FMemoryImageWriter& Writer |
Containers/SparseArray.h |
Static
| Name | Remarks | Include Path | Unreal Specifiers |
|---|---|---|---|
static void AppendHash
(
const FPlatformTypeLayoutParameters& LayoutParams, |
Containers/SparseArray.h | ||
static void Move
(
SparseArrayType& ToArray, |
Containers/SparseArray.h |
Operators
| Name | Remarks | Include Path | Unreal Specifiers |
|---|---|---|---|
bool operator!=
(
const TSparseArray& B |
Inequality comparison operator. | Containers/SparseArray.h | |
ElementType & operator[]
(
int32 Index |
Accessors. | Containers/SparseArray.h | |
const ElementType & operator[]
(
int32 Index |
Containers/SparseArray.h | ||
TSparseArray & operator+=
(
const TSparseArray& OtherArray |
Concatenation operators | Containers/SparseArray.h | |
TSparseArray & operator+=
(
const TArray< ElementType >& OtherArray |
Containers/SparseArray.h | ||
TSparseArray & operator=
(
TSparseArray&& InCopy |
Move assignment operator. | Containers/SparseArray.h | |
TSparseArray & operator=
(
const TSparseArray& InCopy |
Copy assignment operator. | Containers/SparseArray.h | |
TSparseArray & operator=
(
std::initializer_list< ElementType > InList |
Initializer list assignment operator. | Containers/SparseArray.h | |
bool operator==
(
const TSparseArray& B |
Equality comparison operator. | Containers/SparseArray.h | |
bool operator==
(
FIntrusiveUnsetOptionalState Tag |
Containers/SparseArray.h |