Libft
Custom implementation of core libc functions with additional utility helpers.
Loading...
Searching...
No Matches
Linked List API

Doubly linked list utilities. More...

Functions

t_nodenode_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_nodelist_get_node_n (t_list list, size_t index)
 Gets the node at a specific index in the list.
t_nodelist_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.

Detailed Description

Doubly linked list utilities.

Functions to create, manipulate and traverse doubly linked lists.

Function Documentation

◆ 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
listPointer to the list pointer (borrowed).
new_contentContent for the new node (ownership transferred).
Returns
true on success, false on allocation failure.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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
listPointer to the list pointer (borrowed).
new_contentContent for the new node (ownership transferred).
Returns
true on success, false on allocation failure.
Here is the call graph for this function:

◆ list_get_content()

void * list_get_content ( t_list list,
bool(* select_function )(void *) )

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
listList to search (borrowed).
select_functionFunction 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
listList to search (borrowed).
Returns
Content of last node (borrowed), or NULL if list is empty.
Here is the call graph for this function:

◆ 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
listList to search (borrowed).
indexZero-based index.
Returns
Content at index (borrowed), or NULL if index out of bounds.
Here is the call graph for this function:

◆ list_get_node_last()

t_node * list_get_node_last ( t_list list)

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
listList to search (borrowed).
Returns
Last node (borrowed), or NULL if list is empty.
Here is the caller graph for this function:

◆ list_get_node_n()

t_node * list_get_node_n ( t_list list,
size_t index )

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
listList to search (borrowed).
indexZero-based index.
Returns
Node at index (borrowed), or NULL if index out of bounds.
Here is the caller graph for this function:

◆ list_get_size()

size_t list_get_size ( t_list list)

Calculates the number of nodes in the list.

Parameters
listList to count.
Returns
Number of nodes in the list.

◆ list_iter()

void list_iter ( t_list lst,
void(* )(void *) )

Applies a function to each element of the list.

Parameters
lstList to iterate over (borrowed).
fFunction to apply to each element's content.

◆ list_map()

t_list list_map ( t_list list,
void *(* )(void *),
void(* del )(void *) )

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
listSource list (borrowed).
fFunction to apply to each element (returns new content, owned).
delFunction to delete content on failure.
Returns
New list (owned), or NULL on failure.
Here is the call graph for this function:

◆ list_rm()

void list_rm ( t_list * list,
t_node * node,
void(* del_content )(void *) )

Removes a specific node from the list.

Parameters
listPointer to the list pointer (borrowed).
nodeNode to remove (ownership taken, will be freed).
del_contentFunction to delete the node's content (can be NULL).
Here is the caller graph for this function:

◆ list_rm_all()

void list_rm_all ( t_list * list,
void(* del_content )(void *) )

Removes all nodes from the list.

Parameters
listPointer to the list pointer (set to NULL after).
del_contentFunction to delete each node's content (can be NULL).
Here is the caller graph for this function:

◆ node_free()

void node_free ( t_node ** node,
void(* del_content )(void *) )

Frees a node and optionally its content.

Parameters
nodePointer to the node pointer (set to NULL after freeing).
del_contentFunction to delete the content (can be NULL to skip).

◆ node_new()

t_node * node_new ( void * content,
t_node * prev,
t_node * next )

Creates a new list node.

Note
Ownership of content is transferred to the node on success.
Parameters
contentContent for the new node (ownership transferred).
prevPointer to the previous node (borrowed, can be NULL).
nextPointer to the next node (borrowed, can be NULL).
Returns
Pointer to the new node (owned), or NULL on allocation failure.
Here is the caller graph for this function: