src/ucx/array.h

branch
feature/array
changeset 356
77efe51c6c9a
parent 355
d315a068235a
child 357
0f5732f0dc00
     1.1 --- a/src/ucx/array.h	Tue Sep 24 20:16:00 2019 +0200
     1.2 +++ b/src/ucx/array.h	Thu Oct 03 10:55:39 2019 +0200
     1.3 @@ -145,9 +145,9 @@
     1.4   * Creates a new UCX array with the given capacity and element size.
     1.5   * @param capacity the initial capacity
     1.6   * @param elemsize the element size
     1.7 - * @return a new UCX array structure
     1.8 + * @return a pointer to a new UCX array structure
     1.9   */
    1.10 -UcxArray ucx_array_new(size_t capacity, size_t elemsize);
    1.11 +UcxArray* ucx_array_new(size_t capacity, size_t elemsize);
    1.12  
    1.13  /**
    1.14   * Creates a new UCX array using the specified allocator.
    1.15 @@ -155,20 +155,44 @@
    1.16   * @param capacity the initial capacity
    1.17   * @param elemsize the element size
    1.18   * @param allocator the allocator to use
    1.19 - * @return a new UCX array structure
    1.20 + * @return a pointer to new UCX array structure
    1.21   */
    1.22 -UcxArray ucx_array_new_a(size_t capacity, size_t elemsize,
    1.23 +UcxArray* ucx_array_new_a(size_t capacity, size_t elemsize,
    1.24 +        UcxAllocator* allocator);
    1.25 +
    1.26 +/**
    1.27 + * Initializes a UCX array structure with the given capacity and element size.
    1.28 + * The structure must be uninitialized as the data pointer will be overwritten.
    1.29 + * 
    1.30 + * @param array the structure to initialize
    1.31 + * @param capacity the initial capacity
    1.32 + * @param elemsize the element size
    1.33 + */
    1.34 +void ucx_array_init(UcxArray* array, size_t capacity, size_t elemsize);
    1.35 +
    1.36 +/**
    1.37 + * Initializes a UCX array structure using the specified allocator.
    1.38 + * The structure must be uninitialized as the data pointer will be overwritten.
    1.39 + * 
    1.40 + * @param capacity the initial capacity
    1.41 + * @param elemsize the element size
    1.42 + * @param allocator the allocator to use
    1.43 + */
    1.44 +void ucx_array_init_a(UcxArray* array, size_t capacity, size_t elemsize,
    1.45          UcxAllocator* allocator);
    1.46  
    1.47  /**
    1.48   * Creates an shallow copy of an array.
    1.49   * 
    1.50   * This function clones the specified array by using memcpy().
    1.51 + * If the destination capacity is insufficient, an automatic reallocation is
    1.52 + * attempted.
    1.53   * 
    1.54 - * @param array the array to copy
    1.55 - * @return the copy (may be an empty array on allocation errors)
    1.56 + * @param dest the array to copy to
    1.57 + * @param src the array to copy from
    1.58 + * @return zero on success, non-zero on reallocation failure.
    1.59   */
    1.60 -UcxArray ucx_array_clone(UcxArray array);
    1.61 +int ucx_array_clone(UcxArray* dest, UcxArray const* src);
    1.62  
    1.63  
    1.64  /**
    1.65 @@ -187,7 +211,7 @@
    1.66   * @param data additional data for the compare function
    1.67   * @return 1, if and only if the two arrays equal element-wise, 0 otherwise
    1.68   */
    1.69 -int ucx_array_equals(UcxArray array1, UcxArray array2,
    1.70 +int ucx_array_equals(UcxArray const *array1, UcxArray const *array2,
    1.71          cmp_func cmpfnc, void* data);
    1.72  
    1.73  /**
    1.74 @@ -202,6 +226,13 @@
    1.75  void ucx_array_destroy(UcxArray *array);
    1.76  
    1.77  /**
    1.78 + * Destroys and frees the array.
    1.79 + * 
    1.80 + * @param array the array to free
    1.81 + */
    1.82 +void ucx_array_free(UcxArray *array);
    1.83 +
    1.84 +/**
    1.85   * Inserts elements at the end of the array.
    1.86   * 
    1.87   * This is an O(1) operation.
    1.88 @@ -362,7 +393,7 @@
    1.89   * @return a pointer to the element at the specified index or <code>NULL</code>,
    1.90   * if the index is greater than the array size
    1.91   */
    1.92 -void *ucx_array_at(UcxArray array, size_t index);
    1.93 +void *ucx_array_at(UcxArray const* array, size_t index);
    1.94  
    1.95  /**
    1.96   * Returns the index of an element containing the specified data.
    1.97 @@ -381,7 +412,8 @@
    1.98   * @return the index of the element containing the specified data or the size of
    1.99   * the array, if the data is not found in this array
   1.100   */
   1.101 -size_t ucx_array_find(UcxArray array, void *elem, cmp_func cmpfnc, void *data);
   1.102 +size_t ucx_array_find(UcxArray const *array, void *elem,
   1.103 +    cmp_func cmpfnc, void *data);
   1.104  
   1.105  /**
   1.106   * Checks, if an array contains a specific element.
   1.107 @@ -395,7 +427,8 @@
   1.108   * @return 1, if and only if the array contains the specified element data
   1.109   * @see ucx_array_find()
   1.110   */
   1.111 -int ucx_array_contains(UcxArray array, void *elem, cmp_func cmpfnc, void *data);
   1.112 +int ucx_array_contains(UcxArray const *array, void *elem,
   1.113 +    cmp_func cmpfnc, void *data);
   1.114  
   1.115  /**
   1.116   * Sorts a UcxArray with the best available sort algorithm.
   1.117 @@ -411,7 +444,7 @@
   1.118   * @param cmpfnc the function that shall be used to compare the element data
   1.119   * @param data additional data for the cmp_func() or <code>NULL</code>
   1.120   */
   1.121 -void ucx_array_sort(UcxArray array, cmp_func cmpfnc, void *data);
   1.122 +void ucx_array_sort(UcxArray* array, cmp_func cmpfnc, void *data);
   1.123  
   1.124  /**
   1.125   * Removes an element from the array.

mercurial