src/cx/map.h

changeset 1479
ac1baaed2fd7
parent 1474
84de0ba791af
equal deleted inserted replaced
1478:bba2e5efdca0 1479:ac1baaed2fd7
601 */ 601 */
602 cx_attr_nonnull_arg(1, 2, 3) 602 cx_attr_nonnull_arg(1, 2, 3)
603 CX_EXPORT int cxMapUnion(CxMap *dst, const CxMap *src, 603 CX_EXPORT int cxMapUnion(CxMap *dst, const CxMap *src,
604 cx_clone_func clone_func, const CxAllocator *clone_allocator, void *data); 604 cx_clone_func clone_func, const CxAllocator *clone_allocator, void *data);
605 605
606 /**
607 * Performs a shallow clone of one map into another.
608 *
609 * This function uses the default allocator, if needed, and performs
610 * shallow clones with @c memcpy().
611 *
612 * If the destination map already contains entries, the cloned entries
613 * are added to that map, possibly overwriting existing elements when
614 * the keys already exist.
615 *
616 * When elements in the destination map need to be replaced, any destructor
617 * function is called on the replaced elements before replacing them.
618 *
619 * @attention If the cloned elements need to be destroyed by a destructor
620 * function, you must make sure that the destination map also uses this
621 * destructor function.
622 *
623 * @param dst the destination map
624 * @param src the source map
625 * @retval zero when all elements were successfully cloned
626 * @retval non-zero when an allocation error occurred
627 * @see cxMapClone()
628 */
629 cx_attr_nonnull
630 CX_EXPORT int cxMapCloneSimple(CxMap *dst, const CxMap *src);
631
632 /**
633 * Clones entries of a map if their key is not present in another map.
634 *
635 * This function uses the default allocator, if needed, and performs
636 * shallow clones with @c memcpy().
637 *
638 * @param dst the destination map
639 * @param minuend the map to subtract the entries from
640 * @param subtrahend the map containing the elements to be subtracted
641 * @retval zero when the elements were successfully cloned
642 * @retval non-zero when an allocation error occurred
643 */
644 cx_attr_nonnull
645 CX_EXPORT int cxMapDifferenceSimple(CxMap *dst, const CxMap *minuend, const CxMap *subtrahend);
646
647 /**
648 * Clones entries of a map if their key is not present in a list.
649 *
650 * This function uses the default allocator, if needed, and performs
651 * shallow clones with @c memcpy().
652 *
653 * Note that the list must contain keys of type @c CxKey
654 * (or pointers to such keys) and must use @c cx_hash_key_cmp
655 * as the compare function.
656 * Generic key types cannot be processed in this case.
657 *
658 * @param dst the destination map
659 * @param src the source map
660 * @param keys the list of @c CxKey items
661 * @retval zero when the elements were successfully cloned
662 * @retval non-zero when an allocation error occurred
663 * @see cxMapListDifference()
664 */
665 cx_attr_nonnull
666 CX_EXPORT int cxMapListDifferenceSimple(CxMap *dst, const CxMap *src, const CxList *keys);
667
668
669 /**
670 * Clones entries of a map only if their key is present in another map.
671 *
672 * This function uses the default allocator, if needed, and performs
673 * shallow clones with @c memcpy().
674 *
675 * @param dst the destination map
676 * @param src the map to clone the entries from
677 * @param other the map to check for existence of the keys
678 * @retval zero when the elements were successfully cloned
679 * @retval non-zero when an allocation error occurred
680 */
681 cx_attr_nonnull
682 CX_EXPORT int cxMapIntersectionSimple(CxMap *dst, const CxMap *src, const CxMap *other);
683
684 /**
685 * Clones entries of a map only if their key is present in a list.
686 *
687 * This function uses the default allocator, if needed, and performs
688 * shallow clones with @c memcpy().
689 *
690 * Note that the list must contain keys of type @c CxKey
691 * (or pointers to such keys) and must use @c cx_hash_key_cmp
692 * as the compare function.
693 * Generic key types cannot be processed in this case.
694 *
695 * @param dst the destination map
696 * @param src the source map
697 * @param keys the list of @c CxKey items
698 * @retval zero when the elements were successfully cloned
699 * @retval non-zero when an allocation error occurred
700 */
701 cx_attr_nonnull
702 CX_EXPORT int cxMapListIntersectionSimple(CxMap *dst, const CxMap *src, const CxList *keys);
703
704 /**
705 * Clones entries into a map if their key does not exist yet.
706 *
707 * This function uses the default allocator, if needed, and performs
708 * shallow clones with @c memcpy().
709 *
710 * If you want to calculate the union of two maps into a fresh new map,
711 * you can proceed as follows:
712 * 1. Clone the first map into a fresh, empty map.
713 * 2. Use this function to clone the second map into the result from step 1.
714 *
715 * @param dst the destination map
716 * @param src the map to clone the entries from
717 * @retval zero when the elements were successfully cloned
718 * @retval non-zero when an allocation error occurred
719 */
720 cx_attr_nonnull
721 CX_EXPORT int cxMapUnionSimple(CxMap *dst, const CxMap *src);
722
606 #ifdef __cplusplus 723 #ifdef __cplusplus
607 } // extern "C" 724 } // extern "C"
608 #endif 725 #endif
609 726
610 #endif // UCX_MAP_H 727 #endif // UCX_MAP_H

mercurial