Ark Server API (ASE) - Wiki
Loading...
Searching...
No Matches
TSparseArray< InElementType, Allocator > Class Template Reference

#include <SparseArray.h>

+ Collaboration diagram for TSparseArray< InElementType, Allocator >:

Classes

class  FElementCompareClass
 
class  TBaseIterator
 
class  TConstIterator
 
class  TConstSubsetIterator
 
class  TIterator
 
class  TRangedForConstIterator
 
class  TRangedForIterator
 

Public Member Functions

 ~TSparseArray ()
 
FSparseArrayAllocationInfo AllocateIndex (int32 Index)
 
FSparseArrayAllocationInfo AddUninitialized ()
 
int32 Add (typename TTypeTraits< ElementType >::ConstInitType Element)
 
FSparseArrayAllocationInfo InsertUninitialized (int32 Index)
 
void Insert (int32 Index, typename TTypeTraits< ElementType >::ConstInitType Element)
 
void RemoveAt (int32 Index, int32 Count=1)
 
void RemoveAtUninitialized (int32 Index, int32 Count=1)
 
void Empty (int32 ExpectedNumElements=0)
 
void Reset ()
 
void Reserve (int32 ExpectedNumElements)
 
void Shrink ()
 
bool Compact ()
 
bool CompactStable ()
 
uint32 GetAllocatedSize (void) const
 
 TSparseArray ()
 
 TSparseArray (TSparseArray &&InCopy)
 
 TSparseArray (const TSparseArray &InCopy)
 
TSparseArrayoperator= (TSparseArray &&InCopy)
 
TSparseArrayoperator= (const TSparseArray &InCopy)
 
ElementTypeoperator[] (int32 Index)
 
const ElementTypeoperator[] (int32 Index) const
 
bool IsAllocated (int32 Index) const
 
int32 GetMaxIndex () const
 
int32 Num () const
 
FORCEINLINE void CheckAddress (const ElementType *Addr) const
 
TIterator CreateIterator ()
 
TConstIterator CreateConstIterator () const
 
TSparseArrayoperator+= (const TSparseArray &OtherArray)
 
TSparseArrayoperator+= (const TArray< ElementType > &OtherArray)
 

Private Types

using ElementType = InElementType
 
typedef TSparseArrayElementOrFreeListLink< TAlignedBytes< sizeof(ElementType), alignof(ElementType)> > FElementOrFreeListLink
 
typedef TArray< FElementOrFreeListLink, typename Allocator::ElementAllocator > DataType
 
typedef TBitArray< typename Allocator::BitArrayAllocator > AllocationBitArrayType
 

Private Member Functions

FElementOrFreeListLinkGetData (int32 Index)
 
const FElementOrFreeListLinkGetData (int32 Index) const
 

Static Private Member Functions

template<typename SparseArrayType >
static FORCEINLINE TEnableIf< TContainerTraits< SparseArrayType >::MoveWillEmptyContainer >::Type MoveOrCopy (SparseArrayType &ToArray, SparseArrayType &FromArray)
 
template<typename SparseArrayType >
static FORCEINLINE TEnableIf<!TContainerTraits< SparseArrayType >::MoveWillEmptyContainer >::Type MoveOrCopy (SparseArrayType &ToArray, SparseArrayType &FromArray)
 

Private Attributes

DataType Data
 
AllocationBitArrayType AllocationFlags
 
int32 FirstFreeIndex
 
int32 NumFreeIndices
 

Friends

struct TContainerTraits< TSparseArray >
 
class FScriptSparseArray
 
bool operator== (const TSparseArray &A, const TSparseArray &B)
 
bool operator!= (const TSparseArray &A, const TSparseArray &B)
 
FORCEINLINE friend TRangedForIterator begin (TSparseArray &Array)
 
FORCEINLINE friend TRangedForConstIterator begin (const TSparseArray &Array)
 
FORCEINLINE friend TRangedForIterator end (TSparseArray &Array)
 
FORCEINLINE friend TRangedForConstIterator end (const TSparseArray &Array)
 

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

Definition at line 58 of file SparseArray.h.

Member Typedef Documentation

◆ AllocationBitArrayType

template<typename InElementType , typename Allocator >
typedef TBitArray<typename Allocator::BitArrayAllocator> TSparseArray< InElementType, Allocator >::AllocationBitArrayType
private

Definition at line 873 of file SparseArray.h.

◆ DataType

template<typename InElementType , typename Allocator >
typedef TArray<FElementOrFreeListLink,typename Allocator::ElementAllocator> TSparseArray< InElementType, Allocator >::DataType
private

Definition at line 870 of file SparseArray.h.

◆ ElementType

template<typename InElementType , typename Allocator >
using TSparseArray< InElementType, Allocator >::ElementType = InElementType
private

Definition at line 60 of file SparseArray.h.

◆ FElementOrFreeListLink

template<typename InElementType , typename Allocator >
typedef TSparseArrayElementOrFreeListLink< TAlignedBytes<sizeof(ElementType), alignof(ElementType)> > TSparseArray< InElementType, Allocator >::FElementOrFreeListLink
private

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

