Nebula
Loading...
Searching...
No Matches
Util::Array< TYPE, SMALL_VECTOR_SIZE > Class Template Reference

#include <array.h>

Detailed Description

template<class TYPE, int SMALL_VECTOR_SIZE = 0>
class Util::Array< TYPE, SMALL_VECTOR_SIZE >

Nebula's dynamic array class.

This class is also used by most other collection classes.

The default constructor will not pre-allocate elements, so no space is wasted as long as no elements are added. As soon as the first element is added to the array, an initial buffer of 16 elements is created. Whenever the element buffer would overflow, a new buffer of twice the size of the previous buffer is created and the existing elements are then copied over to the new buffer. The element buffer will never shrink, the only way to reclaim unused memory is to copy the Array to a new Array object. This is usually not a problem since most arrays will oscillate around some specific size, so once the array has reached this specific size, no costly memory free or allocs will be performed.

It is possible to sort the array using the Sort() method, this uses std::sort (one of the very few exceptions where the STL is used in Nebula).

One should generally be careful with costly copy operators, the Array class (and the other container classes using Array) may do some heavy element shuffling in some situations (especially when sorting and erasing elements).

Inherited by Util::PinnedArray< MAX_ALLOCS, TYPE >, and Util::TrivialArray< TYPE >.

Public Types

typedef TYPE * Iterator
 define iterator
 
typedef const TYPE * ConstIterator
 
using ArrayT = Array<TYPE, SMALL_VECTOR_SIZE>
 

Public Member Functions

 Array ()
 constructor with default parameters
 
 Array (SizeT initialCapacity, SizeT initialGrow)
 constuctor with initial size and grow size
 
 Array (SizeT initialSize, SizeT initialGrow, const TYPE &initialValue)
 constructor with initial size, grow size and initial values
 
 Array (const ArrayT &rhs)
 copy constructor
 
 Array (ArrayT &&rhs) noexcept
 move constructor
 
 Array (std::initializer_list< TYPE > list)
 constructor from initializer list
 
 Array (std::nullptr_t)
 construct an empty fixed array
 
 Array (const TYPE *const buf, SizeT num)
 constructor from TYPE pointer and size.
 
 ~Array ()
 destructor
 
void operator= (const Array< TYPE, SMALL_VECTOR_SIZE > &rhs)
 assignment operator
 
void operator= (Array< TYPE, SMALL_VECTOR_SIZE > &&rhs) noexcept
 move operator
 
TYPE & operator[] (IndexT index) const
 [] operator
 
TYPE & operator[] (IndexT index)
 [] operator
 
bool operator== (const Array< TYPE, SMALL_VECTOR_SIZE > &rhs) const
 equality operator
 
bool operator!= (const Array< TYPE, SMALL_VECTOR_SIZE > &rhs) const
 inequality operator
 
template<typename T >
As () const
 convert to "anything"
 
TYPE & Get (IndexT index) const
 Get element (same as operator[] but as a function)
 
template<typename ... ELEM_TYPE>
void Append (const TYPE &first, const ELEM_TYPE &... elements)
 Append multiple elements to the end of the array.
 
void Append (const TYPE &elm)
 append element to end of array
 
void Append (TYPE &&elm)
 append an element which is being forwarded
 
void AppendArray (const Array< TYPE, SMALL_VECTOR_SIZE > &rhs)
 append the contents of an array to this array
 
void AppendArray (const TYPE *arr, const SizeT count)
 append from C array
 
TYPE & Emplace ()
 Emplace item (create new item and return reference)
 
TYPE * EmplaceArray (const SizeT count)
 Emplace range of items and return pointer to first.
 
void Reserve (SizeT num)
 increase capacity to fit N more elements into the array.
 
const SizeT Size () const
 get number of elements in array
 
const SizeT ByteSize () const
 return the byte size of the array.
 
const SizeT Capacity () const
 get overall allocated size of array in number of elements
 
TYPE & Front () const
 return reference to first element
 
TYPE & Back () const
 return reference to last element
 
bool IsEmpty () const
 return true if array empty
 
bool IsValidIndex (IndexT index) const
 check if index is valid
 
void EraseIndex (IndexT index)
 erase element at index, keep sorting intact
 
Iterator Erase (Iterator iter)
 erase element pointed to by iterator, keep sorting intact
 
void EraseIndexSwap (IndexT index)
 erase element at index, fill gap by swapping in last element, destroys sorting!
 
