17 #ifndef AWALI_LINKED_MAP_HXX
18 #define AWALI_LINKED_MAP_HXX
22 #include <unordered_map>
33 template <
typename K,
typename H = std::hash<K>>
37 return (key ==
nullptr) ? 0 : H::operator()(*key);
46 template <
typename K,
typename E = std::equal_to<K>>
50 return (key1 ==
nullptr || key2 ==
nullptr) ? (key1 == key2)
51 : E::operator()(*key1,*key2);
70 template <
typename K,
typename V,
71 typename H = std::hash<K>,
typename E = std::equal_to<K>>
77 typedef std::pair<key_t const,value_t>
pair_t;
81 typedef typename std::list<pair_t>::iterator
iterator;
83 typedef std::unordered_map<
key_t const*,
104 for(
auto it =
list.begin(); it !=
list.end(); it++) {
106 auto x =
map.find(&(it->first));
110 map[&(it->first)]=it;
159 auto res =
map.find(&key);
160 if (res ==
map.end())
173 auto res =
map.find(&key);
174 if (res ==
map.end())
186 return map.find(&key) !=
map.end();
202 bool overwrite_existing =
false)
204 auto it =
map.find(&key);
205 if (it !=
map.end()) {
206 if (overwrite_existing) {
207 list.erase(it->second);
214 map.emplace(&(res->first),res);
225 bool overwrite_existing =
false)
247 insert(
end(), std::move(key), std::move(
value), overwrite_existing);
258 if (pos == this->
cend())
260 map.erase(&(pos->first));
261 return list.erase(pos);
271 auto it =
map.find(&key);
287 auto it =
map.find(&key);
289 return it->second->second;
290 std::stringstream ss;
291 ss <<
"This linked_map does not have a binding with key" << key <<
".";
292 throw std::out_of_range(ss.str());
303 auto it =
map.find(&key);
305 return it->second->second;
306 std::stringstream ss;
307 ss <<
"This linked_map does not have a binding with key" << key <<
".";
308 throw std::out_of_range(ss.str());
324 auto it =
map.find(&key);
326 return it->second->second;
329 map[&(x->first)] = x;
345 template <
class Compare>
385 typename std::enable_if<
389 for (
auto&
pair : container) {
395 remap(require_remap);
405 {
return !( (*this) == other);}
427 template<
typename KeyEquality = E,
typename ValueEquality = std::equal_to<V>>
434 while (it1 !=
end() && it2 != other.
end()) {
435 if (!ke(it1->first,it2->first))
437 if (!ve(it1->second,it2->second))
442 return (it1 ==
end() && it2 == other.
end());
454 template<
typename ValueEquality = std::equal_to<V>>
461 for(pair_t
const&
pair: other) {
465 if (!ve(
pair.second,it->second))
Implemention of a linked hash-map.
Definition: linked_map.hxx:72
size_type max_bucket_count() const noexcept
Accessor directly inherited from std::unordered_map.
Definition: linked_map.hxx:131
linked_map_t(std::initializer_list< pair_t > l)
Definition: linked_map.hxx:355
list_t list
Definition: linked_map.hxx:91
std::list< pair_t >::iterator iterator
Definition: linked_map.hxx:81
void push_front(key_t key, value_t value, bool overwrite_existing=false)
Inserts a new key/value binding at the front of this linked_map_t; deletes existing binding for key p...
Definition: linked_map.hxx:224
size_type count(key_t const &key) const
Returns the number of binding associated with key, that is 0 or 1.
Definition: linked_map.hxx:183
size_type erase(key_t const &key)
Deletes the value bound to key.
Definition: linked_map.hxx:269
std::pair< key_t const, value_t > pair_t
Definition: linked_map.hxx:77
map_t::size_type size_type
Definition: linked_map.hxx:87
iterator insert(const_iterator pos, key_t key, value_t value, bool overwrite_existing=false)
Inserts a new key/value binding before pos; deletes existing binding for key prior to insertion if ov...
Definition: linked_map.hxx:201
bool equals_as_map(self_type_t const &other) const
Returns true if the bindings in this linked_map_t are exactly those in other, when considered as maps...
Definition: linked_map.hxx:455
bool empty() const noexcept
Returns if this linked_map_t is empty.
Definition: linked_map.hxx:116
bool operator==(self_type_t const &other)
Returns true if this linked_map_t is equal to other, when both are considered as lists of pairs.
Definition: linked_map.hxx:416
pair_t & front()
Definition: linked_map.hxx:231
iterator begin() noexcept
Definition: linked_map.hxx:143
value_t & operator[](key_t key)
Access, modify or set the value bound to key.
Definition: linked_map.hxx:322
size_type size() const noexcept
Returns the number of bindings in this linked_map_t.
Definition: linked_map.hxx:119
const_iterator begin() const noexcept
Definition: linked_map.hxx:146
const_iterator find(key_t const &key) const
Returns the position corresponding to the binding of key.
Definition: linked_map.hxx:170
std::list< pair_t > list_t
Definition: linked_map.hxx:80
linked_map_t(linked_map_t< key_t, value_t > const &other)
Definition: linked_map.hxx:361
bool operator!=(self_type_t const &other)
Returns true if this linked_map_t is different from other.
Definition: linked_map.hxx:404
linked_map_t(O &&container, typename std::enable_if< is_iterable_with< O, init_pair_t >::value, bool >::type require_remap=true)
Universal constructor to build a linked_map_t from any kind of iterable containing std::pair<std::str...
Definition: linked_map.hxx:383
const_iterator cbegin() const noexcept
Definition: linked_map.hxx:149
void reserve(size_type n)
Accessor directly inherited from std::unordered_map.
Definition: linked_map.hxx:141
linked_map_t(std::list< pair_t > l)
Definition: linked_map.hxx:358
void remap(bool hard)
Recompute map from list.
Definition: linked_map.hxx:101
pair_t const & front() const
Definition: linked_map.hxx:232
void max_load_factor(float x)
Accessor directly inherited from std::unordered_map.
Definition: linked_map.hxx:137
void sort(Compare comp)
Sort this linked_map_t by given comparison.
Definition: linked_map.hxx:346
bool equals_as_list(self_type_t const &other) const
Returns true if this linked_map_t is equal to other, when both are considered as lists of pairs.
Definition: linked_map.hxx:428
linked_map_t< K, V, H, E > self_type_t
Definition: linked_map.hxx:74
std::unordered_map< key_t const *, iterator, pointed_hash_t< key_t const, H >, pointed_equal_t< key_t const, E > > map_t
Definition: linked_map.hxx:86
V value_t
Definition: linked_map.hxx:76
float max_load_factor() const noexcept
Accessor directly inherited from std::unordered_map.
Definition: linked_map.hxx:135
std::pair< key_t, value_t > init_pair_t
Definition: linked_map.hxx:79
map_t map
Definition: linked_map.hxx:90
const_iterator cend() const noexcept
Definition: linked_map.hxx:150
pair_t const & back() const
Definition: linked_map.hxx:236
value_t & at(key_t const &key)
Access value bound to key.
Definition: linked_map.hxx:285
float load_factor() const noexcept
Accessor directly inherited from std::unordered_map.
Definition: linked_map.hxx:133
std::list< pair_t >::const_iterator const_iterator
Definition: linked_map.hxx:82
void sort()
Sort this linked_map_t by key assuming operator< exists on key_t.
Definition: linked_map.hxx:337
size_type bucket_size(unsigned n) const noexcept
Accessor directly inherited from std::unordered_map.
Definition: linked_map.hxx:129
iterator find(key_t const &key)
Returns the position corresponding to the binding of key.
Definition: linked_map.hxx:157
K key_t
Definition: linked_map.hxx:75
iterator erase(const_iterator pos)
Definition: linked_map.hxx:256
pair_t & back()
Definition: linked_map.hxx:235
pair_t value_type
Definition: linked_map.hxx:78
linked_map_t(linked_map_t< key_t, value_t > &&other)
Definition: linked_map.hxx:364
value_t const & at(key_t const &key) const
Access value bound to key.
Definition: linked_map.hxx:300
void rehash(size_type n)
Accessor directly inherited from std::unordered_map.
Definition: linked_map.hxx:139
void clear() noexcept
Clears this linked_map_t.
Definition: linked_map.hxx:124
void push_back(key_t key, value_t value, bool overwrite_existing=false)
Inserts a new key/value binding at the back of this linked_map_t; deletes existing binding for key pr...
Definition: linked_map.hxx:245
size_type bucket_count() const noexcept
Accessor directly inherited from std::unordered_map.
Definition: linked_map.hxx:127
const_iterator end() const noexcept
Definition: linked_map.hxx:147
size_type max_size() const noexcept
Definition: linked_map.hxx:121
linked_map_t()
Definition: linked_map.hxx:353
iterator end() noexcept
Definition: linked_map.hxx:144
This class takes a type E that computes equality for type K and allows to compute equality for type K...
Definition: linked_map.hxx:47
bool operator()(K *key1, K *key2) const noexcept
Definition: linked_map.hxx:49
This class takes a hasher for type K and makes a hasher for type K const* that hash the pointed value...
Definition: linked_map.hxx:34
std::size_t operator()(K *key) const noexcept
Definition: linked_map.hxx:36
static constexpr TOP< void > value
Definition: priority.hh:93
pair_automaton< Aut > pair(const Aut &aut, bool keep_initials=false)
Definition: synchronizing_word.hh:266
Main namespace of Awali.
Definition: ato.hh:22
decltype(internal::is_iterable_aux2< T, X >(priority::value)) is_iterable_with
Trait to test whether type T can be iterated over and assign its values to type X.
Definition: is_iterable.hxx:97