Mention glibc function 'fallocate'.
[gnulib.git] / lib / gl_list.c
1 /* Abstract sequential list data type.
2    Copyright (C) 2006-2008 Free Software Foundation, Inc.
3    Written by Bruno Haible <bruno@clisp.org>, 2006.
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 3 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, see <http://www.gnu.org/licenses/>.  */
17
18 #include <config.h>
19
20 /* Specification.  */
21 #include "gl_list.h"
22
23 #if !HAVE_INLINE
24
25 /* Define all functions of this file as inline accesses to the
26    struct gl_list_implementation.
27    Use #define to avoid a warning because of extern vs. static.  */
28
29 gl_list_t
30 gl_list_create_empty (gl_list_implementation_t implementation,
31                       gl_listelement_equals_fn equals_fn,
32                       gl_listelement_hashcode_fn hashcode_fn,
33                       gl_listelement_dispose_fn dispose_fn,
34                       bool allow_duplicates)
35 {
36   return implementation->create_empty (implementation, equals_fn, hashcode_fn,
37                                        dispose_fn, allow_duplicates);
38 }
39
40 gl_list_t
41 gl_list_create (gl_list_implementation_t implementation,
42                 gl_listelement_equals_fn equals_fn,
43                 gl_listelement_hashcode_fn hashcode_fn,
44                 gl_listelement_dispose_fn dispose_fn,
45                 bool allow_duplicates,
46                 size_t count, const void **contents)
47 {
48   return implementation->create (implementation, equals_fn, hashcode_fn,
49                                  dispose_fn, allow_duplicates, count, contents);
50 }
51
52 size_t
53 gl_list_size (gl_list_t list)
54 {
55   return ((const struct gl_list_impl_base *) list)->vtable
56          ->size (list);
57 }
58
59 const void *
60 gl_list_node_value (gl_list_t list, gl_list_node_t node)
61 {
62   return ((const struct gl_list_impl_base *) list)->vtable
63          ->node_value (list, node);
64 }
65
66 void
67 gl_list_node_set_value (gl_list_t list, gl_list_node_t node, const void *elt)
68 {
69   ((const struct gl_list_impl_base *) list)->vtable
70   ->node_set_value (list, node, elt);
71 }
72
73 gl_list_node_t
74 gl_list_next_node (gl_list_t list, gl_list_node_t node)
75 {
76   return ((const struct gl_list_impl_base *) list)->vtable
77          ->next_node (list, node);
78 }
79
80 gl_list_node_t
81 gl_list_previous_node (gl_list_t list, gl_list_node_t node)
82 {
83   return ((const struct gl_list_impl_base *) list)->vtable
84          ->previous_node (list, node);
85 }
86
87 const void *
88 gl_list_get_at (gl_list_t list, size_t position)
89 {
90   return ((const struct gl_list_impl_base *) list)->vtable
91          ->get_at (list, position);
92 }
93
94 gl_list_node_t
95 gl_list_set_at (gl_list_t list, size_t position, const void *elt)
96 {
97   return ((const struct gl_list_impl_base *) list)->vtable
98          ->set_at (list, position, elt);
99 }
100
101 gl_list_node_t
102 gl_list_search (gl_list_t list, const void *elt)
103 {
104   size_t size = ((const struct gl_list_impl_base *) list)->vtable->size (list);
105   return ((const struct gl_list_impl_base *) list)->vtable
106          ->search_from_to (list, 0, size, elt);
107 }
108
109 gl_list_node_t
110 gl_list_search_from (gl_list_t list, size_t start_index, const void *elt)
111 {
112   size_t size = ((const struct gl_list_impl_base *) list)->vtable->size (list);
113   return ((const struct gl_list_impl_base *) list)->vtable
114          ->search_from_to (list, start_index, size, elt);
115 }
116
117 gl_list_node_t
118 gl_list_search_from_to (gl_list_t list, size_t start_index, size_t end_index, const void *elt)
119 {
120   return ((const struct gl_list_impl_base *) list)->vtable
121          ->search_from_to (list, start_index, end_index, elt);
122 }
123
124 size_t
125 gl_list_indexof (gl_list_t list, const void *elt)
126 {
127   size_t size = ((const struct gl_list_impl_base *) list)->vtable->size (list);
128   return ((const struct gl_list_impl_base *) list)->vtable
129          ->indexof_from_to (list, 0, size, elt);
130 }
131
132 size_t
133 gl_list_indexof_from (gl_list_t list, size_t start_index, const void *elt)
134 {
135   size_t size = ((const struct gl_list_impl_base *) list)->vtable->size (list);
136   return ((const struct gl_list_impl_base *) list)->vtable
137          ->indexof_from_to (list, start_index, size, elt);
138 }
139
140 size_t
141 gl_list_indexof_from_to (gl_list_t list, size_t start_index, size_t end_index, const void *elt)
142 {
143   return ((const struct gl_list_impl_base *) list)->vtable
144          ->indexof_from_to (list, start_index, end_index, elt);
145 }
146
147 gl_list_node_t
148 gl_list_add_first (gl_list_t list, const void *elt)
149 {
150   return ((const struct gl_list_impl_base *) list)->vtable
151          ->add_first (list, elt);
152 }
153
154 gl_list_node_t
155 gl_list_add_last (gl_list_t list, const void *elt)
156 {
157   return ((const struct gl_list_impl_base *) list)->vtable
158          ->add_last (list, elt);
159 }
160
161 gl_list_node_t
162 gl_list_add_before (gl_list_t list, gl_list_node_t node, const void *elt)
163 {
164   return ((const struct gl_list_impl_base *) list)->vtable
165          ->add_before (list, node, elt);
166 }
167
168 gl_list_node_t
169 gl_list_add_after (gl_list_t list, gl_list_node_t node, const void *elt)
170 {
171   return ((const struct gl_list_impl_base *) list)->vtable
172          ->add_after (list, node, elt);
173 }
174
175 gl_list_node_t
176 gl_list_add_at (gl_list_t list, size_t position, const void *elt)
177 {
178   return ((const struct gl_list_impl_base *) list)->vtable
179          ->add_at (list, position, elt);
180 }
181
182 bool
183 gl_list_remove_node (gl_list_t list, gl_list_node_t node)
184 {
185   return ((const struct gl_list_impl_base *) list)->vtable
186          ->remove_node (list, node);
187 }
188
189 bool
190 gl_list_remove_at (gl_list_t list, size_t position)
191 {
192   return ((const struct gl_list_impl_base *) list)->vtable
193          ->remove_at (list, position);
194 }
195
196 bool
197 gl_list_remove (gl_list_t list, const void *elt)
198 {
199   return ((const struct gl_list_impl_base *) list)->vtable
200          ->remove (list, elt);
201 }
202
203 void
204 gl_list_free (gl_list_t list)
205 {
206   ((const struct gl_list_impl_base *) list)->vtable->list_free (list);
207 }
208
209 gl_list_iterator_t
210 gl_list_iterator (gl_list_t list)
211 {
212   return ((const struct gl_list_impl_base *) list)->vtable
213          ->iterator (list);
214 }
215
216 gl_list_iterator_t
217 gl_list_iterator_from_to (gl_list_t list, size_t start_index, size_t end_index)
218 {
219   return ((const struct gl_list_impl_base *) list)->vtable
220          ->iterator_from_to (list, start_index, end_index);
221 }
222
223 bool
224 gl_list_iterator_next (gl_list_iterator_t *iterator,
225                        const void **eltp, gl_list_node_t *nodep)
226 {
227   return iterator->vtable->iterator_next (iterator, eltp, nodep);
228 }
229
230 void
231 gl_list_iterator_free (gl_list_iterator_t *iterator)
232 {
233   iterator->vtable->iterator_free (iterator);
234 }
235
236 gl_list_node_t
237 gl_sortedlist_search (gl_list_t list, gl_listelement_compar_fn compar, const void *elt)
238 {
239   return ((const struct gl_list_impl_base *) list)->vtable
240          ->sortedlist_search (list, compar, elt);
241 }
242
243 gl_list_node_t
244 gl_sortedlist_search_from_to (gl_list_t list, gl_listelement_compar_fn compar, size_t start_index, size_t end_index, const void *elt)
245 {
246   return ((const struct gl_list_impl_base *) list)->vtable
247          ->sortedlist_search_from_to (list, compar, start_index, end_index,
248                                       elt);
249 }
250
251 size_t
252 gl_sortedlist_indexof (gl_list_t list, gl_listelement_compar_fn compar, const void *elt)
253 {
254   return ((const struct gl_list_impl_base *) list)->vtable
255          ->sortedlist_indexof (list, compar, elt);
256 }
257
258 size_t
259 gl_sortedlist_indexof_from_to (gl_list_t list, gl_listelement_compar_fn compar, size_t start_index, size_t end_index, const void *elt)
260 {
261   return ((const struct gl_list_impl_base *) list)->vtable
262          ->sortedlist_indexof_from_to (list, compar, start_index, end_index,
263                                        elt);
264 }
265
266 gl_list_node_t
267 gl_sortedlist_add (gl_list_t list, gl_listelement_compar_fn compar, const void *elt)
268 {
269   return ((const struct gl_list_impl_base *) list)->vtable
270          ->sortedlist_add (list, compar, elt);
271 }
272
273 bool
274 gl_sortedlist_remove (gl_list_t list, gl_listelement_compar_fn compar, const void *elt)
275 {
276   return ((const struct gl_list_impl_base *) list)->vtable
277          ->sortedlist_remove (list, compar, elt);
278 }
279
280 #endif