/usr/include/polymake/next/hash_map is in libpolymake-dev-common 3.2r2-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 | /* Copyright (c) 1997-2018
Ewgenij Gawrilow, Michael Joswig (Technische Universitaet Berlin, Germany)
http://www.polymake.org
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2, or (at your option) any
later version: http://www.gnu.org/licenses/gpl.txt.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
--------------------------------------------------------------------------------
*/
#ifndef POLYMAKE_HASH_MAP_
#define POLYMAKE_HASH_MAP_
#include <unordered_map>
#include "polymake/internal/assoc.h"
#include "polymake/internal/hash_iterators.h"
namespace pm {
template <typename Key, typename Value, typename... TParams>
class hash_map
: public std::unordered_map<Key, Value, hash_func<Key>, typename hash_table_cmp_adapter<Key, TParams...>::type> {
typedef std::unordered_map<Key, Value, hash_func<Key>, typename hash_table_cmp_adapter<Key, TParams...>::type> base_t;
typedef typename mlist_wrap<TParams...>::type params;
typedef typename mtagged_list_extract<params, DefaultValueTag, operations::clear<Value>>::type default_value_supplier;
default_value_supplier dflt;
public:
typedef Key key_type;
typedef Value mapped_type;
typedef operations::cmp key_comparator_type;
hash_map() {}
explicit hash_map(size_t start_cap) : base_t(start_cap) {}
explicit hash_map(const default_value_supplier& dflt_arg) : dflt(dflt_arg) {}
hash_map(const default_value_supplier& dflt_arg, size_t start_cap) : base_t(start_cap), dflt(dflt_arg) {}
template <typename Iterator>
hash_map(Iterator first, Iterator last) : base_t(first,last) {}
template <typename Iterator>
hash_map(Iterator first, Iterator last, const default_value_supplier& dflt_arg) : base_t(first,last), dflt(dflt_arg) {}
bool exists(const Key& k) const
{
return this->find(k) != this->end();
}
typename base_t::iterator
insert(const Key& k)
{
return this->emplace(k, dflt()).first;
}
template <typename ValueArg, typename... MoreArgs>
typename base_t::iterator
insert(const Key& k, ValueArg&& v, MoreArgs&& ...more_args)
{
auto ret=this->emplace(k, std::forward<ValueArg>(v), std::forward<MoreArgs>(more_args)...);
if (!ret.second) ret.first->second=Value(std::forward<ValueArg>(v), std::forward<MoreArgs>(more_args)...);
return ret.first;
}
std::pair<typename base_t::iterator, bool>
find_or_insert(const Key& k)
{
return this->emplace(k, dflt());
}
std::pair<typename base_t::iterator, bool>
insert(const typename base_t::value_type& p)
{
return base_t::insert(p);
}
template <typename Iterator>
void insert(Iterator first, Iterator last, typename std::enable_if<!(std::is_same<Iterator, Key>::value && std::is_same<Iterator, Value>::value), void**>::type=nullptr)
{
base_t::insert(first, last);
}
/** @brief Associative search.
Find the data element associated with the given key. If it doesn't exist so far, it will be created with the default constructor.
Note that the type of the search key is not necessarily the same as of the map entries.
It suffices that both are comparable with each other.
k can also be a container with keys; the result will be a sequence of corresponding values.
*/
template <typename TKeys>
typename assoc_helper<hash_map, TKeys>::result_type operator[] (const TKeys& k)
{
return assoc_helper<hash_map, TKeys>()(*this, k);
}
/** @brief Associative search (const).
Find the data element associated with the given key. If it doesn't exist so far, it will raise an exception.
Note that the type of the search key is not necessarily the same as of the map entries.
It suffices that both are comparable with each other.
k can also be a container with keys; the result will be a sequence of corresponding values.
*/
template <typename TKeys>
typename assoc_helper<const hash_map, TKeys>::result_type operator[] (const TKeys& k) const
{
return assoc_helper<const hash_map, TKeys>()(*this, k);
}
// synonym for compatibility
template <typename TKeys>
typename assoc_helper<const hash_map, TKeys>::result_type
at(const TKeys& k) const
{
return assoc_helper<const hash_map, TKeys>()(*this, k);
}
class filler {
public:
filler(hash_map& me_arg) : me(me_arg) {};
void operator() (const typename base_t::value_type& p) const { me.insert(p); }
template <typename... ValueArg>
void operator() (const Key& k, ValueArg&& ... v) const
{
me.insert(k, std::forward<ValueArg>(v)...);
}
private:
hash_map& me;
};
filler make_filler() { return filler(*this); }
};
template <typename Key, typename Value, typename... TParams>
struct spec_object_traits< hash_map<Key, Value, TParams...> >
: spec_object_traits<is_container> {
static const IO_separator_kind IO_separator=IO_sep_inherit;
};
template <typename Key, typename Value, typename... TParams>
struct choose_generic_object_traits<hash_map<Key, Value, TParams...>, false, false>
: spec_object_traits<hash_map<Key, Value, TParams...>> {
typedef void generic_type;
typedef is_map generic_tag;
typedef hash_map<Key, Value, TParams...> persistent_type;
};
template <typename Key, typename Value, typename... TParams>
struct is_ordered< hash_map<Key, Value, TParams...> >
: std::false_type { };
template <typename TKeys, typename TValues>
class assoc_helper<const hash_map<TKeys,TValues>, TKeys, true> {
public:
typedef const hash_map<TKeys,TValues> TMap;
typedef typename inherit_const<typename TMap::mapped_type, TMap>::type& result_type;
result_type operator()(TMap& map, const TKeys& k) const
{
auto e=map.find(k);
if (e == map.end()) throw no_match();
return e->second;
}
};
template <typename TKeys, typename TValues>
class assoc_helper<hash_map<TKeys,TValues>, TKeys, true> {
public:
typedef hash_map<TKeys,TValues> TMap;
typedef typename inherit_const<typename TMap::mapped_type, TMap>::type& result_type;
result_type operator()(TMap& map, const TKeys& k)
{
return map.insert(k)->second;
}
};
} // end namespace pm
namespace polymake {
using pm::hash_map;
}
#endif // POLYMAKE_HASH_MAP_
// Local Variables:
// mode:C++
// c-basic-offset:3
// indent-tabs-mode:nil
// End:
|