|
|
|
Operations on SetsSome of the operators that are used for bitwise operations (|, & and ^) can also be used for operations on sets, such as union and intersection. They can be applied to multisets, but also to arrays and mappings.
Two calculate the difference between two multisets, arrays or mappings, you use the - operator:
When using mappings in set operations, we only consider the indices. The values are copied along with the indices. If an index is present in both mappings in a union or intersection, the one from the right-side mapping will be used. Some examples:
You can also use the operator + on multisets, arrays and mappings. For multisets and mappings, it calculates the union, i e the same as the | operator. For arrays, it gives a different result: it just concatenates the arrays, instead of calculating the union:
|
|||||||||||||||||||||||||||||||||||||||