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>
290 capacity(SMALL_VECTOR_SIZE),
292 elements(stackElements.data())
299 this->
GrowTo(initialSize);
300 this->
count = initialSize;
302 for (i = 0; i < initialSize; i++)
311template<
class TYPE,
int SMALL_VECTOR_SIZE>
314 capacity(SMALL_VECTOR_SIZE),
316 elements(stackElements.data())
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>
331 capacity(SMALL_VECTOR_SIZE),
333 elements(stackElements.data())
338 for (i = 0; i < this->
count; i++)
340 this->
elements[i] = list.begin()[i];
347template<
class TYPE,
int SMALL_VECTOR_SIZE>
350 capacity(SMALL_VECTOR_SIZE),
352 elements(stackElements.data())
359template<
class TYPE,
int SMALL_VECTOR_SIZE>
362 capacity(SMALL_VECTOR_SIZE),
364 elements(this->stackElements.data())
372template<
class TYPE,
int SMALL_VECTOR_SIZE>
375 capacity(rhs.capacity),
377 elements(this->stackElements.data())
380 if (rhs.capacity <= SMALL_VECTOR_SIZE)
382 for (
IndexT i = 0; i < rhs.capacity; i++)
383 this->elements[i] = rhs.elements[i];
388 this->elements = rhs.elements;
389 rhs.elements = rhs.stackElements.data();
392 rhs.capacity = SMALL_VECTOR_SIZE;
398template<
class TYPE,
int SMALL_VECTOR_SIZE>
402 #if NEBULA_BOUNDSCHECKS
404 n_assert(this->stackElements.data() == this->elements);
408 this->grow = src.
grow;
409 this->count = src.
count;
411 for (i = 0; i < this->count; i++)
413 this->elements[i] = src.
elements[i];
420template<
class TYPE,
int SMALL_VECTOR_SIZE>
426 if (this->capacity > 0)
428 if (this->elements != this->stackElements.data())
430 ArrayFree(this->capacity, this->elements);
435 this->DestroyRange(0, this->count);
438 this->elements = this->stackElements.data();
440 this->capacity = 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
469 this->capacity = _capacity;
470 this->count = _capacity;
471 if (this->capacity > 0)
473 this->GrowTo(this->capacity);
484template<
class TYPE,
int SMALL_VECTOR_SIZE>
void
489 if ((this->capacity > 0) && (rhs.
count <= this->capacity))
495 if (rhs.
count < this->count)
497 this->DestroyRange(rhs.
count, this->count);
499 this->grow = rhs.
grow;
500 this->count = rhs.
count;
514template<
class TYPE,
int SMALL_VECTOR_SIZE>
void
522 if (rhs.elements != rhs.stackElements.data())
524 this->elements = rhs.elements;
525 rhs.elements =
nullptr;
530 this->MoveRange(this->elements, rhs.elements, rhs.count);
533 this->grow = rhs.grow;
534 this->count = rhs.count;
535 this->capacity = rhs.capacity;
544template<
class TYPE,
int SMALL_VECTOR_SIZE>
void
547 if (newCapacity > SMALL_VECTOR_SIZE)
552 this->MoveRange(newArray, this->elements, this->count);
555 if (this->elements != this->stackElements.data())
556 ArrayFree(this->capacity, this->elements);
558 this->elements = newArray;
559 this->capacity = newCapacity;
566template<
class TYPE,
int SMALL_VECTOR_SIZE>
570 #if NEBULA_BOUNDSCHECKS
575 if (0 == this->capacity)
577 growToSize = this->grow;
582 SizeT growBy = this->capacity >> 1;
585 growBy = MinGrowSize;
587 else if (growBy > MaxGrowSize)
589 growBy = MaxGrowSize;
591 growToSize = this->capacity + growBy;
593 this->GrowTo(growToSize);
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;
621 while (neededSize > this->capacity)
626 if (fromIndex > toIndex)
629 this->MoveRange(&this->elements[toIndex], &this->elements[fromIndex], num);
630 this->DestroyRange(fromIndex + num - 1, this->count);
636 for (i = num - 1; i >= 0; --i)
638 this->elements[toIndex + i] = this->elements[fromIndex + i];
642 this->DestroyRange(fromIndex, toIndex);
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++)
660 this->Destroy(&(this->elements[i]));
665 Memory::Clear((
void*)&this->elements[fromIndex],
sizeof(TYPE) * (toIndex - fromIndex));
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
721 n_assert(this->elements !=
nullptr);
724 return this->elements[index];
730template<
class TYPE,
int SMALL_VECTOR_SIZE>
735 if (this->count == this->capacity)
739 #if NEBULA_BOUNDSCHECKS
742 this->elements[this->count++] = elm;
748template<
class TYPE,
int SMALL_VECTOR_SIZE>
753 if (this->count == this->capacity)
757#if NEBULA_BOUNDSCHECKS
760 this->elements[this->count++] = std::move(elm);
766template<
class TYPE,
int SMALL_VECTOR_SIZE>
770 SizeT neededCapacity = this->count + rhs.
count;
771 if (neededCapacity > this->capacity)
773 this->GrowTo(neededCapacity);
778 for (i = 0; i < rhs.
count; i++)
780 this->elements[this->count + i] = rhs.
elements[i];
782 this->count += rhs.
count;
788template<
class TYPE,
int SMALL_VECTOR_SIZE>
792 SizeT neededCapacity = this->count + count;
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>
815 if (this->count == this->capacity)
819#if NEBULA_BOUNDSCHECKS
822 this->elements[this->count] = TYPE();
823 return this->elements[this->count++];
829template<
class TYPE,
int SMALL_VECTOR_SIZE>
833 SizeT neededCapacity = this->count + count;
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
868 SizeT neededCapacity = this->count + num;
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>
902 return this->capacity;
910template<
class TYPE,
int SMALL_VECTOR_SIZE>
914 #if NEBULA_BOUNDSCHECKS
915 n_assert(this->elements && (index < this->count) && (index >= 0));
917 return this->elements[index];
925template<
class TYPE,
int SMALL_VECTOR_SIZE>
929#if NEBULA_BOUNDSCHECKS
930 n_assert(this->elements && (index < this->count) && (index >= 0));
932 return this->elements[index];
940template<
class TYPE,
int SMALL_VECTOR_SIZE>
944 if (rhs.
Size() == this->Size())
947 SizeT num = this->Size();
948 for (i = 0; i < num; i++)
950 if (!(this->elements[i] == rhs.
elements[i]))
968template<
class TYPE,
int SMALL_VECTOR_SIZE>
972 return !(*
this == rhs);
978template<
class TYPE,
int SMALL_VECTOR_SIZE>
982 #if NEBULA_BOUNDSCHECKS
983 n_assert(this->elements && (this->count > 0));
985 return this->elements[0];
991template<
class TYPE,
int SMALL_VECTOR_SIZE>
995 #if NEBULA_BOUNDSCHECKS
996 n_assert(this->elements && (this->count > 0));
998 return this->elements[this->count - 1];
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
1039 n_assert(this->elements && (index < this->count) && (index >= 0));
1041 if (index == (this->count - 1))
1048 this->Move(index + 1, index);
1056template<
class TYPE,
int SMALL_VECTOR_SIZE>
1060 #if NEBULA_BOUNDSCHECKS
1061 n_assert(this->elements && (index < this->count) && (index >= 0));
1065 IndexT lastElementIndex = this->count - 1;
1066 if (index < lastElementIndex)
1068 if constexpr (!std::is_trivially_move_assignable<TYPE>::value)
1069 this->elements[index] = std::move(this->elements[lastElementIndex]);
1071 this->elements[index] = this->elements[lastElementIndex];
1079template<
class TYPE,
int SMALL_VECTOR_SIZE>
1083 #if NEBULA_BOUNDSCHECKS
1084 n_assert(this->elements && (iter >= this->elements) && (iter < (this->elements + this->count)));
1086 this->EraseIndex(
IndexT(iter - this->elements));
1094template<
class TYPE,
int SMALL_VECTOR_SIZE>
1098 #if NEBULA_BOUNDSCHECKS
1099 n_assert(this->elements && (iter >= this->elements) && (iter < (this->elements + this->count)));
1101 this->EraseIndexSwap(
IndexT(iter - this->elements));
1108template<
class TYPE,
int SMALL_VECTOR_SIZE>
1115 this->EraseIndex(start);
1119 this->DestroyRange(start, end);
1120 SizeT numMove = this->count - end;
1121 this->MoveRange(&this->elements[start], &this->elements[end], numMove);
1122 this->count -= end - start;
1129template<
class TYPE,
int SMALL_VECTOR_SIZE>
1134 if constexpr (!std::is_trivially_destructible<TYPE>::value)
1135 this->Destroy(&(this->elements[this->count - 1]));
1142template<
class TYPE,
int SMALL_VECTOR_SIZE>
1146 this->EraseIndex(0);
1152template<
class TYPE,
int SMALL_VECTOR_SIZE>
1156#if NEBULA_BOUNDSCHECKS
1159 TYPE ret = std::move(this->elements[0]);
1160 this->EraseIndex(0);
1167template<
class TYPE,
int SMALL_VECTOR_SIZE>
1171#if NEBULA_BOUNDSCHECKS
1175 return std::move(this->elements[this->count]);
1181template<
class TYPE,
int SMALL_VECTOR_SIZE>
1185 #if NEBULA_BOUNDSCHECKS
1186 n_assert(index <= this->count && (index >= 0));
1188 if (index == this->count)
1195 this->Move(index, index + 1);
1196 this->elements[index] = elm;
1205template<
class TYPE,
int SMALL_VECTOR_SIZE>
1209 if (this->count > 0)
1211 this->DestroyRange(0, this->count);
1221template<
class TYPE,
int SMALL_VECTOR_SIZE>
1232template<
class TYPE,
int SMALL_VECTOR_SIZE>
1243template<
class TYPE,
int SMALL_VECTOR_SIZE>
1247 return this->elements;
1253template<
class TYPE,
int SMALL_VECTOR_SIZE>
1263template<
class TYPE,
int SMALL_VECTOR_SIZE>
1267 return this->elements + this->count;
1273template<
class TYPE,
int SMALL_VECTOR_SIZE>
1288template<
class TYPE,
int SMALL_VECTOR_SIZE>
1294 for (index = start; index < this->count; index++)
1296 if (this->elements[index] == elm)
1298 return &(this->elements[index]);
1312template<
class TYPE,
int SMALL_VECTOR_SIZE>
1318 for (index = start; index < this->count; index++)
1320 if (this->elements[index] == elm)
1331template<
class TYPE,
int SMALL_VECTOR_SIZE>
1332template<
typename ...ELEM_TYPE>
1337 const int size =
sizeof...(elements) + 1;
1338 this->Reserve(size);
1339 TYPE res[size] = { first, elements... };
1340 for (
IndexT i = 0; i < size; i++)
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++)
1370 if (this->elements[index] == elm)
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++)
1400 this->elements[i] = elm;
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>
1494 SizeT num = this->Size();
1503 if (0 != (
half = num/2))
1505 mid = lo + ((num & 1) ?
half : (
half - 1));
1506 if (elm < this->elements[mid])
1511 else if (elm > this->elements[mid])
1523 if (elm != this->elements[lo])
1550template<
class TYPE,
int SMALL_VECTOR_SIZE>
1551template<
typename KEYTYPE>
inline IndexT
1554 SizeT num = this->Size();
1563 if (0 != (
half = num / 2))
1565 mid = lo + ((num & 1) ?
half : (
half - 1));
1566 if (this->elements[mid] > elm)
1571 else if (this->elements[mid] < elm)
1583 if (this->elements[lo] != elm)
1604template<
class TYPE,
int SMALL_VECTOR_SIZE>
1608 if (num < this->count)
1610 this->DestroyRange(num, this->count);
1612 else if (num > this->capacity)
1623template<
class TYPE,
int SMALL_VECTOR_SIZE>
1624template<
typename ...ARGS>
1627 if (num < this->count)
1629 this->DestroyRange(num, this->count);
1631 else if (num > this->capacity)
1633 SizeT oldCapacity = this->capacity;
1635 for (
IndexT i = oldCapacity; i < this->capacity; i++)
1636 this->elements[i] = TYPE(args...);
1645template<
class TYPE,
int SMALL_VECTOR_SIZE>
1648 if (num > this->capacity)
1658template<
class TYPE,
int SMALL_VECTOR_SIZE>
1668template<
class TYPE,
int SMALL_VECTOR_SIZE>
1675 this->MoveRange(newArray, this->elements, this->count);
1676 if (this->elements != this->stackElements.data())
1677 ArrayFree(this->capacity, this->elements);
1679 this->elements = newArray;
1681 this->capacity = this->count;
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>
1712 return this->elements;
1718template<
class TYPE,
int SMALL_VECTOR_SIZE>
1722 return this->elements + this->count;
1728template<
class TYPE,
int SMALL_VECTOR_SIZE>
1732 if (
static_cast<SizeT>(s) > this->capacity)
1734 this->GrowTo(
static_cast<SizeT>(s));
1736 this->count =
static_cast<SizeT>(s);
1745template<
class TYPE,
int SMALL_VECTOR_SIZE>
1749 if (this->count > 1)
1752 for (i = 0; i < this->count - 1; i++)
1754 if (this->elements[i] > this->elements[i + 1])
1769template<
class TYPE,
int SMALL_VECTOR_SIZE>
1773 IndexT i = startIndex + 1;
1774 for (; i < this->count; i++)
1776 if (this->elements[i] != elm)
1778 this->Insert(i, elm);
1785 return (this->Size() - 1);
1793template<
class TYPE,
int SMALL_VECTOR_SIZE>
1797 SizeT num = this->Size();
1802 return this->Size() - 1;
1812 if (0 != (
half = num/2))
1814 mid = lo + ((num & 1) ?
half : (
half - 1));
1815 if (elm < this->elements[mid])
1820 else if (elm > this->elements[mid])
1829 return this->InsertAtEndOfIdenticalRange(mid, elm);
1834 if (elm < this->elements[lo])
1836 this->Insert(lo, elm);
1839 else if (elm > this->elements[lo])
1841 this->Insert(lo + 1, elm);
1848 return this->InsertAtEndOfIdenticalRange(lo, elm);
1853 #if NEBULA_BOUNDSCHECKS
1856 this->Insert(lo, elm);
1860 if (elm < this->elements[lo])
1862 this->Insert(lo, elm);
1865 else if (elm > this->elements[lo])
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)
move elements, grows array if needed
Definition array.h:603
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
void Destroy(TYPE *elm)
destroy an element (call destructor without freeing memory)
Definition array.h:447
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
TYPE * Iterator
define iterator
Definition array.h:63
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
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)
copy content
Definition array.h:400
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 Delete()
delete content
Definition array.h:422
void Append(TYPE &&elm)
append an element which is being forwarded
Definition array.h:750
void DestroyRange(IndexT fromIndex, IndexT toIndex)
destroy range of elements
Definition array.h:654
Iterator end() const
Definition array.h:1720
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
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 Grow()
grow array with grow value
Definition array.h:568
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)
grow array to target size
Definition array.h:545
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)
Definition array.h:1006
size_t size() const
Definition array.h:1699
void CopyRange(TYPE *to, TYPE *from, SizeT num)
copy range
Definition array.h:674
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)
move range
Definition array.h:696
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
const TYPE * ConstIterator
Definition array.h:64
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
Implements a fixed size one-dimensional array.
Definition fixedarray.h:20
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:63
TYPE * ArrayAlloc(size_t size)
Definition memory.h:27
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:209
__forceinline void MoveElements(const T *from, T *to, size_t numElements)
Move a chunk of memory, can handle overlapping regions.
Definition posixmemory.h:192
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
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:54
int SizeT
Definition types.h:49
int IndexT
Definition types.h:48