Jlm
Classes | Public Types | Public Member Functions | Private Types | Private Attributes | List of all members
jlm::util::BijectiveMap< K, V > Class Template Reference

#include <BijectiveMap.hpp>

Classes

class  ConstIterator
 

Public Types

using ItemType = std::pair< const K, V >
 

Public Member Functions

 ~BijectiveMap () noexcept=default
 
 BijectiveMap ()=default
 
 BijectiveMap (const BijectiveMap &other)=default
 
 BijectiveMap (BijectiveMap &&other) noexcept=default
 
template<class InputIt >
 BijectiveMap (InputIt first, InputIt last)
 
 BijectiveMap (std::initializer_list< ItemType > init)
 
BijectiveMapoperator= (const BijectiveMap &other)=default
 
BijectiveMapoperator= (BijectiveMap &&other)=default
 
void Clear () noexcept
 
std::size_t Size () const noexcept
 
bool Insert (const K &key, const V &value)
 
template<typename IteratorType >
size_t InsertPairs (IteratorType begin, IteratorType end)
 
void InsertOrThrow (const K &key, const V &value)
 
bool HasKey (const K &key) const noexcept
 
bool HasValue (const V &value) const noexcept
 
const V & LookupKey (const K &key) const
 
const K & LookupValue (const V &value) const
 
ConstIterator begin () const noexcept
 
ConstIterator end () const noexcept
 
ConstIterator Erase (ConstIterator it)
 
bool RemoveKey (const K &key)
 
bool RemoveValue (const V &value)
 
template<typename F >
size_t RemoveWhere (const F &match)
 
template<typename F >
size_t RemoveKeysWhere (const F &match)
 
template<typename F >
size_t RemoveValuesWhere (const F &match)
 
bool operator== (const BijectiveMap &other) const noexcept
 
bool operator!= (const BijectiveMap &other) const noexcept
 

Private Types

using ForwardMapType = std::unordered_map< K, V >
 
using ReverseMapType = std::unordered_map< V, K >
 

Private Attributes

ForwardMapType ForwardMap_
 
ReverseMapType ReverseMap_
 

Detailed Description

template<typename K, typename V>
class jlm::util::BijectiveMap< K, V >

Represents a bijective mapping between keys and values, with on average constant time lookups by either key or value. Keys and values must be unique among themselves.

Template Parameters
Kthe type of keys
Vthe type of values

Definition at line 22 of file BijectiveMap.hpp.

Member Typedef Documentation

◆ ForwardMapType

template<typename K , typename V >
using jlm::util::BijectiveMap< K, V >::ForwardMapType = std::unordered_map<K, V>
private

Definition at line 24 of file BijectiveMap.hpp.

◆ ItemType

template<typename K , typename V >
using jlm::util::BijectiveMap< K, V >::ItemType = std::pair<const K, V>

Definition at line 28 of file BijectiveMap.hpp.

◆ ReverseMapType

template<typename K , typename V >
using jlm::util::BijectiveMap< K, V >::ReverseMapType = std::unordered_map<V, K>
private

Definition at line 25 of file BijectiveMap.hpp.

Constructor & Destructor Documentation

◆ ~BijectiveMap()

template<typename K , typename V >
jlm::util::BijectiveMap< K, V >::~BijectiveMap ( )
defaultnoexcept

◆ BijectiveMap() [1/5]

template<typename K , typename V >
jlm::util::BijectiveMap< K, V >::BijectiveMap ( )
default

Constructs an empty BijectiveMap

◆ BijectiveMap() [2/5]

template<typename K , typename V >
jlm::util::BijectiveMap< K, V >::BijectiveMap ( const BijectiveMap< K, V > &  other)
default

◆ BijectiveMap() [3/5]

template<typename K , typename V >
jlm::util::BijectiveMap< K, V >::BijectiveMap ( BijectiveMap< K, V > &&  other)
defaultnoexcept

◆ BijectiveMap() [4/5]

template<typename K , typename V >
template<class InputIt >
jlm::util::BijectiveMap< K, V >::BijectiveMap ( InputIt  first,
InputIt  last 
)
inlineexplicit

Constructs a BijectiveMap from a range of std::pair<K, V>.

Exceptions
jlm::util::errorif any key or value is not unique

Definition at line 106 of file BijectiveMap.hpp.

◆ BijectiveMap() [5/5]

template<typename K , typename V >
jlm::util::BijectiveMap< K, V >::BijectiveMap ( std::initializer_list< ItemType init)
inline