Definition at line 839 of file SparseArray.h.

Constructor & Destructor Documentation

◆ ~TSparseArray()

template<typename InElementType , typename Allocator >
TSparseArray< InElementType, Allocator >::~TSparseArray ( )
inline

Destructor.

Definition at line 68 of file SparseArray.h.

◆ TSparseArray() [1/3]

template<typename InElementType , typename Allocator >
TSparseArray< InElementType, Allocator >::TSparseArray ( )
inline

Default constructor.

Definition at line 474 of file SparseArray.h.

◆ TSparseArray() [2/3]

template<typename InElementType , typename Allocator >
TSparseArray< InElementType, Allocator >::TSparseArray ( TSparseArray< InElementType, Allocator > && InCopy)
inline

Move constructor.

Definition at line 480 of file SparseArray.h.

◆ TSparseArray() [3/3]

template<typename InElementType , typename Allocator >
TSparseArray< InElementType, Allocator >::TSparseArray ( const TSparseArray< InElementType, Allocator > & InCopy)
inline

Copy constructor.

Definition at line 486 of file SparseArray.h.

Member Function Documentation

◆ Add()

template<typename InElementType , typename Allocator >
int32 TSparseArray< InElementType, Allocator >::Add ( typename TTypeTraits< ElementType >::ConstInitType Element)
inline

Adds an element to the array.

Definition at line 121 of file SparseArray.h.

◆ AddUninitialized()

template<typename InElementType , typename Allocator >
FSparseArrayAllocationInfo TSparseArray< InElementType, Allocator >::AddUninitialized ( )
inline

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.

Definition at line 96 of file SparseArray.h.

◆ AllocateIndex()

template<typename InElementType , typename Allocator >
FSparseArrayAllocationInfo TSparseArray< InElementType, Allocator >::AllocateIndex ( int32 Index)
inline

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

Definition at line 75 of file SparseArray.h.

◆ CheckAddress()

template<typename InElementType , typename Allocator >
FORCEINLINE 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.

Definition at line 603 of file SparseArray.h.

◆ Compact()

template<typename InElementType , typename Allocator >
bool TSparseArray< InElementType, Allocator >::Compact ( )
inline

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

Definition at line 355 of file SparseArray.h.

◆ CompactStable()

template<typename InElementType , typename Allocator >
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.

Definition at line 402 of file SparseArray.h.

◆ CreateConstIterator()

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

Creates a const iterator for the contents of this array

Definition at line 759 of file SparseArray.h.

◆ CreateIterator()

template<typename InElementType , typename Allocator >
TIterator TSparseArray< InElementType, Allocator >::CreateIterator ( )
inline

Creates an iterator for the contents of this array

Definition at line 753 of file SparseArray.h.

◆ Empty()

template<typename InElementType , typename Allocator >
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.

Definition at line 225 of file SparseArray.h.

◆ GetAllocatedSize()

template<typename InElementType , typename Allocator >
uint32 TSparseArray< InElementType, Allocator >::GetAllocatedSize ( void ) const
inline

Helper function to return the amount of memory allocated by this container

Returns
number of bytes allocated by this container

Definition at line 427 of file SparseArray.h.

◆ GetData() [1/2]

template<typename InElementType , typename Allocator >
FElementOrFreeListLink & TSparseArray< InElementType, Allocator >::GetData ( int32 Index)
inlineprivate

Accessor for the element or free list data.

Definition at line 859 of file SparseArray.h.

◆ GetData() [2/2]

template<typename InElementType , typename Allocator >
const FElementOrFreeListLink & TSparseArray< InElementType, Allocator >::GetData ( int32 Index) const
inlineprivate

Accessor for the element or free list data.

Definition at line 865 of file SparseArray.h.

◆ GetMaxIndex()

template<typename InElementType , typename Allocator >
int32 TSparseArray< InElementType, Allocator >::GetMaxIndex ( ) const
inline

Definition at line 594 of file SparseArray.h.

◆ Insert()

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

Inserts an element to the array.

Definition at line 179 of file SparseArray.h.

◆ InsertUninitialized()

template<typename InElementType , typename Allocator >
FSparseArrayAllocationInfo TSparseArray< InElementType, Allocator >::InsertUninitialized ( int32 Index)
inline

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.

Definition at line 132 of file SparseArray.h.

◆ IsAllocated()

template<typename InElementType , typename Allocator >
bool TSparseArray< InElementType, Allocator >::IsAllocated ( int32 Index) const
inline

Definition at line 593 of file SparseArray.h.

◆ MoveOrCopy() [1/2]

template<typename InElementType , typename Allocator >
template<typename SparseArrayType >
static FORCEINLINE TEnableIf< TContainerTraits< SparseArrayType >::MoveWillEmptyContainer >::Type TSparseArray< InElementType, Allocator >::MoveOrCopy ( SparseArrayType & ToArray,
SparseArrayType & FromArray )
inlinestaticprivate

Definition at line 552 of file SparseArray.h.

◆ MoveOrCopy() [2/2]

