-
Notifications
You must be signed in to change notification settings - Fork 0
/
list.h
67 lines (56 loc) · 1.45 KB
/
list.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
#ifndef CRATE_LIST_H_
#define CRATE_LIST_H_
#include <inttypes.h>
typedef struct dsList {
uint64_t magic;
uint64_t count;
uint64_t headOffset;
} dsList;
typedef struct dsListEntry {
uint64_t magic;
uint64_t prevOffset;
uint64_t nextOffset;
uint64_t dataOffset;
} dsListEntry;
/*
* Allocate and initialize a new list object.
*
* On success, a pointer to the new list object is returned.
* On error, -1 is returned and errno is set appropriately.
*/
dsList *dsListAlloc();
/*
* Initialize an already allocated list object.
*
* On success, zero is returned.
* On error, -1 is returned and errno is set appropriately.
*/
int dsListInit(dsList *list);
/*
* Add a new entry to the list that points to 'data'.
*
* On success, a pointer to the new list entry is returned.
* On error, NULL is returned and errno is set appropriately.
*/
dsListEntry *dsListAdd(dsList *list, void *data);
/*
* Remove the first entry that points to 'data'.
*
* On success, zero is returned.
* On error, -1 is returned and errno is set appropriately.
*/
int dsListDel(dsList *list, void *data);
/*
* Get a count of how many entries are in the list.
*
* On success, the number of entries in the list is returned.
* On error, -1 is returned and errno is set appropriately.
*/
uint64_t dsListCount(dsList *list);
/*
* Iterator functions.
*/
dsListEntry *dsListBegin(dsList *list);
dsListEntry *dsListNext(dsListEntry *entry);
void *dsListData(dsListEntry *entry);
#endif