215 interpreting the `elem` as an array of size one, copied to the past-by-one index of the target array. |
215 interpreting the `elem` as an array of size one, copied to the past-by-one index of the target array. |
216 |
216 |
217 ## Insertion Sort |
217 ## Insertion Sort |
218 |
218 |
219 ```C |
219 ```C |
|
220 #include <cx/array_list.h> |
|
221 |
220 int cx_array_insert_sorted( |
222 int cx_array_insert_sorted( |
221 void **target, size_t *size, size_t *capacity, |
223 void **target, size_t *size, size_t *capacity, |
222 cx_compare_func cmp_func, |
224 cx_compare_func cmp_func, |
223 const void *src, size_t elem_size, size_t elem_count, |
225 const void *src, size_t elem_size, size_t elem_count, |
224 CxArrayReallocator *reallocator); |
226 CxArrayReallocator *reallocator); |
248 |
250 |
249 If either the target or the source array is not already sorted with respect to the given compare function, the behavior is undefined. |
251 If either the target or the source array is not already sorted with respect to the given compare function, the behavior is undefined. |
250 |
252 |
251 The convenience macros are all calling `cx_array_insert_sorted()` by deducing the missing arguments. |
253 The convenience macros are all calling `cx_array_insert_sorted()` by deducing the missing arguments. |
252 The `cx_array_add_sorted()` family of macros are interpreting the `elem` as a `src` array with an `elem_count` of one. |
254 The `cx_array_add_sorted()` family of macros are interpreting the `elem` as a `src` array with an `elem_count` of one. |
|
255 |
|
256 ## Sets of Unique Elements |
|
257 |
|
258 ```C |
|
259 #include <cx/array_list.h> |
|
260 |
|
261 int cx_array_insert_unique( |
|
262 void **target, size_t *size, size_t *capacity, |
|
263 cx_compare_func cmp_func, |
|
264 const void *src, size_t elem_size, size_t elem_count, |
|
265 CxArrayReallocator *reallocator); |
|
266 |
|
267 #define cx_array_simple_insert_unique(ARRAY, |
|
268 src, elem_count, cmp_func) |
|
269 |
|
270 #define cx_array_simple_insert_unique_a(reallocator, ARRAY, |
|
271 src, elem_count, cmp_func) |
|
272 |
|
273 #define cx_array_add_unique(target, size, capacity, |
|
274 elem_size, elem, cx_compare_func cmp_func, reallocator); |
|
275 |
|
276 #define cx_array_simple_add_unique(ARRAY, |
|
277 elem, cmp_func) |
|
278 |
|
279 #define cx_array_simple_add_unique_a(reallocator, ARRAY, |
|
280 elem, cmp_func) |
|
281 ``` |
|
282 |
|
283 The above functions are similar to `cx_array_insert_sorted()` and its [relatives](#insertion-sort), |
|
284 except that they skip insertion of elements that are already present in the target array. |
253 |
285 |
254 ## Binary Search |
286 ## Binary Search |
255 |
287 |
256 ```C |
288 ```C |
257 #include <cx/array_list.h> |
289 #include <cx/array_list.h> |