template<typename InElementType , typename Allocator >
template<typename SparseArrayType >
static FORCEINLINE TEnableIf<!TContainerTraits< SparseArrayType >::MoveWillEmptyContainer >::Type TSparseArray< InElementType, Allocator >::MoveOrCopy ( SparseArrayType & ToArray,
SparseArrayType & FromArray )
inlinestaticprivate

Definition at line 573 of file SparseArray.h.

◆ Num()

template<typename InElementType , typename Allocator >
int32 TSparseArray< InElementType, Allocator >::Num ( ) const
inline

Definition at line 595 of file SparseArray.h.

◆ operator+=() [1/2]

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

Definition at line 821 of file SparseArray.h.

◆ operator+=() [2/2]

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

Concatenation operators

Definition at line 812 of file SparseArray.h.

◆ operator=() [1/2]

template<typename InElementType , typename Allocator >
TSparseArray & TSparseArray< InElementType, Allocator >::operator= ( const TSparseArray< InElementType, Allocator > & InCopy)
inline

Copy assignment operator.

Definition at line 504 of file SparseArray.h.

◆ operator=() [2/2]

template<typename InElementType , typename Allocator >
TSparseArray & TSparseArray< InElementType, Allocator >::operator= ( TSparseArray< InElementType, Allocator > && InCopy)
inline

Move assignment operator.

Definition at line 494 of file SparseArray.h.

◆ operator[]() [1/2]

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

Definition at line 580 of file SparseArray.h.

◆ operator[]() [2/2]

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

Definition at line 586 of file SparseArray.h.

◆ RemoveAt()

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

Removes Count elements from the array, starting from Index.

Definition at line 185 of file SparseArray.h.

◆ RemoveAtUninitialized()

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

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

Definition at line 199 of file SparseArray.h.

◆ Reserve()

template<typename InElementType , typename Allocator >
void TSparseArray< InElementType, Allocator >::Reserve ( int32 ExpectedNumElements)
inline

Preallocates enough memory to contain the specified number of elements.

Parameters
ExpectedNumElementsthe total number of elements that the array will have

Definition at line 269 of file SparseArray.h.

◆ Reset()

template<typename InElementType , typename Allocator >
void TSparseArray< InElementType, Allocator >::Reset ( )
inline

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

Definition at line 245 of file SparseArray.h.

◆ Shrink()

template<typename InElementType , typename Allocator >
void TSparseArray< InElementType, Allocator >::Shrink ( )
inline

Shrinks the array's storage to avoid slack.

Definition at line 299 of file SparseArray.h.

Friends And Related Symbol Documentation

◆ begin [1/2]

template<typename InElementType , typename Allocator >
FORCEINLINE friend TRangedForConstIterator begin ( const TSparseArray< InElementType, Allocator > & Array)
friend

Definition at line 770 of file SparseArray.h.

◆ begin [2/2]

template<typename InElementType , typename Allocator >
FORCEINLINE friend TRangedForIterator begin ( TSparseArray< InElementType, Allocator > & Array)
friend

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

Definition at line 769 of file SparseArray.h.

◆ end [1/2]

template<typename InElementType , typename Allocator >
FORCEINLINE friend TRangedForConstIterator end ( const TSparseArray< InElementType, Allocator > & Array)
friend

Definition at line 772 of file SparseArray.h.

◆ end [2/2]

template<typename InElementType , typename Allocator >
FORCEINLINE friend TRangedForIterator end ( TSparseArray< InElementType, Allocator > & Array)
friend

Definition at line 771 of file SparseArray.h.

◆ FScriptSparseArray

template<typename InElementType , typename Allocator >
friend class FScriptSparseArray
friend

Definition at line 63 of file SparseArray.h.

◆ operator!=

template<typename InElementType , typename Allocator >
bool operator!= ( const TSparseArray< InElementType, Allocator > & A,
const TSparseArray< InElementType, Allocator > & B )
friend

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

Definition at line 468 of file SparseArray.h.

◆ operator==

template<typename InElementType , typename Allocator >
bool operator== ( const TSparseArray< InElementType, Allocator > & A,
const TSparseArray< InElementType, Allocator > & B )
friend

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

Definition at line 437 of file SparseArray.h.

◆ TContainerTraits< TSparseArray >

template<typename InElementType , typename Allocator >
friend struct TContainerTraits< TSparseArray >
friend

Definition at line 44 of file SparseArray.h.

Member Data Documentation

◆ AllocationFlags

template<typename InElementType , typename Allocator >
AllocationBitArrayType TSparseArray< InElementType, Allocator >::AllocationFlags
private

Definition at line 874 of file SparseArray.h.

◆ Data

template<typename InElementType , typename Allocator >
DataType TSparseArray< InElementType, Allocator >::Data
private

Definition at line 871 of file SparseArray.h.

◆ FirstFreeIndex

template<typename InElementType , typename Allocator >
int32 TSparseArray< InElementType, Allocator >::FirstFreeIndex
private

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

Definition at line 877 of file SparseArray.h.

◆ NumFreeIndices

template<typename InElementType , typename Allocator >
int32 TSparseArray< InElementType, Allocator >::NumFreeIndices
private

The number of elements in the free list.

Definition at line 880 of file SparseArray.h.


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