Iterator EraseSwap (Iterator iter)
 erase element at iterator, fill gap by swapping in last element, destroys sorting!
 
void EraseRange (IndexT start, IndexT end)
 erase range, excluding the element at end
 
void EraseBack ()
 erase back
 
void EraseFront ()
 erase front
 
TYPE PopFront ()
 Pop front.
 
TYPE PopBack ()
 Pop back.
 
void Insert (IndexT index, const TYPE &elm)
 insert element before element at index
 
IndexT InsertSorted (const TYPE &elm)
 insert element into sorted array, return index where element was included
 
IndexT InsertAtEndOfIdenticalRange (IndexT startIndex, const TYPE &elm)
 insert element at the first non-identical position, return index of inclusion position
 
bool IsSorted () const
 test if the array is sorted, this is a slow operation!
 
void Clear ()
 clear array (calls destructors)
 
void Reset ()
 reset array (does NOT call destructors)
 
void Free ()
 free memory and reset size
 
Iterator Begin () const
 return iterator to beginning of array
 
ConstIterator ConstBegin () const
 return const iterator to beginning of array
 
Iterator End () const
 return iterator to end of array
 
ConstIterator ConstEnd () const
 return const iterator to end of array
 
Iterator Find (const TYPE &elm, const IndexT start=0) const
 find identical element in array, return iterator
 
IndexT FindIndex (const TYPE &elm, const IndexT start=0) const
 find identical element in array, return index, InvalidIndex if not found
 
template<typename KEYTYPE >
IndexT FindIndex (typename std::enable_if< true, const KEYTYPE & >::type elm, const IndexT start=0) const
 find identical element using a specific key type
 
void Fill (IndexT first, SizeT num, const TYPE &elm)
 fill array range with element
 
void Realloc (SizeT capacity, SizeT grow)
 clear contents and preallocate with new attributes
 
ArrayT Difference (const Array< TYPE, SMALL_VECTOR_SIZE > &rhs)
 returns new array with elements which are not in rhs (slow!)
 
void Sort ()
 sort the array
 
void QuickSort ()
 quick sort the array
 
void SortWithFunc (bool(*func)(const TYPE &lhs, const TYPE &rhs))
 sort with custom function
 
void QuickSortWithFunc (int(*func)(const void *lhs, const void *rhs))
 quick sort the array
 
IndexT BinarySearchIndex (const TYPE &elm) const
 do a binary search, requires a sorted array
 
template<typename KEYTYPE >
IndexT BinarySearchIndex (typename std::enable_if< true, const KEYTYPE & >::type elm) const
 do a binary search using a specific key type
 
void Resize (SizeT num)
 Set size. Grows array if num is greater than capacity. Calls destroy on all objects at index > num!
 
template<typename ... ARGS>
void Resize (SizeT num, ARGS... args)
 Resize and fill new elements with arguments.
 
void Extend (SizeT num)
 Resize to fit the provided value, but don't shrink if the new size is smaller.
 
void Fit ()
 Fit the size of the array to the amount of elements.
 
constexpr SizeT TypeSize () const
 Returns sizeof(TYPE)
 
Iterator begin () const
 for range-based iteration
 
Iterator end () const
 
size_t size () const
 
void resize (size_t size)
 
void clear () noexcept
 
void push_back (const TYPE &item)
 
void Grow ()
 grow array with grow value
 

Protected Member Functions

void Destroy (TYPE *elm)
 destroy an element (call destructor without freeing memory)
 
void Copy (const Array< TYPE, SMALL_VECTOR_SIZE > &src)
 copy content
 
void Delete ()
 delete content
 
void GrowTo (SizeT newCapacity)
 grow array to target size
 
void Move (IndexT fromIndex, IndexT toIndex)
 move elements, grows array if needed
 
void DestroyRange (IndexT fromIndex, IndexT toIndex)
 destroy range of elements
 
void CopyRange (TYPE *to, TYPE *from, SizeT num)
 copy range
 
void MoveRange (TYPE *to, TYPE *from, SizeT num)
 move range
 

Protected Attributes

SizeT grow
 
SizeT capacity
 
SizeT count
 
TYPE * elements
 
_smallvector< TYPE, SMALL_VECTOR_SIZE > stackElements
 

Static Protected Attributes

static const SizeT MinGrowSize = 16
 
static const SizeT MaxGrowSize = 65536
 

Friends

template<class T , bool S>
class FixedArray
 

Member Typedef Documentation

◆ ArrayT

template<class TYPE , int SMALL_VECTOR_SIZE = 0>
using Util::Array< TYPE, SMALL_VECTOR_SIZE >::ArrayT = Array<TYPE, SMALL_VECTOR_SIZE>

◆ ConstIterator

template<class TYPE , int SMALL_VECTOR_SIZE = 0>
const TYPE* Util::Array< TYPE, SMALL_VECTOR_SIZE >::ConstIterator

◆ Iterator

template<class TYPE , int SMALL_VECTOR_SIZE = 0>
TYPE* Util::Array< TYPE, SMALL_VECTOR_SIZE >::Iterator

define iterator

Constructor & Destructor Documentation

◆ Array() [1/8]

template<class TYPE , int SMALL_VECTOR_SIZE>
Util::Array< TYPE, SMALL_VECTOR_SIZE >::Array ( )

constructor with default parameters

◆ Array() [2/8]

template<class TYPE , int SMALL_VECTOR_SIZE>
Util::Array< TYPE, SMALL_VECTOR_SIZE >::Array ( SizeT initialCapacity,
SizeT initialGrow )

constuctor with initial size and grow size

◆ Array() [3/8]

template<class TYPE , int SMALL_VECTOR_SIZE>
Util::Array< TYPE, SMALL_VECTOR_SIZE >::Array ( SizeT initialSize,
SizeT initialGrow,
const TYPE & initialValue )

constructor with initial size, grow size and initial values

◆ Array() [4/8]

template<class TYPE , int SMALL_VECTOR_SIZE>
Util::Array< TYPE, SMALL_VECTOR_SIZE >::Array ( const ArrayT & rhs)

copy constructor

◆ Array() [5/8]

template<class TYPE , int SMALL_VECTOR_SIZE>
Util::Array< TYPE, SMALL_VECTOR_SIZE >::Array ( ArrayT && rhs)
noexcept

move constructor

◆ Array() [6/8]

template<class TYPE , int SMALL_VECTOR_SIZE>
Util::Array< TYPE, SMALL_VECTOR_SIZE >::Array ( std::initializer_list< TYPE > list)

constructor from initializer list

◆ Array() [7/8]

template<class TYPE , int SMALL_VECTOR_SIZE>
Util::Array< TYPE, SMALL_VECTOR_SIZE >::Array ( std::nullptr_t )

construct an empty fixed array

◆ Array() [8/8]

template<class TYPE , int SMALL_VECTOR_SIZE>
Util::Array< TYPE, SMALL_VECTOR_SIZE >::Array ( const TYPE *const buf,
SizeT num )

constructor from TYPE pointer and size.

Note
copies the buffer.

◆ ~Array()

template<class TYPE , int SMALL_VECTOR_SIZE>
Util::Array< TYPE, SMALL_VECTOR_SIZE >::~Array ( )

destructor

Member Function Documentation

◆ Append() [1/3]

template<class TYPE , int SMALL_VECTOR_SIZE>
void Util::Array< TYPE, SMALL_VECTOR_SIZE >::Append ( const TYPE & elm)

append element to end of array

◆ Append() [2/3]

template<class TYPE , int SMALL_VECTOR_SIZE>
template<typename ... ELEM_TYPE>
void Util::Array< TYPE, SMALL_VECTOR_SIZE >::Append ( const TYPE & first,
const ELEM_TYPE &... elements )
inline

Append multiple elements to the end of the array.

◆ Append() [3/3]

template<class TYPE , int SMALL_VECTOR_SIZE>
void Util::Array< TYPE, SMALL_VECTOR_SIZE >::Append ( TYPE && elm)

append an element which is being forwarded

◆ AppendArray() [1/2]

template<class TYPE , int SMALL_VECTOR_SIZE>
void Util::Array< TYPE, SMALL_VECTOR_SIZE >::AppendArray ( const Array< TYPE, SMALL_VECTOR_SIZE > & rhs)

append the contents of an array to this array

◆ AppendArray() [2/2]

template<class TYPE , int SMALL_VECTOR_SIZE>
void Util::Array< TYPE, SMALL_VECTOR_SIZE >::AppendArray ( const TYPE * arr,
const SizeT count )

append from C array

◆ As()

