Lely core libraries 2.3.4
sllist.c
Go to the documentation of this file.
1
24#include "util.h"
25#define LELY_UTIL_SLLIST_INLINE extern inline
26#include <lely/util/sllist.h>
27#include <lely/util/util.h>
28
29#include <assert.h>
30
31struct slnode *
33{
34 assert(list);
35
36 struct slnode **pnode = &list->first;
37 while (*pnode && (*pnode)->next)
38 pnode = &(*pnode)->next;
39 struct slnode *node = *pnode;
40 if (node)
41 *(list->plast = pnode) = NULL;
42 return node;
43}
44
45struct slnode *
46sllist_remove(struct sllist *list, struct slnode *node)
47{
48 assert(list);
49
50 if (node) {
51 struct slnode **pnode = &list->first;
52 while (*pnode && *pnode != node)
53 pnode = &(*pnode)->next;
54 if ((node = *pnode)) {
55 if (!(*pnode = node->next))
56 list->plast = pnode;
57 node->next = NULL;
58 }
59 }
60 return node;
61}
62
63int
64sllist_contains(const struct sllist *list, const struct slnode *node)
65{
66 assert(list);
67
68 if (!node)
69 return 0;
70
71 sllist_foreach (list, node_) {
72 if (node_ == node)
73 return 1;
74 }
75
76 return 0;
77}
78
79struct slnode *
80sllist_last(const struct sllist *list)
81{
82 assert(list);
83
84 return list->plast != &list->first
85 ? structof(list->plast, struct slnode, next)
86 : NULL;
87}
This is the public header file of the utilities library.
#define structof(ptr, type, member)
Obtains the address of a structure from the address of one of its members.
Definition util.h:93
int sllist_contains(const struct sllist *list, const struct slnode *node)
Checks if a node is part of a singly-linked list.
Definition sllist.c:64
struct slnode * sllist_remove(struct sllist *list, struct slnode *node)
Removes a node from a singly-linked list.
Definition sllist.c:46
struct slnode * sllist_last(const struct sllist *list)
Returns a pointer to the last node in a singly-linked list.
Definition sllist.c:80
struct slnode * sllist_pop_back(struct sllist *list)
Pops a node from the back of a singly-linked list.
Definition sllist.c:32
This header file is part of the utilities library; it contains the singly-linked list declarations.
#define sllist_foreach(list, node)
Iterates in order over each node in a singly-linked list.
Definition sllist.h:183
This is the internal header file of the utilities library.
A node in a pairing heap.
Definition pheap.h:52
struct pnode * next
A pointer to the next sibling node.
Definition pheap.h:62
A singly-linked list.
Definition sllist.h:52
A node in a singly-linked list.
Definition sllist.h:40
struct slnode * next
A pointer to the next node in the list.
Definition sllist.h:42