src/ucx/map.h

changeset 374
be77fb2da242
parent 327
fbc33813265b
     1.1 --- a/src/ucx/map.h	Thu Dec 19 18:47:23 2019 +0100
     1.2 +++ b/src/ucx/map.h	Thu Dec 19 19:58:41 2019 +0100
     1.3 @@ -124,7 +124,7 @@
     1.4  /** Structure for an iterator over a UcxMap. */
     1.5  struct UcxMapIterator {
     1.6      /** The map to iterate over. */
     1.7 -    UcxMap        *map;
     1.8 +    UcxMap const  *map;
     1.9      
    1.10      /** The current map element. */
    1.11      UcxMapElement *cur;
    1.12 @@ -211,7 +211,7 @@
    1.13   * @param data additional data for the copy function
    1.14   * @return 0 on success or a non-zero value on memory allocation errors
    1.15   */
    1.16 -int ucx_map_copy(UcxMap *from, UcxMap *to, copy_func fnc, void *data);
    1.17 +int ucx_map_copy(UcxMap const *from, UcxMap *to, copy_func fnc, void *data);
    1.18  
    1.19  /**
    1.20   * Clones the map and rehashes if necessary.
    1.21 @@ -227,7 +227,25 @@
    1.22   * @return the cloned map
    1.23   * @see ucx_map_copy()
    1.24   */
    1.25 -UcxMap *ucx_map_clone(UcxMap *map, copy_func fnc, void *data);
    1.26 +UcxMap *ucx_map_clone(UcxMap const *map, copy_func fnc, void *data);
    1.27 +
    1.28 +/**
    1.29 + * Clones the map and rehashes if necessary.
    1.30 + *
    1.31 + * <b>Note:</b> In contrast to ucx_map_rehash() the load factor is irrelevant.
    1.32 + * This function <i>always</i> ensures a new UcxMap.size of at least
    1.33 + * 2.5*UcxMap.count.
    1.34 + *
    1.35 + * @param allocator the allocator to use for the cloned map
    1.36 + * @param map the map to clone
    1.37 + * @param fnc the copy function to use or <code>NULL</code> if the new and
    1.38 + * the old map shall share the data pointers
    1.39 + * @param data additional data for the copy function
    1.40 + * @return the cloned map
    1.41 + * @see ucx_map_copy()
    1.42 + */
    1.43 +UcxMap *ucx_map_clone_a(UcxAllocator *allocator,
    1.44 +                        UcxMap const *map, copy_func fnc, void *data);
    1.45  
    1.46  /**
    1.47   * Increases size of the hash map, if necessary.
    1.48 @@ -264,7 +282,7 @@
    1.49   * @param key the key
    1.50   * @return the value
    1.51   */
    1.52 -void* ucx_map_get(UcxMap *map, UcxKey key);
    1.53 +void* ucx_map_get(UcxMap const *map, UcxKey key);
    1.54  
    1.55  /**
    1.56   * Removes a key/value-pair from the map by using the key.
    1.57 @@ -406,7 +424,7 @@
    1.58   * first element list
    1.59   * @see ucx_map_iter_next()
    1.60   */
    1.61 -UcxMapIterator ucx_map_iterator(UcxMap *map);
    1.62 +UcxMapIterator ucx_map_iterator(UcxMap const *map);
    1.63  
    1.64  /**
    1.65   * Proceeds to the next element of the map (if any).
    1.66 @@ -426,6 +444,102 @@
    1.67   */
    1.68  int ucx_map_iter_next(UcxMapIterator *iterator, UcxKey *key, void **value);
    1.69  
    1.70 +/**
    1.71 + * Returns the union of two maps.
    1.72 + *
    1.73 + * The union is a fresh map which is filled by two successive calls of
    1.74 + * ucx_map_copy() on the two input maps.
    1.75 + *
    1.76 + * @param first the first source map
    1.77 + * @param second the second source map
    1.78 + * @param cpfnc a function to copy the elements
    1.79 + * @param cpdata additional data for the copy function
    1.80 + * @return a new map containing the union
    1.81 + */
    1.82 +UcxMap* ucx_map_union(const UcxMap *first, const UcxMap *second,
    1.83 +                      copy_func cpfnc, void* cpdata);
    1.84 +
    1.85 +/**
    1.86 + * Returns the union of two maps.
    1.87 + *
    1.88 + * The union is a fresh map which is filled by two successive calls of
    1.89 + * ucx_map_copy() on the two input maps.
    1.90 + *
    1.91 + * @param allocator the allocator that shall be used by the new map
    1.92 + * @param first the first source map
    1.93 + * @param second the second source map
    1.94 + * @param cpfnc a function to copy the elements
    1.95 + * @param cpdata additional data for the copy function
    1.96 + * @return a new map containing the union
    1.97 + */
    1.98 +UcxMap* ucx_map_union_a(UcxAllocator *allocator,
    1.99 +                        const UcxMap *first, const UcxMap *second,
   1.100 +                        copy_func cpfnc, void* cpdata);
   1.101 +
   1.102 +/**
   1.103 + * Returns the intersection of two maps.
   1.104 + *
   1.105 + * The intersection is defined as a copy of the first map with every element
   1.106 + * removed that has no valid key in the second map.
   1.107 + *
   1.108 + * @param first the first source map
   1.109 + * @param second the second source map
   1.110 + * @param cpfnc a function to copy the elements
   1.111 + * @param cpdata additional data for the copy function
   1.112 + * @return a new map containing the intersection
   1.113 + */
   1.114 +UcxMap* ucx_map_intersection(const UcxMap *first, const UcxMap *second,
   1.115 +                             copy_func cpfnc, void* cpdata);
   1.116 +
   1.117 +/**
   1.118 + * Returns the intersection of two maps.
   1.119 + *
   1.120 + * The intersection is defined as a copy of the first map with every element
   1.121 + * removed that has no valid key in the second map.
   1.122 + *
   1.123 + * @param allocator the allocator that shall be used by the new map
   1.124 + * @param first the first source map
   1.125 + * @param second the second source map
   1.126 + * @param cpfnc a function to copy the elements
   1.127 + * @param cpdata additional data for the copy function
   1.128 + * @return a new map containing the intersection
   1.129 + */
   1.130 +UcxMap* ucx_map_intersection_a(UcxAllocator *allocator,
   1.131 +                               const UcxMap *first, const UcxMap *second,
   1.132 +                               copy_func cpfnc, void* cpdata);
   1.133 +
   1.134 +/**
   1.135 + * Returns the difference of two maps.
   1.136 + *
   1.137 + * The difference contains a copy of all elements of the first map
   1.138 + * for which the corresponding keys cannot be found in the second map.
   1.139 + *
   1.140 + * @param first the first source map
   1.141 + * @param second the second source map
   1.142 + * @param cpfnc a function to copy the elements
   1.143 + * @param cpdata additional data for the copy function
   1.144 + * @return a new list containing the difference
   1.145 + */
   1.146 +UcxMap* ucx_map_difference(const UcxMap *first, const UcxMap *second,
   1.147 +                           copy_func cpfnc, void* cpdata);
   1.148 +
   1.149 +/**
   1.150 + * Returns the difference of two maps.
   1.151 + *
   1.152 + * The difference contains a copy of all elements of the first map
   1.153 + * for which the corresponding keys cannot be found in the second map.
   1.154 + *
   1.155 + * @param allocator the allocator that shall be used by the new map
   1.156 + * @param first the first source map
   1.157 + * @param second the second source map
   1.158 + * @param cpfnc a function to copy the elements
   1.159 + * @param cpdata additional data for the copy function
   1.160 + * @return a new list containing the difference
   1.161 + */
   1.162 +UcxMap* ucx_map_difference_a(UcxAllocator *allocator,
   1.163 +                             const UcxMap *first, const UcxMap *second,
   1.164 +                             copy_func cpfnc, void* cpdata);
   1.165 +
   1.166  
   1.167  #ifdef	__cplusplus
   1.168  }

mercurial