45template<
class TYPE, 
int STACK_SIZE>
 
   56    TYPE* 
data() { 
return nullptr; }
 
 
   59template<
class TYPE, 
int SMALL_VECTOR_SIZE = 0> 
class Array 
   79    Array(std::initializer_list<TYPE> list);
 
  100    template<
typename T> T 
As() 
const;
 
  106    template <
typename ...ELEM_TYPE>
 
  182    template <
typename KEYTYPE> 
IndexT FindIndex(
typename std::enable_if<true, const KEYTYPE&>::type elm, 
const IndexT start = 0) 
const;
 
  225    template<class T, 
bool S>
 
 
  258template<class TYPE, 
int SMALL_VECTOR_SIZE>
 
  270template<
class TYPE, 
int SMALL_VECTOR_SIZE>
 
  287template<
class TYPE, 
int SMALL_VECTOR_SIZE>
 
  299    this->
GrowTo(initialSize);
 
  300    this->
count = initialSize;
 
  302    for (i = 0; i < initialSize; i++)
 
 
  311template<
class TYPE, 
int SMALL_VECTOR_SIZE>
 
  318    static_assert(std::is_trivially_copyable<TYPE>::value, 
"TYPE is not trivially copyable; Util::Array cannot be constructed from pointer of TYPE.");
 
  321    const SizeT bytes = num * 
sizeof(TYPE);
 
 
  328template<
class TYPE, 
int SMALL_VECTOR_SIZE>
 
  338    for (i = 0; i < this->
count; i++)
 
  340        this->
elements[i] = list.begin()[i];
 
 
  347template<
class TYPE, 
int SMALL_VECTOR_SIZE>
 
  359template<
class TYPE, 
int SMALL_VECTOR_SIZE>
 
  372template<
class TYPE, 
int SMALL_VECTOR_SIZE>
 
  380    if (rhs.capacity <= SMALL_VECTOR_SIZE)
 
  382        for (
IndexT i = 0; i < rhs.capacity; i++)
 
  383            this->
elements[i] = rhs.elements[i];
 
  389        rhs.elements = rhs.stackElements.data();
 
  392    rhs.capacity = SMALL_VECTOR_SIZE;
 
 
  398template<
class TYPE, 
int SMALL_VECTOR_SIZE> 
 
  402    #if NEBULA_BOUNDSCHECKS 
  411    for (i = 0; i < this->
count; i++)
 
 
  420template<
class TYPE, 
int SMALL_VECTOR_SIZE> 
 
  446template<
class TYPE, 
int SMALL_VECTOR_SIZE> 
void 
  455template<
class TYPE, 
int SMALL_VECTOR_SIZE>
 
  464template<
class TYPE, 
int SMALL_VECTOR_SIZE> 
void 
  470    this->
count = _capacity;
 
 
  484template<
class TYPE, 
int SMALL_VECTOR_SIZE> 
void  
  495            if (rhs.
count < this->count)
 
 
  514template<
class TYPE, 
int SMALL_VECTOR_SIZE> 
void 
  522        if (rhs.elements != rhs.stackElements.data())
 
  525            rhs.elements = 
nullptr;
 
  533        this->
grow = rhs.grow;
 
  534        this->
count = rhs.count;
 
 
  544template<
class TYPE, 
int SMALL_VECTOR_SIZE> 
void 
  547    if (newCapacity > SMALL_VECTOR_SIZE)
 
 
  566template<
class TYPE, 
int SMALL_VECTOR_SIZE> 
 
  570    #if NEBULA_BOUNDSCHECKS 
  577        growToSize = this->
grow;
 
  591        growToSize = this->
capacity + growBy;
 
 
  601template<
class TYPE, 
int SMALL_VECTOR_SIZE> 
 
  605    #if NEBULA_BOUNDSCHECKS 
  611    if (fromIndex == toIndex)
 
  617    SizeT num = this->count - fromIndex;
 
  620    SizeT neededSize = toIndex + num;
 
  626    if (fromIndex > toIndex)
 
  636        for (i = num - 1; i >= 0; --i)
 
  646    this->count = toIndex + num;
 
 
  652template<
class TYPE, 
int SMALL_VECTOR_SIZE>
 
  656    if constexpr (!std::is_trivially_destructible<TYPE>::value)
 
  658        for (
IndexT i = fromIndex; i < toIndex; i++)
 
 
  672template<
