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 #ifndef UCX_LIST_H
37 #define UCX_LIST_H
38
39 #include "common.h"
40 #include "collection.h"
41
42 #ifdef __cplusplus
43 extern "C" {
44 #endif
45
46
47
48
49 typedef struct cx_list_class_s cx_list_class;
50
51
52
53
54 struct cx_list_s {
55 CX_COLLECTION_BASE;
56
57
58
59 cx_list_class
const *cl;
60
61
62
63 cx_list_class
const *climpl;
64 };
65
66
67
68
69 struct cx_list_class_s {
70
71
72
73
74
75
76 void (*destructor)(
struct cx_list_s *list);
77
78
79
80
81
82 int (*insert_element)(
83 struct cx_list_s *list,
84 size_t index,
85 void const *data
86 );
87
88
89
90
91
92 size_t (*insert_array)(
93 struct cx_list_s *list,
94 size_t index,
95 void const *data,
96 size_t n
97 );
98
99
100
101
102 int (*insert_iter)(
103 struct cx_iterator_s *iter,
104 void const *elem,
105 int prepend
106 );
107
108
109
110
111 int (*remove)(
112 struct cx_list_s *list,
113 size_t index
114 );
115
116
117
118
119 void (*clear)(
struct cx_list_s *list);
120
121
122
123
124 int (*swap)(
125 struct cx_list_s *list,
126 size_t i,
127 size_t j
128 );
129
130
131
132
133 void *(*at)(
134 struct cx_list_s
const *list,
135 size_t index
136 );
137
138
139
140
141 ssize_t (*find_remove)(
142 struct cx_list_s *list,
143 void const *elem,
144 bool remove
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->collection.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->collection.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->collection.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->collection.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 CxIterator *iter,
340 void const *elem
341 ) {
342 return ((
struct cx_list_s *) iter->src_handle.m)->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 CxIterator *iter,
363 void const *elem
364 ) {
365 return ((
struct cx_list_s *) iter->src_handle.m)->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 CxIterator 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 CxIterator 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 CxIterator 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->collection.size -
1, true);
551 }
552
553
554
555
556
557
558
559
560
561
562
563 __attribute__((__nonnull__, __warn_unused_result__))
564 static inline CxIterator cxListMutBackwardsIterator(CxList *list) {
565 return cxListMutBackwardsIteratorAt(list, list->collection.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_remove((CxList*)list, elem, false);
584 }
585
586
587
588
589
590
591
592
593
594
595
596 __attribute__((__nonnull__))
597 static inline
ssize_t cxListFindRemove(
598 CxList *list,
599 void const *elem
600 ) {
601 return list->cl->find_remove(list, elem, true);
602 }
603
604
605
606
607
608
609
610
611 __attribute__((__nonnull__))
612 static inline
void cxListSort(CxList *list) {
613 list->cl->sort(list);
614 }
615
616
617
618
619
620
621 __attribute__((__nonnull__))
622 static inline
void cxListReverse(CxList *list) {
623 list->cl->reverse(list);
624 }
625
626
627
628
629
630
631
632
633
634
635
636
637 __attribute__((__nonnull__))
638 int cxListCompare(
639 CxList
const *list,
640 CxList
const *other
641 );
642
643
644
645
646
647
648
649
650
651
652
653 __attribute__((__nonnull__))
654 void cxListDestroy(CxList *list);
655
656
657
658
659
660
661 extern CxList *
const cxEmptyList;
662
663
664 #ifdef __cplusplus
665 }
666 #endif
667
668 #endif
669