C Standard Library Extensions  1.2.3
cxlist.h
1 /*
2  * This file is part of the ESO C Extension Library
3  * Copyright (C) 2001-2017 European Southern Observatory
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18  */
19 
20 #ifndef CX_LIST_H
21 #define CX_LIST_H
22 
23 #include <cxmemory.h>
24 
25 CX_BEGIN_DECLS
26 
27 typedef struct _cx_lnode_ *cx_list_iterator;
28 typedef const struct _cx_lnode_ *cx_list_const_iterator;
29 
30 typedef struct _cx_list_ cx_list;
31 
32 
33 /*
34  * Create, copy and destroy operations
35  */
36 
37 cx_list *cx_list_new(void);
38 void cx_list_delete(cx_list *);
39 void cx_list_destroy(cx_list *, cx_free_func);
40 
41 /*
42  * Non-modifying operations
43  */
44 
45 cxsize cx_list_size(const cx_list *);
46 cxbool cx_list_empty(const cx_list *);
47 cxsize cx_list_max_size(const cx_list *);
48 
49 /*
50  * Assignment operations
51  */
52 
53 void cx_list_swap(cx_list *, cx_list *);
54 cxptr cx_list_assign(cx_list *, cx_list_iterator, cxcptr);
55 
56 /*
57  * Element access
58  */
59 
60 cxptr cx_list_front(const cx_list *);
61 cxptr cx_list_back(const cx_list *);
62 cxptr cx_list_get(const cx_list *, cx_list_const_iterator);
63 
64 /*
65  * Iterator functions
66  */
67 
68 cx_list_iterator cx_list_begin(const cx_list *);
69 cx_list_iterator cx_list_end(const cx_list *);
70 cx_list_iterator cx_list_next(const cx_list *, cx_list_const_iterator);
71 cx_list_iterator cx_list_previous(const cx_list *, cx_list_const_iterator);
72 
73 /*
74  * Inserting and removing elements
75  */
76 
77 void cx_list_push_front(cx_list *, cxcptr);
78 cxptr cx_list_pop_front(cx_list *);
79 void cx_list_push_back(cx_list *, cxcptr);
80 cxptr cx_list_pop_back(cx_list *);
81 
82 cx_list_iterator cx_list_insert(cx_list *, cx_list_iterator, cxcptr);
83 cx_list_iterator cx_list_erase(cx_list *, cx_list_iterator, cx_free_func);
84 cxptr cx_list_extract(cx_list *, cx_list_iterator);
85 void cx_list_remove(cx_list *, cxcptr);
86 void cx_list_clear(cx_list *);
87 
88 /*
89  * Splice functions
90  */
91 
92 void cx_list_unique(cx_list *, cx_compare_func);
93 void cx_list_splice(cx_list *, cx_list_iterator, cx_list *,
94  cx_list_iterator, cx_list_iterator);
95 void cx_list_merge(cx_list *, cx_list *, cx_compare_func);
96 void cx_list_sort(cx_list *, cx_compare_func);
97 void cx_list_reverse(cx_list *);
98 
99 CX_END_DECLS
100 
101 #endif /* CX_LIST_H */
void cx_list_delete(cx_list *)
Destroy a list.
Definition: cxlist.c:720
void cx_list_reverse(cx_list *)
Reverse the order of all list elements.
Definition: cxlist.c:1425
void cx_list_merge(cx_list *, cx_list *, cx_compare_func)
Merge two sorted lists.
Definition: cxlist.c:1370
cx_list_iterator cx_list_insert(cx_list *, cx_list_iterator, cxcptr)
Insert data into a list at a given iterator position.
Definition: cxlist.c:992
void cx_list_swap(cx_list *, cx_list *)
Swap the data of two lists.
Definition: cxlist.c:834
void cx_list_sort(cx_list *, cx_compare_func)
Sort all elements of a list using the given comparison function.
Definition: cxlist.c:1401
cxsize cx_list_size(const cx_list *)
Get the actual number of list elements.
Definition: cxlist.c:787
cx_list_iterator cx_list_next(const cx_list *, cx_list_const_iterator)
Get an iterator for the next list element.
Definition: cxlist.c:592
cx_list_iterator cx_list_previous(const cx_list *, cx_list_const_iterator)
Get an iterator for the previous list element.
Definition: cxlist.c:620
cxptr cx_list_front(const cx_list *)
Get the first element of a list.
Definition: cxlist.c:911
void cx_list_splice(cx_list *, cx_list_iterator, cx_list *, cx_list_iterator, cx_list_iterator)
Move a range of list elements in front of a given position.
Definition: cxlist.c:1318
void cx_list_destroy(cx_list *, cx_free_func)
Destroy a list and all its elements.
Definition: cxlist.c:748
cx_list_iterator cx_list_erase(cx_list *, cx_list_iterator, cx_free_func)
Erase a list element.
Definition: cxlist.c:1088
cx_list_iterator cx_list_end(const cx_list *)
Get an iterator for the position after the last list element.
Definition: cxlist.c:566
cxsize cx_list_max_size(const cx_list *)
Get the maximum number of list elements possible.
Definition: cxlist.c:809
void cx_list_remove(cx_list *, cxcptr)
Remove all elements with a given value from a list.
Definition: cxlist.c:1221
cxptr cx_list_get(const cx_list *, cx_list_const_iterator)
Get the data at a given iterator position.
Definition: cxlist.c:964
cxptr cx_list_assign(cx_list *, cx_list_iterator, cxcptr)
Assign data to a list element.
Definition: cxlist.c:877
cx_list * cx_list_new(void)
Create a new list without any elements.
Definition: cxlist.c:696
cxptr cx_list_back(const cx_list *)
Get the last element of a list.
Definition: cxlist.c:939
void cx_list_unique(cx_list *, cx_compare_func)
Remove duplicates of consecutive elements.
Definition: cxlist.c:1265
cxptr cx_list_pop_back(cx_list *)
Remove the last element of a list.
Definition: cxlist.c:1191
void cx_list_push_front(cx_list *, cxcptr)
Insert data at the beginning of a list.
Definition: cxlist.c:1031
cx_list_iterator cx_list_begin(const cx_list *)
Get an iterator for the first list element.
Definition: cxlist.c:542
cxbool cx_list_empty(const cx_list *)
Check whether a list is empty.
Definition: cxlist.c:675
void cx_list_push_back(cx_list *, cxcptr)
Append data at the end of a list.
Definition: cxlist.c:1061
void cx_list_clear(cx_list *)
Remove all elements from a list.
Definition: cxlist.c:648
cxptr cx_list_extract(cx_list *, cx_list_iterator)
Extract a list element.
Definition: cxlist.c:1123
cxptr cx_list_pop_front(cx_list *)
Remove the first list element.
Definition: cxlist.c:1159