/usr/include/polymake/next/hash_map is in polymake 3.0r1-4.
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 | /* Copyright (c) 1997-2015
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_
#if defined(__cplusplus) && __cplusplus >= 201103L && !defined(PM_FORCE_TR1)
#include <unordered_map>
#define PmTr1NS std
#else
#include <tr1/unordered_map>
#define PmTr1NS std::tr1
#endif
#include "polymake/internal/assoc.h"
#include "polymake/internal/hash_iterators.h"
namespace pm {
template <typename Key, typename Value, typename Params=void>
class hash_map
: public PmTr1NS::unordered_map<Key, Value, hash_func<Key>, typename hash_table_cmp_adapter<Key,Params>::type> {
typedef PmTr1NS::unordered_map<Key, Value, hash_func<Key>, typename hash_table_cmp_adapter<Key,Params>::type> _super;
typedef typename extract_type_param<Params, DefaultValue, operations::clear<Value> >::type default_value_supplier;
default_value_supplier dflt;
public:
hash_map() {}
explicit hash_map(size_t start_cap) : _super(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) : _super(start_cap), dflt(dflt_arg) {}
template <typename Iterator>
hash_map(Iterator first, Iterator last) : _super(first,last) {}
template <typename Iterator>
hash_map(Iterator first, Iterator last, const default_value_supplier& dflt_arg) : _super(first,last), dflt(dflt_arg) {}
bool exists(typename function_argument<Key>::type k) const
{
return _super::find(k) != _super::end();
}
typename _super::iterator
insert(typename function_argument<Key>::type k)
{
return _super::insert(typename _super::value_type(k, dflt())).first;
}
#if 0
template <typename Operation>
typename _super::iterator
insert(typename function_argument<Key>::type k, const Operation& op, typename disable_if<void**, identical<Operation,Value>::value>::type=0)
{
std::pair<typename _super::iterator,bool> ret=_super::insert(typename _super::value_type(k, dflt()));
if (!ret.second) op(ret.first->second);
return ret.first;
}
#endif
typename _super::iterator
insert(typename function_argument<Key>::type k, typename function_argument<Value>::type v)
{
std::pair<typename _super::iterator,bool> ret=_super::insert(typename _super::value_type(k,v));
if (!ret.second) ret.first->second=v;
return ret.first;
}
#if 0
template <typename Operation>
typename _super::iterator
insert(typename function_argument<Key>::type k, typename function_argument<Value>::type v, const Operation& op)
{
std::pair<typename _super::iterator,bool> ret=_super::insert(typename _super::value_type(k,v));
if (!ret.second) op(ret.first->second,v);
return ret.first;
}
#endif
std::pair<typename _super::iterator,bool>
find_or_insert(typename function_argument<Key>::type k)
{
return _super::insert(typename _super::value_type(k, dflt()));
}
std::pair<typename _super::iterator,bool>
insert(const typename _super::value_type& p) { return _super::insert(p); }
template <typename Iterator>
void insert(Iterator first, Iterator last, typename disable_if<void**, identical<Iterator,Key>::value && identical<Iterator,Value>::value>::type=0)
{
_super::insert(first,last);
}
bool operator== (const hash_map& other) const
{
if (this->size() != other.size()) return false;
typename _super::const_iterator not_found=this->end();
for (typename _super::const_iterator elem=other.begin(), other_end=other.end(); elem != other_end; ++elem) {
typename _super::const_iterator my=this->find(elem->first);
if (my==not_found || my->second != elem->second)
return false;
}
return true;
}
bool operator!= (const hash_map& other) const { return !operator==(other); }
class filler {
public:
filler(hash_map& me_arg) : me(me_arg) {};
void operator() (const typename _super::value_type& p) const { me.insert(p); }
void operator() (typename function_argument<Key>::type k, typename function_argument<Value>::type v) const { me.insert(k,v); }
private:
hash_map& me;
};
filler make_filler() { return filler(*this); }
};
template <typename Key, typename Value, typename Params>
struct spec_object_traits< hash_map<Key,Value,Params> >
: spec_object_traits<is_container> {
static const IO_separator_kind IO_separator=IO_sep_inherit;
};
// FIXME: soon deprecated
template <typename Key, typename Value, typename HashFcn=hash_func<Key>, typename EqualKey=std::equal_to<Key> >
class hash_map_as_property_map
: public PmTr1NS::unordered_map<Key, Value, HashFcn, EqualKey> {
typedef PmTr1NS::unordered_map<Key, Value, HashFcn, EqualKey> _super;
public:
hash_map_as_property_map() {}
explicit hash_map_as_property_map(size_t start_cap)
: _super(start_cap) {}
Value& operator() (const Key& k)
{
return (_super::insert(typename _super::value_type(k, def_val))).first->second;
}
const Value& operator() (const Key& k) const
{
typename _super::const_iterator ii=this->find(k);
return ii==this->end() ? def_val : ii->second;
}
std::pair<typename _super::iterator, bool>
insert(const Key& k, typename function_argument<Value>::type v)
{
return _super::insert(typename _super::value_type(k, v));
}
void set_default_value(typename function_argument<Value>::type default_value)
{
def_val=default_value;
}
protected:
Value def_val;
};
} // 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:
|