5.3.19. The Concept of Set Operations
The following sections describe the concept of set operations to help you work with set operators, in particular if the receiver collection class differs from the argument collection class.
Rexx provides the following set-operator methods:
difference
intersection
subset
union
xor
These methods are available to instances of the following collection classes:
The OrderedCollections Array, List, Queue, and CircularQueue
The MapCollections Directory, Stem, Table, IdentityTable, and Relation
The SetCollections Set and Bag.
result = receiver~setoperator(argument)
where:
- receiver
is the collection object receiving the set-operator message.
- setoperator
is the set-operator method used.
- argument
is the argument collection supplier supplied to the method. It can be an instance of one of the Rexx collection classes or any object that implements a makearray method or supplier method, depending on class of receiver.
The result object is of the same class as the receiver collection object.
5.3.19.1. The Principles of Operation
A set operation is performed by iterating over the elements of the
receiver collection to compare each element of the
receiver with each element of the
argument collection. The element is defined as the tuple <
index,item> (see
Section 5.3.19.4, “Determining the Identity of an Item”). Depending on the set-operator method and the result of the comparison, an element of the receiver collection is, or is not, included in the resulting collection. A receiver collection that allows for duplicate elements can, depending on the set-operator method, also accept elements of the argument collection after they have been coerced to the type of the receiver collection.
The following examples are to help you understand the semantics of set operations. The collections are represented as a list of elements enclosed in curly brackets. The list elements are separated by a comma.