AMCAX Kernel 1.0.0.0
AMCAX::Bimap< key_type, value_type > Class Template Reference

Template class of bidirectional map. More...

#include <common/Bimap.hpp>

Collaboration diagram for AMCAX::Bimap< key_type, value_type >:

Public Types

using map_type1 = std::unordered_map< key_type, value_type >
 Type of the forward map.
 
using map_type2 = std::unordered_map< value_type, key_type >
 Type of the inverse map.
 
using map_iterator1 = typename map_type1::iterator
 Iterator of the forward map.
 
using map_iterator2 = typename map_type2::iterator
 Iterator of the inverse map.
 
using map_const_iterator1 = typename map_type1::const_iterator
 Constant iterator of the forward map.
 
using map_const_iterator2 = typename map_type2::const_iterator
 Constant iterator of the inverse map.
 

Public Member Functions

 Bimap ()=default
 Default constructor.
 
 Bimap (const std::unordered_map< key_type, value_type > &smap)
 Construct from a normal map. More...
 
bool empty () const noexcept
 Is the map empty. More...
 
int size () const noexcept
 Get the size of map. More...
 
void clear ()
 Clear the map.
 
bool insert (const key_type &key, const value_type &value)
 Insert a pair of key and value. More...
 
bool insert_replace (const key_type &key, const value_type &value)
 Insert a pair of key and value, replace the data if existed. More...
 
bool erase_key (const key_type &key)
 Erase the data by key. More...
 
map_iterator1 erase_key (map_iterator1 it)
 Erase the data by iterator of forward map. More...
 
map_iterator1 erase_key (map_const_iterator1 it)
 Erase the data by constant iterator of forward map. More...
 
bool erase_value (const value_type &value)
 Erase the data by value. More...
 
map_iterator2 erase_value (map_iterator2 it)
 Erase the data by iterator of inverse map. More...
 
map_iterator2 erase_value (map_const_iterator2 it)
 Erase the data by constant iterator of inverse map. More...
 
void swap (Bimap &other)
 Swap with another bimap. More...
 
std::pair< map_const_iterator1, bool > find_value_from_key (const key_type &k) const
 Find the value from a key. More...
 
std::pair< map_const_iterator2, bool > find_key_from_value (const value_type &v) const
 Find the key from a value. More...
 
constexpr auto begin () noexcept
 Get the begin iterator. More...
 
constexpr auto begin () const noexcept
 Get the constant begin iterator. More...
 
constexpr auto cbegin () const noexcept
 Get the constant begin iterator. More...
 
constexpr auto end () noexcept
 Get the end iterator. More...
 
constexpr auto end () const noexcept
 Get the constant end iterator. More...
 
constexpr auto cend () const noexcept
 Get the constant end iterator. More...
 
constexpr auto & inverse_map () const noexcept
 Get the inverse map. More...
 

Protected Attributes

map_type1 map1
 Map from key to value.
 
map_type2 map2
 Map from value to key.
 

Detailed Description

template<typename key_type, typename value_type>
class AMCAX::Bimap< key_type, value_type >

Template class of bidirectional map.

Template Parameters
key_typeType of key
value_typeType of value

Constructor & Destructor Documentation

◆ Bimap()

template<typename key_type , typename value_type >
AMCAX::Bimap< key_type, value_type >::Bimap ( const std::unordered_map< key_type, value_type > &  smap)
inlineexplicit

Construct from a normal map.

Parameters
smapThe map

Member Function Documentation

◆ begin() [1/2]

template<typename key_type , typename value_type >
constexpr auto AMCAX::Bimap< key_type, value_type >::begin ( ) const
inlineconstexprnoexcept

Get the constant begin iterator.

Returns
The constant begin iterator

◆ begin() [2/2]

template<typename key_type , typename value_type >
constexpr auto AMCAX::Bimap< key_type, value_type >::begin ( )
inlineconstexprnoexcept

Get the begin iterator.

Returns
The begin iterator

◆ cbegin()

template<typename key_type , typename value_type >
constexpr auto AMCAX::Bimap< key_type, value_type >::cbegin ( ) const
inlineconstexprnoexcept

Get the constant begin iterator.

Returns
The constant begin iterator

◆ cend()

template<typename key_type , typename value_type >
constexpr auto AMCAX::Bimap< key_type, value_type >::cend ( ) const
inlineconstexprnoexcept

Get the constant end iterator.

Returns
The constant end iterator

◆ empty()

template<typename key_type , typename value_type >
bool AMCAX::Bimap< key_type, value_type >::empty ( ) const
inlinenoexcept

