Simple linked-list utility implementation.
More...
#include <sys/types.h>
#include <inttypes.h>
Go to the source code of this file.
|
#define | LLIST_DUPLICATE(ref_llist_dst, llist_src, node_dup_fxn, node_dup_fxn_t, ret_code) |
|
#define | LLIST_RELEASE(ref_llist_head, node_release_fxn, node_type) |
|
Simple linked-list utility implementation.
- Author
- Rafael Antoniello
Definition in file llist.h.
#define LLIST_DUPLICATE |
( |
|
ref_llist_dst, |
|
|
|
llist_src, |
|
|
|
node_dup_fxn, |
|
|
|
node_dup_fxn_t, |
|
|
|
ret_code |
|
) |
| |
Duplicate entire linked list (MACRO).
- Parameters
-
ref_llist_dst | Reference to the pointer to the so-called "head" of the destination list (where the nodes are to be copied). |
Pointer | to the "head" of the list to be copied. |
node_dup_fxn | Pointer to the function to be applied to copy each of the node-elements of the source list. The prototype of this function is: 'node_dup_fxn_t*(node_dup_fxn)(const node_dup_fxn_t)'. |
node_dup_fxn_t | Data type used in function 'node_dup_fxn'. |
ret_code | Status code set as result (refer to 'stat_codes_ctx_t' type). |
- See also
- stat_codes_ctx_t
Definition at line 121 of file llist.h.
#define LLIST_RELEASE |
( |
|
ref_llist_head, |
|
|
|
node_release_fxn, |
|
|
|
node_type |
|
) |
| |
Value:while((*ref_llist_head)!= NULL) {\
void (*_node_release_fxn)(node_type**)= node_release_fxn;\
node_type *node= (node_type*)
llist_pop(ref_llist_head);\
if(node!= NULL) _node_release_fxn(&node);\
}
void * llist_pop(llist_t **ref_llist_head)
Release the entire linked list (MACRO).
- Parameters
-
ref_llist_head | Reference to the pointer to the so-called "head" of the list to be released. |
node_release_fxn | Pointer to the function to be applied to release each of the node-elements of the given list. The prototype of this function is: 'void (*node_release_fxn)(node_type**)'. |
node_type | Data type used in function 'node_release_fxn'. |
Definition at line 165 of file llist.h.
Linked list type structure.
Definition at line 44 of file llist.h.
void* llist_get_nth |
( |
const llist_t * |
llist_head, |
|
|
int |
index |
|
) |
| |
Get the 'Nth' element of the list (does not delete the element).
- Parameters
-
Pointer | to the so-called "head" of the list. Position of the element within the list. |
- Returns
- Pointer to the element if found, NULL otherwise.
Definition at line 113 of file llist.c.
int llist_insert_nth |
( |
llist_t ** |
ref_llist_head, |
|
|
int |
index, |
|
|
void * |
data |
|
) |
| |
Insert the given element in the 'N-th' position of the list. If the given index position is out of bounds, the element will be appended at the end of the list.
- Parameters
-
ref_llist_head | Reference to the pointer to the so-called "head" of the list. If the list is empty, the head pointer should be NULL. Position in which the element is to be inserted within the list. |
data | Pointer to a new data element to be inserted in the list. |
- Returns
- Status code (refer to 'stat_codes_ctx_t' type).
- See also
- stat_codes_ctx_t
Definition at line 137 of file llist.c.
int llist_len |
( |
const llist_t * |
llist_head | ) |
|
Return the number of nodes in a list.
- Parameters
-
Pointer | to the so-called "head" of the list. |
- Returns
- The number of elements in the list is returned. Note that if a NULL pointer is passed by argument, we assume that the linked list is empty (thus, returning zero).
Definition at line 95 of file llist.c.
void* llist_pop |
( |
llist_t ** |
ref_llist_head | ) |
|
Extract the data from the head node of the list, delete the node, and advance the head pointer to point at the next node list.
- Parameters
-
ref_llist_head | Reference to the pointer to the so-called "head" of the list. The head pointer will be updated to point to the next node of the list. |
- Returns
- Data element popped, or NULL in the case of error due to wrong parameter or empty list.
Definition at line 75 of file llist.c.
int llist_push |
( |
llist_t ** |
ref_llist_head, |
|
|
void * |
data |
|
) |
| |
Creates a new link node with the given data and pushes it onto the front of the list.
- Parameters
-
ref_llist_head | Reference to the pointer to the so-called "head" of the list. If the list is empty, the head pointer should be NULL. The head pointer will be updated to the newly created node. |
data | Pointer to a new data element to be inserted in the list. |
- Returns
- Status code (refer to 'stat_codes_ctx_t' type).
- See also
- stat_codes_ctx_t
Definition at line 57 of file llist.c.