template<class TYPE , int SMALL_VECTOR_SIZE = 0>
template<typename T >
T Util::Array< TYPE, SMALL_VECTOR_SIZE >::As ( ) const

convert to "anything"

◆ Back()

template<class TYPE , int SMALL_VECTOR_SIZE>
TYPE & Util::Array< TYPE, SMALL_VECTOR_SIZE >::Back ( ) const

return reference to last element

◆ Begin()

template<class TYPE , int SMALL_VECTOR_SIZE>
Array< TYPE, SMALL_VECTOR_SIZE >::Iterator Util::Array< TYPE, SMALL_VECTOR_SIZE >::Begin ( ) const

return iterator to beginning of array

◆ begin()

template<class TYPE , int SMALL_VECTOR_SIZE>
Array< TYPE, SMALL_VECTOR_SIZE >::Iterator Util::Array< TYPE, SMALL_VECTOR_SIZE >::begin ( ) const

for range-based iteration

◆ BinarySearchIndex() [1/2]

template<class TYPE , int SMALL_VECTOR_SIZE>
IndexT Util::Array< TYPE, SMALL_VECTOR_SIZE >::BinarySearchIndex ( const TYPE & elm) const

do a binary search, requires a sorted array

Does a binary search on the array, returns the index of the identical element, or InvalidIndex if not found.

◆ BinarySearchIndex() [2/2]

template<class TYPE , int SMALL_VECTOR_SIZE>
template<typename KEYTYPE >
IndexT Util::Array< TYPE, SMALL_VECTOR_SIZE >::BinarySearchIndex ( typename std::enable_if< true, const KEYTYPE & >::type elm) const
inline

do a binary search using a specific key type

Template type is used to force a specific type comparison.

This might mitigate some expensive implicit constructions to TYPE.

This templated method requires a explicit template type, which is enforced by using typename to put the template type in a non-deducable context. The enable_if does nothing except allow us to use typename.

◆ ByteSize()

template<class TYPE , int SMALL_VECTOR_SIZE>
const SizeT Util::Array< TYPE, SMALL_VECTOR_SIZE >::ByteSize ( ) const

return the byte size of the array.

◆ Capacity()

template<class TYPE , int SMALL_VECTOR_SIZE>
const SizeT Util::Array< TYPE, SMALL_VECTOR_SIZE >::Capacity ( ) const

get overall allocated size of array in number of elements

◆ Clear()

template<class TYPE , int SMALL_VECTOR_SIZE>
void Util::Array< TYPE, SMALL_VECTOR_SIZE >::Clear ( )

clear array (calls destructors)

The current implementation of this method does not shrink the preallocated space.

It simply sets the array _size to 0.

◆ clear()

template<class TYPE , int SMALL_VECTOR_SIZE>
void Util::Array< TYPE, SMALL_VECTOR_SIZE >::clear ( )
noexcept

◆ ConstBegin()

template<class TYPE , int SMALL_VECTOR_SIZE>
Array< TYPE, SMALL_VECTOR_SIZE >::ConstIterator Util::Array< TYPE, SMALL_VECTOR_SIZE >::ConstBegin ( ) const

return const iterator to beginning of array

◆ ConstEnd()

template<class TYPE , int SMALL_VECTOR_SIZE>
Array< TYPE, SMALL_VECTOR_SIZE >::ConstIterator Util::Array< TYPE, SMALL_VECTOR_SIZE >::ConstEnd ( ) const

return const iterator to end of array

◆ Copy()

template<class TYPE , int SMALL_VECTOR_SIZE>
void Util::Array< TYPE, SMALL_VECTOR_SIZE >::Copy ( const Array< TYPE, SMALL_VECTOR_SIZE > & src)
protected

copy content

◆ CopyRange()

template<class TYPE , int SMALL_VECTOR_SIZE>
void Util::Array< TYPE, SMALL_VECTOR_SIZE >::CopyRange ( TYPE * to,
TYPE * from,
SizeT num )
inlineprotected

copy range

◆ Delete()

template<class TYPE , int SMALL_VECTOR_SIZE>
void Util::Array< TYPE, SMALL_VECTOR_SIZE >::Delete ( )
protected

delete content

◆ Destroy()

template<class TYPE , int SMALL_VECTOR_SIZE>
void Util::Array< TYPE, SMALL_VECTOR_SIZE >::Destroy ( TYPE * elm)
protected

destroy an element (call destructor without freeing memory)

◆ DestroyRange()

