Lely core libraries  2.2.5
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 
31 struct slnode *
32 sllist_pop_back(struct sllist *list)
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 
45 struct slnode *
46 sllist_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 
63 struct slnode *
64 sllist_last(const struct sllist *list)
65 {
66  assert(list);
67 
68  return list->plast != &list->first
69  ? structof(list->plast, struct slnode, next)
70  : NULL;
71 }
pnode
A node in a pairing heap.
Definition: pheap.h:51
sllist.h
slnode::next
struct slnode * next
A pointer to the next node in the list.
Definition: sllist.h:41
util.h
pnode::next
struct pnode * next
A pointer to the next sibling node.
Definition: pheap.h:61
sllist
A singly-linked list.
Definition: sllist.h:51
structof
#define structof(ptr, type, member)
Obtains the address of a structure from the address of one of its members.
Definition: util.h:93
sllist_remove
struct slnode * sllist_remove(struct sllist *list, struct slnode *node)
Removes a node from a singly-linked list.
Definition: sllist.c:46
slnode
A node in a singly-linked list.
Definition: sllist.h:39
sllist_pop_back
struct slnode * sllist_pop_back(struct sllist *list)
Pops a node from the back of a singly-linked list.
Definition: sllist.c:32
sllist_last
struct slnode * sllist_last(const struct sllist *list)
Returns a pointer to the last node in a singly-linked list.
Definition: sllist.c:64