My Project
SetUtil.h
Go to the documentation of this file.
1 #ifndef _SETUTIL_H__
2 #define _SETUTIL_H__
3 
4 #include <algorithm>
5 #include <iterator>
6 #include <set>
7 
8 using namespace std;
9 
11 using setInt = set<int>;
12 
20 class setOp
21 {
22 public:
23 
25  static setInt setIntersection(const setInt& S1, const setInt& S2) {
26  setInt R;
27  set_intersection(S1.begin(),S1.end(),S2.begin(),S2.end(),
28  std::inserter(R,R.begin()));
29  return R;
30  }
31 
33  static setInt setUnion(const setInt& S1, const setInt& S2) {
34  setInt R = S1;
35  R.insert(S2.begin(), S2.end());
36  return R;
37  }
38 
40  static setInt setDifference(const setInt& S, const setInt& notS) {
41  setInt R;
42  std::set_difference(S.begin(), S.end(), notS.begin(), notS.end(),
43  std::inserter(R, R.end()));
44 
45  return R;
46  }
47 
49  static bool setEqual(const setInt& S1, const setInt& S2) {
50  return S1 == S2;
51  }
52 
54  static bool setIncludes(const setInt& S1, const setInt& S2) {
55  return std::includes(S1.begin(), S1.end(), S2.begin(), S2.end());
56  }
57 };
58 
59 
60 #endif // _SETUTIL_H__
static bool setIncludes(const setInt &S1, const setInt &S2)
Checks whether S1 includes S2.
Definition: SetUtil.h:54
static setInt setIntersection(const setInt &S1, const setInt &S2)
Set Intersection.
Definition: SetUtil.h:25
static bool setEqual(const setInt &S1, const setInt &S2)
Checks whether two sets are equal (the == operator can also be used)
Definition: SetUtil.h:49
static setInt setUnion(const setInt &S1, const setInt &S2)
Set Union.
Definition: SetUtil.h:33
Definition: SetUtil.h:20
static setInt setDifference(const setInt &S, const setInt &notS)
Set Difference: S \ notS.
Definition: SetUtil.h:40
set< int > setInt
Operations on sets of integers.
Definition: SetUtil.h:11