120 * Destructor function. |
120 * Destructor function. |
121 */ |
121 */ |
122 void (*destructor)(struct cx_list_s *list); |
122 void (*destructor)(struct cx_list_s *list); |
123 |
123 |
124 /** |
124 /** |
125 * Member function for adding an element. |
|
126 */ |
|
127 int (*add)( |
|
128 struct cx_list_s *list, |
|
129 void const *elem |
|
130 ); |
|
131 |
|
132 /** |
|
133 * Member function for adding multiple elements. |
|
134 */ |
|
135 size_t (*add_array)( |
|
136 struct cx_list_s *list, |
|
137 void const *array, |
|
138 size_t n |
|
139 ); |
|
140 |
|
141 /** |
|
142 * Member function for inserting an element. |
|
143 */ |
|
144 int (*insert)( |
|
145 struct cx_list_s *list, |
|
146 size_t index, |
|
147 void const *elem |
|
148 ); |
|
149 |
|
150 /** |
|
151 * Member function for inserting multiple elements. |
125 * Member function for inserting multiple elements. |
|
126 * Implementors SHOULD see to performant implementations for corner cases. |
152 */ |
127 */ |
153 size_t (*insert_array)( |
128 size_t (*insert_array)( |
154 struct cx_list_s *list, |
129 struct cx_list_s *list, |
155 size_t index, |
130 size_t index, |
156 void const *data, |
131 void const *data, |
207 * Member function for reversing the order of the items. |
182 * Member function for reversing the order of the items. |
208 */ |
183 */ |
209 void (*reverse)(struct cx_list_s *list); |
184 void (*reverse)(struct cx_list_s *list); |
210 |
185 |
211 /** |
186 /** |
212 * Returns an iterator pointing to the specified index. |
187 * Member function for returning an iterator pointing to the specified index. |
213 */ |
188 */ |
214 struct cx_iterator_s (*iterator)( |
189 struct cx_iterator_s (*iterator)( |
215 struct cx_list_s const *list, |
190 struct cx_list_s const *list, |
216 size_t index |
191 size_t index |
217 ); |
192 ); |
218 |
|
219 /** |
|
220 * Returns a mutating iterator pointing to the specified index. |
|
221 */ |
|
222 struct cx_mut_iterator_s (*mut_iterator)( |
|
223 struct cx_list_s *list, |
|
224 size_t index |
|
225 ); |
|
226 }; |
193 }; |
227 |
194 |
228 /** |
195 /** |
229 * Common type for all list implementations. |
196 * Common type for all list implementations. |
230 */ |
197 */ |
241 __attribute__((__nonnull__)) |
208 __attribute__((__nonnull__)) |
242 static inline int cxListAdd( |
209 static inline int cxListAdd( |
243 CxList *list, |
210 CxList *list, |
244 void const *elem |
211 void const *elem |
245 ) { |
212 ) { |
246 return list->cl->add(list, elem); |
213 return list->cl->insert_array(list, list->size, elem, 1) != 1; |
247 } |
214 } |
248 |
215 |
249 /** |
216 /** |
250 * Adds multiple items to the end of the list. |
217 * Adds multiple items to the end of the list. |
251 * |
218 * |
285 static inline int cxListInsert( |
252 static inline int cxListInsert( |
286 CxList *list, |
253 CxList *list, |
287 size_t index, |
254 size_t index, |
288 void const *elem |
255 void const *elem |
289 ) { |
256 ) { |
290 return list->cl->insert(list, index, elem); |
257 return list->cl->insert_array(list, index, elem, 1) != 1; |
291 } |
258 } |
292 |
259 |
293 /** |
260 /** |
294 * Inserts multiple items to the list at the specified index. |
261 * Inserts multiple items to the list at the specified index. |
295 * If \p index equals the list size, this is effectively cxListAddArray(). |
262 * If \p index equals the list size, this is effectively cxListAddArray(). |
420 * @param list the list |
387 * @param list the list |
421 * @param index the index where the iterator shall point at |
388 * @param index the index where the iterator shall point at |
422 * @return a new iterator |
389 * @return a new iterator |
423 */ |
390 */ |
424 __attribute__((__nonnull__, __warn_unused_result__)) |
391 __attribute__((__nonnull__, __warn_unused_result__)) |
425 static inline CxMutIterator cxListMutIterator( |
392 CxMutIterator cxListMutIterator( |
426 CxList *list, |
393 CxList *list, |
427 size_t index |
394 size_t index |
428 ) { |
395 ); |
429 return list->cl->mut_iterator(list, index); |
|
430 } |
|
431 |
396 |
432 /** |
397 /** |
433 * Returns an iterator pointing to the first item of the list. |
398 * Returns an iterator pointing to the first item of the list. |
434 * |
399 * |
435 * The returned iterator is position-aware. |
400 * The returned iterator is position-aware. |
454 * @param list the list |
419 * @param list the list |
455 * @return a new iterator |
420 * @return a new iterator |
456 */ |
421 */ |
457 __attribute__((__nonnull__, __warn_unused_result__)) |
422 __attribute__((__nonnull__, __warn_unused_result__)) |
458 static inline CxMutIterator cxListBeginMut(CxList *list) { |
423 static inline CxMutIterator cxListBeginMut(CxList *list) { |
459 return list->cl->mut_iterator(list, 0); |
424 return cxListMutIterator(list, 0); |
460 } |
425 } |
461 |
426 |
462 /** |
427 /** |
463 * Returns the index of the first element that equals \p elem. |
428 * Returns the index of the first element that equals \p elem. |
464 * |
429 * |