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 #ifndef UCX_LIST_H
38 #define UCX_LIST_H
39
40 #include "common.h"
41 #include "collection.h"
42
43 #ifdef __cplusplus
44 extern "C" {
45 #endif
46
47
48
49
50 typedef struct cx_list_class_s cx_list_class;
51
52
53
54
55 struct cx_list_s {
56 CX_COLLECTION_MEMBERS
57
58
59
60 cx_list_class
const *cl;
61
62
63
64 cx_list_class
const *climpl;
65 };
66
67
68
69
70 struct cx_list_class_s {
71
72
73
74
75
76
77 void (*destructor)(
struct cx_list_s *list);
78
79
80
81
82
83 int (*insert_element)(
84 struct cx_list_s *list,
85 size_t index,
86 void const *data
87 );
88
89
90
91
92
93 size_t (*insert_array)(
94 struct cx_list_s *list,
95 size_t index,
96 void const *data,
97 size_t n
98 );
99
100
101
102
103 int (*insert_iter)(
104 struct cx_mut_iterator_s *iter,
105 void const *elem,
106 int prepend
107 );
108
109
110
111
112 int (*remove)(
113 struct cx_list_s *list,
114 size_t index
115 );
116
117
118
119
120 void (*clear)(
struct cx_list_s *list);
121
122
123
124
125 int (*swap)(
126 struct cx_list_s *list,
127 size_t i,
128 size_t j
129 );
130
131
132
133
134 void *(*at)(
135 struct cx_list_s
const *list,
136 size_t index
137 );
138
139
140
141
142 ssize_t (*find)(
143 struct cx_list_s
const *list,
144 void const *elem
145 );
146
147
148
149
150 void (*sort)(
struct cx_list_s *list);
151
152
153
154
155 int (*compare)(
156 struct cx_list_s
const *list,
157 struct cx_list_s
const *other
158 );
159
160
161
162
163 void (*reverse)(
struct cx_list_s *list);
164
165
166
167
168 struct cx_iterator_s (*iterator)(
169 struct cx_list_s
const *list,
170 size_t index,
171 bool backward
172 );
173 };
174
175
176
177
178 typedef struct cx_list_s CxList;
179
180
181
182
183
184
185
186
187
188
189 __attribute__((__nonnull__))
190 void cxListStoreObjects(CxList *list);
191
192
193
194
195
196
197
198
199
200
201
202
203
204 __attribute__((__nonnull__))
205 void cxListStorePointers(CxList *list);
206
207
208
209
210
211
212
213
214 __attribute__((__nonnull__))
215 static inline bool cxListIsStoringPointers(CxList
const *list) {
216 return list->store_pointer;
217 }
218
219
220
221
222
223
224
225 __attribute__((__nonnull__))
226 static inline
size_t cxListSize(CxList
const *list) {
227 return list->size;
228 }
229
230
231
232
233
234
235
236
237
238 __attribute__((__nonnull__))
239 static inline
int cxListAdd(
240 CxList *list,
241 void const *elem
242 ) {
243 return list->cl->insert_element(list, list->size, elem);
244 }
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262 __attribute__((__nonnull__))
263 static inline
size_t cxListAddArray(
264 CxList *list,
265 void const *array,
266 size_t n
267 ) {
268 return list->cl->insert_array(list, list->size, array, n);
269 }
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284 __attribute__((__nonnull__))
285 static inline
int cxListInsert(
286 CxList *list,
287 size_t index,
288 void const *elem
289 ) {
290 return list->cl->insert_element(list, index, elem);
291 }
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312 __attribute__((__nonnull__))
313 static inline
size_t cxListInsertArray(
314 CxList *list,
315 size_t index,
316 void const *array,
317 size_t n
318 ) {
319 return list->cl->insert_array(list, index, array, n);
320 }
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337 __attribute__((__nonnull__))
338 static inline
int cxListInsertAfter(
339 CxMutIterator *iter,
340 void const *elem
341 ) {
342 return ((
struct cx_list_s *) iter->src_handle)->cl->insert_iter(iter, elem,
0);
343 }
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360 __attribute__((__nonnull__))
361 static inline
int cxListInsertBefore(
362 CxMutIterator *iter,
363 void const *elem
364 ) {
365 return ((
struct cx_list_s *) iter->src_handle)->cl->insert_iter(iter, elem,
1);
366 }
367
368
369
370
371
372
373
374
375
376
377
378 __attribute__((__nonnull__))
379 static inline
int cxListRemove(
380 CxList *list,
381 size_t index
382 ) {
383 return list->cl->remove(list, index);
384 }
385
386
387
388
389
390
391
392
393
394 __attribute__((__nonnull__))
395 static inline
void cxListClear(CxList *list) {
396 list->cl->clear(list);
397 }
398
399
400
401
402
403
404
405
406
407
408
409
410 __attribute__((__nonnull__))
411 static inline
int cxListSwap(
412 CxList *list,
413 size_t i,
414 size_t j
415 ) {
416 return list->cl->swap(list, i, j);
417 }
418
419
420
421
422
423
424
425
426 __attribute__((__nonnull__))
427 static inline
void *cxListAt(
428 CxList *list,
429 size_t index
430 ) {
431 return list->cl->at(list, index);
432 }
433
434
435
436
437
438
439
440
441
442
443
444
445 __attribute__((__nonnull__, __warn_unused_result__))
446 static inline CxIterator cxListIteratorAt(
447 CxList
const *list,
448 size_t index
449 ) {
450 return list->cl->iterator(list, index, false);
451 }
452
453
454
455
456
457
458
459
460
461
462
463
464 __attribute__((__nonnull__, __warn_unused_result__))
465 static inline CxIterator cxListBackwardsIteratorAt(
466 CxList
const *list,
467 size_t index
468 ) {
469 return list->cl->iterator(list, index, true);
470 }
471
472
473
474
475
476
477
478
479
480
481
482
483 __attribute__((__nonnull__, __warn_unused_result__))
484 CxMutIterator cxListMutIteratorAt(
485 CxList *list,
486 size_t index
487 );
488
489
490
491
492
493
494
495
496
497
498
499
500
501 __attribute__((__nonnull__, __warn_unused_result__))
502 CxMutIterator cxListMutBackwardsIteratorAt(
503 CxList *list,
504 size_t index
505 );
506
507
508
509
510
511
512
513
514
515
516
517 __attribute__((__nonnull__, __warn_unused_result__))
518 static inline CxIterator cxListIterator(CxList
const *list) {
519 return list->cl->iterator(list,
0, false);
520 }
521
522
523
524
525
526
527
528
529
530
531
532 __attribute__((__nonnull__, __warn_unused_result__))
533 static inline CxMutIterator cxListMutIterator(CxList *list) {
534 return cxListMutIteratorAt(list,
0);
535 }
536
537
538
539
540
541
542
543
544
545
546
547
548 __attribute__((__nonnull__, __warn_unused_result__))
549 static inline CxIterator cxListBackwardsIterator(CxList
const *list) {
550 return list->cl->iterator(list, list->size -
1, true);
551 }
552
553
554
555
556
557
558
559
560
561
562
563 __attribute__((__nonnull__, __warn_unused_result__))
564 static inline CxMutIterator cxListMutBackwardsIterator(CxList *list) {
565 return cxListMutBackwardsIteratorAt(list, list->size -
1);
566 }
567
568
569
570
571
572
573
574
575
576
577
578 __attribute__((__nonnull__))
579 static inline
ssize_t cxListFind(
580 CxList
const *list,
581 void const *elem
582 ) {
583 return list->cl->find(list, elem);
584 }
585
586
587
588
589
590
591
592
593 __attribute__((__nonnull__))
594 static inline
void cxListSort(CxList *list) {
595 list->cl->sort(list);
596 }
597
598
599
600
601
602
603 __attribute__((__nonnull__))
604 static inline
void cxListReverse(CxList *list) {
605 list->cl->reverse(list);
606 }
607
608
609
610
611
612
613
614
615
616
617
618
619 __attribute__((__nonnull__))
620 int cxListCompare(
621 CxList
const *list,
622 CxList
const *other
623 );
624
625
626
627
628
629
630
631
632
633
634
635 __attribute__((__nonnull__))
636 void cxListDestroy(CxList *list);
637
638
639
640
641
642
643 extern CxList *
const cxEmptyList;
644
645
646 #ifdef __cplusplus
647 }
648 #endif
649
650 #endif
651