| 289 * |
285 * |
| 290 * Only use this function if you are creating your own list implementation. |
286 * Only use this function if you are creating your own list implementation. |
| 291 * The purpose of this function is to be called in the initialization code |
287 * The purpose of this function is to be called in the initialization code |
| 292 * of your list to set certain members correctly. |
288 * of your list to set certain members correctly. |
| 293 * |
289 * |
| 294 * This is particularly important when you want your list to support |
290 * This is particularly useful when you want your list to support |
| 295 * #CX_STORE_POINTERS as @p elem_size. This function will wrap the list |
291 * #CX_STORE_POINTERS as @p elem_size. |
| 296 * class accordingly and make sure that you can implement your list as if |
|
| 297 * it was only storing objects, and the wrapper will automatically enable |
|
| 298 * the feature of storing pointers. |
|
| 299 * |
292 * |
| 300 * @par Example |
293 * @par Example |
| 301 * |
294 * |
| 302 * @code |
295 * @code |
| 303 * CxList *myCustomListCreate( |
296 * CxList *myCustomListCreate( |
| 304 * const CxAllocator *allocator, |
297 * const CxAllocator *allocator, |
| 305 * cx_compare_func comparator, |
|
| 306 * size_t elem_size |
298 * size_t elem_size |
| 307 * ) { |
299 * ) { |
| 308 * if (allocator == NULL) { |
300 * if (allocator == NULL) { |
| 309 * allocator = cxDefaultAllocator; |
301 * allocator = cxDefaultAllocator; |
| 310 * } |
302 * } |
| 311 * |
303 * |
| 312 * MyCustomList *list = cxCalloc(allocator, 1, sizeof(MyCustomList)); |
304 * MyCustomList *list = cxZalloc(allocator, sizeof(MyCustomList)); |
| 313 * if (list == NULL) return NULL; |
305 * if (list == NULL) return NULL; |
| 314 * |
306 * |
| 315 * // initialize |
307 * // initialize |
| 316 * cx_list_init((CxList*)list, &my_custom_list_class, |
308 * cx_list_init((CxList*)list, &my_custom_list_class, |
| 317 * allocator, comparator, elem_size); |
309 * allocator, elem_size); |
| 318 * |
310 * |
| 319 * // ... some more custom stuff ... |
311 * // ... some more custom stuff ... |
| 320 * |
312 * |
| 321 * return (CxList *) list; |
313 * return (CxList *) list; |
| 322 * } |
314 * } |
| 323 * @endcode |
315 * @endcode |
| 324 * |
316 * |
| 325 * @param list the list to initialize |
317 * @param list the list to initialize |
| 326 * @param cl the list class |
318 * @param cl the list class |
| 327 * @param allocator the allocator for the elements |
319 * @param allocator the allocator for the elements |
| 328 * @param comparator a compare function for the elements |
|
| 329 * @param elem_size the size of one element |
320 * @param elem_size the size of one element |
| 330 */ |
321 */ |
| 331 cx_attr_nonnull_arg(1, 2, 3) |
322 cx_attr_nonnull_arg(1, 2, 3) |
| 332 CX_EXPORT void cx_list_init(struct cx_list_s *list, |
323 CX_EXPORT void cx_list_init(struct cx_list_s *list, |
| 333 struct cx_list_class_s *cl, const struct cx_allocator_s *allocator, |
324 struct cx_list_class_s *cl, const struct cx_allocator_s *allocator, |
| 334 cx_compare_func comparator, size_t elem_size); |
325 size_t elem_size); |
| |
326 |
| |
327 /** |
| |
328 * A @c cx_compare_func2 compatible wrapper for the compare functions of a list. |
| |
329 * |
| |
330 * @param left first element |
| |
331 * @param right second element |
| |
332 * @param list the list which is comparing the elements |
| |
333 * @return the comparison result |
| |
334 */ |
| |
335 cx_attr_nonnull |
| |
336 CX_EXPORT int cx_list_compare_wrapper( |
| |
337 const void *left, const void *right, void *list); |
| 335 |
338 |
| 336 /** |
339 /** |
| 337 * Returns the number of elements currently stored in the list. |
340 * Returns the number of elements currently stored in the list. |
| 338 * |
341 * |
| 339 * @param list the list |
342 * @param list the list |
| 982 * @param clone_func the clone function for the elements |
985 * @param clone_func the clone function for the elements |
| 983 * @param clone_allocator the allocator that is passed to the clone function |
986 * @param clone_allocator the allocator that is passed to the clone function |
| 984 * @param data optional additional data that is passed to the clone function |
987 * @param data optional additional data that is passed to the clone function |
| 985 * @retval zero when all elements were successfully cloned |
988 * @retval zero when all elements were successfully cloned |
| 986 * @retval non-zero when an allocation error occurred |
989 * @retval non-zero when an allocation error occurred |
| 987 * @see cxListCloneSimple() |
990 * @see cxListCloneShallow() |
| 988 */ |
991 */ |
| 989 cx_attr_nonnull_arg(1, 2, 3) |
992 cx_attr_nonnull_arg(1, 2, 3) |
| 990 CX_EXPORT int cxListClone(CxList *dst, const CxList *src, |
993 CX_EXPORT int cxListClone(CxList *dst, const CxList *src, |
| 991 cx_clone_func clone_func, const CxAllocator *clone_allocator, void *data); |
994 cx_clone_func clone_func, const CxAllocator *clone_allocator, void *data); |
| 992 |
995 |
| 1005 * @param clone_func the clone function for the elements |
1008 * @param clone_func the clone function for the elements |
| 1006 * @param clone_allocator the allocator that is passed to the clone function |
1009 * @param clone_allocator the allocator that is passed to the clone function |
| 1007 * @param data optional additional data that is passed to the clone function |
1010 * @param data optional additional data that is passed to the clone function |
| 1008 * @retval zero when the elements were successfully cloned |
1011 * @retval zero when the elements were successfully cloned |
| 1009 * @retval non-zero when an allocation error occurred |
1012 * @retval non-zero when an allocation error occurred |
| 1010 * @see cxListDifferenceSimple() |
1013 * @see cxListDifferenceShallow() |
| 1011 */ |
1014 */ |
| 1012 cx_attr_nonnull_arg(1, 2, 3, 4) |
1015 cx_attr_nonnull_arg(1, 2, 3, 4) |
| 1013 CX_EXPORT int cxListDifference(CxList *dst, |
1016 CX_EXPORT int cxListDifference(CxList *dst, |
| 1014 const CxList *minuend, const CxList *subtrahend, |
1017 const CxList *minuend, const CxList *subtrahend, |
| 1015 cx_clone_func clone_func, const CxAllocator *clone_allocator, void *data); |
1018 cx_clone_func clone_func, const CxAllocator *clone_allocator, void *data); |
| 1029 * @param clone_func the clone function for the elements |
1032 * @param clone_func the clone function for the elements |
| 1030 * @param clone_allocator the allocator that is passed to the clone function |
1033 * @param clone_allocator the allocator that is passed to the clone function |
| 1031 * @param data optional additional data that is passed to the clone function |
1034 * @param data optional additional data that is passed to the clone function |
| 1032 * @retval zero when the elements were successfully cloned |
1035 * @retval zero when the elements were successfully cloned |
| 1033 * @retval non-zero when an allocation error occurred |
1036 * @retval non-zero when an allocation error occurred |
| 1034 * @see cxListIntersectionSimple() |
1037 * @see cxListIntersectionShallow() |
| 1035 */ |
1038 */ |
| 1036 cx_attr_nonnull_arg(1, 2, 3, 4) |
1039 cx_attr_nonnull_arg(1, 2, 3, 4) |
| 1037 CX_EXPORT int cxListIntersection(CxList *dst, const CxList *src, const CxList *other, |
1040 CX_EXPORT int cxListIntersection(CxList *dst, const CxList *src, const CxList *other, |
| 1038 cx_clone_func clone_func, const CxAllocator *clone_allocator, void *data); |
1041 cx_clone_func clone_func, const CxAllocator *clone_allocator, void *data); |
| 1039 |
1042 |
| 1054 * @param clone_func the clone function for the elements |
1057 * @param clone_func the clone function for the elements |
| 1055 * @param clone_allocator the allocator that is passed to the clone function |
1058 * @param clone_allocator the allocator that is passed to the clone function |
| 1056 * @param data optional additional data that is passed to the clone function |
1059 * @param data optional additional data that is passed to the clone function |
| 1057 * @retval zero when the elements were successfully cloned |
1060 * @retval zero when the elements were successfully cloned |
| 1058 * @retval non-zero when an allocation error occurred |
1061 * @retval non-zero when an allocation error occurred |
| 1059 * @see cxListUnionSimple() |
1062 * @see cxListUnionShallow() |
| 1060 */ |
1063 */ |
| 1061 cx_attr_nonnull_arg(1, 2, 3, 4) |
1064 cx_attr_nonnull_arg(1, 2, 3, 4) |
| 1062 CX_EXPORT int cxListUnion(CxList *dst, const CxList *src, const CxList *other, |
1065 CX_EXPORT int cxListUnion(CxList *dst, const CxList *src, const CxList *other, |
| 1063 cx_clone_func clone_func, const CxAllocator *clone_allocator, void *data); |
1066 cx_clone_func clone_func, const CxAllocator *clone_allocator, void *data); |
| 1064 |
1067 |
| 1080 * @retval zero when all elements were successfully cloned |
1083 * @retval zero when all elements were successfully cloned |
| 1081 * @retval non-zero when an allocation error occurred |
1084 * @retval non-zero when an allocation error occurred |
| 1082 * @see cxListClone() |
1085 * @see cxListClone() |
| 1083 */ |
1086 */ |
| 1084 cx_attr_nonnull |
1087 cx_attr_nonnull |
| 1085 CX_EXPORT int cxListCloneSimple(CxList *dst, const CxList *src); |
1088 CX_EXPORT int cxListCloneShallow(CxList *dst, const CxList *src); |
| 1086 |
1089 |
| 1087 /** |
1090 /** |
| 1088 * Clones elements from a list only if they are not present in another list. |
1091 * Clones elements from a list only if they are not present in another list. |
| 1089 * |
1092 * |
| 1090 * This function uses the default allocator, if needed, and performs |
1093 * This function uses the default allocator, if needed, and performs |
| 1125 * @retval zero when the elements were successfully cloned |
1128 * @retval zero when the elements were successfully cloned |
| 1126 * @retval non-zero when an allocation error occurred |
1129 * @retval non-zero when an allocation error occurred |
| 1127 * @see cxListIntersection() |
1130 * @see cxListIntersection() |
| 1128 */ |
1131 */ |
| 1129 cx_attr_nonnull |
1132 cx_attr_nonnull |
| 1130 CX_EXPORT int cxListIntersectionSimple(CxList *dst, const CxList *src, const CxList *other); |
1133 CX_EXPORT int cxListIntersectionShallow(CxList *dst, const CxList *src, const CxList *other); |
| 1131 |
1134 |
| 1132 /** |
1135 /** |
| 1133 * Performs a deep clone of one list into another, skipping duplicates. |
1136 * Performs a deep clone of one list into another, skipping duplicates. |
| 1134 * |
1137 * |
| 1135 * This function uses the default allocator, if needed, and performs |
1138 * This function uses the default allocator, if needed, and performs |
| 1149 * @retval zero when the elements were successfully cloned |
1152 * @retval zero when the elements were successfully cloned |
| 1150 * @retval non-zero when an allocation error occurred |
1153 * @retval non-zero when an allocation error occurred |
| 1151 * @see cxListUnion() |
1154 * @see cxListUnion() |
| 1152 */ |
1155 */ |
| 1153 cx_attr_nonnull |
1156 cx_attr_nonnull |
| 1154 CX_EXPORT int cxListUnionSimple(CxList *dst, const CxList *src, const CxList *other); |
1157 CX_EXPORT int cxListUnionShallow(CxList *dst, const CxList *src, const CxList *other); |
| 1155 |
1158 |
| 1156 /** |
1159 /** |
| 1157 * Asks the list to reserve enough memory for a given total number of elements. |
1160 * Asks the list to reserve enough memory for a given total number of elements. |
| 1158 * |
1161 * |
| 1159 * List implementations are free to choose if reserving memory upfront makes |
1162 * List implementations are free to choose if reserving memory upfront makes |