![]() |
Awali
Another Weighted Automata library
|
Implemention of a linked hash-map. More...
#include <linked_map.hxx>
Public Types | |
typedef std::list< pair_t >::const_iterator | const_iterator |
typedef std::pair< key_t, value_t > | init_pair_t |
typedef std::list< pair_t >::iterator | iterator |
typedef K | key_t |
typedef std::list< pair_t > | list_t |
typedef std::unordered_map< key_t const *, iterator, pointed_hash_t< key_t const, H >, pointed_equal_t< key_t const, E > > | map_t |
typedef std::pair< key_t const, value_t > | pair_t |
typedef linked_map_t< K, V, H, E > | self_type_t |
typedef map_t::size_type | size_type |
typedef V | value_t |
typedef pair_t | value_type |
Public Member Functions | |
linked_map_t () | |
linked_map_t (linked_map_t< key_t, value_t > &&other) | |
linked_map_t (linked_map_t< key_t, value_t > const &other) | |
template<class O > | |
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::string,std::string> 's. More... | |
linked_map_t (std::initializer_list< pair_t > l) | |
linked_map_t (std::list< pair_t > l) | |
value_t & | at (key_t const &key) |
Access value bound to key . More... | |
value_t const & | at (key_t const &key) const |
Access value bound to key . More... | |
pair_t & | back () |
pair_t const & | back () const |
const_iterator | begin () const noexcept |
iterator | begin () noexcept |
size_type | bucket_count () const noexcept |
Accessor directly inherited from std::unordered_map. More... | |
size_type | bucket_size (unsigned n) const noexcept |
Accessor directly inherited from std::unordered_map. More... | |
const_iterator | cbegin () const noexcept |
const_iterator | cend () const noexcept |
void | clear () noexcept |
Clears this linked_map_t. More... | |
size_type | count (key_t const &key) const |
Returns the number of binding associated with key , that is 0 or 1. More... | |
bool | empty () const noexcept |
Returns if this linked_map_t is empty. More... | |
const_iterator | end () const noexcept |
iterator | end () noexcept |
template<typename KeyEquality = E, typename ValueEquality = std::equal_to<V>> | |
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. More... | |
template<typename ValueEquality = std::equal_to<V>> | |
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 mapsr. More... | |
iterator | erase (const_iterator pos) |
size_type | erase (key_t const &key) |
Deletes the value bound to key . More... | |
iterator | find (key_t const &key) |
Returns the position corresponding to the binding of key . More... | |
const_iterator | find (key_t const &key) const |
Returns the position corresponding to the binding of key . More... | |
pair_t & | front () |
pair_t const & | front () const |
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 overwrite_existing is true . More... | |
float | load_factor () const noexcept |
Accessor directly inherited from std::unordered_map. More... | |
size_type | max_bucket_count () const noexcept |
Accessor directly inherited from std::unordered_map. More... | |
float | max_load_factor () const noexcept |
Accessor directly inherited from std::unordered_map. More... | |
void | max_load_factor (float x) |
Accessor directly inherited from std::unordered_map. More... | |
size_type | max_size () const noexcept |
bool | operator!= (self_type_t const &other) |
Returns true if this linked_map_t is different from other . More... | |
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. More... | |
value_t & | operator[] (key_t key) |
Access, modify or set the value bound to key . More... | |
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 prior to insertion if overwrite_existing is true . More... | |
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 prior to insertion if overwrite_existing is true . More... | |
void | rehash (size_type n) |
Accessor directly inherited from std::unordered_map. More... | |
void | reserve (size_type n) |
Accessor directly inherited from std::unordered_map. More... | |
size_type | size () const noexcept |
Returns the number of bindings in this linked_map_t. More... | |
void | sort () |
Sort this linked_map_t by key assuming operator< exists on key_t. More... | |
template<class Compare > | |
void | sort (Compare comp) |
Sort this linked_map_t by given comparison. More... | |
Protected Member Functions | |
void | remap (bool hard) |
Recompute map from list. More... | |
Protected Attributes | |
list_t | list |
map_t | map |
Implemention of a linked hash-map.
The main structure is in field list, a std::list
of std::pair<K const, V>
(const is there to avoid user to break the structure invariant). The iterators of a {@link linked_map_t} (
iteratorand
const_iterator`) are directly those of list. The secondary structure is map, an std::unordered_map
that maps keys of type K*
to iterators of the list above. The map uses the classes pointed_hash_t and pointed_equal_t to hash its keys: they wrap the possibility user-defined H
and E
in order to compute equality and hash based on the pointed value (of type K
) instead of the pointer value (of type K*
).
typedef std::list<pair_t>::const_iterator awali::linked_map_t< K, V, H, E >::const_iterator |
typedef std::pair<key_t,value_t> awali::linked_map_t< K, V, H, E >::init_pair_t |
typedef std::list<pair_t>::iterator awali::linked_map_t< K, V, H, E >::iterator |
typedef K awali::linked_map_t< K, V, H, E >::key_t |
typedef std::list<pair_t> awali::linked_map_t< K, V, H, E >::list_t |
typedef std::unordered_map< key_t const*, iterator, pointed_hash_t<key_t const,H>, pointed_equal_t<key_t const,E> > awali::linked_map_t< K, V, H, E >::map_t |
typedef std::pair<key_t const,value_t> awali::linked_map_t< K, V, H, E >::pair_t |
typedef linked_map_t<K,V,H,E> awali::linked_map_t< K, V, H, E >::self_type_t |
typedef map_t::size_type awali::linked_map_t< K, V, H, E >::size_type |
typedef V awali::linked_map_t< K, V, H, E >::value_t |
typedef pair_t awali::linked_map_t< K, V, H, E >::value_type |
awali::linked_map_t< K, V, H, E >::linked_map_t | ( | ) |
awali::linked_map_t< K, V, H, E >::linked_map_t | ( | std::initializer_list< pair_t > | l | ) |
awali::linked_map_t< K, V, H, E >::linked_map_t | ( | std::list< pair_t > | l | ) |
awali::linked_map_t< K, V, H, E >::linked_map_t | ( | linked_map_t< key_t, value_t > const & | other | ) |
awali::linked_map_t< K, V, H, E >::linked_map_t | ( | linked_map_t< key_t, value_t > && | other | ) |
awali::linked_map_t< K, V, H, E >::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::string,std::string>
's.
If provided with an rvalue reference, it moves the elements out of it (so the container does not change size, but its elements are emptied). If provided with an lvalue reference, it copies each pair from it.
container | Container to copy or move the binding pairs from |
require_remap | If set to false , the first elements in the pairs in container are assumed to be unique; if it is not the case, the produced linked_map_t is inconsistent. If set to true , only the last binding for a given key is kept. extra checks. |
value_t& awali::linked_map_t< K, V, H, E >::at | ( | key_t const & | key | ) |
Access value bound to key
.
std::out_of_range | if key is unbound. |
value_t const& awali::linked_map_t< K, V, H, E >::at | ( | key_t const & | key | ) | const |
Access value bound to key
.
std::out_of_range | if key is unbound. |
pair_t& awali::linked_map_t< K, V, H, E >::back | ( | ) |
pair_t const& awali::linked_map_t< K, V, H, E >::back | ( | ) | const |
|
noexcept |
|
noexcept |
|
noexcept |
Accessor directly inherited from std::unordered_map.
|
noexcept |
Accessor directly inherited from std::unordered_map.
|
noexcept |
|
noexcept |
|
noexcept |
Clears this linked_map_t.
size_type awali::linked_map_t< K, V, H, E >::count | ( | key_t const & | key | ) | const |
Returns the number of binding associated with key
, that is 0 or 1.
|
noexcept |
Returns if this linked_map_t is empty.
|
noexcept |
|
noexcept |
bool awali::linked_map_t< K, V, H, E >::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.
KeyEquality
.ValueEquality
. bool awali::linked_map_t< K, V, H, E >::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 mapsr.
E
: each key bound in other
is looked up in this.ValueEquality
, built using the default constructor. iterator awali::linked_map_t< K, V, H, E >::erase | ( | const_iterator | pos | ) |
size_type awali::linked_map_t< K, V, H, E >::erase | ( | key_t const & | key | ) |
Deletes the value bound to key
.
key
was bound, 0 if it was not). iterator awali::linked_map_t< K, V, H, E >::find | ( | key_t const & | key | ) |
Returns the position corresponding to the binding of key
.
Returns end() if key is unbound.
const_iterator awali::linked_map_t< K, V, H, E >::find | ( | key_t const & | key | ) | const |
Returns the position corresponding to the binding of key
.
Returns end() if key is unbound.
pair_t& awali::linked_map_t< K, V, H, E >::front | ( | ) |
pair_t const& awali::linked_map_t< K, V, H, E >::front | ( | ) | const |
iterator awali::linked_map_t< K, V, H, E >::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 overwrite_existing
is true
.
If key was unbound, insert binding before pos
. If key was bound and overwrite_existing
is true
, delete old binding and inserts the new binding before pos
. If key was bound and overwrite_existing
is false
, do nothing.
|
noexcept |
Accessor directly inherited from std::unordered_map.
|
noexcept |
Accessor directly inherited from std::unordered_map.
|
noexcept |
Accessor directly inherited from std::unordered_map.
void awali::linked_map_t< K, V, H, E >::max_load_factor | ( | float | x | ) |
Accessor directly inherited from std::unordered_map.
|
noexcept |
bool awali::linked_map_t< K, V, H, E >::operator!= | ( | self_type_t const & | other | ) |
Returns true
if this linked_map_t is different from other
.
Alias for !( (*this) == other)
.
bool awali::linked_map_t< K, V, H, E >::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.
E
.operator==
.Same as equals_as_list with default values for template parameters.
value_t& awali::linked_map_t< K, V, H, E >::operator[] | ( | key_t | key | ) |
Access, modify or set the value bound to key
.
If key
is unbound before the call, a new binding is inserted at the end of this linked_map. It associates key
to the value resulting from the default value_t constructor, and returns a reference to it. Typical usage is map[key] = value
where key is of type key_t and value of type value_t.
void awali::linked_map_t< K, V, H, E >::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
prior to insertion if overwrite_existing
is true
.
Alias for insert(end(),key,value,overwrite_existing)
void awali::linked_map_t< K, V, H, E >::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
prior to insertion if overwrite_existing
is true
.
Alias for insert(begin(),key,value,overwrite_existing)
void awali::linked_map_t< K, V, H, E >::rehash | ( | size_type | n | ) |
Accessor directly inherited from std::unordered_map.
|
protected |
hard
tells whether the list may contain key duplicates:
hard
is true
: duplicates key are removed from list might have duplicates and only the last binding is kept.hard
is false
: list is not verified for key duplicates; if it has duplicated, this linked_map_t is in an inconsistent state. void awali::linked_map_t< K, V, H, E >::reserve | ( | size_type | n | ) |
Accessor directly inherited from std::unordered_map.
|
noexcept |
Returns the number of bindings in this linked_map_t.
void awali::linked_map_t< K, V, H, E >::sort | ( | ) |
Sort this linked_map_t by key assuming operator<
exists on key_t.
void awali::linked_map_t< K, V, H, E >::sort | ( | Compare | comp | ) |
Sort this linked_map_t by given comparison.
|
protected |
|
protected |