Vcsn  2.1
Be Rational
set.hh
Go to the documentation of this file.
1 #pragma once
2 
3 #include <algorithm> // set_intersection
4 #include <set>
5 
8 
9 namespace std
10 {
11 
12  /*---------------.
13  | hash(set<T>). |
14  `---------------*/
15 
16  template <typename T, typename Compare, typename Alloc>
17  struct hash<set<T, Compare, Alloc>>
18  {
19  using type = set<T, Compare, Alloc>;
20  size_t operator()(const type& ss) const
21  {
22  size_t res = 0;
23  for (const auto& s: ss)
24  hash_combine(res, s);
25  return res;
26  }
27  };
28 }
29 
30 namespace vcsn
31 {
33  template <typename T, typename Compare, typename Alloc>
34  std::set<T, Compare, Alloc>
35  set_difference(const std::set<T, Compare, Alloc>& set1,
36  const std::set<T, Compare, Alloc>& set2)
37  {
38  using set_t = std::set<T, Compare, Alloc>;
39  set_t res;
40  std::insert_iterator<set_t> i{res, begin(res)};
41  std::set_difference(begin(set1), end(set1),
42  begin(set2), end(set2),
43  i);
44  return res;
45  }
46 
48  template <typename T, typename Compare, typename Alloc>
49  bool
50  has(const std::set<T, Compare, Alloc>& s, const T& e)
51  ATTRIBUTE_PURE;
52 
54  template <typename T, typename Compare, typename Alloc>
55  std::set<T, Compare, Alloc>
56  intersection(const std::set<T, Compare, Alloc>& set1,
57  const std::set<T, Compare, Alloc>& set2);
58 
60  template <typename T, typename Compare, typename Alloc>
61  std::set<std::set<T, Compare, Alloc>>
62  intersection_closure(std::set<std::set<T, Compare, Alloc>> pset);
63 
65  template <typename T, typename Compare, typename Alloc>
66  std::set<T, Compare, Alloc>
67  get_union(const std::set<T, Compare, Alloc>& set1,
68  const std::set<T, Compare, Alloc>& set2);
69 
71  template <typename T, typename Compare, typename Alloc>
72  std::ostream&
73  print(const std::set<T, Compare, Alloc>& set, std::ostream& o);
74 
76  template <typename Container>
77  bool subset(const Container& set1, const Container& set2)
78  ATTRIBUTE_PURE;
79 }
80 
81 #include <vcsn/misc/set.hxx>
STL namespace.
std::set< std::set< T, Compare, Alloc > > intersection_closure(std::set< std::set< T, Compare, Alloc >> pset)
The set of all the intersections of the sets in pset.
Definition: set.hxx:31
std::set< T, Compare, Alloc > set_difference(const std::set< T, Compare, Alloc > &set1, const std::set< T, Compare, Alloc > &set2)
The set of members of set1 that are not members of set2.
Definition: set.hh:35
bool subset(const Container &set1, const Container &set2) ATTRIBUTE_PURE
Whether set1 ⊆ set2.
Definition: set.hxx:78
size_t operator()(const type &ss) const
Definition: set.hh:20
void hash_combine(std::size_t &seed, const T &v)
Definition: functional.hh:32
std::ostream & print(const Aut &aut, std::ostream &out, const std::string &format)
Definition: print.hh:77
std::set< T, Compare, Alloc > get_union(const std::set< T, Compare, Alloc > &set1, const std::set< T, Compare, Alloc > &set2)
The union of two sets.
Definition: set.hxx:49
set< T, Compare, Alloc > type
Definition: set.hh:19
ATTRIBUTE_PURE bool has(const std::deque< T, Allocator > &s, const T &e)
Whether e is member of s.
Definition: deque.hh:13
std::set< T, Compare, Alloc > intersection(const std::set< T, Compare, Alloc > &set1, const std::set< T, Compare, Alloc > &set2)
The intersection of two sets.
Definition: set.hxx:15