TSparseArray

Forward declarations.

Windows
MacOS
Linux

References

Module

Core

Header

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

Include

#include "Containers/SparseArray.h"

Syntax

template<typename InElementType, typename Allocator>
class TSparseArray

Remarks

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).

Constructors

Name Description

Public function

TSparseArray()

Default constructor.

Public function

TSparseArray

(
    TSparseArray&& InCopy
)

Move constructor.

Public function

TSparseArray

(
    const TSparseArray& InCopy
)

Copy constructor.

Destructors

Name Description

Public function

~TSparseArray()

Destructor.

Functions

Name Description

Public function

int32

 

Add

(
    const ElementType& Element
)

Adds an element to the array.

Public function

int32

 

Add

(
    ElementType&& Element
)

Adds an element to the array.

Public function

FSparseArray...

 

AddUninitialized()

Allocates space for an element in the array.

Public function

FSparseArray...

 

AddUninitializedAtLowestFreeIndex

(
    int32& LowestFreeIndexSearchStart
)

Public function

FSparseArray...

 

AllocateIndex

(
    int32 Index
)

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

Public function Static

void

 

AppendHash

(
    const FPlatformTypeLayoutParameters...,
    FSHA1& Hasher
)

Public function Const

TRangedForCo...

 

begin()

Public function

TRangedForIt...

 

begin()

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

Public function Const

void

 

CheckAddress

(
    const ElementType* Addr
)

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

Public function

bool

 

Compact()

Compacts the allocated elements into a contiguous index range.

Public function

bool

 

CompactStable()

Compacts the allocated elements into a contiguous index range.

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 array

Public function

TIterator

 

CreateIterator()

Creates an iterator for the contents of this array

Public function

int32

 

Emplace

(
    ArgsType&&... Args
)

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

Public function

int32

 

EmplaceAtLowestFreeIndex

(
    int32& LowestFreeIndexSearchStart,
    ArgsType&&... Args
)

Constructs a new item at the lowest free index of the array.

Public function

void

 

Empty

(
    int32 ExpectedNumElements
)

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

Public function Const

TRangedForCo...

 

end()

Public function

TRangedForIt...

 

end()

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

void

 

Insert

(
    int32 Index,
    typename TTypeTraits< ElementType >...
)

Inserts an element to the array.

Public function

FSparseArray...

 

InsertUninitialized

(
    int32 Index
)

Allocates space for an element in the array at a given index.

Public function Const

bool

 

IsAllocated

(
    int32 Index
)

Public function Const

bool

 

IsCompact()

Public function Const

bool

 

IsValidIndex

(
    int32 Index
)

Public function Const

int32

 

Num()

Public function Const

int32

 

PointerToIndex

(
    const ElementType* Ptr
)

Public function

void

 

RemoveAt

(
    int32 Index,
    int32 Count
)

Removes Count elements from the array, starting from Index.

Public function

void

 

RemoveAtUninitialized

(
    int32 Index,
    int32 Count
)

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

Public function

void

 

Reserve

(
    int32 ExpectedNumElements
)

Preallocates enough memory to contain the specified number of elements.

Public function

void

 

Reset()

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

Public function

void

 

Shrink()

Shrinks the array's storage to avoid slack.

Public function

void

 

Sort()

Sorts the elements assuming < operator is defined for ElementType.

Public function

void

 

Sort

(
    const PREDICATE_CLASS& Predicate
)

Sorts the elements using the provided comparison class.

Public function

void

 

StableSort()

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

Public function

void

 

StableSort

(
    const PREDICATE_CLASS& Predicate
)

Stable sorts the elements using the provided comparison class.

Public function Const

void

 

WriteMemoryImage

(
    FMemoryImageWriter& Writer
)

Operators

Name Description

Public function Const

const Elemen...

 

operator[]

(
    int32 Index
)

Public function

ElementType ...

 

operator[]

(
    int32 Index
)

Accessors.

Public function

TSparseArray...

 

operator+=

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

Public function

TSparseArray...

 

operator+=

(
    const TSparseArray& OtherArray
)

Concatenation operators

Public function

TSparseArray...

 

operator=

(
    const TSparseArray& InCopy
)

Copy assignment operator.

Public function

TSparseArray...

 

operator=

(
    TSparseArray&& InCopy
)

Move assignment operator.

Classes

Name

Description

Public class

TConstIterator

Iterates over all allocated elements in a const sparse array.

Public class

TConstSubsetIterator

An iterator which only iterates over the elements of the array which correspond to set bits in a separate bit array.

Public class

TIterator

Iterates over all allocated elements in a sparse array.

Public class

TRangedForConstIterator

Public class

TRangedForIterator

Typedefs

Name

Description

AllocationBitArrayType

DataType

ElementType

FElementOrFreeListLink

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

Constants

Name

Description

SupportsFreezeMemoryImage

Deprecated Functions

Name Description

Public function

int32

 

AddAtLowestFreeIndex

(
    const ElementType& Element,
    int32& LowestFreeIndexSearchStart
)

AddAtLowestFreeIndex API is deprecated; please use EmplaceAtLowestFreeIndex instead.

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