src/cx/array_list.h

changeset 891
49d8cff6f0ee
parent 890
54565fd74e74
equal deleted inserted replaced
890:54565fd74e74 891:49d8cff6f0ee
157 * @param elem_count the number of elements to copy 157 * @param elem_count the number of elements to copy
158 * @param reallocator the array reallocator to use, or \c NULL 158 * @param reallocator the array reallocator to use, or \c NULL
159 * if reallocation shall not happen 159 * if reallocation shall not happen
160 * @return zero on success, non-zero error code on failure 160 * @return zero on success, non-zero error code on failure
161 */ 161 */
162 __attribute__((__nonnull__(1, 2, 5)))
162 enum cx_array_result cx_array_copy( 163 enum cx_array_result cx_array_copy(
163 void **target, 164 void **target,
164 size_t *size, 165 size_t *size,
165 size_t *capacity, 166 size_t *capacity,
166 size_t index, 167 size_t index,
167 const void *src, 168 const void *src,
168 size_t elem_size, 169 size_t elem_size,
169 size_t elem_count, 170 size_t elem_count,
170 struct cx_array_reallocator_s *reallocator 171 struct cx_array_reallocator_s *reallocator
171 ) __attribute__((__nonnull__(1, 2, 5))); 172 );
172 173
173 /** 174 /**
174 * Convenience macro that uses cx_array_copy() with a default layout and the default reallocator. 175 * Convenience macro that uses cx_array_copy() with a default layout and the default reallocator.
175 * 176 *
176 * @param array the name of the array (NOT a pointer to the array) 177 * @param array the name of the array (NOT a pointer to the array)
234 * @param elem_size the size of one element 235 * @param elem_size the size of one element
235 * @param elem_count the number of elements to insert 236 * @param elem_count the number of elements to insert
236 * @param reallocator the array reallocator to use 237 * @param reallocator the array reallocator to use
237 * @return zero on success, non-zero error code on failure 238 * @return zero on success, non-zero error code on failure
238 */ 239 */
240 __attribute__((__nonnull__))
239 enum cx_array_result cx_array_insert_sorted( 241 enum cx_array_result cx_array_insert_sorted(
240 void **target, 242 void **target,
241 size_t *size, 243 size_t *size,
242 size_t *capacity, 244 size_t *capacity,
243 cx_compare_func cmp_func, 245 cx_compare_func cmp_func,
244 const void *src, 246 const void *src,
245 size_t elem_size, 247 size_t elem_size,
246 size_t elem_count, 248 size_t elem_count,
247 struct cx_array_reallocator_s *reallocator 249 struct cx_array_reallocator_s *reallocator
248 ) __attribute__((__nonnull__)); 250 );
249 251
250 /** 252 /**
251 * Inserts an element into a sorted array. 253 * Inserts an element into a sorted array.
252 * 254 *
253 * If the target array is not already sorted with respect 255 * If the target array is not already sorted with respect
313 * @param elem_size the size of one element 315 * @param elem_size the size of one element
314 * @param elem the element to find 316 * @param elem the element to find
315 * @param cmp_func the compare function 317 * @param cmp_func the compare function
316 * @return the index of the largest lower bound, or \p size 318 * @return the index of the largest lower bound, or \p size
317 */ 319 */
320 __attribute__((__nonnull__))
318 size_t cx_array_binary_search_inf( 321 size_t cx_array_binary_search_inf(
319 const void *arr, 322 const void *arr,
320 size_t size, 323 size_t size,
321 size_t elem_size, 324 size_t elem_size,
322 const void *elem, 325 const void *elem,
323 cx_compare_func cmp_func 326 cx_compare_func cmp_func
324 ) __attribute__((__nonnull__)); 327 );
325 328
326 /** 329 /**
327 * Searches an item in a sorted array. 330 * Searches an item in a sorted array.
328 * 331 *
329 * If the array is not sorted with respect to the \p cmp_func, the behavior 332 * If the array is not sorted with respect to the \p cmp_func, the behavior
400 * @param arr the array 403 * @param arr the array
401 * @param elem_size the element size 404 * @param elem_size the element size
402 * @param idx1 index of first element 405 * @param idx1 index of first element
403 * @param idx2 index of second element 406 * @param idx2 index of second element
404 */ 407 */
408 __attribute__((__nonnull__))
405 void cx_array_swap( 409 void cx_array_swap(
406 void *arr, 410 void *arr,
407 size_t elem_size, 411 size_t elem_size,
408 size_t idx1, 412 size_t idx1,
409 size_t idx2 413 size_t idx2
410 ) __attribute__((__nonnull__)); 414 );
411 415
412 /** 416 /**
413 * Allocates an array list for storing elements with \p elem_size bytes each. 417 * Allocates an array list for storing elements with \p elem_size bytes each.
414 * 418 *
415 * If \p elem_size is CX_STORE_POINTERS, the created list will be created as if 419 * If \p elem_size is CX_STORE_POINTERS, the created list will be created as if

mercurial