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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
| // (C) Copyright Jeremy Siek 2001.
| // Distributed under the Boost Software License, Version 1.0. (See
| // accompanying file LICENSE_1_0.txt or copy at
| // http://www.boost.org/LICENSE_1_0.txt)
|
| #ifndef BOOST_SET_ADAPTOR_HPP
| #define BOOST_SET_ADAPTOR_HPP
|
| #include <set>
| #include <boost/unordered_set.hpp>
|
| namespace boost
| {
|
| template < class K, class C, class A, class T >
| bool set_contains(const std::set< K, C, A >& s, const T& x)
| {
| return s.find(x) != s.end();
| }
|
| template < class K, class H, class C, class A, class T >
| bool set_contains(const boost::unordered_set< K, H, C, A >& s, const T& x)
| {
| return s.find(x) != s.end();
| }
|
| template < class K, class C, class A >
| bool set_equal(const std::set< K, C, A >& x, const std::set< K, C, A >& y)
| {
| return x == y;
| }
|
| // Not the same as lexicographical_compare_3way applied to std::set.
| // this is equivalent semantically to bitset::operator<()
| template < class K, class C, class A >
| int set_lex_order(const std::set< K, C, A >& x, const std::set< K, C, A >& y)
| {
| typename std::set< K, C, A >::iterator xi = x.begin(), yi = y.begin(),
| xend = x.end(), yend = y.end();
| for (; xi != xend && yi != yend; ++xi, ++yi)
| {
| if (*xi < *yi)
| return 1;
| else if (*yi < *xi)
| return -1;
| }
| if (xi == xend)
| return (yi == yend) ? 0 : -1;
| else
| return 1;
| }
|
| template < class K, class C, class A > void set_clear(std::set< K, C, A >& x)
| {
| x.clear();
| }
|
| template < class K, class C, class A >
| bool set_empty(const std::set< K, C, A >& x)
| {
| return x.empty();
| }
|
| template < class K, class C, class A, class T >
| void set_insert(std::set< K, C, A >& x, const T& a)
| {
| x.insert(a);
| }
|
| template < class K, class C, class A, class T >
| void set_remove(std::set< K, C, A >& x, const T& a)
| {
| x.erase(a);
| }
|
| template < class K, class C, class A >
| void set_intersect(const std::set< K, C, A >& x, const std::set< K, C, A >& y,
| std::set< K, C, A >& z)
| {
| z.clear();
| std::set_intersection(
| x.begin(), x.end(), y.begin(), y.end(), std::inserter(z));
| }
|
| template < class K, class C, class A >
| void set_union(const std::set< K, C, A >& x, const std::set< K, C, A >& y,
| std::set< K, C, A >& z)
| {
| z.clear();
| std::set_union(x.begin(), x.end(), y.begin(), y.end(), std::inserter(z));
| }
|
| template < class K, class C, class A >
| void set_difference(const std::set< K, C, A >& x, const std::set< K, C, A >& y,
| std::set< K, C, A >& z)
| {
| z.clear();
| std::set_difference(
| x.begin(), x.end(), y.begin(), y.end(), std::inserter(z, z.begin()));
| }
|
| template < class K, class C, class A >
| bool set_subset(const std::set< K, C, A >& x, const std::set< K, C, A >& y)
| {
| return std::includes(x.begin(), x.end(), y.begin(), y.end());
| }
|
| // Shit, can't implement this without knowing the size of the
| // universe.
| template < class K, class C, class A >
| void set_compliment(const std::set< K, C, A >& /*x*/, std::set< K, C, A >& z)
| {
| z.clear();
| }
|
| } // namespace boost
|
| #endif // BOOST_SET_ADAPTOR_HPP
|
|