## containers.set -- mutable set type A mutable tree and hash set implementation based on the `map` type ### Index namespace [std](#std) class [Set](#set) - [Set<@T>](#set_ctor)(_kind_: enum<tree,hash> = $tree) - [.size](#size)(invar _self_: Set<@T>) => int - [insert](#insert)(_self_: Set<@T>, invar value: @T) - [contains](#contains)(invar _self_: Set<@T>, invar _value_: @T) => bool - [[]](#contains)(invar _self_: Set<@T>, invar _value_: @T) => bool - [contains](#contains2)(invar _self_: Set<@T>, invar other: Set<@T>|list<@T>) => bool - [erase](#erase)(_self_: Set<@T>, invar _value_: @T) - [clone](#clone)(invar _self_: Set<@T>) => Set<@T> - [clear](#clear)(_self_: Set<@T>) - [+=](#op_add_set)(_self_: Set<@T>, invar _other_: Set<@T>|list<@T>) => Set<int> - [|=](#op_add_set)(_self_: Set<@T>, invar _other_: Set<@T>|list<@T>) => Set<int> - [-=](#op_sub_set)(_self_: Set<@T>, invar _other_: Set<@T>|list<@T>) => Set<int> - [+](#op_add)(invar _a_: Set<@T>, invar _b_: Set<@T>|list<@T>) => Set<@T> - [+](#op_add)(c: Set<@T>, invar _a_: Set<@T>, invar _b_: Set<@T>|list<@T>) => Set<@T> - [|](#op_add)(invar _a_: Set<@T>, invar _b_: Set<@T>|list<@T>) => Set<@T> - [|](#op_add)(c: Set<@T>, invar _a_: Set<@T>, invar _b_: Set<@T>|list<@T>) => Set<@T> - [-](#op_sub)(invar _a_: Set<@T>, invar _b_: Set<@T>|list<@T>) => Set<@T> - [-](#op_sub)(c: Set<@T>, invar _a_: Set<@T>, invar _b_: Set<@T>|list<@T>) => Set<@T> - [&](#op_and)(invar _a_: Set<@T>, invar _b_: Set<@T>|list<@T>) => Set<@T> - [&](#op_and)(c: Set<@T>, invar _a_: Set<@T>, invar _b_: Set<@T>|list<@T>) => Set<@T> - [^](#op_xor)(invar _a_: Set<@T>, invar _b_: Set<@T>|list<@T>) => Set<@T> - [^](#op_xor)(c: Set<@T>, invar _a_: Set<@T>, invar _b_: Set<@T>|list<@T>) => Set<@T> - [*](#op_mul)(invar _a_: Set<@X>, invar _b_: Set<@Y>|list<@Y>) => Set<tuple<@X,@Y>> - [*](#op_mul)(_c_: Set<tuple<@X,@Y>>, invar _a_: Set<@X>, invar _b_: Set<@Y>|list<@Y>) => Set<tuple<@X,@Y>> - [(string)](#string)(invar _self_: Set<@T>) - [items](#items)(invar _self_: Set<@T>) => list<@T> - [==](#cmp)(invar _a_: Set<@T>, invar b: Set<@T>|list<@T>) => bool - [!=](#cmp)(invar _a_: Set<@T>, invar b: Set<@T>|list<@T>) => bool - [for](#for)(invar _self_: Set<@T>, _iterator_: ForIterator) - [[]](#for)(invar _self_: Set<@T>, _index_: ForIterator) => @T - [collect](#collect)(invar _self_: Set<@T>)[invar _item_: @T => @V|none] => Set<@V> - [collect](#collect2)(invar _self_: Set<@X>, invar _other_: Set<@Y>)[invar _item_: @X, invar _item2_: @Y => @V|none] => Set<@V> - [associate](#associate)(invar _self_: Set<@T>, _hashing_: enum<none,auto,random>|int = $none)[invar _item_: @T => none|tuple<@K,@V>] => map<@K,@V> - [associate](#associate2)(invar _self_: Set<@X>, invar _other_: Set<@Y>, _hashing_: enum<none,auto,random>|int = $none)[invar _item_: @X, invar _item2_: @Y => none|tuple<@K,@V>] => map<@K,@V> - [find](#find)(invar _self_: Set<@T>)[invar _item_: @T => bool] => @T|none - [reduce](#reduce)(invar _self_: Set<@T>)[invar _item_: @T, _value_: @T => @T] => @T|none - [reduce](#reduce)(invar _self_: Set<@T>, init: @V)[invar _item_: @T, _value_: @V => @V] => @V - [select](#select)(invar _self_: Set<@T>)[invar _item_: @T => bool] => Set<@T> - [iterate](#iterate)(invar _self_: Set<@T>)[invar _item_: @T] ### Classes #### `std::Set` Tree- or hash-based set type. __Note:__ For set operations involving two sets and producing a new set, the kind of the resulting set is determined by the left operand #### Methods ```ruby Set<@T>(kind: enum = $tree) ``` Constructs new tree- or hash-based set depending on *kind* ```ruby .size(invar self: Set<@T>) => int ``` Set size ```ruby insert(self: Set<@T>, invar value: @T) ``` Inserts \a value into the set ```ruby contains(invar self: Set<@T>, invar value: @T) => bool [](invar self: Set<@T>, invar value: @T) => bool ``` Check if the set contains the given *value* ```ruby contains(invar self: Set<@T>, invar other: Set<@T>|list<@T>) => bool ``` Check if the set contains *other* set ```ruby erase(self: Set<@T>, invar value: @T) ``` Removes *value* from the set ```ruby clone(invar self: Set<@T>) => Set<@T> ``` Returns set copy ```ruby clear(self: Set<@T>) ``` Removes all items from the set ```ruby +=(self: Set<@T>, invar other: Set<@T>|list<@T>) => Set |=(self: Set<@T>, invar other: Set<@T>|list<@T>) => Set ``` Insert *other* items in the set and returns self ```ruby -=(self: Set<@T>, invar other: Set<@T>|list<@T>) => Set ``` Removes *other* items from the set and returns self ```ruby +(invar a: Set<@T>, invar b: Set<@T>|list<@T>) => Set<@T> +(c: Set<@T>, invar a: Set<@T>, invar b: Set<@T>|list<@T>) => Set<@T> |(invar a: Set<@T>, invar b: Set<@T>|list<@T>) => Set<@T> |(c: Set<@T>, invar a: Set<@T>, invar b: Set<@T>|list<@T>) => Set<@T> ``` Union of *a* and *b* ```ruby -(invar a: Set<@T>, invar b: Set<@T>|list<@T>) => Set<@T> -(c: Set<@T>, invar a: Set<@T>, invar b: Set<@T>|list<@T>) => Set<@T> ``` Difference of *a* and *b* ```ruby &(invar a: Set<@T>, invar b: Set<@T>|list<@T>) => Set<@T> &(c: Set<@T>, invar a: Set<@T>, invar b: Set<@T>|list<@T>) => Set<@T> ``` Intersection of *a* and *b* ```ruby ^(invar a: Set<@T>, invar b: Set<@T>|list<@T>) => Set<@T> ^(c: Set<@T>, invar a: Set<@T>, invar b: Set<@T>|list<@T>) => Set<@T> ``` Symmetric defference of *a* and *b* ```ruby *(invar a: Set<@X>, invar b: Set<@Y>|list<@Y>) => Set> *(c: Set>, invar a: Set<@X>, invar b: Set<@Y>|list<@Y>) => Set> ``` Cartesian product *a* and *b* ```ruby (string)(invar self: Set<@T>) ``` String conversion ```ruby items(invar self: Set<@T>) => list<@T> ``` Set items as list ```ruby ==(invar a: Set<@T>, invar b: Set<@T>|list<@T>) => bool !=(invar a: Set<@T>, invar b: Set<@T>|list<@T>) => bool ``` Set comparison ```ruby for(invar self: Set<@T>, iterator: ForIterator) [](invar self: Set<@T>, index: ForIterator) => @T ``` For-in iteration support ```ruby collect(invar self: Set<@T>)[invar item: @T => @V|none] => Set<@V> ``` Iterates over the set, collecting non-`none` values returned from the code section into a new set ```ruby collect(invar self: Set<@X>, invar other: Set<@Y>)[invar item: @X, invar item2: @Y => @V|none] => Set<@V> ``` Iterates over the two sets in parallel, collecting non-`none` values returned from the code section into a new set ```ruby associate(invar self: Set<@T>, hashing: enum|int = $none)[invar item: @T => none|tuple<@K,@V>] => map<@K,@V> ``` Iterates over the set, forming a map out of the key-value tuples returned from the code section ```ruby associate(invar self: Set<@X>, invar other: Set<@Y>, hashing: enum|int = $none)[invar item: @X, invar item2: @Y => none|tuple<@K,@V>] => map<@K,@V> ``` Iterates over the two sets in parallel, forming a map out of the key-value tuples returned from the code section ```ruby find(invar self: Set<@T>)[invar item: @T => bool] => @T|none ``` Returns the first item in the set satisfying the condition specified by the code section (`none` if not found) ```ruby reduce(invar self: Set<@T>)[invar item: @T, value: @T => @T] => @T|none reduce(invar self: Set<@T>, init: @V)[invar item: @T, value: @V => @V] => @V ``` Iterates over the set, yielding each *item* and accumulated *value* (with the initial value of *init* or the first item in the set); code section result forms the new value to be passed to the next iteration. Returns the accumulated value ```ruby select(invar self: Set<@T>)[invar item: @T => bool] => Set<@T> ``` Selects all items satisfying the condition specified by the code section and returns them in a new set ```ruby iterate(invar self: Set<@T>)[invar item: @T] ``` Iterates over set items