blob: 68a1f451cebaea760a1478701397ab5d3127a1f7 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.difference = exports.symmetricDifference = exports.intersection = exports.union = exports.isSuperset = void 0;
/**
* Test if a Set contains all elements of another Set.
*
* @param set -
* @param subset -
*
* @returns True if set contains all elements of subset, otherwise false.
*/
function isSuperset(set, subset) {
for (const elem of subset) {
if (!set.has(elem)) {
return false;
}
}
return true;
}
exports.isSuperset = isSuperset;
/**
* Construct the union of two Sets.
*
* @param setA -
* @param setB -
*
* @returns A new Set containing all elements from setA and setB.
*/
function union(setA, setB) {
const result = new Set(setA);
for (const elem of setB) {
result.add(elem);
}
return result;
}
exports.union = union;
/**
* Construct the intersection of two Sets.
*
* @param setA -
* @param setB -
*
* @returns A new Set containing only those elements which appear in both setA and setB.
*/
function intersection(setA, setB) {
const result = new Set();
for (const elem of setB) {
if (setA.has(elem)) {
result.add(elem);
}
}
return result;
}
exports.intersection = intersection;
/**
* Construct the symmetric difference (XOR) of two Sets.
*
* @param setA -
* @param setB -
*
* @returns A new Set containing only those elements which appear in setA or in setB but not in both setA and setB.
*/
function symmetricDifference(setA, setB) {
const result = new Set(setA);
for (const elem of setB) {
if (result.has(elem)) {
result.delete(elem);
}
else {
result.add(elem);
}
}
return result;
}
exports.symmetricDifference = symmetricDifference;
/**
* Construct the difference of two Sets.
*
* @param setA -
* @param setB -
*
* @returns A new Set containing the elements of setA which do not appear in setB.
*/
function difference(setA, setB) {
const result = new Set(setA);
for (const elem of setB) {
result.delete(elem);
}
return result;
}
exports.difference = difference;
//# sourceMappingURL=set.js.map
|