class TYPE, 
int SMALL_VECTOR_SIZE>
 
  677    if constexpr (!std::is_trivially_copyable<TYPE>::value)
 
  680        for (i = 0; i < num; i++)
 
 
  694template<
class TYPE, 
int SMALL_VECTOR_SIZE>
 
  699    if constexpr (!std::is_trivially_move_assignable<TYPE>::value && std::is_move_assignable<TYPE>::value)
 
  702        for (i = 0; i < num; i++)
 
  704            to[i] = std::move(from[i]);
 
 
  716template<
class TYPE, 
int SMALL_VECTOR_SIZE>
 
  720#if NEBULA_BOUNDSCHECKS 
 
  730template<
class TYPE, 
int SMALL_VECTOR_SIZE> 
 
  739    #if NEBULA_BOUNDSCHECKS 
 
  748template<
class TYPE, 
int SMALL_VECTOR_SIZE> 
 
  757#if NEBULA_BOUNDSCHECKS 
 
  766template<
class TYPE, 
int SMALL_VECTOR_SIZE> 
 
  771    if (neededCapacity > this->
capacity)
 
  773        this->
GrowTo(neededCapacity);
 
  778    for (i = 0; i < rhs.
count; i++)
 
 
  788template<
class TYPE, 
int SMALL_VECTOR_SIZE> 
 
  793    if (neededCapacity > this->
capacity)
 
  795        this->
GrowTo(neededCapacity);
 
  800    for (i = 0; i < 
count; i++)
 
  802        this->
elements[this->count + i] = arr[i];
 
  804    this->count += 
count;
 
 
  810template<
class TYPE, 
int SMALL_VECTOR_SIZE>
 
  819#if NEBULA_BOUNDSCHECKS 
 
  829template<
class TYPE, 
int SMALL_VECTOR_SIZE>
 
  834    if (neededCapacity > this->
capacity)
 
  836        this->
GrowTo(neededCapacity);
 
  841    for (i = 0; i < 
count; i++)
 
  843        this->
elements[this->count + i] = TYPE();
 
  845    TYPE* first = &this->
elements[this->count];
 
  846    this->count += 
count;
 
 
  860template<
class TYPE, 
int SMALL_VECTOR_SIZE> 
 
  864#if NEBULA_BOUNDSCHECKS 
  869    if (neededCapacity > this->
capacity)
 
  871        this->
GrowTo(neededCapacity);
 
 
  878template<
class TYPE, 
int SMALL_VECTOR_SIZE> 
 
  888template<
class TYPE, 
int SMALL_VECTOR_SIZE> 
 
  892    return this->
count * 
sizeof(TYPE);
 
 
  898template<
class TYPE, 
int SMALL_VECTOR_SIZE> 
 
  910template<
class TYPE, 
int SMALL_VECTOR_SIZE> 
 
  914    #if NEBULA_BOUNDSCHECKS 
 
  925template<
class TYPE, 
int SMALL_VECTOR_SIZE> 
 
  929#if NEBULA_BOUNDSCHECKS 
 
  940template<
class TYPE, 
int SMALL_VECTOR_SIZE> 
 
  944    if (rhs.
Size() == this->Size())
 
  948        for (i = 0; i < num; i++)
 
 
  968template<
class TYPE, 
int SMALL_VECTOR_SIZE> 
 
  972    return !(*
this == rhs);
 
 
  978template<
class TYPE, 
int SMALL_VECTOR_SIZE> 
 
  982    #if NEBULA_BOUNDSCHECKS 
 
  991template<
class TYPE, 
int SMALL_VECTOR_SIZE> 
 
  995    #if NEBULA_BOUNDSCHECKS 
 
 1004template<
class TYPE, 
int SMALL_VECTOR_SIZE>
 
 1014template<
class TYPE, 
int SMALL_VECTOR_SIZE> 
 
 1018    return (this->
count == 0);
 
 
 1024template<
class TYPE, 
int SMALL_VECTOR_SIZE>
 
 1028    return this->
elements && (index < this->
count) && (index >= 0);
 
 
 1034template<
class TYPE, 
int SMALL_VECTOR_SIZE> 
 
 1038    #if NEBULA_BOUNDSCHECKS 
 1041    if (index == (this->count - 1))
 
 1048        this->
