Mercurial > hg > octave-nkf > gnulib-hg
annotate lib/gl_list.c @ 10001:facc928673d7
Declare rpmatch.
author | Bruno Haible <bruno@clisp.org> |
---|---|
date | Tue, 29 Apr 2008 02:55:59 +0200 |
parents | 25f7280c9cf0 |
children | e0b4f68f21c2 |
rev | line source |
---|---|
6984 | 1 /* Abstract sequential list data type. |
9686
25f7280c9cf0
New abstract list operation 'node_set_value'.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
2 Copyright (C) 2006-2008 Free Software Foundation, Inc. |
6984 | 3 Written by Bruno Haible <bruno@clisp.org>, 2006. |
4 | |
9309
bbbbbf4cd1c5
Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
8438
diff
changeset
|
5 This program is free software: you can redistribute it and/or modify |
6984 | 6 it under the terms of the GNU General Public License as published by |
9309
bbbbbf4cd1c5
Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
8438
diff
changeset
|
7 the Free Software Foundation; either version 3 of the License, or |
bbbbbf4cd1c5
Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
8438
diff
changeset
|
8 (at your option) any later version. |
6984 | 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 | |
9309
bbbbbf4cd1c5
Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
8438
diff
changeset
|
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
6984 | 17 |
7304
1c4ed7637c24
Include <config.h> unconditionally.
Bruno Haible <bruno@clisp.org>
parents:
6984
diff
changeset
|
18 #include <config.h> |
6984 | 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, | |
8438
238942284e2f
Allow the use of a destructor for the values stored in the list.
Bruno Haible <bruno@clisp.org>
parents:
7410
diff
changeset
|
33 gl_listelement_dispose_fn dispose_fn, |
6984 | 34 bool allow_duplicates) |
35 { | |
36 return implementation->create_empty (implementation, equals_fn, hashcode_fn, | |
8438
238942284e2f
Allow the use of a destructor for the values stored in the list.
Bruno Haible <bruno@clisp.org>
parents:
7410
diff
changeset
|
37 dispose_fn, allow_duplicates); |
6984 | 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, | |
8438
238942284e2f
Allow the use of a destructor for the values stored in the list.
Bruno Haible <bruno@clisp.org>
parents:
7410
diff
changeset
|
44 gl_listelement_dispose_fn dispose_fn, |
6984 | 45 bool allow_duplicates, |
46 size_t count, const void **contents) | |
47 { | |
48 return implementation->create (implementation, equals_fn, hashcode_fn, | |
8438
238942284e2f
Allow the use of a destructor for the values stored in the list.
Bruno Haible <bruno@clisp.org>
parents:
7410
diff
changeset
|
49 dispose_fn, allow_duplicates, count, contents); |
6984 | 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 | |
9686
25f7280c9cf0
New abstract list operation 'node_set_value'.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
66 void |
25f7280c9cf0
New abstract list operation 'node_set_value'.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
67 gl_list_node_set_value (gl_list_t list, gl_list_node_t node, const void *elt) |
25f7280c9cf0
New abstract list operation 'node_set_value'.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
68 { |
25f7280c9cf0
New abstract list operation 'node_set_value'.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
69 ((const struct gl_list_impl_base *) list)->vtable |
25f7280c9cf0
New abstract list operation 'node_set_value'.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
70 ->node_set_value (list, node, elt); |
25f7280c9cf0
New abstract list operation 'node_set_value'.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
71 } |
25f7280c9cf0
New abstract list operation 'node_set_value'.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
72 |
6984 | 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 { | |
7405
0de49c40e105
Add searching operations, limited to a subsequence of the list.
Bruno Haible <bruno@clisp.org>
parents:
7304
diff
changeset
|
104 size_t size = ((const struct gl_list_impl_base *) list)->vtable->size (list); |
6984 | 105 return ((const struct gl_list_impl_base *) list)->vtable |
7405
0de49c40e105
Add searching operations, limited to a subsequence of the list.
Bruno Haible <bruno@clisp.org>
parents:
7304
diff
changeset
|
106 ->search_from_to (list, 0, size, elt); |
0de49c40e105
Add searching operations, limited to a subsequence of the list.
Bruno Haible <bruno@clisp.org>
parents:
7304
diff
changeset
|
107 } |
0de49c40e105
Add searching operations, limited to a subsequence of the list.
Bruno Haible <bruno@clisp.org>
parents:
7304
diff
changeset
|
108 |
0de49c40e105
Add searching operations, limited to a subsequence of the list.
Bruno Haible <bruno@clisp.org>
parents:
7304
diff
changeset
|
109 gl_list_node_t |
0de49c40e105
Add searching operations, limited to a subsequence of the list.
Bruno Haible <bruno@clisp.org>
parents:
7304
diff
changeset
|
110 gl_list_search_from (gl_list_t list, size_t start_index, const void *elt) |
0de49c40e105
Add searching operations, limited to a subsequence of the list.
Bruno Haible <bruno@clisp.org>
parents:
7304
diff
changeset
|
111 { |
0de49c40e105
Add searching operations, limited to a subsequence of the list.
Bruno Haible <bruno@clisp.org>
parents:
7304
diff
changeset
|
112 size_t size = ((const struct gl_list_impl_base *) list)->vtable->size (list); |
0de49c40e105
Add searching operations, limited to a subsequence of the list.
Bruno Haible <bruno@clisp.org>
parents:
7304
diff
changeset
|
113 return ((const struct gl_list_impl_base *) list)->vtable |
0de49c40e105
Add searching operations, limited to a subsequence of the list.
Bruno Haible <bruno@clisp.org>
parents:
7304
diff
changeset
|
114 ->search_from_to (list, start_index, size, elt); |
0de49c40e105
Add searching operations, limited to a subsequence of the list.
Bruno Haible <bruno@clisp.org>
parents:
7304
diff
changeset
|
115 } |
0de49c40e105
Add searching operations, limited to a subsequence of the list.
Bruno Haible <bruno@clisp.org>
parents:
7304
diff
changeset
|
116 |
0de49c40e105
Add searching operations, limited to a subsequence of the list.
Bruno Haible <bruno@clisp.org>
parents:
7304
diff
changeset
|
117 gl_list_node_t |
0de49c40e105
Add searching operations, limited to a subsequence of the list.
Bruno Haible <bruno@clisp.org>
parents:
7304
diff
changeset
|
118 gl_list_search_from_to (gl_list_t list, size_t start_index, size_t end_index, const void *elt) |
0de49c40e105
Add searching operations, limited to a subsequence of the list.
Bruno Haible <bruno@clisp.org>
parents:
7304
diff
changeset
|
119 { |
0de49c40e105
Add searching operations, limited to a subsequence of the list.
Bruno Haible <bruno@clisp.org>
parents:
7304
diff
changeset
|
120 return ((const struct gl_list_impl_base *) list)->vtable |
0de49c40e105
Add searching operations, limited to a subsequence of the list.
Bruno Haible <bruno@clisp.org>
parents:
7304
diff
changeset
|
121 ->search_from_to (list, start_index, end_index, elt); |
6984 | 122 } |
123 | |
124 size_t | |
125 gl_list_indexof (gl_list_t list, const void *elt) | |
126 { | |
7405
0de49c40e105
Add searching operations, limited to a subsequence of the list.
Bruno Haible <bruno@clisp.org>
parents:
7304
diff
changeset
|
127 size_t size = ((const struct gl_list_impl_base *) list)->vtable->size (list); |
6984 | 128 return ((const struct gl_list_impl_base *) list)->vtable |
7405
0de49c40e105
Add searching operations, limited to a subsequence of the list.
Bruno Haible <bruno@clisp.org>
parents:
7304
diff
changeset
|
129 ->indexof_from_to (list, 0, size, elt); |
0de49c40e105
Add searching operations, limited to a subsequence of the list.
Bruno Haible <bruno@clisp.org>
parents:
7304
diff
changeset
|
130 } |
0de49c40e105
Add searching operations, limited to a subsequence of the list.
Bruno Haible <bruno@clisp.org>
parents:
7304
diff
changeset
|
131 |
0de49c40e105
Add searching operations, limited to a subsequence of the list.
Bruno Haible <bruno@clisp.org>
parents:
7304
diff
changeset
|
132 size_t |
0de49c40e105
Add searching operations, limited to a subsequence of the list.
Bruno Haible <bruno@clisp.org>
parents:
7304
diff
changeset
|
133 gl_list_indexof_from (gl_list_t list, size_t start_index, const void *elt) |
0de49c40e105
Add searching operations, limited to a subsequence of the list.
Bruno Haible <bruno@clisp.org>
parents:
7304
diff
changeset
|
134 { |
0de49c40e105
Add searching operations, limited to a subsequence of the list.
Bruno Haible <bruno@clisp.org>
parents:
7304
diff
changeset
|
135 size_t size = ((const struct gl_list_impl_base *) list)->vtable->size (list); |
0de49c40e105
Add searching operations, limited to a subsequence of the list.
Bruno Haible <bruno@clisp.org>
parents:
7304
diff
changeset
|
136 return ((const struct gl_list_impl_base *) list)->vtable |
0de49c40e105
Add searching operations, limited to a subsequence of the list.
Bruno Haible <bruno@clisp.org>
parents:
7304
diff
changeset
|
137 ->indexof_from_to (list, start_index, size, elt); |
0de49c40e105
Add searching operations, limited to a subsequence of the list.
Bruno Haible <bruno@clisp.org>
parents:
7304
diff
changeset
|
138 } |
0de49c40e105
Add searching operations, limited to a subsequence of the list.
Bruno Haible <bruno@clisp.org>
parents:
7304
diff
changeset
|
139 |
0de49c40e105
Add searching operations, limited to a subsequence of the list.
Bruno Haible <bruno@clisp.org>
parents:
7304
diff
changeset
|
140 size_t |
0de49c40e105
Add searching operations, limited to a subsequence of the list.
Bruno Haible <bruno@clisp.org>
parents:
7304
diff
changeset
|
141 gl_list_indexof_from_to (gl_list_t list, size_t start_index, size_t end_index, const void *elt) |
0de49c40e105
Add searching operations, limited to a subsequence of the list.
Bruno Haible <bruno@clisp.org>
parents:
7304
diff
changeset
|
142 { |
0de49c40e105
Add searching operations, limited to a subsequence of the list.
Bruno Haible <bruno@clisp.org>
parents:
7304
diff
changeset
|
143 return ((const struct gl_list_impl_base *) list)->vtable |
0de49c40e105
Add searching operations, limited to a subsequence of the list.
Bruno Haible <bruno@clisp.org>
parents:
7304
diff
changeset
|
144 ->indexof_from_to (list, start_index, end_index, elt); |
6984 | 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 | |
7410
9704ff2cbdfe
Add bounded list search operations.
Bruno Haible <bruno@clisp.org>
parents:
7405
diff
changeset
|
243 gl_list_node_t |
9704ff2cbdfe
Add bounded list search operations.
Bruno Haible <bruno@clisp.org>
parents:
7405
diff
changeset
|
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) |
9704ff2cbdfe
Add bounded list search operations.
Bruno Haible <bruno@clisp.org>
parents:
7405
diff
changeset
|
245 { |
9704ff2cbdfe
Add bounded list search operations.
Bruno Haible <bruno@clisp.org>
parents:
7405
diff
changeset
|
246 return ((const struct gl_list_impl_base *) list)->vtable |
9704ff2cbdfe
Add bounded list search operations.
Bruno Haible <bruno@clisp.org>
parents:
7405
diff
changeset
|
247 ->sortedlist_search_from_to (list, compar, start_index, end_index, |
9704ff2cbdfe
Add bounded list search operations.
Bruno Haible <bruno@clisp.org>
parents:
7405
diff
changeset
|
248 elt); |
9704ff2cbdfe
Add bounded list search operations.
Bruno Haible <bruno@clisp.org>
parents:
7405
diff
changeset
|
249 } |
9704ff2cbdfe
Add bounded list search operations.
Bruno Haible <bruno@clisp.org>
parents:
7405
diff
changeset
|
250 |
6984 | 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 | |
7410
9704ff2cbdfe
Add bounded list search operations.
Bruno Haible <bruno@clisp.org>
parents:
7405
diff
changeset
|
258 size_t |
9704ff2cbdfe
Add bounded list search operations.
Bruno Haible <bruno@clisp.org>
parents:
7405
diff
changeset
|
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) |
9704ff2cbdfe
Add bounded list search operations.
Bruno Haible <bruno@clisp.org>
parents:
7405
diff
changeset
|
260 { |
9704ff2cbdfe
Add bounded list search operations.
Bruno Haible <bruno@clisp.org>
parents:
7405
diff
changeset
|
261 return ((const struct gl_list_impl_base *) list)->vtable |
9704ff2cbdfe
Add bounded list search operations.
Bruno Haible <bruno@clisp.org>
parents:
7405
diff
changeset
|
262 ->sortedlist_indexof_from_to (list, compar, start_index, end_index, |
9704ff2cbdfe
Add bounded list search operations.
Bruno Haible <bruno@clisp.org>
parents:
7405
diff
changeset
|
263 elt); |
9704ff2cbdfe
Add bounded list search operations.
Bruno Haible <bruno@clisp.org>
parents:
7405
diff
changeset
|
264 } |
9704ff2cbdfe
Add bounded list search operations.
Bruno Haible <bruno@clisp.org>
parents:
7405
diff
changeset
|
265 |
6984 | 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 |