MediaProcessors
Classes | Macros | Typedefs | Functions
llist.h File Reference

Simple linked-list utility implementation. More...

#include <sys/types.h>
#include <inttypes.h>
Include dependency graph for llist.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  llist_s
 

Macros

#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)
 

Typedefs

typedef struct llist_s llist_t
 

Functions

int llist_push (llist_t **ref_llist_head, void *data)
 
void * llist_pop (llist_t **ref_llist_head)
 
int llist_len (const llist_t *llist_head)
 
void * llist_get_nth (const llist_t *llist_head, int index)
 
int llist_insert_nth (llist_t **ref_llist_head, int index, void *data)
 

Detailed Description

Simple linked-list utility implementation.

Author
Rafael Antoniello

Definition in file llist.h.

Macro Definition Documentation

#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_dstReference to the pointer to the so-called "head" of the destination list (where the nodes are to be copied).
Pointerto the "head" of the list to be copied.
node_dup_fxnPointer 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_tData type used in function 'node_dup_fxn'.
ret_codeStatus 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);\
ASSERT(node== NULL);\
}
void * llist_pop(llist_t **ref_llist_head)
Definition: llist.c:75
#define ASSERT(COND)
Definition: check_utils.h:51

Release the entire linked list (MACRO).

Parameters
ref_llist_headReference to the pointer to the so-called "head" of the list to be released.
node_release_fxnPointer 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_typeData type used in function 'node_release_fxn'.

Definition at line 165 of file llist.h.

Typedef Documentation

typedef struct llist_s llist_t

Linked list type structure.

Definition at line 44 of file llist.h.

Function Documentation

void* llist_get_nth ( const llist_t llist_head,
int  index 
)

Get the 'Nth' element of the list (does not delete the element).

Parameters
Pointerto 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_headReference 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.
dataPointer 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
Pointerto 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_headReference 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_headReference 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.
dataPointer 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.