src/ucx/array.h

branch
feature/array
changeset 342
8f0a3c00d1d2
parent 339
ae368664625f
child 343
c09da4ee177f
equal deleted inserted replaced
341:b9715d7317c1 342:8f0a3c00d1d2
197 * if the index is greater than the array size 197 * if the index is greater than the array size
198 */ 198 */
199 void *ucx_array_at(UcxArray array, size_t index); 199 void *ucx_array_at(UcxArray array, size_t index);
200 200
201 /** 201 /**
202 * Returns an element of the specified type by value.
203 *
204 * This expression can also be assigned to.
205 *
206 * If <code>sizeof(type)</code> does not equal the array's element size, the
207 * behavior is undefined.
208 * If the index is out of bounds, the behavior is undefined.
209 *
210 * @param type the type of the element
211 * @param array the array to retrieve the element from
212 * @param index index of the element to return
213 * @return the requested element
214 * @see ucx_array_at()
215 */
216 #define ucx_array_at_typed(type, array, index) (((type*)((array).data))[index])
217
218 /**
219 * Shorthand for ucx_array_at_typed().
220 */
221 #define ucx_array_at_int(arr, i) ucx_array_at_typed(int, arr, i)
222
223 /**
224 * Shorthand for ucx_array_at_typed().
225 */
226 #define ucx_array_at_short(arr, i) ucx_array_at_typed(short, arr, i)
227
228 /**
229 * Shorthand for ucx_array_at_typed().
230 */
231 #define ucx_array_at_longint(arr, i) ucx_array_at_typed(long int, arr, i)
232
233 /**
234 * Shorthand for ucx_array_at_typed().
235 */
236 #define ucx_array_at_uint(arr, i) ucx_array_at_typed(unsigned int, arr, i)
237
238 /**
239 * Shorthand for ucx_array_at_typed().
240 */
241 #define ucx_array_at_ushort(arr, i) ucx_array_at_typed(unsigned short, arr, i)
242
243 /**
244 * Shorthand for ucx_array_at_typed().
245 */
246 #define ucx_array_at_ulongint(arr, i) \
247 ucx_array_at_typed(unsigned long int, arr, i)
248
249 /**
250 * Shorthand for ucx_array_get_typed().
251 */
252 #define ucx_array_get_float(arr, i) ucx_array_get_typed(float, arr, i)
253
254 /**
255 * Shorthand for ucx_array_get_typed().
256 */
257 #define ucx_array_get_double(arr, i) ucx_array_get_typed(double, arr, i)
258
259 /**
260 * Returns the index of an element containing the specified data. 202 * Returns the index of an element containing the specified data.
261 * 203 *
262 * This function uses a cmp_func() to compare the data of each list element 204 * This function uses a cmp_func() to compare the data of each list element
263 * with the specified data. If no cmp_func is provided, memcmp() is used. 205 * with the specified data. If no cmp_func is provided, memcmp() is used.
264 * 206 *
288 * @see ucx_array_find() 230 * @see ucx_array_find()
289 */ 231 */
290 int ucx_array_contains(UcxArray array, void *elem, cmp_func cmpfnc, void *data); 232 int ucx_array_contains(UcxArray array, void *elem, cmp_func cmpfnc, void *data);
291 233
292 /** 234 /**
293 * Sorts a UcxArray with an almost in-place merge sort. 235 * Sorts a UcxArray with the best available sort algorithm.
294 * 236 *
295 * This function uses additional memory for exactly one element. 237 * If present, qsort_s() will be used. Otherwise, if no additional data is
238 * specified, qsort() is used as a fall back.
239 *
240 * If qsort_s() is not available and <code>data</code> is not <code>NULL</code>,
241 * a custom almost in-place merge sort algorithm is used, which uses additional
242 * memory for exactly one element.
296 * 243 *
297 * @param array the array to sort 244 * @param array the array to sort
298 * @param cmpfnc the function that shall be used to compare the element data 245 * @param cmpfnc the function that shall be used to compare the element data
299 * @param data additional data for the cmp_func() 246 * @param data additional data for the cmp_func()
300 */ 247 */

mercurial