Sets
Operators and functions for working with an array of boolean values (set type) are described here.

Operator
Result
Description
* set
int
Returns the set size.
^ set
set
Returns a new set as logical NOT of the source set. !s[i] for each item.
set = set
set
Assignment operator.
set &= set
set
Create a clone of the set. The new variable will work with the same data set.
set += set
set
Appends a set to a set variable.
set & set
set
Returns a set that is the intersection of two sets. left[i] && right[i] for each item.
set | set
set
Returns a set that is the union of two sets. left[i] || right[i] for each item.
set [ int ]
bool
Sets/gets a set value.

The arr function converts a set value to an array of integers that contains indexes of set items.

The set function converts a string to a set value and returns it. The string must only have 1 and 0 characters.

The set function converts an array of integers to a set value and returns it. The result set will have items with corresponding indexes.
run arr.int {
set s &= {780, 99, 128, 105, 136}
arr.int as = arr(s)
as += 330
s &= set(as)
return arr(s) // [99 105 128 136 330 780]
}

The str function converts a set value to a string and returns it. The result string contains only 1 and 0.

The Set function adds an index item to the set. It is the same as s[index] = true. The function returns s.

The Toggle function adds an index item to the set if the set doesn't have it and otherwise, the function removes the item. It is the same as s[index] = !s[index]. The function returns the previous state - true if the item existed and, otherwise, false.

The UnSet function removes an index item from the set. It is the same as s[index] = false. The function returns s.
Last modified 3yr ago
Copy link
On this page
Operators
Functions
arr(set s) arr.int
set(str s) set
set(arr.int a) set
str(set s) str
Set(set s, int index) set
Toggle(set s, int index) bool
UnSet(set s, int index) set