-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdllist_headers.h
134 lines (77 loc) · 2.91 KB
/
dllist_headers.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/**
* @file dlist_headers.h
* @brief Function prototypes for lists
* @author Dominique LaSalle <[email protected]>
* Copyright (c) 2013-2015, Dominique LaSalle
* @version 1
* @date 2013-10-07
*/
/* prefixing ugliness */
#define DLLIST_PRE2(prefix,suffix) prefix ## _ ## suffix
#define DLLIST_PRE1(prefix,suffix) DLLIST_PRE2(prefix,suffix)
#define DLLIST_PUB(name) DLLIST_PRE1(DLLIST_PREFIX,name)
#define DLLIST_PRI(name) DLLIST_PRE1(_,DLLIST_PRE1(DLLIST_PREFIX,name))
/******************************************************************************
* TYPES ***********************************************************************
******************************************************************************/
#ifdef DLLIST_LINKED
typedef struct DLLIST_PRI(list_node_t) {
struct DLLIST_PRI(list_node_t) * next;
struct DLLIST_PRI(list_node_t) * prev;
DLLIST_TYPE_T val;
} DLLIST_PRI(list_node_t);
#endif
typedef struct DLLIST_PUB(list_t) {
#ifdef DLLIST_LINKED
DLLIST_PRI(list_node_t) * head;
DLLIST_PRI(list_node_t) * tail;
#else
size_t maxsize;
size_t front;
DLLIST_TYPE_T * val;
#endif
size_t size;
} DLLIST_PUB(list_t);
#ifndef DLLIST_STATIC
/******************************************************************************
* FUNCTION PROTOTYPES *********************************************************
******************************************************************************/
#ifdef DLLIST_LINKED
DLLIST_PUB(list_t) * DLLIST_PUB(list_create)(void);
#else
DLLIST_PUB(list_t) * DLLIST_PUB(list_create)(size_t size);
#endif
int DLLIST_PUB(list_add)(DLLIST_TYPE_T item, DLLIST_PUB(list_t) * lst);
int DLLIST_PUB(list_enqueue)(DLLIST_TYPE_T item, DLLIST_PUB(list_t) * lst);
int DLLIST_PUB(list_push)(DLLIST_TYPE_T item, DLLIST_PUB(list_t) * lst);
DLLIST_TYPE_T DLLIST_PUB(list_get)(size_t idx, DLLIST_PUB(list_t) * lst);
DLLIST_TYPE_T DLLIST_PUB(list_peek)(DLLIST_PUB(list_t) * lst);
DLLIST_TYPE_T DLLIST_PUB(list_front)(DLLIST_PUB(list_t) * lst);
DLLIST_TYPE_T DLLIST_PUB(list_remove)(size_t idx, DLLIST_PUB(list_t) * lst);
DLLIST_TYPE_T DLLIST_PUB(list_dequeue)(DLLIST_PUB(list_t) * lst);
DLLIST_TYPE_T DLLIST_PUB(list_pop)(DLLIST_PUB(list_t) * lst);
DLLIST_TYPE_T DLLIST_PUB(list_replace)(DLLIST_TYPE_T item, size_t idx,
DLLIST_PUB(list_t) * lst);
size_t DLLIST_PUB(list_clear)(DLLIST_PUB(list_t) * lst);
ssize_t DLLIST_PUB(list_indexof)(DLLIST_TYPE_T val,
const DLLIST_PUB(list_t) * lst);
int DLLIST_PUB(list_contains)(DLLIST_TYPE_T val,
const DLLIST_PUB(list_t) * lst);
void DLLIST_PUB(list_free)(DLLIST_PUB(list_t) * lst);
#ifdef DLLIST_ARRAY
size_t DLLIST_PUB(list_expand)(DLLIST_PUB(list_t) * lst,
size_t newsize);
#endif
#undef DLLIST_PRE2
#undef DLLIST_PRE1
#undef DLLIST_PUB
#undef DLLIST_PRI
#else
#undef DLLIST_PRE2
#undef DLLIST_PRE1
#undef DLLIST_PUB
#undef DLLIST_PRI
#define DLLIST_VISIBILITY static
#include "dllist_funcs.h"
#undef DLLIST_VISIBILITY
#endif