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 #ifndef UCX_ARRAY_LIST_H
39 #define UCX_ARRAY_LIST_H
40
41 #include "list.h"
42
43 #ifdef __cplusplus
44 extern "C" {
45 #endif
46
47
48
49
50 extern unsigned cx_array_swap_sbo_size;
51
52
53
54
55
56
57
58
59 #define CX_ARRAY_DECLARE(type, name) \
60 type * name; \
61 size_t name##_size; \
62 size_t name##_capacity
63
64
65
66
67
68
69
70
71 #define cx_array_initialize(array, capacity) \
72 array##_capacity = capacity; \
73 array##_size =
0; \
74 array = malloc(
sizeof(array[
0]) * capacity)
75
76
77
78
79 struct cx_array_reallocator_s {
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95 void *(*realloc)(
96 void *array,
97 size_t capacity,
98 size_t elem_size,
99 struct cx_array_reallocator_s *alloc
100 );
101
102
103
104
105 void *ptr1;
106
107
108
109 void *ptr2;
110
111
112
113 size_t int1;
114
115
116
117 size_t int2;
118 };
119
120
121
122
123 extern struct cx_array_reallocator_s *cx_array_default_reallocator;
124
125
126
127
128 enum cx_array_result {
129 CX_ARRAY_SUCCESS,
130 CX_ARRAY_REALLOC_NOT_SUPPORTED,
131 CX_ARRAY_REALLOC_FAILED,
132 };
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159 enum cx_array_result cx_array_copy(
160 void **target,
161 size_t *size,
162 size_t *capacity,
163 size_t index,
164 void const *src,
165 size_t elem_size,
166 size_t elem_count,
167 struct cx_array_reallocator_s *reallocator
168 ) __attribute__((__nonnull__(
1,
2,
5)));
169
170
171
172
173
174
175
176
177
178 #define cx_array_simple_copy(array, index, src, count) \
179 cx_array_copy((
void**)&(array), &(array##_size), &(array##_capacity), \
180 index, src,
sizeof((array)[
0]), count, cx_array_default_reallocator)
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201 #define cx_array_add(target, size, capacity, elem_size, elem, reallocator) \
202 cx_array_copy((
void**)(target), size, capacity, *(size), elem, elem_size,
1, reallocator)
203
204
205
206
207
208
209
210 #define cx_array_simple_add(array, elem) \
211 cx_array_simple_copy(array, array##_size, &(elem),
1)
212
213
214
215
216
217
218
219
220
221 void cx_array_swap(
222 void *arr,
223 size_t elem_size,
224 size_t idx1,
225 size_t idx2
226 ) __attribute__((__nonnull__));
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244 CxList *cxArrayListCreate(
245 CxAllocator
const *allocator,
246 cx_compare_func comparator,
247 size_t elem_size,
248 size_t initial_capacity
249 );
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266 #define cxArrayListCreateSimple(elem_size, initial_capacity) \
267 cxArrayListCreate(
NULL,
NULL, elem_size, initial_capacity)
268
269 #ifdef __cplusplus
270 }
271 #endif
272
273 #endif
274