Vcsn  2.4
Be Rational
set.hxx
Go to the documentation of this file.
1 #include <iostream>
2 
3 #include <vcsn/misc/algorithm.hh> // set_intersection
4 
5 namespace vcsn
6 {
7  template <typename T, typename Compare, typename Alloc>
8  bool
9  has(const std::set<T, Compare, Alloc>& s, const T& e)
10  {
11  return s.find(e) != std::end(s);
12  }
13 
14 
15  template <typename T, typename Compare, typename Alloc>
16  std::set<std::set<T, Compare, Alloc>>
17  intersection_closure(std::set<std::set<T, Compare, Alloc>> pset)
18  {
19  while (true)
20  {
21  bool done = true;
22  for (const auto& set1: pset)
23  for (const auto& set2: pset)
24  if (pset.emplace(set_intersection(set1, set2)).second)
25  done = false;
26  if (done)
27  break;
28  }
29  return pset;
30  }
31 
32 
33  template <typename T, typename Compare, typename Alloc>
34  std::ostream&
35  print(const std::set<T, Compare, Alloc>& set, std::ostream& o)
36  {
37  const char* sep = "";
38  for (const auto& m: set)
39  {
40  o << sep << m;
41  sep = ", ";
42  }
43  return o;
44  }
45 
46 
47  template <typename Container>
48  bool subset(const Container& set1, const Container& set2)
49  {
50  return std::includes(set2.begin(), set2.end(),
51  set1.begin(), set1.end(),
52  set1.key_comp());
53  }
54 }
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:17
Container set_intersection(const Container &s1, const Container &s2)
The intersection of two sets.
Definition: algorithm.hh:184
std::ostream & print(const Aut &aut, std::ostream &out=std::cout, const std::string &fmt="default")
Definition: print.hh:83
Definition: a-star.hh:8
bool subset(const Container &set1, const Container &set2) ATTRIBUTE_PURE
Whether set1 ⊆ set2.
Definition: set.hxx:48
ATTRIBUTE_PURE bool has(const boost::container::flat_set< Key, Compare, Allocator > &s, const Key &e)
Whether e is member of s.
Definition: setalpha.hh:25
Request the set implementation (bool weights).