G.3.17 Set operations

The following functions implements operations on sets, not multisets; this means we must make sure that there are no duplicates in the arrays. Also there is no need to sort arrays: while it is more efficient to keep sets sorted, when possible, these functions do not require that.

For the semantics of the parameter ARRY see Conventions of the arrays API. For the semantics of the parameter ARRYS see Conventions of the arrays API. For the semantics of the parameter ISEQUAL see Conventions of the arrays API.

Function: mbfl_array_set_union UNION_ARRY ARRY1 ARRY2
Function: mbfl_array_set_union UNION_ARRY ARRY1 ARRY2 ISEQUAL

Copy values from ARRY1 and ARRY2 to UNION_ARRY; use ISEQUAL to include only unique values.

mbfl_declare_index_array_varref(ARRY1, (a b c d e))
mbfl_declare_index_array_varref(ARRY2,     (c d e f g h i))
mbfl_declare_index_array_varref(UNION)

mbfl_array_set_union _(UNION) _(ARRY1) _(ARRY2)
mbfl_slots_qvalues(UNION)               ⇒ a b c d e f g h i
Function: mbfl_array_set_intersection INTERSECTION_ARRY ARRY1 ARRY2
Function: mbfl_array_set_intersection INTERSECTION_ARRY ARRY1 ARRY2 ISEQUAL

Copy values from ARRY1 and ARRY2 to INTERSECTION_ARRY; use ISEQUAL to include only values present in both ARRY1 and ARRY2.

mbfl_declare_index_array_varref(ARRY1, (a b c d e))
mbfl_declare_index_array_varref(ARRY2,     (c d e f g h i))
mbfl_declare_index_array_varref(INTERSECTION)

mbfl_array_set_intersection _(INTERSECTION) _(ARRY1) _(ARRY2)
mbfl_slots_qvalues(INTERSECTION)        ⇒ c d e
Function: mbfl_array_set_xor XOR_ARRY ARRY1 ARRY2
Function: mbfl_array_set_xor XOR_ARRY ARRY1 ARRY2 ISEQUAL

Copy values from ARRY1 and ARRY2 to XOR_ARRY; use ISEQUAL to include only values exclusively present in either ARRY1 or ARRY2.

mbfl_declare_index_array_varref(ARRY1, (a b c d e))
mbfl_declare_index_array_varref(ARRY2,     (c d e f g h i))
mbfl_declare_index_array_varref(XOR)

mbfl_array_set_xor _(XOR) _(ARRY1) _(ARRY2)
mbfl_slots_qvalues(XOR)                 ⇒ a b f g h i
Function: mbfl_array_set_difference DIFFERENCE_ARRY ARRY1 ARRY2
Function: mbfl_array_set_difference DIFFERENCE_ARRY ARRY1 ARRY2 ISEQUAL

Copy values from ARRY1 to DIFFERENCE_ARRY; use ISEQUAL to include only values exclusively present in ARRY1 and not in ARRY2.

mbfl_declare_index_array_varref(ARRY1, (a b c d e))
mbfl_declare_index_array_varref(ARRY2,     (c d e f g h i))
mbfl_declare_index_array_varref(DIFFERENCE)

mbfl_array_set_difference _(DIFFERENCE) _(ARRY1) _(ARRY2)
mbfl_slots_qvalues(DIFFERENCE)          ⇒ a b

This document describes version 3.0.0-devel.9 of Marcos Bash Functions Library.