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