annotate lib/gl_list.h @ 7692:85409a7d11bc

* lib/regex.h (__restrict_arr): Redo logic of #if, for clarity.
author Paul Eggert <eggert@cs.ucla.edu>
date Mon, 27 Nov 2006 19:41:42 +0000
parents 579cface12e9
children 238942284e2f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6984
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1 /* Abstract sequential list data type.
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
2 Copyright (C) 2006 Free Software Foundation, Inc.
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3 Written by Bruno Haible <bruno@clisp.org>, 2006.
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
4
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
5 This program is free software; you can redistribute it and/or modify
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
6 it under the terms of the GNU General Public License as published by
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
7 the Free Software Foundation; either version 2, or (at your option)
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
8 any later version.
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
9
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
10 This program is distributed in the hope that it will be useful,
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
13 GNU General Public License for more details.
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
14
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
15 You should have received a copy of the GNU General Public License
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
16 along with this program; if not, write to the Free Software Foundation,
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
17 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
18
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
19 #ifndef _GL_LIST_H
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
20 #define _GL_LIST_H
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
21
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
22 #include <stdbool.h>
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
23 #include <stddef.h>
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
24
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
25 #ifdef __cplusplus
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
26 extern "C" {
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
27 #endif
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
28
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
29
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
30 /* gl_list is an abstract list data type. It can contain any number of
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
31 objects ('void *' or 'const void *' pointers) in any given order.
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
32 Duplicates are allowed, but can optionally be forbidden.
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
33
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
34 There are several implementations of this list datatype, optimized for
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
35 different operations or for memory. You can start using the simplest list
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
36 implementation, GL_ARRAY_LIST, and switch to a different implementation
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
37 later, when you realize which operations are performed the most frequently.
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
38 The API of the different implementations is exactly the same; when
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
39 switching to a different implementation, you only have to change the
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
40 gl_list_create call.
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
41
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
42 The implementations are:
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
43 GL_ARRAY_LIST a growable array
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
44 GL_CARRAY_LIST a growable circular array
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
45 GL_LINKED_LIST a linked list
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
46 GL_AVLTREE_LIST a binary tree (AVL tree)
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
47 GL_RBTREE_LIST a binary tree (red-black tree)
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
48 GL_LINKEDHASH_LIST a hash table with a linked list
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
49 GL_AVLTREEHASH_LIST a hash table with a binary tree (AVL tree)
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
50 GL_RBTREEHASH_LIST a hash table with a binary tree (red-black tree)
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
51
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
52 The memory consumption is asymptotically the same: O(1) for every object
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
53 in the list. When looking more closely at the average memory consumed
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
54 for an object, GL_ARRAY_LIST is the most compact representation, and
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
55 GL_LINKEDHASH_LIST and GL_TREEHASH_LIST need more memory.
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
56
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
57 The guaranteed average performance of the operations is, for a list of
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
58 n elements:
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
59
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
60 Operation ARRAY LINKED TREE LINKEDHASH TREEHASH
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
61 CARRAY with|without with|without
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
62 duplicates duplicates
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
63
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
64 gl_list_size O(1) O(1) O(1) O(1) O(1)
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
65 gl_list_node_value O(1) O(1) O(1) O(1) O(1)
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
66 gl_list_next_node O(1) O(1) O(log n) O(1) O(log n)
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
67 gl_list_previous_node O(1) O(1) O(log n) O(1) O(log n)
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
68 gl_list_get_at O(1) O(n) O(log n) O(n) O(log n)
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
69 gl_list_set_at O(1) O(n) O(log n) O(n) O((log n)²)/O(log n)
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
70 gl_list_search O(n) O(n) O(n) O(n)/O(1) O(log n)/O(1)
7405
0de49c40e105 Add searching operations, limited to a subsequence of the list.
Bruno Haible <bruno@clisp.org>
parents: 6984
diff changeset
71 gl_list_search_from O(n) O(n) O(n) O(n)/O(1) O((log n)²)/O(log n)
0de49c40e105 Add searching operations, limited to a subsequence of the list.
Bruno Haible <bruno@clisp.org>
parents: 6984
diff changeset
72 gl_list_search_from_to O(n) O(n) O(n) O(n)/O(1) O((log n)²)/O(log n)
6984
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
73 gl_list_indexof O(n) O(n) O(n) O(n) O(log n)
7405
0de49c40e105 Add searching operations, limited to a subsequence of the list.
Bruno Haible <bruno@clisp.org>
parents: 6984
diff changeset
74 gl_list_indexof_from O(n) O(n) O(n) O(n) O((log n)²)/O(log n)
0de49c40e105 Add searching operations, limited to a subsequence of the list.
Bruno Haible <bruno@clisp.org>
parents: 6984
diff changeset
75 gl_list_indexof_from_to O(n) O(n) O(n) O(n) O((log n)²)/O(log n)
6984
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
76 gl_list_add_first O(n)/O(1) O(1) O(log n) O(1) O((log n)²)/O(log n)
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
77 gl_list_add_last O(1) O(1) O(log n) O(1) O((log n)²)/O(log n)
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
78 gl_list_add_before O(n) O(1) O(log n) O(1) O((log n)²)/O(log n)
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
79 gl_list_add_after O(n) O(1) O(log n) O(1) O((log n)²)/O(log n)
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
80 gl_list_add_at O(n) O(n) O(log n) O(n) O((log n)²)/O(log n)
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
81 gl_list_remove_node O(n) O(1) O(log n) O(n)/O(1) O((log n)²)/O(log n)
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
82 gl_list_remove_at O(n) O(n) O(log n) O(n) O((log n)²)/O(log n)
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
83 gl_list_remove O(n) O(n) O(n) O(n)/O(1) O((log n)²)/O(log n)
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
84 gl_list_iterator O(1) O(1) O(log n) O(1) O(log n)
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
85 gl_list_iterator_from_to O(1) O(n) O(log n) O(n) O(log n)
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
86 gl_list_iterator_next O(1) O(1) O(log n) O(1) O(log n)
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
87 gl_sortedlist_search O(log n) O(n) O(log n) O(n) O(log n)
7410
9704ff2cbdfe Add bounded list search operations.
Bruno Haible <bruno@clisp.org>
parents: 7405
diff changeset
88 gl_sortedlist_search_from O(log n) O(n) O(log n) O(n) O(log n)
6984
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
89 gl_sortedlist_indexof O(log n) O(n) O(log n) O(n) O(log n)
7410
9704ff2cbdfe Add bounded list search operations.
Bruno Haible <bruno@clisp.org>
parents: 7405
diff changeset
90 gl_sortedlist_indexof_fro O(log n) O(n) O(log n) O(n) O(log n)
6984
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
91 gl_sortedlist_add O(n) O(n) O(log n) O(n) O((log n)²)/O(log n)
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
92 gl_sortedlist_remove O(n) O(n) O(log n) O(n) O((log n)²)/O(log n)
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
93 */
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
94
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
95 /* -------------------------- gl_list_t Data Type -------------------------- */
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
96
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
97 /* Type of function used to compare two elements.
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
98 NULL denotes pointer comparison. */
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
99 typedef bool (*gl_listelement_equals_fn) (const void *elt1, const void *elt2);
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
100
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
101 /* Type of function used to compute a hash code.
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
102 NULL denotes a function that depends only on the pointer itself. */
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
103 typedef size_t (*gl_listelement_hashcode_fn) (const void *elt);
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
104
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
105 struct gl_list_impl;
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
106 /* Type representing an entire list. */
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
107 typedef struct gl_list_impl * gl_list_t;
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
108
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
109 struct gl_list_node_impl;
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
110 /* Type representing the position of an element in the list, in a way that
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
111 is more adapted to the list implementation than a plain index.
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
112 Note: It is invalidated by insertions and removals! */
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
113 typedef struct gl_list_node_impl * gl_list_node_t;
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
114
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
115 struct gl_list_implementation;
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
116 /* Type representing a list datatype implementation. */
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
117 typedef const struct gl_list_implementation * gl_list_implementation_t;
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
118
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
119 /* Create an empty list.
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
120 IMPLEMENTATION is one of GL_ARRAY_LIST, GL_CARRAY_LIST, GL_LINKED_LIST,
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
121 GL_AVLTREE_LIST, GL_RBTREE_LIST, GL_LINKEDHASH_LIST, GL_AVLTREEHASH_LIST,
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
122 GL_RBTREEHASH_LIST.
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
123 EQUALS_FN is an element comparison function or NULL.
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
124 HASHCODE_FN is an element hash code function or NULL.
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
125 ALLOW_DUPLICATES is false if duplicate elements shall not be allowed in
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
126 the list. The implementation may verify this at runtime. */
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
127 extern gl_list_t gl_list_create_empty (gl_list_implementation_t implementation,
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
128 gl_listelement_equals_fn equals_fn,
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
129 gl_listelement_hashcode_fn hashcode_fn,
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
130 bool allow_duplicates);
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
131
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
132 /* Create a list with given contents.
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
133 IMPLEMENTATION is one of GL_ARRAY_LIST, GL_CARRAY_LIST, GL_LINKED_LIST,
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
134 GL_AVLTREE_LIST, GL_RBTREE_LIST, GL_LINKEDHASH_LIST, GL_AVLTREEHASH_LIST,
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
135 GL_RBTREEHASH_LIST.
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
136 EQUALS_FN is an element comparison function or NULL.
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
137 HASHCODE_FN is an element hash code function or NULL.
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
138 ALLOW_DUPLICATES is false if duplicate elements shall not be allowed in
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
139 the list. The implementation may verify this at runtime.
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
140 COUNT is the number of initial elements.
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
141 CONTENTS[0..COUNT-1] is the initial contents. */
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
142 extern gl_list_t gl_list_create (gl_list_implementation_t implementation,
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
143 gl_listelement_equals_fn equals_fn,
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
144 gl_listelement_hashcode_fn hashcode_fn,
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
145 bool allow_duplicates,
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
146 size_t count, const void **contents);
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
147
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
148 /* Return the current number of elements in a list. */
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
149 extern size_t gl_list_size (gl_list_t list);
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
150
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
151 /* Return the element value represented by a list node. */
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
152 extern const void * gl_list_node_value (gl_list_t list, gl_list_node_t node);
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
153
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
154 /* Return the node immediately after the given node in the list, or NULL
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
155 if the given node is the last (rightmost) one in the list. */
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
156 extern gl_list_node_t gl_list_next_node (gl_list_t list, gl_list_node_t node);
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
157
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
158 /* Return the node immediately before the given node in the list, or NULL
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
159 if the given node is the first (leftmost) one in the list. */
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
160 extern gl_list_node_t gl_list_previous_node (gl_list_t list, gl_list_node_t node);
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
161
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
162 /* Return the element at a given position in the list.
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
163 POSITION must be >= 0 and < gl_list_size (list). */
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
164 extern const void * gl_list_get_at (gl_list_t list, size_t position);
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
165
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
166 /* Replace the element at a given position in the list.
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
167 POSITION must be >= 0 and < gl_list_size (list).
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
168 Return its node. */
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
169 extern gl_list_node_t gl_list_set_at (gl_list_t list, size_t position,
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
170 const void *elt);
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
171
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
172 /* Search whether an element is already in the list.
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
173 Return its node if found, or NULL if not present in the list. */
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
174 extern gl_list_node_t gl_list_search (gl_list_t list, const void *elt);
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
175
7405
0de49c40e105 Add searching operations, limited to a subsequence of the list.
Bruno Haible <bruno@clisp.org>
parents: 6984
diff changeset
176 /* Search whether an element is already in the list,
0de49c40e105 Add searching operations, limited to a subsequence of the list.
Bruno Haible <bruno@clisp.org>
parents: 6984
diff changeset
177 at a position >= START_INDEX.
0de49c40e105 Add searching operations, limited to a subsequence of the list.
Bruno Haible <bruno@clisp.org>
parents: 6984
diff changeset
178 Return its node if found, or NULL if not present in the list. */
0de49c40e105 Add searching operations, limited to a subsequence of the list.
Bruno Haible <bruno@clisp.org>
parents: 6984
diff changeset
179 extern gl_list_node_t gl_list_search_from (gl_list_t list, size_t start_index,
0de49c40e105 Add searching operations, limited to a subsequence of the list.
Bruno Haible <bruno@clisp.org>
parents: 6984
diff changeset
180 const void *elt);
0de49c40e105 Add searching operations, limited to a subsequence of the list.
Bruno Haible <bruno@clisp.org>
parents: 6984
diff changeset
181
0de49c40e105 Add searching operations, limited to a subsequence of the list.
Bruno Haible <bruno@clisp.org>
parents: 6984
diff changeset
182 /* Search whether an element is already in the list,
0de49c40e105 Add searching operations, limited to a subsequence of the list.
Bruno Haible <bruno@clisp.org>
parents: 6984
diff changeset
183 at a position >= START_INDEX and < END_INDEX.
0de49c40e105 Add searching operations, limited to a subsequence of the list.
Bruno Haible <bruno@clisp.org>
parents: 6984
diff changeset
184 Return its node if found, or NULL if not present in the list. */
0de49c40e105 Add searching operations, limited to a subsequence of the list.
Bruno Haible <bruno@clisp.org>
parents: 6984
diff changeset
185 extern gl_list_node_t gl_list_search_from_to (gl_list_t list,
0de49c40e105 Add searching operations, limited to a subsequence of the list.
Bruno Haible <bruno@clisp.org>
parents: 6984
diff changeset
186 size_t start_index,
0de49c40e105 Add searching operations, limited to a subsequence of the list.
Bruno Haible <bruno@clisp.org>
parents: 6984
diff changeset
187 size_t end_index,
0de49c40e105 Add searching operations, limited to a subsequence of the list.
Bruno Haible <bruno@clisp.org>
parents: 6984
diff changeset
188 const void *elt);
0de49c40e105 Add searching operations, limited to a subsequence of the list.
Bruno Haible <bruno@clisp.org>
parents: 6984
diff changeset
189
6984
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
190 /* Search whether an element is already in the list.
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
191 Return its position if found, or (size_t)(-1) if not present in the list. */
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
192 extern size_t gl_list_indexof (gl_list_t list, const void *elt);
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
193
7405
0de49c40e105 Add searching operations, limited to a subsequence of the list.
Bruno Haible <bruno@clisp.org>
parents: 6984
diff changeset
194 /* Search whether an element is already in the list,
0de49c40e105 Add searching operations, limited to a subsequence of the list.
Bruno Haible <bruno@clisp.org>
parents: 6984
diff changeset
195 at a position >= START_INDEX.
0de49c40e105 Add searching operations, limited to a subsequence of the list.
Bruno Haible <bruno@clisp.org>
parents: 6984
diff changeset
196 Return its position if found, or (size_t)(-1) if not present in the list. */
0de49c40e105 Add searching operations, limited to a subsequence of the list.
Bruno Haible <bruno@clisp.org>
parents: 6984
diff changeset
197 extern size_t gl_list_indexof_from (gl_list_t list, size_t start_index,
0de49c40e105 Add searching operations, limited to a subsequence of the list.
Bruno Haible <bruno@clisp.org>
parents: 6984
diff changeset
198 const void *elt);
0de49c40e105 Add searching operations, limited to a subsequence of the list.
Bruno Haible <bruno@clisp.org>
parents: 6984
diff changeset
199
0de49c40e105 Add searching operations, limited to a subsequence of the list.
Bruno Haible <bruno@clisp.org>
parents: 6984
diff changeset
200 /* Search whether an element is already in the list,
0de49c40e105 Add searching operations, limited to a subsequence of the list.
Bruno Haible <bruno@clisp.org>
parents: 6984
diff changeset
201 at a position >= START_INDEX and < END_INDEX.
0de49c40e105 Add searching operations, limited to a subsequence of the list.
Bruno Haible <bruno@clisp.org>
parents: 6984
diff changeset
202 Return its position if found, or (size_t)(-1) if not present in the list. */
0de49c40e105 Add searching operations, limited to a subsequence of the list.
Bruno Haible <bruno@clisp.org>
parents: 6984
diff changeset
203 extern size_t gl_list_indexof_from_to (gl_list_t list,
0de49c40e105 Add searching operations, limited to a subsequence of the list.
Bruno Haible <bruno@clisp.org>
parents: 6984
diff changeset
204 size_t start_index, size_t end_index,
0de49c40e105 Add searching operations, limited to a subsequence of the list.
Bruno Haible <bruno@clisp.org>
parents: 6984
diff changeset
205 const void *elt);
0de49c40e105 Add searching operations, limited to a subsequence of the list.
Bruno Haible <bruno@clisp.org>
parents: 6984
diff changeset
206
6984
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
207 /* Add an element as the first element of the list.
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
208 Return its node. */
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
209 extern gl_list_node_t gl_list_add_first (gl_list_t list, const void *elt);
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
210
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
211 /* Add an element as the last element of the list.
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
212 Return its node. */
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
213 extern gl_list_node_t gl_list_add_last (gl_list_t list, const void *elt);
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
214
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
215 /* Add an element before a given element node of the list.
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
216 Return its node. */
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
217 extern gl_list_node_t gl_list_add_before (gl_list_t list, gl_list_node_t node,
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
218 const void *elt);
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
219
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
220 /* Add an element after a given element node of the list.
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
221 Return its node. */
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
222 extern gl_list_node_t gl_list_add_after (gl_list_t list, gl_list_node_t node,
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
223 const void *elt);
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
224
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
225 /* Add an element add a given position in the list.
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
226 POSITION must be >= 0 and <= gl_list_size (list). */
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
227 extern gl_list_node_t gl_list_add_at (gl_list_t list, size_t position,
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
228 const void *elt);
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
229
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
230 /* Remove an element from the list.
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
231 Return true. */
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
232 extern bool gl_list_remove_node (gl_list_t list, gl_list_node_t node);
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
233
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
234 /* Remove an element at a given position from the list.
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
235 POSITION must be >= 0 and < gl_list_size (list).
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
236 Return true. */
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
237 extern bool gl_list_remove_at (gl_list_t list, size_t position);
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
238
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
239 /* Search and remove an element from the list.
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
240 Return true if it was found and removed. */
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
241 extern bool gl_list_remove (gl_list_t list, const void *elt);
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
242
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
243 /* Free an entire list.
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
244 (But this call does not free the elements of the list.) */
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
245 extern void gl_list_free (gl_list_t list);
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
246
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
247 /* --------------------- gl_list_iterator_t Data Type --------------------- */
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
248
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
249 /* Functions for iterating through a list. */
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
250
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
251 /* Type of an iterator that traverses a list.
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
252 This is a fixed-size struct, so that creation of an iterator doesn't need
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
253 memory allocation on the heap. */
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
254 typedef struct
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
255 {
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
256 /* For fast dispatch of gl_list_iterator_next. */
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
257 const struct gl_list_implementation *vtable;
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
258 /* For detecting whether the last returned element was removed. */
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
259 gl_list_t list;
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
260 size_t count;
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
261 /* Other, implementation-private fields. */
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
262 void *p; void *q;
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
263 size_t i; size_t j;
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
264 } gl_list_iterator_t;
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
265
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
266 /* Create an iterator traversing a list.
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
267 The list contents must not be modified while the iterator is in use,
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
268 except for replacing or removing the last returned element. */
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
269 extern gl_list_iterator_t gl_list_iterator (gl_list_t list);
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
270
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
271 /* Create an iterator traversing the element with indices i,
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
272 start_index <= i < end_index, of a list.
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
273 The list contents must not be modified while the iterator is in use,
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
274 except for replacing or removing the last returned element. */
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
275 extern gl_list_iterator_t gl_list_iterator_from_to (gl_list_t list,
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
276 size_t start_index,
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
277 size_t end_index);
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
278
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
279 /* If there is a next element, store the next element in *ELTP, store its
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
280 node in *NODEP if NODEP is non-NULL, advance the iterator and return true.
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
281 Otherwise, return false. */
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
282 extern bool gl_list_iterator_next (gl_list_iterator_t *iterator,
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
283 const void **eltp, gl_list_node_t *nodep);
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
284
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
285 /* Free an iterator. */
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
286 extern void gl_list_iterator_free (gl_list_iterator_t *iterator);
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
287
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
288 /* ---------------------- Sorted gl_list_t Data Type ---------------------- */
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
289
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
290 /* The following functions are for lists without duplicates where the
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
291 order is given by a sort criterion. */
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
292
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
293 /* Type of function used to compare two elements. Same as for qsort().
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
294 NULL denotes pointer comparison. */
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
295 typedef int (*gl_listelement_compar_fn) (const void *elt1, const void *elt2);
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
296
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
297 /* Search whether an element is already in the list.
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
298 The list is assumed to be sorted with COMPAR.
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
299 Return its node if found, or NULL if not present in the list.
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
300 If the list contains several copies of ELT, the node of the leftmost one is
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
301 returned. */
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
302 extern gl_list_node_t gl_sortedlist_search (gl_list_t list,
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
303 gl_listelement_compar_fn compar,
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
304 const void *elt);
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
305
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
306 /* Search whether an element is already in the list.
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
307 The list is assumed to be sorted with COMPAR.
7410
9704ff2cbdfe Add bounded list search operations.
Bruno Haible <bruno@clisp.org>
parents: 7405
diff changeset
308 Only list elements with indices >= START_INDEX and < END_INDEX are
9704ff2cbdfe Add bounded list search operations.
Bruno Haible <bruno@clisp.org>
parents: 7405
diff changeset
309 considered; the implementation uses these bounds to minimize the number
9704ff2cbdfe Add bounded list search operations.
Bruno Haible <bruno@clisp.org>
parents: 7405
diff changeset
310 of COMPAR invocations.
9704ff2cbdfe Add bounded list search operations.
Bruno Haible <bruno@clisp.org>
parents: 7405
diff changeset
311 Return its node if found, or NULL if not present in the list.
9704ff2cbdfe Add bounded list search operations.
Bruno Haible <bruno@clisp.org>
parents: 7405
diff changeset
312 If the list contains several copies of ELT, the node of the leftmost one is
9704ff2cbdfe Add bounded list search operations.
Bruno Haible <bruno@clisp.org>
parents: 7405
diff changeset
313 returned. */
9704ff2cbdfe Add bounded list search operations.
Bruno Haible <bruno@clisp.org>
parents: 7405
diff changeset
314 extern gl_list_node_t gl_sortedlist_search_from_to (gl_list_t list,
9704ff2cbdfe Add bounded list search operations.
Bruno Haible <bruno@clisp.org>
parents: 7405
diff changeset
315 gl_listelement_compar_fn compar,
9704ff2cbdfe Add bounded list search operations.
Bruno Haible <bruno@clisp.org>
parents: 7405
diff changeset
316 size_t start_index,
9704ff2cbdfe Add bounded list search operations.
Bruno Haible <bruno@clisp.org>
parents: 7405
diff changeset
317 size_t end_index,
9704ff2cbdfe Add bounded list search operations.
Bruno Haible <bruno@clisp.org>
parents: 7405
diff changeset
318 const void *elt);
9704ff2cbdfe Add bounded list search operations.
Bruno Haible <bruno@clisp.org>
parents: 7405
diff changeset
319
9704ff2cbdfe Add bounded list search operations.
Bruno Haible <bruno@clisp.org>
parents: 7405
diff changeset
320 /* Search whether an element is already in the list.
9704ff2cbdfe Add bounded list search operations.
Bruno Haible <bruno@clisp.org>
parents: 7405
diff changeset
321 The list is assumed to be sorted with COMPAR.
6984
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
322 Return its position if found, or (size_t)(-1) if not present in the list.
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
323 If the list contains several copies of ELT, the position of the leftmost one
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
324 is returned. */
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
325 extern size_t gl_sortedlist_indexof (gl_list_t list,
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
326 gl_listelement_compar_fn compar,
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
327 const void *elt);
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
328
7410
9704ff2cbdfe Add bounded list search operations.
Bruno Haible <bruno@clisp.org>
parents: 7405
diff changeset
329 /* Search whether an element is already in the list.
9704ff2cbdfe Add bounded list search operations.
Bruno Haible <bruno@clisp.org>
parents: 7405
diff changeset
330 The list is assumed to be sorted with COMPAR.
9704ff2cbdfe Add bounded list search operations.
Bruno Haible <bruno@clisp.org>
parents: 7405
diff changeset
331 Only list elements with indices >= START_INDEX and < END_INDEX are
9704ff2cbdfe Add bounded list search operations.
Bruno Haible <bruno@clisp.org>
parents: 7405
diff changeset
332 considered; the implementation uses these bounds to minimize the number
9704ff2cbdfe Add bounded list search operations.
Bruno Haible <bruno@clisp.org>
parents: 7405
diff changeset
333 of COMPAR invocations.
9704ff2cbdfe Add bounded list search operations.
Bruno Haible <bruno@clisp.org>
parents: 7405
diff changeset
334 Return its position if found, or (size_t)(-1) if not present in the list.
9704ff2cbdfe Add bounded list search operations.
Bruno Haible <bruno@clisp.org>
parents: 7405
diff changeset
335 If the list contains several copies of ELT, the position of the leftmost one
9704ff2cbdfe Add bounded list search operations.
Bruno Haible <bruno@clisp.org>
parents: 7405
diff changeset
336 is returned. */
9704ff2cbdfe Add bounded list search operations.
Bruno Haible <bruno@clisp.org>
parents: 7405
diff changeset
337 extern size_t gl_sortedlist_indexof_from_to (gl_list_t list,
9704ff2cbdfe Add bounded list search operations.
Bruno Haible <bruno@clisp.org>
parents: 7405
diff changeset
338 gl_listelement_compar_fn compar,
9704ff2cbdfe Add bounded list search operations.
Bruno Haible <bruno@clisp.org>
parents: 7405
diff changeset
339 size_t start_index,
9704ff2cbdfe Add bounded list search operations.
Bruno Haible <bruno@clisp.org>
parents: 7405
diff changeset
340 size_t end_index,
9704ff2cbdfe Add bounded list search operations.
Bruno Haible <bruno@clisp.org>
parents: 7405
diff changeset
341 const void *elt);
9704ff2cbdfe Add bounded list search operations.
Bruno Haible <bruno@clisp.org>
parents: 7405
diff changeset
342
6984
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
343 /* Add an element at the appropriate position in the list.
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
344 The list is assumed to be sorted with COMPAR.
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
345 Return its node. */
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
346 extern gl_list_node_t gl_sortedlist_add (gl_list_t list,
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
347 gl_listelement_compar_fn compar,
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
348 const void *elt);
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
349
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
350 /* Search and remove an element from the list.
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
351 The list is assumed to be sorted with COMPAR.
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
352 Return true if it was found and removed.
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
353 If the list contains several copies of ELT, only the leftmost one is
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
354 removed. */
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
355 extern bool gl_sortedlist_remove (gl_list_t list,
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
356 gl_listelement_compar_fn compar,
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
357 const void *elt);
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
358
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
359 /* ------------------------ Implementation Details ------------------------ */
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
360
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
361 struct gl_list_implementation
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
362 {
7554
579cface12e9 Pure ANSI C!
Bruno Haible <bruno@clisp.org>
parents: 7410
diff changeset
363 /* gl_list_t functions. */
6984
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
364 gl_list_t (*create_empty) (gl_list_implementation_t implementation,
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
365 gl_listelement_equals_fn equals_fn,
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
366 gl_listelement_hashcode_fn hashcode_fn,
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
367 bool allow_duplicates);
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
368 gl_list_t (*create) (gl_list_implementation_t implementation,
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
369 gl_listelement_equals_fn equals_fn,
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
370 gl_listelement_hashcode_fn hashcode_fn,
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
371 bool allow_duplicates,
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
372 size_t count, const void **contents);
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
373 size_t (*size) (gl_list_t list);
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
374 const void * (*node_value) (gl_list_t list, gl_list_node_t node);
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
375 gl_list_node_t (*next_node) (gl_list_t list, gl_list_node_t node);
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
376 gl_list_node_t (*previous_node) (gl_list_t list, gl_list_node_t node);
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
377 const void * (*get_at) (gl_list_t list, size_t position);
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
378 gl_list_node_t (*set_at) (gl_list_t list, size_t position, const void *elt);
7405
0de49c40e105 Add searching operations, limited to a subsequence of the list.
Bruno Haible <bruno@clisp.org>
parents: 6984
diff changeset
379 gl_list_node_t (*search_from_to) (gl_list_t list, size_t start_index,
0de49c40e105 Add searching operations, limited to a subsequence of the list.
Bruno Haible <bruno@clisp.org>
parents: 6984
diff changeset
380 size_t end_index, const void *elt);
0de49c40e105 Add searching operations, limited to a subsequence of the list.
Bruno Haible <bruno@clisp.org>
parents: 6984
diff changeset
381 size_t (*indexof_from_to) (gl_list_t list, size_t start_index,
0de49c40e105 Add searching operations, limited to a subsequence of the list.
Bruno Haible <bruno@clisp.org>
parents: 6984
diff changeset
382 size_t end_index, const void *elt);
6984
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
383 gl_list_node_t (*add_first) (gl_list_t list, const void *elt);
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
384 gl_list_node_t (*add_last) (gl_list_t list, const void *elt);
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
385 gl_list_node_t (*add_before) (gl_list_t list, gl_list_node_t node,
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
386 const void *elt);
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
387 gl_list_node_t (*add_after) (gl_list_t list, gl_list_node_t node,
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
388 const void *elt);
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
389 gl_list_node_t (*add_at) (gl_list_t list, size_t position,
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
390 const void *elt);
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
391 bool (*remove_node) (gl_list_t list, gl_list_node_t node);
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
392 bool (*remove_at) (gl_list_t list, size_t position);
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
393 bool (*remove) (gl_list_t list, const void *elt);
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
394 void (*list_free) (gl_list_t list);
7554
579cface12e9 Pure ANSI C!
Bruno Haible <bruno@clisp.org>
parents: 7410
diff changeset
395 /* gl_list_iterator_t functions. */
6984
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
396 gl_list_iterator_t (*iterator) (gl_list_t list);
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
397 gl_list_iterator_t (*iterator_from_to) (gl_list_t list,
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
398 size_t start_index,
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
399 size_t end_index);
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
400 bool (*iterator_next) (gl_list_iterator_t *iterator,
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
401 const void **eltp, gl_list_node_t *nodep);
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
402 void (*iterator_free) (gl_list_iterator_t *iterator);
7554
579cface12e9 Pure ANSI C!
Bruno Haible <bruno@clisp.org>
parents: 7410
diff changeset
403 /* Sorted gl_list_t functions. */
6984
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
404 gl_list_node_t (*sortedlist_search) (gl_list_t list,
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
405 gl_listelement_compar_fn compar,
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
406 const void *elt);
7410
9704ff2cbdfe Add bounded list search operations.
Bruno Haible <bruno@clisp.org>
parents: 7405
diff changeset
407 gl_list_node_t (*sortedlist_search_from_to) (gl_list_t list,
9704ff2cbdfe Add bounded list search operations.
Bruno Haible <bruno@clisp.org>
parents: 7405
diff changeset
408 gl_listelement_compar_fn compar,
9704ff2cbdfe Add bounded list search operations.
Bruno Haible <bruno@clisp.org>
parents: 7405
diff changeset
409 size_t start_index,
9704ff2cbdfe Add bounded list search operations.
Bruno Haible <bruno@clisp.org>
parents: 7405
diff changeset
410 size_t end_index,
9704ff2cbdfe Add bounded list search operations.
Bruno Haible <bruno@clisp.org>
parents: 7405
diff changeset
411 const void *elt);
6984
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
412 size_t (*sortedlist_indexof) (gl_list_t list,
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
413 gl_listelement_compar_fn compar,
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
414 const void *elt);
7410
9704ff2cbdfe Add bounded list search operations.
Bruno Haible <bruno@clisp.org>
parents: 7405
diff changeset
415 size_t (*sortedlist_indexof_from_to) (gl_list_t list,
9704ff2cbdfe Add bounded list search operations.
Bruno Haible <bruno@clisp.org>
parents: 7405
diff changeset
416 gl_listelement_compar_fn compar,
9704ff2cbdfe Add bounded list search operations.
Bruno Haible <bruno@clisp.org>
parents: 7405
diff changeset
417 size_t start_index, size_t end_index,
9704ff2cbdfe Add bounded list search operations.
Bruno Haible <bruno@clisp.org>
parents: 7405
diff changeset
418 const void *elt);
6984
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
419 gl_list_node_t (*sortedlist_add) (gl_list_t list,
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
420 gl_listelement_compar_fn compar,
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
421 const void *elt);
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
422 bool (*sortedlist_remove) (gl_list_t list,
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
423 gl_listelement_compar_fn compar,
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
424 const void *elt);
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
425 };
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
426
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
427 struct gl_list_impl_base
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
428 {
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
429 const struct gl_list_implementation *vtable;
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
430 gl_listelement_equals_fn equals_fn;
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
431 gl_listelement_hashcode_fn hashcode_fn;
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
432 bool allow_duplicates;
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
433 };
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
434
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
435 #if HAVE_INLINE
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
436
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
437 /* Define all functions of this file as inline accesses to the
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
438 struct gl_list_implementation.
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
439 Use #define to avoid a warning because of extern vs. static. */
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
440
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
441 # define gl_list_create_empty gl_list_create_empty_inline
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
442 static inline gl_list_t
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
443 gl_list_create_empty (gl_list_implementation_t implementation,
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
444 gl_listelement_equals_fn equals_fn,
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
445 gl_listelement_hashcode_fn hashcode_fn,
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
446 bool allow_duplicates)
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
447 {
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
448 return implementation->create_empty (implementation, equals_fn, hashcode_fn,
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
449 allow_duplicates);
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
450 }
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
451
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
452 # define gl_list_create gl_list_create_inline
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
453 static inline gl_list_t
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
454 gl_list_create (gl_list_implementation_t implementation,
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
455 gl_listelement_equals_fn equals_fn,
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
456 gl_listelement_hashcode_fn hashcode_fn,
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
457 bool allow_duplicates,
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
458 size_t count, const void **contents)
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
459 {
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
460 return implementation->create (implementation, equals_fn, hashcode_fn,
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
461 allow_duplicates, count, contents);
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
462 }
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
463
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
464 # define gl_list_size gl_list_size_inline
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
465 static inline size_t
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
466 gl_list_size (gl_list_t list)
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
467 {
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
468 return ((const struct gl_list_impl_base *) list)->vtable
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
469 ->size (list);
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
470 }
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
471
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
472 # define gl_list_node_value gl_list_node_value_inline
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
473 static inline const void *
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
474 gl_list_node_value (gl_list_t list, gl_list_node_t node)
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
475 {
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
476 return ((const struct gl_list_impl_base *) list)->vtable
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
477 ->node_value (list, node);
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
478 }
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
479
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
480 # define gl_list_next_node gl_list_next_node_inline
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
481 static inline gl_list_node_t
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
482 gl_list_next_node (gl_list_t list, gl_list_node_t node)
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
483 {
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
484 return ((const struct gl_list_impl_base *) list)->vtable
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
485 ->next_node (list, node);
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
486 }
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
487
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
488 # define gl_list_previous_node gl_list_previous_node_inline
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
489 static inline gl_list_node_t
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
490 gl_list_previous_node (gl_list_t list, gl_list_node_t node)
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
491 {
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
492 return ((const struct gl_list_impl_base *) list)->vtable
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
493 ->previous_node (list, node);
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
494 }
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
495
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
496 # define gl_list_get_at gl_list_get_at_inline
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
497 static inline const void *
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
498 gl_list_get_at (gl_list_t list, size_t position)
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
499 {
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
500 return ((const struct gl_list_impl_base *) list)->vtable
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
501 ->get_at (list, position);
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
502 }
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
503
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
504 # define gl_list_set_at gl_list_set_at_inline
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
505 static inline gl_list_node_t
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
506 gl_list_set_at (gl_list_t list, size_t position, const void *elt)
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
507 {
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
508 return ((const struct gl_list_impl_base *) list)->vtable
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
509 ->set_at (list, position, elt);
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
510 }
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
511
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
512 # define gl_list_search gl_list_search_inline
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
513 static inline gl_list_node_t
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
514 gl_list_search (gl_list_t list, const void *elt)
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
515 {
7405
0de49c40e105 Add searching operations, limited to a subsequence of the list.
Bruno Haible <bruno@clisp.org>
parents: 6984
diff changeset
516 size_t size = ((const struct gl_list_impl_base *) list)->vtable->size (list);
6984
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
517 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: 6984
diff changeset
518 ->search_from_to (list, 0, size, elt);
0de49c40e105 Add searching operations, limited to a subsequence of the list.
Bruno Haible <bruno@clisp.org>
parents: 6984
diff changeset
519 }
0de49c40e105 Add searching operations, limited to a subsequence of the list.
Bruno Haible <bruno@clisp.org>
parents: 6984
diff changeset
520
0de49c40e105 Add searching operations, limited to a subsequence of the list.
Bruno Haible <bruno@clisp.org>
parents: 6984
diff changeset
521 # define gl_list_search_from gl_list_search_from_inline
0de49c40e105 Add searching operations, limited to a subsequence of the list.
Bruno Haible <bruno@clisp.org>
parents: 6984
diff changeset
522 static inline gl_list_node_t
0de49c40e105 Add searching operations, limited to a subsequence of the list.
Bruno Haible <bruno@clisp.org>
parents: 6984
diff changeset
523 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: 6984
diff changeset
524 {
0de49c40e105 Add searching operations, limited to a subsequence of the list.
Bruno Haible <bruno@clisp.org>
parents: 6984
diff changeset
525 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: 6984
diff changeset
526 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: 6984
diff changeset
527 ->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: 6984
diff changeset
528 }
0de49c40e105 Add searching operations, limited to a subsequence of the list.
Bruno Haible <bruno@clisp.org>
parents: 6984
diff changeset
529
0de49c40e105 Add searching operations, limited to a subsequence of the list.
Bruno Haible <bruno@clisp.org>
parents: 6984
diff changeset
530 # define gl_list_search_from_to gl_list_search_from_to_inline
0de49c40e105 Add searching operations, limited to a subsequence of the list.
Bruno Haible <bruno@clisp.org>
parents: 6984
diff changeset
531 static inline gl_list_node_t
0de49c40e105 Add searching operations, limited to a subsequence of the list.
Bruno Haible <bruno@clisp.org>
parents: 6984
diff changeset
532 gl_list_search_from_to (gl_list_t list, size_t start_index, size_t end_index,
0de49c40e105 Add searching operations, limited to a subsequence of the list.
Bruno Haible <bruno@clisp.org>
parents: 6984
diff changeset
533 const void *elt)
0de49c40e105 Add searching operations, limited to a subsequence of the list.
Bruno Haible <bruno@clisp.org>
parents: 6984
diff changeset
534 {
0de49c40e105 Add searching operations, limited to a subsequence of the list.
Bruno Haible <bruno@clisp.org>
parents: 6984
diff changeset
535 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: 6984
diff changeset
536 ->search_from_to (list, start_index, end_index, elt);
6984
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
537 }
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
538
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
539 # define gl_list_indexof gl_list_indexof_inline
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
540 static inline size_t
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
541 gl_list_indexof (gl_list_t list, const void *elt)
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
542 {
7405
0de49c40e105 Add searching operations, limited to a subsequence of the list.
Bruno Haible <bruno@clisp.org>
parents: 6984
diff changeset
543 size_t size = ((const struct gl_list_impl_base *) list)->vtable->size (list);
6984
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
544 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: 6984
diff changeset
545 ->indexof_from_to (list, 0, size, elt);
0de49c40e105 Add searching operations, limited to a subsequence of the list.
Bruno Haible <bruno@clisp.org>
parents: 6984
diff changeset
546 }
0de49c40e105 Add searching operations, limited to a subsequence of the list.
Bruno Haible <bruno@clisp.org>
parents: 6984
diff changeset
547
0de49c40e105 Add searching operations, limited to a subsequence of the list.
Bruno Haible <bruno@clisp.org>
parents: 6984
diff changeset
548 # define gl_list_indexof_from gl_list_indexof_from_inline
0de49c40e105 Add searching operations, limited to a subsequence of the list.
Bruno Haible <bruno@clisp.org>
parents: 6984
diff changeset
549 static inline size_t
0de49c40e105 Add searching operations, limited to a subsequence of the list.
Bruno Haible <bruno@clisp.org>
parents: 6984
diff changeset
550 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: 6984
diff changeset
551 {
0de49c40e105 Add searching operations, limited to a subsequence of the list.
Bruno Haible <bruno@clisp.org>
parents: 6984
diff changeset
552 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: 6984
diff changeset
553 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: 6984
diff changeset
554 ->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: 6984
diff changeset
555 }
0de49c40e105 Add searching operations, limited to a subsequence of the list.
Bruno Haible <bruno@clisp.org>
parents: 6984
diff changeset
556
0de49c40e105 Add searching operations, limited to a subsequence of the list.
Bruno Haible <bruno@clisp.org>
parents: 6984
diff changeset
557 # define gl_list_indexof_from_to gl_list_indexof_from_to_inline
0de49c40e105 Add searching operations, limited to a subsequence of the list.
Bruno Haible <bruno@clisp.org>
parents: 6984
diff changeset
558 static inline size_t
0de49c40e105 Add searching operations, limited to a subsequence of the list.
Bruno Haible <bruno@clisp.org>
parents: 6984
diff changeset
559 gl_list_indexof_from_to (gl_list_t list, size_t start_index, size_t end_index,
0de49c40e105 Add searching operations, limited to a subsequence of the list.
Bruno Haible <bruno@clisp.org>
parents: 6984
diff changeset
560 const void *elt)
0de49c40e105 Add searching operations, limited to a subsequence of the list.
Bruno Haible <bruno@clisp.org>
parents: 6984
diff changeset
561 {
0de49c40e105 Add searching operations, limited to a subsequence of the list.
Bruno Haible <bruno@clisp.org>
parents: 6984
diff changeset
562 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: 6984
diff changeset
563 ->indexof_from_to (list, start_index, end_index, elt);
6984
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
564 }
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
565
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
566 # define gl_list_add_first gl_list_add_first_inline
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
567 static inline gl_list_node_t
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
568 gl_list_add_first (gl_list_t list, const void *elt)
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
569 {
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
570 return ((const struct gl_list_impl_base *) list)->vtable
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
571 ->add_first (list, elt);
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
572 }
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
573
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
574 # define gl_list_add_last gl_list_add_last_inline
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
575 static inline gl_list_node_t
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
576 gl_list_add_last (gl_list_t list, const void *elt)
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
577 {
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
578 return ((const struct gl_list_impl_base *) list)->vtable
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
579 ->add_last (list, elt);
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
580 }
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
581
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
582 # define gl_list_add_before gl_list_add_before_inline
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
583 static inline gl_list_node_t
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
584 gl_list_add_before (gl_list_t list, gl_list_node_t node, const void *elt)
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
585 {
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
586 return ((const struct gl_list_impl_base *) list)->vtable
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
587 ->add_before (list, node, elt);
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
588 }
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
589
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
590 # define gl_list_add_after gl_list_add_after_inline
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
591 static inline gl_list_node_t
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
592 gl_list_add_after (gl_list_t list, gl_list_node_t node, const void *elt)
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
593 {
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
594 return ((const struct gl_list_impl_base *) list)->vtable
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
595 ->add_after (list, node, elt);
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
596 }
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
597
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
598 # define gl_list_add_at gl_list_add_at_inline
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
599 static inline gl_list_node_t
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
600 gl_list_add_at (gl_list_t list, size_t position, const void *elt)
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
601 {
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
602 return ((const struct gl_list_impl_base *) list)->vtable
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
603 ->add_at (list, position, elt);
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
604 }
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
605
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
606 # define gl_list_remove_node gl_list_remove_node_inline
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
607 static inline bool
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
608 gl_list_remove_node (gl_list_t list, gl_list_node_t node)
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
609 {
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
610 return ((const struct gl_list_impl_base *) list)->vtable
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
611 ->remove_node (list, node);
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
612 }
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
613
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
614 # define gl_list_remove_at gl_list_remove_at_inline
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
615 static inline bool
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
616 gl_list_remove_at (gl_list_t list, size_t position)
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
617 {
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
618 return ((const struct gl_list_impl_base *) list)->vtable
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
619 ->remove_at (list, position);
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
620 }
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
621
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
622 # define gl_list_remove gl_list_remove_inline
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
623 static inline bool
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
624 gl_list_remove (gl_list_t list, const void *elt)
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
625 {
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
626 return ((const struct gl_list_impl_base *) list)->vtable
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
627 ->remove (list, elt);
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
628 }
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
629
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
630 # define gl_list_free gl_list_free_inline
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
631 static inline void
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
632 gl_list_free (gl_list_t list)
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
633 {
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
634 ((const struct gl_list_impl_base *) list)->vtable->list_free (list);
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
635 }
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
636
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
637 # define gl_list_iterator gl_list_iterator_inline
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
638 static inline gl_list_iterator_t
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
639 gl_list_iterator (gl_list_t list)
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
640 {
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
641 return ((const struct gl_list_impl_base *) list)->vtable
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
642 ->iterator (list);
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
643 }
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
644
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
645 # define gl_list_iterator_from_to gl_list_iterator_from_to_inline
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
646 static inline gl_list_iterator_t
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
647 gl_list_iterator_from_to (gl_list_t list, size_t start_index, size_t end_index)
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
648 {
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
649 return ((const struct gl_list_impl_base *) list)->vtable
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
650 ->iterator_from_to (list, start_index, end_index);
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
651 }
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
652
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
653 # define gl_list_iterator_next gl_list_iterator_next_inline
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
654 static inline bool
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
655 gl_list_iterator_next (gl_list_iterator_t *iterator,
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
656 const void **eltp, gl_list_node_t *nodep)
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
657 {
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
658 return iterator->vtable->iterator_next (iterator, eltp, nodep);
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
659 }
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
660
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
661 # define gl_list_iterator_free gl_list_iterator_free_inline
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
662 static inline void
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
663 gl_list_iterator_free (gl_list_iterator_t *iterator)
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
664 {
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
665 iterator->vtable->iterator_free (iterator);
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
666 }
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
667
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
668 # define gl_sortedlist_search gl_sortedlist_search_inline
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
669 static inline gl_list_node_t
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
670 gl_sortedlist_search (gl_list_t list, gl_listelement_compar_fn compar, const void *elt)
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
671 {
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
672 return ((const struct gl_list_impl_base *) list)->vtable
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
673 ->sortedlist_search (list, compar, elt);
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
674 }
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
675
7410
9704ff2cbdfe Add bounded list search operations.
Bruno Haible <bruno@clisp.org>
parents: 7405
diff changeset
676 # define gl_sortedlist_search_from_to gl_sortedlist_search_from_to_inline
9704ff2cbdfe Add bounded list search operations.
Bruno Haible <bruno@clisp.org>
parents: 7405
diff changeset
677 static inline gl_list_node_t
9704ff2cbdfe Add bounded list search operations.
Bruno Haible <bruno@clisp.org>
parents: 7405
diff changeset
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)
9704ff2cbdfe Add bounded list search operations.
Bruno Haible <bruno@clisp.org>
parents: 7405
diff changeset
679 {
9704ff2cbdfe Add bounded list search operations.
Bruno Haible <bruno@clisp.org>
parents: 7405
diff changeset
680 return ((const struct gl_list_impl_base *) list)->vtable
9704ff2cbdfe Add bounded list search operations.
Bruno Haible <bruno@clisp.org>
parents: 7405
diff changeset
681 ->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
682 elt);
9704ff2cbdfe Add bounded list search operations.
Bruno Haible <bruno@clisp.org>
parents: 7405
diff changeset
683 }
9704ff2cbdfe Add bounded list search operations.
Bruno Haible <bruno@clisp.org>
parents: 7405
diff changeset
684
6984
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
685 # define gl_sortedlist_indexof gl_sortedlist_indexof_inline
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
686 static inline size_t
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
687 gl_sortedlist_indexof (gl_list_t list, gl_listelement_compar_fn compar, const void *elt)
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
688 {
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
689 return ((const struct gl_list_impl_base *) list)->vtable
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
690 ->sortedlist_indexof (list, compar, elt);
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
691 }
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
692
7410
9704ff2cbdfe Add bounded list search operations.
Bruno Haible <bruno@clisp.org>
parents: 7405
diff changeset
693 # define gl_sortedlist_indexof_from_to gl_sortedlist_indexof_from_to_inline
9704ff2cbdfe Add bounded list search operations.
Bruno Haible <bruno@clisp.org>
parents: 7405
diff changeset
694 static inline size_t
9704ff2cbdfe Add bounded list search operations.
Bruno Haible <bruno@clisp.org>
parents: 7405
diff changeset
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)
9704ff2cbdfe Add bounded list search operations.
Bruno Haible <bruno@clisp.org>
parents: 7405
diff changeset
696 {
9704ff2cbdfe Add bounded list search operations.
Bruno Haible <bruno@clisp.org>
parents: 7405
diff changeset
697 return ((const struct gl_list_impl_base *) list)->vtable
9704ff2cbdfe Add bounded list search operations.
Bruno Haible <bruno@clisp.org>
parents: 7405
diff changeset
698 ->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
699 elt);
9704ff2cbdfe Add bounded list search operations.
Bruno Haible <bruno@clisp.org>
parents: 7405
diff changeset
700 }
9704ff2cbdfe Add bounded list search operations.
Bruno Haible <bruno@clisp.org>
parents: 7405
diff changeset
701
6984
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
702 # define gl_sortedlist_add gl_sortedlist_add_inline
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
703 static inline gl_list_node_t
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
704 gl_sortedlist_add (gl_list_t list, gl_listelement_compar_fn compar, const void *elt)
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
705 {
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
706 return ((const struct gl_list_impl_base *) list)->vtable
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
707 ->sortedlist_add (list, compar, elt);
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
708 }
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
709
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
710 # define gl_sortedlist_remove gl_sortedlist_remove_inline
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
711 static inline bool
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
712 gl_sortedlist_remove (gl_list_t list, gl_listelement_compar_fn compar, const void *elt)
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
713 {
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
714 return ((const struct gl_list_impl_base *) list)->vtable
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
715 ->sortedlist_remove (list, compar, elt);
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
716 }
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
717
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
718 #endif
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
719
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
720 #ifdef __cplusplus
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
721 }
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
722 #endif
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
723
416726372f54 Abstract list data type.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
724 #endif /* _GL_LIST_H */