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