Is the map empty.

Returns
True if the map is empty

◆ end() [1/2]

template<typename key_type , typename value_type >
constexpr auto AMCAX::Bimap< key_type, value_type >::end ( ) const
inlineconstexprnoexcept

Get the constant end iterator.

Returns
The constant end iterator

◆ end() [2/2]

template<typename key_type , typename value_type >
constexpr auto AMCAX::Bimap< key_type, value_type >::end ( )
inlineconstexprnoexcept

Get the end iterator.

Returns
The end iterator

◆ erase_key() [1/3]

template<typename key_type , typename value_type >
bool AMCAX::Bimap< key_type, value_type >::erase_key ( const key_type &  key)
inline

Erase the data by key.

Parameters
keyThe key to be erased
Returns
True if the key is erased

◆ erase_key() [2/3]

template<typename key_type , typename value_type >
map_iterator1 AMCAX::Bimap< key_type, value_type >::erase_key ( map_const_iterator1  it)
inline

Erase the data by constant iterator of forward map.

Parameters
itThe constant iterator of forward map
Returns
The iterator after the erased iterator

◆ erase_key() [3/3]

template<typename key_type , typename value_type >
map_iterator1 AMCAX::Bimap< key_type, value_type >::erase_key ( map_iterator1  it)
inline

Erase the data by iterator of forward map.

Parameters
itThe iterator of forward map
Returns
The iterator after the erased iterator

◆ erase_value() [1/3]

template<typename key_type , typename value_type >
bool AMCAX::Bimap< key_type, value_type >::erase_value ( const value_type &  value)
inline

Erase the data by value.

Parameters
valueThe value to be erased
Returns
True if the value is erased

◆ erase_value() [2/3]

template<typename key_type , typename value_type >
map_iterator2 AMCAX::Bimap< key_type, value_type >::erase_value ( map_const_iterator2  it)
inline

Erase the data by constant iterator of inverse map.

Parameters
itThe constant iterator of inverse map
Returns
The iterator after the erased iterator

◆ erase_value() [3/3]

template<typename key_type , typename value_type >
map_iterator2 AMCAX::Bimap< key_type, value_type >::erase_value ( map_iterator2  it)
inline

Erase the data by iterator of inverse map.

Parameters
itThe iterator of inverse map
Returns
The iterator after the erased iterator

◆ find_key_from_value()

template<typename key_type , typename value_type >
std::pair< map_const_iterator2, bool > AMCAX::Bimap< key_type, value_type >::find_key_from_value ( const value_type &  v) const
inline

Find the key from a value.

Parameters
vThe value
Returns
The pair of iterator of inverse map and a boolean which shows whether the value is found

◆ find_value_from_key()

template<typename key_type , typename value_type >
std::pair< map_const_iterator1, bool > AMCAX::Bimap< key_type, value_type >::find_value_from_key ( const key_type &  k) const
inline

Find the value from a key.

Parameters
kThe key
Returns
The pair of iterator of map and a boolean which shows whether the key is found

◆ insert()

template<typename key_type , typename value_type >
bool AMCAX::Bimap< key_type, value_type >::insert ( const key_type &  key,
const value_type &  value 
)
inline

Insert a pair of key and value.

If either the key or the value is found in the map, do nothing

Parameters
keyThe key to be inserted
valueThe value to be inserted
Returns
True if the insertion succeed

◆ insert_replace()

template<typename key_type , typename value_type >
bool AMCAX::Bimap< key_type, value_type >::insert_replace ( const key_type &  key,
const value_type &  value 
)
inline

Insert a pair of key and value, replace the data if existed.

If the key and value are both found in the map, but not mapped to each other, the insertion fails.

Parameters
keyThe key to be inserted
valueThe value to be inserted
Returns
True if the insertion succeed

◆ inverse_map()

template<typename key_type , typename value_type >
constexpr auto & AMCAX::Bimap< key_type, value_type >::inverse_map ( ) const
inlineconstexprnoexcept

Get the inverse map.

Returns
The inverse map

◆ size()

template<typename key_type , typename value_type >
int AMCAX::Bimap< key_type, value_type >::size ( ) const
inlinenoexcept

Get the size of map.

Returns
The size of map

◆ swap()

template<typename key_type , typename value_type >
void AMCAX::Bimap< key_type, value_type >::swap ( Bimap< key_type, value_type > &  other)
inline

Swap with another bimap.

Parameters
otherThe other bimap

The documentation for this class was generated from the following file: