squareball  0.2.0.41-ea05
A general-purpose library for C99
sb-slist.h File Reference

Singly-linked list implementation. More...

#include "sb-mem.h"

Go to the source code of this file.

Data Structures

struct  sb_slist_t
 

Functions

sb_slist_tsb_slist_append (sb_slist_t *l, void *data)
 
sb_slist_tsb_slist_prepend (sb_slist_t *l, void *data)
 
void sb_slist_free (sb_slist_t *l)
 
void sb_slist_free_full (sb_slist_t *l, sb_free_func_t free_func)
 
size_t sb_slist_length (sb_slist_t *l)
 

Detailed Description

Singly-linked list implementation.

Function Documentation

sb_slist_t* sb_slist_append ( sb_slist_t l,
void *  data 
)

Function that appends a node to the singly-linked list.

Parameters
lThe singly-linked list.
dataThe pointer to the data that will be stored in the new list node.
Returns
The singly-linked list itself.
Examples:
hello_slist.c.
void sb_slist_free ( sb_slist_t l)

Function that frees all the memory used by the singly-linked list.

Parameters
lThe singly-linked list.
void sb_slist_free_full ( sb_slist_t l,
sb_free_func_t  free_func 
)

Function that frees all the memory used by the singly-linked list, and the data stored in the list nodes, using the provided helper function.

Parameters
lThe singly-linked list.
free_funcHelper function, to free data stored in each node.
Examples:
hello_slist.c.
size_t sb_slist_length ( sb_slist_t l)

Function that counts the number of nodes in the provided singly-linked list.

Parameters
lThe singly-linked list.
Returns
The number of nodes in the singly-linked list.
Examples:
hello_slist.c.
sb_slist_t* sb_slist_prepend ( sb_slist_t l,
void *  data 
)

Function that prepends a node to the singly-linked list.

Parameters
lThe singly-linked list.
dataThe pointer to the data that will be stored in the new list node.
Returns
The singly-linked list itself, a pointer to the new start node.
Examples:
hello_slist.c.