Sets
Operators and functions for working with an array of boolean values (set type) are described here.
Operators
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. |
Functions
arr(set s) arr.int
The arr function converts a set value to an array of integers that contains indexes of set items.
set(str s) set
The set function converts a string to a set value and returns it. The string must only have 1 and 0 characters.
set(arr.int a) set
The set function converts an array of integers to a set value and returns it. The result set will have items with corresponding indexes.
str(set s) str
The str function converts a set value to a string and returns it. The result string contains only 1 and 0.
Set(set s, int index) set
The Set function adds an index item to the set. It is the same as s[index] = true. The function returns s.
Toggle(set s, int index) bool
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.
UnSet(set s, int index) set
The UnSet function removes an index item from the set. It is the same as s[index] = false. The function returns s.
Last updated