src/cx/list.h

changeset 875
ee84ac776cbc
parent 856
6bbbf219251d
child 876
f4ce7df9cff0
equal deleted inserted replaced
874:cdce47f34d48 875:ee84ac776cbc
86 ); 86 );
87 87
88 /** 88 /**
89 * Member function for inserting multiple elements. 89 * Member function for inserting multiple elements.
90 * Implementors SHOULD see to performant implementations for corner cases. 90 * Implementors SHOULD see to performant implementations for corner cases.
91 * @see cx_list_default_insert_array()
91 */ 92 */
92 size_t (*insert_array)( 93 size_t (*insert_array)(
93 struct cx_list_s *list, 94 struct cx_list_s *list,
94 size_t index, 95 size_t index,
95 void const *data, 96 void const *data,
118 */ 119 */
119 void (*clear)(struct cx_list_s *list); 120 void (*clear)(struct cx_list_s *list);
120 121
121 /** 122 /**
122 * Member function for swapping two elements. 123 * Member function for swapping two elements.
124 * @see cx_list_default_swap()
123 */ 125 */
124 int (*swap)( 126 int (*swap)(
125 struct cx_list_s *list, 127 struct cx_list_s *list,
126 size_t i, 128 size_t i,
127 size_t j 129 size_t j
144 bool remove 146 bool remove
145 ); 147 );
146 148
147 /** 149 /**
148 * Member function for sorting the list in-place. 150 * Member function for sorting the list in-place.
151 * @see cx_list_default_sort()
149 */ 152 */
150 void (*sort)(struct cx_list_s *list); 153 void (*sort)(struct cx_list_s *list);
151 154
152 /** 155 /**
153 * Member function for comparing this list to another list of the same type. 156 * Optional member function for comparing this list
157 * to another list of the same type.
158 * If set to \c NULL, comparison won't be optimized.
154 */ 159 */
155 int (*compare)( 160 int (*compare)(
156 struct cx_list_s const *list, 161 struct cx_list_s const *list,
157 struct cx_list_s const *other 162 struct cx_list_s const *other
158 ); 163 );
169 struct cx_list_s const *list, 174 struct cx_list_s const *list,
170 size_t index, 175 size_t index,
171 bool backward 176 bool backward
172 ); 177 );
173 }; 178 };
179
180 /**
181 * Default implementation of an array insert.
182 *
183 * This function uses the element insert function for each element of the array.
184 *
185 * Use this in your own list class if you do not want to implement an optimized
186 * version for your list.
187 *
188 * @param list the list
189 * @param index the index where to insert the data
190 * @param data a pointer to the array of data to insert
191 * @param n the number of elements to insert
192 * @return the number of elements actually inserted
193 */
194 __attribute__((__nonnull__))
195 size_t cx_list_default_insert_array(
196 struct cx_list_s *list,
197 size_t index,
198 void const *data,
199 size_t n
200 );
201
202 /**
203 * Default unoptimized sort implementation.
204 *
205 * This function will copy all data to an array, sort the array with standard
206 * qsort, and then copy the data back to the list memory.
207 *
208 * Use this in your own list class if you do not want to implement an optimized
209 * version for your list.
210 *
211 * @param list the list that shall be sorted
212 */
213 __attribute__((__nonnull__))
214 void cx_list_default_sort(struct cx_list_s *list);
215
216 /**
217 * Default unoptimized swap implementation.
218 *
219 * Use this in your own list class if you do not want to implement an optimized
220 * version for your list.
221 *
222 * @param list the list in which to swap
223 * @param i index of one element
224 * @param j index of the other element
225 */
226 __attribute__((__nonnull__))
227 int cx_list_default_swap(struct cx_list_s *list, size_t i, size_t j);
174 228
175 /** 229 /**
176 * Common type for all list implementations. 230 * Common type for all list implementations.
177 */ 231 */
178 typedef struct cx_list_s CxList; 232 typedef struct cx_list_s CxList;

mercurial