cctools
list.h
Go to the documentation of this file.
1 /*
2 Copyright (C) 2003-2004 Douglas Thain and the University of Wisconsin
3 Copyright (C) 2005- The University of Notre Dame
4 This software is distributed under the GNU General Public License.
5 See the file COPYING for details.
6 */
7 
8 #ifndef LIST_H
9 #define LIST_H
10 
13 /*
14 It turns out that many libraries and tools make use of
15 symbols like "debug" and "fatal". This causes strange
16 failures when we link against such codes. Rather than change
17 all of our code, we simply insert these defines to
18 transparently modify the linker namespace we are using.
19 */
20 
21 #define list_delete cctools_list_delete
22 #define list_free cctools_list_free
23 #define list_pop_head cctools_list_pop_head
24 #define list_peek_head cctools_list_peek_head
25 #define list_pop_tail cctools_list_pop_tail
26 #define list_peek_tail cctools_list_peek_tail
27 #define list_peek_current cctools_list_peek_current
28 #define list_remove cctools_list_remove
29 #define list_find cctools_list_find
30 #define list_create cctools_list_create
31 #define list_splice cctools_list_splice
32 #define list_split cctools_list_split
33 #define list_size cctools_list_size
34 #define list_push_priority cctools_list_push_priority
35 #define list_push_head cctools_list_push_head
36 #define list_push_tail cctools_list_push_tail
37 #define list_iterate cctools_list_iterate
38 #define list_iterate_reverse cctools_list_iterate_reverse
39 #define list_first_item cctools_list_first_item
40 #define list_next_item cctools_list_next_item
41 
42 struct list_node {
43  void *data;
44  struct list_node *next;
45  struct list_node *prev;
46  double priority;
47 };
48 
49 struct list {
50  struct list_node *head;
51  struct list_node *tail;
52  struct list_node *iter;
53  int size;
54 };
55 
56 typedef int (*list_op_t) (void *item, const void *arg);
57 
62 struct list *list_create();
63 
71 struct list *list_duplicate(struct list *list);
72 
79 void list_delete(struct list *list);
80 
86 void list_free(struct list *list);
87 
94 struct list *list_splice(struct list *top, struct list *bottom);
95 
105 struct list *list_split(struct list *src, list_op_t cmp, const void *arg);
106 
112 int list_size(struct list *list);
113 
120 int list_push_priority(struct list *list, void *item, double prio);
121 
127 int list_push_head(struct list *list, void *item);
128 
133 void *list_pop_head(struct list *list);
134 
139 void *list_peek_head(struct list *list);
140 
146 int list_push_tail(struct list *list, void *item);
147 
152 void *list_pop_tail(struct list *list);
153 
158 void *list_peek_tail(struct list *list);
159 
164 void *list_peek_current(struct list *list);
165 
174 void *list_find(struct list *list, list_op_t cmp, const void *arg);
175 
183 void *list_remove(struct list *list, const void *value);
184 
191 void list_first_item(struct list *list);
192 
200 void *list_next_item(struct list *list);
201 
209 int list_iterate(struct list *list, list_op_t op, const void *arg);
210 
217 int list_iterate_reverse(struct list *list, list_op_t op, const void *arg);
218 
224 struct list *list_sort(struct list *list, int (*comparator) (const void *, const void *));
225 
226 #endif
struct list * list_duplicate(struct list *list)
Duplicate a linked list Returns a copy of the linked list.
void * list_find(struct list *list, list_op_t cmp, const void *arg)
Find an element within a list This function searches the list, comparing each element in the list to...
int list_push_head(struct list *list, void *item)
Push an item onto the list head.
struct list * list_split(struct list *src, list_op_t cmp, const void *arg)
Split a list into two at the given item If arg is NULL or not found, list_split returns NULL and the...
struct list * list_sort(struct list *list, int(*comparator)(const void *, const void *))
Sort a list using a comparator function.
void list_first_item(struct list *list)
Begin traversing a list.
int list_push_tail(struct list *list, void *item)
Push an item onto the list tail.
void * list_peek_tail(struct list *list)
Peek at the list tail.
struct list * list_create()
Create a new linked list.
void list_delete(struct list *list)
Delete a linked list.
int list_size(struct list *list)
Count the elements in a list.
void * list_pop_tail(struct list *list)
Pop an item off of the list tail.
struct list * list_splice(struct list *top, struct list *bottom)
Splice two lists together.
void * list_peek_head(struct list *list)
Peek at the list head.
int list_iterate_reverse(struct list *list, list_op_t op, const void *arg)
Apply a function to a list in reverse.
Definition: list.h:42
int list_iterate(struct list *list, list_op_t op, const void *arg)
Apply a function to a list.
Definition: list.h:49
int list_push_priority(struct list *list, void *item, double prio)
Push an item in priority order.
void * list_peek_current(struct list *list)
Peek at the current element in the iteration.
void * list_pop_head(struct list *list)
Pop an item off of the list head.
void list_free(struct list *list)
Free every item referred to by the list.
void * list_remove(struct list *list, const void *value)
Remove an item from the list This function searches the list for the item pointed to by value and re...
void * list_next_item(struct list *list)
Continue traversing a list.