1 /* Abstract sequential list data type.
2 Copyright (C) 2006 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 2, or (at your option)
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, write to the Free Software Foundation,
17 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
30 /* gl_list is an abstract list data type. It can contain any number of
31 objects ('void *' or 'const void *' pointers) in any given order.
32 Duplicates are allowed, but can optionally be forbidden.
34 There are several implementations of this list datatype, optimized for
35 different operations or for memory. You can start using the simplest list
36 implementation, GL_ARRAY_LIST, and switch to a different implementation
37 later, when you realize which operations are performed the most frequently.
38 The API of the different implementations is exactly the same; when
39 switching to a different implementation, you only have to change the
42 The implementations are:
43 GL_ARRAY_LIST a growable array
44 GL_CARRAY_LIST a growable circular array
45 GL_LINKED_LIST a linked list
46 GL_AVLTREE_LIST a binary tree (AVL tree)
47 GL_RBTREE_LIST a binary tree (red-black tree)
48 GL_LINKEDHASH_LIST a hash table with a linked list
49 GL_AVLTREEHASH_LIST a hash table with a binary tree (AVL tree)
50 GL_RBTREEHASH_LIST a hash table with a binary tree (red-black tree)
52 The memory consumption is asymptotically the same: O(1) for every object
53 in the list. When looking more closely at the average memory consumed
54 for an object, GL_ARRAY_LIST is the most compact representation, and
55 GL_LINKEDHASH_LIST and GL_TREEHASH_LIST need more memory.
57 The guaranteed average performance of the operations is, for a list of
60 Operation ARRAY LINKED TREE LINKEDHASH TREEHASH
61 CARRAY with|without with|without
64 gl_list_size O(1) O(1) O(1) O(1) O(1)
65 gl_list_node_value O(1) O(1) O(1) O(1) O(1)
66 gl_list_next_node O(1) O(1) O(log n) O(1) O(log n)
67 gl_list_previous_node O(1) O(1) O(log n) O(1) O(log n)
68 gl_list_get_at O(1) O(n) O(log n) O(n) O(log n)
69 gl_list_set_at O(1) O(n) O(log n) O(n) O((log n)²)/O(log n)
70 gl_list_search O(n) O(n) O(n) O(n)/O(1) O(log n)/O(1)
71 gl_list_search_from O(n) O(n) O(n) O(n)/O(1) O((log n)²)/O(log n)
72 gl_list_search_from_to O(n) O(n) O(n) O(n)/O(1) O((log n)²)/O(log n)
73 gl_list_indexof O(n) O(n) O(n) O(n) O(log n)
74 gl_list_indexof_from O(n) O(n) O(n) O(n) O((log n)²)/O(log n)
75 gl_list_indexof_from_to O(n) O(n) O(n) O(n) O((log n)²)/O(log n)
76 gl_list_add_first O(n)/O(1) O(1) O(log n) O(1) O((log n)²)/O(log n)
77 gl_list_add_last O(1) O(1) O(log n) O(1) O((log n)²)/O(log n)
78 gl_list_add_before O(n) O(1) O(log n) O(1) O((log n)²)/O(log n)
79 gl_list_add_after O(n) O(1) O(log n) O(1) O((log n)²)/O(log n)
80 gl_list_add_at O(n) O(n) O(log n) O(n) O((log n)²)/O(log n)
81 gl_list_remove_node O(n) O(1) O(log n) O(n)/O(1) O((log n)²)/O(log n)
82 gl_list_remove_at O(n) O(n) O(log n) O(n) O((log n)²)/O(log n)
83 gl_list_remove O(n) O(n) O(n) O(n)/O(1) O((log n)²)/O(log n)
84 gl_list_iterator O(1) O(1) O(log n) O(1) O(log n)
85 gl_list_iterator_from_to O(1) O(n) O(log n) O(n) O(log n)
86 gl_list_iterator_next O(1) O(1) O(log n) O(1) O(log n)
87 gl_sortedlist_search O(log n) O(n) O(log n) O(n) O(log n)
88 gl_sortedlist_search_from O(log n) O(n) O(log n) O(n) O(log n)
89 gl_sortedlist_indexof O(log n) O(n) O(log n) O(n) O(log n)
90 gl_sortedlist_indexof_fro O(log n) O(n) O(log n) O(n) O(log n)
91 gl_sortedlist_add O(n) O(n) O(log n) O(n) O((log n)²)/O(log n)
92 gl_sortedlist_remove O(n) O(n) O(log n) O(n) O((log n)²)/O(log n)
95 /* -------------------------- gl_list_t Data Type -------------------------- */
97 /* Type of function used to compare two elements.
98 NULL denotes pointer comparison. */
99 typedef bool (*gl_listelement_equals_fn) (const void *elt1, const void *elt2);
101 /* Type of function used to compute a hash code.
102 NULL denotes a function that depends only on the pointer itself. */
103 typedef size_t (*gl_listelement_hashcode_fn) (const void *elt);
106 /* Type representing an entire list. */
107 typedef struct gl_list_impl * gl_list_t;
109 struct gl_list_node_impl;
110 /* Type representing the position of an element in the list, in a way that
111 is more adapted to the list implementation than a plain index.
112 Note: It is invalidated by insertions and removals! */
113 typedef struct gl_list_node_impl * gl_list_node_t;
115 struct gl_list_implementation;
116 /* Type representing a list datatype implementation. */
117 typedef const struct gl_list_implementation * gl_list_implementation_t;
119 /* Create an empty list.
120 IMPLEMENTATION is one of GL_ARRAY_LIST, GL_CARRAY_LIST, GL_LINKED_LIST,
121 GL_AVLTREE_LIST, GL_RBTREE_LIST, GL_LINKEDHASH_LIST, GL_AVLTREEHASH_LIST,
123 EQUALS_FN is an element comparison function or NULL.
124 HASHCODE_FN is an element hash code function or NULL.
125 ALLOW_DUPLICATES is false if duplicate elements shall not be allowed in
126 the list. The implementation may verify this at runtime. */
127 extern gl_list_t gl_list_create_empty (gl_list_implementation_t implementation,
128 gl_listelement_equals_fn equals_fn,
129 gl_listelement_hashcode_fn hashcode_fn,
130 bool allow_duplicates);
132 /* Create a list with given contents.
133 IMPLEMENTATION is one of GL_ARRAY_LIST, GL_CARRAY_LIST, GL_LINKED_LIST,
134 GL_AVLTREE_LIST, GL_RBTREE_LIST, GL_LINKEDHASH_LIST, GL_AVLTREEHASH_LIST,
136 EQUALS_FN is an element comparison function or NULL.
137 HASHCODE_FN is an element hash code function or NULL.
138 ALLOW_DUPLICATES is false if duplicate elements shall not be allowed in
139 the list. The implementation may verify this at runtime.
140 COUNT is the number of initial elements.
141 CONTENTS[0..COUNT-1] is the initial contents. */
142 extern gl_list_t gl_list_create (gl_list_implementation_t implementation,
143 gl_listelement_equals_fn equals_fn,
144 gl_listelement_hashcode_fn hashcode_fn,
145 bool allow_duplicates,
146 size_t count, const void **contents);
148 /* Return the current number of elements in a list. */
149 extern size_t gl_list_size (gl_list_t list);
151 /* Return the element value represented by a list node. */
152 extern const void * gl_list_node_value (gl_list_t list, gl_list_node_t node);
154 /* Return the node immediately after the given node in the list, or NULL
155 if the given node is the last (rightmost) one in the list. */
156 extern gl_list_node_t gl_list_next_node (gl_list_t list, gl_list_node_t node);
158 /* Return the node immediately before the given node in the list, or NULL
159 if the given node is the first (leftmost) one in the list. */
160 extern gl_list_node_t gl_list_previous_node (gl_list_t list, gl_list_node_t node);
162 /* Return the element at a given position in the list.
163 POSITION must be >= 0 and < gl_list_size (list). */
164 extern const void * gl_list_get_at (gl_list_t list, size_t position);
166 /* Replace the element at a given position in the list.
167 POSITION must be >= 0 and < gl_list_size (list).
169 extern gl_list_node_t gl_list_set_at (gl_list_t list, size_t position,
172 /* Search whether an element is already in the list.
173 Return its node if found, or NULL if not present in the list. */
174 extern gl_list_node_t gl_list_search (gl_list_t list, const void *elt);
176 /* Search whether an element is already in the list,
177 at a position >= START_INDEX.
178 Return its node if found, or NULL if not present in the list. */
179 extern gl_list_node_t gl_list_search_from (gl_list_t list, size_t start_index,
182 /* Search whether an element is already in the list,
183 at a position >= START_INDEX and < END_INDEX.
184 Return its node if found, or NULL if not present in the list. */
185 extern gl_list_node_t gl_list_search_from_to (gl_list_t list,
190 /* Search whether an element is already in the list.
191 Return its position if found, or (size_t)(-1) if not present in the list. */
192 extern size_t gl_list_indexof (gl_list_t list, const void *elt);
194 /* Search whether an element is already in the list,
195 at a position >= START_INDEX.
196 Return its position if found, or (size_t)(-1) if not present in the list. */
197 extern size_t gl_list_indexof_from (gl_list_t list, size_t start_index,
200 /* Search whether an element is already in the list,
201 at a position >= START_INDEX and < END_INDEX.
202 Return its position if found, or (size_t)(-1) if not present in the list. */
203 extern size_t gl_list_indexof_from_to (gl_list_t list,
204 size_t start_index, size_t end_index,
207 /* Add an element as the first element of the list.
209 extern gl_list_node_t gl_list_add_first (gl_list_t list, const void *elt);
211 /* Add an element as the last element of the list.
213 extern gl_list_node_t gl_list_add_last (gl_list_t list, const void *elt);
215 /* Add an element before a given element node of the list.
217 extern gl_list_node_t gl_list_add_before (gl_list_t list, gl_list_node_t node,
220 /* Add an element after a given element node of the list.
222 extern gl_list_node_t gl_list_add_after (gl_list_t list, gl_list_node_t node,
225 /* Add an element add a given position in the list.
226 POSITION must be >= 0 and <= gl_list_size (list). */
227 extern gl_list_node_t gl_list_add_at (gl_list_t list, size_t position,
230 /* Remove an element from the list.
232 extern bool gl_list_remove_node (gl_list_t list, gl_list_node_t node);
234 /* Remove an element at a given position from the list.
235 POSITION must be >= 0 and < gl_list_size (list).
237 extern bool gl_list_remove_at (gl_list_t list, size_t position);
239 /* Search and remove an element from the list.
240 Return true if it was found and removed. */
241 extern bool gl_list_remove (gl_list_t list, const void *elt);
243 /* Free an entire list.
244 (But this call does not free the elements of the list.) */
245 extern void gl_list_free (gl_list_t list);
247 /* --------------------- gl_list_iterator_t Data Type --------------------- */
249 /* Functions for iterating through a list. */
251 /* Type of an iterator that traverses a list.
252 This is a fixed-size struct, so that creation of an iterator doesn't need
253 memory allocation on the heap. */
256 /* For fast dispatch of gl_list_iterator_next. */
257 const struct gl_list_implementation *vtable;
258 /* For detecting whether the last returned element was removed. */
261 /* Other, implementation-private fields. */
264 } gl_list_iterator_t;
266 /* Create an iterator traversing a list.
267 The list contents must not be modified while the iterator is in use,
268 except for replacing or removing the last returned element. */
269 extern gl_list_iterator_t gl_list_iterator (gl_list_t list);
271 /* Create an iterator traversing the element with indices i,
272 start_index <= i < end_index, of a list.
273 The list contents must not be modified while the iterator is in use,
274 except for replacing or removing the last returned element. */
275 extern gl_list_iterator_t gl_list_iterator_from_to (gl_list_t list,
279 /* If there is a next element, store the next element in *ELTP, store its
280 node in *NODEP if NODEP is non-NULL, advance the iterator and return true.
281 Otherwise, return false. */
282 extern bool gl_list_iterator_next (gl_list_iterator_t *iterator,
283 const void **eltp, gl_list_node_t *nodep);
285 /* Free an iterator. */
286 extern void gl_list_iterator_free (gl_list_iterator_t *iterator);
288 /* ---------------------- Sorted gl_list_t Data Type ---------------------- */
290 /* The following functions are for lists without duplicates where the
291 order is given by a sort criterion. */
293 /* Type of function used to compare two elements. Same as for qsort().
294 NULL denotes pointer comparison. */
295 typedef int (*gl_listelement_compar_fn) (const void *elt1, const void *elt2);
297 /* Search whether an element is already in the list.
298 The list is assumed to be sorted with COMPAR.
299 Return its node if found, or NULL if not present in the list.
300 If the list contains several copies of ELT, the node of the leftmost one is
302 extern gl_list_node_t gl_sortedlist_search (gl_list_t list,
303 gl_listelement_compar_fn compar,
306 /* Search whether an element is already in the list.
307 The list is assumed to be sorted with COMPAR.
308 Only list elements with indices >= START_INDEX and < END_INDEX are
309 considered; the implementation uses these bounds to minimize the number
310 of COMPAR invocations.
311 Return its node if found, or NULL if not present in the list.
312 If the list contains several copies of ELT, the node of the leftmost one is
314 extern gl_list_node_t gl_sortedlist_search_from_to (gl_list_t list,
315 gl_listelement_compar_fn compar,
320 /* Search whether an element is already in the list.
321 The list is assumed to be sorted with COMPAR.
322 Return its position if found, or (size_t)(-1) if not present in the list.
323 If the list contains several copies of ELT, the position of the leftmost one
325 extern size_t gl_sortedlist_indexof (gl_list_t list,
326 gl_listelement_compar_fn compar,
329 /* Search whether an element is already in the list.
330 The list is assumed to be sorted with COMPAR.
331 Only list elements with indices >= START_INDEX and < END_INDEX are
332 considered; the implementation uses these bounds to minimize the number
333 of COMPAR invocations.
334 Return its position if found, or (size_t)(-1) if not present in the list.
335 If the list contains several copies of ELT, the position of the leftmost one
337 extern size_t gl_sortedlist_indexof_from_to (gl_list_t list,
338 gl_listelement_compar_fn compar,
343 /* Add an element at the appropriate position in the list.
344 The list is assumed to be sorted with COMPAR.
346 extern gl_list_node_t gl_sortedlist_add (gl_list_t list,
347 gl_listelement_compar_fn compar,
350 /* Search and remove an element from the list.
351 The list is assumed to be sorted with COMPAR.
352 Return true if it was found and removed.
353 If the list contains several copies of ELT, only the leftmost one is
355 extern bool gl_sortedlist_remove (gl_list_t list,
356 gl_listelement_compar_fn compar,
359 /* ------------------------ Implementation Details ------------------------ */
361 struct gl_list_implementation
363 // gl_list_t functions.
364 gl_list_t (*create_empty) (gl_list_implementation_t implementation,
365 gl_listelement_equals_fn equals_fn,
366 gl_listelement_hashcode_fn hashcode_fn,
367 bool allow_duplicates);
368 gl_list_t (*create) (gl_list_implementation_t implementation,
369 gl_listelement_equals_fn equals_fn,
370 gl_listelement_hashcode_fn hashcode_fn,
371 bool allow_duplicates,
372 size_t count, const void **contents);
373 size_t (*size) (gl_list_t list);
374 const void * (*node_value) (gl_list_t list, gl_list_node_t node);
375 gl_list_node_t (*next_node) (gl_list_t list, gl_list_node_t node);
376 gl_list_node_t (*previous_node) (gl_list_t list, gl_list_node_t node);
377 const void * (*get_at) (gl_list_t list, size_t position);
378 gl_list_node_t (*set_at) (gl_list_t list, size_t position, const void *elt);
379 gl_list_node_t (*search_from_to) (gl_list_t list, size_t start_index,
380 size_t end_index, const void *elt);
381 size_t (*indexof_from_to) (gl_list_t list, size_t start_index,
382 size_t end_index, const void *elt);
383 gl_list_node_t (*add_first) (gl_list_t list, const void *elt);
384 gl_list_node_t (*add_last) (gl_list_t list, const void *elt);
385 gl_list_node_t (*add_before) (gl_list_t list, gl_list_node_t node,
387 gl_list_node_t (*add_after) (gl_list_t list, gl_list_node_t node,
389 gl_list_node_t (*add_at) (gl_list_t list, size_t position,
391 bool (*remove_node) (gl_list_t list, gl_list_node_t node);
392 bool (*remove_at) (gl_list_t list, size_t position);
393 bool (*remove) (gl_list_t list, const void *elt);
394 void (*list_free) (gl_list_t list);
395 // gl_list_iterator_t functions.
396 gl_list_iterator_t (*iterator) (gl_list_t list);
397 gl_list_iterator_t (*iterator_from_to) (gl_list_t list,
400 bool (*iterator_next) (gl_list_iterator_t *iterator,
401 const void **eltp, gl_list_node_t *nodep);
402 void (*iterator_free) (gl_list_iterator_t *iterator);
403 // Sorted gl_list_t functions.
404 gl_list_node_t (*sortedlist_search) (gl_list_t list,
405 gl_listelement_compar_fn compar,
407 gl_list_node_t (*sortedlist_search_from_to) (gl_list_t list,
408 gl_listelement_compar_fn compar,
412 size_t (*sortedlist_indexof) (gl_list_t list,
413 gl_listelement_compar_fn compar,
415 size_t (*sortedlist_indexof_from_to) (gl_list_t list,
416 gl_listelement_compar_fn compar,
417 size_t start_index, size_t end_index,
419 gl_list_node_t (*sortedlist_add) (gl_list_t list,
420 gl_listelement_compar_fn compar,
422 bool (*sortedlist_remove) (gl_list_t list,
423 gl_listelement_compar_fn compar,
427 struct gl_list_impl_base
429 const struct gl_list_implementation *vtable;
430 gl_listelement_equals_fn equals_fn;
431 gl_listelement_hashcode_fn hashcode_fn;
432 bool allow_duplicates;
437 /* Define all functions of this file as inline accesses to the
438 struct gl_list_implementation.
439 Use #define to avoid a warning because of extern vs. static. */
441 # define gl_list_create_empty gl_list_create_empty_inline
442 static inline gl_list_t
443 gl_list_create_empty (gl_list_implementation_t implementation,
444 gl_listelement_equals_fn equals_fn,
445 gl_listelement_hashcode_fn hashcode_fn,
446 bool allow_duplicates)
448 return implementation->create_empty (implementation, equals_fn, hashcode_fn,
452 # define gl_list_create gl_list_create_inline
453 static inline gl_list_t
454 gl_list_create (gl_list_implementation_t implementation,
455 gl_listelement_equals_fn equals_fn,
456 gl_listelement_hashcode_fn hashcode_fn,
457 bool allow_duplicates,
458 size_t count, const void **contents)
460 return implementation->create (implementation, equals_fn, hashcode_fn,
461 allow_duplicates, count, contents);
464 # define gl_list_size gl_list_size_inline
466 gl_list_size (gl_list_t list)
468 return ((const struct gl_list_impl_base *) list)->vtable
472 # define gl_list_node_value gl_list_node_value_inline
473 static inline const void *
474 gl_list_node_value (gl_list_t list, gl_list_node_t node)
476 return ((const struct gl_list_impl_base *) list)->vtable
477 ->node_value (list, node);
480 # define gl_list_next_node gl_list_next_node_inline
481 static inline gl_list_node_t
482 gl_list_next_node (gl_list_t list, gl_list_node_t node)
484 return ((const struct gl_list_impl_base *) list)->vtable
485 ->next_node (list, node);
488 # define gl_list_previous_node gl_list_previous_node_inline
489 static inline gl_list_node_t
490 gl_list_previous_node (gl_list_t list, gl_list_node_t node)
492 return ((const struct gl_list_impl_base *) list)->vtable
493 ->previous_node (list, node);
496 # define gl_list_get_at gl_list_get_at_inline
497 static inline const void *
498 gl_list_get_at (gl_list_t list, size_t position)
500 return ((const struct gl_list_impl_base *) list)->vtable
501 ->get_at (list, position);
504 # define gl_list_set_at gl_list_set_at_inline
505 static inline gl_list_node_t
506 gl_list_set_at (gl_list_t list, size_t position, const void *elt)
508 return ((const struct gl_list_impl_base *) list)->vtable
509 ->set_at (list, position, elt);
512 # define gl_list_search gl_list_search_inline
513 static inline gl_list_node_t
514 gl_list_search (gl_list_t list, const void *elt)
516 size_t size = ((const struct gl_list_impl_base *) list)->vtable->size (list);
517 return ((const struct gl_list_impl_base *) list)->vtable
518 ->search_from_to (list, 0, size, elt);
521 # define gl_list_search_from gl_list_search_from_inline
522 static inline gl_list_node_t
523 gl_list_search_from (gl_list_t list, size_t start_index, const void *elt)
525 size_t size = ((const struct gl_list_impl_base *) list)->vtable->size (list);
526 return ((const struct gl_list_impl_base *) list)->vtable
527 ->search_from_to (list, start_index, size, elt);
530 # define gl_list_search_from_to gl_list_search_from_to_inline
531 static inline gl_list_node_t
532 gl_list_search_from_to (gl_list_t list, size_t start_index, size_t end_index,
535 return ((const struct gl_list_impl_base *) list)->vtable
536 ->search_from_to (list, start_index, end_index, elt);
539 # define gl_list_indexof gl_list_indexof_inline
541 gl_list_indexof (gl_list_t list, const void *elt)
543 size_t size = ((const struct gl_list_impl_base *) list)->vtable->size (list);
544 return ((const struct gl_list_impl_base *) list)->vtable
545 ->indexof_from_to (list, 0, size, elt);
548 # define gl_list_indexof_from gl_list_indexof_from_inline
550 gl_list_indexof_from (gl_list_t list, size_t start_index, const void *elt)
552 size_t size = ((const struct gl_list_impl_base *) list)->vtable->size (list);
553 return ((const struct gl_list_impl_base *) list)->vtable
554 ->indexof_from_to (list, start_index, size, elt);
557 # define gl_list_indexof_from_to gl_list_indexof_from_to_inline
559 gl_list_indexof_from_to (gl_list_t list, size_t start_index, size_t end_index,
562 return ((const struct gl_list_impl_base *) list)->vtable
563 ->indexof_from_to (list, start_index, end_index, elt);
566 # define gl_list_add_first gl_list_add_first_inline
567 static inline gl_list_node_t
568 gl_list_add_first (gl_list_t list, const void *elt)
570 return ((const struct gl_list_impl_base *) list)->vtable
571 ->add_first (list, elt);
574 # define gl_list_add_last gl_list_add_last_inline
575 static inline gl_list_node_t
576 gl_list_add_last (gl_list_t list, const void *elt)
578 return ((const struct gl_list_impl_base *) list)->vtable
579 ->add_last (list, elt);
582 # define gl_list_add_before gl_list_add_before_inline
583 static inline gl_list_node_t
584 gl_list_add_before (gl_list_t list, gl_list_node_t node, const void *elt)
586 return ((const struct gl_list_impl_base *) list)->vtable
587 ->add_before (list, node, elt);
590 # define gl_list_add_after gl_list_add_after_inline
591 static inline gl_list_node_t
592 gl_list_add_after (gl_list_t list, gl_list_node_t node, const void *elt)
594 return ((const struct gl_list_impl_base *) list)->vtable
595 ->add_after (list, node, elt);
598 # define gl_list_add_at gl_list_add_at_inline
599 static inline gl_list_node_t
600 gl_list_add_at (gl_list_t list, size_t position, const void *elt)
602 return ((const struct gl_list_impl_base *) list)->vtable
603 ->add_at (list, position, elt);
606 # define gl_list_remove_node gl_list_remove_node_inline
608 gl_list_remove_node (gl_list_t list, gl_list_node_t node)
610 return ((const struct gl_list_impl_base *) list)->vtable
611 ->remove_node (list, node);
614 # define gl_list_remove_at gl_list_remove_at_inline
616 gl_list_remove_at (gl_list_t list, size_t position)
618 return ((const struct gl_list_impl_base *) list)->vtable
619 ->remove_at (list, position);
622 # define gl_list_remove gl_list_remove_inline
624 gl_list_remove (gl_list_t list, const void *elt)
626 return ((const struct gl_list_impl_base *) list)->vtable
627 ->remove (list, elt);
630 # define gl_list_free gl_list_free_inline
632 gl_list_free (gl_list_t list)
634 ((const struct gl_list_impl_base *) list)->vtable->list_free (list);
637 # define gl_list_iterator gl_list_iterator_inline
638 static inline gl_list_iterator_t
639 gl_list_iterator (gl_list_t list)
641 return ((const struct gl_list_impl_base *) list)->vtable
645 # define gl_list_iterator_from_to gl_list_iterator_from_to_inline
646 static inline gl_list_iterator_t
647 gl_list_iterator_from_to (gl_list_t list, size_t start_index, size_t end_index)
649 return ((const struct gl_list_impl_base *) list)->vtable
650 ->iterator_from_to (list, start_index, end_index);
653 # define gl_list_iterator_next gl_list_iterator_next_inline
655 gl_list_iterator_next (gl_list_iterator_t *iterator,
656 const void **eltp, gl_list_node_t *nodep)
658 return iterator->vtable->iterator_next (iterator, eltp, nodep);
661 # define gl_list_iterator_free gl_list_iterator_free_inline
663 gl_list_iterator_free (gl_list_iterator_t *iterator)
665 iterator->vtable->iterator_free (iterator);
668 # define gl_sortedlist_search gl_sortedlist_search_inline
669 static inline gl_list_node_t
670 gl_sortedlist_search (gl_list_t list, gl_listelement_compar_fn compar, const void *elt)
672 return ((const struct gl_list_impl_base *) list)->vtable
673 ->sortedlist_search (list, compar, elt);
676 # define gl_sortedlist_search_from_to gl_sortedlist_search_from_to_inline
677 static inline gl_list_node_t
678 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)
680 return ((const struct gl_list_impl_base *) list)->vtable
681 ->sortedlist_search_from_to (list, compar, start_index, end_index,
685 # define gl_sortedlist_indexof gl_sortedlist_indexof_inline
687 gl_sortedlist_indexof (gl_list_t list, gl_listelement_compar_fn compar, const void *elt)
689 return ((const struct gl_list_impl_base *) list)->vtable
690 ->sortedlist_indexof (list, compar, elt);
693 # define gl_sortedlist_indexof_from_to gl_sortedlist_indexof_from_to_inline
695 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)
697 return ((const struct gl_list_impl_base *) list)->vtable
698 ->sortedlist_indexof_from_to (list, compar, start_index, end_index,
702 # define gl_sortedlist_add gl_sortedlist_add_inline
703 static inline gl_list_node_t
704 gl_sortedlist_add (gl_list_t list, gl_listelement_compar_fn compar, const void *elt)
706 return ((const struct gl_list_impl_base *) list)->vtable
707 ->sortedlist_add (list, compar, elt);
710 # define gl_sortedlist_remove gl_sortedlist_remove_inline
712 gl_sortedlist_remove (gl_list_t list, gl_listelement_compar_fn compar, const void *elt)
714 return ((const struct gl_list_impl_base *) list)->vtable
715 ->sortedlist_remove (list, compar, elt);
724 #endif /* _GL_LIST_H */