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