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