Skip to content

AP List Page 3

Addio edited this page Mar 12, 2022 · 1 revision

Contents

Unsafe Macros

All Unsafe Macros can be located in "geneticc/list/geneticc_list.h

Unsafe macros use malloc internally


Unsafe Macros

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

List_FindAllIndexes

Enumerates through each value in the list, and checks it against the predicate's condition. Every value that satisfied the condition, its index will be added to a list and returned.

Prototypes/Overloads

  • List_FindAllIndexes(list, predicate)
  • List_FindAllIndexes(list, predicate, index)
  • List_FindAllIndexes(list, predicate, index, length)

Parameters

Name Type Optional Description
list LIST_PTR No Pointer to the list.
predicate PREDICATE No Function pointer of type PREDICATE, used to check if an element satisfies a condition.
arg_count int No How many variadic arguments have been passed.
ap va_list No The variadic arguments.
index index_t Yes Zero based index at which to start enumeration.
length length_t Yes The number of elements to enumerate.

Returns

LIST_PTR

A list of zero based indexes to all values in the array that matched the predicate, or NULL if there were no matches.

Example

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

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

LIST_PTR list = Array_To_List(array);

LIST_PTR indexes = List_FindAllIndexes(list, predicate); //Result = A list containing indexes to all the elements that satisfied the predicate.

index_t* aligned = indexes->array;

for(int i = 0; i < List_Count(indexes ); i++)
{
	int value = list->array[aligned[i]];
}

List_FindAll

Enumerates through each value in the list, and checks it against the predicate's condition. Every value that satisfied the condition, will have a pointer to them added to a list that will be returned.

Prototypes/Overloads

  • List_FindAll(list, predicate)
  • List_FindAll(list, predicate, index)
  • List_FindAll(list, predicate, index, length)

Parameters

Name Type Optional Description
list LIST_PTR No Pointer to the list.
predicate PREDICATE No Function pointer of type PREDICATE, used to check if an element satisfies a condition.
arg_count int No How many variadic arguments have been passed.
ap va_list No The variadic arguments.
index index_t Yes Zero based index at which to start enumeration.
length length_t Yes The number of elements to enumerate.

Returns

LIST_PTR

A list of pointers to each value in the list that matched the predicate's conditions, or NULL if there were no matches.

Example

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

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

LIST_PTR list = Array_To_List(array);

LIST_PTR pointers = List_FindAllIndexes(list, predicate); //Result = A list containing pointers to all the elements that satisfied the predicate.

int** aligned = pointers->array;

for(int i = 0; i < List_Count(pointers); i++)
{
	int value = *aligned[i];
}

List_FindAllValues

Enumerates through each value in the list, and checks it against the predicate's condition. Every value that satisfied the condition, will be added to a list and returned.

Prototypes/Overloads

  • List_FindAllValues(list, predicate)
  • List_FindAllValues(list, predicate, index)
  • List_FindAllValues(list, predicate, index, length)

Parameters

Name Type Optional Description
list LIST_PTR No Pointer to the list.
predicate PREDICATE No Function pointer of type PREDICATE, used to check if an element satisfies a condition.
arg_count int No How many variadic arguments have been passed.
ap va_list No The variadic arguments.
index index_t Yes Zero based index at which to start enumeration.
length length_t Yes The number of elements to enumerate.

Returns

LIST_PTR

A list of values from the original list that matched the conditions defined by predicate, or NULL if there was no matches.

Example

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

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

LIST_PTR list = Array_To_List(array);

LIST_PTR values = List_FindAllIndexes(list, predicate); //Result = A list containing copies of the values that satisfied the predicate.

int* aligned = values->array;

for(int i = 0; i < List_Count(values ); i++)
{
	int value = aligned[i];
}

List_FindAllIndexesArgs

Enumerates through each value in the list, and checks it against the predicate's condition. Every value that satisfied the condition, its index will be added to a list and returned.

Prototypes/Overloads

  • List_FindAllIndexesArgs(list, predicate, arg_count, ...)

Parameters

Name Type Optional Description
list LIST_PTR No Pointer to the list.
predicate PREDICATE_ARGS No Function pointer of type PREDICATE_ARGS, used to check if an element satisfies a condition.
arg_count int No How many variadic arguments have been passed.
... Variadic No The variadic arguments.

Returns

LIST_PTR

A list of zero based indexes to all values in the array that matched the predicate, or NULL if there were no matches.

