EII Message Bus C Reference
Classes | Macros | Typedefs | Enumerations | Functions
linkedlist.h File Reference

C singly linked list. More...

#include <stdbool.h>

Go to the source code of this file.

Classes

struct  _node_t
 
struct  linkedlist_t
 

Macros

#define LINKEDLIST_FOREACH(LL, VALUE_TYPE, CODE)
 

Typedefs

typedef struct _node_t node_t
 

Enumerations

enum  linkedlist_ret_t { LL_SUCCESS = 0, LL_ERR_APPEND = 1, LL_ERR_NOT_FOUND = 2 }
 

Functions

linkedlist_tlinkedlist_new ()
 
node_tlinkedlist_node_new (void *value, void(*free_fn)(void *))
 
linkedlist_ret_t linkedlist_add (linkedlist_t *ll, node_t *node)
 
node_tlinkedlist_get_at (linkedlist_t *ll, int idx)
 
linkedlist_ret_t linkedlist_remove_at (linkedlist_t *ll, int idx)
 
void linkedlist_destroy (linkedlist_t *ll)
 

Detailed Description

C singly linked list.

Macro Definition Documentation

◆ LINKEDLIST_FOREACH

#define LINKEDLIST_FOREACH (   LL,
  VALUE_TYPE,
  CODE 
)
Value:
{ \
node_t* curr = LL->root; \
while(curr != NULL) { \
VALUE_TYPE* value = (VALUE_TYPE*) curr->value; \
CODE \
curr = curr->next; \
} \
}

Helper macro to loop through each linked list value.

Note
A variable value will be available that is casted to the underlying type for the void* in the node given via the VALUE_TYPE parameter.
Parameters
LL- Linked list to loop through
VALUE_TYPE- Type to cast the void* to
CODE- Code block to execute for each node

Typedef Documentation

◆ node_t

typedef struct _node_t node_t

Linked list node type.

Enumeration Type Documentation

◆ linkedlist_ret_t

Return types for the linked list.

Function Documentation

◆ linkedlist_add()

linkedlist_ret_t linkedlist_add ( linkedlist_t ll,
node_t node 
)

Add new item onto the end of the linked list.

Parameters
ll- Linked list
node- Node to be appended
Returns
linkedlist_ret_t

◆ linkedlist_destroy()

void linkedlist_destroy ( linkedlist_t ll)

Destroy the given linked list freeing all of its memory (including all of the node's memory).

Parameters
ll- Linked list to destroy

◆ linkedlist_get_at()

node_t* linkedlist_get_at ( linkedlist_t ll,
int  idx 
)

Get node at index from the linked list.

Parameters
ll- Linked list
idx- Index from which to get the element
Returns
node_t, or NULL if not found

◆ linkedlist_new()

linkedlist_t* linkedlist_new ( )

Create a new linked list.

Returns
linkedlist_t, or NULL if an error occurs

◆ linkedlist_node_new()

node_t* linkedlist_node_new ( void *  value,
void(*)(void *)  free_fn 
)

Create a new node for the linked list.

◆ linkedlist_remove_at()

linkedlist_ret_t linkedlist_remove_at ( linkedlist_t ll,
int  idx 
)

Remove item at the given index from the linked list.

Parameters
ll- Linked list
idx- Index at which to remove a node