| 300 * @par Example |
296 * @par Example |
| 301 * |
297 * |
| 302 * @code |
298 * @code |
| 303 * CxList *myCustomListCreate( |
299 * CxList *myCustomListCreate( |
| 304 * const CxAllocator *allocator, |
300 * const CxAllocator *allocator, |
| 305 * cx_compare_func comparator, |
|
| 306 * size_t elem_size |
301 * size_t elem_size |
| 307 * ) { |
302 * ) { |
| 308 * if (allocator == NULL) { |
303 * if (allocator == NULL) { |
| 309 * allocator = cxDefaultAllocator; |
304 * allocator = cxDefaultAllocator; |
| 310 * } |
305 * } |
| 311 * |
306 * |
| 312 * MyCustomList *list = cxCalloc(allocator, 1, sizeof(MyCustomList)); |
307 * MyCustomList *list = cxZalloc(allocator, sizeof(MyCustomList)); |
| 313 * if (list == NULL) return NULL; |
308 * if (list == NULL) return NULL; |
| 314 * |
309 * |
| 315 * // initialize |
310 * // initialize |
| 316 * cx_list_init((CxList*)list, &my_custom_list_class, |
311 * cx_list_init((CxList*)list, &my_custom_list_class, |
| 317 * allocator, comparator, elem_size); |
312 * allocator, elem_size); |
| 318 * |
313 * |
| 319 * // ... some more custom stuff ... |
314 * // ... some more custom stuff ... |
| 320 * |
315 * |
| 321 * return (CxList *) list; |
316 * return (CxList *) list; |
| 322 * } |
317 * } |
| 323 * @endcode |
318 * @endcode |
| 324 * |
319 * |
| 325 * @param list the list to initialize |
320 * @param list the list to initialize |
| 326 * @param cl the list class |
321 * @param cl the list class |
| 327 * @param allocator the allocator for the elements |
322 * @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 |
323 * @param elem_size the size of one element |
| 330 */ |
324 */ |
| 331 cx_attr_nonnull_arg(1, 2, 3) |
325 cx_attr_nonnull_arg(1, 2, 3) |
| 332 CX_EXPORT void cx_list_init(struct cx_list_s *list, |
326 CX_EXPORT void cx_list_init(struct cx_list_s *list, |
| 333 struct cx_list_class_s *cl, const struct cx_allocator_s *allocator, |
327 struct cx_list_class_s *cl, const struct cx_allocator_s *allocator, |
| 334 cx_compare_func comparator, size_t elem_size); |
328 size_t elem_size); |
| |
329 |
| |
330 /** |
| |
331 * A @c cx_compare_func2 compatible wrapper for the compare functions of a list. |
| |
332 * |
| |
333 * @param left first element |
| |
334 * @param right second element |
| |
335 * @param list the list which is comparing the elements |
| |
336 * @return the comparison result |
| |
337 */ |
| |
338 cx_attr_nonnull |
| |
339 CX_EXPORT int cx_list_compare_wrapper( |
| |
340 const void *left, const void *right, void *list); |
| 335 |
341 |
| 336 /** |
342 /** |
| 337 * Returns the number of elements currently stored in the list. |
343 * Returns the number of elements currently stored in the list. |
| 338 * |
344 * |
| 339 * @param list the list |
345 * @param list the list |
| 982 * @param clone_func the clone function for the elements |
988 * @param clone_func the clone function for the elements |
| 983 * @param clone_allocator the allocator that is passed to the clone function |
989 * @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 |
990 * @param data optional additional data that is passed to the clone function |
| 985 * @retval zero when all elements were successfully cloned |
991 * @retval zero when all elements were successfully cloned |
| 986 * @retval non-zero when an allocation error occurred |
992 * @retval non-zero when an allocation error occurred |
| 987 * @see cxListCloneSimple() |
993 * @see cxListCloneShallow() |
| 988 */ |
994 */ |
| 989 cx_attr_nonnull_arg(1, 2, 3) |
995 cx_attr_nonnull_arg(1, 2, 3) |
| 990 CX_EXPORT int cxListClone(CxList *dst, const CxList *src, |
996 CX_EXPORT int cxListClone(CxList *dst, const CxList *src, |
| 991 cx_clone_func clone_func, const CxAllocator *clone_allocator, void *data); |
997 cx_clone_func clone_func, const CxAllocator *clone_allocator, void *data); |
| 992 |
998 |
| 1005 * @param clone_func the clone function for the elements |
1011 * @param clone_func the clone function for the elements |
| 1006 * @param clone_allocator the allocator that is passed to the clone function |
1012 * @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 |
1013 * @param data optional additional data that is passed to the clone function |
| 1008 * @retval zero when the elements were successfully cloned |
1014 * @retval zero when the elements were successfully cloned |
| 1009 * @retval non-zero when an allocation error occurred |
1015 * @retval non-zero when an allocation error occurred |
| 1010 * @see cxListDifferenceSimple() |
1016 * @see cxListDifferenceShallow() |
| 1011 */ |
1017 */ |
| 1012 cx_attr_nonnull_arg(1, 2, 3, 4) |
1018 cx_attr_nonnull_arg(1, 2, 3, 4) |
| 1013 CX_EXPORT int cxListDifference(CxList *dst, |
1019 CX_EXPORT int cxListDifference(CxList *dst, |
| 1014 const CxList *minuend, const CxList *subtrahend, |
1020 const CxList *minuend, const CxList *subtrahend, |
| 1015 cx_clone_func clone_func, const CxAllocator *clone_allocator, void *data); |
1021 cx_clone_func clone_func, const CxAllocator *clone_allocator, void *data); |
| 1029 * @param clone_func the clone function for the elements |
1035 * @param clone_func the clone function for the elements |
| 1030 * @param clone_allocator the allocator that is passed to the clone function |
1036 * @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 |
1037 * @param data optional additional data that is passed to the clone function |
| 1032 * @retval zero when the elements were successfully cloned |
1038 * @retval zero when the elements were successfully cloned |
| 1033 * @retval non-zero when an allocation error occurred |
1039 * @retval non-zero when an allocation error occurred |
| 1034 * @see cxListIntersectionSimple() |
1040 * @see cxListIntersectionShallow() |
| 1035 */ |
1041 */ |
| 1036 cx_attr_nonnull_arg(1, 2, 3, 4) |
1042 cx_attr_nonnull_arg(1, 2, 3, 4) |
| 1037 CX_EXPORT int cxListIntersection(CxList *dst, const CxList *src, const CxList *other, |
1043 CX_EXPORT int cxListIntersection(CxList *dst, const CxList *src, const CxList *other, |
| 1038 cx_clone_func clone_func, const CxAllocator *clone_allocator, void *data); |
1044 cx_clone_func clone_func, const CxAllocator *clone_allocator, void *data); |
| 1039 |
1045 |
| 1054 * @param clone_func the clone function for the elements |
1060 * @param clone_func the clone function for the elements |
| 1055 * @param clone_allocator the allocator that is passed to the clone function |
1061 * @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 |
1062 * @param data optional additional data that is passed to the clone function |
| 1057 * @retval zero when the elements were successfully cloned |
1063 * @retval zero when the elements were successfully cloned |
| 1058 * @retval non-zero when an allocation error occurred |
1064 * @retval non-zero when an allocation error occurred |
| 1059 * @see cxListUnionSimple() |
1065 * @see cxListUnionShallow() |
| 1060 */ |
1066 */ |
| 1061 cx_attr_nonnull_arg(1, 2, 3, 4) |
1067 cx_attr_nonnull_arg(1, 2, 3, 4) |
| 1062 CX_EXPORT int cxListUnion(CxList *dst, const CxList *src, const CxList *other, |
1068 CX_EXPORT int cxListUnion(CxList *dst, const CxList *src, const CxList *other, |
| 1063 cx_clone_func clone_func, const CxAllocator *clone_allocator, void *data); |
1069 cx_clone_func clone_func, const CxAllocator *clone_allocator, void *data); |
| 1064 |
1070 |
| 1080 * @retval zero when all elements were successfully cloned |
1086 * @retval zero when all elements were successfully cloned |
| 1081 * @retval non-zero when an allocation error occurred |
1087 * @retval non-zero when an allocation error occurred |
| 1082 * @see cxListClone() |
1088 * @see cxListClone() |
| 1083 */ |
1089 */ |
| 1084 cx_attr_nonnull |
1090 cx_attr_nonnull |
| 1085 CX_EXPORT int cxListCloneSimple(CxList *dst, const CxList *src); |
1091 CX_EXPORT int cxListCloneShallow(CxList *dst, const CxList *src); |
| 1086 |
1092 |
| 1087 /** |
1093 /** |
| 1088 * Clones elements from a list only if they are not present in another list. |
1094 * Clones elements from a list only if they are not present in another list. |
| 1089 * |
1095 * |
| 1090 * This function uses the default allocator, if needed, and performs |
1096 * This function uses the default allocator, if needed, and performs |
| 1102 * @retval zero when the elements were successfully cloned |
1108 * @retval zero when the elements were successfully cloned |
| 1103 * @retval non-zero when an allocation error occurred |
1109 * @retval non-zero when an allocation error occurred |
| 1104 * @see cxListDifference() |
1110 * @see cxListDifference() |
| 1105 */ |
1111 */ |
| 1106 cx_attr_nonnull |
1112 cx_attr_nonnull |
| 1107 CX_EXPORT int cxListDifferenceSimple(CxList *dst, |
1113 CX_EXPORT int cxListDifferenceShallow(CxList *dst, |
| 1108 const CxList *minuend, const CxList *subtrahend); |
1114 const CxList *minuend, const CxList *subtrahend); |
| 1109 |
1115 |
| 1110 /** |
1116 /** |
| 1111 * Clones elements from a list only if they are also present in another list. |
1117 * Clones elements from a list only if they are also present in another list. |
| 1112 * |
1118 * |
| 1125 * @retval zero when the elements were successfully cloned |
1131 * @retval zero when the elements were successfully cloned |
| 1126 * @retval non-zero when an allocation error occurred |
1132 * @retval non-zero when an allocation error occurred |
| 1127 * @see cxListIntersection() |
1133 * @see cxListIntersection() |
| 1128 */ |
1134 */ |
| 1129 cx_attr_nonnull |
1135 cx_attr_nonnull |
| 1130 CX_EXPORT int cxListIntersectionSimple(CxList *dst, const CxList *src, const CxList *other); |
1136 CX_EXPORT int cxListIntersectionShallow(CxList *dst, const CxList *src, const CxList *other); |
| 1131 |
1137 |
| 1132 /** |
1138 /** |
| 1133 * Performs a deep clone of one list into another, skipping duplicates. |
1139 * Performs a deep clone of one list into another, skipping duplicates. |
| 1134 * |
1140 * |
| 1135 * This function uses the default allocator, if needed, and performs |
1141 * This function uses the default allocator, if needed, and performs |
| 1149 * @retval zero when the elements were successfully cloned |
1155 * @retval zero when the elements were successfully cloned |
| 1150 * @retval non-zero when an allocation error occurred |
1156 * @retval non-zero when an allocation error occurred |
| 1151 * @see cxListUnion() |
1157 * @see cxListUnion() |
| 1152 */ |
1158 */ |
| 1153 cx_attr_nonnull |
1159 cx_attr_nonnull |
| 1154 CX_EXPORT int cxListUnionSimple(CxList *dst, const CxList *src, const CxList *other); |
1160 CX_EXPORT int cxListUnionShallow(CxList *dst, const CxList *src, const CxList *other); |
| 1155 |
1161 |
| 1156 /** |
1162 /** |
| 1157 * Asks the list to reserve enough memory for a given total number of elements. |
1163 * Asks the list to reserve enough memory for a given total number of elements. |
| 1158 * |
1164 * |
| 1159 * List implementations are free to choose if reserving memory upfront makes |
1165 * List implementations are free to choose if reserving memory upfront makes |