Example

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

void main()
{
	index_t* indexes = List_FindAllIndexesArgs(list, predicate_args, 2, 3, 6);	

	if(index != NULL)
	{
		for(int i = 0; i < List_Count(indexes ); i++)
		{
			int value = list->array[indexes[i]];
		}
	}
}

List_FindAllArgs

Enumerates through each value in the list, and checks it against the predicate's condition. Every value that satisfied the condition, will have a pointer to them added to a list that will be returned.

Prototypes/Overloads

  • List_FindAllArgs(list, predicate, arg_count, ...)

Parameters

Name Type Optional Description
list LIST_PTR No Pointer to the list.
predicate PREDICATE_ARGS No Function pointer of type PREDICATE_ARGS, used to check if an element satisfies a condition.
arg_count int No How many variadic arguments have been passed.
... Variadic No The variadic arguments.

Returns

LIST_PTR

A list containing pointers to each value in the list that matched the predicate's conditions, or NULL if there were no matches.

Example

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

void main()
{
	int** pointers = List_FindAllIndexesArgs(list, predicate_args, 2, 3, 6);

	if(index != NULL)
	{
		for(int i = 0; i < List_Count(pointers ); i++)
		{
			int value = *pointers[i];
		}
	}
}

List_FindAllValuesArgs

Enumerates through each value in the list, and checks it against the predicate's condition. Every value that satisfied the condition, will be added to a list and returned.

Prototypes/Overloads

  • List_FindAllValuesArgs(list, predicate, arg_count, ...)

Parameters

Name Type Optional Description
list LIST_PTR No Pointer to the list.
predicate PREDICATE_ARGS No Function pointer of type PREDICATE_ARGS, used to check if an element satisfies a condition.
arg_count int No How many variadic arguments have been passed.
... Variadic No The variadic arguments.

Returns

LIST_PTR

A list of values from the original list that matched the conditions defined by predicate, or NULL if there was no matches.

Example

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

void main()
{
	int* values = List_FindAllIndexesArgs(list, predicate_args, 2, , 3, 6);	

	if(values != NULL)
	{
		int value = values[i];
	}
}

List_FindAllIndexesVargs

Enumerates through each value in the list, and checks it against the predicate's condition. Every value that satisfied the condition, its index will be added to a list and returned.

Prototypes/Overloads

  • List_FindAllIndexesVargs(list, predicate, arg_count, ...)

Parameters

Name Type Optional Description
list LIST_PTR No Pointer to the list.
predicate PREDICATE_ARGS No Function pointer of type PREDICATE_ARGS, used to check if an element satisfies a condition.
arg_count int No How many variadic arguments have been passed.
ap va_list No The variadic arguments.

Returns

LIST_PTR

A list of zero based indexes to all values in the array that matched the predicate, or NULL if there were no matches.

Example

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


LIST_PTR 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};
        LIST_PTR list = new_List(sizeof(uint32_t));

	LIST_PTR matches = List_FindAllIndexesArgs(list, predicate_args, arg_count, ap);	

	List_Delete(list);

	return matches;
}

void main()
{
	index_t* indexes = example(2, 3, 6);

	if(index != NULL)
	{
		for(int i = 0; i < List_Count(indexes ); i++)
		{
			int value = list->array[indexes [i]];
		}
	}
}

List_FindAllVargs

Enumerates through each value in the list, and checks it against the predicate's condition. Every value that satisfied the condition, will have a pointer to them added to a list that will be returned.

Prototypes/Overloads

  • List_FindAllVargs(list, predicate, arg_count, ...)

Parameters

Name Type Optional Description
list LIST_PTR No Pointer to the list.
predicate PREDICATE_ARGS No Function pointer of type PREDICATE_ARGS, used to check if an element satisfies a condition.
arg_count int No How many variadic arguments have been passed.
ap va_list No The variadic arguments.

Returns

LIST_PTR

A list containing pointers to each value in the list that matched the predicate's conditions, or NULL if there were no matches.

Example

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


LIST_PTR 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};
        LIST_PTR list = new_List(sizeof(uint32_t));

	LIST_PTR matches = List_FindAllIndexesArgs(list, predicate_args, arg_count, ap);	

	List_Delete(list);

	return matches;
}