Constructs a BijectiveMap from an initializer list of std::pair<K, V>

Parameters
initthe initializer list
Exceptions
jlm::util::errorif any key or value is not unique

Definition at line 119 of file BijectiveMap.hpp.

Member Function Documentation

◆ begin()

template<typename K , typename V >
ConstIterator jlm::util::BijectiveMap< K, V >::begin ( ) const
inlinenoexcept

Provides an iterator pointing to the first key/value mappings in the BijectiveMap, that can be used to iterate over all pairs, with no ordering guarantees.

Returns
ConstIterator pointing to the first key/value mapping

Definition at line 262 of file BijectiveMap.hpp.

◆ Clear()

template<typename K , typename V >
void jlm::util::BijectiveMap< K, V >::Clear ( )
inlinenoexcept

Removes all key/value mappings from the BijectiveMap.

Definition at line 133 of file BijectiveMap.hpp.

◆ end()

template<typename K , typename V >
ConstIterator jlm::util::BijectiveMap< K, V >::end ( ) const
inlinenoexcept

Provides an iterator pointing to the element following the last key/value mapping. It is a placeholder, and must not be accessed.

Returns
ConstIterator pointing past the last key/value mapping

Definition at line 273 of file BijectiveMap.hpp.

◆ Erase()

template<typename K , typename V >
ConstIterator jlm::util::BijectiveMap< K, V >::Erase ( ConstIterator  it)
inline

Given an iterator pointing to a key/value pair in the BijectiveMap, removes that pair. The iterator must be valid, and not point to end(). Only the removed iterator is affected by this operation, all other iterators stay valid.

Parameters
itan iterator pointing to the element to be removed
Returns
ConstIterator pointing to the key/value pair immediately following the removed pair

Definition at line 286 of file BijectiveMap.hpp.

◆ HasKey()

template<typename K , typename V >
bool jlm::util::BijectiveMap< K, V >::HasKey ( const K &  key) const
inlinenoexcept

Checks for the existance of the given key in the BijectiveMap

Parameters
keythe key to look for
Returns
true if the key exists in the BijectiveMap, otherwise false.

Definition at line 212 of file BijectiveMap.hpp.

◆ HasValue()

template<typename K , typename V >
bool jlm::util::BijectiveMap< K, V >::HasValue ( const V &  value) const
inlinenoexcept

Checks for the existance of the given value in the BijectiveMap

Parameters
valuethe value to look for
Returns
true if the value exists in the BijectiveMap, otherwise false.

Definition at line 223 of file BijectiveMap.hpp.

◆ Insert()

template<typename K , typename V >
bool jlm::util::BijectiveMap< K, V >::Insert ( const K &  key,
const V &  value 
)
inline

Inserts a new key/value pair into the BijectiveMap, if neither the key nor the value are present in the map already.

Parameters
keythe key to be inserted, with the associated value
valuethe value to be inserted, associated with the key
Returns
true if the key/value pair is inserted, otherwise false.

Definition at line 157 of file BijectiveMap.hpp.

◆ InsertOrThrow()

template<typename K , typename V >
void jlm::util::BijectiveMap< K, V >::InsertOrThrow ( const K &  key,
const V &  value 
)
inline

Inserts a new key/value pair into the BijectiveMap. Fails if either the key or value are already present in the map.

Parameters
keythe key to be inserted, with the associated value
valuethe value to be inserted, associated with the key
Exceptions
jlm::util::errorif the key or value already exists in the map

Definition at line 200 of file BijectiveMap.hpp.

◆ InsertPairs()

template<typename K , typename V >
template<typename IteratorType >
size_t jlm::util::BijectiveMap< K, V >::InsertPairs ( IteratorType  begin,
IteratorType  end 
)
inline

Tries to insert all key/value mappings provided by an iterator range

Template Parameters
IteratorTypethe iterator type, a forward iterator with std::pair<K, V> value type.
Parameters
beginan iterator pointing to the first key/value pair to be inserted
endan iterator pointing just past the last key/value pair to be inserted
Returns
the number of key/value pairs inserted

Definition at line 176 of file BijectiveMap.hpp.

◆ LookupKey()

template<typename K , typename V >
const V& jlm::util::BijectiveMap< K, V >::LookupKey ( const K &  key) const
inline
Parameters
keythe key to lookup in the BijectiveMap
Returns
the value associated with the given key
Exceptions
jlm::util::errorif the key does not exist in the BijectiveMap

