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;
256template<class TYPE,
int SMALL_VECTOR_SIZE>
268template<
class TYPE,
int SMALL_VECTOR_SIZE>
285template<
class TYPE,
int SMALL_VECTOR_SIZE>
288 capacity(SMALL_VECTOR_SIZE),
290 elements(stackElements.data())
297 this->
GrowTo(initialSize);
298 this->
count = initialSize;
300 for (i = 0; i < initialSize; i++)
309template<
class TYPE,
int SMALL_VECTOR_SIZE>
312 capacity(SMALL_VECTOR_SIZE),
314 elements(stackElements.data())
316 static_assert(std::is_trivially_copyable<TYPE>::value,
"TYPE is not trivially copyable; Util::Array cannot be constructed from pointer of TYPE.");
319 const SizeT bytes = num *
sizeof(TYPE);
326template<
class TYPE,
int SMALL_VECTOR_SIZE>
329 capacity(SMALL_VECTOR_SIZE),
331 elements(stackElements.data())
336 for (i = 0; i < this->
count; i++)
338 this->
elements[i] = list.begin()[i];
345template<
class TYPE,
int SMALL_VECTOR_SIZE>
348 capacity(SMALL_VECTOR_SIZE),
350 elements(stackElements.data())
357template<
class TYPE,
int SMALL_VECTOR_SIZE>
360 capacity(SMALL_VECTOR_SIZE),
362 elements(this->stackElements.data())
370template<
class TYPE,
int SMALL_VECTOR_SIZE>
373 capacity(rhs.capacity),
375 elements(this->stackElements.data())
378 if (rhs.capacity <= SMALL_VECTOR_SIZE)
380 for (
IndexT i = 0; i < rhs.capacity; i++)
381 this->elements[i] = rhs.elements[i];
386 this->elements = rhs.elements;
387 rhs.elements = rhs.stackElements.data();
390 rhs.capacity = SMALL_VECTOR_SIZE;
396template<
class TYPE,
int SMALL_VECTOR_SIZE>
400 #if NEBULA_BOUNDSCHECKS
402 n_assert(this->stackElements.data() == this->elements);
406 this->grow = src.
grow;
407 this->count = src.
count;
409 for (i = 0; i < this->count; i++)
411 this->elements[i] = src.
elements[i];
418template<
class TYPE,
int SMALL_VECTOR_SIZE>
424 if (this->capacity > 0)
426 if (this->elements != this->stackElements.data())
428 ArrayFree(this->capacity, this->elements);
433 this->DestroyRange(0, this->count);
436 this->elements = this->stackElements.data();
438 this->capacity = SMALL_VECTOR_SIZE;
444template<
class TYPE,
int SMALL_VECTOR_SIZE>
void
453template<
class TYPE,
int SMALL_VECTOR_SIZE>
462template<
class TYPE,
int SMALL_VECTOR_SIZE>
void
467 this->capacity = _capacity;
468 this->count = _capacity;
469 if (this->capacity > 0)
471 this->GrowTo(this->capacity);
482template<
class TYPE,
int SMALL_VECTOR_SIZE>
void
487 if ((this->capacity > 0) && (rhs.
count <= this->capacity))
493 if (rhs.
count < this->count)
495 this->DestroyRange(rhs.
count, this->count);
497 this->grow = rhs.
grow;
498 this->count = rhs.
count;
512template<
class TYPE,
int SMALL_VECTOR_SIZE>
void
520 if (rhs.elements != rhs.stackElements.data())
522 this->elements = rhs.elements;
523 rhs.elements =
nullptr;
528 this->MoveRange(this->elements, rhs.elements, rhs.count);
531 this->grow = rhs.grow;
532 this->count = rhs.count;
533 this->capacity = rhs.capacity;
542template<
class TYPE,
int SMALL_VECTOR_SIZE>
void
545 if (newCapacity > SMALL_VECTOR_SIZE)
547 TYPE* newArray = ArrayAlloc<TYPE>(newCapacity);
550 this->MoveRange(newArray, this->elements, this->count);
553 if (this->elements != this->stackElements.data())
554 ArrayFree(this->capacity, this->elements);
556 this->elements = newArray;
557 this->capacity = newCapacity;
564template<
class TYPE,
int SMALL_VECTOR_SIZE>
568 #if NEBULA_BOUNDSCHECKS
573 if (0 == this->capacity)
575 growToSize = this->grow;
580 SizeT growBy = this->capacity >> 1;
583 growBy = MinGrowSize;
585 else if (growBy > MaxGrowSize)
587 growBy = MaxGrowSize;
589 growToSize = this->capacity + growBy;
591 this->GrowTo(growToSize);
599template<
class TYPE,
int SMALL_VECTOR_SIZE>
603 #if NEBULA_BOUNDSCHECKS
609 if (fromIndex == toIndex)
615 SizeT num = this->count - fromIndex;
618 SizeT neededSize = toIndex + num;
619 while (neededSize > this->capacity)
624 if (fromIndex > toIndex)
627 this->MoveRange(&this->elements[toIndex], &this->elements[fromIndex], num);
628 this->DestroyRange(fromIndex + num - 1, this->count);
634 for (i = num - 1; i >= 0; --i)
636 this->elements[toIndex + i] = this->elements[fromIndex + i];
640 this->DestroyRange(fromIndex, toIndex);
644 this->count = toIndex + num;
650template<
class TYPE,
int SMALL_VECTOR_SIZE>
654 if constexpr (!std::is_trivially_destructible<TYPE>::value)
656 for (
IndexT i = fromIndex; i < toIndex; i++)
658 this->Destroy(&(this->elements[i]));
663 Memory::Clear((
void*)&this->elements[fromIndex],
sizeof(TYPE) * (toIndex - fromIndex));
670template<
class TYPE,
int SMALL_VECTOR_SIZE>
675 if constexpr (!std::is_trivially_copyable<TYPE>::value)
678 for (i = 0; i < num; i++)
692template<
class TYPE,
int SMALL_VECTOR_SIZE>
697 if constexpr (!std::is_trivially_move_assignable<TYPE>::value && std::is_move_assignable<TYPE>::value)
700 for (i = 0; i < num; i++)
702 to[i] = std::move(from[i]);
714template<
class TYPE,
int SMALL_VECTOR_SIZE>
718#if NEBULA_BOUNDSCHECKS
719 n_assert(this->elements !=
nullptr);
722 return this->elements[index];
728template<
class TYPE,
int SMALL_VECTOR_SIZE>
733 if (this->count == this->capacity)
737 #if NEBULA_BOUNDSCHECKS
740 this->elements[this->count++] = elm;
746template<
class TYPE,
int SMALL_VECTOR_SIZE>
751 if (this->count == this->capacity)
755#if NEBULA_BOUNDSCHECKS
758 this->elements[this->count++] = std::move(elm);
764template<
class TYPE,
int SMALL_VECTOR_SIZE>
768 SizeT neededCapacity = this->count + rhs.
count;
769 if (neededCapacity > this->capacity)
771 this->GrowTo(neededCapacity);
776 for (i = 0; i < rhs.
count; i++)
778 this->elements[this->count + i] = rhs.
elements[i];
780 this->count += rhs.
count;
786template<
class TYPE,
int SMALL_VECTOR_SIZE>
790 SizeT neededCapacity = this->count + count;
791 if (neededCapacity > this->capacity)
793 this->GrowTo(neededCapacity);
798 for (i = 0; i < count; i++)
800 this->elements[this->count + i] = arr[i];
802 this->count += count;
808template<
class TYPE,
int SMALL_VECTOR_SIZE>
813 if (this->count == this->capacity)
817#if NEBULA_BOUNDSCHECKS
820 this->elements[this->count] = TYPE();
821 return this->elements[this->count++];
827template<
class TYPE,
int SMALL_VECTOR_SIZE>
831 SizeT neededCapacity = this->count + count;
832 if (neededCapacity > this->capacity)
834 this->GrowTo(neededCapacity);
839 for (i = 0; i < count; i++)
841 this->elements[this->count + i] = TYPE();
843 TYPE* first = this->elements[this->count];
844 this->count += count;
858template<
class TYPE,
int SMALL_VECTOR_SIZE>
862#if NEBULA_BOUNDSCHECKS
866 SizeT neededCapacity = this->count + num;
867 if (neededCapacity > this->capacity)
869 this->GrowTo(neededCapacity);
876template<
class TYPE,
int SMALL_VECTOR_SIZE>
886template<
class TYPE,
int SMALL_VECTOR_SIZE>
890 return this->count *
sizeof(TYPE);
896template<
class TYPE,
int SMALL_VECTOR_SIZE>
900 return this->capacity;
908template<
class TYPE,
int SMALL_VECTOR_SIZE>
912 #if NEBULA_BOUNDSCHECKS
913 n_assert(this->elements && (index < this->count) && (index >= 0));
915 return this->elements[index];
923template<
class TYPE,
int SMALL_VECTOR_SIZE>
927#if NEBULA_BOUNDSCHECKS
928 n_assert(this->elements && (index < this->count) && (index >= 0));
930 return this->elements[index];
938template<
class TYPE,
int SMALL_VECTOR_SIZE>
942 if (rhs.
Size() == this->Size())
945 SizeT num = this->Size();
946 for (i = 0; i < num; i++)
948 if (!(this->elements[i] == rhs.
elements[i]))
966template<
class TYPE,
int SMALL_VECTOR_SIZE>
970 return !(*
this == rhs);
976template<
class TYPE,
int SMALL_VECTOR_SIZE>
980 #if NEBULA_BOUNDSCHECKS
981 n_assert(this->elements && (this->count > 0));
983 return this->elements[0];
989template<
class TYPE,
int SMALL_VECTOR_SIZE>
993 #if NEBULA_BOUNDSCHECKS
994 n_assert(this->elements && (this->count > 0));
996 return this->elements[this->count - 1];
1002template<
class TYPE,
int SMALL_VECTOR_SIZE>
1012template<
class TYPE,
int SMALL_VECTOR_SIZE>
1016 return (this->count == 0);
1022template<
class TYPE,
int SMALL_VECTOR_SIZE>
1026 return this->elements && (index < this->count) && (index >= 0);
1032template<
class TYPE,
int SMALL_VECTOR_SIZE>
1036 #if NEBULA_BOUNDSCHECKS
1037 n_assert(this->elements && (index < this->count) && (index >= 0));
1039 if (index == (this->count - 1))
1046 this->Move(index + 1, index);
1054template<
class TYPE,
int SMALL_VECTOR_SIZE>
1058 #if NEBULA_BOUNDSCHECKS
1059 n_assert(this->elements && (index < this->count) && (index >= 0));
1063 IndexT lastElementIndex = this->count - 1;
1064 if (index < lastElementIndex)
1066 if constexpr (!std::is_trivially_move_assignable<TYPE>::value)
1067 this->elements[index] = std::move(this->elements[lastElementIndex]);
1069 this->elements[index] = this->elements[lastElementIndex];
1077template<
class TYPE,
int SMALL_VECTOR_SIZE>
1081 #if NEBULA_BOUNDSCHECKS
1082 n_assert(this->elements && (iter >= this->elements) && (iter < (this->elements + this->count)));
1084 this->EraseIndex(
IndexT(iter - this->elements));
1092template<
class TYPE,
int SMALL_VECTOR_SIZE>
1096 #if NEBULA_BOUNDSCHECKS
1097 n_assert(this->elements && (iter >= this->elements) && (iter < (this->elements + this->count)));
1099 this->EraseIndexSwap(
IndexT(iter - this->elements));
1106template<
class TYPE,
int SMALL_VECTOR_SIZE>
1113 this->EraseIndex(start);
1117 this->DestroyRange(start, end);
1118 SizeT numMove = this->count - end;
1119 this->MoveRange(&this->elements[start], &this->elements[end], numMove);
1120 this->count -= end - start;
1127template<
class TYPE,
int SMALL_VECTOR_SIZE>
1132 if constexpr (!std::is_trivially_destructible<TYPE>::value)
1133 this->Destroy(&(this->elements[this->count - 1]));
1140template<
class TYPE,
int SMALL_VECTOR_SIZE>
1144 this->EraseIndex(0);
1150template<
class TYPE,
int SMALL_VECTOR_SIZE>
1154#if NEBULA_BOUNDSCHECKS
1157 TYPE ret = std::move(this->elements[0]);
1158 this->EraseIndex(0);
1165template<
class TYPE,
int SMALL_VECTOR_SIZE>
1169#if NEBULA_BOUNDSCHECKS
1173 return std::move(this->elements[this->count]);
1179template<
class TYPE,
int SMALL_VECTOR_SIZE>
1183 #if NEBULA_BOUNDSCHECKS
1184 n_assert(index <= this->count && (index >= 0));
1186 if (index == this->count)
1193 this->Move(index, index + 1);
1194 this->elements[index] = elm;
1203template<
class TYPE,
int SMALL_VECTOR_SIZE>
1207 if (this->count > 0)
1209 this->DestroyRange(0, this->count);
1219template<
class TYPE,
int SMALL_VECTOR_SIZE>
1230template<
class TYPE,
int SMALL_VECTOR_SIZE>
1241template<
class TYPE,
int SMALL_VECTOR_SIZE>
1245 return this->elements;
1251template<
class TYPE,
int SMALL_VECTOR_SIZE>
1261template<
class TYPE,
int SMALL_VECTOR_SIZE>
1265 return this->elements + this->count;
1271template<
class TYPE,
int SMALL_VECTOR_SIZE>
1286template<
class TYPE,
int SMALL_VECTOR_SIZE>
1292 for (index = start; index < this->count; index++)
1294 if (this->elements[index] == elm)
1296 return &(this->elements[index]);
1310template<
class TYPE,
int SMALL_VECTOR_SIZE>
1316 for (index = start; index < this->count; index++)
1318 if (this->elements[index] == elm)
1329template<
class TYPE,
int SMALL_VECTOR_SIZE>
1330template<
typename ...ELEM_TYPE>
1335 const int size =
sizeof...(elements) + 1;
1336 this->Reserve(size);
1337 TYPE res[size] = { first, elements... };
1338 for (
IndexT i = 0; i < size; i++)
1340 this->elements[this->count++] = res[i];
1359template<
class TYPE,
int SMALL_VECTOR_SIZE>
1360template<
typename KEYTYPE>
1366 for (index = start; index < this->count; index++)
1368 if (this->elements[index] == elm)
1385template<
class TYPE,
int SMALL_VECTOR_SIZE>
1389 if ((first + num) > this->count)
1391 this->GrowTo(first + num);
1392 this->count = first + num;
1396 for (i = first; i < (first + num); i++)
1398 this->elements[i] = elm;
1409template<
class TYPE,
int SMALL_VECTOR_SIZE>
1416 for (i = 0; i < num; i++)
1418 if (0 == this->Find(rhs[i]))
1430template<
class TYPE,
int SMALL_VECTOR_SIZE>
1434 std::sort(this->Begin(), this->End());
1441template <
class TYPE,
int SMALL_VECTOR_SIZE>
1449 [](
const void* a,
const void* b)
1451 TYPE arg1 = *
static_cast<const TYPE*
>(a);
1452 TYPE arg2 = *
static_cast<const TYPE*
>(b);
1453 return (arg1 > arg2) - (arg1 < arg2);
1461template<
class TYPE,
int SMALL_VECTOR_SIZE>
1465 std::sort(this->Begin(), this->End(), func);
1471template <
class TYPE,
int SMALL_VECTOR_SIZE>
1488template<
class TYPE,
int SMALL_VECTOR_SIZE>
1492 SizeT num = this->Size();
1501 if (0 != (
half = num/2))
1503 mid = lo + ((num & 1) ?
half : (
half - 1));
1504 if (elm < this->elements[mid])
1509 else if (elm > this->elements[mid])
1521 if (elm != this->elements[lo])
1548template<
class TYPE,
int SMALL_VECTOR_SIZE>
1549template<
typename KEYTYPE>
inline IndexT
1552 SizeT num = this->Size();
1561 if (0 != (
half = num / 2))
1563 mid = lo + ((num & 1) ?
half : (
half - 1));
1564 if (this->elements[mid] > elm)
1569 else if (this->elements[mid] < elm)
1581 if (this->elements[lo] != elm)
1602template<
class TYPE,
int SMALL_VECTOR_SIZE>
1606 if (num < this->count)
1608 this->DestroyRange(num, this->count);
1610 else if (num > this->capacity)
1621template<
class TYPE,
int SMALL_VECTOR_SIZE>
1622template<
typename ...ARGS>
1625 if (num < this->count)
1627 this->DestroyRange(num, this->count);
1629 else if (num > this->capacity)
1631 SizeT oldCapacity = this->capacity;
1633 for (
IndexT i = oldCapacity; i < this->capacity; i++)
1634 this->elements[i] = TYPE(args...);
1643template<
class TYPE,
int SMALL_VECTOR_SIZE>
1646 if (num > this->capacity)
1656template<
class TYPE,
int SMALL_VECTOR_SIZE>
1666template<
class TYPE,
int SMALL_VECTOR_SIZE>
1670 TYPE* newArray = ArrayAlloc<TYPE>(this->count);
1673 this->MoveRange(newArray, this->elements, this->count);
1674 if (this->elements != this->stackElements.data())
1675 ArrayFree(this->capacity, this->elements);
1677 this->elements = newArray;
1679 this->capacity = this->count;
1685template<
class TYPE,
int SMALL_VECTOR_SIZE>
1686inline constexpr SizeT
1689 return sizeof(TYPE);
1695template<
class TYPE,
int SMALL_VECTOR_SIZE>
1706template<
class TYPE,
int SMALL_VECTOR_SIZE>
1710 return this->elements;
1716template<
class TYPE,
int SMALL_VECTOR_SIZE>
1720 return this->elements + this->count;
1726template<
class TYPE,
int SMALL_VECTOR_SIZE>
1730 if (
static_cast<SizeT>(s) > this->capacity)
1732 this->GrowTo(
static_cast<SizeT>(s));
1734 this->count =
static_cast<SizeT>(s);
1743template<
class TYPE,
int SMALL_VECTOR_SIZE>
1747 if (this->count > 1)
1750 for (i = 0; i < this->count - 1; i++)
1752 if (this->elements[i] > this->elements[i + 1])
1767template<
class TYPE,
int SMALL_VECTOR_SIZE>
1771 IndexT i = startIndex + 1;
1772 for (; i < this->count; i++)
1774 if (this->elements[i] != elm)
1776 this->Insert(i, elm);
1783 return (this->Size() - 1);
1791template<
class TYPE,
int SMALL_VECTOR_SIZE>
1795 SizeT num = this->Size();
1800 return this->Size() - 1;
1810 if (0 != (
half = num/2))
1812 mid = lo + ((num & 1) ?
half : (
half - 1));
1813 if (elm < this->elements[mid])
1818 else if (elm > this->elements[mid])
1827 return this->InsertAtEndOfIdenticalRange(mid, elm);
1832 if (elm < this->elements[lo])
1834 this->Insert(lo, elm);
1837 else if (elm > this->elements[lo])
1839 this->Insert(lo + 1, elm);
1846 return this->InsertAtEndOfIdenticalRange(lo, elm);
1851 #if NEBULA_BOUNDSCHECKS
1854 this->Insert(lo, elm);
1858 if (elm < this->elements[lo])
1860 this->Insert(lo, elm);
1863 else if (elm > this->elements[lo])
1865 this->Insert(lo + 1, elm);
1874 n_error(
"Array::InsertSorted: Can't happen!");
1878template<
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:346
void Move(IndexT fromIndex, IndexT toIndex)
move elements, grows array if needed
Definition array.h:601
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:1644
Array(SizeT initialCapacity, SizeT initialGrow)
constuctor with initial size and grow size
Definition array.h:269
void Reserve(SizeT num)
increase capacity to fit N more elements into the array.
Definition array.h:860
void Fill(IndexT first, SizeT num, const TYPE &elm)
fill array range with element
Definition array.h:1387
IndexT FindIndex(const TYPE &elm, const IndexT start=0) const
find identical element in array, return index, InvalidIndex if not found
Definition array.h:1312
void Destroy(TYPE *elm)
destroy an element (call destructor without freeing memory)
Definition array.h:445
Iterator End() const
return iterator to end of array
Definition array.h:1263
SizeT capacity
Definition array.h:246
SizeT count
Definition array.h:247
TYPE * EmplaceArray(const SizeT count)
Emplace range of items and return pointer to first.
Definition array.h:829
~Array()
destructor
Definition array.h:454
Iterator Find(const TYPE &elm, const IndexT start=0) const
find identical element in array, return iterator
Definition array.h:1288
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:1362
bool operator!=(const Array< TYPE, SMALL_VECTOR_SIZE > &rhs) const
inequality operator
Definition array.h:968
TYPE * Iterator
define iterator
Definition array.h:63
void EraseFront()
erase front
Definition array.h:1142
TYPE & Back() const
return reference to last element
Definition array.h:991
void Copy(const Array< TYPE, SMALL_VECTOR_SIZE > &src)
copy content
Definition array.h:398
const SizeT Capacity() const
get overall allocated size of array in number of elements
Definition array.h:898
void Clear()
clear array (calls destructors)
Definition array.h:1205
TYPE * elements
Definition array.h:248
IndexT InsertAtEndOfIdenticalRange(IndexT startIndex, const TYPE &elm)
insert element at the first non-identical position, return index of inclusion position
Definition array.h:1769
ConstIterator ConstEnd() const
return const iterator to end of array
Definition array.h:1273
constexpr SizeT TypeSize() const
Returns sizeof(TYPE)
Definition array.h:1687
Array(std::initializer_list< TYPE > list)
constructor from initializer list
Definition array.h:327
void EraseRange(IndexT start, IndexT end)
erase range, excluding the element at end
Definition array.h:1108
IndexT BinarySearchIndex(typename std::enable_if< true, const KEYTYPE & >::type elm) const
do a binary search using a specific key type
Definition array.h:1550
void Sort()
sort the array
Definition array.h:1432
SizeT grow
Definition array.h:245
void operator=(Array< TYPE, SMALL_VECTOR_SIZE > &&rhs) noexcept
move operator
Definition array.h:513
void QuickSort()
quick sort the array
Definition array.h:1443
void Delete()
delete content
Definition array.h:420
void Append(TYPE &&elm)
append an element which is being forwarded
Definition array.h:748
void DestroyRange(IndexT fromIndex, IndexT toIndex)
destroy range of elements
Definition array.h:652
Iterator end() const
Definition array.h:1718
TYPE & operator[](IndexT index) const
[] operator
Definition array.h:910
static const SizeT MinGrowSize
Definition array.h:243
Array(ArrayT &&rhs) noexcept
move constructor
Definition array.h:371
void SortWithFunc(bool(*func)(const TYPE &lhs, const TYPE &rhs))
sort with custom function
Definition array.h:1463
void Append(const TYPE &first, const ELEM_TYPE &... elements)
Append multiple elements to the end of the array.
Definition array.h:1332
TYPE & operator[](IndexT index)
[] operator
Definition array.h:925
Iterator begin() const
for range-based iteration
Definition array.h:1708
Iterator EraseSwap(Iterator iter)
erase element at iterator, fill gap by swapping in last element, destroys sorting!
Definition array.h:1094
TYPE & Emplace()
Emplace item (create new item and return reference)
Definition array.h:810
Array(const TYPE *const buf, SizeT num)
constructor from TYPE pointer and size.
Definition array.h:310
void Reset()
reset array (does NOT call destructors)
Definition array.h:1221
void Realloc(SizeT capacity, SizeT grow)
clear contents and preallocate with new attributes
Definition array.h:463
T As() const
convert to "anything"
bool IsEmpty() const
return true if array empty
Definition array.h:1014
IndexT InsertSorted(const TYPE &elm)
insert element into sorted array, return index where element was included
Definition array.h:1793
void AppendArray(const Array< TYPE, SMALL_VECTOR_SIZE > &rhs)
append the contents of an array to this array
Definition array.h:766
void Grow()
grow array with grow value
Definition array.h:566
void EraseIndex(IndexT index)
erase element at index, keep sorting intact
Definition array.h:1034
static const SizeT MaxGrowSize
Definition array.h:244
const SizeT ByteSize() const
return the byte size of the array.
Definition array.h:888
void EraseIndexSwap(IndexT index)
erase element at index, fill gap by swapping in last element, destroys sorting!
Definition array.h:1056
TYPE PopFront()
Pop front.
Definition array.h:1152
ConstIterator ConstBegin() const
return const iterator to beginning of array
Definition array.h:1253
_smallvector< TYPE, SMALL_VECTOR_SIZE > stackElements
Definition array.h:250
void resize(size_t size)
Definition array.h:1728
Array(SizeT initialSize, SizeT initialGrow, const TYPE &initialValue)
constructor with initial size, grow size and initial values
Definition array.h:286
void operator=(const Array< TYPE, SMALL_VECTOR_SIZE > &rhs)
assignment operator
Definition array.h:483
void Append(const TYPE &elm)
append element to end of array
Definition array.h:730
void GrowTo(SizeT newCapacity)
grow array to target size
Definition array.h:543
TYPE & Get(IndexT index) const
Get element (same as operator[] but as a function)
Definition array.h:716
void Insert(IndexT index, const TYPE &elm)
insert element before element at index
Definition array.h:1181
void push_back(const TYPE &item)
Definition array.h:1004
size_t size() const
Definition array.h:1697
void CopyRange(TYPE *to, TYPE *from, SizeT num)
copy range
Definition array.h:672
void Resize(SizeT num, ARGS... args)
Resize and fill new elements with arguments.
Definition array.h:1623
bool operator==(const Array< TYPE, SMALL_VECTOR_SIZE > &rhs) const
equality operator
Definition array.h:940
ArrayT Difference(const Array< TYPE, SMALL_VECTOR_SIZE > &rhs)
returns new array with elements which are not in rhs (slow!)
Definition array.h:1411
void EraseBack()
erase back
Definition array.h:1129
bool IsValidIndex(IndexT index) const
check if index is valid
Definition array.h:1024
Iterator Begin() const
return iterator to beginning of array
Definition array.h:1243
bool IsSorted() const
test if the array is sorted, this is a slow operation!
Definition array.h:1745
IndexT BinarySearchIndex(const TYPE &elm) const
do a binary search, requires a sorted array
Definition array.h:1490
void MoveRange(TYPE *to, TYPE *from, SizeT num)
move range
Definition array.h:694
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:1604
void QuickSortWithFunc(int(*func)(const void *lhs, const void *rhs))
quick sort the array
Definition array.h:1473
Array()
constructor with default parameters
Definition array.h:257
void Free()
free memory and reset size
Definition array.h:1232
const SizeT Size() const
get number of elements in array
Definition array.h:878
void AppendArray(const TYPE *arr, const SizeT count)
append from C array
Definition array.h:788
void clear() noexcept
Definition array.h:1658
TYPE & Front() const
return reference to first element
Definition array.h:978
TYPE PopBack()
Pop back.
Definition array.h:1167
Iterator Erase(Iterator iter)
erase element pointed to by iterator, keep sorting intact
Definition array.h:1079
void Fit()
Fit the size of the array to the amount of elements.
Definition array.h:1668
Array(const ArrayT &rhs)
copy constructor
Definition array.h:358
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:45
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:208
__forceinline void MoveElements(const T *from, T *to, size_t numElements)
Move a chunk of memory, can handle overlapping regions.
Definition posixmemory.h:191
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