void main()
{
	int** pointers = example(2, 3, 6);

	if(index != NULL)
	{
		for(int i = 0; i < List_Count(pointers ); i++)
		{
			int value = *pointers[i];
		}
	}
}

List_FindAllValuesVargs

Enumerates through each value in the list, and checks it against the predicate's condition. Every value that satisfied the condition, will be added to a list and returned.

Prototypes/Overloads

  • List_FindAllValuesVargs(list, predicate, arg_count, ...)

Parameters

Name Type Optional Description
list LIST_PTR No Pointer to the list.
predicate PREDICATE_ARGS No Function pointer of type PREDICATE_ARGS, used to check if an element satisfies a condition.
arg_count int No How many variadic arguments have been passed.
ap va_list No The variadic arguments.

Returns

LIST_PTR

A list of values from the original list that matched the conditions defined by predicate, or NULL if there was no matches.

Example

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


LIST_PTR 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};
        LIST_PTR list = new_List(sizeof(uint32_t));

	LIST_PTR matches = List_FindAllIndexesArgs(list, predicate_args, arg_count, ap);	

	List_Delete(list);

	return matches;
}

void main()
{
	int* values = example(2, 3, 6);

	if(index != NULL)
	{
		int value = values [i];
	}
}

List_GetRange

Gets a range of elements from a list, and returns them inside a new list.

Prototypes/Overloads

  • List_GetRange(list, index, length)

Parameters

Name Type Optional Description
list LIST_PTR No Pointer to the list.
index index_t No Zero based index at which to start enumeration.
length length_t No The number of elements to get.

Returns

LIST_PTR

Pointer to the new list containing the range.

Example

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

LIST_PTR list = Array_To_List(array);

LIST_PTR range = List_GetRange(list, 5, 3);     //Result = range->array = {6, 7, 8}

List_InsertRange

Inserts an array of values into a list, at the specified index. If range has elements that are a different size than the list, it will discard or pad bytes while inserting.

Prototypes/Overloads

  • List_InsertRange(list, range, index)
  • List_InsertRange(list, range, index, length)
  • List_InsertRange(list, range, index, length, elem_size)

Parameters

Name Type Optional Description
list LIST_PTR No Pointer to the list.
range ARRAY_PTR No The range of values to insert.
index index_t No Zero based index at which to insert the range.
length length_t Yes The number of elements in range. *Required for pointer arrays.
elem_size element_size_t Yes The size of the type of elements in "range." *Required when passing a struct.

Returns

bool

True if the range was inserted, or false if the capacity was at its limit.

Example

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

LIST_PTR list = Array_To_List(array);

List_InsertRange(list, range, 2);     //Result = list->array = {'1', '2', 'r', 'a', 'n', 'g', 'e', '3', '4'}

List_InsertList

Inserts an array of values into a list, at the specified index.

If insert_list->elem_size is different than list->elem_size, it will discard or pad bytes while inserting.

Prototypes/Overloads

  • List_InsertList(list, insert_list, index)

Parameters

Name Type Optional Description
list LIST_PTR No Pointer to the list.
insert_list LIST_PTR No Pointer to the list_t which will be inserted.
index index_t No Zero based index at which to insert the list.

Returns

bool

True if the range was inserted, or false if the capacity was at its limit.

Example

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

LIST_PTR list = Array_To_List(array);
LIST_PTR listRange= Array_To_List(range);

List_InsertList(list, listRange, 2);     //Result = list->array = {'1', '2', 'r', 'a', 'n', 'g', 'e', '3', '4'}

List_Insert

Inserts a value into the list, at the specified index.

If the value is a different size than values in the list, it will discard or pad bytes while inserting.

Prototypes/Overloads

  • List_Insert(list, value, index)
  • List_Insert(list, value, index, elem_size)

Parameters

Name Type Optional Description
list LIST_PTR No Pointer to the list.
value Any No Value or pointer to the value..
index index_t No Zero based index at which to insert the value.
elem_size element_size_t Yes The size of the type of elements in "range." *Required when passing a struct or pointer.

Returns

bool

True if the value was inserted, or false if the capacity was at its limit.

Examples

Constant

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

LIST_PTR list = Array_To_List(array);

List_Insert(list, 'a', 2);     //Result = list->array = {'1', '2','a','3', '4'}

Struct

typedef struct
{
	int a;
	float b;
}example_struct_t;

example_struct_t array[4];

for(int i = 0; i < 4; i++)
{
	array[i].a = i;
	array[i].b = i + 0.5f;
}

