53 template<
typename T> T
As()
const;
56 template <
typename ...ELEM_TYPE>
59 void Append(
const TYPE& elm);
115 template <
typename KEYTYPE>
IndexT FindIndex(
typename std::enable_if<true, const KEYTYPE&>::type elm)
const;
125 void SortWithFunc(
bool (*func)(
const TYPE& lhs,
const TYPE& rhs));
129 template <
typename KEYTYPE>
IndexT BinarySearchIndex(
typename std::enable_if<true, const KEYTYPE&>::type elm)
const;
143 void Reset(TYPE* elm);
167template<
class TYPE,
int STACK_SIZE>
180template<
class TYPE,
int STACK_SIZE>
210template<
class TYPE,
int STACK_SIZE>
231 for (i = 0; i < this->
capacity; i++)
246template<
class TYPE,
int STACK_SIZE>
263 for (i = 0; i < this->
count; i++)
265 this->
elements[i] = list.begin()[i];
278template<
class TYPE,
int STACK_SIZE>
291template<
class TYPE,
int STACK_SIZE>
295 this->
count = rhs.count;
296 this->
grow = rhs.grow;
300 for (
IndexT i = 0; i < rhs.count; ++i)
312 rhs.elements =
nullptr;
318template<
class TYPE,
int STACK_SIZE>
void
321 #if NEBULA_BOUNDSCHECKS
337 for (i = 0; i < this->
count; i++)
347template<
class TYPE,
int STACK_SIZE>
void
365template<
class TYPE,
int STACK_SIZE>
void
374template<
class TYPE,
int STACK_SIZE>
void
377 if constexpr (!std::is_trivially_destructible<TYPE>::value)
380 ::new ((
void*)elm) TYPE();
387template<
class TYPE,
int STACK_SIZE>
396template<
class TYPE,
int STACK_SIZE>
void
402 this->
count = _capacity;
419template<
class TYPE,
int STACK_SIZE>
void
429 for (i = 0; i < rhs.
count; i++)
435 for (; i < this->
count; i++)
440 this->count = rhs.
count;
454template<
class TYPE,
int STACK_SIZE>
467 this->
count = rhs.count;
468 this->
grow = rhs.grow;
472 for (
IndexT i = 0; i < rhs.count; ++i)
486 rhs.elements =
nullptr;
492template<
class TYPE,
int STACK_SIZE>
void
495 if (newCapacity > STACK_SIZE)
497 TYPE* newArray =
new TYPE[newCapacity];
502 for (i = 0; i < this->
count; i++)
520template<
class TYPE,
int STACK_SIZE>
void
523 #if NEBULA_BOUNDSCHECKS
530 growToSize = this->
grow;
544 growToSize = this->
capacity + growBy;
554template<
class TYPE,
int STACK_SIZE>
void
557 #if NEBULA_BOUNDSCHECKS
563 if (fromIndex == toIndex)
569 SizeT num = this->count - fromIndex;
572 SizeT neededSize = toIndex + num;
578 if (fromIndex > toIndex)
582 for (i = 0; i < num; i++)
588 for (i = (fromIndex + i) - 1; i < this->count; i++)
597 for (i = num - 1; i >= 0; --i)
603 for (i =
int(fromIndex); i < int(toIndex); i++)
610 this->count = toIndex + num;
616template<
class TYPE,
int STACK_SIZE>
void
624 #if NEBULA_BOUNDSCHECKS
633template<
class TYPE,
int STACK_SIZE>
inline void
641#if NEBULA_BOUNDSCHECKS
650template<
class TYPE,
int STACK_SIZE>
void
654 if (neededCapacity > this->
capacity)
656 this->
GrowTo(neededCapacity);
661 for (i = 0; i < rhs.
count; i++)
671template<
class TYPE,
int STACK_SIZE>
void
675 if (neededCapacity > this->
capacity)
677 this->
GrowTo(neededCapacity);
682 for (i = 0; i <
count; i++)
684 this->
elements[this->count + i] = arr[i];
686 this->count +=
count;
699template<
class TYPE,
int STACK_SIZE>
void
702 #if NEBULA_BOUNDSCHECKS
706 if (neededCapacity > this->
capacity)
708 this->
GrowTo(neededCapacity);
715template<
class TYPE,
int STACK_SIZE>
const SizeT
724template<
class TYPE,
int STACK_SIZE>
size_t
733template<
class TYPE,
int STACK_SIZE>
void
742template<
class TYPE,
int STACK_SIZE>
const SizeT
745 return this->
count *
sizeof(TYPE);
751template<
class TYPE,
int STACK_SIZE>
const SizeT
762template<
class TYPE,
int STACK_SIZE> TYPE&
765 #if NEBULA_BOUNDSCHECKS
776template<
class TYPE,
int STACK_SIZE>
bool
779 if (rhs.
Size() == this->Size())
783 for (i = 0; i < num; i++)
803template<
class TYPE,
int STACK_SIZE>
bool
806 return !(*
this == rhs);
812template<
class TYPE,
int STACK_SIZE> TYPE&
815 #if NEBULA_BOUNDSCHECKS
824template<
class TYPE,
int STACK_SIZE> TYPE&
827 #if NEBULA_BOUNDSCHECKS
836template<
class TYPE,
int STACK_SIZE>
bool
839 return (this->
count == 0);
845template<
class TYPE,
int STACK_SIZE>
void
848 #if NEBULA_BOUNDSCHECKS
851 if (index == (this->count - 1))
858 this->
Move(index + 1, index);
866template<
class TYPE,
int STACK_SIZE>
void
869 #if NEBULA_BOUNDSCHECKS
874 IndexT lastElementIndex = this->count - 1;
875 if (index < lastElementIndex)
893 #if NEBULA_BOUNDSCHECKS
907 #if NEBULA_BOUNDSCHECKS
917template<
class TYPE,
int STACK_SIZE>
void
928template<
class TYPE,
int STACK_SIZE>
void
937template<
class TYPE,
int STACK_SIZE>
void
940 #if NEBULA_BOUNDSCHECKS
943 if (index == this->count)
950 this->
Move(index, index + 1);
960template<
class TYPE,
int STACK_SIZE>
void
964 for (i = 0; i < this->
count; i++)
976template<
class TYPE,
int STACK_SIZE>
void
986template<
class TYPE,
int STACK_SIZE>
void
1023 for (index = 0; index < this->
count; index++)
1041template<
class TYPE,
int STACK_SIZE>
IndexT
1045 for (index = 0; index < this->
count; index++)
1058template<
class TYPE,
int STACK_SIZE>
1059template<
typename ...ELEM_TYPE>
1083template<
class TYPE,
int STACK_SIZE>
1084template<
typename KEYTYPE>
inline IndexT
1088 for (index = 0; index < this->
count; index++)
1108template<
class TYPE,
int STACK_SIZE>
void
1111 if ((first + num) > this->
count)
1113 this->
GrowTo(first + num);
1114 this->
count = first + num;
1117 for (i = first; i < (first + num); i++)
1136 for (i = 0; i < num; i++)
1138 if (0 == this->
Find(rhs[i]))
1150template<
class TYPE,
int STACK_SIZE>
void
1153 std::sort(this->
Begin(), this->
End());
1159template<
class TYPE,
int STACK_SIZE>
void
1162 std::sort(this->
Begin(), this->
End(), func);
1170template<
class TYPE,
int STACK_SIZE>
IndexT
1182 if (0 != (
half = num/2))
1184 mid = lo + ((num & 1) ?
half : (
half - 1));
1190 else if (elm > this->
elements[mid])
1229template<
class TYPE,
int STACK_SIZE>
1230template<
typename KEYTYPE>
inline IndexT
1242 if (0 != (
half = num / 2))
1244 mid = lo + ((num & 1) ?
half : (
half - 1));
1250 else if (this->
elements[mid] < elm)
1284template<
class TYPE,
int STACK_SIZE>
1313template<
class TYPE,
int STACK_SIZE>
bool
1316 if (this->
count > 1)
1319 for (i = 0; i < this->
count - 1; i++)
1336template<
class TYPE,
int STACK_SIZE>
IndexT
1339 IndexT i = startIndex + 1;
1340 for (; i < this->
count; i++)
1351 return (this->
Size() - 1);
1359template<
class TYPE,
int STACK_SIZE>
IndexT
1367 return this->
Size() - 1;
1377 if (0 != (
half = num/2))
1379 mid = lo + ((num & 1) ?
half : (
half - 1));
1385 else if (elm > this->
elements[mid])
1406 this->
Insert(lo + 1, elm);
1418 #if NEBULA_BOUNDSCHECKS
1432 this->
Insert(lo + 1, elm);
1441 n_error(
"Array::InsertSorted: Can't happen!");
Nebula's small vector optimized array.
Definition arraystack.h:22
bool IsSorted() const
test if the array is sorted, this is a slow operation!
Definition arraystack.h:1314
static const SizeT MinGrowSize
Definition arraystack.h:155
void Destroy(TYPE *elm)
destroy an element (call destructor without freeing memory)
Definition arraystack.h:366
SizeT capacity
Definition arraystack.h:158
void Fill(IndexT first, SizeT num, const TYPE &elm)
fill array range with element
Definition arraystack.h:1109
TYPE & operator[](IndexT index) const
[] operator
Definition arraystack.h:763
Iterator Find(const TYPE &elm) const
find identical element in array, return iterator
Definition arraystack.h:1020
void Realloc(SizeT capacity, SizeT grow)
clear contents and preallocate with new attributes
Definition arraystack.h:397
void Free()
free memory and reset size
Definition arraystack.h:987
void EraseFront()
erase first element
Definition arraystack.h:929
SizeT grow
Definition arraystack.h:157
void GrowTo(SizeT newCapacity)
grow array to target size
Definition arraystack.h:493
void operator=(const ArrayStack< TYPE, STACK_SIZE > &rhs)
assignment operator
Definition arraystack.h:420
static const SizeT MaxGrowSize
Definition arraystack.h:156
void Append(const TYPE &first, const ELEM_TYPE &... elements)
Append multiple elements to the end of the array.
Definition arraystack.h:1061
IndexT InsertSorted(const TYPE &elm)
insert element into sorted array, return index where element was included
Definition arraystack.h:1360
Iterator EraseSwap(Iterator iter)
erase element at iterator, fill gap by swapping in last element, destroys sorting!
Definition arraystack.h:905
ArrayStack()
constructor with default parameters
Definition arraystack.h:168
void push_back(const TYPE &item)
Definition arraystack.h:734
void Copy(const ArrayStack< TYPE, STACK_SIZE > &src)
copy content
Definition arraystack.h:319
IndexT BinarySearchIndex(const TYPE &elm) const
do a binary search, requires a sorted array
Definition arraystack.h:1171
void SortWithFunc(bool(*func)(const TYPE &lhs, const TYPE &rhs))
sort with custom function
Definition arraystack.h:1160
void AppendArray(const ArrayStack< TYPE, STACK_SIZE > &rhs)
append the contents of an array to this array
Definition arraystack.h:651
Iterator begin() const
for range-based iteration
Definition arraystack.h:1294
void EraseIndex(IndexT index)
erase element at index, keep sorting intact
Definition arraystack.h:846
SizeT count
Definition arraystack.h:159
bool operator!=(const ArrayStack< TYPE, STACK_SIZE > &rhs) const
inequality operator
Definition arraystack.h:804
bool IsEmpty() const
return true if array empty
Definition arraystack.h:837
TYPE * elements
Definition arraystack.h:161
ArrayStack< TYPE, STACK_SIZE > Difference(const ArrayStack< TYPE, STACK_SIZE > &rhs)
returns new array with elements which are not in rhs (slow!)
Definition arraystack.h:1131
void Reserve(SizeT num)
increase capacity to fit N more elements into the array
Definition arraystack.h:700
IndexT InsertAtEndOfIdenticalRange(IndexT startIndex, const TYPE &elm)
insert element at the first non-identical position, return index of inclusion position
Definition arraystack.h:1337
void EraseBack()
erase last element
Definition arraystack.h:918
const bool IsStackUsed() const
returns true if the stack is used
Definition arraystack.h:1285
TYPE & Front() const
return reference to first element
Definition arraystack.h:813
const SizeT Capacity() const
get overall allocated size of array in number of elements
Definition arraystack.h:752
const SizeT ByteSize() const
return the byte size of the array.
Definition arraystack.h:743
void Grow()
grow array
Definition arraystack.h:521
T As() const
convert to "anything"
void Delete()
delete content
Definition arraystack.h:348
Iterator end() const
Definition arraystack.h:1303
bool operator==(const ArrayStack< TYPE, STACK_SIZE > &rhs) const
equality operator
Definition arraystack.h:777
size_t size() const
Definition arraystack.h:725
Iterator Begin() const
return iterator to beginning of array
Definition arraystack.h:997
void Move(IndexT fromIndex, IndexT toIndex)
move elements, grows array if needed
Definition arraystack.h:555
void EraseIndexSwap(IndexT index)
erase element at index, fill gap by swapping in last element, destroys sorting!
Definition arraystack.h:867
TYPE & Back() const
return reference to last element
Definition arraystack.h:825
~ArrayStack()
destructor
Definition arraystack.h:388
const SizeT Size() const
get number of elements in array
Definition arraystack.h:716
TYPE smallVector[STACK_SIZE]
Definition arraystack.h:160
TYPE * Iterator
define iterator
Definition arraystack.h:25
void Insert(IndexT index, const TYPE &elm)
insert element before element at index
Definition arraystack.h:938
IndexT FindIndex(const TYPE &elm) const
find identical element in array, return index, InvalidIndex if not found
Definition arraystack.h:1042
Iterator End() const
return iterator to end of array
Definition arraystack.h:1006
void Reset()
reset array (does NOT call destructors)
Definition arraystack.h:977
void Sort()
sort the array
Definition arraystack.h:1151
Iterator Erase(Iterator iter)
erase element pointed to by iterator, keep sorting intact
Definition arraystack.h:891
void Clear()
clear array (calls destructors)
Definition arraystack.h:961
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
A quad tree designed to return regions of free 2D space.
Definition String.cs:6
static const int InvalidIndex
Definition types.h:47
int SizeT
Definition types.h:42
int IndexT
Definition types.h:41