template<class TYPE , int SMALL_VECTOR_SIZE>
void Util::Array< TYPE, SMALL_VECTOR_SIZE >::DestroyRange ( IndexT fromIndex,
IndexT toIndex )
inlineprotected

destroy range of elements

◆ Difference()

template<class TYPE , int SMALL_VECTOR_SIZE>
Array< TYPE, SMALL_VECTOR_SIZE > Util::Array< TYPE, SMALL_VECTOR_SIZE >::Difference ( const Array< TYPE, SMALL_VECTOR_SIZE > & rhs)

returns new array with elements which are not in rhs (slow!)

Returns a new array with all element which are in rhs, but not in this.

Carefull, this method may be very slow with large arrays!

Todo
this method is broken, check test case to see why!

◆ Emplace()

template<class TYPE , int SMALL_VECTOR_SIZE>
TYPE & Util::Array< TYPE, SMALL_VECTOR_SIZE >::Emplace ( )

Emplace item (create new item and return reference)

◆ EmplaceArray()

template<class TYPE , int SMALL_VECTOR_SIZE>
TYPE * Util::Array< TYPE, SMALL_VECTOR_SIZE >::EmplaceArray ( const SizeT count)

Emplace range of items and return pointer to first.

◆ End()

template<class TYPE , int SMALL_VECTOR_SIZE>
Array< TYPE, SMALL_VECTOR_SIZE >::Iterator Util::Array< TYPE, SMALL_VECTOR_SIZE >::End ( ) const

return iterator to end of array

◆ end()

template<class TYPE , int SMALL_VECTOR_SIZE>
Array< TYPE, SMALL_VECTOR_SIZE >::Iterator Util::Array< TYPE, SMALL_VECTOR_SIZE >::end ( ) const

◆ Erase()

template<class TYPE , int SMALL_VECTOR_SIZE = 0>
Array< TYPE, SMALL_VECTOR_SIZE >::Iterator Util::Array< TYPE, SMALL_VECTOR_SIZE >::Erase ( Iterator iter)

erase element pointed to by iterator, keep sorting intact

◆ EraseBack()

template<class TYPE , int SMALL_VECTOR_SIZE>
void Util::Array< TYPE, SMALL_VECTOR_SIZE >::EraseBack ( )

erase back

◆ EraseFront()

template<class TYPE , int SMALL_VECTOR_SIZE>
void Util::Array< TYPE, SMALL_VECTOR_SIZE >::EraseFront ( )

erase front

◆ EraseIndex()

template<class TYPE , int SMALL_VECTOR_SIZE>
void Util::Array< TYPE, SMALL_VECTOR_SIZE >::EraseIndex ( IndexT index)

erase element at index, keep sorting intact

◆ EraseIndexSwap()

template<class TYPE , int SMALL_VECTOR_SIZE>
void Util::Array< TYPE, SMALL_VECTOR_SIZE >::EraseIndexSwap ( IndexT index)

erase element at index, fill gap by swapping in last element, destroys sorting!

NOTE: this method is fast but destroys the sorting order!

◆ EraseRange()

template<class TYPE , int SMALL_VECTOR_SIZE>
void Util::Array< TYPE, SMALL_VECTOR_SIZE >::EraseRange ( IndexT start,
IndexT end )

erase range, excluding the element at end

◆ EraseSwap()

template<class TYPE , int SMALL_VECTOR_SIZE = 0>
Array< TYPE, SMALL_VECTOR_SIZE >::Iterator Util::Array< TYPE, SMALL_VECTOR_SIZE >::EraseSwap ( Iterator iter)

erase element at iterator, fill gap by swapping in last element, destroys sorting!

NOTE: this method is fast but destroys the sorting order!

◆ Extend()

template<class TYPE , int SMALL_VECTOR_SIZE>
void Util::Array< TYPE, SMALL_VECTOR_SIZE >::Extend ( SizeT num)
inline

Resize to fit the provided value, but don't shrink if the new size is smaller.

◆ Fill()

template<class TYPE , int SMALL_VECTOR_SIZE>
void Util::Array< TYPE, SMALL_VECTOR_SIZE >::Fill ( IndexT first,
SizeT num,
const TYPE & elm )

fill array range with element

Fills an array range with the given element value.

Will grow the array if necessary

Parameters
firstindex of first element to start fill
numnum elements to fill
elmfill value

◆ Find()