example struct_t value = {.a = -1, .b = -0.5f};

LIST_PTR list = Array_To_List(array);

//elem_size required when passing structs with this method.
List_Insert(list, &value, 2, sizeof(example_struct_t); 

List_AddRange

Adds an array of values on to the end of the list.

If range has elements that are a different size than the list, it will discard or pad bytes while adding.

Prototypes/Overloads

  • List_AddRange(list, range)
  • List_AddRange(list, range, range_length)
  • List_AddRange(list, range, range_length, elem_size)

Parameters

Name Type Optional Description
list LIST_PTR No Pointer to the list.
range ARRAY_PTR No The range of values to add.
length length_t Yes The amount of elements in "range." *Required for pointer arrays.
elem_size element_size_t Yes The size of the type of elements in "range." *Required when passing a struct.

Returns

bool

True if the range was added, or false if the capacity was at its limit.

Example

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

LIST_PTR list = Array_To_List(array);

List_AddRange(list, range);     //Result = list->array = {'1', '2', '3', '4', 'r', 'a', 'n', 'g', 'e'}

List_AddList

Adds a list of values on to the end of a list.

If add_list->elem_size is different than list->elem_size, it will discard or pad bytes while adding.

Prototypes/Overloads

  • List_AddList(list, add_list)

Parameters

Name Type Optional Description
list LIST_PTR No Pointer to the list.
add_list LIST_PTR No Pointer to the list_t which will be added.

Returns

bool

True if the list was added, or false if the capacity was at its limit.

Example

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

LIST_PTR list = Array_To_List(array);
LIST_PTR rangeList = Array_To_List(rangeList );

List_AddList(list, rangeList);     //Result = list->array = {'1', '2', '3', '4', 'r', 'a', 'n', 'g', 'e'}

List_Add

Adds a value to the end of a list.

If the value is a different size than values in the list, it will discard or pad bytes while adding.

Prototypes/Overloads

  • List_Add(list, value)
  • List_Add(list, value, elem_size)

Parameters

Name Type Optional Description
list LIST_PTR No Pointer to the list.
value Any No Value or pointer to the value..
elem_size element_size_t Yes The size of the type of elements in "range." *Required when passing a struct or pointer.

Returns

bool

True if the value was added, or false if the capacity was at its limit.

Example

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

LIST_PTR list = Array_To_List(array);

List_Add(list, '5');     //Result = list->array = {'1', '2', '3', '4', '5'}

List_PrependRange

Adds a range of values to the start of a list.

If range has elements that are a different size than the list, it will discard or pad bytes while inserting.

Prototypes/Overloads

  • List_PrependRange(list, range)
  • List_PrependRange(list, range, length)
  • List_PrependRange(list, range, length, elem_size)

Parameters

Name Type Optional Description
list LIST_PTR No Pointer to the list.
range ARRAY_PTR No The range of values to prepend.
length length_t Yes The amount of elements in "range." *Required for pointer arrays.
elem_size element_size_t Yes The size of the type of elements in "range." *Required when passing a struct.

Returns

bool

True if the values were prended, or false if the capacity was at its limit.

Example

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

LIST_PTR list = Array_To_List(array);

List_PrependRange(list, range);     //Result = list->array = {'r', 'a', 'n', 'g', 'e', '1', '2', '3', '4'}

List_PrependList

Adds a list of values to the start of a list.

If prepend_list->elem_size is different than list->elem_size, it will discard or pad bytes while inserting.

Prototypes/Overloads

  • /param list Pointer to the list
  • /param prepend_list Pointer to the list to prepend.

Parameters

Name Type Optional Description
list LIST_PTR No Pointer to the list.
prepend_list LIST_PTR No Pointer to a list_t which will be added to the start of "list."

Returns

bool

True if the list was prepended, or false if the capacity was at its limit.

Example

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

LIST_PTR list = Array_To_List(array);
LIST_PTR listRange = Array_To_List(array);

List_PrependList(list, listRange );     //Result = list->array = {'r', 'a', 'n', 'g', 'e', '1', '2', '3', '4'}

List_Prepend

Prepends a value to the start of a list.

If the value is a different size than values in the list, it will discard or pad bytes while prepending.

Prototypes/Overloads

  • List_Prepend(list, value)
  • List_Prepend(list, value, elem_size)

Parameters

Name Type Optional Description
list LIST_PTR No Pointer to the list.
value Any No Value or pointer to the value..
elem_size element_size_t Yes The size of the type of elements in "range." *Required when passing a struct or pointer.

Returns

bool

True if the value was prepended, or false if the capacity was at its limit.

Example

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

LIST_PTR list = Array_To_List(array);

List_Prepend(list, '0');     //Result = list->array = {'0', '1', '2', '3', '4'}

List_RemoveRange

Removes a range of values from a list.

Prototypes/Overloads

  • List_RemoveRange(list, index, length)

Parameters

Name Type Optional Description
list LIST_PTR No Pointer to the list.
index index_t No The element to start removing at.
length length_t No How many elements to remove.

Returns

void

Example

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

LIST_PTR list = Array_To_List(array);

List_RemoveRange(list, 1, 2);     //Result = list->array = {'1', '4'}

List_RemoveAt

Removes an element from a list, at a specified index.

Prototypes/Overloads

  • List_RemoveAt(list, index)

Parameters

Name Type Optional Description
list LIST_PTR No Pointer to the list.
index index_t No The element to start removing at.

Returns

void

Example

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

LIST_PTR list = Array_To_List(array);

List_Remove(list, 1);     //Result = list->array = {'1', '3', '4'}

List_RemoveAt

Removes the first element from the list that matches value.

Prototypes/Overloads

  • List_Remove(list, value)

Parameters

Name Type Optional Description
list LIST_PTR No Pointer to the list.
value Any No The value to remove from the list.

Returns

bool

True or false depending if a value was removed.

Example

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

LIST_PTR list = Array_To_List(array);

bool removed = List_Remove(list, '2');     //Result = true | list->array = {'1', '3', '4'}

removed  = List_Remove(list, 1);           //Result = false | list->array = {'1', '3', '4'}

List_RemoveAll

Removes all elements from the list that matches the value.

Prototypes/Overloads

  • List_RemoveAll(list, value)

Parameters

Name Type Optional Description
list LIST_PTR No Pointer to the list.
value Any No The value used to determine what elements to remove from "list."

Returns

uint32_t

A count of how many elements were removed.

Example

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

LIST_PTR list = Array_To_List(array);

uint32_t removed = List_RemoveAll(list, '3');     //Result = 2 | list->array = {'1', '2', '4', '1', '2', '4'}

List_RemoveMatch

Removes the first element in the list, that satisfies the predicate's condition.

Prototypes/Overloads

  • List_RemoveMatch(list, predicate)

Parameters

Name Type Optional Description
list LIST_PTR No Pointer to the list.
predicate PREDICATE No Function pointer of type PREDICATE, used to check if an element satisfies a condition.

Returns

bool

True or false depending on if an item was matched and removed.

Example

bool predicate(const ELEMENT_PTR element)
{
	return *(int*)element % 2 == 1;
}

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

LIST_PTR list = Array_To_List(array);

bool removed = List_RemoveMatch(list, predicate);     //Result = true | list->array = {'2', '3', '4', '1', '2', '3', '4'}

List_RemoveAllMatching

Removes all elements in the list that satisfies the predicate's condition.

Prototypes/Overloads

  • List_RemoveAllMatching(list, predicate)

Parameters

Name Type Optional Description
list LIST_PTR No Pointer to the list.
predicate PREDICATE No Function pointer of type PREDICATE, used to check if an element satisfies a condition.

Returns

bool

True or false depending on if an item was matched and removed.

Example

bool predicate(const ELEMENT_PTR element)
{
	return *(int*)element % 2 == 1;
}

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

LIST_PTR list = Array_To_List(array);

uint32_t removed = List_RemoveAllMatching(list, predicate);     //Result = 4 | list->array = {'2', '4', '2', '4'}

List_RemoveMatch_Vargs

Removes the first element in the list, that satisfies the predicate's condition.

Prototypes/Overloads

  • List_RemoveMatch_Vargs(list, predicate, arg_count, ap)

Parameters

Name Type Optional Description
list LIST_PTR No Pointer to the list.
predicate PREDICATE_ARGS No Function pointer of type PREDICATE_ARGS, used to check if an element satisfies a condition.
arg_count int No How many variadic arguments have been passed.
ap va_list No The variadic arguments.

Returns

bool

True or false depending on if an item was matched and removed.

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);
}


