Template Class bimap
Defined in File bimap.h
Class Documentation
-
template<typename KEY, typename VALUE>
class bimap A bidirectional version of std::map, declared as bimap<KEY,VALUE> and which actually contains two std::map’s, one for keys and another for values. To use this class, insert new pairs KEY<->VALUE with bimap::insert. Then, you can access the KEY->VALUE map with bimap::direct(), and the VALUE->KEY map with bimap::inverse(). The consistency of the two internal maps is assured at any time.
Note that unique values are required for both KEYS and VALUES, hence this class is designed to work with bijective mappings only. An exception will be thrown if this contract is broken.
Note
Defined in
#include <mrpt/containers/bimap.h>Note
This class can be accessed through iterators to the map KEY->VALUE only.
Note
Both typenames KEY and VALUE must be suitable for being employed as keys in a std::map, i.e. they must be comparable through a “< operator”.
Note
To serialize this class with the mrpt::serialization API, include the header
#include <mrpt/serialization/bimap_serialization.h>(New in MRPT 2.3.3)Public Types
Public Functions
-
bimap() = default
Default constructor - does nothing
-
inline const_iterator begin() const
-
inline const_iterator end() const
-
inline const_iterator_inverse inverse_begin() const
-
inline iterator_inverse inverse_begin()
-
inline const_iterator_inverse inverse_end() const
-
inline iterator_inverse inverse_end()
-
inline size_t size() const
-
inline bool empty() const
-
inline const std::map<KEY, VALUE> &getDirectMap() const
Return a read-only reference to the internal map KEY->VALUES
-
inline const std::map<VALUE, KEY> &getInverseMap() const
Return a read-only reference to the internal map KEY->VALUES
-
inline void clear()
Clear the contents of the bi-map.
-
inline void insert(const KEY &k, const VALUE &v)
Insert a new pair KEY<->VALUE in the bi-map It is legal to insert the same pair (key,value) more than once, but if a duplicated key is attempted to be inserted with a different value (or viceversa) an exception will be thrown. Remember: this class represents a bijective mapping.
-
inline bool direct(const KEY &k, VALUE &out_v) const
Get the value associated the given key, KEY->VALUE, returning false if not present.
- Returns:
false on key not found.
-
inline VALUE direct(const KEY &k) const
Get the value associated the given key, KEY->VALUE, raising an exception if not present (equivalent to
directMap.at()).- Throws:
std::exception – On key not present in the bi-map.
-
inline bool inverse(const VALUE &v, KEY &out_k) const
Get the key associated the given value, VALUE->KEY, returning false if not present (equivalent to
inverseMap.at()).- Returns:
false on value not found.
-
inline KEY inverse(const VALUE &v) const
Get the key associated the given value, VALUE->KEY, raising an exception if not present.
- Returns:
false on value not found.
-
inline const_iterator find_key(const KEY &k) const
-
inline const_iterator_inverse find_value(const VALUE &v) const
-
inline iterator_inverse find_value(const VALUE &v)
-
bimap() = default