template<class TYPE , int SMALL_VECTOR_SIZE>
Array< TYPE, SMALL_VECTOR_SIZE >::Iterator Util::Array< TYPE, SMALL_VECTOR_SIZE >::Find ( const TYPE & elm,
const IndexT start = 0 ) const

find identical element in array, return iterator

Find element in array, return iterator, or 0 if element not found.

Parameters
elmelement to find
Returns
element iterator, or 0 if not found

◆ FindIndex() [1/2]

template<class TYPE , int SMALL_VECTOR_SIZE>
IndexT Util::Array< TYPE, SMALL_VECTOR_SIZE >::FindIndex ( const TYPE & elm,
const IndexT start = 0 ) const

find identical element in array, return index, InvalidIndex if not found

Find element in array, return element index, or InvalidIndex if element not found.

Parameters
elmelement to find
Returns
index to element, or InvalidIndex if not found

◆ FindIndex() [2/2]

template<class TYPE , int SMALL_VECTOR_SIZE>
template<typename KEYTYPE >
IndexT Util::Array< TYPE, SMALL_VECTOR_SIZE >::FindIndex ( typename std::enable_if< true, const KEYTYPE & >::type elm,
const IndexT start = 0 ) const
inline

find identical element using a specific key type

Find element in array, return element index, or InvalidIndex if element not found.

Template type is used to force a specific type comparison. This might mitigate some expensive implicit constructions to TYPE.

This templated method requires a explicit template type, which is enforced by using typename to put the template type in a non-deducable context. The enable_if does nothing except allow us to use typename.

Parameters
elmelement to find
Returns
index to element, or InvalidIndex if not found

◆ Fit()

template<class TYPE , int SMALL_VECTOR_SIZE>
void Util::Array< TYPE, SMALL_VECTOR_SIZE >::Fit ( )
inline

Fit the size of the array to the amount of elements.

◆ Free()

template<class TYPE , int SMALL_VECTOR_SIZE>
void Util::Array< TYPE, SMALL_VECTOR_SIZE >::Free ( )

free memory and reset size

Free up memory and reset the grow.

◆ Front()

template<class TYPE , int SMALL_VECTOR_SIZE>
TYPE & Util::Array< TYPE, SMALL_VECTOR_SIZE >::Front ( ) const

return reference to first element

◆ Get()

template<class TYPE , int SMALL_VECTOR_SIZE>
TYPE & Util::Array< TYPE, SMALL_VECTOR_SIZE >::Get ( IndexT index) const
inline

Get element (same as operator[] but as a function)

◆ Grow()

template<class TYPE , int SMALL_VECTOR_SIZE>
void Util::Array< TYPE, SMALL_VECTOR_SIZE >::Grow ( )

grow array with grow value

◆ GrowTo()

template<class TYPE , int SMALL_VECTOR_SIZE>
void Util::Array< TYPE, SMALL_VECTOR_SIZE >::GrowTo ( SizeT newCapacity)
protected

grow array to target size

◆ Insert()

template<class TYPE , int SMALL_VECTOR_SIZE>
void Util::Array< TYPE, SMALL_VECTOR_SIZE >::Insert ( IndexT index,
const TYPE & elm )

insert element before element at index

◆ InsertAtEndOfIdenticalRange()

template<class TYPE , int SMALL_VECTOR_SIZE>
IndexT Util::Array< TYPE, SMALL_VECTOR_SIZE >::InsertAtEndOfIdenticalRange ( IndexT startIndex,
const TYPE & elm )

insert element at the first non-identical position, return index of inclusion position

This inserts an element at the end of a range of identical elements starting at a given index.

Performance is O(n). Returns the index at which the element was added.

◆ InsertSorted()

template<class TYPE , int SMALL_VECTOR_SIZE>
IndexT Util::Array< TYPE, SMALL_VECTOR_SIZE >::InsertSorted ( const TYPE & elm)

insert element into sorted array, return index where element was included

This inserts the element into a sorted array.

Returns the index at which the element was inserted.

◆ IsEmpty()

template<class TYPE , int SMALL_VECTOR_SIZE>
bool Util::Array< TYPE, SMALL_VECTOR_SIZE >::IsEmpty ( ) const

return true if array empty

◆ IsSorted()

template<class TYPE , int SMALL_VECTOR_SIZE>
bool Util::Array< TYPE, SMALL_VECTOR_SIZE >::IsSorted ( ) const

