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 const cx_list_class *cl;
60
61
62
63 const cx_list_class *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 const void *data
86 );
87
88
89
90
91
92
93 size_t (*insert_array)(
94 struct cx_list_s *list,
95 size_t index,
96 const void *data,
97 size_t n
98 );
99
100
101
102
103
104
105 size_t (*insert_sorted)(
106 struct cx_list_s *list,
107 const void *sorted_data,
108 size_t n
109 );
110
111
112
113
114 int (*insert_iter)(
115 struct cx_iterator_s *iter,
116 const void *elem,
117 int prepend
118 );
119
120
121
122
123 int (*remove)(
124 struct cx_list_s *list,
125 size_t index
126 );
127
128
129
130
131 void (*clear)(
struct cx_list_s *list);
132
133
134
135
136
137 int (*swap)(
138 struct cx_list_s *list,
139 size_t i,
140 size_t j
141 );
142
143
144
145
146 void *(*at)(
147 const struct cx_list_s *list,
148 size_t index
149 );
150
151
152
153
154 ssize_t (*find_remove)(
155 struct cx_list_s *list,
156 const void *elem,
157 bool remove
158 );
159
160
161
162
163
164 void (*sort)(
struct cx_list_s *list);
165
166
167
168
169
170
171 int (*compare)(
172 const struct cx_list_s *list,
173 const struct cx_list_s *other
174 );
175
176
177
178
179 void (*reverse)(
struct cx_list_s *list);
180
181
182
183
184 struct cx_iterator_s (*iterator)(
185 const struct cx_list_s *list,
186 size_t index,
187 bool backward
188 );
189 };
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205 __attribute__((__nonnull__))
206 size_t cx_list_default_insert_array(
207 struct cx_list_s *list,
208 size_t index,
209 const void *data,
210 size_t n
211 );
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229 __attribute__((__nonnull__))
230 size_t cx_list_default_insert_sorted(
231 struct cx_list_s *list,
232 const void *sorted_data,
233 size_t n
234 );
235
236
237
238
239
240
241
242
243
244
245
246
247 __attribute__((__nonnull__))
248 void cx_list_default_sort(
struct cx_list_s *list);
249
250
251
252
253
254
255
256
257
258
259
260
261
262 __attribute__((__nonnull__))
263 int cx_list_default_swap(
struct cx_list_s *list,
size_t i,
size_t j);
264
265
266
267
268 typedef struct cx_list_s CxList;
269
270
271
272
273
274
275
276
277
278
279 __attribute__((__nonnull__))
280 void cxListStoreObjects(CxList *list);
281
282
283
284
285
286
287
288
289
290
291
292
293
294 __attribute__((__nonnull__))
295 void cxListStorePointers(CxList *list);
296
297
298
299
300
301
302
303
304 __attribute__((__nonnull__))
305 static inline bool cxListIsStoringPointers(
const CxList *list) {
306 return list->collection.store_pointer;
307 }
308
309
310
311
312
313
314
315 __attribute__((__nonnull__))
316 static inline
size_t cxListSize(
const CxList *list) {
317 return list->collection.size;
318 }
319
320
321
322
323
324
325
326
327
328 __attribute__((__nonnull__))
329 static inline
int cxListAdd(
330 CxList *list,
331 const void *elem
332 ) {
333 return list->cl->insert_element(list, list->collection.size, elem);
334 }
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352 __attribute__((__nonnull__))
353 static inline
size_t cxListAddArray(
354 CxList *list,
355 const void *array,
356 size_t n
357 ) {
358 return list->cl->insert_array(list, list->collection.size, array, n);
359 }
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374 __attribute__((__nonnull__))
375 static inline
int cxListInsert(
376 CxList *list,
377 size_t index,
378 const void *elem
379 ) {
380 return list->cl->insert_element(list, index, elem);
381 }
382
383
384
385
386
387
388
389
390 __attribute__((__nonnull__))
391 static inline
int cxListInsertSorted(
392 CxList *list,
393 const void *elem
394 ) {
395 const void *data = list->collection.store_pointer ? &elem : elem;
396 return list->cl->insert_sorted(list, data,
1) ==
0;
397 }
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418 __attribute__((__nonnull__))
419 static inline
size_t cxListInsertArray(
420 CxList *list,
421 size_t index,
422 const void *array,
423 size_t n
424 ) {
425 return list->cl->insert_array(list, index, array, n);
426 }
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445 __attribute__((__nonnull__))
446 static inline
size_t cxListInsertSortedArray(
447 CxList *list,
448 const void *array,
449 size_t n
450 ) {
451 return list->cl->insert_sorted(list, array, n);
452 }
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469 __attribute__((__nonnull__))
470 static inline
int cxListInsertAfter(
471 CxIterator *iter,
472 const void *elem
473 ) {
474 return ((
struct cx_list_s *) iter->src_handle.m)->cl->insert_iter(iter, elem,
0);
475 }
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492 __attribute__((__nonnull__))
493 static inline
int cxListInsertBefore(
494 CxIterator *iter,
495 const void *elem
496 ) {
497 return ((
struct cx_list_s *) iter->src_handle.m)->cl->insert_iter(iter, elem,
1);
498 }
499
500
501
502
503
504
505
506
507
508
509
510 __attribute__((__nonnull__))
511 static inline
int cxListRemove(
512 CxList *list,
513 size_t index
514 ) {
515 return list->cl->remove(list, index);
516 }
517
518
519
520
521
522
523
524
525
526 __attribute__((__nonnull__))
527 static inline
void cxListClear(CxList *list) {
528 list->cl->clear(list);
529 }
530
531
532
533
534
535
536
537
538
539
540
541
542 __attribute__((__nonnull__))
543 static inline
int cxListSwap(
544 CxList *list,
545 size_t i,
546 size_t j
547 ) {
548 return list->cl->swap(list, i, j);
549 }
550
551
552
553
554
555
556
557
558 __attribute__((__nonnull__))
559 static inline
void *cxListAt(
560 CxList *list,
561 size_t index
562 ) {
563 return list->cl->at(list, index);
564 }
565
566
567
568
569
570
571
572
573
574
575
576
577 __attribute__((__nonnull__, __warn_unused_result__))
578 static inline CxIterator cxListIteratorAt(
579 const CxList *list,
580 size_t index
581 ) {
582 return list->cl->iterator(list, index, false);
583 }
584
585
586
587
588
589
590
591
592
593
594
595
596 __attribute__((__nonnull__, __warn_unused_result__))
597 static inline CxIterator cxListBackwardsIteratorAt(
598 const CxList *list,
599 size_t index
600 ) {
601 return list->cl->iterator(list, index, true);
602 }
603
604
605
606
607
608
609
610
611
612
613
614
615 __attribute__((__nonnull__, __warn_unused_result__))
616 CxIterator cxListMutIteratorAt(
617 CxList *list,
618 size_t index
619 );
620
621
622
623
624
625
626
627
628
629
630
631
632
633 __attribute__((__nonnull__, __warn_unused_result__))
634 CxIterator cxListMutBackwardsIteratorAt(
635 CxList *list,
636 size_t index
637 );
638
639
640
641
642
643
644
645
646
647
648
649 __attribute__((__nonnull__, __warn_unused_result__))
650 static inline CxIterator cxListIterator(
const CxList *list) {
651 return list->cl->iterator(list,
0, false);
652 }
653
654
655
656
657
658
659
660
661
662
663
664 __attribute__((__nonnull__, __warn_unused_result__))
665 static inline CxIterator cxListMutIterator(CxList *list) {
666 return cxListMutIteratorAt(list,
0);
667 }
668
669
670
671
672
673
674
675
676
677
678
679
680 __attribute__((__nonnull__, __warn_unused_result__))
681 static inline CxIterator cxListBackwardsIterator(
const CxList *list) {
682 return list->cl->iterator(list, list->collection.size -
1, true);
683 }
684
685
686
687
688
689
690
691
692
693
694
695 __attribute__((__nonnull__, __warn_unused_result__))
696 static inline CxIterator cxListMutBackwardsIterator(CxList *list) {
697 return cxListMutBackwardsIteratorAt(list, list->collection.size -
1);
698 }
699
700
701
702
703
704
705
706
707
708
709
710 __attribute__((__nonnull__))
711 static inline
ssize_t cxListFind(
712 const CxList *list,
713 const void *elem
714 ) {
715 return list->cl->find_remove((CxList*)list, elem, false);
716 }
717
718
719
720
721
722
723
724
725
726
727
728 __attribute__((__nonnull__))
729 static inline
ssize_t cxListFindRemove(
730 CxList *list,
731 const void *elem
732 ) {
733 return list->cl->find_remove(list, elem, true);
734 }
735
736
737
738
739
740
741
742
743 __attribute__((__nonnull__))
744 static inline
void cxListSort(CxList *list) {
745 list->cl->sort(list);
746 }
747
748
749
750
751
752
753 __attribute__((__nonnull__))
754 static inline
void cxListReverse(CxList *list) {
755 list->cl->reverse(list);
756 }
757
758
759
760
761
762
763
764
765
766
767
768
769 __attribute__((__nonnull__))
770 int cxListCompare(
771 const CxList *list,
772 const CxList *other
773 );
774
775
776
777
778
779
780
781
782
783
784
785 __attribute__((__nonnull__))
786 void cxListDestroy(CxList *list);
787
788
789
790
791
792
793 extern CxList *
const cxEmptyList;
794
795
796 #ifdef __cplusplus
797 }
798 #endif
799
800 #endif
801