C Standard Library Extensions  1.2.3
cxslist.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_SLIST_H
21 #define CX_SLIST_H
22 
23 #include <cxmemory.h>
24 
25 CX_BEGIN_DECLS
26 
27 typedef struct _cx_slnode_ *cx_slist_iterator;
28 typedef const struct _cx_slnode_ *cx_slist_const_iterator;
29 
30 typedef struct _cx_slist_ cx_slist;
31 
32 
33 /*
34  * Create, copy and destroy operations
35  */
36 
37 cx_slist *cx_slist_new(void);
38 void cx_slist_delete(cx_slist *);
39 void cx_slist_destroy(cx_slist *, cx_free_func);
40 
41 /*
42  * Nonmodifying operations
43  */
44 
45 cxsize cx_slist_size(const cx_slist *);
46 cxbool cx_slist_empty(const cx_slist *);
47 cxsize cx_slist_max_size(const cx_slist *);
48 
49 /*
50  * Assignment operations
51  */
52 
53 void cx_slist_swap(cx_slist *, cx_slist *);
54 cxptr cx_slist_assign(cx_slist *, cx_slist_iterator, cxcptr);
55 
56 /*
57  * Element access
58  */
59 
60 cxptr cx_slist_front(const cx_slist *);
61 cxptr cx_slist_back(const cx_slist *);
62 cxptr cx_slist_get(const cx_slist *, cx_slist_const_iterator);
63 
64 /*
65  * Iterator functions
66  */
67 
68 cx_slist_iterator cx_slist_begin(const cx_slist *);
69 cx_slist_iterator cx_slist_end(const cx_slist *);
70 cx_slist_iterator cx_slist_next(const cx_slist *, cx_slist_const_iterator);
71 
72 /*
73  * Inserting and removing elements
74  */
75 
76 void cx_slist_push_front(cx_slist *, cxcptr);
77 cxptr cx_slist_pop_front(cx_slist *);
78 void cx_slist_push_back(cx_slist *, cxcptr);
79 cxptr cx_slist_pop_back(cx_slist *);
80 
81 cx_slist_iterator cx_slist_insert(cx_slist *, cx_slist_iterator, cxcptr);
82 cx_slist_iterator cx_slist_erase(cx_slist *, cx_slist_iterator, cx_free_func);
83 cxptr cx_slist_extract(cx_slist *, cx_slist_iterator);
84 void cx_slist_remove(cx_slist *, cxcptr);
85 void cx_slist_clear(cx_slist *);
86 
87 /*
88  * Splice functions
89  */
90 
91 void cx_slist_unique(cx_slist *, cx_compare_func);
92 void cx_slist_splice(cx_slist *, cx_slist_iterator, cx_slist *,
93  cx_slist_iterator, cx_slist_iterator);
94 void cx_slist_merge(cx_slist *, cx_slist *, cx_compare_func);
95 void cx_slist_sort(cx_slist *, cx_compare_func);
96 void cx_slist_reverse(cx_slist *);
97 
98 CX_END_DECLS
99 
100 #endif /* CX_SLIST_H */
cx_slist_merge
void cx_slist_merge(cx_slist *list1, cx_slist *list2, cx_compare_func compare)
Merge two sorted lists.
Definition: cxslist.c:1358
cx_slist_empty
cxbool cx_slist_empty(const cx_slist *list)
Check whether a list is empty.
Definition: cxslist.c:689
cx_slist_swap
void cx_slist_swap(cx_slist *list1, cx_slist *list2)
Swap the data of two lists.
Definition: cxslist.c:850
cx_slist_back
cxptr cx_slist_back(const cx_slist *list)
Get the last element of a list.
Definition: cxslist.c:934
cx_slist_clear
void cx_slist_clear(cx_slist *list)
Remove all elements from a list.
Definition: cxslist.c:660
cx_slist_new
cx_slist * cx_slist_new(void)
Create a new list without any elements.
Definition: cxslist.c:710
cx_slist_get
cxptr cx_slist_get(const cx_slist *list, cx_slist_const_iterator position)
Get the data at a given iterator position.
Definition: cxslist.c:962
cx_slist_splice
void cx_slist_splice(cx_slist *tlist, cx_slist_iterator position, cx_slist *slist, cx_slist_iterator first, cx_slist_iterator last)
Move a range of list elements in front of a given position.
Definition: cxslist.c:1295
cx_malloc
cxptr cx_malloc(cxsize nbytes)
Allocate nbytes bytes.
Definition: cxmemory.c:280
cx_slist_sort
void cx_slist_sort(cx_slist *list, cx_compare_func compare)
Sort all elements of a list using the given comparison function.
Definition: cxslist.c:1389
cx_slist_max_size
cxsize cx_slist_max_size(const cx_slist *list)
Get the maximum number of list elements possible.
Definition: cxslist.c:825
cx_slist_delete
void cx_slist_delete(cx_slist *list)
Destroy a list.
Definition: cxslist.c:734
cx_slist_pop_back
cxptr cx_slist_pop_back(cx_slist *list)
Remove the last element of a list.
Definition: cxslist.c:1179
cx_slist_extract
cxptr cx_slist_extract(cx_slist *list, cx_slist_iterator position)
Extract a list element.
Definition: cxslist.c:1125
cx_slist_begin
cx_slist_iterator cx_slist_begin(const cx_slist *list)
Get list iterator to the beginning of a list.
Definition: cxslist.c:580
cx_slist_insert
cx_slist_iterator cx_slist_insert(cx_slist *list, cx_slist_iterator position, cxcptr data)
Insert data into a list at a given iterator position.
Definition: cxslist.c:990
cx_free
void cx_free(cxptr memory)
Memory block deallocation.
Definition: cxmemory.c:486
cx_slist_assign
cxptr cx_slist_assign(cx_slist *list, cx_slist_iterator position, cxcptr data)
Assign data to a list position.
Definition: cxslist.c:879
cx_slist_reverse
void cx_slist_reverse(cx_slist *list)
Reverse the order of all list elements.
Definition: cxslist.c:1413
cx_slist_front
cxptr cx_slist_front(const cx_slist *list)
Get the first element of a list.
Definition: cxslist.c:910
cx_slist_destroy
void cx_slist_destroy(cx_slist *list, cx_free_func deallocate)
Destroy a list and all its elements.
Definition: cxslist.c:762
cx_slist_push_back
void cx_slist_push_back(cx_slist *list, cxcptr data)
Append data at the end of a list.
Definition: cxslist.c:1059
cx_slist_next
cx_slist_iterator cx_slist_next(const cx_slist *list, cx_slist_const_iterator position)
Get a list iterator to the next list element.
Definition: cxslist.c:632
cx_slist_push_front
void cx_slist_push_front(cx_slist *list, cxcptr data)
Insert data at the beginning of a list.
Definition: cxslist.c:1029
cx_slist_erase
cx_slist_iterator cx_slist_erase(cx_slist *list, cx_slist_iterator position, cx_free_func deallocate)
Erase a list list element.
Definition: cxslist.c:1091
cx_slist_size
cxsize cx_slist_size(const cx_slist *list)
Get the actual number of list elements.
Definition: cxslist.c:803
cx_slist_unique
void cx_slist_unique(cx_slist *list, cx_compare_func compare)
Remove duplicates of consecutive elements.
Definition: cxslist.c:1247
cx_slist_end
cx_slist_iterator cx_slist_end(const cx_slist *list)
Get a list iterator to the end of a list.
Definition: cxslist.c:604
cx_slist_remove
void cx_slist_remove(cx_slist *list, cxcptr data)
Remove all elements with a given value from a list.
Definition: cxslist.c:1207
cx_slist_pop_front
cxptr cx_slist_pop_front(cx_slist *list)
Remove the first list element.
Definition: cxslist.c:1150