ASIL provides the same level of support for sets that it provides arrays. You can even make set constants. ASIL sets come in two forms: normal and fixed. A fixed set is actually a type. Normal sets can be based on nothing or a fixed set. If you base a normal set on a fixed set, ASIL knows what can not be inside the set. Fixed sets are immutable. Both types of sets can be any type of variable, even conditional variables.
You declare these with the {} operator. If you postfix the braces with "f
", ASIL will actually create a fixed set. Like the [] operator, the braces go after the rest of the Type descriptor, but before the identifier, so you get the {}f operator. To declare a normal set based on a fixed set, place the identifier for the fixed set inside the braces. The fixed set must already have been declared and initialized.
var int{} aSet var int{}f FixedSet
The syntax here is similar, but the data to place into the set goes after the braces as a comma delimited list. The contents aren't required for normal sets, but are for fixed sets. Again, if the set will be based on a fixed set, place the identifier of the fixed set inside the braces.
new int{} 5, 3, 7, 99 new int{}f 5, 3, 7, 99
var int{}f MyFixedSet = new int{}f 5, 3, 7, 99 var int{MyFixedSet} MyFixedSetInstance = new int{} 5, 3
So MyFixedSetInstance
can only contain the members listed when MyFixedSet was initialized. If you tried to put 19
into the set, an exception would be thrown.
ASIL makes several types of operators available for use with sets. These operators are declared as members of the Set class.
Operator | Meaning | Sample |
---|---|---|
and | Returns a new set that contains only those elements that are in both operands. Operands must both be sets based on the same fixed set or no fixed set at all and have the same base type (like int ). |
a and b |
or | Returns a new set that contains all elements that are in either operand. Operands must both be sets based on the same fixed set or no fixed set at all and have the same base type (like int ). |
a or b |
not | Returns a new set which contains all the elements that weren't part of the operand and no more elements. The operand must be a set based on a fixed set. | not a |
< | Returns true if all the members in the left operand are in the right operand and false otherwise. The operands must either have the same base type (like int ) and be based on the same fixed set or no fixed set at all. The left operand can be either a set or an instance of the base type for the right operand. |
a < b |
<= | Returns true if the sets are identical or < would return true. | a <= b |
> | Identical to <, but with the operands reversed. | a > b |
>= | Identical to >, but with the operands reversed. | a >= b |
If you declare a set based on a reference type like "String{}
", the set is a set of references, not instances.
Fixed sets derive from "FixedSet<T>
" where T
is the base type. Normal sets derive from either "Set<T>
" (when not based on a fixed set) or "FixedSet<T>.Instance<FixedSetInstance>
" where FixedSetInstance
is the type you declared when you created the fixed set. Remember, fixed sets are types.
Wiki: Home
Wiki: keywords-conditional
Wiki: operators-and
Wiki: operators-braces
Wiki: operators-bracesf
Wiki: operators-brackets
Wiki: operators-gt
Wiki: operators-lt
Wiki: operators-not
Wiki: operators-or