forked from DrorFried/Synthesis-via-Decomposition
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSet.hpp
78 lines (53 loc) · 1.57 KB
/
Set.hpp
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
#pragma once
#include <set>
#include <vector>
#include <algorithm>
#include <iterator>
#include <numeric>
#include <cstddef>
/**
* Type alias for std::set and additional operations.
*/
template <class T>
using Set = std::set<T>;
/* Implementation of templated functions in header file so that it can be accessed by code instantiating the template. */
template <class T>
T maxElement(const Set<T>& set)
{
return *set.rbegin();
}
template <class T>
bool isSubset(const Set<T>& subset, const Set<T>& superset)
{
return std::includes(superset.begin(), superset.end(),
subset.begin(), subset.end());
}
template <class T>
Set<T> setUnion(const Set<T>& set1, const Set<T>& set2)
{
Set<T> newSet;
std::set_union(set1.begin(), set1.end(),
set2.begin(), set2.end(),
std::inserter(newSet, newSet.begin()));
return newSet;
}
template <class T>
Set<T> setIntersection(const Set<T>& set1, const Set<T>& set2)
{
Set<T> newSet;
std::set_intersection(set1.begin(), set1.end(),
set2.begin(), set2.end(),
std::inserter(newSet, newSet.begin()));
return newSet;
}
template <class T>
Set<T> setDifference(const Set<T>& set1, const Set<T>& set2)
{
Set<T> newSet;
std::set_difference(set1.begin(), set1.end(),
set2.begin(), set2.end(),
std::inserter(newSet, newSet.begin()));
return newSet;
}
/** Returns the set representing the range [fromInclusive, toInclusive]. */
Set<std::size_t> range(std::size_t fromInclusive, std::size_t toInclusive);