Linked list implementation in C
llist.h
exposes two structures: llist
and llist_node
: The former defines a linked list, while the latter references a linked list node.
When initializing a linked list with llist_init
, two optional function can be provided: a comparator function and an equals function. Their type is defined by the comparator
and equal
type.
A typical initialization looks like this:
llist test_list = llist_init(test_compare, test_equals);
The comparator should take two llist_node
s (a
and b
) and return 1
if a < b
, 0
if a == b
and -1
otherwise.
The equals function should return 1 if the provided nodes are the same, 0 otherwise.
all the functions of this library have a standardized return value, described by the LLIST_RETURN
enum.
The possible return values are:
LLIST_SUCCESS
: All goodLLIST_NODE_NOT_FOUND
: The node was not foundLLIST_EQUALS_MISSING
: The equals function is required but was not providedLLIST_COMPARATOR_MISSING
: The comparator function is required but was not providedLLIST_NULL_ARGUMENT
: A given argument has NULL valueLLIST_MALLOC_ERROR
: Error in allocating resourcesLLIST_ERROR
: Generic error
For documentation on other functions, refer to llist.h
which contains specific documentation for all functions.