bool example(LIST_PTR  list, int arg_count, ...)
{
	va_list ap;
	va_start(ap, arg_count);
	return List_RemoveMatch_Vargs(list, predicate_args, arg_count, ap);	
}

void main()
{
        uint32_t array[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
        LIST_PTR list = new_List(sizeof(uint32_t));
	bool removed = example(list, 2, 3, 0); //Result = true | list->array = {1, 2, 4, 5, 6, 7, 8, 9, 10}
}

List_RemoveAllMatching_Vargs

Removes all elements in the list that satisfies the predicate's condition.

Prototypes/Overloads

  • List_RemoveAllMatching_Vargs(list, predicate, arg_count, ap)

Parameters

Name Type Optional Description
list LIST_PTR No Pointer to the list.
predicate PREDICATE_ARGS No Function pointer of type PREDICATE_ARGS, used to check if an element satisfies a condition.
arg_count int No How many variadic arguments have been passed.
ap va_list No The variadic arguments.

Returns

uint32_t

Count of how many elements were removed from the list.

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);
}


bool example(LIST_PTR  list, int arg_count, ...)
{
	va_list ap;
	va_start(ap, arg_count);
	return List_RemoveAllMatching_Vargs(list, predicate_args, arg_count, ap);	
}

void main()
{
        uint32_t array[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
        LIST_PTR list = new_List(sizeof(uint32_t));
	uint32_t removed = example(list, 2, 3, 1); //Result = 4 | list->array = {2, 3, 5, 6, 8, 9}
}

List_RemoveMatch_Args

Removes the first element in the list, that satisfies the predicate's condition.

Prototypes/Overloads

  • List_RemoveMatch_Args(list, predicate, arg_count, ...)

Parameters

Name Type Optional Description
list LIST_PTR No Pointer to the list.
predicate PREDICATE_ARGS No Function pointer of type PREDICATE_ARGS, used to check if an element satisfies a condition.
arg_count int No How many variadic arguments have been passed.
... Variadic No The variadic arguments.

Returns

bool

True or false depending on if an item was matched and removed.

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);
}


