Array

Templatized array with bounds checking. The backing storage is either auto-allocated (dynamically allocated) or user-allocated (supplied by user). With exception of changing the size and capacity, all operations are guaranteed to be O(1).

dmArray<int> a;
a.SetCapacity(1);
a.Push(1);
int b = a[0];

DM_ARRAY_SIZE

get number of elements in C array

get number of elements in C array

PARAMETERS

Array - [type:]

RETURN

Number - of elements


dmArray()

Templatized array with bounds checking.

The backing storage is either auto-allocated (dynamically allocated) or user-allocated (supplied by user). With exception of changing the size and capacity, all operations are guaranteed to be O(1).


dmArray()

constructor. empty auto-allocated memory

constructor. empty auto-allocated memory

EXAMPLES

dmArray<int> a;
a.Push(1);


dmArray(user_array, size, capacity)

constructor. user-allocated memory

user-allocated array with initial size and capacity

PARAMETERS

user_array - User-allocated array to be used as storage.

size - Initial size

capacity - Initial capacity


~dmArray()

array destructor

Only frees memory when auto-allocated.


Begin()

array begin

Pointer to the start of the backing storage

RETURN

pointer - pointer to start of memory


Begin()

array begin

Pointer to the start of the backing storage

RETURN

pointer - pointer to start of memory


End()

array end

Pointer to the end of the backing storage The end is essentially outside of the used storage.

RETURN

pointer - pointer to end of memory


End()

array end

Pointer to the end of the backing storage The end is essentially outside of the used storage.

RETURN

pointer - pointer to end of memory


Front()

array front

First element of the array

RETURN

reference - reference to the first element


Front()

array front (const)

First element of the array (const)

RETURN

reference - const-reference to the first element


Back()

array back

Last element of the array

RETURN

reference - reference to the last element


Back()

array back (const)

Last element of the array (const)

RETURN

reference - const-reference to the last element


Size()

size of array

Size of the array in elements

RETURN

number - array size


Capacity()

capacity of array

Capacity is currently allocated storage.

RETURN

number - array capacity


Full()

array full

Check if the array is full. The array is full when the size is equal to the capacity.

RETURN

boolean - true if the array is full


Empty()

array empty

Check if the array is empty. The array is empty when the size is zero.

RETURN

boolean - true if the array is empty


Remaining()

remaining size of array

Amount of additional elements that can be stored

RETURN

number - amount of additional elements that can be stored


operator[](index)

array operator[]

Retrieve an element by index

PARAMETERS

index - array index

RETURN

reference - reference to the element at the specified index


operator[](index)

array operator[] (const)

Retrieve an element by index (const)

PARAMETERS

index - array index

RETURN

reference - const-reference to the element at the specified index


SetCapacity(capacity)

array set capacity

Set the capacity of the array. If the size is less than the capacity, the array is truncated. If it is larger, the array is extended. Only allowed for auto-allocated arrays and will result in a new dynamic allocation followed by memcpy of the elements.

PARAMETERS

capacity - capacity of the array


OffsetCapacity(offset)

array offset capacity

Relative change of capacity Equivalent to SetCapacity(Capacity() + offset). Only allowed for auto-allocated arrays and will result in a new dynamic allocation followed by memcpy of the elements.

PARAMETERS

offset - relative amount of elements to change the capacity


SetSize(size)

array set size

Set size of the array

PARAMETERS

size - size of the array, must be less or equal to the capacity


dmArray(user_array, size, capacity, user_allocated)

Set user-allocated memory

user-allocated array with initial size and capacity

PARAMETERS

user_array - User-allocated array to be used as storage.

size - Initial size

capacity - Initial capacity

user_allocated - If false, the ownership is transferred to the dmArray


EraseSwap(index)

array eraseswap

Remove the element at the specified index. The removed element is replaced by the element at the end (if any), thus potentially altering the order. While operation changes the array size, it is guaranteed to be O(1).

PARAMETERS

index - index of the element to remove

RETURN

reference - reference to the new element at index


EraseSwapRef(element)

array reference eraseswap

Remove the element by reference The removed element is replaced by the element at the end (if any), thus potentially altering the order. While operation changes the array size, it is guaranteed to be O(1).

PARAMETERS

element - reference to the element to remove.

RETURN

reference - reference to the new referenced element


Push(element)

array push

Add an element to the end of the array Only allowed when the capacity is larger than size.

PARAMETERS

element - element element to add


PushArray(array, count)

array push array

Add an array of elements to the end of the array Only allowed when the capacity is larger than size + count

PARAMETERS

array - array of elements to add

count - amount of elements in the array


Pop()

array pop

Remove the last element of the array Only allowed when the size is larger than zero.


Swap(rhs)

array swap

Swap the content of two arrays

PARAMETERS

rhs - reference to array to swap content with


Map(fn, ctx)

map a function on all values

map a function on all values

PARAMETERS

fn - function that will be called for each element

ctx - user defined context that will be passed in with each callback