Titan



set


The keyword denotes a structured type representing an unordered sequence of elements, i.e., the ordering of the set fields is not significant. Each element consists of a type and an identifier.

Related keywords:


type set  (identifier  | address) {  type_reference  element_identifier [ optional ] ... };


type set  [ length (set_size) of  type_reference  identifier };


Example 1: type definition

type set MySetType { 
   integer Number1 optional,
   integer Number2,
   charstring String
}

The set called MySetType consists of three elements. There are two fields of type integer having the identifier Number1 (optional) and Number2 . There is one field of type character string and having the identifier String.


Example 2: dot notation (For the type definition see example 1)

var MySetType v_mySet; 
v_mySet.Number1 := omit;
v_mySet.Number2 := 12;

The variable v_mySet of type MySetType is defined. The first field (Number1) is omitted and the value 12 is assigned to the field Number2.


Example 3: assignment notation (For the type and variable definition see example 1 & 2)

v_mySet := {Number2 := 112};

The value 112 is assigned to the field Number2. 


Example 4: the predefined function sizeof()

v_mySet := {Number1 := omit, Number2 := 191, String := "s"};
var integer v_Stk := sizeof (v_mySet);

The variable v_Stk equals two as there are two elements in v_mySet (the first one is omitted).


Example 5: the predefined function ispresent()

v_mySet := {Number1 := omit, Number2 := 191, String := "s"};
var boolean v_kukuccs := ispresent (v_mySet.Number1);

The variable v_kukuccs equals false as there the referenced element in v_mySet (Number1) is omitted.


Example 6: set of the same element type 

type set length (3) of integer IntegerList;
var IntegerList v_il := {71, 92, 83};
var integer v_elem := v_il[1];

A set of three integers is defined. The set is called IntegerList. 
To assign values to the elements of the set, value list notation is used. The elements of the set will have the value 71, 92 and 83, respectively. 
Individual elements of the set may be accessed using the array notation. In the example above the variable v_elem will have the value 92.



BNF definition of set
BNF definition of set of