test if the array is sorted, this is a slow operation!

This tests, whether the array is sorted.

This is a slow operation O(n).

◆ IsValidIndex()

template<class TYPE , int SMALL_VECTOR_SIZE>
bool Util::Array< TYPE, SMALL_VECTOR_SIZE >::IsValidIndex ( IndexT index) const

check if index is valid

◆ Move()

template<class TYPE , int SMALL_VECTOR_SIZE>
void Util::Array< TYPE, SMALL_VECTOR_SIZE >::Move ( IndexT fromIndex,
IndexT toIndex )
protected

move elements, grows array if needed

30-Jan-03 floh serious bugfixes! 07-Dec-04 jo bugfix: neededSize >= this->capacity => neededSize > capacity

◆ MoveRange()

template<class TYPE , int SMALL_VECTOR_SIZE>
void Util::Array< TYPE, SMALL_VECTOR_SIZE >::MoveRange ( TYPE * to,
TYPE * from,
SizeT num )
inlineprotected

move range

◆ operator!=()

template<class TYPE , int SMALL_VECTOR_SIZE>
bool Util::Array< TYPE, SMALL_VECTOR_SIZE >::operator!= ( const Array< TYPE, SMALL_VECTOR_SIZE > & rhs) const

inequality operator

The inequality operator returns true if at least one element in the array is different, or the array sizes are different.

◆ operator=() [1/2]

template<class TYPE , int SMALL_VECTOR_SIZE>
void Util::Array< TYPE, SMALL_VECTOR_SIZE >::operator= ( Array< TYPE, SMALL_VECTOR_SIZE > && rhs)
noexcept

move operator

◆ operator=() [2/2]

template<class TYPE , int SMALL_VECTOR_SIZE>
void Util::Array< TYPE, SMALL_VECTOR_SIZE >::operator= ( const Array< TYPE, SMALL_VECTOR_SIZE > & rhs)

assignment operator

◆ operator==()

template<class TYPE , int SMALL_VECTOR_SIZE>
bool Util::Array< TYPE, SMALL_VECTOR_SIZE >::operator== ( const Array< TYPE, SMALL_VECTOR_SIZE > & rhs) const

equality operator

The equality operator returns true if all elements are identical.

The TYPE class must support the equality operator.

◆ operator[]() [1/2]

template<class TYPE , int SMALL_VECTOR_SIZE>
TYPE & Util::Array< TYPE, SMALL_VECTOR_SIZE >::operator[] ( IndexT index)

[] operator

Access an element.

This method will NOT grow the array, and instead do a range check, which may throw an assertion.

◆ operator[]() [2/2]

template<class TYPE , int SMALL_VECTOR_SIZE>
TYPE & Util::Array< TYPE, SMALL_VECTOR_SIZE >::operator[] ( IndexT index) const

[] operator

Access an element.

This method will NOT grow the array, and instead do a range check, which may throw an assertion.

◆ PopBack()

template<class TYPE , int SMALL_VECTOR_SIZE>
TYPE Util::Array< TYPE, SMALL_VECTOR_SIZE >::PopBack ( )
inline

Pop back.

◆ PopFront()

template<class TYPE , int SMALL_VECTOR_SIZE>
TYPE Util::Array< TYPE, SMALL_VECTOR_SIZE >::PopFront ( )
inline

Pop front.

◆ push_back()

template<class TYPE , int SMALL_VECTOR_SIZE>
void Util::Array< TYPE, SMALL_VECTOR_SIZE >::push_back ( const TYPE & item)

◆ QuickSort()

template<class TYPE , int SMALL_VECTOR_SIZE>
void Util::Array< TYPE, SMALL_VECTOR_SIZE >::QuickSort ( )

quick sort the array

Sorts the array using quick sort.

This just calls the STL sort algorithm.

◆ QuickSortWithFunc()

template<class TYPE , int SMALL_VECTOR_SIZE>
void Util::Array< TYPE, SMALL_VECTOR_SIZE >::QuickSortWithFunc ( int(* func )(const void *lhs, const void *rhs))

quick sort the array

◆ Realloc()

template<class TYPE , int SMALL_VECTOR_SIZE>
void Util::Array< TYPE, SMALL_VECTOR_SIZE >::Realloc ( SizeT capacity,
SizeT grow )

clear contents and preallocate with new attributes

◆ Reserve()

