squareball
0.2.0.53-dd5b
A general-purpose library for C99
|
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_t * | sb_slist_append (sb_slist_t *l, void *data) |
sb_slist_t * | sb_slist_prepend (sb_slist_t *l, void *data) |
sb_slist_t * | sb_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) |
Singly-linked list implementation.
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.
a | The first object to be compared. |
b | The second object to be compared. |
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. sb_slist_t* sb_slist_append | ( | sb_slist_t * | l, |
void * | data | ||
) |
Function that appends a node to the singly-linked list.
l | The singly-linked list. |
data | The pointer to the data that will be stored in the new list node. |
void sb_slist_free | ( | sb_slist_t * | l | ) |
Function that frees all the memory used by the singly-linked list.
l | The 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.
l | The singly-linked list. |
free_func | Helper function, to free data stored in each node. |
size_t sb_slist_length | ( | sb_slist_t * | l | ) |
Function that counts the number of nodes in the provided singly-linked list.
l | The singly-linked list. |
sb_slist_t* sb_slist_prepend | ( | sb_slist_t * | l, |
void * | data | ||
) |
Function that prepends a node to the singly-linked list.
l | The singly-linked list. |
data | The pointer to the data that will be stored in the new list node. |
sb_slist_t* sb_slist_sort | ( | sb_slist_t * | l, |
sb_sort_func_t | cmp | ||
) |
Function that sorts a singly-linked list.
l | The singly-linked list. |
cmp | The comparision helper function. |