void main()
{
        uint32_t array[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
        LIST_PTR list = new_List(sizeof(uint32_t));
	bool removed = List_RemoveMatch_Vargs(list, predicate_args, 2, 3, 0); //Result = true | list->array = {1, 2, 4, 5, 6, 7, 8, 9, 10}
}

List_RemoveAllMatching_Args

Removes all elements in the list that satisfies the predicate's condition.

Prototypes/Overloads

  • List_RemoveAllMatching_Args(list, predicate, arg_count, ...)

Parameters

Name Type Optional Description
list LIST_PTR No Pointer to the list.
predicate PREDICATE_ARGS No Function pointer of type PREDICATE_ARGS, used to check if an element satisfies a condition.
arg_count int No How many variadic arguments have been passed.
... Variadic No The variadic arguments.

Returns

uint32_t

Count of how many elements were removed from the list.

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);
}

void main()
{
        uint32_t array[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
        LIST_PTR list = new_List(sizeof(uint32_t));
	uint32_t removed =  List_RemoveAllMatching_Vargs(list, predicate_args, 2, 3, 1); //Result = 4 | list->array = {2, 3, 5, 6, 8, 9}
}

List_Reverse

Reverse the list's elements in memory.

Prototypes/Overloads

  • List_Reverse(list)

Parameters

Name Type Optional Description
list LIST_PTR No Pointer to the list.

Returns

void

Example

int array[4] = {1, 2, 3, 4};
LIST_PTR list = Array_To_List(array);

List_Reverse(list);

/*list->array = {4, 3, 2, 1}

List_ConvertTo

Casts all values in a list, and returns a new list containing all the cast values.

Prototypes/Overloads

  • List_ConvertTo(list, oldType, newType)

Parameters

Name Type Optional Description
list LIST_PTR No Pointer to the list.
oldType enum type_sized_t No The current type of elements in the list.
newType enum type_sized_t No The type to cast the elements to.

Returns

LIST_PTR

A new list containing the converted values.

Example

float array[4] = {-1.5f, 2.5f, 3.5f, -4.5f};
LIST_PTR list = Array_To_List(array);

LIST_PTR castList= List_ConvertTo(list, TYPE_SIZED_FLOAT, TYPE_SIZED_I32);

/*castList->array = {-1, 2, 3, -4};
Clone this wiki locally