2 summary::a set according to equality
3 related::Classes/IdentitySet, Classes/List, Classes/Dictionary
4 categories::Collections>Unordered
7 A Set is s collection of objects, no two of which are equal. Most of its methods are inherited from Collection. The contents of a Set are unordered. You must not depend on the order of items in a set. For an ordered set, see link::Classes/OrderedIdentitySet::.
11 private::initSet, putCheck, fullCheck, grow, noCheckAdd
13 subsection::Adding and Removing
16 Add anObject to the Set. An object which is equal to an object already in the Set will not be added.
18 Set[1, 2, 3].add(4).postln;
19 Set[1, 2, 3].add(3).postln;
20 Set["abc", "def", "ghi"].add("jkl").postln;
21 Set["abc", "def", "ghi"].add("def").postln;
25 Remove anObject from the Set.
27 Set[1, 2, 3].remove(3).postln;
33 Evaluates function for each item in the Set. The function is passed two arguments, the item and an integer index.
35 Set[1, 2, 3, 300].do({ arg item, i; item.postln });
39 Returns the object at the internal strong::index::. This index is not deterministic.
41 subsection::Set specific operations
44 Return the set theoretical intersection of this and strong::that::.
46 a = Set[1, 2, 3]; b = Set[2, 3, 4, 5];
48 a & b // shorter syntax
52 Return the set theoretical union of this and strong::that::.
54 a = Set[1, 2, 3]; b = Set[2, 3, 4, 5];
56 a | b // shorter syntax
60 Return the set of all items which are elements of this, but not of strong::that::.
62 a = Set[1, 2, 3]; b = Set[2, 3, 4, 5];
64 a - b // shorter syntax
67 method::symmetricDifference, --
68 Return the set of all items which are not elements of both this and strong::that::.
70 a = Set[1, 2, 3]; b = Set[2, 3, 4, 5];
71 symmetricDifference(a, b);
72 a -- b // shorter syntax
76 Returns true if all elements of this are also elements of strong::that::.
79 Set[1, 2].isSubsetOf(a); // true
80 Set[1, 5].isSubsetOf(a); // false
87 b = a.powerset; // set of all parts
88 a.isSubsetOf(b); // false: no set is ever part of itself.
89 b.asArray.reduce(\union) == a; // true parts may not contain other elements that original
90 b.asArray.reduce(\difference).isEmpty; // true.
94 // you can use Set to efficiently remove duplicates from an array:
96 a = [1, 2, 3, 4, 3, 5, 5, 2, 2, 1];
97 a.as(Set); // convert to set
98 a.as(Set).as(Array); // and convert back