Move(index + 1, index);
 
 
 1056template<
class TYPE, 
int SMALL_VECTOR_SIZE>
 
 1060    #if NEBULA_BOUNDSCHECKS 
 1065    IndexT lastElementIndex = this->count - 1;
 
 1066    if (index < lastElementIndex)
 
 1068        if constexpr (!std::is_trivially_move_assignable<TYPE>::value)
 
 
 1079template<
class TYPE, 
int SMALL_VECTOR_SIZE> 
 
 1083    #if NEBULA_BOUNDSCHECKS 
 
 1094template<
class TYPE, 
int SMALL_VECTOR_SIZE> 
 
 1098    #if NEBULA_BOUNDSCHECKS 
 
 1108template<
class TYPE, 
int SMALL_VECTOR_SIZE> 
 
 1122        this->count -= 
end - start;
 
 
 1129template<
class TYPE, 
int SMALL_VECTOR_SIZE> 
 
 1134    if constexpr (!std::is_trivially_destructible<TYPE>::value)
 
 
 1142template<
class TYPE, 
int SMALL_VECTOR_SIZE> 
 
 1152template<
class TYPE, 
int SMALL_VECTOR_SIZE>
 
 1156#if NEBULA_BOUNDSCHECKS 
 1159    TYPE ret = std::move(this->
elements[0]);
 
 
 1167template<
class TYPE, 
int SMALL_VECTOR_SIZE>
 
 1171#if NEBULA_BOUNDSCHECKS 
 
 1181template<
class TYPE, 
int SMALL_VECTOR_SIZE> 
 
 1185    #if NEBULA_BOUNDSCHECKS 
 1188    if (index == this->
count)
 
 1195        this->
Move(index, index + 1);
 
 
 1205template<
class TYPE, 
int SMALL_VECTOR_SIZE> 
 
 1209    if (this->
count > 0)
 
 
 1221template<
class TYPE, 
int SMALL_VECTOR_SIZE> 
 
 1232template<
class TYPE, 
int SMALL_VECTOR_SIZE> 
 
 1243template<
class TYPE, 
int SMALL_VECTOR_SIZE> 
 
 1253template<
class TYPE, 
int SMALL_VECTOR_SIZE> 
 
 1263template<
class TYPE, 
int SMALL_VECTOR_SIZE> 
 
 1273template<
class TYPE, 
int SMALL_VECTOR_SIZE> 
 
 1288template<
class TYPE, 
int SMALL_VECTOR_SIZE> 
 
 1294    for (index = start; index < this->count; index++)
 
 
 1312template<
class TYPE, 
int SMALL_VECTOR_SIZE> 
 
 1318    for (index = start; index < this->count; index++)
 
 
 1331template<
class TYPE, 
int SMALL_VECTOR_SIZE>
 
 1332template<
typename ...ELEM_TYPE>
 
 1337    const int size = 
sizeof...(elements) + 1;
 
 1342        this->elements[this->
count++] = res[i];
 
 
 1361template<
class TYPE, 
int SMALL_VECTOR_SIZE>
 
 1362template<
typename KEYTYPE> 
 
 1368    for (index = start; index < this->count; index++)
 
 
 1387template<
class TYPE, 
int SMALL_VECTOR_SIZE> 
 
 1391    if ((first + num) > this->
count)
 
 1393        this->
GrowTo(first + num);
 
 1394        this->
count = first + num;
 
 1398    for (i = first; i < (first + num); i++)
 
 
 1411template<
class TYPE, 
int SMALL_VECTOR_SIZE> 
 
 1418    for (i = 0; i < num; i++)
 
 1420        if (0 == this->
Find(rhs[i]))
 
 
 1432template<
class TYPE, 
int SMALL_VECTOR_SIZE> 
 
 1436    std::sort(this->
Begin(), this->
End());
 
 
 1443template <
class TYPE, 
int SMALL_VECTOR_SIZE>
 
 1451        [](
const void* a, 
const void* b)
 
 1453            TYPE arg1 = *
static_cast<const TYPE*
>(a);
 
 1454            TYPE arg2 = *
static_cast<const TYPE*
>(b);
 
 1455            return (arg1 > arg2) - (arg1 < arg2);
 
 
 1463template<
