Awali
Another Weighted Automata library
map.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_MAP_HH
18 # define AWALI_MISC_MAP_HH
19 
20 # include <map>
21 #include <awali/utils/hash.hh>
22 
23 namespace std
24 {
25 
26  /*------------------------.
27  | hash(map<Key, Value>). |
28  `------------------------*/
29 
30  template <typename Key, typename Value, typename Compare, typename Alloc>
31  struct hash<map<Key, Value, Compare, Alloc>>
32  {
33  size_t operator()(const map<Key, Value, Compare, Alloc>& m) const
34  {
35  size_t res = 0;
36  for (const auto& kv: m)
37  {
38  hash_combine(res, kv.first);
39  hash_combine(res, kv.second);
40  }
41  return res;
42  }
43  };
44 }
45 
46 namespace awali {
47  namespace sttc {
48  namespace internal {
49 
50  template <typename Key, typename Value, typename Compare, typename Alloc>
51  inline
52  bool
53  has(const std::map<Key, Value, Compare, Alloc>& s, const Key& e)
54  {
55  return s.find(e) != std::end(s);
56  }
57 
59  template <typename ValueSet>
60  class less : public std::less<typename ValueSet::value_t>
61  {
62  public:
63  using valueset_t = ValueSet;
64  using value_t = typename valueset_t::value_t;
65 
66  bool operator()(const value_t& lhs, const value_t& rhs) const
67  {
68  return valueset_t::less_than(lhs, rhs);
69  }
70  };
71  }
72  }
73 }//end of ns awali::stc
74 
75 #endif // !AWALI_MISC_MAP_HH
adapter of std::less to wrap less_than method of valuesets
Definition: map.hh:61
typename valueset_t::value_t value_t
Definition: map.hh:64
bool operator()(const value_t &lhs, const value_t &rhs) const
Definition: map.hh:66
ValueSet valueset_t
Definition: map.hh:63
auto map(const std::tuple< Ts... > &ts, Fun f) -> decltype(map_tuple_(f, ts, make_index_sequence< sizeof...(Ts)>()))
Map a function on a tuple, return tuple of the results.
Definition: tuple.hh:134
bool has(const std::map< Key, Value, Compare, Alloc > &s, const Key &e)
Definition: map.hh:53
RatExpSet::ratexp_t less_than(const RatExpSet &rs, const typename RatExpSet::ratexp_t &v)
Definition: less_than.hh:166
Main namespace of Awali.
Definition: ato.hh:22
size_t operator()(const map< Key, Value, Compare, Alloc > &m) const
Definition: map.hh:33
void hash_combine(std::size_t &seed, const T &v)
Definition: hash.hh:27