Doubly linked list utilities.
More...
|
| t_node * | node_new (void *content, t_node *prev, t_node *next) |
| | Creates a new list node.
|
| |
| void | node_free (t_node **node, void(*del_content)(void *)) |
| | Frees a node and optionally its content.
|
| |
| bool | list_add_end (t_list *list, void *new_content) |
| | Adds a new element at the end of the list.
|
| |
| bool | list_add_start (t_list *list, void *new_content) |
| | Adds a new element at the start of the list.
|
| |
| size_t | list_get_size (t_list list) |
| | Calculates the number of nodes in the list.
|
| |
| void * | list_get_content (t_list list, bool(*select_function)(void *)) |
| | Finds content in list matching a selection function.
|
| |
| void * | list_get_content_n (t_list list, size_t index) |
| | Gets content at a specific index in the list.
|
| |
| void * | list_get_content_last (t_list list) |
| | Gets the content of the last node in the list.
|
| |
| t_node * | list_get_node_n (t_list list, size_t index) |
| | Gets the node at a specific index in the list.
|
| |
| t_node * | list_get_node_last (t_list list) |
| | Gets the last node in the list.
|
| |
| void | list_iter (t_list lst, void(*f)(void *)) |
| | Applies a function to each element of the list.
|
| |
| t_list | list_map (t_list list, void *(*f)(void *), void(*del)(void *)) |
| | Creates a new list by applying a function to each element.
|
| |
| void | list_rm (t_list *list, t_node *node, void(*del_content)(void *)) |
| | Removes a specific node from the list.
|
| |
| void | list_rm_all (t_list *list, void(*del_content)(void *)) |
| | Removes all nodes from the list.
|
| |
Doubly linked list utilities.
Functions to create, manipulate and traverse doubly linked lists.
◆ list_add_end()
| bool list_add_end |
( |
t_list * |
list, |
|
|
void * |
new_content |
|
) |
| |
Adds a new element at the end of the list.
- Note
- Ownership of new_content is transferred to the list on success. On failure, caller retains ownership of new_content.
- Parameters
-
| list | Pointer to the list pointer (borrowed). |
| new_content | Content for the new node (ownership transferred). |
- Returns
- true on success, false on allocation failure.
◆ list_add_start()
| bool list_add_start |
( |
t_list * |
list, |
|
|
void * |
new_content |
|
) |
| |
Adds a new element at the start of the list.
- Note
- Ownership of new_content is transferred to the list on success. On failure, caller retains ownership of new_content.
- Parameters
-
| list | Pointer to the list pointer (borrowed). |
| new_content | Content for the new node (ownership transferred). |
- Returns
- true on success, false on allocation failure.
◆ list_get_content()
| void * list_get_content |
( |
t_list |
list, |
|
|
bool(*)(void *) |
select_function |
|
) |
| |
Finds content in list matching a selection function.
- Note
- Returned pointer is borrowed from the list. Do not free it directly; the list retains ownership. Pointer becomes invalid if node is removed.
- Parameters
-
| list | List to search (borrowed). |
| select_function | Function returning true for desired content. |
- Returns
- Matching content (borrowed), or NULL if not found.
◆ list_get_content_last()
| void * list_get_content_last |
( |
t_list |
list | ) |
|
Gets the content of the last node in the list.
- Note
- Returned pointer is borrowed from the list. Do not free it directly; the list retains ownership. Pointer becomes invalid if node is removed.
- Parameters
-
| list | List to search (borrowed). |
- Returns
- Content of last node (borrowed), or NULL if list is empty.
◆ list_get_content_n()
| void * list_get_content_n |
( |
t_list |
list, |
|
|
size_t |
index |
|
) |
| |
Gets content at a specific index in the list.
- Note
- Returned pointer is borrowed from the list. Do not free it directly; the list retains ownership. Pointer becomes invalid if node is removed.
- Parameters
-
| list | List to search (borrowed). |
| index | Zero-based index. |
- Returns
- Content at index (borrowed), or NULL if index out of bounds.
◆ list_get_node_last()
Gets the last node in the list.
- Note
- Returned pointer is borrowed from the list. Do not free it directly; the list retains ownership. Pointer becomes invalid if node is removed.
- Parameters
-
| list | List to search (borrowed). |
- Returns
- Last node (borrowed), or NULL if list is empty.
◆ list_get_node_n()
Gets the node at a specific index in the list.
- Note
- Returned pointer is borrowed from the list. Do not free it directly; the list retains ownership. Pointer becomes invalid if node is removed.
- Parameters
-
| list | List to search (borrowed). |
| index | Zero-based index. |
- Returns
- Node at index (borrowed), or NULL if index out of bounds.
◆ list_get_size()
| size_t list_get_size |
( |
t_list |
list | ) |
|
Calculates the number of nodes in the list.
- Parameters
-
- Returns
- Number of nodes in the list.
◆ list_iter()
| void list_iter |
( |
t_list |
lst, |
|
|
void(*)(void *) |
f |
|
) |
| |
Applies a function to each element of the list.
- Parameters
-
| lst | List to iterate over (borrowed). |
| f | Function to apply to each element's content. |
◆ list_map()
| t_list list_map |
( |
t_list |
list, |
|
|
void *(*)(void *) |
f, |
|
|
void(*)(void *) |
del |
|
) |
| |
Creates a new list by applying a function to each element.
- Note
- Caller owns the returned list and must free it with list_rm_all.
- Parameters
-
| list | Source list (borrowed). |
| f | Function to apply to each element (returns new content, owned). |
| del | Function to delete content on failure. |
- Returns
- New list (owned), or NULL on failure.
◆ list_rm()
| void list_rm |
( |
t_list * |
list, |
|
|
t_node * |
node, |
|
|
void(*)(void *) |
del_content |
|
) |
| |
Removes a specific node from the list.
- Parameters
-
| list | Pointer to the list pointer (borrowed). |
| node | Node to remove (ownership taken, will be freed). |
| del_content | Function to delete the node's content (can be NULL). |
◆ list_rm_all()
| void list_rm_all |
( |
t_list * |
list, |
|
|
void(*)(void *) |
del_content |
|
) |
| |
Removes all nodes from the list.
- Parameters
-
| list | Pointer to the list pointer (set to NULL after). |
| del_content | Function to delete each node's content (can be NULL). |
◆ node_free()
| void node_free |
( |
t_node ** |
node, |
|
|
void(*)(void *) |
del_content |
|
) |
| |
Frees a node and optionally its content.
- Parameters
-
| node | Pointer to the node pointer (set to NULL after freeing). |
| del_content | Function to delete the content (can be NULL to skip). |
◆ node_new()
Creates a new list node.
- Note
- Ownership of content is transferred to the node on success.
- Parameters
-
| content | Content for the new node (ownership transferred). |
| prev | Pointer to the previous node (borrowed, can be NULL). |
| next | Pointer to the next node (borrowed, can be NULL). |
- Returns
- Pointer to the new node (owned), or NULL on allocation failure.