diff -r 0b8692959d37 -r 4779a6fb4fbe src/ucx/ucx/map.h
--- a/src/ucx/ucx/map.h Tue Aug 25 12:07:56 2020 +0200
+++ b/src/ucx/ucx/map.h Sat Oct 24 17:34:32 2020 +0200
@@ -124,7 +124,7 @@
/** Structure for an iterator over a UcxMap. */
struct UcxMapIterator {
/** The map to iterate over. */
- UcxMap *map;
+ UcxMap const *map;
/** The current map element. */
UcxMapElement *cur;
@@ -211,7 +211,7 @@
* @param data additional data for the copy function
* @return 0 on success or a non-zero value on memory allocation errors
*/
-int ucx_map_copy(UcxMap *from, UcxMap *to, copy_func fnc, void *data);
+int ucx_map_copy(UcxMap const *from, UcxMap *to, copy_func fnc, void *data);
/**
* Clones the map and rehashes if necessary.
@@ -227,7 +227,25 @@
* @return the cloned map
* @see ucx_map_copy()
*/
-UcxMap *ucx_map_clone(UcxMap *map, copy_func fnc, void *data);
+UcxMap *ucx_map_clone(UcxMap const *map, copy_func fnc, void *data);
+
+/**
+ * Clones the map and rehashes if necessary.
+ *
+ * Note: In contrast to ucx_map_rehash() the load factor is irrelevant.
+ * This function always ensures a new UcxMap.size of at least
+ * 2.5*UcxMap.count.
+ *
+ * @param allocator the allocator to use for the cloned map
+ * @param map the map to clone
+ * @param fnc the copy function to use or NULL
if the new and
+ * the old map shall share the data pointers
+ * @param data additional data for the copy function
+ * @return the cloned map
+ * @see ucx_map_copy()
+ */
+UcxMap *ucx_map_clone_a(UcxAllocator *allocator,
+ UcxMap const *map, copy_func fnc, void *data);
/**
* Increases size of the hash map, if necessary.
@@ -264,7 +282,7 @@
* @param key the key
* @return the value
*/
-void* ucx_map_get(UcxMap *map, UcxKey key);
+void* ucx_map_get(UcxMap const *map, UcxKey key);
/**
* Removes a key/value-pair from the map by using the key.
@@ -276,51 +294,6 @@
void* ucx_map_remove(UcxMap *map, UcxKey key);
/**
- * Creates a new map containing all elements from the maps a and b.
- *
- * If a key exists in both maps, the value is taken from map a.
- *
- * @param a map a
- * @param b map b
- * @param fnc the copy function to use or NULL
if the new and
- * the old map shall share the data pointers
- * @param data additional data for the copy function
- * @return the new union map
- * @see ucx_map_copy()
- */
-UcxMap *ucx_map_union(UcxMap *a, UcxMap *b, copy_func fnc, void *data);
-
-/**
- * intersection
- *
- * If a key exists in both maps, the value is taken from map a.
- *
- * @param a map a
- * @param b map b
- * @param fnc the copy function to use or NULL
if the new and
- * the old map shall share the data pointers
- * @param data additional data for the copy function
- * @return the new intersection map
- * @see ucx_map_copy()
- */
-UcxMap *ucx_map_intersection(UcxMap *a, UcxMap *b, copy_func fnc, void *data);
-
-/**
- * relative complement
- *
- * If a key exists in both maps, the value is taken from map a.
- *
- * @param a map a
- * @param b map b
- * @param fnc the copy function to use or NULL
if the new and
- * the old map shall share the data pointers
- * @param data additional data for the copy function
- * @return the new intersection map
- * @see ucx_map_copy()
- */
-UcxMap *ucx_map_relcomplement(UcxMap *a, UcxMap *b, copy_func fnc, void *data);
-
-/**
* Shorthand for putting data with a sstr_t key into the map.
* @param map the map
* @param key the key
@@ -451,7 +424,7 @@
* first element list
* @see ucx_map_iter_next()
*/
-UcxMapIterator ucx_map_iterator(UcxMap *map);
+UcxMapIterator ucx_map_iterator(UcxMap const *map);
/**
* Proceeds to the next element of the map (if any).
@@ -471,6 +444,102 @@
*/
int ucx_map_iter_next(UcxMapIterator *iterator, UcxKey *key, void **value);
+/**
+ * Returns the union of two maps.
+ *
+ * The union is a fresh map which is filled by two successive calls of
+ * ucx_map_copy() on the two input maps.
+ *
+ * @param first the first source map
+ * @param second the second source map
+ * @param cpfnc a function to copy the elements
+ * @param cpdata additional data for the copy function
+ * @return a new map containing the union
+ */
+UcxMap* ucx_map_union(const UcxMap *first, const UcxMap *second,
+ copy_func cpfnc, void* cpdata);
+
+/**
+ * Returns the union of two maps.
+ *
+ * The union is a fresh map which is filled by two successive calls of
+ * ucx_map_copy() on the two input maps.
+ *
+ * @param allocator the allocator that shall be used by the new map
+ * @param first the first source map
+ * @param second the second source map
+ * @param cpfnc a function to copy the elements
+ * @param cpdata additional data for the copy function
+ * @return a new map containing the union
+ */
+UcxMap* ucx_map_union_a(UcxAllocator *allocator,
+ const UcxMap *first, const UcxMap *second,
+ copy_func cpfnc, void* cpdata);
+
+/**
+ * Returns the intersection of two maps.
+ *
+ * The intersection is defined as a copy of the first map with every element
+ * removed that has no valid key in the second map.
+ *
+ * @param first the first source map
+ * @param second the second source map
+ * @param cpfnc a function to copy the elements
+ * @param cpdata additional data for the copy function
+ * @return a new map containing the intersection
+ */
+UcxMap* ucx_map_intersection(const UcxMap *first, const UcxMap *second,
+ copy_func cpfnc, void* cpdata);
+
+/**
+ * Returns the intersection of two maps.
+ *
+ * The intersection is defined as a copy of the first map with every element
+ * removed that has no valid key in the second map.
+ *
+ * @param allocator the allocator that shall be used by the new map
+ * @param first the first source map
+ * @param second the second source map
+ * @param cpfnc a function to copy the elements
+ * @param cpdata additional data for the copy function
+ * @return a new map containing the intersection
+ */
+UcxMap* ucx_map_intersection_a(UcxAllocator *allocator,
+ const UcxMap *first, const UcxMap *second,
+ copy_func cpfnc, void* cpdata);
+
+/**
+ * Returns the difference of two maps.
+ *
+ * The difference contains a copy of all elements of the first map
+ * for which the corresponding keys cannot be found in the second map.
+ *
+ * @param first the first source map
+ * @param second the second source map
+ * @param cpfnc a function to copy the elements
+ * @param cpdata additional data for the copy function
+ * @return a new list containing the difference
+ */
+UcxMap* ucx_map_difference(const UcxMap *first, const UcxMap *second,
+ copy_func cpfnc, void* cpdata);
+
+/**
+ * Returns the difference of two maps.
+ *
+ * The difference contains a copy of all elements of the first map
+ * for which the corresponding keys cannot be found in the second map.
+ *
+ * @param allocator the allocator that shall be used by the new map
+ * @param first the first source map
+ * @param second the second source map
+ * @param cpfnc a function to copy the elements
+ * @param cpdata additional data for the copy function
+ * @return a new list containing the difference
+ */
+UcxMap* ucx_map_difference_a(UcxAllocator *allocator,
+ const UcxMap *first, const UcxMap *second,
+ copy_func cpfnc, void* cpdata);
+
#ifdef __cplusplus
}