librfn
An ad-hoc utility library
list.h
Go to the documentation of this file.
1 /*
2  * list.h
3  *
4  * Part of librfn (a general utility library from redfelineninja.org.uk)
5  *
6  * Copyright (C) 2013-2014 Daniel Thompson <daniel@redfelineninja.org.uk>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU Lesser General Public License as published
10  * by the Free Software Foundation; either version 3 of the License, or
11  * (at your option) any later version.
12  */
13 
14 #ifndef RF_LIST_H_
15 #define RF_LIST_H_
16 
17 #include <stdbool.h>
18 #include <stdint.h>
19 
34 typedef struct list_node {
35  struct list_node *next;
36 } list_node_t;
37 #define LIST_NODE_VAR_INIT { 0 }
38 
39 typedef struct {
42 } list_t;
43 #define LIST_VAR_INIT { 0 }
44 
45 typedef struct {
49 
51 
52 /*
53  * insertion operations
54  */
55 
56 void list_insert(list_t *list, list_node_t *node);
57 void list_insert_sorted(list_t *list, list_node_t *node,
58  list_node_compare_t *nodecmp);
59 void list_push(list_t *list, list_node_t *node);
60 
61 /*
62  * extraction operations
63  */
64 
66 
67 /*
68  * list traversal
69  */
70 
75 
76 /*
77  * search operations
78  */
79 
80 static inline bool list_empty(list_t *list) {
81  return !list->head;
82 }
83 
84 static inline list_node_t * list_peek(list_t *list) {
85  return list->head;
86 }
87 
88 bool list_contains(list_t *list, list_node_t *node, list_iterator_t *iter);
89 bool list_remove(list_t *list, list_node_t *node);
90 
92 #endif // RF_LIST_H_
list_node_t * list_iterate(list_t *list, list_iterator_t *iter)
Definition: list.c:91
Definition: list.h:39
bool list_contains(list_t *list, list_node_t *node, list_iterator_t *iter)
Definition: list.c:155
struct list_node list_node_t
list_node_t * list_iterator_next(list_iterator_t *iter)
Definition: list.c:99
list_t * list
Definition: list.h:47
void list_iterator_insert(list_iterator_t *iter, list_node_t *node)
Definition: list.c:113
struct list_node * next
Definition: list.h:35
int list_node_compare_t(list_node_t *, list_node_t *)
Definition: list.h:50
list_node_t * list_iterator_remove(list_iterator_t *iter)
Definition: list.c:124
list_node_t ** prevnext
Definition: list.h:46
void list_insert(list_t *list, list_node_t *node)
Definition: list.c:21
list_node_t * tail
Definition: list.h:41
Definition: list.h:34
void list_insert_sorted(list_t *list, list_node_t *node, list_node_compare_t *nodecmp)
Definition: list.c:34
list_node_t * head
Definition: list.h:40
list_node_t * list_extract(list_t *list)
Definition: list.c:77
void list_push(list_t *list, list_node_t *node)
Definition: list.c:65
bool list_remove(list_t *list, list_node_t *node)
Definition: list.c:171