Product SiteDocumentation Site

5.3.19.4. Determining the Identity of an Item

Set operations require the definition of the identity of an element to determine whether a certain element exists in the receiver collection. The element of a collection is conceived as the tuple <index,item>. The index is used as the identification tag associated with the item. Depending on the collection class, the index is an instance of a particular class, for example, the string class for a directory element, an integer for an array, or any arbitrary class for a relation. The Array class is an exception because it can be multidimensional having more than one index. However, as a collection, it is conceptionally linearized by the set operator.
For collection classes that require unique indexes, namely the Set, IdentityTable, Table, Directory, and Stem, an item is identified by its index. For collections of collection classes that allow several items to have the same index, namely the Relation class, an item is identified by both its index and its item. For the Bag and the Set subclasses, where several items can have the same index but index and item must be identical, the item is identified by its index. For Array, List, and Queue classes, the index is derived from an object's position within the collection's order. Items are identified using only item.
When collections with different index semantics are used in set operations, the argument collection is coerced into a collection of the same type as the receiver, and the operation is then performed using the converted collection. The coercion process differs based on the types of both the receiver and the argument collection. According to this concept, an item of a collection is identified for the different receiver categories as follows:
Map Collection
If argument is a MapCollection, then index values are used to determine membership, and items are inserted into the result using the index and item pairs.
If argument is an OrderedCollection or SetCollection, argument is converted into a MapCollection using the collection items as both index and item values. Since the argument collection may contain duplicate items, the converted collection is effectively a Relation instance.
For all other argument objects, the makearray method is used to obtain a set of values which are used as if argument was an OrderedCollection.
Ordered Collection and Set Collection
If argument is an instance of Collection, the matching set is obtained from the allItems method. For any other class of object, the makearray method is used. The hasItem method is used to perform the matching operations between the two collections.
Relation
If argument is a MapCollection, then index values are used to determine membership, and items are inserted into the result using the index and item pairs.
If argument is an OrderedCollection or SetCollection, argument is converted into a MapCollection using the collection items as both index and item values. Since the argument collection may contain duplicate items, the converted collection is effectively a Relation instance.
For all other argument objects, the makearray method is used to obtain a set of values which are used as if argument was an OrderedCollection. All tests for result membership are made using both the index and item values.