Lazuli
Functions
list.c File Reference

Linked lists implementation. More...

#include <Lazuli/common.h>
#include <Lazuli/config.h>
#include <Lazuli/list.h>
#include <Lazuli/sys/memory.h>

Go to the source code of this file.

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_LinkedListElementList_PickFirst (Lz_LinkedList *const linkedList)
 Return the first element of an existing linked list. More...
 
Lz_LinkedListElementList_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_LinkedListElementList_Remove (Lz_LinkedList *const linkedList, Lz_LinkedListElement *const itemToRemove)
 Remove an element from an Lz_LinkedList. More...
 
Lz_LinkedListElementList_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...
 

Detailed Description

Linked lists implementation.

This file describes the implementation of generic doubly linked lists.

Definition in file list.c.

Function Documentation

◆ List_Append()

void List_Append ( Lz_LinkedList *const  linkedList,
Lz_LinkedListElement *const  item 
)

Insert an Lz_LinkedListElement as the last element of an existing Lz_LinkedList.

Parameters
linkedListA pointer to the linked list head.
itemA pointer to the item to append to the list.

Definition at line 20 of file list.c.

◆ List_Prepend()

void List_Prepend ( Lz_LinkedList *const  linkedList,
Lz_LinkedListElement *const  item 
)

Insert an Lz_LinkedListElement as the first element of an existing Lz_LinkedList.

Parameters
linkedListA pointer to the linked list head.
itemA pointer to the item to prepend to the list.

Definition at line 44 of file list.c.

◆ List_AppendList()

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.

Parameters
linkedListDestinationA pointer to the Lz_LinkedList on which to append.
linkedListToMoveA pointer to the Lz_LinkedList to move. After the operation, this linked list will be empty.

Definition at line 69 of file list.c.

◆ List_PickFirst()

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.

Parameters
linkedListA pointer to the linked list head.
Returns
A pointer to the first element of the list, or NULL if:
  • The linkedList is empty
  • The parameter linkedList is NULL

Definition at line 96 of file list.c.

◆ List_PointFirst()

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.

Parameters
linkedListA pointer to an existing Lz_LinkedList.
Returns
A pointer to the first element of the list, or NULL if:
  • The linkedList is empty
  • The parameter linkedList is NULL

Definition at line 127 of file list.c.

◆ List_IsEmpty()

bool List_IsEmpty ( const Lz_LinkedList *const  linkedList)

Test if an Lz_LinkedList is empty.

Parameters
linkedListA pointer to the Lz_LinkedList to test.
Returns
  • true if:
    • The linkedList is empty
    • The parameter linkedList is NULL
  • false if:
    • The linkedList contains at least 1 element

Definition at line 139 of file list.c.

◆ List_InsertAfter()

void List_InsertAfter ( Lz_LinkedList *const  linkedList,
Lz_LinkedListElement *const  listItem,
Lz_LinkedListElement *const  itemToInsert 
)

Insert an element after another in an Lz_LinkedList.

Parameters
linkedListA pointer to the LinkedList containing the element listItem on which to insert after.
listItemA pointer to an element on which to insert after, already present in the linkedList.
itemToInsertA pointer to the item to insert in the list.
Warning
The listItem parameter MUST already be part of the Lz_LinkedList pointed to by parameter linkedList. No check is performed.

Definition at line 151 of file list.c.

◆ List_InsertBefore()

void List_InsertBefore ( Lz_LinkedList *const  linkedList,
Lz_LinkedListElement *const  listItem,
Lz_LinkedListElement *const  itemToInsert 
)

Insert an element before another in a Lz_LinkedList.

Parameters
linkedListA pointer to the Lz_LinkedList containing the element listItem on which to insert before.
listItemA pointer to an element on which to insert before, already present in the linkedList.
itemToInsertA pointer to the item to insert in the list.
Warning
The listItem parameter MUST already be part of the Lz_LinkedList pointed to by parameter linkedList. No check is performed.

Definition at line 171 of file list.c.

◆ List_Remove()

Lz_LinkedListElement* List_Remove ( Lz_LinkedList *const  linkedList,
Lz_LinkedListElement *const  itemToRemove 
)

Remove an element from an Lz_LinkedList.

Parameters
linkedListA pointer to the Lz_LinkedList containing the element to remove.
itemToRemoveA pointer to the element to remove from the list.
Returns
A pointer to the previous element of 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.
Warning
The itemToRemove parameter MUST already be part of the Lz_LinkedList pointed to by parameter linkedList. No check is performed.

Definition at line 195 of file list.c.

◆ List_PointElementAt()

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.

Warning
The complexity of this function is O(n), as it is iterative.
Parameters
linkedListA pointer to an Lz_LinkedList.
indexThe index of the element to point.
Returns
A pointer to the indexed Lz_LinkedListElement, or NULL if the index is out of the boundaries of the list.

Definition at line 227 of file list.c.

◆ List_InitLinkedList()

void List_InitLinkedList ( Lz_LinkedList *const  linkedList)

Initialize an Lz_LinkedList.

Parameters
linkedListA pointer to the Lz_LinkedList to initialize.

Definition at line 250 of file list.c.

◆ List_InitLinkedListElement()

void List_InitLinkedListElement ( Lz_LinkedListElement *const  item)

Initialize an Lz_LinkedListElement.

Parameters
itemA pointer to the Lz_LinkedListElement to initialize.

Definition at line 264 of file list.c.