src/ucx/list.h

changeset 371
365b24f20f98
parent 323
b8c49e7a1dba
     1.1 --- a/src/ucx/list.h	Thu Nov 07 10:43:31 2019 +0100
     1.2 +++ b/src/ucx/list.h	Sun Nov 24 17:57:25 2019 +0100
     1.3 @@ -57,7 +57,7 @@
     1.4   * @param elem The variable name of the element
     1.5   */
     1.6  #define UCX_FOREACH(elem,list) \
     1.7 -        for (UcxList* elem = list ; elem != NULL ; elem = elem->next)
     1.8 +        for (UcxList* elem = (UcxList*) list ; elem != NULL ; elem = elem->next)
     1.9  
    1.10  /**
    1.11   * UCX list type.
    1.12 @@ -99,7 +99,7 @@
    1.13   * @param data additional data for the copy_func()
    1.14   * @return a pointer to the copy
    1.15   */
    1.16 -UcxList *ucx_list_clone(UcxList *list, copy_func cpyfnc, void* data);
    1.17 +UcxList *ucx_list_clone(const UcxList *list, copy_func cpyfnc, void* data);
    1.18  
    1.19  /**
    1.20   * Creates an element-wise copy of a list using a UcxAllocator.
    1.21 @@ -117,7 +117,7 @@
    1.22   * @return a pointer to the copy
    1.23   * @see ucx_list_clone()
    1.24   */
    1.25 -UcxList *ucx_list_clone_a(UcxAllocator *allocator, UcxList *list,
    1.26 +UcxList *ucx_list_clone_a(UcxAllocator *allocator, const UcxList *list,
    1.27          copy_func cpyfnc, void* data);
    1.28  
    1.29  /**
    1.30 @@ -328,7 +328,8 @@
    1.31   * @return the index of the element containing the specified data or -1 if the
    1.32   * data is not found in this list
    1.33   */
    1.34 -ssize_t ucx_list_find(UcxList *list, void *elem, cmp_func cmpfnc, void *data);
    1.35 +ssize_t ucx_list_find(const UcxList *list, void *elem,
    1.36 +    cmp_func cmpfnc, void *data);
    1.37  
    1.38  /**
    1.39   * Checks, if a list contains a specific element.
    1.40 @@ -342,7 +343,8 @@
    1.41   * @return 1, if and only if the list contains the specified element data
    1.42   * @see ucx_list_find()
    1.43   */
    1.44 -int ucx_list_contains(UcxList *list, void *elem, cmp_func cmpfnc, void *data);
    1.45 +int ucx_list_contains(const UcxList *list, void *elem,
    1.46 +    cmp_func cmpfnc, void *data);
    1.47  
    1.48  /**
    1.49   * Sorts a UcxList with natural merge sort.
    1.50 @@ -388,6 +390,120 @@
    1.51  UcxList *ucx_list_remove_a(UcxAllocator *allocator, UcxList *list,
    1.52          UcxList *element);
    1.53  
    1.54 +/**
    1.55 + * Returns the union of two lists.
    1.56 + * 
    1.57 + * The union is a list of unique elements regarding cmpfnc obtained from
    1.58 + * both source lists.
    1.59 + * 
    1.60 + * @param left the left source list
    1.61 + * @param right the right source list
    1.62 + * @param cmpfnc a function to compare elements
    1.63 + * @param cmpdata additional data for the compare function
    1.64 + * @param cpfnc a function to copy the elements
    1.65 + * @param cpdata additional data for the copy function
    1.66 + * @return a new list containing the union
    1.67 + */
    1.68 +UcxList* ucx_list_union(const UcxList *left, const UcxList *right,
    1.69 +    cmp_func cmpfnc, void* cmpdata,
    1.70 +    copy_func cpfnc, void* cpdata);
    1.71 +
    1.72 +/**
    1.73 + * Returns the union of two lists.
    1.74 + * 
    1.75 + * The union is a list of unique elements regarding cmpfnc obtained from
    1.76 + * both source lists.
    1.77 + * 
    1.78 + * @param allocator allocates the new list elements
    1.79 + * @param left the left source list
    1.80 + * @param right the right source list
    1.81 + * @param cmpfnc a function to compare elements
    1.82 + * @param cmpdata additional data for the compare function
    1.83 + * @param cpfnc a function to copy the elements
    1.84 + * @param cpdata additional data for the copy function
    1.85 + * @return a new list containing the union
    1.86 + */
    1.87 +UcxList* ucx_list_union_a(UcxAllocator *allocator,
    1.88 +    const UcxList *left, const UcxList *right,
    1.89 +    cmp_func cmpfnc, void* cmpdata,
    1.90 +    copy_func cpfnc, void* cpdata);
    1.91 +
    1.92 +/**
    1.93 + * Returns the intersection of two lists.
    1.94 + * 
    1.95 + * The intersection contains all elements of the left list
    1.96 + * (including duplicates) that can be found in the right list.
    1.97 + * 
    1.98 + * @param left the left source list
    1.99 + * @param right the right source list
   1.100 + * @param cmpfnc a function to compare elements
   1.101 + * @param cmpdata additional data for the compare function
   1.102 + * @param cpfnc a function to copy the elements
   1.103 + * @param cpdata additional data for the copy function
   1.104 + * @return a new list containing the intersection
   1.105 + */
   1.106 +UcxList* ucx_list_intersection(const UcxList *left, const UcxList *right,
   1.107 +    cmp_func cmpfnc, void* cmpdata,
   1.108 +    copy_func cpfnc, void* cpdata);
   1.109 +
   1.110 +/**
   1.111 + * Returns the intersection of two lists.
   1.112 + * 
   1.113 + * The intersection contains all elements of the left list
   1.114 + * (including duplicates) that can be found in the right list.
   1.115 + * 
   1.116 + * @param allocator allocates the new list elements
   1.117 + * @param left the left source list
   1.118 + * @param right the right source list
   1.119 + * @param cmpfnc a function to compare elements
   1.120 + * @param cmpdata additional data for the compare function
   1.121 + * @param cpfnc a function to copy the elements
   1.122 + * @param cpdata additional data for the copy function
   1.123 + * @return a new list containing the intersection
   1.124 + */
   1.125 +UcxList* ucx_list_intersection_a(UcxAllocator *allocator,
   1.126 +    const UcxList *left, const UcxList *right,
   1.127 +    cmp_func cmpfnc, void* cmpdata,
   1.128 +    copy_func cpfnc, void* cpdata);
   1.129 +
   1.130 +/**
   1.131 + * Returns the difference of two lists.
   1.132 + * 
   1.133 + * The difference contains all elements of the left list
   1.134 + * (including duplicates) that are not equal to any element of the right list.
   1.135 + * 
   1.136 + * @param left the left source list
   1.137 + * @param right the right source list
   1.138 + * @param cmpfnc a function to compare elements
   1.139 + * @param cmpdata additional data for the compare function
   1.140 + * @param cpfnc a function to copy the elements
   1.141 + * @param cpdata additional data for the copy function
   1.142 + * @return a new list containing the difference
   1.143 + */
   1.144 +UcxList* ucx_list_difference(const UcxList *left, const UcxList *right,
   1.145 +    cmp_func cmpfnc, void* cmpdata,
   1.146 +    copy_func cpfnc, void* cpdata);
   1.147 +
   1.148 +/**
   1.149 + * Returns the difference of two lists.
   1.150 + * 
   1.151 + * The difference contains all elements of the left list
   1.152 + * (including duplicates) that are not equal to any element of the right list.
   1.153 + * 
   1.154 + * @param allocator allocates the new list elements
   1.155 + * @param left the left source list
   1.156 + * @param right the right source list
   1.157 + * @param cmpfnc a function to compare elements
   1.158 + * @param cmpdata additional data for the compare function
   1.159 + * @param cpfnc a function to copy the elements
   1.160 + * @param cpdata additional data for the copy function
   1.161 + * @return a new list containing the difference
   1.162 + */
   1.163 +UcxList* ucx_list_difference_a(UcxAllocator *allocator,
   1.164 +    const UcxList *left, const UcxList *right,
   1.165 +    cmp_func cmpfnc, void* cmpdata,
   1.166 +    copy_func cpfnc, void* cpdata);
   1.167 +
   1.168  #ifdef	__cplusplus
   1.169  }
   1.170  #endif

mercurial