src/cx/map.h

changeset 1445
e8089a590b71
parent 1444
dd9dcbb39c2f
equal deleted inserted replaced
1444:dd9dcbb39c2f 1445:e8089a590b71
39 #include "common.h" 39 #include "common.h"
40 #include "collection.h" 40 #include "collection.h"
41 #include "string.h" 41 #include "string.h"
42 #include "hash_key.h" 42 #include "hash_key.h"
43 43
44 #ifndef UCX_LIST_H
45 // forward-declare CxList
46 typedef struct cx_list_s CxList;
47 #endif
48
44 #ifdef __cplusplus 49 #ifdef __cplusplus
45 extern "C" { 50 extern "C" {
46 #endif 51 #endif
47 52
48 /** Type for the UCX map. */ 53 /** Type for the UCX map. */
402 * Otherwise, a pointer to the element within the map's memory 407 * Otherwise, a pointer to the element within the map's memory
403 * is returned (which is valid as long as the element stays in the map). 408 * is returned (which is valid as long as the element stays in the map).
404 * 409 *
405 * @param map (@c CxMap*) the map 410 * @param map (@c CxMap*) the map
406 * @param key (any supported key type) the key 411 * @param key (any supported key type) the key
407 * @return (@c void*) the value 412 * @return (@c void*) the value or @c NULL when no value with that @p key exists
408 * @see CX_HASH_KEY() 413 * @see CX_HASH_KEY()
409 */ 414 */
410 #define cxMapGet(map, key) cx_map_get(map, CX_HASH_KEY(key)) 415 #define cxMapGet(map, key) cx_map_get(map, CX_HASH_KEY(key))
416
417 /**
418 * Checks if a map contains a specific key.
419 *
420 * @param map (@c CxMap*) the map
421 * @param key (any supported key type) the key
422 * @retval true if the key exists in the map
423 * @retval false if the key does not exist in the map
424 * @see CX_HASH_KEY()
425 */
426 #define cxMapContains(map, key) (cxMapGet(map, key) != NULL)
411 427
412 /** 428 /**
413 * Removes a key/value-pair from the map by using the key. 429 * Removes a key/value-pair from the map by using the key.
414 * 430 *
415 * Invokes the destructor functions, if any, on the removed element if and only if the 431 * Invokes the destructor functions, if any, on the removed element if and only if the
489 */ 505 */
490 cx_attr_nonnull_arg(1, 2, 3) 506 cx_attr_nonnull_arg(1, 2, 3)
491 CX_EXPORT int cxMapClone(CxMap *dst, const CxMap *src, 507 CX_EXPORT int cxMapClone(CxMap *dst, const CxMap *src,
492 cx_clone_func clone_func, const CxAllocator *clone_allocator, void *data); 508 cx_clone_func clone_func, const CxAllocator *clone_allocator, void *data);
493 509
510
511 cx_attr_nonnull_arg(1, 2, 3, 4)
512 CX_EXPORT int cxMapDifference(CxMap *dst, const CxMap *minuend, const CxMap *subtrahend,
513 cx_clone_func clone_func, const CxAllocator *clone_allocator, void *data);
514
515 cx_attr_nonnull_arg(1, 2, 3, 4)
516 CX_EXPORT int cxMapListDifference(CxMap *dst, const CxMap *src, const CxList *keys,
517 cx_clone_func clone_func, const CxAllocator *clone_allocator, void *data);
518
494 #ifdef __cplusplus 519 #ifdef __cplusplus
495 } // extern "C" 520 } // extern "C"
496 #endif 521 #endif
497 522
498 #endif // UCX_MAP_H 523 #endif // UCX_MAP_H

mercurial