class TYPE, 
int SMALL_VECTOR_SIZE> 
 
 1467    std::sort(this->
Begin(), this->
End(), func);
 
 
 1473template <
class TYPE, 
int SMALL_VECTOR_SIZE>
 
 1490template<
class TYPE, 
int SMALL_VECTOR_SIZE> 
 
 1503            if (0 != (
half = num/2)) 
 
 1505                mid = lo + ((num & 1) ? 
half : (
half - 1));
 
 1511                else if (elm > this->
elements[mid]) 
 
 
 1550template<
class TYPE, 
int SMALL_VECTOR_SIZE>
 
 1551template<
typename KEYTYPE> 
inline IndexT  
 1563            if (0 != (
half = num / 2))
 
 1565                mid = lo + ((num & 1) ? 
half : (
half - 1));
 
 1571                else if (this->
elements[mid] < elm)
 
 
 1604template<
class TYPE, 
int SMALL_VECTOR_SIZE> 
 
 1608    if (num < this->
count)
 
 
 1623template<
class TYPE, 
int SMALL_VECTOR_SIZE>
 
 1624template<
typename ...ARGS>
 
 1627    if (num < this->
count)
 
 
 1645template<
class TYPE, 
int SMALL_VECTOR_SIZE>
 
 1658template<
class TYPE, 
int SMALL_VECTOR_SIZE>
 
 1668template<
class TYPE, 
int SMALL_VECTOR_SIZE>
 
 1687template<
class TYPE, 
int SMALL_VECTOR_SIZE> 
 
 1688inline constexpr SizeT  
 1691    return sizeof(TYPE);
 
 
 1697template<
class TYPE, 
int SMALL_VECTOR_SIZE> 
 
 1708template<
class TYPE, 
int SMALL_VECTOR_SIZE> 
 
 1718template<
class TYPE, 
int SMALL_VECTOR_SIZE> 
 
 1728template<
class TYPE, 
int SMALL_VECTOR_SIZE> 
 
 1745template<
class TYPE, 
int SMALL_VECTOR_SIZE> 
 
 1749    if (this->
count > 1)
 
 1752        for (i = 0; i < this->
count - 1; i++)
 
 
 1769template<
class TYPE, 
int SMALL_VECTOR_SIZE> 
 
 1773    IndexT i = startIndex + 1;
 
 1774    for (; i < this->
count; i++)
 
 1785    return (this->
Size() - 1);
 
 
 1793template<
class TYPE, 
int SMALL_VECTOR_SIZE> 
 
 1802        return this->
Size() - 1;
 
 1812            if (0 != (
half = num/2)) 
 
 1814                mid = lo + ((num & 1) ? 
half : (
half - 1));
 
 1820                else if (elm > this->
elements[mid]) 
 
 1841                    this->
Insert(lo + 1, elm);
 
 1853                #if NEBULA_BOUNDSCHECKS 
 1867            this->
Insert(lo + 1, elm);
 
 1876    n_error(
"Array::InsertSorted: Can't happen!");
 
 
 1880template<
class TYPE, 
int STACK_SIZE>
 
