S2OPC OPCUA Toolkit
|
A singly linked list based on elements with unique identifiers and dynamically allocated. More...
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
Go to the source code of this file.
Typedefs | |
typedef struct SOPC_SLinkedList | SOPC_SLinkedList |
Singly linked list structure. More... | |
typedef struct SOPC_SLinkedList_Elt | SOPC_SLinkedList_Elt |
typedef SOPC_SLinkedList_Elt * | SOPC_SLinkedListIterator |
Functions | |
SOPC_SLinkedList * | SOPC_SLinkedList_Create (size_t sizeMax) |
Create and allocate a new singly linked list containing 0 elements with a size limit of the given size. More... | |
uintptr_t | SOPC_SLinkedList_Prepend (SOPC_SLinkedList *list, uint32_t id, uintptr_t value) |
Add a new element (and allocate new list element) before head of the given linked list. More... | |
uintptr_t | SOPC_SLinkedList_Append (SOPC_SLinkedList *list, uint32_t id, uintptr_t value) |
Add a new element (and allocate new list element) to the tail of the given linked list. More... | |
uintptr_t | SOPC_SLinkedList_SortedInsert (SOPC_SLinkedList *list, uint32_t id, uintptr_t value, int8_t(*pCompFn)(uintptr_t left, uintptr_t right)) |
Insert element in sorted list in correct index regarding compare function. More... | |
uintptr_t | SOPC_SLinkedList_PopHead (SOPC_SLinkedList *list) |
Get and remove the head element of the list. More... | |
uintptr_t | SOPC_SLinkedList_PopLast (SOPC_SLinkedList *list) |
Get and remove the last element of the list. More... | |
uintptr_t | SOPC_SLinkedList_GetHead (SOPC_SLinkedList *list) |
Get the head element of the list without removing it. Note: it shall not be freed. More... | |
uintptr_t | SOPC_SLinkedList_GetLast (SOPC_SLinkedList *list) |
Get the tail element of the list without removing it. Note: it shall not be freed. More... | |
uintptr_t | SOPC_SLinkedList_FindFromId (SOPC_SLinkedList *list, uint32_t id) |
Find the first value associated to the given id in the linked list (iterate from head to tail) More... | |
void | SOPC_SLinkedList_Apply (SOPC_SLinkedList *list, void(*pFn)(uint32_t id, uintptr_t val)) |
Apply a function to the value of each element of the list. More... | |
uintptr_t | SOPC_SLinkedList_RemoveFromId (SOPC_SLinkedList *list, uint32_t id) |
Find and remove the first value associated to the given id in the linked list (iterate from head to tail) More... | |
uintptr_t | SOPC_SLinkedList_RemoveFromValuePtr (SOPC_SLinkedList *list, uintptr_t value) |
Find and remove the first value pointer equal in the linked list (iterate from head to tail) More... | |
void | SOPC_SLinkedList_Clear (SOPC_SLinkedList *list) |
Delete all elements of the given linked list. More... | |
void | SOPC_SLinkedList_Delete (SOPC_SLinkedList *list) |
Delete and deallocate the given linked list. More... | |
void | SOPC_SLinkedList_EltGenericFree (uint32_t id, uintptr_t val) |
Frees the value of an element of the SOPC_SLinkedList. More... | |
SOPC_SLinkedListIterator | SOPC_SLinkedList_GetIterator (SOPC_SLinkedList *list) |
Get an iterator on a linked list to iterate on elements from head to tail. More... | |
bool | SOPC_SLinkedList_HasNext (const SOPC_SLinkedListIterator *it) |
Return true if iterator has a non NULL value to provide on next iteration (iterate from head to tail) More... | |
uintptr_t | SOPC_SLinkedList_Next (SOPC_SLinkedListIterator *it) |
Return the next element pointed by iterator in the linked list (iterate from head to tail) More... | |
uintptr_t | SOPC_SLinkedList_NextWithId (SOPC_SLinkedListIterator *it, uint32_t *pId) |
Return the next element pointed by iterator in the linked list (iterate from head to tail) More... | |
uint32_t | SOPC_SLinkedList_GetLength (SOPC_SLinkedList *list) |
Get the number of elements in the linked list. More... | |
uint32_t | SOPC_SLinkedList_GetCapacity (SOPC_SLinkedList *list) |
Get the maximum number of elements that can be contained in the linked list. More... | |
bool | SOPC_SLinkedList_SetCapacity (SOPC_SLinkedList *list, size_t sizeMax) |
Set the maximum number of elements that can be contained in the linked list. It might be used to modify the value provided on SOPC_SLinkedList_Create. Call to this function will fail if the current length is greater than provided value. More... | |
A singly linked list based on elements with unique identifiers and dynamically allocated.
typedef struct SOPC_SLinkedList SOPC_SLinkedList |
Singly linked list structure.
typedef struct SOPC_SLinkedList_Elt SOPC_SLinkedList_Elt |
SOPC_SLinkedList* SOPC_SLinkedList_Create | ( | size_t | sizeMax | ) |
Create and allocate a new singly linked list containing 0 elements with a size limit of the given size.
sizeMax | The maximum number of elements allowed in the new linked list or 0 if no limit defined |
uintptr_t SOPC_SLinkedList_Prepend | ( | SOPC_SLinkedList * | list, |
uint32_t | id, | ||
uintptr_t | value | ||
) |
Add a new element (and allocate new list element) before head of the given linked list.
list | Pointer on the linked list in which new element must be added |
id | Unique identifier to associate with the element (if not unique Prepend has LIFO behavior for Find and Remove) |
value | Pointer to the value or unsigned integer value of the element to prepend. Value 0 is considered invalid. |
uintptr_t SOPC_SLinkedList_Append | ( | SOPC_SLinkedList * | list, |
uint32_t | id, | ||
uintptr_t | value | ||
) |
Add a new element (and allocate new list element) to the tail of the given linked list.
list | Pointer on the linked list in which new element must be added |
id | Unique identifier to associate with the element (if not unique Append has FIFO behavior for Find and Remove) |
value | Pointer to the value or unsigned integer value of the element to append Value 0 is considered invalid. |
uintptr_t SOPC_SLinkedList_SortedInsert | ( | SOPC_SLinkedList * | list, |
uint32_t | id, | ||
uintptr_t | value, | ||
int8_t(*)(uintptr_t left, uintptr_t right) | pCompFn | ||
) |
Insert element in sorted list in correct index regarding compare function.
The element will be inserted before the element for which the compare function return that new element is < to the existing element (compare returns -1 when new element is left operand and < to right operand).
list | Pointer to the linked list |
id | Identifier of the given value |
value | Value to insert in the sorted list. Value 0 is considered invalid. |
pCompFn | Compare function pointer returning a int8_t equals to -1 if left value < right value, 0 if left value == right value and 1 if left value > right value |
uintptr_t SOPC_SLinkedList_PopHead | ( | SOPC_SLinkedList * | list | ) |
Get and remove the head element of the list.
list | Pointer on the linked list from which head element must be returned and removed |
uintptr_t SOPC_SLinkedList_PopLast | ( | SOPC_SLinkedList * | list | ) |
Get and remove the last element of the list.
list | Pointer on the linked list from which head element must be returned and removed |
uintptr_t SOPC_SLinkedList_GetHead | ( | SOPC_SLinkedList * | list | ) |
Get the head element of the list without removing it. Note: it shall not be freed.
list | Pointer on the linked list from which head element must be returned |
uintptr_t SOPC_SLinkedList_GetLast | ( | SOPC_SLinkedList * | list | ) |
Get the tail element of the list without removing it. Note: it shall not be freed.
list | Pointer on the linked list from which tail element must be returned |
uintptr_t SOPC_SLinkedList_FindFromId | ( | SOPC_SLinkedList * | list, |
uint32_t | id | ||
) |
Find the first value associated to the given id in the linked list (iterate from head to tail)
list | Pointer on the linked list in which element must be found |
id | Unique identifier associated with the element to find |
void SOPC_SLinkedList_Apply | ( | SOPC_SLinkedList * | list, |
void(*)(uint32_t id, uintptr_t val) | pFn | ||
) |
Apply a function to the value of each element of the list.
An example is the SOPC_SLinkedList_EltGenericFree() function which frees the value of each element of the list.
list | Pointer to the linked list |
pFn | Function pointer which takes the id and the value of each element |
uintptr_t SOPC_SLinkedList_RemoveFromId | ( | SOPC_SLinkedList * | list, |
uint32_t | id | ||
) |
Find and remove the first value associated to the given id in the linked list (iterate from head to tail)
list | Pointer on the linked list in which element must be found |
id | Unique identifier associated with the element to remove |
uintptr_t SOPC_SLinkedList_RemoveFromValuePtr | ( | SOPC_SLinkedList * | list, |
uintptr_t | value | ||
) |
Find and remove the first value pointer equal in the linked list (iterate from head to tail)
list | Pointer on the linked list in which element must be found |
value | Pointer to the value or unsigned integer value of the element to remove. Value 0 is considered invalid. |
void SOPC_SLinkedList_Clear | ( | SOPC_SLinkedList * | list | ) |
Delete all elements of the given linked list.
list | Pointer to the list of elements to be deleted |
void SOPC_SLinkedList_Delete | ( | SOPC_SLinkedList * | list | ) |
Delete and deallocate the given linked list.
list | Pointer to the list to deallocate (pointer must not be used anymore after operation) |
void SOPC_SLinkedList_EltGenericFree | ( | uint32_t | id, |
uintptr_t | val | ||
) |
Frees the value of an element of the SOPC_SLinkedList.
id | Unique identifier associated with the element |
val | Element to be freed |
SOPC_SLinkedListIterator SOPC_SLinkedList_GetIterator | ( | SOPC_SLinkedList * | list | ) |
Get an iterator on a linked list to iterate on elements from head to tail.
list | Pointer to the list for which an iterator is requested |
bool SOPC_SLinkedList_HasNext | ( | const SOPC_SLinkedListIterator * | it | ) |
Return true if iterator has a non NULL value to provide on next iteration (iterate from head to tail)
it | An iterator on a linked list |
uintptr_t SOPC_SLinkedList_Next | ( | SOPC_SLinkedListIterator * | it | ) |
Return the next element pointed by iterator in the linked list (iterate from head to tail)
it | An iterator on a linked list |
uintptr_t SOPC_SLinkedList_NextWithId | ( | SOPC_SLinkedListIterator * | it, |
uint32_t * | pId | ||
) |
Return the next element pointed by iterator in the linked list (iterate from head to tail)
it | An iterator on a linked list |
pId | Pointer in which the next element id of the linked list is set |
uint32_t SOPC_SLinkedList_GetLength | ( | SOPC_SLinkedList * | list | ) |
Get the number of elements in the linked list.
list | Pointer to the list |
uint32_t SOPC_SLinkedList_GetCapacity | ( | SOPC_SLinkedList * | list | ) |
Get the maximum number of elements that can be contained in the linked list.
list | Pointer to the list |
bool SOPC_SLinkedList_SetCapacity | ( | SOPC_SLinkedList * | list, |
size_t | sizeMax | ||
) |
Set the maximum number of elements that can be contained in the linked list. It might be used to modify the value provided on SOPC_SLinkedList_Create. Call to this function will fail if the current length is greater than provided value.
list | Pointer to the list |
sizeMax | The maximum number of elements allowed in the new linked list or 0 if no limit defined. If the current list length is greater than the provided value, call will fail. |