Files
Project-Reboot-3.0/Project Reboot 3.0/SparseArray.h
2023-03-05 01:03:51 -05:00

52 lines
1.3 KiB
C++

#pragma once
#include "Array.h"
#include "BitArray.h"
template <typename ElementType>
union TSparseArrayElementOrListLink
{
TSparseArrayElementOrListLink(ElementType& InElement)
: ElementData(InElement)
{
}
TSparseArrayElementOrListLink(ElementType&& InElement)
: ElementData(InElement)
{
}
TSparseArrayElementOrListLink(int32 InPrevFree, int32 InNextFree)
: PrevFreeIndex(InPrevFree)
, NextFreeIndex(InNextFree)
{
}
TSparseArrayElementOrListLink<ElementType> operator=(const TSparseArrayElementOrListLink<ElementType>& Other)
{
return TSparseArrayElementOrListLink(Other.NextFreeIndex, Other.PrevFreeIndex);
}
/** If the element is allocated, its value is stored here. */
ElementType ElementData;
struct
{
/** If the element isn't allocated, this is a link to the previous element in the array's free list. */
int PrevFreeIndex;
/** If the element isn't allocated, this is a link to the next element in the array's free list. */
int NextFreeIndex;
};
};
template <typename ArrayType>
class TSparseArray
{
public:
typedef TSparseArrayElementOrListLink<ArrayType> FSparseArrayElement;
TArray<FSparseArrayElement> Data;
TBitArray AllocationFlags;
int32 FirstFreeIndex;
int32 NumFreeIndices;
};