Nebula's dynamic array class.
Definition array.h:60
Array(std::nullptr_t)
construct an empty fixed array
Definition array.h:348
void Move(IndexT fromIndex, IndexT toIndex)
const TYPE * ConstIterator
Definition array.h:64
void Extend(SizeT num)
Resize to fit the provided value, but don't shrink if the new size is smaller.
Definition array.h:1646
Array(SizeT initialCapacity, SizeT initialGrow)
constuctor with initial size and grow size
Definition array.h:271
void Reserve(SizeT num)
increase capacity to fit N more elements into the array.
Definition array.h:862
void Fill(IndexT first, SizeT num, const TYPE &elm)
fill array range with element
Definition array.h:1389
IndexT FindIndex(const TYPE &elm, const IndexT start=0) const
find identical element in array, return index, InvalidIndex if not found
Definition array.h:1314
Iterator End() const
return iterator to end of array
Definition array.h:1265
SizeT capacity
Definition array.h:248
SizeT count
Definition array.h:249
TYPE * EmplaceArray(const SizeT count)
Emplace range of items and return pointer to first.
Definition array.h:831
~Array()
destructor
Definition array.h:456
Iterator Find(const TYPE &elm, const IndexT start=0) const
find identical element in array, return iterator
Definition array.h:1290
IndexT FindIndex(typename std::enable_if< true, const KEYTYPE & >::type elm, const IndexT start=0) const
find identical element using a specific key type
Definition array.h:1364
bool operator!=(const Array< TYPE, SMALL_VECTOR_SIZE > &rhs) const
inequality operator
Definition array.h:970
TYPE * Iterator
define iterator
Definition array.h:63
void EraseFront()
erase front
Definition array.h:1144
TYPE & Back() const
return reference to last element
Definition array.h:993
void Copy(const Array< TYPE, SMALL_VECTOR_SIZE > &src)
const SizeT Capacity() const
get overall allocated size of array in number of elements
Definition array.h:900
void Clear()
clear array (calls destructors)
Definition array.h:1207
TYPE * elements
Definition array.h:250
IndexT InsertAtEndOfIdenticalRange(IndexT startIndex, const TYPE &elm)
insert element at the first non-identical position, return index of inclusion position
Definition array.h:1771
ConstIterator ConstEnd() const
return const iterator to end of array
Definition array.h:1275
constexpr SizeT TypeSize() const
Returns sizeof(TYPE)
Definition array.h:1689
Array(std::initializer_list< TYPE > list)
constructor from initializer list
Definition array.h:329
void EraseRange(IndexT start, IndexT end)
erase range, excluding the element at end
Definition array.h:1110
IndexT BinarySearchIndex(typename std::enable_if< true, const KEYTYPE & >::type elm) const
do a binary search using a specific key type
Definition array.h:1552
void Sort()
sort the array
Definition array.h:1434
SizeT grow
Definition array.h:247
void operator=(Array< TYPE, SMALL_VECTOR_SIZE > &&rhs) noexcept
move operator
Definition array.h:515
void QuickSort()
quick sort the array
Definition array.h:1445
void Append(TYPE &&elm)
append an element which is being forwarded
Definition array.h:750
void DestroyRange(IndexT fromIndex, IndexT toIndex)
Array< TYPE, SMALL_VECTOR_SIZE > ArrayT
Definition array.h:66
TYPE & operator[](IndexT index) const
[] operator
Definition array.h:912
static const SizeT MinGrowSize
Definition array.h:245
Array(ArrayT &&rhs) noexcept
move constructor
Definition array.h:373
void SortWithFunc(bool(*func)(const TYPE &lhs, const TYPE &rhs))
sort with custom function
Definition array.h:1465
void Append(const TYPE &first, const ELEM_TYPE &... elements)
Append multiple elements to the end of the array.
Definition array.h:1334
TYPE & operator[](IndexT index)
[] operator
Definition array.h:927
Iterator begin() const
for range-based iteration
Definition array.h:1710
Iterator EraseSwap(Iterator iter)
erase element at iterator, fill gap by swapping in last element, destroys sorting!
Definition array.h:1096
TYPE & Emplace()
Emplace item (create new item and return reference)
Definition array.h:812
Array(const TYPE *const buf, SizeT num)
constructor from TYPE pointer and size.
Definition array.h:312
void Reset()
reset array (does NOT call destructors)
Definition array.h:1223
void Realloc(SizeT capacity, SizeT grow)
clear contents and preallocate with new attributes
Definition array.h:465
T As() const
convert to "anything"
bool IsEmpty() const
return true if array empty
Definition array.h:1016
IndexT InsertSorted(const TYPE &elm)
insert element into sorted array, return index where element was included
Definition array.h:1795
void AppendArray(const Array< TYPE, SMALL_VECTOR_SIZE > &rhs)
append the contents of an array to this array
Definition array.h:768
void EraseIndex(IndexT index)
erase element at index, keep sorting intact
Definition array.h:1036
static const SizeT MaxGrowSize
Definition array.h:246
const SizeT ByteSize() const
return the byte size of the array.
Definition array.h:890
void EraseIndexSwap(IndexT index)
erase element at index, fill gap by swapping in last element, destroys sorting!
Definition array.h:1058
TYPE PopFront()
Pop front.
Definition array.h:1154
ConstIterator ConstBegin() const
return const iterator to beginning of array
Definition array.h:1255
_smallvector< TYPE, SMALL_VECTOR_SIZE > stackElements
Definition array.h:252
void resize(size_t size)
Definition array.h:1730
Array(SizeT initialSize, SizeT initialGrow, const TYPE &initialValue)
constructor with initial size, grow size and initial values
Definition array.h:288
void operator=(const Array< TYPE, SMALL_VECTOR_SIZE > &rhs)
assignment operator
Definition array.h:485
void Append(const TYPE &elm)
append element to end of array
Definition array.h:732
void GrowTo(SizeT newCapacity)
TYPE & Get(IndexT index) const
Get element (same as operator[] but as a function)
Definition array.h:718
void Insert(IndexT index, const TYPE &elm)
insert element before element at index
Definition array.h:1183
void push_back(const TYPE &item)
size_t size() const
Definition array.h:1699
void CopyRange(TYPE *to, TYPE *from, SizeT num)
void Resize(SizeT num, ARGS... args)
Resize and fill new elements with arguments.
Definition array.h:1625
bool operator==(const Array< TYPE, SMALL_VECTOR_SIZE > &rhs) const
equality operator
Definition array.h:942
ArrayT Difference(const Array< TYPE, SMALL_VECTOR_SIZE > &rhs)
returns new array with elements which are not in rhs (slow!)
Definition array.h:1413
void EraseBack()
erase back
Definition array.h:1131
bool IsValidIndex(IndexT index) const
check if index is valid
Definition array.h:1026
Iterator Begin() const
return iterator to beginning of array
Definition array.h:1245
bool IsSorted() const
test if the array is sorted, this is a slow operation!
Definition array.h:1747
IndexT BinarySearchIndex(const TYPE &elm) const
do a binary search, requires a sorted array
Definition array.h:1492
void MoveRange(TYPE *to, TYPE *from, SizeT num)
friend class FixedArray
Definition array.h:226
void Resize(SizeT num)
Set size. Grows array if num is greater than capacity. Calls destroy on all objects at index > num!
Definition array.h:1606
void QuickSortWithFunc(int(*func)(const void *lhs, const void *rhs))
quick sort the array
Definition array.h:1475
Array()
constructor with default parameters
Definition array.h:259
void Free()
free memory and reset size
Definition array.h:1234
const SizeT Size() const
get number of elements in array
Definition array.h:880
void AppendArray(const TYPE *arr, const SizeT count)
append from C array
Definition array.h:790
void clear() noexcept
Definition array.h:1660
TYPE & Front() const
return reference to first element
Definition array.h:980
TYPE PopBack()
Pop back.
Definition array.h:1169
Iterator Erase(Iterator iter)
erase element pointed to by iterator, keep sorting intact
Definition array.h:1081
void Fit()
Fit the size of the array to the amount of elements.
Definition array.h:1670
Array(const ArrayT &rhs)
copy constructor
Definition array.h:360
void __cdecl n_error(const char *msg,...)
This function is called when a serious situation is encountered which requires abortion of the applic...
Definition debug.cc:138
#define n_assert(exp)
Definition debug.h:50
void ArrayFree(size_t size, TYPE *buffer)
Definition memory.h:116
TYPE * ArrayAlloc(size_t size)
Definition memory.h:68
void Copy(const void *from, void *to, size_t numBytes)
Copy a chunk of memory (note the argument order is different from memcpy()!
Definition osxmemory.cc:213
__forceinline void CopyElements(const T *from, T *to, size_t numElements)
Copy a chunk of memory (note the argument order is different from memcpy()!
Definition posixmemory.h:218
__forceinline void MoveElements(const T *from, T *to, size_t numElements)
Move a chunk of memory, can handle overlapping regions.
Definition posixmemory.h:194
void Clear(void *ptr, size_t numBytes)
Overwrite a chunk of memory with 0's.
Definition osxmemory.cc:229
A pinned array is an array which manages its own virtual memory.
Definition String.cs:6
Array< TYPE, STACK_SIZE > StackArray
Definition array.h:1881
Nebula's scalar datatype.
TYPE * data()
Definition array.h:56
TYPE stackElements[STACK_SIZE]
Definition array.h:50
TYPE * data()
Definition array.h:48
static const int InvalidIndex
Definition types.h:45
int SizeT
Definition types.h:40
int IndexT
Definition types.h:39