Intersection is the set of elements
shared by the two sets. Difference is the set of elements from the first set that are
not found in the second set.
Set
s1 = new Set(1, 2, 3, 4, 5, 6);
Set s2 = new Set(1, 3, 5, 7, 9, 11);
Set s3 = s1.Union(s2);
Set s4 = s1.Intersect(s2);
Set s5 = s1.Difference(s2);
Assert.AreEqual(s3, new Set(1, 2, 3, 4, 5, 6, 7, 9, 11));
Assert.AreEqual(s4, new Set(1, 3, 5));
Assert.AreEqual(s5, new Set(2, 4, 6));
You can write union as +, intersection as *, and difference as -.
Set s1 = new Set(1, 2, 3, 4, 5, 6);
Set s2 = new Set(1, 3, 5, 7, 9, 11);
Set s3 = s1 + s2;
Set s4 = s1 * s2;
Set s5 = s1 - s2;
Assert.AreEqual(s3, new Set(11, 3, 2, 9, 6, 5, 7, 4, 1));
Assert.AreEqual(s4, new Set(3, 1, 5));
Assert.AreEqual(s5, new Set(6, 4, 2));
10.3.2 Maps
Maps associate unique keys with values. This is similar to the .NET Dictionary type,
except that a map is an immutable value. Operations to add and remove elements
result in new maps instead of making changes to the map given as the argument.
Another difference between maps and the .NET dictionary type is structural
equality. Two maps of the same type are equal if they contain the same key/value
pairs. Dictionaries in .NET use reference equality instead of structural equality.
Pages:
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231