Skip to content

API Array

Addio edited this page Nov 3, 2021 · 6 revisions

Contents

Macros

Unsafe Macros

Unsafe macros use malloc internally, and when you are done using, the array must be freed.

Internal Functions

Internal Unsafe Functions

Macros (Main usage)

Array_Contains

Searches an array for a value, and returns true or false depending on if it exists.

Overloads

  • Array_Contains(array, value)
  • Array_Contains(array, value, length)
  • Array_Contains(array, value, length, start)

Parameters

Name Type Optional Description
array * No Pointer to the array.
value Any No The value or pointer to the value to search for.
length uint32_t Yes The count of elements in the array, or the amount of values to enumerate. *Required for pointer arrays.
start uint32_t Yes The index to start searching from.

Returns

bool

If the array contains the value.

Example

uint32_t array[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
bool contains;
contains = Array_Contains(array, 5);						//Returns true		length not needed as "intarray" is a static array.
contains = Array_Contains(array, 5, sizeof(array) / sizeof(int));		//Returns true		length is optional
contains = Array_Contains(array, 5, 4);					        //Returns false		only checks the first 4 items.
contains = Array_Contains(array, 5, 3, 4);					//Returns true		checks from index 4, to index 7

Array_Exists

Enumerates through an array checking the elements to the predicate, and returns true or false if an element satisfied the condition.

Overloads

  • Array_Exists(array, predicate)
  • Array_Exists(array, predicate, length)
  • Array_Exists(array, predicate, length, start)

Parameters

Name Type Optional Description
array * No Pointer to the array.
predicate PREDICATE No A function pointer of type PREDICATE, which checks each value to its conditions.
length uint32_t Yes The count of elements in the array, or the amount of values to enumerate. *Required for pointer arrays.
start uint32_t Yes The index to start searching from.

Returns

bool

True if an element in the array satisfied the predicate's condition, false if the predicate was unsatisfied.

Example

bool predicate(const uint8_t* value)
{
	return *((int*)value) > 5;
}

uint32_t array[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
bool exists = Array_Exists(array, predicate);			//Result = true
bool exists = Array_Exists(array, predicate, 5);		//Result = false
bool exists = Array_Exists(array, predicate, 4, 6);		//Result = true

Array_IndexOf

Searches an array for a value, and returns the first index.

Overloads

  • Array_IndexOf(array, value)
  • Array_IndexOf(array, value, length)
  • Array_IndexOf(array, value, length, start)

Parameters

Name Type Optional Description
array * No Pointer to the array.
value Any No The value or pointer to the value to search for.
length uint32_t Yes The count of elements in the array, or the amount of values to enumerate. *Required for pointer arrays.
start uint32_t Yes The index to start searching from.

Returns

int

The zero-based index of the value, or -1 if the value does not exist in the array.

Example

uint32_t array[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
int index;
index = Array_IndexOf(array, 1);					//Returns 0		length not needed as "intarray" is a static array.
index = Array_IndexOf(array, 6, sizeof(array) / sizeof(int));		//Returns 5		length is optional.
index = Array_IndexOf(array, 7, 4);					//Returns -1	        only checks the first 4 items.
index = Array_IndexOf(array, 8, 4, 4);					//Returns 7		checks from index 4, to index 8

Array_LastIndexOf

Searches an array for a value, from back to front, and returns the last index.

Overloads

  • Array_LastIndexOf(array, value)
  • Array_LastIndexOf(array, value, length)
  • Array_LastIndexOf(array, value, length, start)

Parameters

Name Type Optional Description
array * No Pointer to the array.
value Any No The value or pointer to the value to search for.
length uint32_t Yes The count of elements in the array, or the amount of values to enumerate. *Required for pointer arrays.
start uint32_t Yes The index to start searching from.

Returns

int

The last index of the value, or -1 if the value does not exist in the array.

Example

uint32_t array[8] = {1, 2, 3, 4, 1, 2, 3, 4};
int index;
index = Array_LastIndexOf(array, 2);		//Returns 5
index = Array_LastIndexOf(array, 2, 4);		//Returns 1
index = Array_LastIndexOf(array, 2, 3, 2);	//Returns -1

Array_ValueCount

Counts how many times "value" is seen in the array.

Overloads

  • Array_ValueCount(array, value)
  • Array_ValueCount(array, value, length)
  • Array_ValueCount(array, value, length, start)

Parameters

Name Type Optional Description
array * No Pointer to the array.
value Any No The value or pointer to the value to search for.
length uint32_t Yes The count of elements in the array, or the amount of values to enumerate. *Required for pointer arrays.
start uint32_t Yes The index to start searching from.

Returns

unsigned int

A count of how many times "value" was in the array.

Example

uint32_t array[8] = {1, 2, 3, 4, 1, 2, 3, 4};
int count = Array_ValueCount(array, 4,  8);		//Returns 2  
int count = Array_ValueCount(array, 4,  4);		//Returns 1  
int count = Array_ValueCount(array, 4,  4, 4);		//Returns 1  

Array_Max

Can only be used with standard data types

Finds the largest value in the array, and returns the index.

Overloads

  • Array_Max(array)
  • Array_Max(array, length)
  • Array_Max(array, length, start)

Parameters

Name Type Optional Description
array Standard Type* No Pointer to an array of standard data types.
length uint32_t Yes The count of elements in the array, or the amount of values to enumerate. *Required for pointer arrays.
start uint32_t Yes The index to start searching from.

Returns

unsigned int

The index of the largest value in the array.

Example

uint32_t array[8] = {1, 2, 3, 4, 1, 2, 3, 4};
int index = Array_Max(array);			//Result = 3
int index = Array_Max(array, 8);		//Result = 3
int index = Array_Max(array, 4, 4);		//Result = 7

Array_Max_Val

Can only be used with standard data types

Finds the largest value in the array, and returns the value.

Overloads

  • Array_Max_Val(array)
  • Array_Max_Val(array, length)
  • Array_Max_Val(array, length, start)

Parameters

Name Type Optional Description
array Standard Type* No Pointer to an array of standard data types.
length uint32_t Yes The count of elements in the array, or the amount of values to enumerate. *Required for pointer arrays.
start uint32_t Yes The index to start searching from.

Returns

Any Standard Data Type

The value of the largest value in the array.

Example

int iarray[8] = {1, 2, 3, 4, 1, 2, 3, 4};

int result = Array_Max_Val(iarray);		//Result = 4
int result = Array_Max_Val(iarray, 8);		//Result = 4
int result = Array_Max_Val(iarray, 4, 3);	//Result = 3

float farray[8] = {1, 2, 3, 4.5f, 1, 2, 3, 4};
float result = Array_Max_Val(farray);		//Result = 4.5f

Array_Min

Can only be used with standard data types

Finds the smallest value in the array, and returns the index.

Overloads

  • Array_Min(array)
  • Array_Min(array, length)
  • Array_Min(array, length, start)

Parameters

Name Type Optional Description
array Standard Type* No Pointer to an array of standard data types.
length uint32_t Yes The count of elements in the array, or the amount of values to enumerate. *Required for pointer arrays.
start uint32_t Yes The index to start searching from.

Returns

unsigned int

The index of the smallest value in the array.

Example

uint32_t array[8] = {1, 2, 3, 4, 1, 2, 3, 4};
int index = Array_Min(array);		        //Result = 0
int index = Array_Min(array, 4);		//Result = 0
int index = Array_Min(array, 4, 3);		//Result = 4

Array_Min_Val

Can only be used with standard data types

Finds the smallest value in the array, and returns the value.

Overloads

  • Array_Min_Val(array)
  • Array_Min_Val(array, length)
  • Array_Min_Val(array, length, start)

Parameters

Name Type Optional Description
array Standard Type* No Pointer to an array of standard data types.
length uint32_t Yes The count of elements in the array, or the amount of values to enumerate. *Required for pointer arrays.
start uint32_t Yes The index to start searching from.

Returns

Any Standard Data Type

The value of the smallest value in the array.

Example

int iarray[8] = {1, 2, -3, 4, 1, 2, 3, 4};

int result = Array_Min_Val(iarray);		//Result = -3
int result = Array_Min_Val(iarray, 8);		//Result = -3
int result = Array_Min_Val(iarray, 4, 3);	//Result = 1

float farray[8] = {1, 2, -3, 4.5f, 1, 2, 3, 4};
float result = Array_Min_Val(farray);		//Result = -3

Array_Sum

The sum of all values in the array.

Overloads

  • Array_Sum(array)
  • Array_Sum(array, length)
  • Array_Sum(array, length, start)

Parameters

Name Type Optional Description
array * No Pointer to the array.
length uint32_t Yes The count of elements in the array, or the amount of values to enumerate. *Required for pointer arrays.
start uint32_t Yes The index to start searching from.

Returns

Any Standard Data Type

The sum of all values in the array.

Example

uint32_t array[8] = {1, 2, 3, 4, 1, 2, 3, 4};
int sum;
sum = Array_Sum(array);					//Result = 20
sum = Array_Sum(array, 3);				//Result = 6
sum = Array_Sum(array, 3, 5);				//Result = 9

Array_Average

The average of all values in the array.

Overloads

  • Array_Average(array)
  • Array_Average(array, length)
  • Array_Average(array, length, start)

Parameters

Name Type Optional Description
array * No Pointer to the array.
length uint32_t Yes The count of elements in the array, or the amount of values to enumerate. *Required for pointer arrays.
start uint32_t Yes The index to start searching from.

Returns

Any Standard Data Type

The average of all values in the array.

Example

float array[8] = {1, 2, 3, 4, 1, 2, 3, 4};
float average;
average= Array_Average(array);			//Result = 2.5f	
average= Array_Average(array, 3, 5);		//Result = 3

Array_FindIndex

Retrieves the index to the first value in the array that matches the predicate.

Overloads

  • Array_FindIndex(array, predicate)
  • Array_FindIndex(array, predicate, length)
  • Array_FindIndex(array, predicate, length, start)

Parameters

Name Type Optional Description
array * No Pointer to the array.
predicate PREDICATE No A function pointer of type PREDICATE.
length uint32_t Yes The count of elements in the array, or the amount of values to enumerate. *Required for pointer arrays.
start uint32_t Yes The index to start searching from.

Returns

unsigned int

Zero based index of the first value in the array that matches the predicate, or -1 if the value does not exist.

Example

bool predicate(const uint8_t* value)
{
	return *((int*)value) > 5;
}

uint32_t array[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
int index = Array_FindIndex(array, predicate);			//Result = 5
int index = Array_FindIndex(array, predicate, 5);			//Result = -1
int index = Array_FindIndex(array, predicate, 4, 6);		//Result = 6

Array_Find

Retrieves a pointer to the first value in the array that matches the predicate.

Overloads

  • Array_Find(array, predicate)
  • Array_Find(array, predicate, length)
  • Array_Find(array, predicate, length, start)

Parameters

Name Type Optional Description
array * No Pointer to the array.
predicate PREDICATE No A function pointer of type PREDICATE.
length uint32_t Yes The count of elements in the array, or the amount of values to enumerate. *Required for pointer arrays.
start uint32_t Yes The index to start searching from.

Returns

*

A pointer to the first value in the array that matches the predicate

Example

bool predicate(const uint8_t* value)
{
	return *((int*)value) > 5;
}

int array[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
int* addr = Array_Find(array, predicate);			//Result = (Pointer to index 5)
int* addr = Array_Find(array, predicate, 5);			//Result = NULL
int* addr = Array_Find(array, predicate, 4, 6);		//Result = (Pointer to index 6)

Array_FindIndexArgs

Retrieves the index to the first value in the array that matches the predicate.

Overloads

  • Array_FindIndexArgs(array, predicate, length, arg_count, ...)

Parameters

Name Type Optional Description
array * No Pointer to the array.
predicate PREDICATE_ARGS No A function pointer of type PREDICATE_ARGS.
length unsigned int Yes The length of the array, or how many elements to enumerate.
arg_count int No How many variadic arguments have been passed.
... Variadic Yes The variadic arguments.

Returns

unsigned int

Zero based index of the first value in the array that matches the predicate, or -1 if the value does not exist.

Example

bool predicate_args( const uint8_t* value, int arg_count, va_list ap)
{
	return *((int*)value) == va_arg(ap, int) + va_arg(ap, int);
}

uint32_t array[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
int index = Array_FindIndexArgs(array, predicate_args, 10, 2, 3, 4);	//Result = 6


Array_FindIndexVargs

Retrieves the index to the first value in the array that matches the predicate.

Overloads

  • Array_FindIndexVargs(array, predicate, arg_count, ap)
  • Array_FindIndexVargs(array, predicate, arg_count, ap, length)
  • Array_FindIndexVargs(array, predicate, arg_count, ap, length, start)

Parameters

Name Type Optional Description
array * No Pointer to the array.
predicate PREDICATE_ARGS No A function pointer of type PREDICATE_ARGS.
arg_count int No How many variadic arguments have been passed.
ap va_list Yes The variadic arguments.
length unsigned int Yes The length of the array, or how many elements to enumerate.
start index_t Yes The index to start at.

Returns

unsigned int

Zero based index of the first value in the array that matches the predicate, or -1 if the value does not exist.

Example

bool predicate_args( const uint8_t* value, int arg_count, va_list ap)
{
	return *((int*)value) == va_arg(ap, int) + va_arg(ap, int);
}


int example(int arg_count, ...)
{
	va_list ap;
	va_start(ap, arg_count);
	
	uint32_t array[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
	return Array_FindIndexVargs(array, predicate_args, arg_count, ap);	
}

void main()
{
	int index = example(2, 4, 5); //Result = 8
}



Array_FindArgs

Retrieves a pointer to the first value in the array that matches the predicate.

Overloads

  • Array_FindArgs(array, predicate, length, arg_count, ...)

Parameters

Name Type Optional Description
array * No Pointer to the array.
predicate PREDICATE_ARGS No A function pointer of type PREDICATE_ARGS.
length unsigned int Yes The length of the array, or how many elements to enumerate.
arg_count int No How many variadic arguments have been passed.
... Variadic Yes The variadic arguments.

Returns

unsigned int

A pointer to the first value in the array that matches the predicate, or null if there were no matches.

Example

bool predicate_args( const uint8_t* value, int arg_count, va_list ap)
{
	return *((int*)value) == va_arg(ap, int) + va_arg(ap, int);
}

int array[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
int* addr = Array_FindArgs(array, predicate, 10, 2, 3, 4);	//Result = (Pointer to index 6)


Array_FindVargs

Retrieves a pointer to the first value in the array that matches the predicate.

Overloads

  • Array_FindVargs(array, predicate, arg_count, ap)

Parameters

Name Type Optional Description
array * No Pointer to the array.
predicate PREDICATE_ARGS No A function pointer of type PREDICATE_ARGS.
arg_count int No How many variadic arguments have been passed.
ap va_list Yes The variadic arguments.
length unsigned int Yes The length of the array, or how many elements to enumerate.
start index_t Yes The index to start at.

Returns

*

A pointer to the first value in the array that matches the predicate, or null if there were no matches.

Example

bool predicate_args( const uint8_t* value, int arg_count, va_list ap)
{
	return *((int*)value) == va_arg(ap, int) + va_arg(ap, int);
}


int* example(int arg_count, ...)
{
	va_list ap;
	va_start(ap, arg_count);
	
	uint32_t array[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
	return Array_FindIndexVargs(array, predicate_args, arg_count, ap);	
}

void main()
{
	int* addr = example(2, 4, 5); //Result = (Pointer to index 8)
}

Unsafe Macros

Array_FindAll

Retrieves an array of pointers to the elements that match the conditions defined by the specified predicate.

Overloads

  • Array_FindAll(array, predicate, out_count)
  • Array_FindAll(array, predicate, length, out_count)
  • Array_FindAll(array, predicate, length, start, out_count)

Parameters

Name Type Optional Description
array * No Pointer to the array.
predicate PREDICATE No A function pointer of type PREDICATE.
length uint32_t Yes The count of elements in the array, or the amount of values to enumerate. *Required for pointer arrays.
start uint32_t Yes The index to start searching from.
*out_count uint* No A pointer used to retrieve the length of the returned array.

Returns

**

A pointer to an array of pointers, which all point to a value in the array that matched the predicate's conditions

Example

bool predicate(const uint8_t* value)
{
	return *((int*)value) > 5;
}

uint32_t array[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
unsigned int matchCount;
ARRAY_PTR* matches = Array_FindAll(array, predicate, &matchCount);	//Result = array holding 5 pointers from array[5] to array[9], matchCount = 5

Array_InsertRange

Inserts a range of values into an array.

Overloads

  • Array_InsertRange(array, range, index)
  • Array_InsertRange(array, range, index, count)
  • Array_InsertRange(array, range, index, count, length)
  • Array_InsertRange(array, range, index, count, length, free_old)

Parameters

Name Type Optional Description
array * No Pointer to the array.
range * No A pointer to an array or value.
index uint No Index at which to insert the range at.
count uint Yes The amount of elements in "range."
length uint32_t Yes The count of elements in the array, or the amount of values to enumerate. *Required for pointer arrays.
free_old bool Yes If true, "array" will be freed/deleted before the function returns.

Returns

*

A pointer to the start of the new array.

Example

char array[4] = {'0', '1', '2', '3'};
char range[5] = {'r', 'a', 'n', 'g', 'e'};

//Inserts range into array, starting at index 2.
char* newArray = Array_InsertRange(array, range, 2);	                       //Result = {'0', '1', 'r', 'a', 'n', 'g', 'e', '2', '3'}

//Inserts the first 2 elements of range back into newArray.
//length is required, as newArray is not static (9).
char* newArray2 = Array_InsertRange(newArray, range, 2, 2, 9, true );		//Result = {'0', '1', 'r', 'a', 'r', 'a', 'n', 'g', 'e', '2', '3'}

Array_Insert

Inserts a value into an array.

Overloads

  • Array_Insert(array, value, index)
  • Array_Insert(array, value, index, length)
  • Array_Insert(array, value, index, length, free_old)

Parameters

Name Type Optional Description
array * No Pointer to the array.
value Any No A value or pointer to a value.
index uint No Index at which to insert the range at.
length uint32_t Yes The count of elements in the array, or the amount of values to enumerate. *Required for pointer arrays.
free_old bool Yes If true, "array" will be freed/deleted before the function returns.

Returns

*

A pointer to the start of the new array.

Example

char array[4] = {'0', '1', '2', '3'};
char range[5] = {'r', 'a', 'n', 'g', 'e'};

char* newArray = Array_Insert(array, 'a', 2);	                //Result = {'0', '1', 'a', '2', '3'}

char* newArray2 = Array_Insert(newArray, 'a', 3, 5, true);	//Result = {'0', '1', 'a', 'b', '2', '3'}

Array_AddRange

Adds a range of values on to the end of an array.

Overloads

  • Array_AddRange(array, value)
  • Array_AddRange(array, value, count)
  • Array_AddRange(array, value, count, length)
  • Array_AddRange(array, value, count, length, free_old)

Parameters

Name Type Optional Description
array * No Pointer to the array.
range Any No Pointer to an array or value.
count uint Yes The amount of values to add. *Required for non static arrays.
length uint32_t Yes The count of elements in the array, or the amount of values to enumerate. *Required for pointer arrays.
free_old bool Yes If true, "array" will be freed/deleted before the function returns.

Returns

*

A pointer to the start of the new array.

Example

char array[4] = {'0', '1', '2', '3'};
char range[5] = {'r', 'a', 'n', 'g', 'e'};

char* newArray1	= Array_AddRange(array, range);	//Result = {'0', '1', '2', '3',  'r', 'a', 'n', 'g', 'e'}

Array_Add

Adds a value to the end of an array.

Overloads

  • Array_Add(array, value)
  • Array_Add(array, value, length)
  • Array_Add(array, value, length, free_old)

Parameters

Name Type Optional Description
array * No Pointer to the array.
value Any No A value or pointer to a value.
length uint32_t Yes The count of elements in the array, or the amount of values to enumerate. *Required for pointer arrays.
free_old bool Yes If true, "array" will be freed/deleted before the function returns.

Returns

*

A pointer to the start of the new array.

Example

char array[4] = {'0', '1', '2', '3'};

char* newArray1	= Array_Add(array,'a');      //Result = {'0', '1', '2', '3', 'a'}

Array_PrependRange

Adds a range of values on to the start of an array.

Overloads

  • Array_PrependRange(array, value)
  • Array_PrependRange(array, value, count)
  • Array_PrependRange(array, value, count, length)
  • Array_PrependRange(array, value, count, length, free_old)

Parameters

Name Type Optional Description
array * No Pointer to the array.
range Any No Pointer to an array or value.
count uint Yes The amount of values to prepend. *Required for non static arrays.
length uint32_t Yes The count of elements in the array, or the amount of values to enumerate. *Required for pointer arrays.
free_old bool Yes If true, "array" will be freed/deleted before the function returns.

Returns

*

A pointer to the start of the new array.

Example

char array[4] = {'0', '1', '2', '3'};
char range[5] = {'r', 'a', 'n', 'g', 'e'};

char* newArray1	= Array_PrependRange(array, range);	//Result = { 'r', 'a', 'n', 'g', 'e', '0', '1', '2', '3'}

Array_Prepend

Adds a value to the start of an array.

Overloads

  • Array_Prepend(array, value)
  • Array_Prepend(array, value, length)
  • Array_Prepend(array, value, length, free_old)

Parameters

Name Type Optional Description
array * No Pointer to the array.
value Any No A value or pointer to a value.
length uint32_t Yes The count of elements in the array, or the amount of values to enumerate. *Required for pointer arrays.
free_old bool Yes If true, "array" will be freed/deleted before the function returns.

Returns

*

A pointer to the start of the new array.

Example

char array[4] = {'0', '1', '2', '3'};

char* newArray1	= Array_Prepend(array, 'a');		//Result = {'a', '0', '1', 'a', '2', '3'}

Array_RemoveRange

Removes a range of values from an array.

Overloads

  • Array_RemoveRange(array, index, count)
  • Array_RemoveRange(array, index, count, length)
  • Array_RemoveRange(array, index, count, length, free_old)

Parameters

Name Type Optional Description
array * No Pointer to the array.
index uint No Index at which to start removing values.
count uint Yes The amount of elements to remove.
length uint32_t Yes The count of elements in the array, or the amount of values to enumerate. *Required for pointer arrays.
free_old bool Yes If true, "array" will be freed/deleted before the function returns.

Returns

*

A pointer to the start of the new array.

Example

uint32_t array[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};

uint32_t* newArray = Array_RemoveRange(array, 3, 3 );		//Result, {1, 2, 3, 7, 8, 9, 10}

Array_RemoveAt

Removes a value from an array by its index.

Overloads

  • Array_RemoveAt(array, index)
  • Array_RemoveAt(array, index, length)
  • Array_RemoveAt(array, index, length, free_old)

Parameters

Name Type Optional Description
array * No Pointer to the array.
index uint No Index at which to start removing values.
length uint32_t Yes The count of elements in the array, or the amount of values to enumerate. *Required for pointer arrays.
free_old bool Yes If true, "array" will be freed/deleted before the function returns.

Returns

*

A pointer to the start of the new array.

Example

uint32_t array[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};

uint32_t* newArray = Array_RemoveAt(array, 3);		//Result, {1, 2, 3, 5, 6, 7, 8, 9, 10}

Array_Remove

Removes the first item from an array which equals "value."

Overloads

  • Array_Remove(array, value)
  • Array_Remove(array, value, out_removed)
  • Array_Remove(array, value, length, out_removed)
  • Array_Remove(array, value, length, free_old, out_removed)

Parameters

Name Type Optional Description
array * No Pointer to the array.
value Any No A value or pointer to a value.
index uint No Index at which to start removing values.
free_old bool Yes If true, "array" will be freed/deleted before the function returns.
out_removed bool* Yes Returns true or false depending if a value was found and removed.

Returns

*

A pointer to the start of the new array.

Example

uint32_t array[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};

bool removed;
int* removeArray = Array_Remove(array, 5, &removed);			//Result, {1, 2, 3, 4, 6, 7, 8, 9, 10}		removed = true

Array_RemoveAll

Removes all items from an array which equals "value."

Overloads

  • Array_RemoveAll(array, value)
  • Array_RemoveAll(array, value, out_count)
  • Array_RemoveAll(array, value, length, out_count)
  • Array_RemoveAll(array, value, length, free_old, out_count)

Parameters

Name Type Optional Description
array * No Pointer to the array.
value Any No A value or pointer to a value.
index uint No Index at which to start removing values.
free_old bool Yes If true, "array" will be freed/deleted before the function returns.
out_count uint32_t* Yes Out parameter used to retrieve the amount of elements removed.

Returns

*

A pointer to the start of the new array.

Example

uint32_t array[8] = {0, 1, 2, 3, 0, 1, 2, 3};

uint32_t removeCount = 0;
uint8_t* removeAllArray = Array_RemoveAll(array, 2, &removeCount );	//Result, {0, 1, 3, 0, 1, 3}	removeCount = 2

Array_Reverse

Reverse the array in memory.

Overloads

  • Array_Reverse(array)
  • Array_Reverse(array, length)
  • Array_Reverse(array, length, free_old)

Parameters

Name Type Optional Description
array * No Pointer to the array.
length uint Yes The count of elements in the array. *Required for pointer arrays.
free_old bool Yes If true, "array" will be freed/deleted before the function returns.

Returns

*

A pointer to the start of the new array.

Example

uint32_t array[8] = {0, 1, 2, 3, 0, 1, 2, 3};

uint32_t* reverseArray = Array_Reverse(array);	//Result, {'3, '2', '1', '0', '3, '2', '1', '0'};

Array_ConvertTo

Converts an array of one data type, to an array of a different data type.

Overloads

  • Array_ConvertTo(array, oldType, newType)
  • Array_ConvertTo(array, length, oldType, newType)
  • Array_ConvertTo(array, length, oldType, newType, free_old)

Parameters

Name Type Optional Description
array * No Pointer to the array.
oldType type_sized_t No The current type of the array.
newType type_sized_t No The type to convert the array in to.
length uint Yes The count of elements in the array. *Required for pointer arrays.
free_old bool Yes If true, "array" will be freed/deleted before the function returns.

Returns

*

A pointer to the start of the new array.

Example

uint32_t array[8] = {0, 1, 2, 3, 0, 1, 2, 3};

float* farray = Array_ConvertTo(array, TYPE_SIZED_U32, TYPE_SIZED_FLOAT);

Internal Functions

Coming Soon