list.h
Go to the documentation of this file.
/*
Copyright (C) 2022 The University of Notre Dame
This software is distributed under the GNU General Public License.
See the file COPYING for details.
*/
#ifndef LIST_H
#define LIST_H
#include <limits.h>
#include <stdbool.h>
/*
It turns out that many libraries and tools make use of
symbols like "debug" and "fatal". This causes strange
failures when we link against such codes. Rather than change
all of our code, we simply insert these defines to
transparently modify the linker namespace we are using.
*/
#ifndef DOXYGEN
#define list_create cctools_list_create
#define list_destroy cctools_list_destroy
#define list_length cctools_list_length
#define list_cursor_create cctools_list_cursor_create
#define list_cursor_destroy cctools_list_cursor_destroy
#define list_cursor_clone cctools_list_cursor_clone
#define list_reset cctools_list_reset
#define list_seek cctools_list_seek
#define list_tell cctools_list_tell
#define list_next cctools_list_next
#define list_prev cctools_list_prev
#define list_get cctools_list_get
#define list_set cctools_list_set
#define list_drop cctools_list_drop
#define list_insert cctools_list_insert
#define list_size cctools_list_size
#define list_delete cctools_list_delete
#define list_free cctools_list_free
#define list_pop_head cctools_list_pop_head
#define list_peek_head cctools_list_peek_head
#define list_pop_tail cctools_list_pop_tail
#define list_peek_tail cctools_list_peek_tail
#define list_peek_current cctools_list_peek_current
#define list_remove cctools_list_remove
#define list_find cctools_list_find
#define list_splice cctools_list_splice
#define list_split cctools_list_split
#define list_push_head cctools_list_push_head
#define list_push_tail cctools_list_push_tail
#define list_push_priority cctools_list_push_priority
#define list_iterate cctools_list_iterate
#define list_iterate_reverse cctools_list_iterate_reverse
#define list_first_item cctools_list_first_item
#define list_next_item cctools_list_next_item
#endif
struct list *list_create(void);
bool list_destroy(struct list *list);
unsigned list_length(struct list *list);
struct list_cursor *list_cursor_create(struct list *list);
void list_cursor_destroy(struct list_cursor *cur);
struct list_cursor *list_cursor_clone(struct list_cursor *cur);
void list_reset(struct list_cursor *cur);
bool list_seek(struct list_cursor *cur, int index);
bool list_tell(struct list_cursor *cur, unsigned *index);
bool list_next(struct list_cursor *cur);
bool list_prev(struct list_cursor *cur);
bool list_get(struct list_cursor *cur, void **item);
bool list_set(struct list_cursor *cur, void *item);
bool list_drop(struct list_cursor *cur);
void list_insert(struct list_cursor *cur, void *item);
// Utility functions
typedef int (*list_op_t) (void *item, const void *arg);
typedef double (*list_priority_t) (void *item);
int list_size(struct list *list);
struct list *list_duplicate(struct list *list);
void list_delete(struct list *list);
void list_free(struct list *list);
void list_clear(struct list *list, void (*delete_func)(void*item) );
struct list *list_splice(struct list *top, struct list *bottom);
struct list *list_split(struct list *src, list_op_t cmp, const void *arg);
int list_push_head(struct list *list, void *item);
void *list_pop_head(struct list *list);
void *list_peek_head(struct list *list);
int list_push_tail(struct list *list, void *item);
void *list_pop_tail(struct list *list);
void *list_rotate(struct list *list);
void *list_peek_tail(struct list *list);
void *list_peek_current(struct list *list);
void list_push_priority(struct list *list, list_priority_t p, void *item);
void *list_find(struct list *list, list_op_t cmp, const void *arg);
void *list_remove(struct list *list, const void *value);
void list_first_item(struct list *list);
void *list_next_item(struct list *list);
int list_iterate(struct list *list, list_op_t op, const void *arg);
int list_iterate_reverse(struct list *list, list_op_t op, const void *arg);
struct list *list_sort(struct list *list, int (*comparator) (const void *, const void *));
#define LIST_ITERATE( list, item ) list_first_item(list); while((item=list_next_item(list)))
#endif
list_prev
bool list_prev(struct list_cursor *cur)
Move a cursor to the previous item.
list_iterate
int list_iterate(struct list *list, list_op_t op, const void *arg)
Apply a function to a list.
list_next_item
void * list_next_item(struct list *list)
Continue traversing a list.
list_splice
struct list * list_splice(struct list *top, struct list *bottom)
Splice two lists together.
list_cursor_clone
struct list_cursor * list_cursor_clone(struct list_cursor *cur)
Get a copy of an existing cursor.
list_find
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 ...
list_seek
bool list_seek(struct list_cursor *cur, int index)
Move a cursor to an item by index.
list_peek_current
void * list_peek_current(struct list *list)
Peek at the current element in the iteration.
list_drop
bool list_drop(struct list_cursor *cur)
Remove the item under the cursor.
list_push_priority
void list_push_priority(struct list *list, list_priority_t p, void *item)
Push an item onto of a list in priority order.
list_pop_tail
void * list_pop_tail(struct list *list)
Pop an item off of the list tail.
list_sort
struct list * list_sort(struct list *list, int(*comparator)(const void *, const void *))
Sort a list using a comparator function.
list_length
unsigned list_length(struct list *list)
Get the number of items in a list.
list_free
void list_free(struct list *list)
Free every item referred to by the list.
list_split
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 ...
list_first_item
void list_first_item(struct list *list)
Begin traversing a list.
list_tell
bool list_tell(struct list_cursor *cur, unsigned *index)
Get the position of a cursor within a list.
list_peek_head
void * list_peek_head(struct list *list)
Peek at the list head.
list_iterate_reverse
int list_iterate_reverse(struct list *list, list_op_t op, const void *arg)
Apply a function to a list in reverse.
list_create
struct list * list_create(void)
Create an empty linked list.
list_pop_head
void * list_pop_head(struct list *list)
Pop an item off of the list head.
list_clear
void list_clear(struct list *list, void(*delete_func)(void *item))
Delete every item contained within this list, using the provided function.
list_delete
void list_delete(struct list *list)
Delete a linked list.
list_peek_tail
void * list_peek_tail(struct list *list)
Peek at the list tail.
list_push_head
int list_push_head(struct list *list, void *item)
Push an item onto the list head.
list_size
int list_size(struct list *list)
Count the elements in a list.
list_cursor_create
struct list_cursor * list_cursor_create(struct list *list)
Create a new cursor on a list.
list_push_tail
int list_push_tail(struct list *list, void *item)
Push an item onto the list tail.
list_reset
void list_reset(struct list_cursor *cur)
Reset the position of a cursor.
list_remove
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 rem...
list_set
bool list_set(struct list_cursor *cur, void *item)
Set the value under the cursor.
list_rotate
void * list_rotate(struct list *list)
Move the list head to the tail.
list_get
bool list_get(struct list_cursor *cur, void **item)
Get the item under a cursor.
list_next
bool list_next(struct list_cursor *cur)
Move a cursor to the next item.
list_insert
void list_insert(struct list_cursor *cur, void *item)
Insert an item to the left of the cursor.
list_duplicate
struct list * list_duplicate(struct list *list)
Duplicate a linked list Returns a copy of the linked list.
list_destroy
bool list_destroy(struct list *list)
Delete an empty list.
list_cursor_destroy
void list_cursor_destroy(struct list_cursor *cur)
Delete a previously created cursor.