1 /* Abstract sequential list data type.
2 Copyright (C) 2006-2012 Free Software Foundation, Inc.
3 Written by Bruno Haible <bruno@clisp.org>, 2006.
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.
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.
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/>. */
24 _GL_INLINE_HEADER_BEGIN
25 #ifndef GL_LIST_INLINE
26 # define GL_LIST_INLINE _GL_INLINE
34 /* gl_list is an abstract list data type. It can contain any number of
35 objects ('void *' or 'const void *' pointers) in any given order.
36 Duplicates are allowed, but can optionally be forbidden.
38 There are several implementations of this list datatype, optimized for
39 different operations or for memory. You can start using the simplest list
40 implementation, GL_ARRAY_LIST, and switch to a different implementation
41 later, when you realize which operations are performed the most frequently.
42 The API of the different implementations is exactly the same; when
43 switching to a different implementation, you only have to change the
46 The implementations are:
47 GL_ARRAY_LIST a growable array
48 GL_CARRAY_LIST a growable circular array
49 GL_LINKED_LIST a linked list
50 GL_AVLTREE_LIST a binary tree (AVL tree)
51 GL_RBTREE_LIST a binary tree (red-black tree)
52 GL_LINKEDHASH_LIST a hash table with a linked list
53 GL_AVLTREEHASH_LIST a hash table with a binary tree (AVL tree)
54 GL_RBTREEHASH_LIST a hash table with a binary tree (red-black tree)
56 The memory consumption is asymptotically the same: O(1) for every object
57 in the list. When looking more closely at the average memory consumed
58 for an object, GL_ARRAY_LIST is the most compact representation, and
59 GL_LINKEDHASH_LIST and GL_TREEHASH_LIST need more memory.
61 The guaranteed average performance of the operations is, for a list of
64 Operation ARRAY LINKED TREE LINKEDHASH TREEHASH
65 CARRAY with|without with|without
68 gl_list_size O(1) O(1) O(1) O(1) O(1)
69 gl_list_node_value O(1) O(1) O(1) O(1) O(1)
70 gl_list_node_set_value O(1) O(1) O(1) O(1) O((log n)²)/O(1)
71 gl_list_next_node O(1) O(1) O(log n) O(1) O(log n)
72 gl_list_previous_node O(1) O(1) O(log n) O(1) O(log n)
73 gl_list_get_at O(1) O(n) O(log n) O(n) O(log n)
74 gl_list_set_at O(1) O(n) O(log n) O(n) O((log n)²)/O(log n)
75 gl_list_search O(n) O(n) O(n) O(n)/O(1) O(log n)/O(1)
76 gl_list_search_from O(n) O(n) O(n) O(n)/O(1) O((log n)²)/O(log n)
77 gl_list_search_from_to O(n) O(n) O(n) O(n)/O(1) O((log n)²)/O(log n)
78 gl_list_indexof O(n) O(n) O(n) O(n) O(log n)
79 gl_list_indexof_from O(n) O(n) O(n) O(n) O((log n)²)/O(log n)
80 gl_list_indexof_from_to O(n) O(n) O(n) O(n) O((log n)²)/O(log n)
81 gl_list_add_first O(n)/O(1) O(1) O(log n) O(1) O((log n)²)/O(log n)
82 gl_list_add_last O(1) O(1) O(log n) O(1) O((log n)²)/O(log n)
83 gl_list_add_before O(n) O(1) O(log n) O(1) O((log n)²)/O(log n)
84 gl_list_add_after O(n) O(1) O(log n) O(1) O((log n)²)/O(log n)
85 gl_list_add_at O(n) O(n) O(log n) O(n) O((log n)²)/O(log n)
86 gl_list_remove_node O(n) O(1) O(log n) O(n)/O(1) O((log n)²)/O(log n)
87 gl_list_remove_at O(n) O(n) O(log n) O(n) O((log n)²)/O(log n)
88 gl_list_remove O(n) O(n) O(n) O(n)/O(1) O((log n)²)/O(log n)
89 gl_list_iterator O(1) O(1) O(log n) O(1) O(log n)
90 gl_list_iterator_from_to O(1) O(n) O(log n) O(n) O(log n)
91 gl_list_iterator_next O(1) O(1) O(log n) O(1) O(log n)
92 gl_sortedlist_search O(log n) O(n) O(log n) O(n) O(log n)
93 gl_sortedlist_search_from O(log n) O(n) O(log n) O(n) O(log n)
94 gl_sortedlist_indexof O(log n) O(n) O(log n) O(n) O(log n)
95 gl_sortedlist_indexof_fro O(log n) O(n) O(log n) O(n) O(log n)
96 gl_sortedlist_add O(n) O(n) O(log n) O(n) O((log n)²)/O(log n)
97 gl_sortedlist_remove O(n) O(n) O(log n) O(n) O((log n)²)/O(log n)
100 /* -------------------------- gl_list_t Data Type -------------------------- */
102 /* Type of function used to compare two elements.
103 NULL denotes pointer comparison. */
104 typedef bool (*gl_listelement_equals_fn) (const void *elt1, const void *elt2);
106 /* Type of function used to compute a hash code.
107 NULL denotes a function that depends only on the pointer itself. */
108 typedef size_t (*gl_listelement_hashcode_fn) (const void *elt);
110 /* Type of function used to dispose an element once it's removed from a list.
111 NULL denotes a no-op. */
112 typedef void (*gl_listelement_dispose_fn) (const void *elt);
115 /* Type representing an entire list. */
116 typedef struct gl_list_impl * gl_list_t;
118 struct gl_list_node_impl;
119 /* Type representing the position of an element in the list, in a way that
120 is more adapted to the list implementation than a plain index.
121 Note: It is invalidated by insertions and removals! */
122 typedef struct gl_list_node_impl * gl_list_node_t;
124 struct gl_list_implementation;
125 /* Type representing a list datatype implementation. */
126 typedef const struct gl_list_implementation * gl_list_implementation_t;
128 /* Create an empty list.
129 IMPLEMENTATION is one of GL_ARRAY_LIST, GL_CARRAY_LIST, GL_LINKED_LIST,
130 GL_AVLTREE_LIST, GL_RBTREE_LIST, GL_LINKEDHASH_LIST, GL_AVLTREEHASH_LIST,
132 EQUALS_FN is an element comparison function or NULL.
133 HASHCODE_FN is an element hash code function or NULL.
134 DISPOSE_FN is an element disposal function or NULL.
135 ALLOW_DUPLICATES is false if duplicate elements shall not be allowed in
136 the list. The implementation may verify this at runtime. */
137 #if 0 /* declared in gl_xlist.h */
138 extern gl_list_t gl_list_create_empty (gl_list_implementation_t implementation,
139 gl_listelement_equals_fn equals_fn,
140 gl_listelement_hashcode_fn hashcode_fn,
141 gl_listelement_dispose_fn dispose_fn,
142 bool allow_duplicates);
144 /* Likewise. Return NULL upon out-of-memory. */
145 extern gl_list_t gl_list_nx_create_empty (gl_list_implementation_t implementation,
146 gl_listelement_equals_fn equals_fn,
147 gl_listelement_hashcode_fn hashcode_fn,
148 gl_listelement_dispose_fn dispose_fn,
149 bool allow_duplicates);
151 /* Create a list with given contents.
152 IMPLEMENTATION is one of GL_ARRAY_LIST, GL_CARRAY_LIST, GL_LINKED_LIST,
153 GL_AVLTREE_LIST, GL_RBTREE_LIST, GL_LINKEDHASH_LIST, GL_AVLTREEHASH_LIST,
155 EQUALS_FN is an element comparison function or NULL.
156 HASHCODE_FN is an element hash code function or NULL.
157 DISPOSE_FN is an element disposal function or NULL.
158 ALLOW_DUPLICATES is false if duplicate elements shall not be allowed in
159 the list. The implementation may verify this at runtime.
160 COUNT is the number of initial elements.
161 CONTENTS[0..COUNT-1] is the initial contents. */
162 #if 0 /* declared in gl_xlist.h */
163 extern gl_list_t gl_list_create (gl_list_implementation_t implementation,
164 gl_listelement_equals_fn equals_fn,
165 gl_listelement_hashcode_fn hashcode_fn,
166 gl_listelement_dispose_fn dispose_fn,
167 bool allow_duplicates,
168 size_t count, const void **contents);
170 /* Likewise. Return NULL upon out-of-memory. */
171 extern gl_list_t gl_list_nx_create (gl_list_implementation_t implementation,
172 gl_listelement_equals_fn equals_fn,
173 gl_listelement_hashcode_fn hashcode_fn,
174 gl_listelement_dispose_fn dispose_fn,
175 bool allow_duplicates,
176 size_t count, const void **contents);
178 /* Return the current number of elements in a list. */
179 extern size_t gl_list_size (gl_list_t list);
181 /* Return the element value represented by a list node. */
182 extern const void * gl_list_node_value (gl_list_t list, gl_list_node_t node);
184 /* Replace the element value represented by a list node. */
185 #if 0 /* declared in gl_xlist.h */
186 extern void gl_list_node_set_value (gl_list_t list, gl_list_node_t node,
189 /* Likewise. Return 0 upon success, -1 upon out-of-memory. */
190 extern int gl_list_node_nx_set_value (gl_list_t list, gl_list_node_t node,
192 #if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)
193 __attribute__ ((__warn_unused_result__))
197 /* Return the node immediately after the given node in the list, or NULL
198 if the given node is the last (rightmost) one in the list. */
199 extern gl_list_node_t gl_list_next_node (gl_list_t list, gl_list_node_t node);
201 /* Return the node immediately before the given node in the list, or NULL
202 if the given node is the first (leftmost) one in the list. */
203 extern gl_list_node_t gl_list_previous_node (gl_list_t list, gl_list_node_t node);
205 /* Return the element at a given position in the list.
206 POSITION must be >= 0 and < gl_list_size (list). */
207 extern const void * gl_list_get_at (gl_list_t list, size_t position);
209 /* Replace the element at a given position in the list.
210 POSITION must be >= 0 and < gl_list_size (list).
212 #if 0 /* declared in gl_xlist.h */
213 extern gl_list_node_t gl_list_set_at (gl_list_t list, size_t position,
216 /* Likewise. Return NULL upon out-of-memory. */
217 extern gl_list_node_t gl_list_nx_set_at (gl_list_t list, size_t position,
219 #if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)
220 __attribute__ ((__warn_unused_result__))
224 /* Search whether an element is already in the list.
225 Return its node if found, or NULL if not present in the list. */
226 extern gl_list_node_t gl_list_search (gl_list_t list, const void *elt);
228 /* Search whether an element is already in the list,
229 at a position >= START_INDEX.
230 Return its node if found, or NULL if not present in the list. */
231 extern gl_list_node_t gl_list_search_from (gl_list_t list, size_t start_index,
234 /* Search whether an element is already in the list,
235 at a position >= START_INDEX and < END_INDEX.
236 Return its node if found, or NULL if not present in the list. */
237 extern gl_list_node_t gl_list_search_from_to (gl_list_t list,
242 /* Search whether an element is already in the list.
243 Return its position if found, or (size_t)(-1) if not present in the list. */
244 extern size_t gl_list_indexof (gl_list_t list, const void *elt);
246 /* Search whether an element is already in the list,
247 at a position >= START_INDEX.
248 Return its position if found, or (size_t)(-1) if not present in the list. */
249 extern size_t gl_list_indexof_from (gl_list_t list, size_t start_index,
252 /* Search whether an element is already in the list,
253 at a position >= START_INDEX and < END_INDEX.
254 Return its position if found, or (size_t)(-1) if not present in the list. */
255 extern size_t gl_list_indexof_from_to (gl_list_t list,
256 size_t start_index, size_t end_index,
259 /* Add an element as the first element of the list.
261 #if 0 /* declared in gl_xlist.h */
262 extern gl_list_node_t gl_list_add_first (gl_list_t list, const void *elt);
264 /* Likewise. Return NULL upon out-of-memory. */
265 extern gl_list_node_t gl_list_nx_add_first (gl_list_t list, const void *elt)
266 #if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)
267 __attribute__ ((__warn_unused_result__))
271 /* Add an element as the last element of the list.
273 #if 0 /* declared in gl_xlist.h */
274 extern gl_list_node_t gl_list_add_last (gl_list_t list, const void *elt);
276 /* Likewise. Return NULL upon out-of-memory. */
277 extern gl_list_node_t gl_list_nx_add_last (gl_list_t list, const void *elt)
278 #if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)
279 __attribute__ ((__warn_unused_result__))
283 /* Add an element before a given element node of the list.
285 #if 0 /* declared in gl_xlist.h */
286 extern gl_list_node_t gl_list_add_before (gl_list_t list, gl_list_node_t node,
289 /* Likewise. Return NULL upon out-of-memory. */
290 extern gl_list_node_t gl_list_nx_add_before (gl_list_t list,
293 #if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)
294 __attribute__ ((__warn_unused_result__))
298 /* Add an element after a given element node of the list.
300 #if 0 /* declared in gl_xlist.h */
301 extern gl_list_node_t gl_list_add_after (gl_list_t list, gl_list_node_t node,
304 /* Likewise. Return NULL upon out-of-memory. */
305 extern gl_list_node_t gl_list_nx_add_after (gl_list_t list, gl_list_node_t node,
307 #if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)
308 __attribute__ ((__warn_unused_result__))
312 /* Add an element at a given position in the list.
313 POSITION must be >= 0 and <= gl_list_size (list). */
314 #if 0 /* declared in gl_xlist.h */
315 extern gl_list_node_t gl_list_add_at (gl_list_t list, size_t position,
318 /* Likewise. Return NULL upon out-of-memory. */
319 extern gl_list_node_t gl_list_nx_add_at (gl_list_t list, size_t position,
321 #if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)
322 __attribute__ ((__warn_unused_result__))
326 /* Remove an element from the list.
328 extern bool gl_list_remove_node (gl_list_t list, gl_list_node_t node);
330 /* Remove an element at a given position from the list.
331 POSITION must be >= 0 and < gl_list_size (list).
333 extern bool gl_list_remove_at (gl_list_t list, size_t position);
335 /* Search and remove an element from the list.
336 Return true if it was found and removed. */
337 extern bool gl_list_remove (gl_list_t list, const void *elt);
339 /* Free an entire list.
340 (But this call does not free the elements of the list.) */
341 extern void gl_list_free (gl_list_t list);
343 /* --------------------- gl_list_iterator_t Data Type --------------------- */
345 /* Functions for iterating through a list. */
347 /* Type of an iterator that traverses a list.
348 This is a fixed-size struct, so that creation of an iterator doesn't need
349 memory allocation on the heap. */
352 /* For fast dispatch of gl_list_iterator_next. */
353 const struct gl_list_implementation *vtable;
354 /* For detecting whether the last returned element was removed. */
357 /* Other, implementation-private fields. */
360 } gl_list_iterator_t;
362 /* Create an iterator traversing a list.
363 The list contents must not be modified while the iterator is in use,
364 except for replacing or removing the last returned element. */
365 extern gl_list_iterator_t gl_list_iterator (gl_list_t list);
367 /* Create an iterator traversing the element with indices i,
368 start_index <= i < end_index, of a list.
369 The list contents must not be modified while the iterator is in use,
370 except for replacing or removing the last returned element. */
371 extern gl_list_iterator_t gl_list_iterator_from_to (gl_list_t list,
375 /* If there is a next element, store the next element in *ELTP, store its
376 node in *NODEP if NODEP is non-NULL, advance the iterator and return true.
377 Otherwise, return false. */
378 extern bool gl_list_iterator_next (gl_list_iterator_t *iterator,
379 const void **eltp, gl_list_node_t *nodep);
381 /* Free an iterator. */
382 extern void gl_list_iterator_free (gl_list_iterator_t *iterator);
384 /* ---------------------- Sorted gl_list_t Data Type ---------------------- */
386 /* The following functions are for lists without duplicates where the
387 order is given by a sort criterion. */
389 /* Type of function used to compare two elements. Same as for qsort().
390 NULL denotes pointer comparison. */
391 typedef int (*gl_listelement_compar_fn) (const void *elt1, const void *elt2);
393 /* Search whether an element is already in the list.
394 The list is assumed to be sorted with COMPAR.
395 Return its node if found, or NULL if not present in the list.
396 If the list contains several copies of ELT, the node of the leftmost one is
398 extern gl_list_node_t gl_sortedlist_search (gl_list_t list,
399 gl_listelement_compar_fn compar,
402 /* Search whether an element is already in the list.
403 The list is assumed to be sorted with COMPAR.
404 Only list elements with indices >= START_INDEX and < END_INDEX are
405 considered; the implementation uses these bounds to minimize the number
406 of COMPAR invocations.
407 Return its node if found, or NULL if not present in the list.
408 If the list contains several copies of ELT, the node of the leftmost one is
410 extern gl_list_node_t gl_sortedlist_search_from_to (gl_list_t list,
411 gl_listelement_compar_fn compar,
416 /* Search whether an element is already in the list.
417 The list is assumed to be sorted with COMPAR.
418 Return its position if found, or (size_t)(-1) if not present in the list.
419 If the list contains several copies of ELT, the position of the leftmost one
421 extern size_t gl_sortedlist_indexof (gl_list_t list,
422 gl_listelement_compar_fn compar,
425 /* Search whether an element is already in the list.
426 The list is assumed to be sorted with COMPAR.
427 Only list elements with indices >= START_INDEX and < END_INDEX are
428 considered; the implementation uses these bounds to minimize the number
429 of COMPAR invocations.
430 Return its position if found, or (size_t)(-1) if not present in the list.
431 If the list contains several copies of ELT, the position of the leftmost one
433 extern size_t gl_sortedlist_indexof_from_to (gl_list_t list,
434 gl_listelement_compar_fn compar,
439 /* Add an element at the appropriate position in the list.
440 The list is assumed to be sorted with COMPAR.
442 #if 0 /* declared in gl_xlist.h */
443 extern gl_list_node_t gl_sortedlist_add (gl_list_t list,
444 gl_listelement_compar_fn compar,
447 /* Likewise. Return NULL upon out-of-memory. */
448 extern gl_list_node_t gl_sortedlist_nx_add (gl_list_t list,
449 gl_listelement_compar_fn compar,
451 #if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)
452 __attribute__ ((__warn_unused_result__))
456 /* Search and remove an element from the list.
457 The list is assumed to be sorted with COMPAR.
458 Return true if it was found and removed.
459 If the list contains several copies of ELT, only the leftmost one is
461 extern bool gl_sortedlist_remove (gl_list_t list,
462 gl_listelement_compar_fn compar,
465 /* ------------------------ Implementation Details ------------------------ */
467 struct gl_list_implementation
469 /* gl_list_t functions. */
470 gl_list_t (*nx_create_empty) (gl_list_implementation_t implementation,
471 gl_listelement_equals_fn equals_fn,
472 gl_listelement_hashcode_fn hashcode_fn,
473 gl_listelement_dispose_fn dispose_fn,
474 bool allow_duplicates);
475 gl_list_t (*nx_create) (gl_list_implementation_t implementation,
476 gl_listelement_equals_fn equals_fn,
477 gl_listelement_hashcode_fn hashcode_fn,
478 gl_listelement_dispose_fn dispose_fn,
479 bool allow_duplicates,
480 size_t count, const void **contents);
481 size_t (*size) (gl_list_t list);
482 const void * (*node_value) (gl_list_t list, gl_list_node_t node);
483 int (*node_nx_set_value) (gl_list_t list, gl_list_node_t node,
485 gl_list_node_t (*next_node) (gl_list_t list, gl_list_node_t node);
486 gl_list_node_t (*previous_node) (gl_list_t list, gl_list_node_t node);
487 const void * (*get_at) (gl_list_t list, size_t position);
488 gl_list_node_t (*nx_set_at) (gl_list_t list, size_t position,
490 gl_list_node_t (*search_from_to) (gl_list_t list, size_t start_index,
491 size_t end_index, const void *elt);
492 size_t (*indexof_from_to) (gl_list_t list, size_t start_index,
493 size_t end_index, const void *elt);
494 gl_list_node_t (*nx_add_first) (gl_list_t list, const void *elt);
495 gl_list_node_t (*nx_add_last) (gl_list_t list, const void *elt);
496 gl_list_node_t (*nx_add_before) (gl_list_t list, gl_list_node_t node,
498 gl_list_node_t (*nx_add_after) (gl_list_t list, gl_list_node_t node,
500 gl_list_node_t (*nx_add_at) (gl_list_t list, size_t position,
502 bool (*remove_node) (gl_list_t list, gl_list_node_t node);
503 bool (*remove_at) (gl_list_t list, size_t position);
504 bool (*remove_elt) (gl_list_t list, const void *elt);
505 void (*list_free) (gl_list_t list);
506 /* gl_list_iterator_t functions. */
507 gl_list_iterator_t (*iterator) (gl_list_t list);
508 gl_list_iterator_t (*iterator_from_to) (gl_list_t list,
511 bool (*iterator_next) (gl_list_iterator_t *iterator,
512 const void **eltp, gl_list_node_t *nodep);
513 void (*iterator_free) (gl_list_iterator_t *iterator);
514 /* Sorted gl_list_t functions. */
515 gl_list_node_t (*sortedlist_search) (gl_list_t list,
516 gl_listelement_compar_fn compar,
518 gl_list_node_t (*sortedlist_search_from_to) (gl_list_t list,
519 gl_listelement_compar_fn compar,
523 size_t (*sortedlist_indexof) (gl_list_t list,
524 gl_listelement_compar_fn compar,
526 size_t (*sortedlist_indexof_from_to) (gl_list_t list,
527 gl_listelement_compar_fn compar,
528 size_t start_index, size_t end_index,
530 gl_list_node_t (*sortedlist_nx_add) (gl_list_t list,
531 gl_listelement_compar_fn compar,
533 bool (*sortedlist_remove) (gl_list_t list,
534 gl_listelement_compar_fn compar,
538 struct gl_list_impl_base
540 const struct gl_list_implementation *vtable;
541 gl_listelement_equals_fn equals_fn;
542 gl_listelement_hashcode_fn hashcode_fn;
543 gl_listelement_dispose_fn dispose_fn;
544 bool allow_duplicates;
547 /* Define all functions of this file as accesses to the
548 struct gl_list_implementation. */
550 GL_LIST_INLINE gl_list_t
551 gl_list_nx_create_empty (gl_list_implementation_t implementation,
552 gl_listelement_equals_fn equals_fn,
553 gl_listelement_hashcode_fn hashcode_fn,
554 gl_listelement_dispose_fn dispose_fn,
555 bool allow_duplicates)
557 return implementation->nx_create_empty (implementation, equals_fn,
558 hashcode_fn, dispose_fn,
562 GL_LIST_INLINE gl_list_t
563 gl_list_nx_create (gl_list_implementation_t implementation,
564 gl_listelement_equals_fn equals_fn,
565 gl_listelement_hashcode_fn hashcode_fn,
566 gl_listelement_dispose_fn dispose_fn,
567 bool allow_duplicates,
568 size_t count, const void **contents)
570 return implementation->nx_create (implementation, equals_fn, hashcode_fn,
571 dispose_fn, allow_duplicates, count,
575 GL_LIST_INLINE size_t
576 gl_list_size (gl_list_t list)
578 return ((const struct gl_list_impl_base *) list)->vtable
582 GL_LIST_INLINE const void *
583 gl_list_node_value (gl_list_t list, gl_list_node_t node)
585 return ((const struct gl_list_impl_base *) list)->vtable
586 ->node_value (list, node);
590 gl_list_node_nx_set_value (gl_list_t list, gl_list_node_t node,
593 return ((const struct gl_list_impl_base *) list)->vtable
594 ->node_nx_set_value (list, node, elt);
597 GL_LIST_INLINE gl_list_node_t
598 gl_list_next_node (gl_list_t list, gl_list_node_t node)
600 return ((const struct gl_list_impl_base *) list)->vtable
601 ->next_node (list, node);
604 GL_LIST_INLINE gl_list_node_t
605 gl_list_previous_node (gl_list_t list, gl_list_node_t node)
607 return ((const struct gl_list_impl_base *) list)->vtable
608 ->previous_node (list, node);
611 GL_LIST_INLINE const void *
612 gl_list_get_at (gl_list_t list, size_t position)
614 return ((const struct gl_list_impl_base *) list)->vtable
615 ->get_at (list, position);
618 GL_LIST_INLINE gl_list_node_t
619 gl_list_nx_set_at (gl_list_t list, size_t position, const void *elt)
621 return ((const struct gl_list_impl_base *) list)->vtable
622 ->nx_set_at (list, position, elt);
625 GL_LIST_INLINE gl_list_node_t
626 gl_list_search (gl_list_t list, const void *elt)
628 size_t size = ((const struct gl_list_impl_base *) list)->vtable->size (list);
629 return ((const struct gl_list_impl_base *) list)->vtable
630 ->search_from_to (list, 0, size, elt);
633 GL_LIST_INLINE gl_list_node_t
634 gl_list_search_from (gl_list_t list, size_t start_index, const void *elt)
636 size_t size = ((const struct gl_list_impl_base *) list)->vtable->size (list);
637 return ((const struct gl_list_impl_base *) list)->vtable
638 ->search_from_to (list, start_index, size, elt);
641 GL_LIST_INLINE gl_list_node_t
642 gl_list_search_from_to (gl_list_t list, size_t start_index, size_t end_index,
645 return ((const struct gl_list_impl_base *) list)->vtable
646 ->search_from_to (list, start_index, end_index, elt);
649 GL_LIST_INLINE size_t
650 gl_list_indexof (gl_list_t list, const void *elt)
652 size_t size = ((const struct gl_list_impl_base *) list)->vtable->size (list);
653 return ((const struct gl_list_impl_base *) list)->vtable
654 ->indexof_from_to (list, 0, size, elt);
657 GL_LIST_INLINE size_t
658 gl_list_indexof_from (gl_list_t list, size_t start_index, const void *elt)
660 size_t size = ((const struct gl_list_impl_base *) list)->vtable->size (list);
661 return ((const struct gl_list_impl_base *) list)->vtable
662 ->indexof_from_to (list, start_index, size, elt);
665 GL_LIST_INLINE size_t
666 gl_list_indexof_from_to (gl_list_t list, size_t start_index, size_t end_index,
669 return ((const struct gl_list_impl_base *) list)->vtable
670 ->indexof_from_to (list, start_index, end_index, elt);
673 GL_LIST_INLINE gl_list_node_t
674 gl_list_nx_add_first (gl_list_t list, const void *elt)
676 return ((const struct gl_list_impl_base *) list)->vtable
677 ->nx_add_first (list, elt);
680 GL_LIST_INLINE gl_list_node_t
681 gl_list_nx_add_last (gl_list_t list, const void *elt)
683 return ((const struct gl_list_impl_base *) list)->vtable
684 ->nx_add_last (list, elt);
687 GL_LIST_INLINE gl_list_node_t
688 gl_list_nx_add_before (gl_list_t list, gl_list_node_t node, const void *elt)
690 return ((const struct gl_list_impl_base *) list)->vtable
691 ->nx_add_before (list, node, elt);
694 GL_LIST_INLINE gl_list_node_t
695 gl_list_nx_add_after (gl_list_t list, gl_list_node_t node, const void *elt)
697 return ((const struct gl_list_impl_base *) list)->vtable
698 ->nx_add_after (list, node, elt);
701 GL_LIST_INLINE gl_list_node_t
702 gl_list_nx_add_at (gl_list_t list, size_t position, const void *elt)
704 return ((const struct gl_list_impl_base *) list)->vtable
705 ->nx_add_at (list, position, elt);
709 gl_list_remove_node (gl_list_t list, gl_list_node_t node)
711 return ((const struct gl_list_impl_base *) list)->vtable
712 ->remove_node (list, node);
716 gl_list_remove_at (gl_list_t list, size_t position)
718 return ((const struct gl_list_impl_base *) list)->vtable
719 ->remove_at (list, position);
723 gl_list_remove (gl_list_t list, const void *elt)
725 return ((const struct gl_list_impl_base *) list)->vtable
726 ->remove_elt (list, elt);
730 gl_list_free (gl_list_t list)
732 ((const struct gl_list_impl_base *) list)->vtable->list_free (list);
735 GL_LIST_INLINE gl_list_iterator_t
736 gl_list_iterator (gl_list_t list)
738 return ((const struct gl_list_impl_base *) list)->vtable
742 GL_LIST_INLINE gl_list_iterator_t
743 gl_list_iterator_from_to (gl_list_t list, size_t start_index, size_t end_index)
745 return ((const struct gl_list_impl_base *) list)->vtable
746 ->iterator_from_to (list, start_index, end_index);
750 gl_list_iterator_next (gl_list_iterator_t *iterator,
751 const void **eltp, gl_list_node_t *nodep)
753 return iterator->vtable->iterator_next (iterator, eltp, nodep);
757 gl_list_iterator_free (gl_list_iterator_t *iterator)
759 iterator->vtable->iterator_free (iterator);
762 GL_LIST_INLINE gl_list_node_t
763 gl_sortedlist_search (gl_list_t list, gl_listelement_compar_fn compar, const void *elt)
765 return ((const struct gl_list_impl_base *) list)->vtable
766 ->sortedlist_search (list, compar, elt);
769 GL_LIST_INLINE gl_list_node_t
770 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)
772 return ((const struct gl_list_impl_base *) list)->vtable
773 ->sortedlist_search_from_to (list, compar, start_index, end_index,
777 GL_LIST_INLINE size_t
778 gl_sortedlist_indexof (gl_list_t list, gl_listelement_compar_fn compar, const void *elt)
780 return ((const struct gl_list_impl_base *) list)->vtable
781 ->sortedlist_indexof (list, compar, elt);
784 GL_LIST_INLINE size_t
785 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)
787 return ((const struct gl_list_impl_base *) list)->vtable
788 ->sortedlist_indexof_from_to (list, compar, start_index, end_index,
792 GL_LIST_INLINE gl_list_node_t
793 gl_sortedlist_nx_add (gl_list_t list, gl_listelement_compar_fn compar, const void *elt)
795 return ((const struct gl_list_impl_base *) list)->vtable
796 ->sortedlist_nx_add (list, compar, elt);
800 gl_sortedlist_remove (gl_list_t list, gl_listelement_compar_fn compar, const void *elt)
802 return ((const struct gl_list_impl_base *) list)->vtable
803 ->sortedlist_remove (list, compar, elt);
810 _GL_INLINE_HEADER_END
812 #endif /* _GL_LIST_H */