squareball  0.2.0.50-8649
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
 
typedef int(* sb_sort_func_t) (const void *a, const void *b)
 
sb_slist_tsb_slist_append (sb_slist_t *l, void *data)
 
sb_slist_tsb_slist_prepend (sb_slist_t *l, void *data)
 
sb_slist_tsb_slist_sort (sb_slist_t *l, sb_sort_func_t cmp)
 
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.

Typedef Documentation

typedef int(* sb_sort_func_t) (const void *a, const void *b)

Function signature for comparision helpers that are used to sort lists. A list of strings could use strcmp(3) as this function.

Parameters
aThe first object to be compared.
bThe second object to be compared.
Returns
Should return 0 if objects are equal, less than 0 if first object is ordered before the second and greater than 0 if the second object is ordered before the first object.

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.
sb_slist_t* sb_slist_sort ( sb_slist_t l,
sb_sort_func_t  cmp 
)

Function that sorts a singly-linked list.

Parameters
lThe singly-linked list.
cmpThe comparision helper function.
Returns
The singly-linked list itself, a pointer to the new start node.