cctools
list.h
1 /*
2 Copyright (C) 2018- The University of Notre Dame
3 This software is distributed under the GNU General Public License.
4 See the file COPYING for details.
5 */
6 
35 #ifndef LIST_H
36 #define LIST_H
37 
38 #include <limits.h>
39 #include <stdbool.h>
40 
41 /*
42 It turns out that many libraries and tools make use of
43 symbols like "debug" and "fatal". This causes strange
44 failures when we link against such codes. Rather than change
45 all of our code, we simply insert these defines to
46 transparently modify the linker namespace we are using.
47 */
48 
49 #define list_create cctools_list_create
50 #define list_destroy cctools_list_destroy
51 #define list_length cctools_list_length
52 #define list_cursor_create cctools_list_cursor_create
53 #define list_cursor_destroy cctools_list_cursor_destroy
54 #define list_cursor_clone cctools_list_cursor_clone
55 #define list_reset cctools_list_reset
56 #define list_seek cctools_list_seek
57 #define list_tell cctools_list_tell
58 #define list_next cctools_list_next
59 #define list_prev cctools_list_prev
60 #define list_get cctools_list_get
61 #define list_set cctools_list_set
62 #define list_drop cctools_list_drop
63 #define list_insert cctools_list_insert
64 
65 #define list_size cctools_list_size
66 #define list_delete cctools_list_delete
67 #define list_free cctools_list_free
68 #define list_pop_head cctools_list_pop_head
69 #define list_peek_head cctools_list_peek_head
70 #define list_pop_tail cctools_list_pop_tail
71 #define list_peek_tail cctools_list_peek_tail
72 #define list_peek_current cctools_list_peek_current
73 #define list_remove cctools_list_remove
74 #define list_find cctools_list_find
75 #define list_splice cctools_list_splice
76 #define list_split cctools_list_split
77 #define list_push_head cctools_list_push_head
78 #define list_push_tail cctools_list_push_tail
79 #define list_push_priority cctools_list_push_priority
80 #define list_iterate cctools_list_iterate
81 #define list_iterate_reverse cctools_list_iterate_reverse
82 #define list_first_item cctools_list_first_item
83 #define list_next_item cctools_list_next_item
84 
88 struct list *list_create(void);
89 
99 bool list_destroy(struct list *list);
100 
105 unsigned list_length(struct list *list);
106 
113 struct list_cursor *list_cursor_create(struct list *list);
114 
121 void list_cursor_destroy(struct list_cursor *cur);
122 
129 struct list_cursor *list_cursor_clone(struct list_cursor *cur);
130 
136 void list_reset(struct list_cursor *cur);
137 
148 bool list_seek(struct list_cursor *cur, int index);
149 
161 bool list_tell(struct list_cursor *cur, unsigned *index);
162 
168 bool list_next(struct list_cursor *cur);
169 
175 bool list_prev(struct list_cursor *cur);
176 
186 bool list_get(struct list_cursor *cur, void **item);
187 
196 bool list_set(struct list_cursor *cur, void *item);
197 
206 bool list_drop(struct list_cursor *cur);
207 
215 void list_insert(struct list_cursor *cur, void *item);
216 
217 
218 // Utility functions
219 
220 typedef int (*list_op_t) (void *item, const void *arg);
221 typedef double (*list_priority_t) (void *item);
222 
228 int list_size(struct list *list);
229 
237 struct list *list_duplicate(struct list *list);
238 
245 void list_delete(struct list *list);
246 
252 void list_free(struct list *list);
253 
260 struct list *list_splice(struct list *top, struct list *bottom);
261 
271 struct list *list_split(struct list *src, list_op_t cmp, const void *arg);
272 
278 int list_push_head(struct list *list, void *item);
279 
284 void *list_pop_head(struct list *list);
285 
290 void *list_peek_head(struct list *list);
291 
297 int list_push_tail(struct list *list, void *item);
298 
303 void *list_pop_tail(struct list *list);
304 
309 void *list_peek_tail(struct list *list);
310 
315 void *list_peek_current(struct list *list);
316 
329 void list_push_priority(struct list *list, list_priority_t p, void *item);
330 
339 void *list_find(struct list *list, list_op_t cmp, const void *arg);
340 
348 void *list_remove(struct list *list, const void *value);
349 
356 void list_first_item(struct list *list);
357 
365 void *list_next_item(struct list *list);
366 
374 int list_iterate(struct list *list, list_op_t op, const void *arg);
375 
382 int list_iterate_reverse(struct list *list, list_op_t op, const void *arg);
383 
389 struct list *list_sort(struct list *list, int (*comparator) (const void *, const void *));
390 
391 #endif