-
Notifications
You must be signed in to change notification settings - Fork 0
API List Page 2
Macros
All Macros can be located in "geneticc/list/geneticc_list.h
- List_Contains
- List_Exists
- List_IndexOf
- List_LastIndexOf
- List_ValueCount
- List_Max
- List_Max_Val
- List_Min
- List_Min_Val
- List_Sum
- List_Average
- List_ForEach
- List_All
- List_Any
- List_FindIndex
- List_FindIndexArgs
- List_FindIndexVargs
- List_Find
- List_FindArgs
- List_FindVargs
Searches n list for a value, and confirms its existence.
Prototypes/Overloads
- List_Contains(list, value )
- List_Contains(list, value, index)
- List_Contains(list, value, index, length)
Parameters
Name | Type | Optional | Description |
---|---|---|---|
list | LIST_PTR | No | Pointer to the list. |
value | Any Value or pointer to value | No | The value to search for |
index | index_t | Yes | The index to start searching at |
length | unsigned int | Yes | The amount of elements to search |
Returns
bool
If the list contains the value.
Example
char array[5] = {1, 2, 3, 4, 5};
LIST_PTR list = Array_To_List(&array);
bool contains = List_Contains(list, 3); //True
Enumerates through all elements in the list, checking them to the predicate's conditions, and returning if the predicate was satisfied.
Prototypes/Overloads
- List_Exists(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 if an element in the list satisfied the predicate's condition, false if the predicate was unsatisfied.
Example
//Checks to see if the element is above 5.
bool predicate(const uint8_t* value)
{
return *((int*)value) == 3 + 3;
}
int array[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
LIST_PTR list = Array_To_List(array);
bool exists = List_Exists(list, predicate); //Returns true
Search an list for a specific value, and returns the first index.
Prototypes/Overloads
- List_IndexOf(list, value)
- List_IndexOf(list, value, start)
- List_IndexOf(list, value, start, length)
Parameters
Name | Type | Optional | Description |
---|---|---|---|
list | LIST_PTR | No | Pointer to the list. |
value | Any | No | The value or pointer to the value to search for. |
index | index_t | Yes | The index to start searching at |
length | length_t | Yes | The amount of elements to search |
Returns
int
The zero-based index of the value, or -1 if the value does not exist in the array
Example
char array[5] = {1, 2, 3, 4, 5};
LIST_PTR list = Array_To_List(&array);
int index = List_IndexOf(list, 3); //Result = 2
Searches an list from back to front for a value, and returns the index of the first match (latest index).
Prototypes/Overloads
- List_LastIndexOf(list, value)
- List_LastIndexOf(list, value, index)
- List_LastIndexOf(list, value, index, length)
Parameters
Name | Type | Optional | Description |
---|---|---|---|
list | LIST_PTR | No | Pointer to the list. |
value | Any | No | The value or pointer to the value to search for. |
index | index_t | Yes | The index to start searching at |
length | length_t | Yes | The amount of elements to search |
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};
LIST_PTR list = Array_To_List(&array);
int index = List_LastIndexOf(list, 3); //Result = 5
Counts how many times "value" is seen in the list.
Prototypes/Overloads
- List_ValueCount(list, value)
- List_ValueCount(list, value, index)
- List_ValueCount(list, value, index, length)
Parameters
Name | Type | Optional | Description |
---|---|---|---|
list | LIST_PTR | No | Pointer to the list. |
value | Any | No | The value or pointer to the value to search for. |
index | index_t | Yes | The index to start searching at |
length | ;ength_t | Yes | The amount of elements to search |
Returns
int
A count of how many times "value" was in the list.
Example
uint32_t array[8] = {1, 2, 3, 4, 1, 2, 3, 4};
LIST_PTR list = Array_To_List(&array);
int count = List_ValueCount(list, 3); //Result = 2
Searches an list for the largest value, and returns its index.
Prototypes/Overloads
- List_Max(list)
- List_Max(list, index)
- List_Max(list, index, length)
Parameters
Name | Type | Optional | Description |
---|---|---|---|
list | LIST_PTR | No | Pointer to the list. |
index | index_t | Yes | The index to start searching at |
length | length_t | Yes | The amount of elements to search |
Returns
uint
The index of the largest value in the list.
Example
uint32_t array[8] = {1, 2, 3, 4, 1, 2, 3, 4};
LIST_PTR list = Array_To_List(&array);
int index = List_Max(list); //Result = 3
Searches an list for the largest value, and returns the value.
Prototypes/Overloads
- List_Max_Val(list)
- List_Max_Val(list, index)
- List_Max_Val(list, index, length)
Parameters
Name | Type | Optional | Description |
---|---|---|---|
list | LIST_PTR | No | Pointer to the list. |
index | index_t | Yes | The index to start searching at |
length | length_t | Yes | The amount of elements to search |
Returns
uint
The largest value in the list.
Example
uint32_t array[8] = {1, 2, 3, 4, 1, 2, 3, 4};
LIST_PTR list = Array_To_List(&array);
int value = List_Max_Val(list); //Result = 4
Searches an list for the smallest value, and returns its index.
Prototypes/Overloads
- List_Min(list)
- List_Min(list, index)
- List_Min(list, index, length)
Parameters
Name | Type | Optional | Description |
---|---|---|---|
list | LIST_PTR | No | Pointer to the list. |
index | index_t | Yes | The index to start searching at |
length | length_t | Yes | The amount of elements to search |
Returns
uint
The index of the smallest value in the list.
Example
int array[8] = {1, 2, 3, -4, 1, 2, 3, 4};
LIST_PTR list = Array_To_List(&array);
int index = List_Min(list); //Result = 3
Searches an list for the smallest value, and returns the value.
Prototypes/Overloads
- List_Min_Val(list)
- List_Min_Val(list, index)
- List_Min_Val(list, index, length)
Parameters
Name | Type | Optional | Description |
---|---|---|---|
list | LIST_PTR | No | Pointer to the list. |
index | index_t | Yes | The index to start searching at |
length | length_t | Yes | The amount of elements to search |
Returns
uint
The smallest value in the list.
Example
int array[8] = {1, 2, 3, -4, 1, 2, 3, 4};
LIST_PTR list = Array_To_List(&array);
int value = List_Min_Val(list); //Result = -4
Gets the sum of all values in the list.
Prototypes/Overloads
- List_Sum(list)
- List_Sum(list, index)
- List_Sum(list, index, length)
Parameters
Name | Type | Optional | Description |
---|---|---|---|
list | LIST_PTR | No | Pointer to the list. |
index | index_t | Yes | The index to start searching at |
length | length_t | Yes | The amount of elements to search |
Returns
Any Standard Data Type
The sum of all values in the list.
Example
uint32_t array[8] = {1, 2, 3, 4, 1, 2, 3, 4};
LIST_PTR list = Array_To_List(&array);
int sum= List_Sum(list); //Result = 20
Gets the average of all values in the list.
Prototypes/Overloads
- List_Average(list)
- List_Average(list, index)
- List_Average(list, index, length)
Parameters
Name | Type | Optional | Description |
---|---|---|---|
list | LIST_PTR | No | Pointer to the list. |
index | index_t | Yes | The index to start searching at |
length | length_t | Yes | The amount of elements to search |
Returns
Any Standard Data Type
The index of the smallest value in the list.
Example
float array[8] = {1, 2, 3, 4, 1, 2, 3, 4};
LIST_PTR list = Array_To_List(&array);
float average;
average= List_Average(array); //Result = 2.5f
average= List_Average(array, 5, 3); //Result = 3
Enumerates each element in the list, and performs an action on them.
Prototypes/Overloads
- List_ForEach(list, action)
- List_ForEach(list, action, index)
- List_ForEach(list, action, index, length)
Parameters
Name | Type | Optional | Description |
---|---|---|---|
list | LIST_PTR | No | Pointer to the list. |
action | ACTION | No | Function pointer of type action. |
index | index_t | Yes | The element to start performing actions at. |
length | length_t | Yes | How many elements to perform an action on. |
Returns
void
Example
void action_example(ELEMENT_PTR element)
{
free(*(int**)element);
}
int pointers[4];
LIST_PTR list = new_List(sizeof(int*));
pointers[0] = malloc(4);
pointers[1] = malloc(4);
pointers[2] = malloc(4);
pointers[3] = malloc(4);
List_AddRange(list, pointers);
//Will free each pointer in the list.
List_ForEach(list, action_example);
Determines whether all elements of a sequence satisfy a condition.
Prototypes/Overloads
- List_All(list, predicate)
- List_All(list, predicate, index)
- List_All(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. |
index | index_t | Yes | The element to start at. |
length | length_t | Yes | How many elements to enumerate. |
Returns
bool
True if all elements in the sequence satisfied the condition.
Example
//Checks to see if the element is positive.
bool predicate(const ELEMENT_PTR value)
{
return *((int*)value) > 0;
}
int array1[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
int array2[10] = {1, 2, 3, 4, -5, 6, 7, 8, 9, 10};
LIST_PTR list1 = Array_To_List(array1);
LIST_PTR list2 = Array_To_List(array2);
bool allTrue1 = List_All(list1, predicate); //Returns true
bool allTrue2 = List_All(list2, predicate); //Returns false
Determines whether any element of a sequence exists or satisfies a condition.
Prototypes/Overloads
- List_Any(list, predicate)
- List_Any(list, predicate, index)
- List_Any(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. |
index | index_t | Yes | The element to start at. |
length | length_t | Yes | How many elements to enumerate. |
Returns
bool
True if any elements in the sequence satisfied the condition.
Example
//Checks to see if the element is negative.
bool predicate(const ELEMENT_PTR value)
{
return *((int*)value) < 0;
}
int array1[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
int array2[10] = {1, 2, 3, 4, -5, 6, 7, 8, 9, 10};
LIST_PTR list1 = Array_To_List(array1);
LIST_PTR list2 = Array_To_List(array2);
bool allTrue1 = List_Any(list1, predicate); //Returns false
bool allTrue2 = List_Any(list2, predicate); //Returns true
Retrieves the index to the first value in the list that matches the predicate.
Prototypes/Overloads
- List_FindIndex(list, predicate)
- List_FindIndex(list, predicate, index)
- List_FindIndex(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. |
index | index_t | Yes | The element to start at. |
length | length_t | Yes | How many elements to enumerate. |
Returns
int
Zero based index of the first value in the array that matches the predicate, or -1 if the value does not exist.
Example
//Checks to see if the element is above 5.
bool predicate(const uint8_t* 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);
int index = List_FindIndex(list, predicate); //Returns 5
int index = List_FindIndex(list, predicate, 5); //Result = -1
int index = List_FindIndex(list, predicate, 4, 6); //Result = 6
Retrieves the index to the first value in the list that matches the predicate.
Prototypes/Overloads
- List_FindIndexArgs(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
int
Zero based index of the first value in the array that matches the predicate, or -1 if the value does not exist.
Example
//Checks to see if the element equals 3 + 4
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};
LIST_PTR list = Array_To_List(array);
int index = List_FindIndexArgs(array, predicate_args, 2, 3, 4); //Result = 6
Retrieves the index to the first value in the list that matches the predicate.
Prototypes/Overloads
- List_FindIndexVargs(list, predicate, arg_count, ap)
- List_FindIndexVargs(list, predicate, arg_count, ap, index)
- List_FindIndexVargs(list, predicate, arg_count, ap, index, length)
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. |
index | index_t | Yes | The index to start searching at |
length | length_t | Yes | How many elements to enumerate. |
Returns
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};
LIST_PTR list = new_List(sizeof(uint32_t));
return List_FindIndexVargs(list, predicate_args, arg_count, ap);
}
void main()
{
int index = example(2, 4, 5); //Result = 8
}
Retrieves a pointer to the first value in the list that matches the predicate.
Prototypes/Overloads
- List_Find(list, predicate)
- List_Find(list, predicate, index)
- List_Find(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. |
index | index_t | Yes | The element to start at. |
length | length_t | Yes | How many elements to enumerate. |
Returns
*
Zero based index of the first value in the array that matches the predicate, or -1 if the value does not exist.
Example
//Checks to see if the element is above 5.
bool predicate(const uint8_t* 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);
int* pointer = List_FindIndex(list, predicate); //Returns pointer to index [5] which is 6
int* index = List_FindIndex(list, predicate, 5); //Result = NULL
Retrieves a pointer to the first value in the list that matches the predicate.
Prototypes/Overloads
- List_FindArgs(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
*
A pointer to the first value in the array that matches the predicate
Example
//Checks to see if the element equals 3 + 4
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};
LIST_PTR list = Array_To_List(array);
int* pointer = List_FindIndexArgs(array, predicate_args, 2, 3, 4); //Result = pointer to index 6, which holds a 7
Retrieves a pointer to the first value in the list that matches the predicate.
Prototypes/Overloads
- List_FindVargs(list, predicate, arg_count, ap)
- List_FindVargs(list, predicate, arg_count, ap, index)
- List_FindVargs(list, predicate, arg_count, ap, index, length)
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. |
index | index_t | Yes | The element to start at. |
length | length_t | Yes | How many elements to enumerate. |
Returns
*
A pointer to the first value in the array that matches the predicate
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};
LIST_PTR list = new_List(sizeof(uint32_t));
return List_FindIndexVargs(list, predicate_args, arg_count, ap);
}
void main()
{
int* index = example(2, 4, 5); //Result = pointer to index 8, which holds a 9
}