Awali
Another Weighted Automata library
set.hh
Go to the documentation of this file.
1 // This file is part of Awali.
2 // Copyright 2016-2022 Sylvain Lombardy, Victor Marsault, Jacques Sakarovitch
3 //
4 // Awali is a free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
16 
17 #ifndef AWALI_MISC_SET_HH
18 # define AWALI_MISC_SET_HH
19 
20 # include <algorithm> // set_intersection
21 # include <map>
22 # include <set>
23 
25 #include <awali/utils/hash.hh>
26 
27 namespace std
28 {
29 
30  /*---------------.
31  | hash(set<T>). |
32  `---------------*/
33 
34  template <typename T>
35  struct hash<set<T>>
36  {
37  size_t operator()(const set<T>& ss) const
38  {
39  size_t res = 0;
40  for (const auto& s: ss)
41  hash_combine(res, s);
42  return res;
43  }
44  };
45 }
46 
47 namespace awali {
48  namespace sttc {
49  namespace internal {
50 
52  template <typename T, typename Compare, typename Alloc>
53  bool
54  has(const std::set<T, Compare, Alloc>& s, const T& e)
55  ATTRIBUTE_PURE;
56 
58  template <typename Key, typename Value, typename Comp, typename Alloc>
59  std::set<typename std::map<Key, Value, Comp, Alloc>::mapped_type>
60  image(const std::map<Key, Value, Comp, Alloc>& m);
61 
63  template <typename T, typename Compare, typename Alloc>
64  std::set<T, Compare, Alloc>
65  intersection(const std::set<T, Compare, Alloc>& set1,
66  const std::set<T, Compare, Alloc>& set2);
67 
69  template <typename T, typename Compare, typename Alloc>
70  std::set<std::set<T, Compare, Alloc>>
71  intersection_closure(std::set<std::set<T, Compare, Alloc>> pset);
72 
74  template <typename T, typename Compare, typename Alloc>
75  std::set<T, Compare, Alloc>
76  get_union(const std::set<T, Compare, Alloc>& set1,
77  const std::set<T, Compare, Alloc>& set2);
78 
80  template <typename T, typename Compare, typename Alloc>
81  std::ostream&
82  print(const std::set<T, Compare, Alloc>& set, std::ostream& o);
83 
85  template <typename Container1, typename Container2>
86  bool subset(const Container1& set1, const Container2& set2)
87  ATTRIBUTE_PURE;
88  }
89  }
90 }//end of ns awali::stc
91 
92 #include <awali/sttc/misc/set.hxx>
93 
94 #endif // !AWALI_MISC_SET_HH
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.
std::ostream & print(const std::set< T, Compare, Alloc > &set, std::ostream &o)
Print with a separator. Meant to help debugging.
bool subset(const Container1 &set1, const Container2 &set2) ATTRIBUTE_PURE
Whether set1 ⊆ set2.
Definition: set.hxx:105
bool has(const std::map< Key, Value, Compare, Alloc > &s, const Key &e)
Definition: map.hh:53
std::set< typename std::map< Key, Value, Comp, Alloc >::mapped_type > image(const std::map< Key, Value, Comp, Alloc > &m)
The set of values of a map.
Definition: set.hxx:33
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.
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.
Main namespace of Awali.
Definition: ato.hh:22
size_t operator()(const set< T > &ss) const
Definition: set.hh:37
void hash_combine(std::size_t &seed, const T &v)
Definition: hash.hh:27