Lazuli
|
Doubly linked lists interface. More...
Go to the source code of this file.
Data Structures | |
struct | _Lz_LinkedListElement |
Represents an element of a doubly linked list. More... | |
struct | Lz_LinkedList |
Represents the main container for doubly linked elements. More... | |
Macros | |
#define | LINKED_LIST_INIT { NULL, NULL } |
Define the initialization value for the type Lz_LinkedList. | |
#define | LINKED_LIST_ELEMENT_INIT { NULL, NULL } |
Define the initialization value for the type Lz_LinkedListElement. | |
#define | List_UntypedForEach(LINKEDLIST, ITEM) |
Run through an Lz_LinkedList like a for loop. More... | |
#define | List_ForEach(LINKEDLIST, TYPE, ITEM, MEMBER) |
Run through an Lz_LinkedList like a for loop. More... | |
#define | List_RemovableForEach(LINKEDLIST, TYPE, ITEM, MEMBER, ITERATOR) |
Run through an Lz_LinkedList like a for loop, with the ability of removing elements from the list while iterating on it. More... | |
Typedefs | |
typedef struct _Lz_LinkedListElement | Lz_LinkedListElement |
Represents an element of a doubly linked list. | |
Functions | |
void | List_Append (Lz_LinkedList *const linkedList, Lz_LinkedListElement *const item) |
Insert an Lz_LinkedListElement as the last element of an existing Lz_LinkedList. More... | |
void | List_Prepend (Lz_LinkedList *const linkedList, Lz_LinkedListElement *const item) |
Insert an Lz_LinkedListElement as the first element of an existing Lz_LinkedList. More... | |
void | List_AppendList (Lz_LinkedList *const linkedListDestination, Lz_LinkedList *const linkedListToMove) |
Move the content of an Lz_LinkedList to the end of an existing Lz_LinkedList. More... | |
Lz_LinkedListElement * | List_PickFirst (Lz_LinkedList *const linkedList) |
Return the first element of an existing linked list. More... | |
Lz_LinkedListElement * | List_PointFirst (const Lz_LinkedList *const linkedList) |
Return a pointer to the first element of an existing linked list. More... | |
bool | List_IsEmpty (const Lz_LinkedList *const linkedList) |
Test if an Lz_LinkedList is empty. More... | |
void | List_InsertAfter (Lz_LinkedList *const linkedList, Lz_LinkedListElement *const listItem, Lz_LinkedListElement *const itemToInsert) |
Insert an element after another in an Lz_LinkedList. More... | |
void | List_InsertBefore (Lz_LinkedList *const linkedList, Lz_LinkedListElement *const listItem, Lz_LinkedListElement *const itemToInsert) |
Insert an element before another in a Lz_LinkedList. More... | |
Lz_LinkedListElement * | List_Remove (Lz_LinkedList *const linkedList, Lz_LinkedListElement *const itemToRemove) |
Remove an element from an Lz_LinkedList. More... | |
Lz_LinkedListElement * | List_PointElementAt (const Lz_LinkedList *const linkedList, const size_t index) |
Point to an indexed element in an Lz_LinkedList, starting at index 0. More... | |
void | List_InitLinkedList (Lz_LinkedList *const linkedList) |
Initialize an Lz_LinkedList. More... | |
void | List_InitLinkedListElement (Lz_LinkedListElement *const item) |
Initialize an Lz_LinkedListElement. More... | |
Doubly linked lists interface.
Describes types and functions related to doubly linked lists.
Definition in file list.h.
#define List_UntypedForEach | ( | LINKEDLIST, | |
ITEM | |||
) |
Run through an Lz_LinkedList like a for loop.
If the list is empty, no loop is performed, and the execution will continue after the foreach.
With configuration option CHECK_NULL_PARAMETERS_IN_LISTS, this implementation can also verify if the LINKEDLIST
pointer is NULL. If so, the loop is not run and the execution continues after the loop.
LINKEDLIST | A pointer to the Lz_LinkedList to run through. |
ITEM | A pointer to an Lz_LinkedListElement that will point to the current item of each loop turn. This pointer will never be NULL. |
#define List_ForEach | ( | LINKEDLIST, | |
TYPE, | |||
ITEM, | |||
MEMBER | |||
) |
Run through an Lz_LinkedList like a for loop.
This foreach implementation is typed, so each loop turn will return a typed pointer to the current loop element (ie. not a pointer to a raw Lz_LinkedListElement).
If the list is empty, no loop is performed, and the execution will continue after the foreach.
With configuration option CHECK_NULL_PARAMETERS_IN_LISTS, this implementation can also verify if the LINKEDLIST
pointer is NULL. If so, the loop is not run and the execution continues after the loop.
LINKEDLIST | A pointer to the Lz_LinkedList to run through. |
TYPE | The real type of the list elements |
ITEM | A pointer to a struct of type TYPE containing the Lz_LinkedListELement. This pointer will point to the current item of each loop turn. This pointer will never be NULL while the loop is running. |
MEMBER | The name of the member in TYPE which bears the Lz_LinkedListElement. |
#define List_RemovableForEach | ( | LINKEDLIST, | |
TYPE, | |||
ITEM, | |||
MEMBER, | |||
ITERATOR | |||
) |
Run through an Lz_LinkedList like a for loop, with the ability of removing elements from the list while iterating on it.
An iterator must be provided, in the form of a pointer to an allocated Lz_LinkedListElement. In order to remove elements while iterating, the iterator must be updated with the return value of List_Remove.
This foreach implementation is typed, so each loop turn will return a typed pointer to the current loop element (ie. not a pointer to a raw Lz_LinkedListElement).
If the list is empty, no loop is performed, and the execution will continue after the foreach.
With configuration option CHECK_NULL_PARAMETERS_IN_LISTS, this implementation can also verify if the LINKEDLIST
pointer is NULL. If so, the loop is not run and the execution continues after the loop.
LINKEDLIST | A pointer to the Lz_LinkedList to run through. |
TYPE | The real type of the list elements |
ITEM | A pointer to a struct of type TYPE containing the Lz_LinkedListELement. This pointer will point to the current item of each loop turn. This pointer will never be NULL while the loop is running. |
MEMBER | The name of the member in TYPE which bears the Lz_LinkedListElement. |
ITERATOR | A pointer to an allocated Lz_LinkedListElement that will be used as the loop iterator. This iterator can be updated when removing elements from the list, using the return value of List_Remove. |
void List_Append | ( | Lz_LinkedList *const | linkedList, |
Lz_LinkedListElement *const | item | ||
) |
Insert an Lz_LinkedListElement as the last element of an existing Lz_LinkedList.
linkedList | A pointer to the linked list head. |
item | A pointer to the item to append to the list. |
void List_Prepend | ( | Lz_LinkedList *const | linkedList, |
Lz_LinkedListElement *const | item | ||
) |
Insert an Lz_LinkedListElement as the first element of an existing Lz_LinkedList.
linkedList | A pointer to the linked list head. |
item | A pointer to the item to prepend to the list. |
void List_AppendList | ( | Lz_LinkedList *const | linkedListDestination, |
Lz_LinkedList *const | linkedListToMove | ||
) |
Move the content of an Lz_LinkedList to the end of an existing Lz_LinkedList.
linkedListDestination | A pointer to the Lz_LinkedList on which to append. |
linkedListToMove | A pointer to the Lz_LinkedList to move. After the operation, this linked list will be empty. |
Lz_LinkedListElement* List_PickFirst | ( | Lz_LinkedList *const | linkedList | ) |
Return the first element of an existing linked list.
This function drops the first element of the list if it exists.
linkedList | A pointer to the linked list head. |
linkedList
is emptylinkedList
is NULL Lz_LinkedListElement* List_PointFirst | ( | const Lz_LinkedList *const | linkedList | ) |
Return a pointer to the first element of an existing linked list.
This function does not drop the first element of the list.
linkedList | A pointer to an existing Lz_LinkedList. |
linkedList
is emptylinkedList
is NULL bool List_IsEmpty | ( | const Lz_LinkedList *const | linkedList | ) |
Test if an Lz_LinkedList is empty.
linkedList | A pointer to the Lz_LinkedList to test. |
linkedList
is emptylinkedList
is NULLlinkedList
contains at least 1 element void List_InsertAfter | ( | Lz_LinkedList *const | linkedList, |
Lz_LinkedListElement *const | listItem, | ||
Lz_LinkedListElement *const | itemToInsert | ||
) |
Insert an element after another in an Lz_LinkedList.
linkedList | A pointer to the LinkedList containing the element listItem on which to insert after. |
listItem | A pointer to an element on which to insert after, already present in the linkedList . |
itemToInsert | A pointer to the item to insert in the list. |
listItem
parameter MUST already be part of the Lz_LinkedList pointed to by parameter linkedList
. No check is performed. void List_InsertBefore | ( | Lz_LinkedList *const | linkedList, |
Lz_LinkedListElement *const | listItem, | ||
Lz_LinkedListElement *const | itemToInsert | ||
) |
Insert an element before another in a Lz_LinkedList.
linkedList | A pointer to the Lz_LinkedList containing the element listItem on which to insert before. |
listItem | A pointer to an element on which to insert before, already present in the linkedList . |
itemToInsert | A pointer to the item to insert in the list. |
listItem
parameter MUST already be part of the Lz_LinkedList pointed to by parameter linkedList
. No check is performed. Lz_LinkedListElement* List_Remove | ( | Lz_LinkedList *const | linkedList, |
Lz_LinkedListElement *const | itemToRemove | ||
) |
Remove an element from an Lz_LinkedList.
linkedList | A pointer to the Lz_LinkedList containing the element to remove. |
itemToRemove | A pointer to the element to remove from the list. |
itemToRemove
before it is removed. This return value must be used to update an iterator when using List_RemovableForEach, in order to allow removing elements from a list while iterating on it.itemToRemove
parameter MUST already be part of the Lz_LinkedList pointed to by parameter linkedList
. No check is performed. Lz_LinkedListElement* List_PointElementAt | ( | const Lz_LinkedList *const | linkedList, |
const size_t | index | ||
) |
Point to an indexed element in an Lz_LinkedList, starting at index 0.
The element will not be removed from the list.
linkedList | A pointer to an Lz_LinkedList. |
index | The index of the element to point. |
void List_InitLinkedList | ( | Lz_LinkedList *const | linkedList | ) |
Initialize an Lz_LinkedList.
linkedList | A pointer to the Lz_LinkedList to initialize. |
void List_InitLinkedListElement | ( | Lz_LinkedListElement *const | item | ) |