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         auto list_it = it->second;
 
  214     auto res = 
list.emplace(pos, std::move(key),std::move(
value));
 
  215     map.emplace(&(res->first),res);
 
  226                   bool overwrite_existing = 
false)
 
  248     insert(
end(), std::move(key), std::move(
value), overwrite_existing);
 
  259     if (pos == this->
cend())
 
  261     map.erase(&(pos->first));
 
  262     return list.erase(pos);
 
  272     auto it = 
map.find(&key);
 
  288     auto it = 
map.find(&key);
 
  290       return it->second->second;
 
  291     std::stringstream ss;
 
  292     ss << 
"This linked_map does not have a binding with key" << key << 
".";
 
  293     throw std::out_of_range(ss.str());
 
  304     auto it = 
map.find(&key);
 
  306       return it->second->second;
 
  307     std::stringstream ss;
 
  308     ss << 
"This linked_map does not have a binding with key" << key << 
".";
 
  309     throw std::out_of_range(ss.str());
 
  325     auto it = 
map.find(&key);
 
  327       return it->second->second;
 
  330     map[&(x->first)] = x;
 
  346   template <
class Compare>
 
  386     typename std::enable_if<
 
  390     for (
auto& 
pair : container) {
 
  396     remap(require_remap);
 
  406   {
return !( (*this) ==  other);}
 
  428   template<
typename KeyEquality = E, 
typename ValueEquality = std::equal_to<V>>
 
  435     while (it1 != 
end() && it2 != other.
end()) {
 
  436       if (!ke(it1->first,it2->first))
 
  438       if (!ve(it1->second,it2->second))
 
  443     return (it1 == 
end() && it2 == other.
end());
 
  455   template<
typename ValueEquality = std::equal_to<V>>
 
  462     for(pair_t 
const& 
pair: other) {
 
  466       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:356
 
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:225
 
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:270
 
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:456
 
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:417
 
pair_t & front()
Definition: linked_map.hxx:232
 
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:323
 
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:362
 
bool operator!=(self_type_t const &other)
Returns true if this linked_map_t is different from other.
Definition: linked_map.hxx:405
 
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:384
 
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:359
 
void remap(bool hard)
Recompute map from list.
Definition: linked_map.hxx:101
 
pair_t const  & front() const
Definition: linked_map.hxx:233
 
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:347
 
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:429
 
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:237
 
value_t & at(key_t const &key)
Access value bound to key.
Definition: linked_map.hxx:286
 
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:338
 
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:257
 
pair_t & back()
Definition: linked_map.hxx:236
 
pair_t value_type
Definition: linked_map.hxx:78
 
linked_map_t(linked_map_t< key_t, value_t > &&other)
Definition: linked_map.hxx:365
 
value_t const  & at(key_t const &key) const
Access value bound to key.
Definition: linked_map.hxx:301
 
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:246
 
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:354
 
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