Definition at line 234 of file BijectiveMap.hpp.

◆ LookupValue()

template<typename K , typename V >
const K& jlm::util::BijectiveMap< K, V >::LookupValue ( const V &  value) const
inline
Parameters
valuethe value to lookup in the BijectiveMap
Returns
the key associated with the given value
Exceptions
jlm::util::errorif the value does not exist in the BijectiveMap

Definition at line 248 of file BijectiveMap.hpp.

◆ operator!=()

template<typename K , typename V >
bool jlm::util::BijectiveMap< K, V >::operator!= ( const BijectiveMap< K, V > &  other) const
inlinenoexcept

Checks for inequality between two BijectiveMaps.

See also
operator==

Definition at line 407 of file BijectiveMap.hpp.

◆ operator=() [1/2]

template<typename K , typename V >
BijectiveMap& jlm::util::BijectiveMap< K, V >::operator= ( BijectiveMap< K, V > &&  other)
default

◆ operator=() [2/2]

template<typename K , typename V >
BijectiveMap& jlm::util::BijectiveMap< K, V >::operator= ( const BijectiveMap< K, V > &  other)
default

◆ operator==()

template<typename K , typename V >
bool jlm::util::BijectiveMap< K, V >::operator== ( const BijectiveMap< K, V > &  other) const
inlinenoexcept

Compares the key/value mapping in two BijectiveMaps.

Parameters
otherthe BijectiveMap to comapre against
Returns
true if the set of key/value pairs are identical across the two BijectiveMaps

Definition at line 396 of file BijectiveMap.hpp.

◆ RemoveKey()

template<typename K , typename V >
bool jlm::util::BijectiveMap< K, V >::RemoveKey ( const K &  key)
inline

Removes a key/value pair from the BijectiveMap, if the given key exists

Parameters
keythe key to be removed
Returns
true if a key/value pair was removed

Definition at line 300 of file BijectiveMap.hpp.

◆ RemoveKeysWhere()

template<typename K , typename V >
template<typename F >
size_t jlm::util::BijectiveMap< K, V >::RemoveKeysWhere ( const F &  match)
inline

Removes all key/value pairs where the key satisfies the predicate match.

Template Parameters
Fa functor with the signature (const K &) -> bool
Parameters
matchan instance of F, to be invoked on each key
Returns
the number of key/value pairs that were removed

Definition at line 364 of file BijectiveMap.hpp.

◆ RemoveValue()

template<typename K , typename V >
bool jlm::util::BijectiveMap< K, V >::RemoveValue ( const V &  value)
inline

Removes a key/value pair from the BijectiveMap, if the given value exists

Parameters
valuethe value to be removed
Returns
true if a key/value pair was removed

Definition at line 316 of file BijectiveMap.hpp.

◆ RemoveValuesWhere()

template<typename K , typename V >
template<typename F >
size_t jlm::util::BijectiveMap< K, V >::RemoveValuesWhere ( const F &  match)
inline

Removes all key/value pairs where the value satisfies the predicate match.

Template Parameters
Fa functor with the signature (const V &) -> bool
Parameters
matchan instance of F, to be invoked on each value
Returns
the number of key/value pairs that were removed

Definition at line 381 of file BijectiveMap.hpp.

◆ RemoveWhere()

template<typename K , typename V >
template<typename F >
size_t jlm::util::BijectiveMap< K, V >::RemoveWhere ( const F &  match)
inline

Removes all key/value pairs in the BijectiveMap that satisfy the predicate match.

Template Parameters
Fa functor with the signature (const K &, const V &) -> bool
Parameters
matchan instance of F, to be invoked on each pair
Returns
the number of key/value pairs that were removed

Definition at line 337 of file BijectiveMap.hpp.

◆ Size()

template<typename K , typename V >
std::size_t jlm::util::BijectiveMap< K, V >::Size ( ) const
inlinenoexcept

Gets the number of key/value mappings in the BijectiveMap.

Definition at line 143 of file BijectiveMap.hpp.

Member Data Documentation

◆ ForwardMap_

template<typename K , typename V >
ForwardMapType jlm::util::BijectiveMap< K, V >::ForwardMap_
private

Definition at line 413 of file BijectiveMap.hpp.

◆ ReverseMap_

template<typename K , typename V >
ReverseMapType jlm::util::BijectiveMap< K, V >::ReverseMap_
private

Definition at line 414 of file BijectiveMap.hpp.


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