template<class TYPE , int SMALL_VECTOR_SIZE>
void Util::Array< TYPE, SMALL_VECTOR_SIZE >::Reserve ( SizeT num)

increase capacity to fit N more elements into the array.

This increases the capacity to make room for N elements.

If the number of elements is known before appending the elements, this method can be used to prevent reallocation. If there is already enough room for N more elements, nothing will happen.

NOTE: the functionality of this method has been changed as of 26-Apr-08, it will now only change the capacity of the array, not its size.

◆ Reset()

template<class TYPE , int SMALL_VECTOR_SIZE>
void Util::Array< TYPE, SMALL_VECTOR_SIZE >::Reset ( )

reset array (does NOT call destructors)

This is identical with Clear(), but does NOT call destructors (it just resets the _size member.

USE WITH CARE!

◆ Resize() [1/2]

template<class TYPE , int SMALL_VECTOR_SIZE>
void Util::Array< TYPE, SMALL_VECTOR_SIZE >::Resize ( SizeT num)

Set size. Grows array if num is greater than capacity. Calls destroy on all objects at index > num!

◆ Resize() [2/2]

template<class TYPE , int SMALL_VECTOR_SIZE>
template<typename ... ARGS>
void Util::Array< TYPE, SMALL_VECTOR_SIZE >::Resize ( SizeT num,
ARGS... args )

Resize and fill new elements with arguments.

◆ resize()

template<class TYPE , int SMALL_VECTOR_SIZE>
void Util::Array< TYPE, SMALL_VECTOR_SIZE >::resize ( size_t size)

◆ Size()

template<class TYPE , int SMALL_VECTOR_SIZE>
const SizeT Util::Array< TYPE, SMALL_VECTOR_SIZE >::Size ( ) const

get number of elements in array

◆ size()

template<class TYPE , int SMALL_VECTOR_SIZE>
size_t Util::Array< TYPE, SMALL_VECTOR_SIZE >::size ( ) const

◆ Sort()

template<class TYPE , int SMALL_VECTOR_SIZE>
void Util::Array< TYPE, SMALL_VECTOR_SIZE >::Sort ( )

sort the array

Sorts the array.

This just calls the STL sort algorithm.

◆ SortWithFunc()

template<class TYPE , int SMALL_VECTOR_SIZE = 0>
void Util::Array< TYPE, SMALL_VECTOR_SIZE >::SortWithFunc ( bool(* func )(const TYPE &lhs, const TYPE &rhs))

sort with custom function

◆ TypeSize()

template<class TYPE , int SMALL_VECTOR_SIZE>
SizeT Util::Array< TYPE, SMALL_VECTOR_SIZE >::TypeSize ( ) const
inlineconstexpr

Returns sizeof(TYPE)

Friends And Related Symbol Documentation

◆ FixedArray

template<class TYPE , int SMALL_VECTOR_SIZE = 0>
template<class T , bool S>
friend class FixedArray
friend

Member Data Documentation

◆ capacity

template<class TYPE , int SMALL_VECTOR_SIZE = 0>
SizeT Util::Array< TYPE, SMALL_VECTOR_SIZE >::capacity
protected

◆ count

template<class TYPE , int SMALL_VECTOR_SIZE = 0>
SizeT Util::Array< TYPE, SMALL_VECTOR_SIZE >::count
protected

◆ elements

template<class TYPE , int SMALL_VECTOR_SIZE = 0>
TYPE* Util::Array< TYPE, SMALL_VECTOR_SIZE >::elements
protected

◆ grow

template<class TYPE , int SMALL_VECTOR_SIZE = 0>
SizeT Util::Array< TYPE, SMALL_VECTOR_SIZE >::grow
protected

◆ MaxGrowSize

template<class TYPE , int SMALL_VECTOR_SIZE = 0>
const SizeT Util::Array< TYPE, SMALL_VECTOR_SIZE >::MaxGrowSize = 65536
staticprotected

◆ MinGrowSize

template<class TYPE , int SMALL_VECTOR_SIZE = 0>
const SizeT Util::Array< TYPE, SMALL_VECTOR_SIZE >::MinGrowSize = 16
staticprotected

◆ stackElements

template<class TYPE , int SMALL_VECTOR_SIZE = 0>
_smallvector<TYPE, SMALL_VECTOR_SIZE> Util::Array< TYPE, SMALL_VECTOR_SIZE >::stackElements
protected

The documentation for this class was generated from the following file: