ucx/ucx/list.h

changeset 162
18892c0a9adc
parent 157
0b33b9396851
equal deleted inserted replaced
161:b1eac0878ce7 162:18892c0a9adc
55 * 55 *
56 * @param list The first element of the list 56 * @param list The first element of the list
57 * @param elem The variable name of the element 57 * @param elem The variable name of the element
58 */ 58 */
59 #define UCX_FOREACH(elem,list) \ 59 #define UCX_FOREACH(elem,list) \
60 for (UcxList* elem = list ; elem != NULL ; elem = elem->next) 60 for (UcxList* elem = (UcxList*) list ; elem != NULL ; elem = elem->next)
61 61
62 /** 62 /**
63 * UCX list type. 63 * UCX list type.
64 * @see UcxList 64 * @see UcxList
65 */ 65 */
97 * @param cpyfnc a pointer to the function that shall copy an element (may be 97 * @param cpyfnc a pointer to the function that shall copy an element (may be
98 * <code>NULL</code>) 98 * <code>NULL</code>)
99 * @param data additional data for the copy_func() 99 * @param data additional data for the copy_func()
100 * @return a pointer to the copy 100 * @return a pointer to the copy
101 */ 101 */
102 UcxList *ucx_list_clone(UcxList *list, copy_func cpyfnc, void* data); 102 UcxList *ucx_list_clone(const UcxList *list, copy_func cpyfnc, void* data);
103 103
104 /** 104 /**
105 * Creates an element-wise copy of a list using a UcxAllocator. 105 * Creates an element-wise copy of a list using a UcxAllocator.
106 * 106 *
107 * See ucx_list_clone() for details. 107 * See ucx_list_clone() for details.
115 * <code>NULL</code>) 115 * <code>NULL</code>)
116 * @param data additional data for the copy_func() 116 * @param data additional data for the copy_func()
117 * @return a pointer to the copy 117 * @return a pointer to the copy
118 * @see ucx_list_clone() 118 * @see ucx_list_clone()
119 */ 119 */
120 UcxList *ucx_list_clone_a(UcxAllocator *allocator, UcxList *list, 120 UcxList *ucx_list_clone_a(UcxAllocator *allocator, const UcxList *list,
121 copy_func cpyfnc, void* data); 121 copy_func cpyfnc, void* data);
122 122
123 /** 123 /**
124 * Compares two UCX lists element-wise by using a compare function. 124 * Compares two UCX lists element-wise by using a compare function.
125 * 125 *
326 * @param cmpfnc the compare function 326 * @param cmpfnc the compare function
327 * @param data additional data for the compare function 327 * @param data additional data for the compare function
328 * @return the index of the element containing the specified data or -1 if the 328 * @return the index of the element containing the specified data or -1 if the
329 * data is not found in this list 329 * data is not found in this list
330 */ 330 */
331 ssize_t ucx_list_find(UcxList *list, void *elem, cmp_func cmpfnc, void *data); 331 ssize_t ucx_list_find(const UcxList *list, void *elem,
332 cmp_func cmpfnc, void *data);
332 333
333 /** 334 /**
334 * Checks, if a list contains a specific element. 335 * Checks, if a list contains a specific element.
335 * 336 *
336 * An element is found, if ucx_list_find() returns a value greater than -1. 337 * An element is found, if ucx_list_find() returns a value greater than -1.
340 * @param cmpfnc the compare function 341 * @param cmpfnc the compare function
341 * @param data additional data for the compare function 342 * @param data additional data for the compare function
342 * @return 1, if and only if the list contains the specified element data 343 * @return 1, if and only if the list contains the specified element data
343 * @see ucx_list_find() 344 * @see ucx_list_find()
344 */ 345 */
345 int ucx_list_contains(UcxList *list, void *elem, cmp_func cmpfnc, void *data); 346 int ucx_list_contains(const UcxList *list, void *elem,
347 cmp_func cmpfnc, void *data);
346 348
347 /** 349 /**
348 * Sorts a UcxList with natural merge sort. 350 * Sorts a UcxList with natural merge sort.
349 * 351 *
350 * This function uses O(n) additional temporary memory for merge operations 352 * This function uses O(n) additional temporary memory for merge operations
386 * @see ucx_list_remove() 388 * @see ucx_list_remove()
387 */ 389 */
388 UcxList *ucx_list_remove_a(UcxAllocator *allocator, UcxList *list, 390 UcxList *ucx_list_remove_a(UcxAllocator *allocator, UcxList *list,
389 UcxList *element); 391 UcxList *element);
390 392
393 /**
394 * Returns the union of two lists.
395 *
396 * The union is a list of unique elements regarding cmpfnc obtained from
397 * both source lists.
398 *
399 * @param left the left source list
400 * @param right the right source list
401 * @param cmpfnc a function to compare elements
402 * @param cmpdata additional data for the compare function
403 * @param cpfnc a function to copy the elements
404 * @param cpdata additional data for the copy function
405 * @return a new list containing the union
406 */
407 UcxList* ucx_list_union(const UcxList *left, const UcxList *right,
408 cmp_func cmpfnc, void* cmpdata,
409 copy_func cpfnc, void* cpdata);
410
411 /**
412 * Returns the union of two lists.
413 *
414 * The union is a list of unique elements regarding cmpfnc obtained from
415 * both source lists.
416 *
417 * @param allocator allocates the new list elements
418 * @param left the left source list
419 * @param right the right source list
420 * @param cmpfnc a function to compare elements
421 * @param cmpdata additional data for the compare function
422 * @param cpfnc a function to copy the elements
423 * @param cpdata additional data for the copy function
424 * @return a new list containing the union
425 */
426 UcxList* ucx_list_union_a(UcxAllocator *allocator,
427 const UcxList *left, const UcxList *right,
428 cmp_func cmpfnc, void* cmpdata,
429 copy_func cpfnc, void* cpdata);
430
431 /**
432 * Returns the intersection of two lists.
433 *
434 * The intersection contains all elements of the left list
435 * (including duplicates) that can be found in the right list.
436 *
437 * @param left the left source list
438 * @param right the right source list
439 * @param cmpfnc a function to compare elements
440 * @param cmpdata additional data for the compare function
441 * @param cpfnc a function to copy the elements
442 * @param cpdata additional data for the copy function
443 * @return a new list containing the intersection
444 */
445 UcxList* ucx_list_intersection(const UcxList *left, const UcxList *right,
446 cmp_func cmpfnc, void* cmpdata,
447 copy_func cpfnc, void* cpdata);
448
449 /**
450 * Returns the intersection of two lists.
451 *
452 * The intersection contains all elements of the left list
453 * (including duplicates) that can be found in the right list.
454 *
455 * @param allocator allocates the new list elements
456 * @param left the left source list
457 * @param right the right source list
458 * @param cmpfnc a function to compare elements
459 * @param cmpdata additional data for the compare function
460 * @param cpfnc a function to copy the elements
461 * @param cpdata additional data for the copy function
462 * @return a new list containing the intersection
463 */
464 UcxList* ucx_list_intersection_a(UcxAllocator *allocator,
465 const UcxList *left, const UcxList *right,
466 cmp_func cmpfnc, void* cmpdata,
467 copy_func cpfnc, void* cpdata);
468
469 /**
470 * Returns the difference of two lists.
471 *
472 * The difference contains all elements of the left list
473 * (including duplicates) that are not equal to any element of the right list.
474 *
475 * @param left the left source list
476 * @param right the right source list
477 * @param cmpfnc a function to compare elements
478 * @param cmpdata additional data for the compare function
479 * @param cpfnc a function to copy the elements
480 * @param cpdata additional data for the copy function
481 * @return a new list containing the difference
482 */
483 UcxList* ucx_list_difference(const UcxList *left, const UcxList *right,
484 cmp_func cmpfnc, void* cmpdata,
485 copy_func cpfnc, void* cpdata);
486
487 /**
488 * Returns the difference of two lists.
489 *
490 * The difference contains all elements of the left list
491 * (including duplicates) that are not equal to any element of the right list.
492 *
493 * @param allocator allocates the new list elements
494 * @param left the left source list
495 * @param right the right source list
496 * @param cmpfnc a function to compare elements
497 * @param cmpdata additional data for the compare function
498 * @param cpfnc a function to copy the elements
499 * @param cpdata additional data for the copy function
500 * @return a new list containing the difference
501 */
502 UcxList* ucx_list_difference_a(UcxAllocator *allocator,
503 const UcxList *left, const UcxList *right,
504 cmp_func cmpfnc, void* cmpdata,
505 copy_func cpfnc, void* cpdata);
506
391 #ifdef __cplusplus 507 #ifdef __cplusplus
392 } 508 }
393 #endif 509 #endif
394 510
395 #endif /* UCX_LIST_H */ 511 #endif /* UCX_LIST_H */

mercurial