ucx/ucx/map.h

changeset 162
18892c0a9adc
parent 157
0b33b9396851
equal deleted inserted replaced
161:b1eac0878ce7 162:18892c0a9adc
122 }; 122 };
123 123
124 /** Structure for an iterator over a UcxMap. */ 124 /** Structure for an iterator over a UcxMap. */
125 struct UcxMapIterator { 125 struct UcxMapIterator {
126 /** The map to iterate over. */ 126 /** The map to iterate over. */
127 UcxMap *map; 127 UcxMap const *map;
128 128
129 /** The current map element. */ 129 /** The current map element. */
130 UcxMapElement *cur; 130 UcxMapElement *cur;
131 131
132 /** 132 /**
209 * @param fnc the copy function or <code>NULL</code> if the pointer address 209 * @param fnc the copy function or <code>NULL</code> if the pointer address
210 * shall be copied 210 * shall be copied
211 * @param data additional data for the copy function 211 * @param data additional data for the copy function
212 * @return 0 on success or a non-zero value on memory allocation errors 212 * @return 0 on success or a non-zero value on memory allocation errors
213 */ 213 */
214 int ucx_map_copy(UcxMap *from, UcxMap *to, copy_func fnc, void *data); 214 int ucx_map_copy(UcxMap const *from, UcxMap *to, copy_func fnc, void *data);
215 215
216 /** 216 /**
217 * Clones the map and rehashes if necessary. 217 * Clones the map and rehashes if necessary.
218 * 218 *
219 * <b>Note:</b> In contrast to ucx_map_rehash() the load factor is irrelevant. 219 * <b>Note:</b> In contrast to ucx_map_rehash() the load factor is irrelevant.
225 * the old map shall share the data pointers 225 * the old map shall share the data pointers
226 * @param data additional data for the copy function 226 * @param data additional data for the copy function
227 * @return the cloned map 227 * @return the cloned map
228 * @see ucx_map_copy() 228 * @see ucx_map_copy()
229 */ 229 */
230 UcxMap *ucx_map_clone(UcxMap *map, copy_func fnc, void *data); 230 UcxMap *ucx_map_clone(UcxMap const *map, copy_func fnc, void *data);
231
232 /**
233 * Clones the map and rehashes if necessary.
234 *
235 * <b>Note:</b> In contrast to ucx_map_rehash() the load factor is irrelevant.
236 * This function <i>always</i> ensures a new UcxMap.size of at least
237 * 2.5*UcxMap.count.
238 *
239 * @param allocator the allocator to use for the cloned map
240 * @param map the map to clone
241 * @param fnc the copy function to use or <code>NULL</code> if the new and
242 * the old map shall share the data pointers
243 * @param data additional data for the copy function
244 * @return the cloned map
245 * @see ucx_map_copy()
246 */
247 UcxMap *ucx_map_clone_a(UcxAllocator *allocator,
248 UcxMap const *map, copy_func fnc, void *data);
231 249
232 /** 250 /**
233 * Increases size of the hash map, if necessary. 251 * Increases size of the hash map, if necessary.
234 * 252 *
235 * The load value is 0.75*UcxMap.size. If the element count exceeds the load 253 * The load value is 0.75*UcxMap.size. If the element count exceeds the load
262 * 280 *
263 * @param map the map 281 * @param map the map
264 * @param key the key 282 * @param key the key
265 * @return the value 283 * @return the value
266 */ 284 */
267 void* ucx_map_get(UcxMap *map, UcxKey key); 285 void* ucx_map_get(UcxMap const *map, UcxKey key);
268 286
269 /** 287 /**
270 * Removes a key/value-pair from the map by using the key. 288 * Removes a key/value-pair from the map by using the key.
271 * 289 *
272 * @param map the map 290 * @param map the map
404 * @param map the map to create the iterator for 422 * @param map the map to create the iterator for
405 * @return an iterator initialized on the first element of the 423 * @return an iterator initialized on the first element of the
406 * first element list 424 * first element list
407 * @see ucx_map_iter_next() 425 * @see ucx_map_iter_next()
408 */ 426 */
409 UcxMapIterator ucx_map_iterator(UcxMap *map); 427 UcxMapIterator ucx_map_iterator(UcxMap const *map);
410 428
411 /** 429 /**
412 * Proceeds to the next element of the map (if any). 430 * Proceeds to the next element of the map (if any).
413 * 431 *
414 * Subsequent calls on the same iterator proceed to the next element and 432 * Subsequent calls on the same iterator proceed to the next element and
424 * @return 1, if another element was found, 0 if all elements has been processed 442 * @return 1, if another element was found, 0 if all elements has been processed
425 * @see ucx_map_iterator() 443 * @see ucx_map_iterator()
426 */ 444 */
427 int ucx_map_iter_next(UcxMapIterator *iterator, UcxKey *key, void **value); 445 int ucx_map_iter_next(UcxMapIterator *iterator, UcxKey *key, void **value);
428 446
447 /**
448 * Returns the union of two maps.
449 *
450 * The union is a fresh map which is filled by two successive calls of
451 * ucx_map_copy() on the two input maps.
452 *
453 * @param first the first source map
454 * @param second the second source map
455 * @param cpfnc a function to copy the elements
456 * @param cpdata additional data for the copy function
457 * @return a new map containing the union
458 */
459 UcxMap* ucx_map_union(const UcxMap *first, const UcxMap *second,
460 copy_func cpfnc, void* cpdata);
461
462 /**
463 * Returns the union of two maps.
464 *
465 * The union is a fresh map which is filled by two successive calls of
466 * ucx_map_copy() on the two input maps.
467 *
468 * @param allocator the allocator that shall be used by the new map
469 * @param first the first source map
470 * @param second the second source map
471 * @param cpfnc a function to copy the elements
472 * @param cpdata additional data for the copy function
473 * @return a new map containing the union
474 */
475 UcxMap* ucx_map_union_a(UcxAllocator *allocator,
476 const UcxMap *first, const UcxMap *second,
477 copy_func cpfnc, void* cpdata);
478
479 /**
480 * Returns the intersection of two maps.
481 *
482 * The intersection is defined as a copy of the first map with every element
483 * removed that has no valid key in the second map.
484 *
485 * @param first the first source map
486 * @param second the second source map
487 * @param cpfnc a function to copy the elements
488 * @param cpdata additional data for the copy function
489 * @return a new map containing the intersection
490 */
491 UcxMap* ucx_map_intersection(const UcxMap *first, const UcxMap *second,
492 copy_func cpfnc, void* cpdata);
493
494 /**
495 * Returns the intersection of two maps.
496 *
497 * The intersection is defined as a copy of the first map with every element
498 * removed that has no valid key in the second map.
499 *
500 * @param allocator the allocator that shall be used by the new map
501 * @param first the first source map
502 * @param second the second source map
503 * @param cpfnc a function to copy the elements
504 * @param cpdata additional data for the copy function
505 * @return a new map containing the intersection
506 */
507 UcxMap* ucx_map_intersection_a(UcxAllocator *allocator,
508 const UcxMap *first, const UcxMap *second,
509 copy_func cpfnc, void* cpdata);
510
511 /**
512 * Returns the difference of two maps.
513 *
514 * The difference contains a copy of all elements of the first map
515 * for which the corresponding keys cannot be found in the second map.
516 *
517 * @param first the first source map
518 * @param second the second source map
519 * @param cpfnc a function to copy the elements
520 * @param cpdata additional data for the copy function
521 * @return a new list containing the difference
522 */
523 UcxMap* ucx_map_difference(const UcxMap *first, const UcxMap *second,
524 copy_func cpfnc, void* cpdata);
525
526 /**
527 * Returns the difference of two maps.
528 *
529 * The difference contains a copy of all elements of the first map
530 * for which the corresponding keys cannot be found in the second map.
531 *
532 * @param allocator the allocator that shall be used by the new map
533 * @param first the first source map
534 * @param second the second source map
535 * @param cpfnc a function to copy the elements
536 * @param cpdata additional data for the copy function
537 * @return a new list containing the difference
538 */
539 UcxMap* ucx_map_difference_a(UcxAllocator *allocator,
540 const UcxMap *first, const UcxMap *second,
541 copy_func cpfnc, void* cpdata);
542
429 543
430 #ifdef __cplusplus 544 #ifdef __cplusplus
431 } 545 }
432 #endif 546 #endif
433 547

mercurial