Linked list
API
#include <ds/llist.h>
Handle
-
struct llist
A node in a slingly linked list.
![digraph llist {
layout = "circo"
node [shape=record]
head[label="head|<n>"]
next[label="next|<n>"]
null[label="nil" shape="diamond"]
head:n -> next
next:n -> null
}](../../_images/graphviz-351b3324144b00d1beb7457a3f1dcc0919c3b080.png)
Nodes have no associated data and should be embedded onto containers instead.
See also
Functions
-
void llist_append(struct llist *p, struct llist *el)
Appends a node to the end of the list.
- Parameters:
p – Handle to the list.
el – Handle to the node to append.
-
struct llist *llist_search(struct llist *p, data *el, int (*cmp)(data*, data*))
Finds an element on the list and returns a handle to it value, if it exists.
Finds the node that compares equally to the given element, if it exists. Returns null otherwise. The comparator receives a pointer to the given element, and a pointer to the key being compared, respectively.
- Parameters:
p – Handle to the list.
el – Handle to the element to search for.
cmp – Search comparator.
-
bool llist_delete(struct llist **p, data *el, int (*cmp)(data*, data*))
Finds and deletes a node from the list.
Finds the node that compares equally to the given element and deletes it, if it exists. Does not change the list if the node doesn’t exist. The comparator receives a pointer to the given element, and a pointer to the key being compared, respectively.
- Parameters:
p – Handle to the tree.
key – Handle to the key to delete.
cmp – Deletion comparator.
- Returns:
Whether or not the value was on the list.
Macros
-
llist_foreach(ctype, member, iterator, p)
Loop through each element of the list.
Loops through each element of the list, assigning the container of the current element to an iterator.
- Parameters:
ctype – Type of the container.
member – Member of the container that holds the list node.
iterator – Where to store the current element.
p – Handle to the list.