-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathclist.h
86 lines (67 loc) · 2.39 KB
/
clist.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#ifndef _CLIST_H_
#define _CLIST_H_
#include <sys/types.h>
struct clist;
struct clist_iterator;
/**
* Creates a new circular list with the given capacity and item size.
*/
struct clist *clist_create(size_t capacity, size_t item_sz);
/**
* Creates a new clist iterator.
*/
struct clist_iterator clist_create_iter(void);
/**
* Cleans up data structures and any memory associated with the provided clist
*/
void clist_destroy(struct clist *list);
/**
* Adds a new element to the list by copying the contents pointed to by 'item'
* into the next available space in the list.
*/
ssize_t clist_add(struct clist *list, void *item);
/**
* 'Adds' a new element by returning a pointer to the next available space in
* the list. The element is not cleared, so it may point to
* previously-initialized data.
*/
void *clist_add_new(struct clist *list);
/**
* Retrieves element at the provided index, or NULL if not found. Note that this
* is *NOT* the array index, but rather the circular index (for example, one
* might retrieve index 682 from a circular list that only stores 5 elements).
*/
void *clist_get(struct clist *list, size_t idx);
/**
* Iterates through the provided list, starting with the most recent insertion
* and working backward until the end of the list is reached. Each invocation of
* the function retrieves the next element, with NULL indicating the end of the
* list has been reached. 'iter' is used to track state through the iteration.
*/
void *clist_iterate(struct clist *list, struct clist_iterator *iter);
/**
* Iterates through the provided list, starting with the least-recently inserted
* element and proceeding forward to the beginning (most recent) element of the
* list. NULL indicates the start of the list has been reached. 'iter' is used
* to track state through the iteration.
*/
void *clist_iterate_rev(struct clist *list, struct clist_iterator *iter);
#endif
/*
*
Group 0: (Matthew)
struct clist_iterator clist_create_iter(void);
Group 1:
struct clist *clist_create(size_t capacity, size_t item_sz);
void clist_destroy(struct clist *list);
Group 2:
ssize_t clist_add(struct clist *list, void *item);
Group 3:
void *clist_add_new(struct clist *list);
Group 4:
void *clist_get(struct clist *list, size_t idx);
Group 5:
void *clist_iterate(struct clist *list, struct clist_iterator *iter);
Group 6:
void *clist_iterate_rev(struct clist *list, struct clist_iterator *iter);
*/